Improve editor changelogs, delete confirms, and stop false fence dirtying.
Drop neighbor-connect recompute on chunk load, log quest/dialogue edits with usernames, and add a global changelog view.
@@ -58,6 +58,7 @@
58
58
<button id="open-quests" type="button">Quests</button>
59
59
<button id="open-dialogues" type="button">Dialogues</button>
60
60
<button id="open-gifts" type="button">Gifts</button>
61
<button id="open-global-changelog" type="button">Global changelog</button>
61
62
<p class="hint">The red border is the chunk you are editing. Paint only inside the border. Hover shows tile config tooltips. Right-click a spawner to edit or remove it. Spawners are editor-only markers (invisible and non-blocking in play). Mouse wheel zooms; Shift+wheel cycles visual states (seasonal outdoor tiles cycle spring/summer/autumn/winter and update Season preview).</p>
62
63
</aside>
63
64
<section id="side-panels">
@@ -98,44 +99,65 @@
98
99
</div>
99
100
<div id="quests-backdrop" hidden></div>
100
101
<div id="quests-modal" hidden>
101
<header>
102
<h2>Quests</h2>
103
<button id="quests-close" type="button">Close</button>
104
</header>
105
<div class="content-editor-layout">
106
<aside class="content-editor-list-pane">
107
<button id="quests-new" type="button">New</button>
108
<div id="quests-list" class="content-editor-list"></div>
109
</aside>
110
<div id="quests-editor" class="content-editor-detail"></div>
102
<div id="quests-main">
103
<header>
104
<h2>Quests</h2>
105
<button id="quests-close" type="button">Close</button>
106
</header>
107
<div class="content-editor-layout">
108
<aside class="content-editor-list-pane">
109
<button id="quests-new" type="button">New</button>
110
<div id="quests-list" class="content-editor-list"></div>
111
</aside>
112
<div id="quests-editor" class="content-editor-detail"></div>
113
</div>
114
<footer>
115
<button id="quests-delete" type="button" disabled>Delete</button>
116
<button id="quests-save" type="button" disabled>Save</button>
117
</footer>
111
118
</div>
112
<footer>
113
<button id="quests-delete" type="button" disabled>Delete</button>
114
<button id="quests-save" type="button" disabled>Save</button>
115
</footer>
119
<aside id="quests-log-wrap" class="content-editor-log-wrap">
120
<h2>Quest log</h2>
121
<div id="quests-log"></div>
122
</aside>
116
123
</div>
117
124
118
125
<div id="dialogues-backdrop" hidden></div>
119
126
<div id="dialogues-modal" hidden>
120
<header>
121
<div class="dialogues-header-title">
122
<h2>Dialogues</h2>
123
<button id="dialogues-tokens-help" type="button" title="Text replacements" aria-label="Text replacements help">?</button>
127
<div id="dialogues-main">
128
<header>
129
<div class="dialogues-header-title">
130
<h2>Dialogues</h2>
131
<button id="dialogues-tokens-help" type="button" title="Text replacements" aria-label="Text replacements help">?</button>
132
</div>
133
<button id="dialogues-close" type="button">Close</button>
134
</header>
135
<div class="content-editor-layout">
136
<aside class="content-editor-list-pane">
137
<button id="dialogues-new" type="button">New</button>
138
<div id="dialogues-list" class="content-editor-list"></div>
139
</aside>
140
<div id="dialogues-editor" class="content-editor-detail"></div>
124
141
</div>
125
<button id="dialogues-close" type="button">Close</button>
126
</header>
127
<div class="content-editor-layout">
128
<aside class="content-editor-list-pane">
129
<button id="dialogues-new" type="button">New</button>
130
<div id="dialogues-list" class="content-editor-list"></div>
131
</aside>
132
<div id="dialogues-editor" class="content-editor-detail"></div>
142
<footer>
143
<button id="dialogues-delete" type="button" disabled>Delete</button>
144
<button id="dialogues-simulate" type="button" disabled>Simulate</button>
145
<button id="dialogues-save" type="button" disabled>Save</button>
146
</footer>
133
147
</div>
134
<footer>
135
<button id="dialogues-delete" type="button" disabled>Delete</button>
136
<button id="dialogues-simulate" type="button" disabled>Simulate</button>
137
<button id="dialogues-save" type="button" disabled>Save</button>
138
</footer>
148
<aside id="dialogues-log-wrap" class="content-editor-log-wrap">
149
<h2>Dialogue log</h2>
150
<div id="dialogues-log"></div>
151
</aside>
152
</div>
153
154
<div id="global-changelog-backdrop" hidden></div>
155
<div id="global-changelog-modal" hidden>
156
<header>
157
<h2>Global changelog</h2>
158
<button id="global-changelog-close" type="button">Close</button>
159
</header>
160
<div id="global-changelog" class="global-changelog-body"></div>
139
161
</div>
140
162
141
163
<div id="dialogue-tokens-backdrop" hidden></div>
@@ -58,6 +58,7 @@58
<button id="open-quests" type="button">Quests</button>58
<button id="open-quests" type="button">Quests</button>59
<button id="open-dialogues" type="button">Dialogues</button>59
<button id="open-dialogues" type="button">Dialogues</button>60
<button id="open-gifts" type="button">Gifts</button>60
<button id="open-gifts" type="button">Gifts</button>61
<button id="open-global-changelog" type="button">Global changelog</button>61
<p class="hint">The red border is the chunk you are editing. Paint only inside the border. Hover shows tile config tooltips. Right-click a spawner to edit or remove it. Spawners are editor-only markers (invisible and non-blocking in play). Mouse wheel zooms; Shift+wheel cycles visual states (seasonal outdoor tiles cycle spring/summer/autumn/winter and update Season preview).</p>62
<p class="hint">The red border is the chunk you are editing. Paint only inside the border. Hover shows tile config tooltips. Right-click a spawner to edit or remove it. Spawners are editor-only markers (invisible and non-blocking in play). Mouse wheel zooms; Shift+wheel cycles visual states (seasonal outdoor tiles cycle spring/summer/autumn/winter and update Season preview).</p>62
</aside>63
</aside>63
<section id="side-panels">64
<section id="side-panels">@@ -98,44 +99,65 @@98
</div>99
</div>99
<div id="quests-backdrop" hidden></div>100
<div id="quests-backdrop" hidden></div>100
<div id="quests-modal" hidden>101
<div id="quests-modal" hidden>101
<header>102
<div id="quests-main">102
<h2>Quests</h2>103
<header>103
<button id="quests-close" type="button">Close</button>104
<h2>Quests</h2>104
</header>105
<button id="quests-close" type="button">Close</button>105
<div class="content-editor-layout">106
</header>106
<aside class="content-editor-list-pane">107
<div class="content-editor-layout">107
<button id="quests-new" type="button">New</button>108
<aside class="content-editor-list-pane">108
<div id="quests-list" class="content-editor-list"></div>109
<button id="quests-new" type="button">New</button>109
</aside>110
<div id="quests-list" class="content-editor-list"></div>110
<div id="quests-editor" class="content-editor-detail"></div>111
</aside>112
<div id="quests-editor" class="content-editor-detail"></div>113
</div>114
<footer>115
<button id="quests-delete" type="button" disabled>Delete</button>116
<button id="quests-save" type="button" disabled>Save</button>117
</footer>111
</div>118
</div>112
<footer>119
<aside id="quests-log-wrap" class="content-editor-log-wrap">113
<button id="quests-delete" type="button" disabled>Delete</button>120
<h2>Quest log</h2>114
<button id="quests-save" type="button" disabled>Save</button>121
<div id="quests-log"></div>115
</footer>122
</aside>116
</div>123
</div>117
124
118
<div id="dialogues-backdrop" hidden></div>125
<div id="dialogues-backdrop" hidden></div>119
<div id="dialogues-modal" hidden>126
<div id="dialogues-modal" hidden>120
<header>127
<div id="dialogues-main">121
<div class="dialogues-header-title">128
<header>122
<h2>Dialogues</h2>129
<div class="dialogues-header-title">123
<button id="dialogues-tokens-help" type="button" title="Text replacements" aria-label="Text replacements help">?</button>130
<h2>Dialogues</h2>131
<button id="dialogues-tokens-help" type="button" title="Text replacements" aria-label="Text replacements help">?</button>132
</div>133
<button id="dialogues-close" type="button">Close</button>134
</header>135
<div class="content-editor-layout">136
<aside class="content-editor-list-pane">137
<button id="dialogues-new" type="button">New</button>138
<div id="dialogues-list" class="content-editor-list"></div>139
</aside>140
<div id="dialogues-editor" class="content-editor-detail"></div>124
</div>141
</div>125
<button id="dialogues-close" type="button">Close</button>142
<footer>126
</header>143
<button id="dialogues-delete" type="button" disabled>Delete</button>127
<div class="content-editor-layout">144
<button id="dialogues-simulate" type="button" disabled>Simulate</button>128
<aside class="content-editor-list-pane">145
<button id="dialogues-save" type="button" disabled>Save</button>129
<button id="dialogues-new" type="button">New</button>146
</footer>130
<div id="dialogues-list" class="content-editor-list"></div>131
</aside>132
<div id="dialogues-editor" class="content-editor-detail"></div>133
</div>147
</div>134
<footer>148
<aside id="dialogues-log-wrap" class="content-editor-log-wrap">135
<button id="dialogues-delete" type="button" disabled>Delete</button>149
<h2>Dialogue log</h2>136
<button id="dialogues-simulate" type="button" disabled>Simulate</button>150
<div id="dialogues-log"></div>137
<button id="dialogues-save" type="button" disabled>Save</button>151
</aside>138
</footer>152
</div>153
154
<div id="global-changelog-backdrop" hidden></div>155
<div id="global-changelog-modal" hidden>156
<header>157
<h2>Global changelog</h2>158
<button id="global-changelog-close" type="button">Close</button>159
</header>160
<div id="global-changelog" class="global-changelog-body"></div>139
</div>161
</div>140
162
141
<div id="dialogue-tokens-backdrop" hidden></div>163
<div id="dialogue-tokens-backdrop" hidden></div>@@ -24,6 +24,7 @@ export function initDialoguesModal ({
24
24
const modal = document.getElementById("dialogues-modal");
25
25
const listEl = document.getElementById("dialogues-list");
26
26
const editorEl = document.getElementById("dialogues-editor");
27
const logEl = document.getElementById("dialogues-log");
27
28
const saveBtn = document.getElementById("dialogues-save");
28
29
const deleteBtn = document.getElementById("dialogues-delete");
29
30
const simulateBtn = document.getElementById("dialogues-simulate");
@@ -42,6 +43,8 @@ export function initDialoguesModal ({
42
43
/** @type {any|null} */
43
44
let draft = null;
44
45
let selectedId = null;
46
/** @type {object[]} */
47
let changelog = [];
45
48
46
49
const simulate = initDialogueSimulate({
47
50
getTree: () => (draft ? normalizeDialogueTree(draft) : null),
@@ -310,6 +313,8 @@ export function initDialoguesModal ({
310
313
box.className = "content-editor-section";
311
314
box.append(sectionHeader(`Step ${stepIndex + 1}`, null, () =>
312
315
{
316
if (!window.confirm(`Delete dialogue step "${step.stepId || stepIndex + 1}"?`))
317
{ return; }
313
318
draft.steps.splice(stepIndex, 1);
314
319
if (draft.steps.length === 0)
315
320
{
@@ -357,6 +362,8 @@ export function initDialoguesModal ({
357
362
text.addEventListener("input", () => { line.text = text.value; });
358
363
row.append(speaker, text, removeButton(() =>
359
364
{
365
if (!window.confirm("Delete this dialogue line?"))
366
{ return; }
360
367
step.lines.splice(lineIndex, 1);
361
368
if (step.lines.length === 0)
362
369
{ step.lines.push({ speaker: "npc", text: "…", effects: [] }); }
@@ -699,6 +706,42 @@ export function initDialoguesModal ({
699
706
{
700
707
renderList();
701
708
renderEditor();
709
renderLog();
710
}
711
712
function renderLog ()
713
{
714
if (!logEl)
715
{ return; }
716
logEl.innerHTML = "";
717
const scopeId = draft?.dialogueId ?? selectedId;
718
const entries = scopeId
719
? changelog.filter((entry) => entry.dialogueId === scopeId)
720
: changelog;
721
if (!entries.length)
722
{
723
logEl.innerHTML = scopeId
724
? "<p class=\"hint\">No edits logged for this dialogue yet.</p>"
725
: "<p class=\"hint\">No dialogue edits logged yet.</p>";
726
return;
727
}
728
for (const entry of entries)
729
{
730
const item = document.createElement("article");
731
const who = entry.editorDisplayName || entry.editor_admin_id;
732
const scope = scopeId ? "" : ` · ${entry.dialogueId}`;
733
item.innerHTML = `<header>${who}${scope} · ${new Date(entry.edited_at).toLocaleString()}</header>`;
734
const list = document.createElement("ul");
735
for (const bullet of entry.diffEntries ?? [])
736
{
737
const li = document.createElement("li");
738
li.textContent = bullet;
739
list.append(li);
740
}
741
item.append(list);
742
logEl.append(item);
743
}
744
logEl.scrollTop = logEl.scrollHeight;
702
745
}
703
746
704
747
document.getElementById("open-dialogues").addEventListener("click", () =>
@@ -771,6 +814,7 @@ export function initDialoguesModal ({
771
814
assignedSpawnerCount: d.assignedSpawnerCount ?? 0
772
815
};
773
816
});
817
changelog = message.changelog ?? [];
774
818
if (draft)
775
819
{
776
820
const still = dialogues.find((d) => d.dialogueId === draft.dialogueId);
@@ -24,6 +24,7 @@ export function initDialoguesModal ({24
const modal = document.getElementById("dialogues-modal");24
const modal = document.getElementById("dialogues-modal");25
const listEl = document.getElementById("dialogues-list");25
const listEl = document.getElementById("dialogues-list");26
const editorEl = document.getElementById("dialogues-editor");26
const editorEl = document.getElementById("dialogues-editor");27
const logEl = document.getElementById("dialogues-log");27
const saveBtn = document.getElementById("dialogues-save");28
const saveBtn = document.getElementById("dialogues-save");28
const deleteBtn = document.getElementById("dialogues-delete");29
const deleteBtn = document.getElementById("dialogues-delete");29
const simulateBtn = document.getElementById("dialogues-simulate");30
const simulateBtn = document.getElementById("dialogues-simulate");@@ -42,6 +43,8 @@ export function initDialoguesModal ({42
/** @type {any|null} */43
/** @type {any|null} */43
let draft = null;44
let draft = null;44
let selectedId = null;45
let selectedId = null;46
/** @type {object[]} */47
let changelog = [];45
48
46
const simulate = initDialogueSimulate({49
const simulate = initDialogueSimulate({47
getTree: () => (draft ? normalizeDialogueTree(draft) : null),50
getTree: () => (draft ? normalizeDialogueTree(draft) : null),@@ -310,6 +313,8 @@ export function initDialoguesModal ({310
box.className = "content-editor-section";313
box.className = "content-editor-section";311
box.append(sectionHeader(`Step ${stepIndex + 1}`, null, () =>314
box.append(sectionHeader(`Step ${stepIndex + 1}`, null, () =>312
{315
{316
if (!window.confirm(`Delete dialogue step "${step.stepId || stepIndex + 1}"?`))317
{ return; }313
draft.steps.splice(stepIndex, 1);318
draft.steps.splice(stepIndex, 1);314
if (draft.steps.length === 0)319
if (draft.steps.length === 0)315
{320
{@@ -357,6 +362,8 @@ export function initDialoguesModal ({357
text.addEventListener("input", () => { line.text = text.value; });362
text.addEventListener("input", () => { line.text = text.value; });358
row.append(speaker, text, removeButton(() =>363
row.append(speaker, text, removeButton(() =>359
{364
{365
if (!window.confirm("Delete this dialogue line?"))366
{ return; }360
step.lines.splice(lineIndex, 1);367
step.lines.splice(lineIndex, 1);361
if (step.lines.length === 0)368
if (step.lines.length === 0)362
{ step.lines.push({ speaker: "npc", text: "…", effects: [] }); }369
{ step.lines.push({ speaker: "npc", text: "…", effects: [] }); }@@ -699,6 +706,42 @@ export function initDialoguesModal ({699
{706
{700
renderList();707
renderList();701
renderEditor();708
renderEditor();709
renderLog();710
}711
712
function renderLog ()713
{714
if (!logEl)715
{ return; }716
logEl.innerHTML = "";717
const scopeId = draft?.dialogueId ?? selectedId;718
const entries = scopeId719
? changelog.filter((entry) => entry.dialogueId === scopeId)720
: changelog;721
if (!entries.length)722
{723
logEl.innerHTML = scopeId724
? "<p class=\"hint\">No edits logged for this dialogue yet.</p>"725
: "<p class=\"hint\">No dialogue edits logged yet.</p>";726
return;727
}728
for (const entry of entries)729
{730
const item = document.createElement("article");731
const who = entry.editorDisplayName || entry.editor_admin_id;732
const scope = scopeId ? "" : ` · ${entry.dialogueId}`;733
item.innerHTML = `<header>${who}${scope} · ${new Date(entry.edited_at).toLocaleString()}</header>`;734
const list = document.createElement("ul");735
for (const bullet of entry.diffEntries ?? [])736
{737
const li = document.createElement("li");738
li.textContent = bullet;739
list.append(li);740
}741
item.append(list);742
logEl.append(item);743
}744
logEl.scrollTop = logEl.scrollHeight;702
}745
}703
746
704
document.getElementById("open-dialogues").addEventListener("click", () =>747
document.getElementById("open-dialogues").addEventListener("click", () =>@@ -771,6 +814,7 @@ export function initDialoguesModal ({771
assignedSpawnerCount: d.assignedSpawnerCount ?? 0814
assignedSpawnerCount: d.assignedSpawnerCount ?? 0772
};815
};773
});816
});817
changelog = message.changelog ?? [];774
if (draft)818
if (draft)775
{819
{776
const still = dialogues.find((d) => d.dialogueId === draft.dialogueId);820
const still = dialogues.find((d) => d.dialogueId === draft.dialogueId);@@ -799,26 +799,6 @@ function refreshNeighborConnect (localX, localY, typeId)
799
799
}
800
800
}
801
801
802
/** Fix legacy/wrong connect states (e.g. old diagonal masks saved as nesw) from live neighbors. */
803
function recomputeAllNeighborConnectInDraft ()
804
{
805
if (!draft)
806
{ return; }
807
for (let localY = 0; localY < CHUNK_SIZE; localY++)
808
{
809
for (let localX = 0; localX < CHUNK_SIZE; localX++)
810
{
811
const block = draft.blocks[localY * CHUNK_SIZE + localX];
812
if (!block)
813
{ continue; }
814
const def = BLOCK_DEFINITIONS[block.typeId];
815
if (!definitionUsesNeighborConnect(def))
816
{ continue; }
817
refreshNeighborConnect(localX, localY, block.typeId);
818
}
819
}
820
}
821
822
802
function updateRevisionUI ()
823
803
{
824
804
const applyBtn = $("apply");
@@ -867,7 +847,7 @@ function showSelectedChunk (payload)
867
847
for (const entry of payload.changelog ?? [])
868
848
{
869
849
const item = document.createElement("article");
870
item.innerHTML = `<header>${entry.editor_admin_id} · ${new Date(entry.edited_at).toLocaleString()}</header>`;
850
item.innerHTML = `<header>${entry.editorDisplayName || entry.editor_admin_id} · ${new Date(entry.edited_at).toLocaleString()}</header>`;
871
851
const list = document.createElement("ul");
872
852
for (const bullet of entry.diffEntries)
873
853
{
@@ -881,7 +861,6 @@ function showSelectedChunk (payload)
881
861
view.applySnapshot(snapshotFromPayload(payload));
882
862
syncSpawnersOverlay(payload.chunkX, payload.chunkY, draft.spawners);
883
863
captureDraftBaseline();
884
recomputeAllNeighborConnectInDraft();
885
864
syncSaveButton();
886
865
if (navigateAfterSave && pendingNavigate)
887
866
{
@@ -1045,7 +1024,8 @@ function anyModalOpen ()
1045
1024
|| questsModal?.isOpen()
1046
1025
|| dialoguesModal?.isOpen()
1047
1026
|| giftsModal?.isOpen()
1048
|| !$("unsaved-chunk-modal")?.hidden;
1027
|| !$("unsaved-chunk-modal")?.hidden
1028
|| !$("global-changelog-modal")?.hidden;
1049
1029
}
1050
1030
1051
1031
function updateHoverStatus (local)
@@ -1440,6 +1420,8 @@ async function main ()
1440
1420
else if (message.type === MessageType.editorGiftCharacters
1441
1421
|| message.type === MessageType.editorGiftSent)
1442
1422
{ giftsModal?.handleMessage(message); }
1423
else if (message.type === MessageType.editorGlobalChangelog)
1424
{ renderGlobalChangelog(message.changelog ?? []); }
1443
1425
else if (message.type === MessageType.editorChunk)
1444
1426
{
1445
1427
const msgDim = normalizeDimensionId(message.dimensionId ?? OVERWORLD_ID);
@@ -1719,6 +1701,64 @@ $("season").addEventListener("change", () =>
1719
1701
applySeasonPreview($("season").value);
1720
1702
});
1721
1703
1704
function showGlobalChangelog (visible)
1705
{
1706
const backdrop = $("global-changelog-backdrop");
1707
const modal = $("global-changelog-modal");
1708
if (backdrop)
1709
{ backdrop.hidden = !visible; }
1710
if (modal)
1711
{ modal.hidden = !visible; }
1712
}
1713
1714
function renderGlobalChangelog (changelog)
1715
{
1716
const log = $("global-changelog");
1717
if (!log)
1718
{ return; }
1719
log.innerHTML = "";
1720
if (!changelog.length)
1721
{
1722
log.innerHTML = "<p class=\"hint\">No edits logged yet.</p>";
1723
return;
1724
}
1725
const kindLabel = {
1726
chunk: "Chunk",
1727
settings: "Settings",
1728
quest: "Quest",
1729
dialogue: "Dialogue"
1730
};
1731
for (const entry of changelog)
1732
{
1733
const item = document.createElement("article");
1734
const who = entry.editorDisplayName || entry.editor_admin_id;
1735
const kind = kindLabel[entry.kind] || entry.kind || "Edit";
1736
const scope = entry.scope ? ` · ${entry.scope}` : "";
1737
item.innerHTML = `<header>${kind}${scope} · ${who} · ${new Date(entry.edited_at).toLocaleString()}</header>`;
1738
const list = document.createElement("ul");
1739
for (const bullet of entry.diffEntries ?? [])
1740
{
1741
const li = document.createElement("li");
1742
li.textContent = bullet;
1743
list.append(li);
1744
}
1745
item.append(list);
1746
log.append(item);
1747
}
1748
log.scrollTop = 0;
1749
}
1750
1751
document.getElementById("open-global-changelog")?.addEventListener("click", () =>
1752
{
1753
const log = $("global-changelog");
1754
if (log)
1755
{ log.innerHTML = "<p class=\"hint\">Loading…</p>"; }
1756
showGlobalChangelog(true);
1757
socket.send({ type: MessageType.editorLoadGlobalChangelog });
1758
});
1759
document.getElementById("global-changelog-close")?.addEventListener("click", () => showGlobalChangelog(false));
1760
document.getElementById("global-changelog-backdrop")?.addEventListener("click", () => showGlobalChangelog(false));
1761
1722
1762
function syncSeasonControls (season)
1723
1763
{
1724
1764
const next = season === SeasonId.spring
@@ -799,26 +799,6 @@ function refreshNeighborConnect (localX, localY, typeId)799
}799
}800
}800
}801
801
802
/** Fix legacy/wrong connect states (e.g. old diagonal masks saved as nesw) from live neighbors. */803
function recomputeAllNeighborConnectInDraft ()804
{805
if (!draft)806
{ return; }807
for (let localY = 0; localY < CHUNK_SIZE; localY++)808
{809
for (let localX = 0; localX < CHUNK_SIZE; localX++)810
{811
const block = draft.blocks[localY * CHUNK_SIZE + localX];812
if (!block)813
{ continue; }814
const def = BLOCK_DEFINITIONS[block.typeId];815
if (!definitionUsesNeighborConnect(def))816
{ continue; }817
refreshNeighborConnect(localX, localY, block.typeId);818
}819
}820
}821
822
function updateRevisionUI ()802
function updateRevisionUI ()823
{803
{824
const applyBtn = $("apply");804
const applyBtn = $("apply");@@ -867,7 +847,7 @@ function showSelectedChunk (payload)867
for (const entry of payload.changelog ?? [])847
for (const entry of payload.changelog ?? [])868
{848
{869
const item = document.createElement("article");849
const item = document.createElement("article");870
item.innerHTML = `<header>${entry.editor_admin_id} · ${new Date(entry.edited_at).toLocaleString()}</header>`;850
item.innerHTML = `<header>${entry.editorDisplayName || entry.editor_admin_id} · ${new Date(entry.edited_at).toLocaleString()}</header>`;871
const list = document.createElement("ul");851
const list = document.createElement("ul");872
for (const bullet of entry.diffEntries)852
for (const bullet of entry.diffEntries)873
{853
{@@ -881,7 +861,6 @@ function showSelectedChunk (payload)881
view.applySnapshot(snapshotFromPayload(payload));861
view.applySnapshot(snapshotFromPayload(payload));882
syncSpawnersOverlay(payload.chunkX, payload.chunkY, draft.spawners);862
syncSpawnersOverlay(payload.chunkX, payload.chunkY, draft.spawners);883
captureDraftBaseline();863
captureDraftBaseline();884
recomputeAllNeighborConnectInDraft();885
syncSaveButton();864
syncSaveButton();886
if (navigateAfterSave && pendingNavigate)865
if (navigateAfterSave && pendingNavigate)887
{866
{@@ -1045,7 +1024,8 @@ function anyModalOpen ()1045
|| questsModal?.isOpen()1024
|| questsModal?.isOpen()1046
|| dialoguesModal?.isOpen()1025
|| dialoguesModal?.isOpen()1047
|| giftsModal?.isOpen()1026
|| giftsModal?.isOpen()1048
|| !$("unsaved-chunk-modal")?.hidden;1027
|| !$("unsaved-chunk-modal")?.hidden1028
|| !$("global-changelog-modal")?.hidden;1049
}1029
}1050
1030
1051
function updateHoverStatus (local)1031
function updateHoverStatus (local)@@ -1440,6 +1420,8 @@ async function main ()1440
else if (message.type === MessageType.editorGiftCharacters1420
else if (message.type === MessageType.editorGiftCharacters1441
|| message.type === MessageType.editorGiftSent)1421
|| message.type === MessageType.editorGiftSent)1442
{ giftsModal?.handleMessage(message); }1422
{ giftsModal?.handleMessage(message); }1423
else if (message.type === MessageType.editorGlobalChangelog)1424
{ renderGlobalChangelog(message.changelog ?? []); }1443
else if (message.type === MessageType.editorChunk)1425
else if (message.type === MessageType.editorChunk)1444
{1426
{1445
const msgDim = normalizeDimensionId(message.dimensionId ?? OVERWORLD_ID);1427
const msgDim = normalizeDimensionId(message.dimensionId ?? OVERWORLD_ID);@@ -1719,6 +1701,64 @@ $("season").addEventListener("change", () =>1719
applySeasonPreview($("season").value);1701
applySeasonPreview($("season").value);1720
});1702
});1721
1703
1704
function showGlobalChangelog (visible)1705
{1706
const backdrop = $("global-changelog-backdrop");1707
const modal = $("global-changelog-modal");1708
if (backdrop)1709
{ backdrop.hidden = !visible; }1710
if (modal)1711
{ modal.hidden = !visible; }1712
}1713
1714
function renderGlobalChangelog (changelog)1715
{1716
const log = $("global-changelog");1717
if (!log)1718
{ return; }1719
log.innerHTML = "";1720
if (!changelog.length)1721
{1722
log.innerHTML = "<p class=\"hint\">No edits logged yet.</p>";1723
return;1724
}1725
const kindLabel = {1726
chunk: "Chunk",1727
settings: "Settings",1728
quest: "Quest",1729
dialogue: "Dialogue"1730
};1731
for (const entry of changelog)1732
{1733
const item = document.createElement("article");1734
const who = entry.editorDisplayName || entry.editor_admin_id;1735
const kind = kindLabel[entry.kind] || entry.kind || "Edit";1736
const scope = entry.scope ? ` · ${entry.scope}` : "";1737
item.innerHTML = `<header>${kind}${scope} · ${who} · ${new Date(entry.edited_at).toLocaleString()}</header>`;1738
const list = document.createElement("ul");1739
for (const bullet of entry.diffEntries ?? [])1740
{1741
const li = document.createElement("li");1742
li.textContent = bullet;1743
list.append(li);1744
}1745
item.append(list);1746
log.append(item);1747
}1748
log.scrollTop = 0;1749
}1750
1751
document.getElementById("open-global-changelog")?.addEventListener("click", () =>1752
{1753
const log = $("global-changelog");1754
if (log)1755
{ log.innerHTML = "<p class=\"hint\">Loading…</p>"; }1756
showGlobalChangelog(true);1757
socket.send({ type: MessageType.editorLoadGlobalChangelog });1758
});1759
document.getElementById("global-changelog-close")?.addEventListener("click", () => showGlobalChangelog(false));1760
document.getElementById("global-changelog-backdrop")?.addEventListener("click", () => showGlobalChangelog(false));1761
1722
function syncSeasonControls (season)1762
function syncSeasonControls (season)1723
{1763
{1724
const next = season === SeasonId.spring1764
const next = season === SeasonId.spring@@ -16,6 +16,7 @@ export function initQuestsModal ({
16
16
const modal = document.getElementById("quests-modal");
17
17
const listEl = document.getElementById("quests-list");
18
18
const editorEl = document.getElementById("quests-editor");
19
const logEl = document.getElementById("quests-log");
19
20
const saveBtn = document.getElementById("quests-save");
20
21
const deleteBtn = document.getElementById("quests-delete");
21
22
let open = false;
@@ -26,6 +27,8 @@ export function initQuestsModal ({
26
27
/** @type {ReturnType<typeof normalizeQuestDef>|null} */
27
28
let draft = null;
28
29
let selectedId = null;
30
/** @type {object[]} */
31
let changelog = [];
29
32
30
33
/** @type {null | { resultsEl: HTMLElement, inputEl: HTMLInputElement }} */
31
34
let itemPickContext = null;
@@ -199,6 +202,8 @@ export function initQuestsModal ({
199
202
box.className = "content-editor-section";
200
203
const head = sectionHeader(`Step ${stepIndex + 1}`, null, () =>
201
204
{
205
if (!window.confirm(`Delete quest step "${step.stepId || stepIndex + 1}"?`))
206
{ return; }
202
207
draft.steps.splice(stepIndex, 1);
203
208
if (draft.steps.length === 0)
204
209
{
@@ -235,6 +240,8 @@ export function initQuestsModal ({
235
240
objBox.append(
236
241
sectionHeader(`Objective ${objIndex + 1}`, null, () =>
237
242
{
243
if (!window.confirm(`Delete objective "${obj.text || obj.objectiveId || objIndex + 1}"?`))
244
{ return; }
238
245
step.objectives.splice(objIndex, 1);
239
246
if (step.objectives.length === 0)
240
247
{
@@ -412,6 +419,42 @@ export function initQuestsModal ({
412
419
{
413
420
renderList();
414
421
renderEditor();
422
renderLog();
423
}
424
425
function renderLog ()
426
{
427
if (!logEl)
428
{ return; }
429
logEl.innerHTML = "";
430
const scopeId = draft?.questId ?? selectedId;
431
const entries = scopeId
432
? changelog.filter((entry) => entry.questId === scopeId)
433
: changelog;
434
if (!entries.length)
435
{
436
logEl.innerHTML = scopeId
437
? "<p class=\"hint\">No edits logged for this quest yet.</p>"
438
: "<p class=\"hint\">No quest edits logged yet.</p>";
439
return;
440
}
441
for (const entry of entries)
442
{
443
const item = document.createElement("article");
444
const who = entry.editorDisplayName || entry.editor_admin_id;
445
const scope = scopeId ? "" : ` · ${entry.questId}`;
446
item.innerHTML = `<header>${who}${scope} · ${new Date(entry.edited_at).toLocaleString()}</header>`;
447
const list = document.createElement("ul");
448
for (const bullet of entry.diffEntries ?? [])
449
{
450
const li = document.createElement("li");
451
li.textContent = bullet;
452
list.append(li);
453
}
454
item.append(list);
455
logEl.append(item);
456
}
457
logEl.scrollTop = logEl.scrollHeight;
415
458
}
416
459
417
460
document.getElementById("open-quests").addEventListener("click", () =>
@@ -465,6 +508,7 @@ export function initQuestsModal ({
465
508
if (message.type !== MessageType.editorQuests)
466
509
{ return; }
467
510
quests = (message.quests ?? []).map((q) => normalizeQuestDef(q));
511
changelog = message.changelog ?? [];
468
512
if (draft)
469
513
{
470
514
const still = quests.find((q) => q.questId === draft.questId);
@@ -16,6 +16,7 @@ export function initQuestsModal ({16
const modal = document.getElementById("quests-modal");16
const modal = document.getElementById("quests-modal");17
const listEl = document.getElementById("quests-list");17
const listEl = document.getElementById("quests-list");18
const editorEl = document.getElementById("quests-editor");18
const editorEl = document.getElementById("quests-editor");19
const logEl = document.getElementById("quests-log");19
const saveBtn = document.getElementById("quests-save");20
const saveBtn = document.getElementById("quests-save");20
const deleteBtn = document.getElementById("quests-delete");21
const deleteBtn = document.getElementById("quests-delete");21
let open = false;22
let open = false;@@ -26,6 +27,8 @@ export function initQuestsModal ({26
/** @type {ReturnType<typeof normalizeQuestDef>|null} */27
/** @type {ReturnType<typeof normalizeQuestDef>|null} */27
let draft = null;28
let draft = null;28
let selectedId = null;29
let selectedId = null;30
/** @type {object[]} */31
let changelog = [];29
32
30
/** @type {null | { resultsEl: HTMLElement, inputEl: HTMLInputElement }} */33
/** @type {null | { resultsEl: HTMLElement, inputEl: HTMLInputElement }} */31
let itemPickContext = null;34
let itemPickContext = null;@@ -199,6 +202,8 @@ export function initQuestsModal ({199
box.className = "content-editor-section";202
box.className = "content-editor-section";200
const head = sectionHeader(`Step ${stepIndex + 1}`, null, () =>203
const head = sectionHeader(`Step ${stepIndex + 1}`, null, () =>201
{204
{205
if (!window.confirm(`Delete quest step "${step.stepId || stepIndex + 1}"?`))206
{ return; }202
draft.steps.splice(stepIndex, 1);207
draft.steps.splice(stepIndex, 1);203
if (draft.steps.length === 0)208
if (draft.steps.length === 0)204
{209
{@@ -235,6 +240,8 @@ export function initQuestsModal ({235
objBox.append(240
objBox.append(236
sectionHeader(`Objective ${objIndex + 1}`, null, () =>241
sectionHeader(`Objective ${objIndex + 1}`, null, () =>237
{242
{243
if (!window.confirm(`Delete objective "${obj.text || obj.objectiveId || objIndex + 1}"?`))244
{ return; }238
step.objectives.splice(objIndex, 1);245
step.objectives.splice(objIndex, 1);239
if (step.objectives.length === 0)246
if (step.objectives.length === 0)240
{247
{@@ -412,6 +419,42 @@ export function initQuestsModal ({412
{419
{413
renderList();420
renderList();414
renderEditor();421
renderEditor();422
renderLog();423
}424
425
function renderLog ()426
{427
if (!logEl)428
{ return; }429
logEl.innerHTML = "";430
const scopeId = draft?.questId ?? selectedId;431
const entries = scopeId432
? changelog.filter((entry) => entry.questId === scopeId)433
: changelog;434
if (!entries.length)435
{436
logEl.innerHTML = scopeId437
? "<p class=\"hint\">No edits logged for this quest yet.</p>"438
: "<p class=\"hint\">No quest edits logged yet.</p>";439
return;440
}441
for (const entry of entries)442
{443
const item = document.createElement("article");444
const who = entry.editorDisplayName || entry.editor_admin_id;445
const scope = scopeId ? "" : ` · ${entry.questId}`;446
item.innerHTML = `<header>${who}${scope} · ${new Date(entry.edited_at).toLocaleString()}</header>`;447
const list = document.createElement("ul");448
for (const bullet of entry.diffEntries ?? [])449
{450
const li = document.createElement("li");451
li.textContent = bullet;452
list.append(li);453
}454
item.append(list);455
logEl.append(item);456
}457
logEl.scrollTop = logEl.scrollHeight;415
}458
}416
459
417
document.getElementById("open-quests").addEventListener("click", () =>460
document.getElementById("open-quests").addEventListener("click", () =>@@ -465,6 +508,7 @@ export function initQuestsModal ({465
if (message.type !== MessageType.editorQuests)508
if (message.type !== MessageType.editorQuests)466
{ return; }509
{ return; }467
quests = (message.quests ?? []).map((q) => normalizeQuestDef(q));510
quests = (message.quests ?? []).map((q) => normalizeQuestDef(q));511
changelog = message.changelog ?? [];468
if (draft)512
if (draft)469
{513
{470
const still = quests.find((q) => q.questId === draft.questId);514
const still = quests.find((q) => q.questId === draft.questId);@@ -1224,7 +1224,7 @@ function renderLog (log, changelog)
1224
1224
for (const entry of changelog)
1225
1225
{
1226
1226
const item = document.createElement("article");
1227
item.innerHTML = `<header>${entry.editor_admin_id} · ${new Date(entry.edited_at).toLocaleString()}</header>`;
1227
item.innerHTML = `<header>${entry.editorDisplayName || entry.editor_admin_id} · ${new Date(entry.edited_at).toLocaleString()}</header>`;
1228
1228
const list = document.createElement("ul");
1229
1229
for (const bullet of entry.diffEntries)
1230
1230
{
@@ -1224,7 +1224,7 @@ function renderLog (log, changelog)1224
for (const entry of changelog)1224
for (const entry of changelog)1225
{1225
{1226
const item = document.createElement("article");1226
const item = document.createElement("article");1227
item.innerHTML = `<header>${entry.editor_admin_id} · ${new Date(entry.edited_at).toLocaleString()}</header>`;1227
item.innerHTML = `<header>${entry.editorDisplayName || entry.editor_admin_id} · ${new Date(entry.edited_at).toLocaleString()}</header>`;1228
const list = document.createElement("ul");1228
const list = document.createElement("ul");1229
for (const bullet of entry.diffEntries)1229
for (const bullet of entry.diffEntries)1230
{1230
{@@ -1239,6 +1239,15 @@ export function initTileConfigModal ({
1239
1239
{
1240
1240
if (!context)
1241
1241
{ return; }
1242
if (context.kind === "spawner")
1243
{
1244
const label = context.config?.displayName
1245
|| context.config?.mobTypeId
1246
|| context.config?.spawnerId
1247
|| "this spawner";
1248
if (!window.confirm(`Delete mob spawner "${label}"?`))
1249
{ return; }
1250
}
1242
1251
onRemove?.(context);
1243
1252
show(false);
1244
1253
});
@@ -1239,6 +1239,15 @@ export function initTileConfigModal ({1239
{1239
{1240
if (!context)1240
if (!context)1241
{ return; }1241
{ return; }1242
if (context.kind === "spawner")1243
{1244
const label = context.config?.displayName1245
|| context.config?.mobTypeId1246
|| context.config?.spawnerId1247
|| "this spawner";1248
if (!window.confirm(`Delete mob spawner "${label}"?`))1249
{ return; }1250
}1242
onRemove?.(context);1251
onRemove?.(context);1243
show(false);1252
show(false);1244
});1253
});@@ -1307,7 +1307,8 @@ label {
1307
1307
#quests-modal,
1308
1308
#dialogues-modal,
1309
1309
#gifts-modal,
1310
#dialogue-tokens-modal {
1310
#dialogue-tokens-modal,
1311
#global-changelog-modal {
1311
1312
position: fixed;
1312
1313
inset: 5vh 5vw;
1313
1314
z-index: 20;
@@ -1318,6 +1319,19 @@ label {
1318
1319
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
1319
1320
}
1320
1321
1322
#quests-modal,
1323
#dialogues-modal {
1324
flex-direction: row;
1325
}
1326
1327
#quests-main,
1328
#dialogues-main {
1329
flex: 1;
1330
min-width: 0;
1331
display: flex;
1332
flex-direction: column;
1333
}
1334
1321
1335
#quests-modal[hidden],
1322
1336
#quests-backdrop[hidden],
1323
1337
#dialogues-modal[hidden],
@@ -1325,16 +1339,68 @@ label {
1325
1339
#gifts-modal[hidden],
1326
1340
#gifts-backdrop[hidden],
1327
1341
#dialogue-tokens-modal[hidden],
1328
#dialogue-tokens-backdrop[hidden] {
1342
#dialogue-tokens-backdrop[hidden],
1343
#global-changelog-modal[hidden],
1344
#global-changelog-backdrop[hidden] {
1329
1345
display: none !important;
1330
1346
}
1331
1347
1332
#quests-modal>header,
1333
#dialogues-modal>header,
1348
#global-changelog-backdrop {
1349
position: fixed;
1350
inset: 0;
1351
background: rgba(0, 0, 0, 0.62);
1352
z-index: 19;
1353
}
1354
1355
#global-changelog-modal {
1356
inset: 6vh 8vw;
1357
}
1358
1359
#global-changelog-modal>header {
1360
display: flex;
1361
align-items: center;
1362
justify-content: space-between;
1363
gap: 0.75rem;
1364
padding: 0.75rem 1rem;
1365
border-bottom: 1px solid #2c3340;
1366
}
1367
1368
.global-changelog-body {
1369
flex: 1;
1370
min-height: 0;
1371
overflow: auto;
1372
padding: 0.75rem 1rem 1rem;
1373
}
1374
1375
.content-editor-log-wrap {
1376
width: min(320px, 30vw);
1377
flex-shrink: 0;
1378
border-left: 1px solid #2c3340;
1379
display: flex;
1380
flex-direction: column;
1381
background: #1a1e26;
1382
}
1383
1384
.content-editor-log-wrap h2 {
1385
margin: 0;
1386
padding: 0.75rem 1rem;
1387
border-bottom: 1px solid #2c3340;
1388
font-size: 1rem;
1389
}
1390
1391
#quests-log,
1392
#dialogues-log {
1393
flex: 1;
1394
overflow: auto;
1395
padding: 0.75rem 1rem;
1396
}
1397
1398
#quests-main>header,
1399
#dialogues-main>header,
1334
1400
#gifts-modal>header,
1335
1401
#dialogue-tokens-modal>header,
1336
#quests-modal>footer,
1337
#dialogues-modal>footer {
1402
#quests-main>footer,
1403
#dialogues-main>footer {
1338
1404
display: flex;
1339
1405
align-items: center;
1340
1406
justify-content: space-between;
@@ -1343,8 +1409,8 @@ label {
1343
1409
border-bottom: 1px solid #2c3340;
1344
1410
}
1345
1411
1346
#quests-modal>footer,
1347
#dialogues-modal>footer {
1412
#quests-main>footer,
1413
#dialogues-main>footer {
1348
1414
border-bottom: 0;
1349
1415
border-top: 1px solid #2c3340;
1350
1416
justify-content: flex-end;
@@ -1307,7 +1307,8 @@ label {1307
#quests-modal,1307
#quests-modal,1308
#dialogues-modal,1308
#dialogues-modal,1309
#gifts-modal,1309
#gifts-modal,1310
#dialogue-tokens-modal {1310
#dialogue-tokens-modal,1311
#global-changelog-modal {1311
position: fixed;1312
position: fixed;1312
inset: 5vh 5vw;1313
inset: 5vh 5vw;1313
z-index: 20;1314
z-index: 20;@@ -1318,6 +1319,19 @@ label {1318
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);1319
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);1319
}1320
}1320
1321
1322
#quests-modal,1323
#dialogues-modal {1324
flex-direction: row;1325
}1326
1327
#quests-main,1328
#dialogues-main {1329
flex: 1;1330
min-width: 0;1331
display: flex;1332
flex-direction: column;1333
}1334
1321
#quests-modal[hidden],1335
#quests-modal[hidden],1322
#quests-backdrop[hidden],1336
#quests-backdrop[hidden],1323
#dialogues-modal[hidden],1337
#dialogues-modal[hidden],@@ -1325,16 +1339,68 @@ label {1325
#gifts-modal[hidden],1339
#gifts-modal[hidden],1326
#gifts-backdrop[hidden],1340
#gifts-backdrop[hidden],1327
#dialogue-tokens-modal[hidden],1341
#dialogue-tokens-modal[hidden],1328
#dialogue-tokens-backdrop[hidden] {1342
#dialogue-tokens-backdrop[hidden],1343
#global-changelog-modal[hidden],1344
#global-changelog-backdrop[hidden] {1329
display: none !important;1345
display: none !important;1330
}1346
}1331
1347
1332
#quests-modal>header,1348
#global-changelog-backdrop {1333
#dialogues-modal>header,1349
position: fixed;1350
inset: 0;1351
background: rgba(0, 0, 0, 0.62);1352
z-index: 19;1353
}1354
1355
#global-changelog-modal {1356
inset: 6vh 8vw;1357
}1358
1359
#global-changelog-modal>header {1360
display: flex;1361
align-items: center;1362
justify-content: space-between;1363
gap: 0.75rem;1364
padding: 0.75rem 1rem;1365
border-bottom: 1px solid #2c3340;1366
}1367
1368
.global-changelog-body {1369
flex: 1;1370
min-height: 0;1371
overflow: auto;1372
padding: 0.75rem 1rem 1rem;1373
}1374
1375
.content-editor-log-wrap {1376
width: min(320px, 30vw);1377
flex-shrink: 0;1378
border-left: 1px solid #2c3340;1379
display: flex;1380
flex-direction: column;1381
background: #1a1e26;1382
}1383
1384
.content-editor-log-wrap h2 {1385
margin: 0;1386
padding: 0.75rem 1rem;1387
border-bottom: 1px solid #2c3340;1388
font-size: 1rem;1389
}1390
1391
#quests-log,1392
#dialogues-log {1393
flex: 1;1394
overflow: auto;1395
padding: 0.75rem 1rem;1396
}1397
1398
#quests-main>header,1399
#dialogues-main>header,1334
#gifts-modal>header,1400
#gifts-modal>header,1335
#dialogue-tokens-modal>header,1401
#dialogue-tokens-modal>header,1336
#quests-modal>footer,1402
#quests-main>footer,1337
#dialogues-modal>footer {1403
#dialogues-main>footer {1338
display: flex;1404
display: flex;1339
align-items: center;1405
align-items: center;1340
justify-content: space-between;1406
justify-content: space-between;@@ -1343,8 +1409,8 @@ label {1343
border-bottom: 1px solid #2c3340;1409
border-bottom: 1px solid #2c3340;1344
}1410
}1345
1411
1346
#quests-modal>footer,1412
#quests-main>footer,1347
#dialogues-modal>footer {1413
#dialogues-main>footer {1348
border-bottom: 0;1414
border-bottom: 0;1349
border-top: 1px solid #2c3340;1415
border-top: 1px solid #2c3340;1350
justify-content: flex-end;1416
justify-content: flex-end;@@ -36,9 +36,28 @@ import {
36
36
37
37
export class EditorService
38
38
{
39
constructor (worldDb)
39
constructor (worldDb, stateDb = null)
40
40
{
41
41
this.worldDb = worldDb;
42
this.stateDb = stateDb;
43
}
44
45
#editorDisplayName (editorAdminId)
46
{
47
const subject = String(editorAdminId ?? "").trim();
48
if (!subject)
49
{ return "unknown"; }
50
const username = this.stateDb?.getAccountBySubject?.(subject)?.username;
51
const trimmed = username != null ? String(username).trim() : "";
52
return trimmed || subject;
53
}
54
55
#enrichChangelog (entries)
56
{
57
return (entries ?? []).map((entry) => ({
58
...entry,
59
editorDisplayName: this.#editorDisplayName(entry.editor_admin_id)
60
}));
42
61
}
43
62
44
63
#defaultGroundForDimension (dimensionId, revisionId = null)
@@ -79,7 +98,7 @@ export class EditorService
79
98
settings,
80
99
data,
81
100
closedEdges: closedNeighborEdges(chunkX, chunkY, isOpen),
82
changelog: this.worldDb.listChangelog(chunkX, chunkY, dimId)
101
changelog: this.#enrichChangelog(this.worldDb.listChangelog(chunkX, chunkY, dimId))
83
102
};
84
103
}
85
104
@@ -244,7 +263,14 @@ export class EditorService
244
263
{
245
264
return {
246
265
settings: this.worldDb.getLiveSettings(),
247
changelog: this.worldDb.listSettingsChangelog()
266
changelog: this.#enrichChangelog(this.worldDb.listSettingsChangelog())
267
};
268
}
269
270
loadGlobalChangelog (limit = 250)
271
{
272
return {
273
changelog: this.#enrichChangelog(this.worldDb.listGlobalChangelog(limit))
248
274
};
249
275
}
250
276
@@ -351,7 +377,7 @@ export class EditorService
351
377
{
352
378
return {
353
379
settings: current,
354
changelog: this.worldDb.listSettingsChangelog(),
380
changelog: this.#enrichChangelog(this.worldDb.listSettingsChangelog()),
355
381
changed: {}
356
382
};
357
383
}
@@ -377,7 +403,7 @@ export class EditorService
377
403
this.worldDb.appendSettingsChangelog(editorAdminId, bullets);
378
404
return {
379
405
settings,
380
changelog: this.worldDb.listSettingsChangelog(),
406
changelog: this.#enrichChangelog(this.worldDb.listSettingsChangelog()),
381
407
changed,
382
408
diffEntries: bullets
383
409
};
@@ -404,22 +430,39 @@ export class EditorService
404
430
revisionId,
405
431
pendingRevisionId: this.worldDb.getPendingRevisionId(),
406
432
activeRevisionId: this.worldDb.getActiveRevisionId(),
407
quests
433
quests,
434
changelog: this.#enrichChangelog(this.worldDb.listQuestChangelog())
408
435
};
409
436
}
410
437
411
438
saveQuest (raw, editorAdminId)
412
439
{
413
440
const def = normalizeQuestDef(raw);
414
const revisionId = this.worldDb.ensurePendingRevision(editorAdminId);
415
this.worldDb.saveQuestDef(revisionId, def);
441
const revisionId = this.worldDb.getEditorRevisionId();
442
const previousRaw = this.worldDb.getQuestDef(revisionId, def.questId);
443
const previous = previousRaw ? normalizeQuestDef(previousRaw) : null;
444
const bullets = diffQuests(previous, def);
445
const pendingId = this.worldDb.ensurePendingRevision(editorAdminId);
446
this.worldDb.saveQuestDef(pendingId, def);
447
if (bullets.length > 0)
448
{ this.worldDb.appendQuestChangelog(def.questId, pendingId, editorAdminId, bullets); }
416
449
return this.loadQuests();
417
450
}
418
451
419
452
deleteQuest (questId, editorAdminId)
420
453
{
421
const revisionId = this.worldDb.ensurePendingRevision(editorAdminId);
422
this.worldDb.deleteQuestDef(revisionId, String(questId));
454
const id = String(questId);
455
const revisionId = this.worldDb.getEditorRevisionId();
456
const previousRaw = this.worldDb.getQuestDef(revisionId, id);
457
const pendingId = this.worldDb.ensurePendingRevision(editorAdminId);
458
this.worldDb.deleteQuestDef(pendingId, id);
459
if (previousRaw)
460
{
461
const previous = normalizeQuestDef(previousRaw);
462
this.worldDb.appendQuestChangelog(id, pendingId, editorAdminId, [
463
`Quest "${previous.title}" (${id}) deleted.`
464
]);
465
}
423
466
return this.loadQuests();
424
467
}
425
468
@@ -435,14 +478,17 @@ export class EditorService
435
478
dialogues: trees.map((tree) => ({
436
479
...tree,
437
480
assignedSpawnerCount: assignmentCounts.get(tree.dialogueId) ?? 0
438
}))
481
})),
482
changelog: this.#enrichChangelog(this.worldDb.listDialogueChangelog())
439
483
};
440
484
}
441
485
442
486
saveDialogue (raw, editorAdminId)
443
487
{
444
488
const tree = normalizeDialogueTree(raw);
445
const revisionId = this.worldDb.ensurePendingRevision(editorAdminId);
489
const revisionId = this.worldDb.getEditorRevisionId();
490
const previousRaw = this.worldDb.getDialogueTree(revisionId, tree.dialogueId);
491
const previous = previousRaw ? normalizeDialogueTree(previousRaw) : null;
446
492
const assignmentCounts = this.#countDialogueAssignments(revisionId);
447
493
const assigned = assignmentCounts.get(tree.dialogueId) ?? 0;
448
494
if (tree.unique && assigned > 1)
@@ -461,7 +507,11 @@ export class EditorService
461
507
throw err;
462
508
}
463
509
}
464
this.worldDb.saveDialogueTree(revisionId, tree);
510
const bullets = diffDialogues(previous, tree);
511
const pendingId = this.worldDb.ensurePendingRevision(editorAdminId);
512
this.worldDb.saveDialogueTree(pendingId, tree);
513
if (bullets.length > 0)
514
{ this.worldDb.appendDialogueChangelog(tree.dialogueId, pendingId, editorAdminId, bullets); }
465
515
return this.loadDialogues();
466
516
}
467
517
@@ -476,8 +526,16 @@ export class EditorService
476
526
err.userFacing = true;
477
527
throw err;
478
528
}
529
const previousRaw = this.worldDb.getDialogueTree(revisionId, id);
479
530
const pendingId = this.worldDb.ensurePendingRevision(editorAdminId);
480
531
this.worldDb.deleteDialogueTree(pendingId, id);
532
if (previousRaw)
533
{
534
const previous = normalizeDialogueTree(previousRaw);
535
this.worldDb.appendDialogueChangelog(id, pendingId, editorAdminId, [
536
`Dialogue "${previous.label}" (${id}) deleted.`
537
]);
538
}
481
539
return this.loadDialogues();
482
540
}
483
541
@@ -667,6 +725,72 @@ export function diffChunks (chunkX, chunkY, previous, next, previousAuthored)
667
725
return bullets;
668
726
}
669
727
728
export function diffQuests (previous, next)
729
{
730
if (!previous)
731
{ return [`Quest "${next.title}" (${next.questId}) created.`]; }
732
if (JSON.stringify(previous) === JSON.stringify(next))
733
{ return []; }
734
const bullets = [];
735
if (previous.title !== next.title)
736
{ bullets.push(`Title: "${previous.title}" → "${next.title}".`); }
737
if (previous.description !== next.description)
738
{ bullets.push("Description changed."); }
739
if (!!previous.cancelable !== !!next.cancelable)
740
{ bullets.push(`Cancelable: ${previous.cancelable ? "yes" : "no"} → ${next.cancelable ? "yes" : "no"}.`); }
741
if (JSON.stringify(previous.rewards) !== JSON.stringify(next.rewards))
742
{ bullets.push("Quest rewards changed."); }
743
744
const prevSteps = new Map((previous.steps ?? []).map((step) => [step.stepId, step]));
745
const nextSteps = new Map((next.steps ?? []).map((step) => [step.stepId, step]));
746
for (const stepId of new Set([...prevSteps.keys(), ...nextSteps.keys()]))
747
{
748
const prev = prevSteps.get(stepId);
749
const cur = nextSteps.get(stepId);
750
if (!prev && cur)
751
{ bullets.push(`Step "${cur.title}" (${stepId}) added.`); }
752
else if (prev && !cur)
753
{ bullets.push(`Step "${prev.title}" (${stepId}) removed.`); }
754
else if (JSON.stringify(prev) !== JSON.stringify(cur))
755
{ bullets.push(`Step "${cur.title}" (${stepId}) updated.`); }
756
}
757
if (bullets.length === 0)
758
{ bullets.push(`Quest "${next.questId}" updated.`); }
759
return bullets;
760
}
761
762
export function diffDialogues (previous, next)
763
{
764
if (!previous)
765
{ return [`Dialogue "${next.label}" (${next.dialogueId}) created.`]; }
766
if (JSON.stringify(previous) === JSON.stringify(next))
767
{ return []; }
768
const bullets = [];
769
if (previous.label !== next.label)
770
{ bullets.push(`Label: "${previous.label}" → "${next.label}".`); }
771
if (!!previous.unique !== !!next.unique)
772
{ bullets.push(`Unique: ${previous.unique ? "yes" : "no"} → ${next.unique ? "yes" : "no"}.`); }
773
if (previous.entryStepId !== next.entryStepId)
774
{ bullets.push(`Entry step: ${previous.entryStepId} → ${next.entryStepId}.`); }
775
776
const prevSteps = new Map((previous.steps ?? []).map((step) => [step.stepId, step]));
777
const nextSteps = new Map((next.steps ?? []).map((step) => [step.stepId, step]));
778
for (const stepId of new Set([...prevSteps.keys(), ...nextSteps.keys()]))
779
{
780
const prev = prevSteps.get(stepId);
781
const cur = nextSteps.get(stepId);
782
if (!prev && cur)
783
{ bullets.push(`Step "${cur.label}" (${stepId}) added.`); }
784
else if (prev && !cur)
785
{ bullets.push(`Step "${prev.label}" (${stepId}) removed.`); }
786
else if (JSON.stringify(prev) !== JSON.stringify(cur))
787
{ bullets.push(`Step "${cur.label}" (${stepId}) updated.`); }
788
}
789
if (bullets.length === 0)
790
{ bullets.push(`Dialogue "${next.dialogueId}" updated.`); }
791
return bullets;
792
}
793
670
794
function indexSpawners (spawners)
671
795
{
672
796
const map = new Map();
@@ -36,9 +36,28 @@ import {36
36
37
export class EditorService37
export class EditorService38
{38
{39
constructor (worldDb)39
constructor (worldDb, stateDb = null)40
{40
{41
this.worldDb = worldDb;41
this.worldDb = worldDb;42
this.stateDb = stateDb;43
}44
45
#editorDisplayName (editorAdminId)46
{47
const subject = String(editorAdminId ?? "").trim();48
if (!subject)49
{ return "unknown"; }50
const username = this.stateDb?.getAccountBySubject?.(subject)?.username;51
const trimmed = username != null ? String(username).trim() : "";52
return trimmed || subject;53
}54
55
#enrichChangelog (entries)56
{57
return (entries ?? []).map((entry) => ({58
...entry,59
editorDisplayName: this.#editorDisplayName(entry.editor_admin_id)60
}));42
}61
}43
62
44
#defaultGroundForDimension (dimensionId, revisionId = null)63
#defaultGroundForDimension (dimensionId, revisionId = null)@@ -79,7 +98,7 @@ export class EditorService79
settings,98
settings,80
data,99
data,81
closedEdges: closedNeighborEdges(chunkX, chunkY, isOpen),100
closedEdges: closedNeighborEdges(chunkX, chunkY, isOpen),82
changelog: this.worldDb.listChangelog(chunkX, chunkY, dimId)101
changelog: this.#enrichChangelog(this.worldDb.listChangelog(chunkX, chunkY, dimId))83
};102
};84
}103
}85
104
@@ -244,7 +263,14 @@ export class EditorService244
{263
{245
return {264
return {246
settings: this.worldDb.getLiveSettings(),265
settings: this.worldDb.getLiveSettings(),247
changelog: this.worldDb.listSettingsChangelog()266
changelog: this.#enrichChangelog(this.worldDb.listSettingsChangelog())267
};268
}269
270
loadGlobalChangelog (limit = 250)271
{272
return {273
changelog: this.#enrichChangelog(this.worldDb.listGlobalChangelog(limit))248
};274
};249
}275
}250
276
@@ -351,7 +377,7 @@ export class EditorService351
{377
{352
return {378
return {353
settings: current,379
settings: current,354
changelog: this.worldDb.listSettingsChangelog(),380
changelog: this.#enrichChangelog(this.worldDb.listSettingsChangelog()),355
changed: {}381
changed: {}356
};382
};357
}383
}@@ -377,7 +403,7 @@ export class EditorService377
this.worldDb.appendSettingsChangelog(editorAdminId, bullets);403
this.worldDb.appendSettingsChangelog(editorAdminId, bullets);378
return {404
return {379
settings,405
settings,380
changelog: this.worldDb.listSettingsChangelog(),406
changelog: this.#enrichChangelog(this.worldDb.listSettingsChangelog()),381
changed,407
changed,382
diffEntries: bullets408
diffEntries: bullets383
};409
};@@ -404,22 +430,39 @@ export class EditorService404
revisionId,430
revisionId,405
pendingRevisionId: this.worldDb.getPendingRevisionId(),431
pendingRevisionId: this.worldDb.getPendingRevisionId(),406
activeRevisionId: this.worldDb.getActiveRevisionId(),432
activeRevisionId: this.worldDb.getActiveRevisionId(),407
quests433
quests,434
changelog: this.#enrichChangelog(this.worldDb.listQuestChangelog())408
};435
};409
}436
}410
437
411
saveQuest (raw, editorAdminId)438
saveQuest (raw, editorAdminId)412
{439
{413
const def = normalizeQuestDef(raw);440
const def = normalizeQuestDef(raw);414
const revisionId = this.worldDb.ensurePendingRevision(editorAdminId);441
const revisionId = this.worldDb.getEditorRevisionId();415
this.worldDb.saveQuestDef(revisionId, def);442
const previousRaw = this.worldDb.getQuestDef(revisionId, def.questId);443
const previous = previousRaw ? normalizeQuestDef(previousRaw) : null;444
const bullets = diffQuests(previous, def);445
const pendingId = this.worldDb.ensurePendingRevision(editorAdminId);446
this.worldDb.saveQuestDef(pendingId, def);447
if (bullets.length > 0)448
{ this.worldDb.appendQuestChangelog(def.questId, pendingId, editorAdminId, bullets); }416
return this.loadQuests();449
return this.loadQuests();417
}450
}418
451
419
deleteQuest (questId, editorAdminId)452
deleteQuest (questId, editorAdminId)420
{453
{421
const revisionId = this.worldDb.ensurePendingRevision(editorAdminId);454
const id = String(questId);422
this.worldDb.deleteQuestDef(revisionId, String(questId));455
const revisionId = this.worldDb.getEditorRevisionId();456
const previousRaw = this.worldDb.getQuestDef(revisionId, id);457
const pendingId = this.worldDb.ensurePendingRevision(editorAdminId);458
this.worldDb.deleteQuestDef(pendingId, id);459
if (previousRaw)460
{461
const previous = normalizeQuestDef(previousRaw);462
this.worldDb.appendQuestChangelog(id, pendingId, editorAdminId, [463
`Quest "${previous.title}" (${id}) deleted.`464
]);465
}423
return this.loadQuests();466
return this.loadQuests();424
}467
}425
468
@@ -435,14 +478,17 @@ export class EditorService435
dialogues: trees.map((tree) => ({478
dialogues: trees.map((tree) => ({436
...tree,479
...tree,437
assignedSpawnerCount: assignmentCounts.get(tree.dialogueId) ?? 0480
assignedSpawnerCount: assignmentCounts.get(tree.dialogueId) ?? 0438
}))481
})),482
changelog: this.#enrichChangelog(this.worldDb.listDialogueChangelog())439
};483
};440
}484
}441
485
442
saveDialogue (raw, editorAdminId)486
saveDialogue (raw, editorAdminId)443
{487
{444
const tree = normalizeDialogueTree(raw);488
const tree = normalizeDialogueTree(raw);445
const revisionId = this.worldDb.ensurePendingRevision(editorAdminId);489
const revisionId = this.worldDb.getEditorRevisionId();490
const previousRaw = this.worldDb.getDialogueTree(revisionId, tree.dialogueId);491
const previous = previousRaw ? normalizeDialogueTree(previousRaw) : null;446
const assignmentCounts = this.#countDialogueAssignments(revisionId);492
const assignmentCounts = this.#countDialogueAssignments(revisionId);447
const assigned = assignmentCounts.get(tree.dialogueId) ?? 0;493
const assigned = assignmentCounts.get(tree.dialogueId) ?? 0;448
if (tree.unique && assigned > 1)494
if (tree.unique && assigned > 1)@@ -461,7 +507,11 @@ export class EditorService461
throw err;507
throw err;462
}508
}463
}509
}464
this.worldDb.saveDialogueTree(revisionId, tree);510
const bullets = diffDialogues(previous, tree);511
const pendingId = this.worldDb.ensurePendingRevision(editorAdminId);512
this.worldDb.saveDialogueTree(pendingId, tree);513
if (bullets.length > 0)514
{ this.worldDb.appendDialogueChangelog(tree.dialogueId, pendingId, editorAdminId, bullets); }465
return this.loadDialogues();515
return this.loadDialogues();466
}516
}467
517
@@ -476,8 +526,16 @@ export class EditorService476
err.userFacing = true;526
err.userFacing = true;477
throw err;527
throw err;478
}528
}529
const previousRaw = this.worldDb.getDialogueTree(revisionId, id);479
const pendingId = this.worldDb.ensurePendingRevision(editorAdminId);530
const pendingId = this.worldDb.ensurePendingRevision(editorAdminId);480
this.worldDb.deleteDialogueTree(pendingId, id);531
this.worldDb.deleteDialogueTree(pendingId, id);532
if (previousRaw)533
{534
const previous = normalizeDialogueTree(previousRaw);535
this.worldDb.appendDialogueChangelog(id, pendingId, editorAdminId, [536
`Dialogue "${previous.label}" (${id}) deleted.`537
]);538
}481
return this.loadDialogues();539
return this.loadDialogues();482
}540
}483
541
@@ -667,6 +725,72 @@ export function diffChunks (chunkX, chunkY, previous, next, previousAuthored)667
return bullets;725
return bullets;668
}726
}669
727
728
export function diffQuests (previous, next)729
{730
if (!previous)731
{ return [`Quest "${next.title}" (${next.questId}) created.`]; }732
if (JSON.stringify(previous) === JSON.stringify(next))733
{ return []; }734
const bullets = [];735
if (previous.title !== next.title)736
{ bullets.push(`Title: "${previous.title}" → "${next.title}".`); }737
if (previous.description !== next.description)738
{ bullets.push("Description changed."); }739
if (!!previous.cancelable !== !!next.cancelable)740
{ bullets.push(`Cancelable: ${previous.cancelable ? "yes" : "no"} → ${next.cancelable ? "yes" : "no"}.`); }741
if (JSON.stringify(previous.rewards) !== JSON.stringify(next.rewards))742
{ bullets.push("Quest rewards changed."); }743
744
const prevSteps = new Map((previous.steps ?? []).map((step) => [step.stepId, step]));745
const nextSteps = new Map((next.steps ?? []).map((step) => [step.stepId, step]));746
for (const stepId of new Set([...prevSteps.keys(), ...nextSteps.keys()]))747
{748
const prev = prevSteps.get(stepId);749
const cur = nextSteps.get(stepId);750
if (!prev && cur)751
{ bullets.push(`Step "${cur.title}" (${stepId}) added.`); }752
else if (prev && !cur)753
{ bullets.push(`Step "${prev.title}" (${stepId}) removed.`); }754
else if (JSON.stringify(prev) !== JSON.stringify(cur))755
{ bullets.push(`Step "${cur.title}" (${stepId}) updated.`); }756
}757
if (bullets.length === 0)758
{ bullets.push(`Quest "${next.questId}" updated.`); }759
return bullets;760
}761
762
export function diffDialogues (previous, next)763
{764
if (!previous)765
{ return [`Dialogue "${next.label}" (${next.dialogueId}) created.`]; }766
if (JSON.stringify(previous) === JSON.stringify(next))767
{ return []; }768
const bullets = [];769
if (previous.label !== next.label)770
{ bullets.push(`Label: "${previous.label}" → "${next.label}".`); }771
if (!!previous.unique !== !!next.unique)772
{ bullets.push(`Unique: ${previous.unique ? "yes" : "no"} → ${next.unique ? "yes" : "no"}.`); }773
if (previous.entryStepId !== next.entryStepId)774
{ bullets.push(`Entry step: ${previous.entryStepId} → ${next.entryStepId}.`); }775
776
const prevSteps = new Map((previous.steps ?? []).map((step) => [step.stepId, step]));777
const nextSteps = new Map((next.steps ?? []).map((step) => [step.stepId, step]));778
for (const stepId of new Set([...prevSteps.keys(), ...nextSteps.keys()]))779
{780
const prev = prevSteps.get(stepId);781
const cur = nextSteps.get(stepId);782
if (!prev && cur)783
{ bullets.push(`Step "${cur.label}" (${stepId}) added.`); }784
else if (prev && !cur)785
{ bullets.push(`Step "${prev.label}" (${stepId}) removed.`); }786
else if (JSON.stringify(prev) !== JSON.stringify(cur))787
{ bullets.push(`Step "${cur.label}" (${stepId}) updated.`); }788
}789
if (bullets.length === 0)790
{ bullets.push(`Dialogue "${next.dialogueId}" updated.`); }791
return bullets;792
}793
670
function indexSpawners (spawners)794
function indexSpawners (spawners)671
{795
{672
const map = new Map();796
const map = new Map();@@ -1002,6 +1002,13 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1002
1002
itemLastSales: simulation.itemLastSalesSnapshot?.() ?? {}
1003
1003
});
1004
1004
break;
1005
case MessageType.editorLoadGlobalChangelog:
1006
requireAdmin(session);
1007
send(session, {
1008
type: MessageType.editorGlobalChangelog,
1009
...editor.loadGlobalChangelog(message.limit)
1010
});
1011
break;
1005
1012
case MessageType.editorLoadGameAdmins:
1006
1013
requireAdmin(session);
1007
1014
send(session, {
@@ -1002,6 +1002,13 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1002
itemLastSales: simulation.itemLastSalesSnapshot?.() ?? {}1002
itemLastSales: simulation.itemLastSalesSnapshot?.() ?? {}1003
});1003
});1004
break;1004
break;1005
case MessageType.editorLoadGlobalChangelog:1006
requireAdmin(session);1007
send(session, {1008
type: MessageType.editorGlobalChangelog,1009
...editor.loadGlobalChangelog(message.limit)1010
});1011
break;1005
case MessageType.editorLoadGameAdmins:1012
case MessageType.editorLoadGameAdmins:1006
requireAdmin(session);1013
requireAdmin(session);1007
send(session, {1014
send(session, {@@ -23,7 +23,7 @@ const port = Number(process.env.PORT ?? 8080);
23
23
24
24
const worldDb = new WorldDatabase(join(dataDir, "world.sqlite"));
25
25
const stateDb = new StateDatabase(join(dataDir, "state.sqlite"));
26
const editor = new EditorService(worldDb);
26
const editor = new EditorService(worldDb, stateDb);
27
27
const characters = new CharacterService(stateDb, console);
28
28
const friends = new FriendService(stateDb);
29
29
const simulation = new Simulation(worldDb, stateDb);
@@ -23,7 +23,7 @@ const port = Number(process.env.PORT ?? 8080);23
23
24
const worldDb = new WorldDatabase(join(dataDir, "world.sqlite"));24
const worldDb = new WorldDatabase(join(dataDir, "world.sqlite"));25
const stateDb = new StateDatabase(join(dataDir, "state.sqlite"));25
const stateDb = new StateDatabase(join(dataDir, "state.sqlite"));26
const editor = new EditorService(worldDb);26
const editor = new EditorService(worldDb, stateDb);27
const characters = new CharacterService(stateDb, console);27
const characters = new CharacterService(stateDb, console);28
const friends = new FriendService(stateDb);28
const friends = new FriendService(stateDb);29
const simulation = new Simulation(worldDb, stateDb);29
const simulation = new Simulation(worldDb, stateDb);@@ -79,6 +79,24 @@ CREATE TABLE IF NOT EXISTS world_dialogue_trees (
79
79
PRIMARY KEY (revision_id, dialogue_id)
80
80
);
81
81
82
CREATE TABLE IF NOT EXISTS world_quest_edit_log (
83
log_id INTEGER PRIMARY KEY AUTOINCREMENT,
84
quest_id TEXT NOT NULL,
85
revision_id INTEGER NOT NULL,
86
editor_admin_id TEXT NOT NULL,
87
edited_at INTEGER NOT NULL,
88
diff_entries TEXT NOT NULL
89
);
90
91
CREATE TABLE IF NOT EXISTS world_dialogue_edit_log (
92
log_id INTEGER PRIMARY KEY AUTOINCREMENT,
93
dialogue_id TEXT NOT NULL,
94
revision_id INTEGER NOT NULL,
95
editor_admin_id TEXT NOT NULL,
96
edited_at INTEGER NOT NULL,
97
diff_entries TEXT NOT NULL
98
);
99
82
100
CREATE TABLE IF NOT EXISTS world_dimensions (
83
101
revision_id INTEGER NOT NULL,
84
102
dimension_id TEXT NOT NULL,
@@ -304,6 +322,125 @@ export class WorldDatabase
304
322
}));
305
323
}
306
324
325
appendQuestChangelog (questId, revisionId, editorAdminId, diffEntries)
326
{
327
this.db.prepare(`
328
INSERT INTO world_quest_edit_log
329
(quest_id, revision_id, editor_admin_id, edited_at, diff_entries)
330
VALUES (?, ?, ?, ?, ?)
331
`).run(String(questId), revisionId, editorAdminId, Date.now(), JSON.stringify(diffEntries));
332
}
333
334
listQuestChangelog (questId = null)
335
{
336
if (questId != null)
337
{
338
return this.db.prepare(`
339
SELECT log_id, quest_id, revision_id, editor_admin_id, edited_at, diff_entries
340
FROM world_quest_edit_log
341
WHERE quest_id = ?
342
ORDER BY edited_at ASC, log_id ASC
343
`).all(String(questId)).map(mapQuestLogRow);
344
}
345
return this.db.prepare(`
346
SELECT log_id, quest_id, revision_id, editor_admin_id, edited_at, diff_entries
347
FROM world_quest_edit_log
348
ORDER BY edited_at ASC, log_id ASC
349
`).all().map(mapQuestLogRow);
350
}
351
352
appendDialogueChangelog (dialogueId, revisionId, editorAdminId, diffEntries)
353
{
354
this.db.prepare(`
355
INSERT INTO world_dialogue_edit_log
356
(dialogue_id, revision_id, editor_admin_id, edited_at, diff_entries)
357
VALUES (?, ?, ?, ?, ?)
358
`).run(String(dialogueId), revisionId, editorAdminId, Date.now(), JSON.stringify(diffEntries));
359
}
360
361
listDialogueChangelog (dialogueId = null)
362
{
363
if (dialogueId != null)
364
{
365
return this.db.prepare(`
366
SELECT log_id, dialogue_id, revision_id, editor_admin_id, edited_at, diff_entries
367
FROM world_dialogue_edit_log
368
WHERE dialogue_id = ?
369
ORDER BY edited_at ASC, log_id ASC
370
`).all(String(dialogueId)).map(mapDialogueLogRow);
371
}
372
return this.db.prepare(`
373
SELECT log_id, dialogue_id, revision_id, editor_admin_id, edited_at, diff_entries
374
FROM world_dialogue_edit_log
375
ORDER BY edited_at ASC, log_id ASC
376
`).all().map(mapDialogueLogRow);
377
}
378
379
/**
380
* Recent edits across chunks, settings, quests, and dialogues (newest first).
381
* @param {number} [limit]
382
*/
383
listGlobalChangelog (limit = 250)
384
{
385
const cap = Math.max(1, Math.min(1000, limit | 0 || 250));
386
const chunkRows = this.db.prepare(`
387
SELECT log_id, dimension_id, chunk_x, chunk_y, editor_admin_id, edited_at, diff_entries
388
FROM world_chunk_edit_log
389
ORDER BY edited_at DESC, log_id DESC
390
LIMIT ?
391
`).all(cap).map((row) => ({
392
kind: "chunk",
393
scope: `${row.dimension_id} ${row.chunk_x},${row.chunk_y}`,
394
editor_admin_id: row.editor_admin_id,
395
edited_at: row.edited_at,
396
diffEntries: JSON.parse(row.diff_entries),
397
_key: row.log_id
398
}));
399
const settingsRows = this.db.prepare(`
400
SELECT log_id, editor_admin_id, edited_at, diff_entries
401
FROM world_settings_edit_log
402
ORDER BY edited_at DESC, log_id DESC
403
LIMIT ?
404
`).all(cap).map((row) => ({
405
kind: "settings",
406
scope: "settings",
407
editor_admin_id: row.editor_admin_id,
408
edited_at: row.edited_at,
409
diffEntries: JSON.parse(row.diff_entries),
410
_key: row.log_id
411
}));
412
const questRows = this.db.prepare(`
413
SELECT log_id, quest_id, editor_admin_id, edited_at, diff_entries
414
FROM world_quest_edit_log
415
ORDER BY edited_at DESC, log_id DESC
416
LIMIT ?
417
`).all(cap).map((row) => ({
418
kind: "quest",
419
scope: row.quest_id,
420
editor_admin_id: row.editor_admin_id,
421
edited_at: row.edited_at,
422
diffEntries: JSON.parse(row.diff_entries),
423
_key: row.log_id
424
}));
425
const dialogueRows = this.db.prepare(`
426
SELECT log_id, dialogue_id, editor_admin_id, edited_at, diff_entries
427
FROM world_dialogue_edit_log
428
ORDER BY edited_at DESC, log_id DESC
429
LIMIT ?
430
`).all(cap).map((row) => ({
431
kind: "dialogue",
432
scope: row.dialogue_id,
433
editor_admin_id: row.editor_admin_id,
434
edited_at: row.edited_at,
435
diffEntries: JSON.parse(row.diff_entries),
436
_key: row.log_id
437
}));
438
return [...chunkRows, ...settingsRows, ...questRows, ...dialogueRows]
439
.sort((a, b) => (b.edited_at - a.edited_at) || (b._key - a._key))
440
.slice(0, cap)
441
.map(({ _key, ...entry }) => entry);
442
}
443
307
444
getActiveRevisionId ()
308
445
{
309
446
return this.db.prepare("SELECT value FROM world_meta WHERE key = 'active_revision'").get()?.value ?? null;
@@ -649,3 +786,21 @@ export class WorldDatabase
649
786
this.db.close();
650
787
}
651
788
}
789
790
function mapQuestLogRow (row)
791
{
792
return {
793
...row,
794
questId: row.quest_id,
795
diffEntries: JSON.parse(row.diff_entries)
796
};
797
}
798
799
function mapDialogueLogRow (row)
800
{
801
return {
802
...row,
803
dialogueId: row.dialogue_id,
804
diffEntries: JSON.parse(row.diff_entries)
805
};
806
}
@@ -79,6 +79,24 @@ CREATE TABLE IF NOT EXISTS world_dialogue_trees (79
PRIMARY KEY (revision_id, dialogue_id)79
PRIMARY KEY (revision_id, dialogue_id)80
);80
);81
81
82
CREATE TABLE IF NOT EXISTS world_quest_edit_log (83
log_id INTEGER PRIMARY KEY AUTOINCREMENT,84
quest_id TEXT NOT NULL,85
revision_id INTEGER NOT NULL,86
editor_admin_id TEXT NOT NULL,87
edited_at INTEGER NOT NULL,88
diff_entries TEXT NOT NULL89
);90
91
CREATE TABLE IF NOT EXISTS world_dialogue_edit_log (92
log_id INTEGER PRIMARY KEY AUTOINCREMENT,93
dialogue_id TEXT NOT NULL,94
revision_id INTEGER NOT NULL,95
editor_admin_id TEXT NOT NULL,96
edited_at INTEGER NOT NULL,97
diff_entries TEXT NOT NULL98
);99
82
CREATE TABLE IF NOT EXISTS world_dimensions (100
CREATE TABLE IF NOT EXISTS world_dimensions (83
revision_id INTEGER NOT NULL,101
revision_id INTEGER NOT NULL,84
dimension_id TEXT NOT NULL,102
dimension_id TEXT NOT NULL,@@ -304,6 +322,125 @@ export class WorldDatabase304
}));322
}));305
}323
}306
324
325
appendQuestChangelog (questId, revisionId, editorAdminId, diffEntries)326
{327
this.db.prepare(`328
INSERT INTO world_quest_edit_log329
(quest_id, revision_id, editor_admin_id, edited_at, diff_entries)330
VALUES (?, ?, ?, ?, ?)331
`).run(String(questId), revisionId, editorAdminId, Date.now(), JSON.stringify(diffEntries));332
}333
334
listQuestChangelog (questId = null)335
{336
if (questId != null)337
{338
return this.db.prepare(`339
SELECT log_id, quest_id, revision_id, editor_admin_id, edited_at, diff_entries340
FROM world_quest_edit_log341
WHERE quest_id = ?342
ORDER BY edited_at ASC, log_id ASC343
`).all(String(questId)).map(mapQuestLogRow);344
}345
return this.db.prepare(`346
SELECT log_id, quest_id, revision_id, editor_admin_id, edited_at, diff_entries347
FROM world_quest_edit_log348
ORDER BY edited_at ASC, log_id ASC349
`).all().map(mapQuestLogRow);350
}351
352
appendDialogueChangelog (dialogueId, revisionId, editorAdminId, diffEntries)353
{354
this.db.prepare(`355
INSERT INTO world_dialogue_edit_log356
(dialogue_id, revision_id, editor_admin_id, edited_at, diff_entries)357
VALUES (?, ?, ?, ?, ?)358
`).run(String(dialogueId), revisionId, editorAdminId, Date.now(), JSON.stringify(diffEntries));359
}360
361
listDialogueChangelog (dialogueId = null)362
{363
if (dialogueId != null)364
{365
return this.db.prepare(`366
SELECT log_id, dialogue_id, revision_id, editor_admin_id, edited_at, diff_entries367
FROM world_dialogue_edit_log368
WHERE dialogue_id = ?369
ORDER BY edited_at ASC, log_id ASC370
`).all(String(dialogueId)).map(mapDialogueLogRow);371
}372
return this.db.prepare(`373
SELECT log_id, dialogue_id, revision_id, editor_admin_id, edited_at, diff_entries374
FROM world_dialogue_edit_log375
ORDER BY edited_at ASC, log_id ASC376
`).all().map(mapDialogueLogRow);377
}378
379
/**380
* Recent edits across chunks, settings, quests, and dialogues (newest first).381
* @param {number} [limit]382
*/383
listGlobalChangelog (limit = 250)384
{385
const cap = Math.max(1, Math.min(1000, limit | 0 || 250));386
const chunkRows = this.db.prepare(`387
SELECT log_id, dimension_id, chunk_x, chunk_y, editor_admin_id, edited_at, diff_entries388
FROM world_chunk_edit_log389
ORDER BY edited_at DESC, log_id DESC390
LIMIT ?391
`).all(cap).map((row) => ({392
kind: "chunk",393
scope: `${row.dimension_id} ${row.chunk_x},${row.chunk_y}`,394
editor_admin_id: row.editor_admin_id,395
edited_at: row.edited_at,396
diffEntries: JSON.parse(row.diff_entries),397
_key: row.log_id398
}));399
const settingsRows = this.db.prepare(`400
SELECT log_id, editor_admin_id, edited_at, diff_entries401
FROM world_settings_edit_log402
ORDER BY edited_at DESC, log_id DESC403
LIMIT ?404
`).all(cap).map((row) => ({405
kind: "settings",406
scope: "settings",407
editor_admin_id: row.editor_admin_id,408
edited_at: row.edited_at,409
diffEntries: JSON.parse(row.diff_entries),410
_key: row.log_id411
}));412
const questRows = this.db.prepare(`413
SELECT log_id, quest_id, editor_admin_id, edited_at, diff_entries414
FROM world_quest_edit_log415
ORDER BY edited_at DESC, log_id DESC416
LIMIT ?417
`).all(cap).map((row) => ({418
kind: "quest",419
scope: row.quest_id,420
editor_admin_id: row.editor_admin_id,421
edited_at: row.edited_at,422
diffEntries: JSON.parse(row.diff_entries),423
_key: row.log_id424
}));425
const dialogueRows = this.db.prepare(`426
SELECT log_id, dialogue_id, editor_admin_id, edited_at, diff_entries427
FROM world_dialogue_edit_log428
ORDER BY edited_at DESC, log_id DESC429
LIMIT ?430
`).all(cap).map((row) => ({431
kind: "dialogue",432
scope: row.dialogue_id,433
editor_admin_id: row.editor_admin_id,434
edited_at: row.edited_at,435
diffEntries: JSON.parse(row.diff_entries),436
_key: row.log_id437
}));438
return [...chunkRows, ...settingsRows, ...questRows, ...dialogueRows]439
.sort((a, b) => (b.edited_at - a.edited_at) || (b._key - a._key))440
.slice(0, cap)441
.map(({ _key, ...entry }) => entry);442
}443
307
getActiveRevisionId ()444
getActiveRevisionId ()308
{445
{309
return this.db.prepare("SELECT value FROM world_meta WHERE key = 'active_revision'").get()?.value ?? null;446
return this.db.prepare("SELECT value FROM world_meta WHERE key = 'active_revision'").get()?.value ?? null;@@ -649,3 +786,21 @@ export class WorldDatabase649
this.db.close();786
this.db.close();650
}787
}651
}788
}789
790
function mapQuestLogRow (row)791
{792
return {793
...row,794
questId: row.quest_id,795
diffEntries: JSON.parse(row.diff_entries)796
};797
}798
799
function mapDialogueLogRow (row)800
{801
return {802
...row,803
dialogueId: row.dialogue_id,804
diffEntries: JSON.parse(row.diff_entries)805
};806
}@@ -0,0 +1,80 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import { mkdtempSync } from "node:fs";
4
import { tmpdir } from "node:os";
5
import { join } from "node:path";
6
import { WorldDatabase } from "../src/persistence/worldDb.js";
7
import { StateDatabase } from "../src/persistence/stateDb.js";
8
import { EditorService, diffQuests, diffDialogues } from "../src/editor/service.js";
9
import { normalizeQuestDef, normalizeDialogueTree } from "../../shared/quests/normalize.js";
10
11
function tempDirs ()
12
{
13
const dir = mkdtempSync(join(tmpdir(), "mmo-editor-log-"));
14
return {
15
worldDb: new WorldDatabase(join(dir, "world.sqlite")),
16
stateDb: new StateDatabase(join(dir, "state.sqlite"))
17
};
18
}
19
20
test("quest and dialogue diffs describe create and field edits", () =>
21
{
22
const created = diffQuests(null, normalizeQuestDef({ questId: "q1", title: "Fetch" }));
23
assert.match(created[0], /created/);
24
const previous = normalizeQuestDef({ questId: "q1", title: "Fetch", description: "A" });
25
const next = normalizeQuestDef({ questId: "q1", title: "Fetch more", description: "B", cancelable: true });
26
const bullets = diffQuests(previous, next);
27
assert.ok(bullets.some((line) => /Title/.test(line)));
28
assert.ok(bullets.some((line) => /Description/.test(line)));
29
assert.ok(bullets.some((line) => /Cancelable/.test(line)));
30
31
const dialogueCreated = diffDialogues(null, normalizeDialogueTree({ dialogueId: "d1", label: "Hi" }));
32
assert.match(dialogueCreated[0], /created/);
33
const prevTree = normalizeDialogueTree({ dialogueId: "d1", label: "Hi", unique: false });
34
const nextTree = normalizeDialogueTree({ dialogueId: "d1", label: "Hello", unique: true });
35
const dialogueBullets = diffDialogues(prevTree, nextTree);
36
assert.ok(dialogueBullets.some((line) => /Label/.test(line)));
37
assert.ok(dialogueBullets.some((line) => /Unique/.test(line)));
38
});
39
40
test("quest and dialogue saves append changelogs with usernames", () =>
41
{
42
const { worldDb, stateDb } = tempDirs();
43
try
44
{
45
stateDb.createAccount("auth:42", true, null, "timfa");
46
const editor = new EditorService(worldDb, stateDb);
47
const saved = editor.saveQuest({
48
questId: "welcome",
49
title: "Welcome",
50
description: "Say hi"
51
}, "auth:42");
52
assert.equal(saved.changelog.length, 1);
53
assert.equal(saved.changelog[0].editorDisplayName, "timfa");
54
assert.equal(saved.changelog[0].editor_admin_id, "auth:42");
55
assert.match(saved.changelog[0].diffEntries[0], /created/);
56
57
const dialogue = editor.saveDialogue({
58
dialogueId: "greeter",
59
label: "Greeter",
60
unique: true
61
}, "auth:42");
62
assert.equal(dialogue.changelog.length, 1);
63
assert.equal(dialogue.changelog[0].editorDisplayName, "timfa");
64
assert.match(dialogue.changelog[0].diffEntries[0], /created/);
65
66
editor.saveSettings({ nightDarkness: 0.2 }, "auth:42");
67
const global = editor.loadGlobalChangelog();
68
assert.ok(global.changelog.length >= 3);
69
assert.ok(global.changelog.every((entry) => entry.editorDisplayName === "timfa"));
70
assert.deepEqual(
71
new Set(global.changelog.map((entry) => entry.kind)),
72
new Set(["quest", "dialogue", "settings"])
73
);
74
}
75
finally
76
{
77
worldDb.close();
78
stateDb.close();
79
}
80
});
@@ -0,0 +1,80 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import { mkdtempSync } from "node:fs";4
import { tmpdir } from "node:os";5
import { join } from "node:path";6
import { WorldDatabase } from "../src/persistence/worldDb.js";7
import { StateDatabase } from "../src/persistence/stateDb.js";8
import { EditorService, diffQuests, diffDialogues } from "../src/editor/service.js";9
import { normalizeQuestDef, normalizeDialogueTree } from "../../shared/quests/normalize.js";10
11
function tempDirs ()12
{13
const dir = mkdtempSync(join(tmpdir(), "mmo-editor-log-"));14
return {15
worldDb: new WorldDatabase(join(dir, "world.sqlite")),16
stateDb: new StateDatabase(join(dir, "state.sqlite"))17
};18
}19
20
test("quest and dialogue diffs describe create and field edits", () =>21
{22
const created = diffQuests(null, normalizeQuestDef({ questId: "q1", title: "Fetch" }));23
assert.match(created[0], /created/);24
const previous = normalizeQuestDef({ questId: "q1", title: "Fetch", description: "A" });25
const next = normalizeQuestDef({ questId: "q1", title: "Fetch more", description: "B", cancelable: true });26
const bullets = diffQuests(previous, next);27
assert.ok(bullets.some((line) => /Title/.test(line)));28
assert.ok(bullets.some((line) => /Description/.test(line)));29
assert.ok(bullets.some((line) => /Cancelable/.test(line)));30
31
const dialogueCreated = diffDialogues(null, normalizeDialogueTree({ dialogueId: "d1", label: "Hi" }));32
assert.match(dialogueCreated[0], /created/);33
const prevTree = normalizeDialogueTree({ dialogueId: "d1", label: "Hi", unique: false });34
const nextTree = normalizeDialogueTree({ dialogueId: "d1", label: "Hello", unique: true });35
const dialogueBullets = diffDialogues(prevTree, nextTree);36
assert.ok(dialogueBullets.some((line) => /Label/.test(line)));37
assert.ok(dialogueBullets.some((line) => /Unique/.test(line)));38
});39
40
test("quest and dialogue saves append changelogs with usernames", () =>41
{42
const { worldDb, stateDb } = tempDirs();43
try44
{45
stateDb.createAccount("auth:42", true, null, "timfa");46
const editor = new EditorService(worldDb, stateDb);47
const saved = editor.saveQuest({48
questId: "welcome",49
title: "Welcome",50
description: "Say hi"51
}, "auth:42");52
assert.equal(saved.changelog.length, 1);53
assert.equal(saved.changelog[0].editorDisplayName, "timfa");54
assert.equal(saved.changelog[0].editor_admin_id, "auth:42");55
assert.match(saved.changelog[0].diffEntries[0], /created/);56
57
const dialogue = editor.saveDialogue({58
dialogueId: "greeter",59
label: "Greeter",60
unique: true61
}, "auth:42");62
assert.equal(dialogue.changelog.length, 1);63
assert.equal(dialogue.changelog[0].editorDisplayName, "timfa");64
assert.match(dialogue.changelog[0].diffEntries[0], /created/);65
66
editor.saveSettings({ nightDarkness: 0.2 }, "auth:42");67
const global = editor.loadGlobalChangelog();68
assert.ok(global.changelog.length >= 3);69
assert.ok(global.changelog.every((entry) => entry.editorDisplayName === "timfa"));70
assert.deepEqual(71
new Set(global.changelog.map((entry) => entry.kind)),72
new Set(["quest", "dialogue", "settings"])73
);74
}75
finally76
{77
worldDb.close();78
stateDb.close();79
}80
});