feat: typeing

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