feat: typeing
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
Page({
|
||||
canvas: null as WechatMiniprogram.Canvas | null,
|
||||
ctx: null as CanvasRenderingContext2D | null,
|
||||
canvas: null as Canvas | null,
|
||||
ctx: null as RenderingContext | null,
|
||||
data: {
|
||||
characters: ['鱼', '鸟', '牛', '羊'] as const, // 固定汉字类型
|
||||
colorMap: new Map([
|
||||
@@ -60,8 +60,8 @@ Page({
|
||||
},
|
||||
|
||||
// 绘制完整游戏界面
|
||||
drawGameBoard(ctx?: CanvasRenderingContext2D) {
|
||||
ctx = ctx || (this.ctx as CanvasRenderingContext2D);
|
||||
drawGameBoard(ctx?: RenderingContext) {
|
||||
ctx = ctx || (this.ctx as RenderingContext);
|
||||
ctx.clearRect(0, 0, 2480, 3508);
|
||||
|
||||
// 绘制标题
|
||||
@@ -77,7 +77,7 @@ Page({
|
||||
},
|
||||
|
||||
// 绘制颜色示例
|
||||
drawColorLegend(ctx: CanvasRenderingContext2D, y: number) {
|
||||
drawColorLegend(ctx: RenderingContext, y: number) {
|
||||
let x = 500;
|
||||
this.data.characters.forEach((char) => {
|
||||
ctx.beginPath();
|
||||
@@ -92,7 +92,7 @@ Page({
|
||||
},
|
||||
|
||||
// 绘制汉字矩阵(6列x7行)
|
||||
drawCharacterMatrix(ctx: CanvasRenderingContext2D, startY: number) {
|
||||
drawCharacterMatrix(ctx: RenderingContext, startY: number) {
|
||||
const cols = 6;
|
||||
const cellSize = 350; // 每个单元格大小
|
||||
|
||||
@@ -137,9 +137,7 @@ Page({
|
||||
const index = e.currentTarget.dataset.index;
|
||||
if (!this.data.selectedColor) return;
|
||||
|
||||
const matrix = this.data.matrix.map((char, i) =>
|
||||
i === index ? this.data.selectedChar : char,
|
||||
);
|
||||
const matrix = this.data.matrix.map((char, i) => (i === index ? this.data.selectedChar : char));
|
||||
|
||||
this.setData({ matrix }, () => {
|
||||
this.drawGameBoard();
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
"strict": true,
|
||||
"strictPropertyInitialization": true,
|
||||
"lib": ["ES2020"],
|
||||
"typeRoots": ["./typings"]
|
||||
"typeRoots": ["./node_modules/@types", "./typings"]
|
||||
},
|
||||
"include": ["./**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// 全局声明
|
||||
type Canvas = WechatMiniprogram.Canvas;
|
||||
type RenderingContext = WechatMiniprogram.CanvasRenderingContext;
|
||||
Vendored
+6
-7
@@ -1,8 +1,7 @@
|
||||
/// <reference path="./types/index.d.ts" />
|
||||
|
||||
/// <reference path="./global.d.ts" />
|
||||
interface IAppOption {
|
||||
globalData: {
|
||||
userInfo?: WechatMiniprogram.UserInfo,
|
||||
}
|
||||
userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback,
|
||||
}
|
||||
globalData: {
|
||||
userInfo?: WechatMiniprogram.UserInfo;
|
||||
};
|
||||
userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback;
|
||||
}
|
||||
|
||||
Vendored
+6178
-8038
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user