mirror of
https://github.com/motajs/template.git
synced 2026-11-09 19:54: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
@@ -42,6 +42,21 @@ export class DynamicTile
|
||||
} else {
|
||||
this.tileRaw = data;
|
||||
}
|
||||
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 {
|
||||
@@ -61,6 +76,7 @@ export class DynamicTile
|
||||
} else {
|
||||
this.tileRaw = data;
|
||||
}
|
||||
this.restoreDefaultEvents();
|
||||
}
|
||||
|
||||
setPos(x: number, y: number): void {
|
||||
@@ -98,26 +114,27 @@ export class DynamicTile
|
||||
}
|
||||
|
||||
saveState(): Readonly<IDynamicBlockSave> {
|
||||
const save: IDynamicBlockSave = {
|
||||
num: this.num()
|
||||
};
|
||||
|
||||
if (this.triggers) {
|
||||
save.triggers = this.triggers;
|
||||
let save: IDynamicBlockSave;
|
||||
if (this.tileEvent().dirty()) {
|
||||
save = {
|
||||
num: this.num(),
|
||||
events: new Map(this.tileEvent().get())
|
||||
};
|
||||
} else {
|
||||
save = {
|
||||
num: this.num()
|
||||
};
|
||||
}
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
loadState(save: Readonly<IDynamicBlockSave>): 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