mirror of
https://github.com/motajs/template.git
synced 2026-11-21 12:14:31 +08:00
refactor(04-07): adapt material interfaces (drop big-image, inject state)
- delete MaterialManager big-image implementation (IBigImageReturn import, bigImageStore/bigImageData/bigImageId fields, 5 methods, setDefaultFrame coupling) - change 7 consumers getIfBigImage -> getTile (door x2, hero x3, renderer, vertex); drop getOffsetPool big-image offset loop - delete cache.ts legacy big-image path (RenderableDataBase.bigImage, literals, destructuring, enemys special-case, big-image branch, unused enemys decl) - inject state via constructor into MaterialManager/AutotileProcessor/AssetBuilder/TrackedAssetData (from ClientCore; renderer uses manager.state) - add MaterialManager.textures (dedicated TextureStore) - declare @user/data-state in client-base/package.json (lockfile not synced)
This commit is contained in:
1 parent
786c00c499
commit
78873d0a27
10 files changed
+31
-130
No files matched your search
@@ -32,8 +32,6 @@ interface RenderableDataBase {
|
||||
frame: number;
|
||||
/** 对应图块属性的动画帧数,-1表示没有设定,0表示第一帧 */
|
||||
animate: number;
|
||||
/** 是否是大怪物 */
|
||||
bigImage: boolean;
|
||||
render: [x: number, y: number, width: number, height: number][];
|
||||
}
|
||||
|
||||
@@ -45,7 +43,6 @@ export interface RenderableData extends RenderableDataBase {
|
||||
export interface AutotileRenderable extends RenderableDataBase {
|
||||
image: Record<string, SizedCanvasImageSource>;
|
||||
autotile: true;
|
||||
bigImage: false;
|
||||
}
|
||||
|
||||
class TextureCache {
|
||||
@@ -124,7 +121,6 @@ class TextureCache {
|
||||
num: number
|
||||
): RenderableData | AutotileRenderable | null {
|
||||
const map = maps_90f36752_8815_4be8_b32b_d7fad1d0542e;
|
||||
const enemys = enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80;
|
||||
const icons = icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1;
|
||||
|
||||
/** 特判空图块与空气墙 */
|
||||
@@ -140,8 +136,7 @@ class TextureCache {
|
||||
frame: 1,
|
||||
render: [[x * 32, y * 32, 32, 32]],
|
||||
animate: 0,
|
||||
autotile: false,
|
||||
bigImage: false
|
||||
autotile: false
|
||||
};
|
||||
this.renderable.set(num, data);
|
||||
return data;
|
||||
@@ -150,48 +145,7 @@ class TextureCache {
|
||||
const data = map[num as Exclude<AllNumbers, 0>];
|
||||
// 地狱般的分支if
|
||||
if (data) {
|
||||
let { faceIds, bigImage } = data;
|
||||
const { cls, id, animate } = data;
|
||||
if (cls === 'enemys' || cls === 'enemy48') {
|
||||
// 怪物需要特殊处理,因为它的大怪物信息不在 maps 里面
|
||||
({ bigImage, faceIds } = enemys[id as EnemyIds]);
|
||||
}
|
||||
if (bigImage) {
|
||||
const image = core.material.images.images[bigImage];
|
||||
if (!image) {
|
||||
logger.warn(10, id);
|
||||
return null;
|
||||
}
|
||||
let line = 0;
|
||||
if (faceIds) {
|
||||
const arr = ['down', 'left', 'right', 'up'];
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
if (faceIds[arr[i] as Dir] === id) {
|
||||
line = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const totalLines = image.width / image.height >= 2 ? 1 : 4;
|
||||
const w = Math.round(image.width / 4);
|
||||
const h = Math.round(image.height / totalLines);
|
||||
const y = h * line;
|
||||
const data: RenderableData = {
|
||||
image,
|
||||
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,
|
||||
bigImage: true
|
||||
};
|
||||
this.renderable.set(num, data);
|
||||
return data;
|
||||
}
|
||||
// enemy48和npc48都应该视为大怪物
|
||||
if (cls === 'enemy48' || cls === 'npc48') {
|
||||
const img = core.material.images[cls];
|
||||
@@ -211,8 +165,7 @@ class TextureCache {
|
||||
[w * 3, y, w, h]
|
||||
],
|
||||
animate: (animate ?? 0) - 1,
|
||||
autotile: false,
|
||||
bigImage: true
|
||||
autotile: false
|
||||
};
|
||||
this.renderable.set(num, data);
|
||||
return data;
|
||||
@@ -240,7 +193,6 @@ class TextureCache {
|
||||
frame: auto.frame,
|
||||
render,
|
||||
autotile: true,
|
||||
bigImage: false,
|
||||
animate: (animate ?? 0) - 1
|
||||
};
|
||||
this.renderable.set(num, data);
|
||||
@@ -273,7 +225,6 @@ class TextureCache {
|
||||
frame: frame,
|
||||
render,
|
||||
autotile: false,
|
||||
bigImage: false,
|
||||
animate: (animate ?? 0) - 1
|
||||
};
|
||||
this.renderable.set(num, data);
|
||||
|
||||
@@ -33,7 +33,7 @@ export class MapDoorRenderer implements IMapDoorRenderer {
|
||||
const array = this.layer.getMapRef().array;
|
||||
const index = y * this.layer.width + x;
|
||||
const num = array[index];
|
||||
const data = this.renderer.manager.getIfBigImage(num);
|
||||
const data = this.renderer.manager.getTile(num);
|
||||
if (!data) return;
|
||||
const frames = data.frames;
|
||||
for (let i = 0; i < frames; i++) {
|
||||
@@ -43,7 +43,7 @@ export class MapDoorRenderer implements IMapDoorRenderer {
|
||||
}
|
||||
|
||||
async closeDoor(num: number, x: number, y: number): Promise<void> {
|
||||
const data = this.renderer.manager.getIfBigImage(num);
|
||||
const data = this.renderer.manager.getTile(num);
|
||||
if (!data) return;
|
||||
const moving = this.renderer.addMovingBlock(this.layer, num, x, y);
|
||||
const frames = data.frames;
|
||||
|
||||
@@ -236,7 +236,7 @@ export class MapHeroRenderer implements IMapHeroRenderer {
|
||||
const tx = block.x + dx;
|
||||
const ty = block.y + dy;
|
||||
const nextTile = state.roleFace.getFaceOf(block.tile, direction);
|
||||
const nextTex = this.renderer.manager.getIfBigImage(
|
||||
const nextTex = this.renderer.manager.getTile(
|
||||
nextTile?.identifier ?? block.tile
|
||||
);
|
||||
entity.animateInterval = time;
|
||||
@@ -361,7 +361,7 @@ export class MapHeroRenderer implements IMapHeroRenderer {
|
||||
const nowFace =
|
||||
degraded === FaceDirection.Unknown ? FaceDirection.Down : degraded;
|
||||
const faced = state.roleFace.getFaceOf(image, nowFace);
|
||||
const tex = this.renderer.manager.getIfBigImage(faced?.face ?? image);
|
||||
const tex = this.renderer.manager.getTile(faced?.face ?? image);
|
||||
if (!tex) {
|
||||
logger.warn(91, image.toString());
|
||||
return;
|
||||
@@ -425,9 +425,7 @@ export class MapHeroRenderer implements IMapHeroRenderer {
|
||||
last.nextDirection
|
||||
);
|
||||
if (!nextFace) continue;
|
||||
const tile = this.renderer.manager.getIfBigImage(
|
||||
nextFace.identifier
|
||||
);
|
||||
const tile = this.renderer.manager.getTile(nextFace.identifier);
|
||||
if (!tile) continue;
|
||||
moving.block.setTexture(tile);
|
||||
moving.direction = last.nextDirection;
|
||||
|
||||
@@ -231,7 +231,7 @@ export class MapRenderer
|
||||
);
|
||||
this.contextData = data;
|
||||
this.vertex = new MapVertexGenerator(this, data);
|
||||
this.autotile = new AutotileProcessor(manager);
|
||||
this.autotile = new AutotileProcessor(manager, manager.state);
|
||||
this.tick = this.tick.bind(this);
|
||||
this.viewport = new MapViewport(this);
|
||||
this.tileAnimater = new TextureColumnAnimater();
|
||||
@@ -648,13 +648,6 @@ export class MapRenderer
|
||||
|
||||
private getOffsetPool(): number[] {
|
||||
const pool = new Set([32]);
|
||||
// 其他的都是 bigImage 了,直接遍历获取
|
||||
for (const identifier of this.manager.bigImageStore.keys()) {
|
||||
const data = this.manager.getBigImage(identifier);
|
||||
if (!data) continue;
|
||||
const offset = data.texture.width / data.frames;
|
||||
pool.add(offset);
|
||||
}
|
||||
// 还有勇士图片
|
||||
for (const tex of this.manager.imageStore.values()) {
|
||||
if (!this.manager.assetContainsTexture(tex)) continue;
|
||||
@@ -1247,7 +1240,7 @@ export class MapRenderer
|
||||
tile: number
|
||||
): Promise<void> {
|
||||
// 图块背景
|
||||
const tex = this.manager.getIfBigImage(tile);
|
||||
const tex = this.manager.getTile(tile);
|
||||
if (!tex) {
|
||||
// 图块不存在
|
||||
logger.error(35);
|
||||
|
||||
@@ -543,7 +543,7 @@ export class MapVertexGenerator
|
||||
) {
|
||||
// 此处仅更新当前图块,不更新周围一圈的自动元件
|
||||
// 周围一圈的自动元件需要在更新某个图块或者某个区域时处理,不在这里处理
|
||||
const tile = this.renderer.manager.getIfBigImage(num);
|
||||
const tile = this.renderer.manager.getTile(num);
|
||||
|
||||
if (!tile) {
|
||||
// 不存在可渲染对象,认为是空图块
|
||||
|
||||
Reference in new issue
Block a user