mirror of
https://github.com/motajs/template.git
synced 2026-11-09 11:44:30 +08:00
fix(01-10): restore tile defaults and stable event snapshots
- Rebuild raw tile event baselines on construction, set, load, and conversion. - Preserve coordinate-owned point events through dynamic movement and copy save Maps.
This commit is contained in:
1 parent
a35e1e116d
commit
bcfa1f9467
4 files changed
+426
-35
No files matched your search
@@ -13,6 +13,21 @@ export class StaticTile
|
||||
{
|
||||
constructor(x: number, y: number, layer: IMapLayer) {
|
||||
super(x, y, layer);
|
||||
this.restoreDefaultEvents();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据当前图块原始数据恢复默认事件并建立干净基准
|
||||
*/
|
||||
private restoreDefaultEvents(): void {
|
||||
this.tileEvent().clear();
|
||||
const data = this.raw();
|
||||
if (data) {
|
||||
for (const [priority, id] of Object.entries(data.events)) {
|
||||
this.tileEvent().set(Number(priority), id);
|
||||
}
|
||||
}
|
||||
this.tileEvent().markPure();
|
||||
}
|
||||
|
||||
num(): number {
|
||||
@@ -25,6 +40,7 @@ export class StaticTile
|
||||
|
||||
set(num: number): void {
|
||||
this.layer.setBlock(num, this.locator.x, this.locator.y);
|
||||
this.restoreDefaultEvents();
|
||||
}
|
||||
|
||||
toDynamic(): IDynamicTile {
|
||||
@@ -32,28 +48,28 @@ export class StaticTile
|
||||
}
|
||||
|
||||
shouldSave(): boolean {
|
||||
return !!this.triggers;
|
||||
return this.tileEvent().dirty();
|
||||
}
|
||||
|
||||
saveState(): Readonly<IStaticBlockSave> {
|
||||
const save: IStaticBlockSave = {};
|
||||
|
||||
if (this.triggers) {
|
||||
save.triggers = this.triggers;
|
||||
let save: IStaticBlockSave;
|
||||
if (this.tileEvent().dirty()) {
|
||||
save = {
|
||||
events: new Map(this.tileEvent().get())
|
||||
};
|
||||
} else {
|
||||
save = {};
|
||||
}
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
loadState(save: Readonly<IStaticBlockSave>): void {
|
||||
if (save.triggers) {
|
||||
if (save.triggers.size === 0) {
|
||||
this.useEmptyTrigger();
|
||||
} else {
|
||||
save.triggers.forEach(v => this.addTrigger(v));
|
||||
this.restoreDefaultEvents();
|
||||
if (save.events) {
|
||||
this.tileEvent().clear();
|
||||
for (const [priority, id] of save.events) {
|
||||
this.tileEvent().set(priority, id);
|
||||
}
|
||||
} else {
|
||||
this.clearTrigger();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user