From 73acc4b50f982e70ab973814e164dba941cc0bff Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Fri, 20 Nov 2026 17:27:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=88=A0=E9=99=A4=E6=97=A7=20textu?= =?UTF-8?q?re=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 4 + .../client-base/src/components/textbox.tsx | 24 +- .../src/components/textboxTyper.ts | 44 +- .../client-base/src/components/tip.tsx | 25 +- .../client-base/src/elements/cache.ts | 488 ------------------ .../client-base/src/material/manager.ts | 8 + .../client-base/src/material/types.ts | 6 + packages-user/client-modules/package.json | 1 - packages-user/client-modules/src/types.ts | 4 +- packages-user/client-system/package.json | 6 - packages-user/client-system/src/index.ts | 1 - packages-user/client-system/src/types.ts | 8 - pnpm-lock.yaml | 9 - 13 files changed, 63 insertions(+), 565 deletions(-) delete mode 100644 packages-user/client-base/src/elements/cache.ts delete mode 100644 packages-user/client-system/package.json delete mode 100644 packages-user/client-system/src/index.ts delete mode 100644 packages-user/client-system/src/types.ts diff --git a/AGENTS.md b/AGENTS.md index e758d44..8843530 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -36,6 +36,10 @@ 代码核心要求:不要求你的代码写的对、不要求测试用例写的多、不要求考虑的边界情况足够多、不要求完全没有类型错误。只要求代码绝对符合 `dev.md` 的要求、代码风格跟已有代码一致,不会看起来不像一个人写的。 +其他要求: + +- 不允许在注释及字符串中写如 `…` 的非汉语及非 ASCII 字符。 + ## 时间要求 在开始前检查本机账户名,如果是 `LHY`(或小写 `lhy`) 或 `13194`,那么每次子代理执行完毕时,检查本机时间,若时间晚于 22:00,则停止执行,避免 22:30 断电导致内容丢失。按照程序严格度执行此条要求,不到 22:00 就继续,到了再停止,不要因为快到 22:00 就停,差一秒也要继续。 diff --git a/packages-user/client-base/src/components/textbox.tsx b/packages-user/client-base/src/components/textbox.tsx index 1705cc3..5913c27 100644 --- a/packages-user/client-base/src/components/textbox.tsx +++ b/packages-user/client-base/src/components/textbox.tsx @@ -28,7 +28,6 @@ import { TextAlign } from './textboxTyper'; import { SetupComponentOptions } from '@motajs/system'; -import { texture } from '../elements'; import { DefaultProps, onExcited } from '@motajs/render-vue'; import { Icon } from './icon'; @@ -198,10 +197,10 @@ export const TextContent = defineComponent< } case TextContentType.Icon: { const { renderable: r, x: dx, y: dy, width, height } = data; - const render = r.render; - const [x, y, w, h] = render[0]; - const icon = r.autotile ? r.image[0] : r.image; - ctx.drawImage(icon, x, y, w, h, dx, dy, width, height); + const w = r.offset; + const h = data.height; + const source = r.texture.source; + ctx.drawImage(source, 0, 0, w, h, dx, dy, width, height); break; } } @@ -390,17 +389,18 @@ export const Textbox = defineComponent< () => data.height! - data.padding! * 2 - contentY.value ); const iconLoc = computed(() => { - const y = contentY.value; - const pad = data.padding!; + // const y = contentY.value; + // const pad = data.padding!; const icon = data.icon; if (isNil(icon) || icon === 'none') { return []; } else { - const num = texture.idNumberMap[icon]; - const renderable = texture.getRenderable(num); - if (!renderable) return []; - const [, , w, h] = renderable.render[0]; - return [pad, pad + y, w, h]; + // const num = texture.idNumberMap[icon]; + // const renderable = texture.getRenderable(num); + // if (!renderable) return []; + // const [, , w, h] = renderable.render[0]; + // return [pad, pad + y, w, h]; + return []; } }); const hasIcon = computed(() => { diff --git a/packages-user/client-base/src/components/textboxTyper.ts b/packages-user/client-base/src/components/textboxTyper.ts index 5b94f38..f0738b4 100644 --- a/packages-user/client-base/src/components/textboxTyper.ts +++ b/packages-user/client-base/src/components/textboxTyper.ts @@ -2,8 +2,8 @@ import { logger } from '@motajs/common'; import { Font, MotaOffscreenCanvas2D } from '@motajs/render'; import EventEmitter from 'eventemitter3'; import { isNil } from 'lodash-es'; -import { RenderableData, AutotileRenderable, texture } from '../elements'; import { IExcitable } from '@motajs/animate'; +import { IMaterialFramedData, ITextureManager } from '../material'; /** 文字的安全填充,会填充在文字的上侧和下侧,防止削顶和削底 */ const SAFE_PAD = 1; @@ -36,6 +36,8 @@ const enum TextGuessStatus { } export interface ITextContentConfig { + /** 使用的游戏贴图管理器 */ + materials: ITextureManager | null; /** 字体 */ font: Font; /** 是否持续上一次的文本,开启后,如果修改后的文本以修改前的文本为开头,那么会继续播放而不会从头播放 */ @@ -126,8 +128,8 @@ export interface ITextContentIconNode extends ITextContentNodeBase { readonly type: TextContentType.Icon; /** 图标节点所在位置的字体大小,用于限制图标显示大小 */ readonly fontSize: number; - /** 图标节点的图标数字 */ - readonly icon: AllNumbers; + /** 图标节点的图标数字或 id */ + readonly icon: number | string; } export interface ITextContentWaitNode extends ITextContentNodeBase { @@ -167,9 +169,9 @@ export interface ITextContentIconBlock extends ITextContentBlockBase, ISizedTextContentBlock { readonly type: TextContentType.Icon; /** 图标 block 显示的图标 */ - readonly icon: AllNumbers; + readonly icon: number | string; /** 图标的渲染信息 */ - readonly renderable: RenderableData | AutotileRenderable; + readonly renderable: IMaterialFramedData; } export interface ITextContentWaitBlock extends ITextContentBlockBase { @@ -283,6 +285,7 @@ export class TextContentTyper this.config = { font, + materials: config.materials ?? null, fontFamily: font.family, fontSize: font.size, fontWeight: font.weight, @@ -707,7 +710,7 @@ export class TextContentParser { this.resolved = ''; } - private addIconRenderable(pointer: number, icon: AllNumbers) { + private addIconRenderable(pointer: number, icon: number | string) { const data: ITextContentIconNode = { type: TextContentType.Icon, raw: this.getRaw(pointer), @@ -813,7 +816,7 @@ export class TextContentParser { const name = header.slice(0, equalIndex); const param = header.slice(equalIndex + 1); if (name !== 'w' || !param) { - logger.warn(55, '[w=…]'); + logger.warn(55, '[w=...]'); return pointer; } const time = parseInt(param); @@ -828,25 +831,14 @@ export class TextContentParser { const name = header.slice(0, equalIndex); const param = header.slice(equalIndex + 1); if (name !== 'icon' || !param) { - logger.warn(55, '[icon=…]'); + logger.warn(55, '[icon=...]'); return pointer; } if (/^\d+$/.test(param)) { const num = Number(param); - this.addIconRenderable(end + 1, num as AllNumbers); + this.addIconRenderable(end + 1, num); } else { - if (/^X\d+$/.test(param)) { - // 额外素材 - const num = Number(param.slice(1)); - this.addIconRenderable(end + 1, num as AllNumbers); - } else { - const num = texture.idNumberMap[param as AllIds]; - if (num === void 0) { - logger.warn(59, param); - return end; - } - this.addIconRenderable(end + 1, num); - } + this.addIconRenderable(end + 1, param); } return end; } @@ -1110,15 +1102,17 @@ export class TextContentParser { return block; } case TextContentType.Icon: { - const renderable = texture.getRenderable(node.icon); - if (!renderable) break; - const [, , width, height] = renderable.render[0]; + const manager = this.config.materials; + if (!manager) break; + const data = manager.tile(node.icon); + if (!data) break; + const { width, height } = data.texture; const scale = node.fontSize / height; const block: ITextContentIconBlock = { type: TextContentType.Icon, raw: node.raw, icon: node.icon, - renderable, + renderable: data, width: width * scale, height: height * scale }; diff --git a/packages-user/client-base/src/components/tip.tsx b/packages-user/client-base/src/components/tip.tsx index c3eeb01..7ecfbf8 100644 --- a/packages-user/client-base/src/components/tip.tsx +++ b/packages-user/client-base/src/components/tip.tsx @@ -3,7 +3,6 @@ import { logger } from '@motajs/common'; import { computed, defineComponent, onUnmounted, ref } from 'vue'; import { cosh } from '@motajs/animate'; import { debounce } from 'lodash-es'; -import { texture } from '../elements'; import { SetupComponentOptions } from '@motajs/system'; import { DefaultProps, transitioned } from '@motajs/render-vue'; import { Icon } from './icon'; @@ -50,10 +49,10 @@ export const Tip = defineComponent((props, { expose }) => { const hidden = computed(() => alpha.ref.value === 0); const showIcon = computed(() => iconNum.value !== 0); const iconSize = computed<[number, number]>(() => { - const renderable = texture.getRenderable(iconNum.value); - if (!renderable) return [1, 1]; - const [, , width, height] = renderable.render[0]; - return [width, height]; + // const renderable = texture.getRenderable(iconNum.value); + // if (!renderable) return [1, 1]; + // const [, , width, height] = renderable.render[0]; + return [0, 0]; }); const iconLoc = computed(() => { const [width, height] = iconSize.value; @@ -92,14 +91,14 @@ export const Tip = defineComponent((props, { expose }) => { alpha.set(0); }, 3000); - const drawTip = (tipText: string, iconId: AllIds | AllNumbers = 0) => { - if (typeof iconId === 'string') { - const num = texture.idNumberMap[iconId]; - iconNum.value = num; - } else { - // 样板竟然会传 null 进来,然后报错 - iconNum.value = iconId ?? 0; - } + const drawTip = (tipText: string) => { + // if (typeof iconId === 'string') { + // const num = texture.idNumberMap[iconId]; + // iconNum.value = num; + // } else { + // // 样板竟然会传 null 进来,然后报错 + // iconNum.value = iconId ?? 0; + // } text.value = core.replaceText(tipText); alpha.set(0, 0); alpha.set(1); diff --git a/packages-user/client-base/src/elements/cache.ts b/packages-user/client-base/src/elements/cache.ts deleted file mode 100644 index 034e7c7..0000000 --- a/packages-user/client-base/src/elements/cache.ts +++ /dev/null @@ -1,488 +0,0 @@ -import { logger } from '@motajs/common'; -import { MotaOffscreenCanvas2D, SizedCanvasImageSource } from '@motajs/render'; - -// 经过测试(https://www.measurethat.net/Benchmarks/Show/30741/1/drawimage-img-vs-canvas-vs-bitmap-cropping-fix-loading) -// 得出结论,ImageBitmap和Canvas的绘制性能不如Image,于是直接画Image就行,所以缓存基本上就是存Image - -type ImageMapKeys = Exclude; -type ImageMap = Record; - -const i = (img: ImageMapKeys) => { - return core.material.images[img]; -}; - -const imageMap: Partial = {}; - -interface AutotileCache { - parent?: Set>; - frame: number; - cache: Record; -} -type AutotileCaches = Record, AutotileCache>; - -interface TextureRequire { - tileset: Record; - material: Record; - autotile: AutotileCaches; - images: Record; -} - -interface RenderableDataBase { - /** 图块的总帧数 */ - frame: number; - /** 对应图块属性的动画帧数,-1表示没有设定,0表示第一帧 */ - animate: number; - render: [x: number, y: number, width: number, height: number][]; -} - -export interface RenderableData extends RenderableDataBase { - image: SizedCanvasImageSource; - autotile: false; -} - -export interface AutotileRenderable extends RenderableDataBase { - image: Record; - autotile: true; -} - -class TextureCache { - tileset!: Record; - material: Record; - autotile!: AutotileCaches; - images!: Record; - - idNumberMap!: IdToNumber; - - /** 渲染信息 */ - renderable: Map = new Map(); - /** 自动元件额外连接信息,用于对非自身图块进行连接 */ - autoConn: Map> = new Map(); - /** 行走图朝向绑定 */ - characterDirection: Record = { - down: 0, - left: 1, - right: 2, - up: 3, - leftup: 1, - leftdown: 1, - rightup: 2, - rightdown: 2 - }; - /** 行走图转向顺序 */ - characterTurn: Dir[] = ['up', 'right', 'down', 'left']; - characterTurn2: Dir2[] = ['leftup', 'rightup', 'rightdown', 'leftdown']; - - constructor() { - this.material = imageMap as Record; - } - - init() { - const map = maps_90f36752_8815_4be8_b32b_d7fad1d0542e; - // @ts-expect-error 无法推导 - this.idNumberMap = {}; - for (const [key, { id }] of Object.entries(map)) { - // @ts-expect-error 无法推导 - this.idNumberMap[id] = parseInt(key) as AllNumbers; - } - this.tileset = core.material.images.tilesets; - this.autotile = splitAutotiles(this.idNumberMap); - this.images = core.material.images.images; - this.calRenderable(); - this.calAutotileConnections(); - } - - /** - * 获取纹理 - * @param type 纹理类型 - * @param key 纹理名称 - */ - require( - type: T, - key: K - ): TextureRequire[T][K] { - return this[type][key]; - } - - /** - * 计算每个图块的可渲染信息 - */ - private calRenderable() { - const map = maps_90f36752_8815_4be8_b32b_d7fad1d0542e; - for (const key of Object.keys(map)) { - this.calRenderableByNum(parseInt(key)); - } - } - - /** - * 根据图块数字计算出它的渲染信息 - * @param num 图块数字 - */ - calRenderableByNum( - num: number - ): RenderableData | AutotileRenderable | null { - const map = maps_90f36752_8815_4be8_b32b_d7fad1d0542e; - const icons = icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1; - - /** 特判空图块与空气墙 */ - if (num === 0 || num === 17) return null; - - // 额外素材 - if (num >= 10000) { - const offset = core.getTilesetOffset(num); - if (!offset) return null; - const { image, x, y } = offset; - const data: RenderableData = { - image: this.tileset[image], - frame: 1, - render: [[x * 32, y * 32, 32, 32]], - animate: 0, - autotile: false - }; - this.renderable.set(num, data); - return data; - } - - const data = map[num as Exclude]; - // 地狱般的分支if - if (data) { - const { cls, id, animate } = data; - // enemy48和npc48都应该视为大怪物 - if (cls === 'enemy48' || cls === 'npc48') { - const img = core.material.images[cls]; - if (!img) return null; - // @ts-expect-error 无法推导 - const line = icons[cls][id]; - const w = 32; - const h = 48; - const y = h * line; - const data: RenderableData = { - image: img, - frame: 4, - render: [ - [0, y, w, h], - [w, y, w, h], - [w * 2, y, w, h], - [w * 3, y, w, h] - ], - animate: (animate ?? 0) - 1, - autotile: false - }; - this.renderable.set(num, data); - return data; - } - // 自动元件 - if (cls === 'autotile') { - if (!this.autotile) return null; - const auto = this.autotile[num as AllNumbersOf<'autotile'>]; - const cell = 32; - const render: [number, number, number, number][] = []; - if (auto.frame >= 1) { - render.push([0, 0, cell, cell]); - } - if (auto.frame >= 3) { - render.push( - [cell, 0, cell, cell], - [cell * 2, 0, cell, cell] - ); - } - if (auto.frame >= 4) { - render.push([cell * 3, 0, cell, cell]); - } - const data: AutotileRenderable = { - image: auto.cache, - frame: auto.frame, - render, - autotile: true, - animate: (animate ?? 0) - 1 - }; - this.renderable.set(num, data); - return data; - } else { - const image = - core.material.images[ - cls as Exclude - ]; - if (!image) return null; - const frame = core.getAnimateFrames(cls); - const cell = 32; - // @ts-expect-error 无法推导 - const offset = (icons[cls][id] as number) * cell; - const render: [number, number, number, number][] = [ - [0, offset, cell, cell] - ]; - if (frame === 2) { - render.push([cell, offset, cell, cell]); - } - if (frame === 4) { - render.push( - [cell, offset, cell, cell], - [cell * 2, offset, cell, cell], - [cell * 3, offset, cell, cell] - ); - } - const data: RenderableData = { - image, - frame: frame, - render, - autotile: false, - animate: (animate ?? 0) - 1 - }; - this.renderable.set(num, data); - return data; - } - } else { - logger.warn(11, num.toString()); - return null; - } - } - - /** - * 获取一个图块的渲染信息,自动元件会特别标明autotile属性 - * @param num 图块数字 - */ - getRenderable(num: number) { - return this.renderable.get(num) ?? this.calRenderableByNum(num); - } - - /** - * 计算自动元件的额外连接 - */ - private calAutotileConnections() { - const icons = icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1; - const maps = maps_90f36752_8815_4be8_b32b_d7fad1d0542e; - - Object.keys(icons.autotile).forEach(v => { - const num = this.idNumberMap[v as AllIdsOf<'autotile'>]; - const data = maps[num]; - const { autotileConnection } = data; - if (!autotileConnection) return; - const list = new Set(); - autotileConnection.forEach(v => { - if (typeof v === 'number') { - list.add(v); - } else { - list.add(this.idNumberMap[v]); - } - }); - this.autoConn.set(num, list); - }); - } - - /** - * 获取自动元件的额外连接情况 - * @param num 自动元件的图块数字 - */ - getAutotileConnections(num: number) { - return this.autoConn.get(num); - } -} - -export const texture = new TextureCache(); - -// 3x4 与 2x3 的自动元件信息 -// 将自动元件按 16x16 切分后,数组分别表示 左上 右上 右下 左下 所在图块位置 -const bigAutotile: Record = {}; -const smallAutotile: Record = {}; - -function getAutotileIndices() { - // 应当从 0 - 255 进行枚举 - // 二进制从高位到低位依次是 左上 上 右上 右 右下 下 左下 左 - // 有兴趣可以研究下这个算法 - const get = ( - target: Record, - mode: 1 | 2 - ) => { - const h = mode === 1 ? 4 : 2; - const v = mode === 1 ? 24 : 8; - const luo = mode === 1 ? 12 : 8; // leftup origin - const ruo = mode === 1 ? 17 : 11; // rightup origin - const ldo = mode === 1 ? 42 : 20; // leftdown origin - const rdo = mode === 1 ? 47 : 23; // rightdown origin - const luc = mode === 1 ? 4 : 2; // leftup corner - const ruc = mode === 1 ? 5 : 3; // rightup corner - const rdc = mode === 1 ? 11 : 7; // rightdown corner - const ldc = mode === 1 ? 10 : 6; // leftdown corner - - for (let i = 0; i <= 0b11111111; i++) { - let lu = luo; // leftup - let ru = ruo; // rightup - let ld = ldo; // leftdown - let rd = rdo; // rightdown - - // 先看四个方向,最后看斜角方向 - if (i & 0b00000001) { - lu += h; - ld += h; - if (i & 0b00010000) { - ru += h / 2; - rd += h / 2; - } - } - if (i & 0b00000100) { - ld -= v; - rd -= v; - if (i & 0b01000000) { - lu -= v / 2; - ru -= v / 2; - } - } - if (i & 0b00010000) { - ru -= h; - rd -= h; - if (i & 0b00000001) { - lu -= h / 2; - ld -= h / 2; - } - } - if (i & 0b01000000) { - lu += v; - ru += v; - if (i & 0b00000100) { - ld += v / 2; - rd += v / 2; - } - } - // 斜角 - if ((i & 0b11000001) === 0b01000001) { - lu = luc; - } - if ((i & 0b01110000) === 0b01010000) { - ru = ruc; - } - if ((i & 0b00011100) === 0b00010100) { - rd = rdc; - } - if ((i & 0b00000111) === 0b00000101) { - ld = ldc; - } - target[i] = [lu, ru, rd, ld]; - } - }; - - get(bigAutotile, 1); - get(smallAutotile, 2); -} -getAutotileIndices(); - -function getRepeatMap() { - // 实际上3x4与2x3的重复映射是一致的,因此只需要计算一个就行了 - // 这里使用2x3的进行计算 - const calculated: Record = {}; - const repeatMap: Record = {}; - for (const [num, [lu, ru, rd, ld]] of Object.entries(smallAutotile)) { - const n = lu + ru * 24 + rd * 24 ** 2 + ld * 24 ** 3; - calculated[num] = n; - for (const [num2, n2] of Object.entries(calculated)) { - if (n2 === n) { - repeatMap[Number(num)] = Number(num2); - break; - } - } - } - - return repeatMap; -} - -function splitAutotiles(map: IdToNumber): AutotileCaches { - const cache: Partial = {}; - /** 重复映射,由于自动元件只有48种,其余的208种是重复的,因此需要获取重复映射 */ - const repeatMap: Record = getRepeatMap(); - /** 每个自动元件左上角32*32的内容,用于判断父子关系 */ - const masterMap: Partial, string>> = {}; - - for (const [key, img] of Object.entries(core.material.images.autotile)) { - const auto = map[key as AllIdsOf<'autotile'>]; - - // 判断自动元件类型 - let mode: 1 | 2 = 1; - let frame = 1; - if (img.width === 384) { - frame = 4; - } else if (img.width === 192) { - mode = 2; - frame = 3; - } else if (img.width === 64) { - mode = 2; - } - - cache[auto] = { - frame, - cache: {} - }; - - // 父子关系,截取本图块的左上角存入map - const master = new MotaOffscreenCanvas2D(); - master.setHD(false); - master.setAntiAliasing(false); - master.size(32, 32); - master.ctx.drawImage(img, 0, 0, 32, 32, 0, 0, 32, 32); - masterMap[auto] = master.canvas.toDataURL('image/png'); - - // 自动图块的绘制信息 - for (let i = 0; i <= 0b11111111; i++) { - const re = repeatMap[i]; - if (re) { - const cached = cache[auto]!.cache[re]; - if (cached) { - cache[auto]!.cache[i] = cached; - continue; - } - } - - const data = (mode === 1 ? bigAutotile : smallAutotile)[i]; - const row = mode === 1 ? 6 : 4; - const info: [number, number][] = data.map(v => [ - (v % row) * 16, - Math.floor(v / row) * 16 - ]); - - const canvas = new MotaOffscreenCanvas2D(); - canvas.setHD(false); - canvas.setAntiAliasing(false); - canvas.size(32 * frame, 32); - const ctx = canvas.ctx; - for (let i = 0; i < frame; i++) { - const dx = 32 * i; - const sx1 = info[0][0] + (i * row * 32) / 2; - const sx2 = info[1][0] + (i * row * 32) / 2; - const sx3 = info[2][0] + (i * row * 32) / 2; - const sx4 = info[3][0] + (i * row * 32) / 2; - const sy1 = info[0][1]; - const sy2 = info[1][1]; - const sy3 = info[2][1]; - const sy4 = info[3][1]; - - ctx.drawImage(img, sx1, sy1, 16, 16, dx, 0, 16, 16); - ctx.drawImage(img, sx2, sy2, 16, 16, dx + 16, 0, 16, 16); - ctx.drawImage(img, sx3, sy3, 16, 16, dx + 16, 16, 16, 16); - ctx.drawImage(img, sx4, sy4, 16, 16, dx, 16, 16, 16); - } - cache[auto]!.cache[i] = canvas.canvas; - } - } - - const judge = new MotaOffscreenCanvas2D(); - judge.setHD(false); - judge.setAntiAliasing(false); - judge.size(32, 32); - // 进行父子关系判断 - for (const [key, img] of Object.entries(core.material.images.autotile)) { - const auto = map[key as AllIdsOf<'autotile'>]; - - // 只针对3*4的图块进行,截取第一行中间的,然后判断 - judge.clear(); - judge.ctx.drawImage(img, 32, 0, 32, 32, 0, 0, 32, 32); - const data = judge.canvas.toDataURL('image/png'); - - for (const [key, data2] of Object.entries(masterMap)) { - const auto2 = map[key as AllIdsOf<'autotile'>]; - - if (data === data2) { - cache[auto]!.parent ??= new Set(); - cache[auto]!.parent!.add(auto2); - } - } - } - - return cache as AutotileCaches; -} diff --git a/packages-user/client-base/src/material/manager.ts b/packages-user/client-base/src/material/manager.ts index 496db91..d51db09 100644 --- a/packages-user/client-base/src/material/manager.ts +++ b/packages-user/client-base/src/material/manager.ts @@ -329,6 +329,14 @@ export class TextureManager implements ITextureManager { } } + tile(tile: number | string): Readonly | null { + if (typeof tile === 'number') { + return this.getTile(tile); + } else { + return this.getTileByAlias(tile); + } + } + getTilesetByAlias(alias: string): ITexture | null { return this.tilesetStore.fromAlias(alias); } diff --git a/packages-user/client-base/src/material/types.ts b/packages-user/client-base/src/material/types.ts index 0f47428..42c2a07 100644 --- a/packages-user/client-base/src/material/types.ts +++ b/packages-user/client-base/src/material/types.ts @@ -195,6 +195,12 @@ export interface ITextureAliasGetter { */ getTileByAlias(alias: string): Readonly | null; + /** + * 根据图块数字或 id 获取图块渲染信息,可以获取额外素材,会自动将未缓存的额外素材缓存 + * @param tile 图块的数字或 id + */ + tile(tile: number | string): Readonly | null; + /** * 根据额外素材名称获取额外素材 * @param alias 额外素材名称 diff --git a/packages-user/client-modules/package.json b/packages-user/client-modules/package.json index 41fa4f0..7bc1066 100644 --- a/packages-user/client-modules/package.json +++ b/packages-user/client-modules/package.json @@ -8,7 +8,6 @@ "@motajs/render-vue": "workspace:*", "@motajs/system": "workspace:*", "@user/client-base": "workspace:*", - "@user/client-system": "workspace:*", "@user/data-common": "workspace:*", "@user/data-base": "workspace:*", "@user/data-system": "workspace:*", diff --git a/packages-user/client-modules/src/types.ts b/packages-user/client-modules/src/types.ts index ce69dc4..6cdec11 100644 --- a/packages-user/client-modules/src/types.ts +++ b/packages-user/client-modules/src/types.ts @@ -1,4 +1,4 @@ -import { IClientSystem } from '@user/client-system'; +import { IClientBase } from '@user/client-base'; import { ICoreStateConfig, IDataPlugin, @@ -77,7 +77,7 @@ export interface IClientCoreConfig extends ICoreStateConfig { readonly clientPlugins: IClientPluginDefine[]; } -export interface IClientCore extends IClientSystem { +export interface IClientCore extends IClientBase { /** * 根据 id 获取已加装的渲染端插件 * @param id 插件的标识符 diff --git a/packages-user/client-system/package.json b/packages-user/client-system/package.json deleted file mode 100644 index d2258bf..0000000 --- a/packages-user/client-system/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "@user/client-system", - "dependencies": { - "@user/client-base": "workspace:*" - } -} diff --git a/packages-user/client-system/src/index.ts b/packages-user/client-system/src/index.ts deleted file mode 100644 index fcb073f..0000000 --- a/packages-user/client-system/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './types'; diff --git a/packages-user/client-system/src/types.ts b/packages-user/client-system/src/types.ts deleted file mode 100644 index ac1297e..0000000 --- a/packages-user/client-system/src/types.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IClientBase } from '@user/client-base'; - -export interface IClientSystem extends IClientBase {} - -export interface IClientSystemExtended { - /** 当前对象的渲染端系统层对象(Layer 5 对象) */ - readonly state: IClientSystem; -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 98705b6..770d274 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -440,9 +440,6 @@ importers: '@user/client-base': specifier: workspace:* version: link:../client-base - '@user/client-system': - specifier: workspace:* - version: link:../client-system '@user/data-base': specifier: workspace:* version: link:../data-base @@ -456,12 +453,6 @@ importers: specifier: workspace:* version: link:../data-system - packages-user/client-system: - dependencies: - '@user/client-base': - specifier: workspace:* - version: link:../client-base - packages-user/data-base: dependencies: '@motajs/common':