Skip to content

Commit dfa1da9

Browse files
committed
feat(editor): add Load Template button and rename Reset Slot to Clear Map
- New 'Load Template' button in the map editor topbar: fetches /api/map/template and loads the shipped template into the current slot (terrain, decorations, paths, NPCs, buildings). Marks dirty so the user still confirms via Save. - 'Reset Slot' renamed to 'Clear Map' — clearer that it wipes content rather than reverting to a template. - Confirm dialogs reworded to state that Save is still required.
1 parent 3d29518 commit dfa1da9

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

client/src/editor/game/scenes/EditorScene.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,9 @@ export class EditorScene extends Phaser.Scene {
12731273
case 'reset-all':
12741274
await this.loadDefault();
12751275
break;
1276+
case 'load-template':
1277+
await this.loadTemplate();
1278+
break;
12761279
}
12771280
}
12781281

@@ -1434,6 +1437,28 @@ export class EditorScene extends Phaser.Scene {
14341437
}
14351438
}
14361439

1440+
private async loadTemplate(): Promise<void> {
1441+
try {
1442+
const res = await fetch(`${SERVER_URL}/api/map/template`);
1443+
if (res.status === 204) throw new Error('No template available');
1444+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
1445+
this.mapConfig = (await res.json()) as MapConfig;
1446+
if (!this.mapConfig.npcs) this.mapConfig.npcs = [];
1447+
if (!this.mapConfig.settings) this.mapConfig.settings = { heroScale: 0.50 };
1448+
this.renderAll();
1449+
this.drawGrid();
1450+
this.selection = null;
1451+
editorBridge.emit('ed:selected', null);
1452+
this.selectionOverlay.clear();
1453+
this.markDirty();
1454+
editorBridge.emit('ed:settings:loaded', this.mapConfig.settings);
1455+
void this.refreshSlotInfo();
1456+
} catch (err) {
1457+
const msg = err instanceof Error ? err.message : String(err);
1458+
editorBridge.emit('ed:save:error', msg);
1459+
}
1460+
}
1461+
14371462
private async resetBuildings(): Promise<void> {
14381463
try {
14391464
const res = await fetch(`${SERVER_URL}/api/map/default`);

client/src/editor/panels/EditorTopBar.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ export function EditorTopBar() {
3737
editorBridge.emit('ed:action', 'set-active');
3838
};
3939

40-
const onResetSlot = () => {
41-
if (confirm('Reset this slot to defaults? This cannot be undone.')) {
40+
const onClearMap = () => {
41+
if (confirm('Clear the map? Terrain, decorations, paths, and NPCs will be wiped. You will still need to Save to persist.')) {
4242
editorBridge.emit('ed:action', 'reset-all');
4343
}
4444
};
4545

46+
const onLoadTemplate = () => {
47+
if (confirm('Load the shipped template into this slot? Unsaved changes will be lost. You will still need to Save to persist.')) {
48+
editorBridge.emit('ed:action', 'load-template');
49+
}
50+
};
51+
4652
const onSlotClick = (info: SlotInfo) => {
4753
editorStore.setCurrentSlot(info.slot);
4854
editorBridge.emit('ed:slot:load', info.slot);
@@ -90,7 +96,14 @@ export function EditorTopBar() {
9096
>
9197
Set Active {currentSlot === activeSlot ? '\u2605' : ''}
9298
</button>
93-
<button className="editor-btn danger" onClick={onResetSlot}>Reset Slot</button>
99+
<button
100+
className="editor-btn"
101+
onClick={onLoadTemplate}
102+
title="Load the shipped template map into this slot (replaces current content)"
103+
>
104+
Load Template
105+
</button>
106+
<button className="editor-btn danger" onClick={onClearMap}>Clear Map</button>
94107
<a className="editor-btn" href="/" style={{ textDecoration: 'none' }}>Back to Village</a>
95108
</div>
96109
</div>

client/src/editor/types/editor-events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type EditorAction =
2020
| 'save'
2121
| 'load-current'
2222
| 'load-default'
23+
| 'load-template'
2324
| 'clear-terrain'
2425
| 'clear-decorations'
2526
| 'clear-paths'

0 commit comments

Comments
 (0)