mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-11-27 22:03:00 +08:00
fix: 设置图块的周围自动元件检测
This commit is contained in:
parent
037746999d
commit
9d4bd381e5
@ -125,12 +125,13 @@ class TrackedAssetData
|
|||||||
}
|
}
|
||||||
const origin = this.originSourceMap.get(index);
|
const origin = this.originSourceMap.get(index);
|
||||||
const prev = this.sourceList.get(index);
|
const prev = this.sourceList.get(index);
|
||||||
if (origin) {
|
if (origin && origin !== source) {
|
||||||
this.skipRef.delete(origin);
|
this.skipRef.delete(origin);
|
||||||
}
|
}
|
||||||
if (prev) {
|
if (prev) {
|
||||||
this.skipRef.delete(prev);
|
this.skipRef.delete(prev);
|
||||||
}
|
}
|
||||||
|
this.originSourceMap.set(index, source);
|
||||||
if (source instanceof ImageBitmap) {
|
if (source instanceof ImageBitmap) {
|
||||||
if (this.skipRef.has(source)) return;
|
if (this.skipRef.has(source)) return;
|
||||||
this.sourceList.set(index, source);
|
this.sourceList.set(index, source);
|
||||||
@ -141,7 +142,6 @@ class TrackedAssetData
|
|||||||
this.skipRef.set(bitmap, index);
|
this.skipRef.set(bitmap, index);
|
||||||
// 要把源也加到映射中,因为这里的 bitmap 与外部源并不同引用
|
// 要把源也加到映射中,因为这里的 bitmap 与外部源并不同引用
|
||||||
this.skipRef.set(source, index);
|
this.skipRef.set(source, index);
|
||||||
this.originSourceMap.set(index, source);
|
|
||||||
}
|
}
|
||||||
this.dirty(index);
|
this.dirty(index);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,4 +5,4 @@ import { materials } from '@user/client-base';
|
|||||||
/** 主地图渲染器,用于渲染游戏画面 */
|
/** 主地图渲染器,用于渲染游戏画面 */
|
||||||
export const mainMapRenderer = new MapRenderer(materials, state.layer);
|
export const mainMapRenderer = new MapRenderer(materials, state.layer);
|
||||||
/** 副地图渲染器,用于渲染缩略图、浏览地图等 */
|
/** 副地图渲染器,用于渲染缩略图、浏览地图等 */
|
||||||
export const expandMapRenderer = new MapRenderer(materials, state.layer);
|
// export const expandMapRenderer = new MapRenderer(materials, state.layer);
|
||||||
|
|||||||
@ -158,7 +158,7 @@ export class BlockSplitter<T> implements IBlockSplitter<T> {
|
|||||||
const bx = Math.floor(x / this.blockWidth);
|
const bx = Math.floor(x / this.blockWidth);
|
||||||
const by = Math.floor(y / this.blockHeight);
|
const by = Math.floor(y / this.blockHeight);
|
||||||
if (!this.checkLocRange(bx, by)) return null;
|
if (!this.checkLocRange(bx, by)) return null;
|
||||||
const index = y * this.width + x;
|
const index = by * this.width + bx;
|
||||||
return this.blockMap.get(index) ?? null;
|
return this.blockMap.get(index) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1230,8 +1230,12 @@ export class MapRenderer
|
|||||||
|
|
||||||
const area = this.viewport.getRenderArea();
|
const area = this.viewport.getRenderArea();
|
||||||
area.blockList.forEach(v => {
|
area.blockList.forEach(v => {
|
||||||
|
if (v.data.dirty) {
|
||||||
this.vertex.updateBlockCache(v);
|
this.vertex.updateBlockCache(v);
|
||||||
|
}
|
||||||
|
if (v.data.renderDirty) {
|
||||||
v.data.render();
|
v.data.render();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (area.dirty.length > 0) {
|
if (area.dirty.length > 0) {
|
||||||
|
|||||||
@ -470,17 +470,19 @@ export class MapVertexGenerator
|
|||||||
if (!block) return;
|
if (!block) return;
|
||||||
const vertex = block.data.getLayerData(layer);
|
const vertex = block.data.getLayerData(layer);
|
||||||
if (!vertex) return;
|
if (!vertex) return;
|
||||||
|
const bx = mx - block.dataX;
|
||||||
|
const by = my - block.dataY;
|
||||||
const newIndex: BlockIndex = {
|
const newIndex: BlockIndex = {
|
||||||
layer,
|
layer,
|
||||||
mapX: mx,
|
mapX: mx,
|
||||||
mapY: my,
|
mapY: my,
|
||||||
mapIndex: my * this.mapWidth + mx,
|
mapIndex: my * this.mapWidth + mx,
|
||||||
blockX: block.x,
|
blockX: bx,
|
||||||
blockY: block.y,
|
blockY: by,
|
||||||
blockIndex: block.y * block.width + block.x
|
blockIndex: by * block.width + bx
|
||||||
};
|
};
|
||||||
const tile = this.renderer.manager.getTile(mapArray[index.mapIndex]);
|
const tile = this.renderer.manager.getTile(mapArray[newIndex.mapIndex]);
|
||||||
if (!tile) return;
|
if (!tile || tile.cls !== BlockCls.Autotile) return;
|
||||||
this.updateAutotile(
|
this.updateAutotile(
|
||||||
mapArray,
|
mapArray,
|
||||||
vertex,
|
vertex,
|
||||||
@ -590,6 +592,7 @@ export class MapVertexGenerator
|
|||||||
blockY: block.y,
|
blockY: block.y,
|
||||||
blockIndex: dIndex
|
blockIndex: dIndex
|
||||||
};
|
};
|
||||||
|
|
||||||
// 需要检查周围一圈的自动元件
|
// 需要检查周围一圈的自动元件
|
||||||
this.checkAutotileConnectionAround(layer, array, index, -1, -1);
|
this.checkAutotileConnectionAround(layer, array, index, -1, -1);
|
||||||
this.checkAutotileConnectionAround(layer, array, index, 0, -1);
|
this.checkAutotileConnectionAround(layer, array, index, 0, -1);
|
||||||
@ -669,7 +672,14 @@ export class MapVertexGenerator
|
|||||||
this.checkUpdateCallPerformance('updateBlockList');
|
this.checkUpdateCallPerformance('updateBlockList');
|
||||||
}
|
}
|
||||||
this.checkRebuild();
|
this.checkRebuild();
|
||||||
if (blocks.length > 50) {
|
|
||||||
|
if (blocks.length <= 50) {
|
||||||
|
blocks.forEach(({ block: num, x, y }) => {
|
||||||
|
this.updateBlockVertex(layer, num, x, y);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 对于超出50个的更新操作使用懒更新
|
// 对于超出50个的更新操作使用懒更新
|
||||||
blocks.forEach(v => {
|
blocks.forEach(v => {
|
||||||
const block = this.block.getBlockByDataLoc(v.x, v.y);
|
const block = this.block.getBlockByDataLoc(v.x, v.y);
|
||||||
@ -756,11 +766,6 @@ export class MapVertexGenerator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
blocks.forEach(({ block: num, x, y }) => {
|
|
||||||
this.updateBlockVertex(layer, num, x, y);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBlockCache(block: Readonly<IBlockData<IMapVertexBlock>>): void {
|
updateBlockCache(block: Readonly<IBlockData<IMapVertexBlock>>): void {
|
||||||
@ -1036,6 +1041,9 @@ class MapVertexBlock implements IMapVertexBlock {
|
|||||||
this.dirty = false;
|
this.dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标记为需要更新渲染缓冲区
|
||||||
|
*/
|
||||||
markRenderDirty() {
|
markRenderDirty() {
|
||||||
this.renderDirty = true;
|
this.renderDirty = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -128,7 +128,7 @@ export class MapViewport implements IMapViewportController {
|
|||||||
return {
|
return {
|
||||||
render: renderArea,
|
render: renderArea,
|
||||||
dirty: updateArea,
|
dirty: updateArea,
|
||||||
blockList: blockList.filter(v => v.data.dirty)
|
blockList: blockList
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ export class CoreState implements ICoreState {
|
|||||||
|
|
||||||
loadState(data: IStateSaveData): void {
|
loadState(data: IStateSaveData): void {
|
||||||
this.hero.removeAllFollowers();
|
this.hero.removeAllFollowers();
|
||||||
data.followers.forEach(v => {
|
data?.followers.forEach(v => {
|
||||||
this.hero.addFollower(v.num, v.identifier);
|
this.hero.addFollower(v.num, v.identifier);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import {
|
|||||||
} from './types';
|
} from './types';
|
||||||
import { Hookable, HookController, logger } from '@motajs/common';
|
import { Hookable, HookController, logger } from '@motajs/common';
|
||||||
|
|
||||||
|
// todo: 提供 core.setBlock 等方法的替代方法,同时添加 setBlockList,以及前景背景的接口
|
||||||
|
|
||||||
export class MapLayer
|
export class MapLayer
|
||||||
extends Hookable<IMapLayerHooks, IMapLayerHookController>
|
extends Hookable<IMapLayerHooks, IMapLayerHookController>
|
||||||
implements IMapLayer
|
implements IMapLayer
|
||||||
|
|||||||
@ -140,6 +140,7 @@ export class TextureMaxRectsStreamComposer
|
|||||||
|
|
||||||
private nextCanvas() {
|
private nextCanvas() {
|
||||||
this.nowCanvas = document.createElement('canvas');
|
this.nowCanvas = document.createElement('canvas');
|
||||||
|
this.nowCanvas.id = `${Math.random()}`;
|
||||||
this.nowCtx = this.nowCanvas.getContext('2d')!;
|
this.nowCtx = this.nowCanvas.getContext('2d')!;
|
||||||
this.nowCanvas.width = this.maxWidth;
|
this.nowCanvas.width = this.maxWidth;
|
||||||
this.nowCanvas.height = this.maxHeight;
|
this.nowCanvas.height = this.maxHeight;
|
||||||
|
|||||||
@ -3138,6 +3138,11 @@ maps.prototype.showBlock = function (x, y, floorId) {
|
|||||||
block?.id ?? 0,
|
block?.id ?? 0,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
if (floorId === core.status.floorId) {
|
||||||
|
const { layer } = Mota.require('@user/data-state').state;
|
||||||
|
const event = layer.getLayerByAlias('event');
|
||||||
|
event.setBlock(block.id, x, y);
|
||||||
|
}
|
||||||
// 在本层,添加动画
|
// 在本层,添加动画
|
||||||
if (floorId == core.status.floorId) {
|
if (floorId == core.status.floorId) {
|
||||||
if (block.event.cls == 'autotile') {
|
if (block.event.cls == 'autotile') {
|
||||||
@ -3170,6 +3175,11 @@ maps.prototype.hideBlock = function (x, y, floorId) {
|
|||||||
0,
|
0,
|
||||||
block?.id ?? 0
|
block?.id ?? 0
|
||||||
);
|
);
|
||||||
|
if (floorId === core.status.floorId) {
|
||||||
|
const { layer } = Mota.require('@user/data-state').state;
|
||||||
|
const event = layer.getLayerByAlias('event');
|
||||||
|
event.setBlock(0, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
// 删除动画,清除地图
|
// 删除动画,清除地图
|
||||||
this._removeBlockFromMap(floorId, block);
|
this._removeBlockFromMap(floorId, block);
|
||||||
@ -3193,6 +3203,11 @@ maps.prototype.hideBlockByIndex = function (index, floorId) {
|
|||||||
0,
|
0,
|
||||||
block?.id ?? 0
|
block?.id ?? 0
|
||||||
);
|
);
|
||||||
|
if (floorId === core.status.floorId) {
|
||||||
|
const { layer } = Mota.require('@user/data-state').state;
|
||||||
|
const event = layer.getLayerByAlias('event');
|
||||||
|
event.setBlock(0, x, y);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
////// 一次性隐藏多个block //////
|
////// 一次性隐藏多个block //////
|
||||||
@ -3265,6 +3280,11 @@ maps.prototype.removeBlockByIndex = function (index, floorId) {
|
|||||||
0,
|
0,
|
||||||
block?.id ?? 0
|
block?.id ?? 0
|
||||||
);
|
);
|
||||||
|
if (floorId === core.status.floorId) {
|
||||||
|
const { layer } = Mota.require('@user/data-state').state;
|
||||||
|
const event = layer.getLayerByAlias('event');
|
||||||
|
event.setBlock(0, x, y);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
////// 一次性删除多个block //////
|
////// 一次性删除多个block //////
|
||||||
@ -3419,6 +3439,11 @@ maps.prototype.setBlock = function (number, x, y, floorId, noredraw) {
|
|||||||
number,
|
number,
|
||||||
originBlock?.id ?? 0
|
originBlock?.id ?? 0
|
||||||
);
|
);
|
||||||
|
if (floorId === core.status.floorId) {
|
||||||
|
const { layer } = Mota.require('@user/data-state').state;
|
||||||
|
const event = layer.getLayerByAlias('event');
|
||||||
|
event.setBlock(number, x, y);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
maps.prototype.animateSetBlock = function (
|
maps.prototype.animateSetBlock = function (
|
||||||
@ -3620,6 +3645,11 @@ maps.prototype.replaceBlock = function (fromNumber, toNumber, floorId) {
|
|||||||
fromNumber,
|
fromNumber,
|
||||||
toNumber
|
toNumber
|
||||||
);
|
);
|
||||||
|
if (floorId === core.status.floorId) {
|
||||||
|
const { layer } = Mota.require('@user/data-state').state;
|
||||||
|
const event = layer.getLayerByAlias('event');
|
||||||
|
event.setBlock(toNumber, x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
if (floorId == core.status.floorId) core.redrawMap();
|
if (floorId == core.status.floorId) core.redrawMap();
|
||||||
@ -3669,6 +3699,11 @@ maps.prototype.setBgFgBlock = function (name, number, x, y, floorId) {
|
|||||||
y,
|
y,
|
||||||
floorId
|
floorId
|
||||||
);
|
);
|
||||||
|
if (floorId === core.status.floorId) {
|
||||||
|
const { layer } = Mota.require('@user/data-state').state;
|
||||||
|
const mapLayer = layer.getLayerByAlias(name);
|
||||||
|
mapLayer.setBlock(block.id, x, y);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
////// 重置地图 //////
|
////// 重置地图 //////
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user