BlueGit

timfa questward

Show a 3x3 editor view with a red border on the selected chunk.

Co-authored-by: Cursor <cursoragent@cursor.com>

timfa Tim Falken · pushed by timfa

Authored 2026-08-24 · 2 months ago

Hash
2b7e9e503c86295271eb21a3dfbb69e0ad1184f8
Parent
05401546
6 files changed +146 −37
client/editor.html +2 −1
@@ -41,12 +41,13 @@
41 41 <label>Sim tick Hz <input id="tick-hz" type="number" min="5" step="1" value="20"></label>
42 42 <button id="save-settings" type="button">Save settings</button>
43 43 </fieldset>
44 <p class="hint">Saves write a pending revision. Apply now reloads the live world. Marketplace placement waits on assets.</p>
44 <p class="hint">The red border is the chunk you are editing. Neighbours are shown for alignment and lighting, but paint only applies inside the border. Saves write a pending revision. Apply now reloads the live world. Marketplace placement waits on assets.</p>
45 45 </aside>
46 46 <section id="changelog-wrap">
47 47 <h2>Changelog</h2>
48 48 <div id="changelog"></div>
49 49 </section>
50 <div id="selection-border" aria-hidden="true"></div>
50 51 <script src="/framework/framework.js"></script>
51 52 <script type="module" src="/src/editor/main.js"></script>
52 53 </body>
@@ -41,12 +41,13 @@
41 <label>Sim tick Hz <input id="tick-hz" type="number" min="5" step="1" value="20"></label>
41 <label>Sim tick Hz <input id="tick-hz" type="number" min="5" step="1" value="20"></label>
42 <button id="save-settings" type="button">Save settings</button>
42 <button id="save-settings" type="button">Save settings</button>
43 </fieldset>
43 </fieldset>
44 <p class="hint">Saves write a pending revision. Apply now reloads the live world. Marketplace placement waits on assets.</p>
44 <p class="hint">The red border is the chunk you are editing. Neighbours are shown for alignment and lighting, but paint only applies inside the border. Saves write a pending revision. Apply now reloads the live world. Marketplace placement waits on assets.</p>
45 </aside>
45 </aside>
46 <section id="changelog-wrap">
46 <section id="changelog-wrap">
47 <h2>Changelog</h2>
47 <h2>Changelog</h2>
48 <div id="changelog"></div>
48 <div id="changelog"></div>
49 </section>
49 </section>
50 <div id="selection-border" aria-hidden="true"></div>
50 <script src="/framework/framework.js"></script>
51 <script src="/framework/framework.js"></script>
51 <script type="module" src="/src/editor/main.js"></script>
52 <script type="module" src="/src/editor/main.js"></script>
52</body>
53</body>
client/src/editor/main.js +126 −31
@@ -1,5 +1,5 @@
1 import { MessageType, CHUNK_SIZE } from "/shared/protocol/constants.js";
2 import { GROUND_DEFINITIONS, BLOCK_DEFINITIONS, GroundType, BlockType } from "/shared/definitions/tiles.js";
1 import { MessageType, CHUNK_SIZE, SPRITE_SIZE_PX, VISIBLE_CHUNK_RADIUS } from "/shared/protocol/constants.js";
2 import { GROUND_DEFINITIONS, BLOCK_DEFINITIONS, GroundType } from "/shared/definitions/tiles.js";
3 3 import { GameSocket, defaultSocketUrl } from "../net/socket.js";
4 4 import { PLAY_IMAGES, assertSpriteSizes, useNearestNeighbour } from "../render/sprites.js";
5 5 import { WorldView } from "../render/worldView.js";
@@ -13,7 +13,7 @@ let chunkX = 0;
13 13 let chunkY = 0;
14 14 let tool = { kind: "ground", typeId: GroundType.grass };
15 15
16 function $(id)
16 function $ (id)
17 17 {
18 18 return document.getElementById(id);
19 19 }
@@ -27,6 +27,34 @@ function selectedToolLabel ()
27 27 return BLOCK_DEFINITIONS[tool.typeId].displayName;
28 28 }
29 29
30 function inEditorView (x, y)
31 {
32 return Math.abs(x - chunkX) <= VISIBLE_CHUNK_RADIUS && Math.abs(y - chunkY) <= VISIBLE_CHUNK_RADIUS;
33 }
34
35 function neighborhoodCoords (centerX, centerY)
36 {
37 const coords = [];
38 for (let dy = -VISIBLE_CHUNK_RADIUS; dy <= VISIBLE_CHUNK_RADIUS; dy++)
39 {
40 for (let dx = -VISIBLE_CHUNK_RADIUS; dx <= VISIBLE_CHUNK_RADIUS; dx++)
41 { coords.push({ chunkX: centerX + dx, chunkY: centerY + dy }); }
42 }
43 return coords;
44 }
45
46 function snapshotFromPayload (payload)
47 {
48 return {
49 chunkX: payload.chunkX,
50 chunkY: payload.chunkY,
51 grounds: payload.data.grounds,
52 blocks: payload.data.blocks,
53 light: payload.data.light,
54 entities: []
55 };
56 }
57
30 58 function paintAt (localX, localY)
31 59 {
32 60 if (!draft || localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)
@@ -48,7 +76,7 @@ function paintAt (localX, localY)
48 76 });
49 77 }
50 78
51 function showChunk (payload)
79 function showSelectedChunk (payload)
52 80 {
53 81 draft = {
54 82 open: payload.data.open,
@@ -56,9 +84,7 @@ function showChunk (payload)
56 84 blocks: payload.data.blocks.map((block) => (block ? { ...block } : null)),
57 85 light: payload.data.light.slice()
58 86 };
59 chunkX = payload.chunkX;
60 chunkY = payload.chunkY;
61 $("coords").textContent = `${chunkX}, ${chunkY}`;
87 $("coords").textContent = `${payload.chunkX}, ${payload.chunkY}`;
62 88 $("open").checked = draft.open;
63 89 $("revision").textContent = `active ${payload.activeRevisionId}` +
64 90 (payload.pendingRevisionId ? ` · pending ${payload.pendingRevisionId}` : " · no pending revision");
@@ -79,41 +105,102 @@ function showChunk (payload)
79 105 item.append(list);
80 106 log.append(item);
81 107 }
82 view.applySnapshot({
83 chunkX,
84 chunkY,
85 grounds: draft.grounds,
86 blocks: draft.blocks,
87 light: draft.light,
88 entities: []
89 });
90 frameChunk();
108 view.applySnapshot(snapshotFromPayload(payload));
109 }
110
111 function pruneView ()
112 {
113 for (const key of [...view.chunks.keys()])
114 {
115 const [x, y] = key.split(",").map(Number);
116 if (!inEditorView(x, y))
117 { view.removeChunk(x, y); }
118 }
91 119 }
92 120
93 function frameChunk ()
121 function frameNeighborhood ()
94 122 {
95 123 const size = view.tileSize();
96 124 view.followPlayer = false;
97 view.scene.cameraPosition.x = 24 - (chunkX * CHUNK_SIZE * size);
98 view.scene.cameraPosition.y = 24 - (chunkY * CHUNK_SIZE * size);
125 const centerX = (chunkX + 0.5) * CHUNK_SIZE * size;
126 const centerY = (chunkY + 0.5) * CHUNK_SIZE * size;
127 view.scene.cameraPosition.x = view.scene.real_size.x / 2 - centerX;
128 view.scene.cameraPosition.y = view.scene.real_size.y / 2 - centerY;
129 updateSelectionBorder();
130 }
131
132 function updateSelectionBorder ()
133 {
134 const border = $("selection-border");
135 const canvas = scene?.canvas;
136 if (!border || !canvas)
137 { return; }
138
139 const rect = canvas.getBoundingClientRect();
140 const size = view.tileSize();
141 const chunkPx = CHUNK_SIZE * size;
142 const screenLeft = chunkX * CHUNK_SIZE * size + scene.cameraPosition.x;
143 const screenTop = chunkY * CHUNK_SIZE * size + scene.cameraPosition.y;
144 border.style.left = `${rect.left + screenLeft}px`;
145 border.style.top = `${rect.top + screenTop}px`;
146 border.style.width = `${chunkPx}px`;
147 border.style.height = `${chunkPx}px`;
148 }
149
150 function layoutScene ()
151 {
152 const header = document.querySelector("header");
153 const aside = document.querySelector("aside");
154 const changelog = $("changelog-wrap");
155 const top = header.offsetHeight;
156 aside.style.top = `${top}px`;
157 changelog.style.top = `${top}px`;
158 const left = aside.offsetWidth;
159 const right = changelog.offsetWidth;
160 const width = Math.max(64, window.innerWidth - left - right);
161 const height = Math.max(64, window.innerHeight - top);
162 scene.position.x = left;
163 scene.position.y = top;
164 scene.size.x = width;
165 scene.size.y = height;
166 scene.g_fixSize();
167 useNearestNeighbour(scene, game.images);
168 const fit = Math.min(width, height) / (CHUNK_SIZE * 3 * SPRITE_SIZE_PX);
169 view.setZoom(fit, { min: 0.5, max: 4 });
170 frameNeighborhood();
171 }
172
173 function requestChunks (coords)
174 {
175 for (const coord of coords)
176 {
177 socket.send({ type: MessageType.editorLoadChunk, chunkX: coord.chunkX, chunkY: coord.chunkY });
178 }
179 }
180
181 function loadNeighborhood (x, y)
182 {
183 chunkX = x;
184 chunkY = y;
185 $("coords").textContent = `${chunkX}, ${chunkY}`;
186 requestChunks(neighborhoodCoords(x, y));
99 187 }
100 188
101 function loadChunk (x, y)
189 function requestNeighbors ()
102 190 {
103 socket.send({ type: MessageType.editorLoadChunk, chunkX: x, chunkY: y });
191 requestChunks(neighborhoodCoords(chunkX, chunkY).filter((coord) => coord.chunkX !== chunkX || coord.chunkY !== chunkY));
104 192 }
105 193
106 194 async function main ()
107 195 {
108 196 await game.preloadImages(PLAY_IMAGES);
109 197 assertSpriteSizes(game.images);
110 const canvasSize = CHUNK_SIZE * 16 * 2 + 48;
111 scene = new Scene(260, 56, canvasSize, canvasSize);
198 scene = new Scene(250, 56, 64, 64);
112 199 game.loadScene(scene);
113 200 useNearestNeighbour(scene, game.images);
114 201 view = new WorldView(game, scene);
115 202 view.followPlayer = false;
116 view.setZoom(2);
203 layoutScene();
117 204 const ticker = new GameObject(0, 0, null, 10);
118 205 ticker.update = (dt) =>
119 206 {
@@ -130,17 +217,18 @@ async function main ()
130 217 }
131 218 }
132 219 view.update(dt);
133 frameChunk();
220 frameNeighborhood();
134 221 };
135 222 scene.addObject(ticker);
136 223 game.startGame();
224 window.addEventListener("resize", layoutScene);
137 225
138 226 socket = new GameSocket(defaultSocketUrl(), (message) =>
139 227 {
140 228 if (message.type === MessageType.session)
141 229 {
142 230 $("who").textContent = `${message.authSubject}${message.isAdmin ? " · admin" : ""}`;
143 loadChunk(0, 0);
231 loadNeighborhood(0, 0);
144 232 }
145 233 else if (message.type === MessageType.editorChunk)
146 234 {
@@ -149,7 +237,13 @@ async function main ()
149 237 $("revision").textContent = `settings saved on pending ${message.settingsSaved.revisionId}`;
150 238 return;
151 239 }
152 showChunk(message);
240 if (!inEditorView(message.chunkX, message.chunkY))
241 { return; }
242 if (message.chunkX === chunkX && message.chunkY === chunkY)
243 { showSelectedChunk(message); }
244 else
245 { view.applySnapshot(snapshotFromPayload(message)); }
246 pruneView();
153 247 }
154 248 else if (message.type === MessageType.error)
155 249 { $("error").textContent = message.message; }
@@ -167,10 +261,10 @@ document.querySelectorAll("[data-tool]").forEach((button) =>
167 261 });
168 262 });
169 263
170 $("north").addEventListener("click", () => loadChunk(chunkX, chunkY - 1));
171 $("south").addEventListener("click", () => loadChunk(chunkX, chunkY + 1));
172 $("west").addEventListener("click", () => loadChunk(chunkX - 1, chunkY));
173 $("east").addEventListener("click", () => loadChunk(chunkX + 1, chunkY));
264 $("north").addEventListener("click", () => loadNeighborhood(chunkX, chunkY - 1));
265 $("south").addEventListener("click", () => loadNeighborhood(chunkX, chunkY + 1));
266 $("west").addEventListener("click", () => loadNeighborhood(chunkX - 1, chunkY));
267 $("east").addEventListener("click", () => loadNeighborhood(chunkX + 1, chunkY));
174 268 $("open").addEventListener("change", () =>
175 269 {
176 270 if (draft)
@@ -185,6 +279,7 @@ $("save").addEventListener("click", () =>
185 279 chunkY,
186 280 draft: { open: $("open").checked, grounds: draft.grounds, blocks: draft.blocks }
187 281 });
282 requestNeighbors();
188 283 });
189 284 $("apply").addEventListener("click", () => socket.send({ type: MessageType.editorApplyRevision }));
190 285 $("night").addEventListener("input", () =>
@@ -1,5 +1,5 @@
1import { MessageType, CHUNK_SIZE } from "/shared/protocol/constants.js";
1import { MessageType, CHUNK_SIZE, SPRITE_SIZE_PX, VISIBLE_CHUNK_RADIUS } from "/shared/protocol/constants.js";
2import { GROUND_DEFINITIONS, BLOCK_DEFINITIONS, GroundType, BlockType } from "/shared/definitions/tiles.js";
2import { GROUND_DEFINITIONS, BLOCK_DEFINITIONS, GroundType } from "/shared/definitions/tiles.js";
3import { GameSocket, defaultSocketUrl } from "../net/socket.js";
3import { GameSocket, defaultSocketUrl } from "../net/socket.js";
4import { PLAY_IMAGES, assertSpriteSizes, useNearestNeighbour } from "../render/sprites.js";
4import { PLAY_IMAGES, assertSpriteSizes, useNearestNeighbour } from "../render/sprites.js";
5import { WorldView } from "../render/worldView.js";
5import { WorldView } from "../render/worldView.js";
@@ -13,7 +13,7 @@ let chunkX = 0;
13let chunkY = 0;
13let chunkY = 0;
14let tool = { kind: "ground", typeId: GroundType.grass };
14let tool = { kind: "ground", typeId: GroundType.grass };
15
15
16function $(id)
16function $ (id)
17{
17{
18 return document.getElementById(id);
18 return document.getElementById(id);
19}
19}
@@ -27,6 +27,34 @@ function selectedToolLabel ()
27 return BLOCK_DEFINITIONS[tool.typeId].displayName;
27 return BLOCK_DEFINITIONS[tool.typeId].displayName;
28}
28}
29
29
30function inEditorView (x, y)
31{
32 return Math.abs(x - chunkX) <= VISIBLE_CHUNK_RADIUS && Math.abs(y - chunkY) <= VISIBLE_CHUNK_RADIUS;
33}
34
35function neighborhoodCoords (centerX, centerY)
36{
37 const coords = [];
38 for (let dy = -VISIBLE_CHUNK_RADIUS; dy <= VISIBLE_CHUNK_RADIUS; dy++)
39 {
40 for (let dx = -VISIBLE_CHUNK_RADIUS; dx <= VISIBLE_CHUNK_RADIUS; dx++)
41 { coords.push({ chunkX: centerX + dx, chunkY: centerY + dy }); }
42 }
43 return coords;
44}
45
46function snapshotFromPayload (payload)
47{
48 return {
49 chunkX: payload.chunkX,
50 chunkY: payload.chunkY,
51 grounds: payload.data.grounds,
52 blocks: payload.data.blocks,
53 light: payload.data.light,
54 entities: []
55 };
56}
57
30function paintAt (localX, localY)
58function paintAt (localX, localY)
31{
59{
32 if (!draft || localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)
60 if (!draft || localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)
@@ -48,7 +76,7 @@ function paintAt (localX, localY)
48 });
76 });
49}
77}
50
78
51function showChunk (payload)
79function showSelectedChunk (payload)
52{
80{
53 draft = {
81 draft = {
54 open: payload.data.open,
82 open: payload.data.open,
@@ -56,9 +84,7 @@ function showChunk (payload)
56 blocks: payload.data.blocks.map((block) => (block ? { ...block } : null)),
84 blocks: payload.data.blocks.map((block) => (block ? { ...block } : null)),
57 light: payload.data.light.slice()
85 light: payload.data.light.slice()
58 };
86 };
59 chunkX = payload.chunkX;
87 $("coords").textContent = `${payload.chunkX}, ${payload.chunkY}`;
60 chunkY = payload.chunkY;
61 $("coords").textContent = `${chunkX}, ${chunkY}`;
62 $("open").checked = draft.open;
88 $("open").checked = draft.open;
63 $("revision").textContent = `active ${payload.activeRevisionId}` +
89 $("revision").textContent = `active ${payload.activeRevisionId}` +
64 (payload.pendingRevisionId ? ` · pending ${payload.pendingRevisionId}` : " · no pending revision");
90 (payload.pendingRevisionId ? ` · pending ${payload.pendingRevisionId}` : " · no pending revision");
@@ -79,41 +105,102 @@ function showChunk (payload)
79 item.append(list);
105 item.append(list);
80 log.append(item);
106 log.append(item);
81 }
107 }
82 view.applySnapshot({
108 view.applySnapshot(snapshotFromPayload(payload));
83 chunkX,
109}
84 chunkY,
110
85 grounds: draft.grounds,
111function pruneView ()
86 blocks: draft.blocks,
112{
87 light: draft.light,
113 for (const key of [...view.chunks.keys()])
88 entities: []
114 {
89 });
115 const [x, y] = key.split(",").map(Number);
90 frameChunk();
116 if (!inEditorView(x, y))
117 { view.removeChunk(x, y); }
118 }
91}
119}
92
120
93function frameChunk ()
121function frameNeighborhood ()
94{
122{
95 const size = view.tileSize();
123 const size = view.tileSize();
96 view.followPlayer = false;
124 view.followPlayer = false;
97 view.scene.cameraPosition.x = 24 - (chunkX * CHUNK_SIZE * size);
125 const centerX = (chunkX + 0.5) * CHUNK_SIZE * size;
98 view.scene.cameraPosition.y = 24 - (chunkY * CHUNK_SIZE * size);
126 const centerY = (chunkY + 0.5) * CHUNK_SIZE * size;
127 view.scene.cameraPosition.x = view.scene.real_size.x / 2 - centerX;
128 view.scene.cameraPosition.y = view.scene.real_size.y / 2 - centerY;
129 updateSelectionBorder();
130}
131
132function updateSelectionBorder ()
133{
134 const border = $("selection-border");
135 const canvas = scene?.canvas;
136 if (!border || !canvas)
137 { return; }
138
139 const rect = canvas.getBoundingClientRect();
140 const size = view.tileSize();
141 const chunkPx = CHUNK_SIZE * size;
142 const screenLeft = chunkX * CHUNK_SIZE * size + scene.cameraPosition.x;
143 const screenTop = chunkY * CHUNK_SIZE * size + scene.cameraPosition.y;
144 border.style.left = `${rect.left + screenLeft}px`;
145 border.style.top = `${rect.top + screenTop}px`;
146 border.style.width = `${chunkPx}px`;
147 border.style.height = `${chunkPx}px`;
148}
149
150function layoutScene ()
151{
152 const header = document.querySelector("header");
153 const aside = document.querySelector("aside");
154 const changelog = $("changelog-wrap");
155 const top = header.offsetHeight;
156 aside.style.top = `${top}px`;
157 changelog.style.top = `${top}px`;
158 const left = aside.offsetWidth;
159 const right = changelog.offsetWidth;
160 const width = Math.max(64, window.innerWidth - left - right);
161 const height = Math.max(64, window.innerHeight - top);
162 scene.position.x = left;
163 scene.position.y = top;
164 scene.size.x = width;
165 scene.size.y = height;
166 scene.g_fixSize();
167 useNearestNeighbour(scene, game.images);
168 const fit = Math.min(width, height) / (CHUNK_SIZE * 3 * SPRITE_SIZE_PX);
169 view.setZoom(fit, { min: 0.5, max: 4 });
170 frameNeighborhood();
171}
172
173function requestChunks (coords)
174{
175 for (const coord of coords)
176 {
177 socket.send({ type: MessageType.editorLoadChunk, chunkX: coord.chunkX, chunkY: coord.chunkY });
178 }
179}
180
181function loadNeighborhood (x, y)
182{
183 chunkX = x;
184 chunkY = y;
185 $("coords").textContent = `${chunkX}, ${chunkY}`;
186 requestChunks(neighborhoodCoords(x, y));
99}
187}
100
188
101function loadChunk (x, y)
189function requestNeighbors ()
102{
190{
103 socket.send({ type: MessageType.editorLoadChunk, chunkX: x, chunkY: y });
191 requestChunks(neighborhoodCoords(chunkX, chunkY).filter((coord) => coord.chunkX !== chunkX || coord.chunkY !== chunkY));
104}
192}
105
193
106async function main ()
194async function main ()
107{
195{
108 await game.preloadImages(PLAY_IMAGES);
196 await game.preloadImages(PLAY_IMAGES);
109 assertSpriteSizes(game.images);
197 assertSpriteSizes(game.images);
110 const canvasSize = CHUNK_SIZE * 16 * 2 + 48;
198 scene = new Scene(250, 56, 64, 64);
111 scene = new Scene(260, 56, canvasSize, canvasSize);
112 game.loadScene(scene);
199 game.loadScene(scene);
113 useNearestNeighbour(scene, game.images);
200 useNearestNeighbour(scene, game.images);
114 view = new WorldView(game, scene);
201 view = new WorldView(game, scene);
115 view.followPlayer = false;
202 view.followPlayer = false;
116 view.setZoom(2);
203 layoutScene();
117 const ticker = new GameObject(0, 0, null, 10);
204 const ticker = new GameObject(0, 0, null, 10);
118 ticker.update = (dt) =>
205 ticker.update = (dt) =>
119 {
206 {
@@ -130,17 +217,18 @@ async function main ()
130 }
217 }
131 }
218 }
132 view.update(dt);
219 view.update(dt);
133 frameChunk();
220 frameNeighborhood();
134 };
221 };
135 scene.addObject(ticker);
222 scene.addObject(ticker);
136 game.startGame();
223 game.startGame();
224 window.addEventListener("resize", layoutScene);
137
225
138 socket = new GameSocket(defaultSocketUrl(), (message) =>
226 socket = new GameSocket(defaultSocketUrl(), (message) =>
139 {
227 {
140 if (message.type === MessageType.session)
228 if (message.type === MessageType.session)
141 {
229 {
142 $("who").textContent = `${message.authSubject}${message.isAdmin ? " · admin" : ""}`;
230 $("who").textContent = `${message.authSubject}${message.isAdmin ? " · admin" : ""}`;
143 loadChunk(0, 0);
231 loadNeighborhood(0, 0);
144 }
232 }
145 else if (message.type === MessageType.editorChunk)
233 else if (message.type === MessageType.editorChunk)
146 {
234 {
@@ -149,7 +237,13 @@ async function main ()
149 $("revision").textContent = `settings saved on pending ${message.settingsSaved.revisionId}`;
237 $("revision").textContent = `settings saved on pending ${message.settingsSaved.revisionId}`;
150 return;
238 return;
151 }
239 }
152 showChunk(message);
240 if (!inEditorView(message.chunkX, message.chunkY))
241 { return; }
242 if (message.chunkX === chunkX && message.chunkY === chunkY)
243 { showSelectedChunk(message); }
244 else
245 { view.applySnapshot(snapshotFromPayload(message)); }
246 pruneView();
153 }
247 }
154 else if (message.type === MessageType.error)
248 else if (message.type === MessageType.error)
155 { $("error").textContent = message.message; }
249 { $("error").textContent = message.message; }
@@ -167,10 +261,10 @@ document.querySelectorAll("[data-tool]").forEach((button) =>
167 });
261 });
168});
262});
169
263
170$("north").addEventListener("click", () => loadChunk(chunkX, chunkY - 1));
264$("north").addEventListener("click", () => loadNeighborhood(chunkX, chunkY - 1));
171$("south").addEventListener("click", () => loadChunk(chunkX, chunkY + 1));
265$("south").addEventListener("click", () => loadNeighborhood(chunkX, chunkY + 1));
172$("west").addEventListener("click", () => loadChunk(chunkX - 1, chunkY));
266$("west").addEventListener("click", () => loadNeighborhood(chunkX - 1, chunkY));
173$("east").addEventListener("click", () => loadChunk(chunkX + 1, chunkY));
267$("east").addEventListener("click", () => loadNeighborhood(chunkX + 1, chunkY));
174$("open").addEventListener("change", () =>
268$("open").addEventListener("change", () =>
175{
269{
176 if (draft)
270 if (draft)
@@ -185,6 +279,7 @@ $("save").addEventListener("click", () =>
185 chunkY,
279 chunkY,
186 draft: { open: $("open").checked, grounds: draft.grounds, blocks: draft.blocks }
280 draft: { open: $("open").checked, grounds: draft.grounds, blocks: draft.blocks }
187 });
281 });
282 requestNeighbors();
188});
283});
189$("apply").addEventListener("click", () => socket.send({ type: MessageType.editorApplyRevision }));
284$("apply").addEventListener("click", () => socket.send({ type: MessageType.editorApplyRevision }));
190$("night").addEventListener("input", () =>
285$("night").addEventListener("input", () =>
client/src/render/worldView.js +4 −2
@@ -89,9 +89,11 @@ export class WorldView
89 89 this.entities.delete(entityId);
90 90 }
91 91
92 setZoom (zoom)
92 setZoom (zoom, limits = { min: 1, max: 4 })
93 93 {
94 this.zoom = Math.min(4, Math.max(1, zoom));
94 const min = limits.min ?? 1;
95 const max = limits.max ?? 4;
96 this.zoom = Math.min(max, Math.max(min, zoom));
95 97 for (const snapshot of this.chunks.values())
96 98 { this.#rebuildChunk(snapshot); }
97 99 const size = this.tileSize();
@@ -89,9 +89,11 @@ export class WorldView
89 this.entities.delete(entityId);
89 this.entities.delete(entityId);
90 }
90 }
91
91
92 setZoom (zoom)
92 setZoom (zoom, limits = { min: 1, max: 4 })
93 {
93 {
94 this.zoom = Math.min(4, Math.max(1, zoom));
94 const min = limits.min ?? 1;
95 const max = limits.max ?? 4;
96 this.zoom = Math.min(max, Math.max(min, zoom));
95 for (const snapshot of this.chunks.values())
97 for (const snapshot of this.chunks.values())
96 { this.#rebuildChunk(snapshot); }
98 { this.#rebuildChunk(snapshot); }
97 const size = this.tileSize();
99 const size = this.tileSize();
client/ui/editor.css +8 −1
@@ -62,4 +62,11 @@ button { cursor: pointer; }
62 62 .open-toggle { display: flex; gap: 0.4rem; align-items: center; }
63 63 article { margin-bottom: 0.75rem; }
64 64 fieldset { border-color: #3a4250; margin-top: 1rem; }
65 label { display: block; margin: 0.4rem 0; }
65 #selection-border {
66 position: fixed;
67 pointer-events: none;
68 box-sizing: border-box;
69 border: 2px solid #e23d3d;
70 box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
71 z-index: 4;
72 }
@@ -62,4 +62,11 @@ button { cursor: pointer; }
62.open-toggle { display: flex; gap: 0.4rem; align-items: center; }
62.open-toggle { display: flex; gap: 0.4rem; align-items: center; }
63article { margin-bottom: 0.75rem; }
63article { margin-bottom: 0.75rem; }
64fieldset { border-color: #3a4250; margin-top: 1rem; }
64fieldset { border-color: #3a4250; margin-top: 1rem; }
65label { display: block; margin: 0.4rem 0; }
65#selection-border {
66 position: fixed;
67 pointer-events: none;
68 box-sizing: border-box;
69 border: 2px solid #e23d3d;
70 box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
71 z-index: 4;
72}
docs/FEATURES.md +1 −1
@@ -70,7 +70,7 @@ Each entry is a short note on behaviour and where the code lives. Update this fi
70 70 ## World editor (client)
71 71
72 72 **Status:** full
73 **Spec:** Separate `/editor` page. One chunk at a time, chunk-step navigation, paint palette (grass, wood, wall, torch, erase), open/closed, changelog, night preview slider, settings fields, save and Apply now. Marketplace placement waits on assets.
73 **Spec:** Separate `/editor` page. 3×3 chunk view with the selected chunk centred and outlined in red. Chunk-step navigation, paint only inside the selected chunk, open/closed, changelog, night preview slider, settings fields, save and Apply now. Marketplace placement waits on assets.
74 74 **Code:** `client/editor.html`, `client/src/editor/main.js`, `client/ui/editor.css`
75 75
76 76 ## Per-chunk changelog
@@ -70,7 +70,7 @@ Each entry is a short note on behaviour and where the code lives. Update this fi
70## World editor (client)
70## World editor (client)
71
71
72**Status:** full
72**Status:** full
73**Spec:** Separate `/editor` page. One chunk at a time, chunk-step navigation, paint palette (grass, wood, wall, torch, erase), open/closed, changelog, night preview slider, settings fields, save and Apply now. Marketplace placement waits on assets.
73**Spec:** Separate `/editor` page. 3×3 chunk view with the selected chunk centred and outlined in red. Chunk-step navigation, paint only inside the selected chunk, open/closed, changelog, night preview slider, settings fields, save and Apply now. Marketplace placement waits on assets.
74**Code:** `client/editor.html`, `client/src/editor/main.js`, `client/ui/editor.css`
74**Code:** `client/editor.html`, `client/src/editor/main.js`, `client/ui/editor.css`
75
75
76## Per-chunk changelog
76## Per-chunk changelog
tile_mmo_server_technical_design_v0.6.md +5 −1
@@ -377,7 +377,11 @@ state, not a per-tick synchronisation mechanism.
377 377 The server includes a separate admin-only world editor UI. It is not
378 378 part of the normal player client.
379 379
380 - Display one 16×16 chunk at a time.
380 - Display a 3×3 of 16×16 chunks, with the currently selected
381 chunk in the centre and a red border around that chunk.
382 Painting, open/closed, and changelog apply only to the
383 selected chunk; neighbours are visible for alignment and
384 baked lighting context.
381 385
382 386 - Provide Up, Down, Left and Right navigation buttons that move the
383 387 editor exactly one chunk in that direction.
@@ -377,7 +377,11 @@ state, not a per-tick synchronisation mechanism.
377The server includes a separate admin-only world editor UI. It is not
377The server includes a separate admin-only world editor UI. It is not
378part of the normal player client.
378part of the normal player client.
379
379
380- Display one 16×16 chunk at a time.
380- Display a 3×3 of 16×16 chunks, with the currently selected
381 chunk in the centre and a red border around that chunk.
382 Painting, open/closed, and changelog apply only to the
383 selected chunk; neighbours are visible for alignment and
384 baked lighting context.
381
385
382- Provide Up, Down, Left and Right navigation buttons that move the
386- Provide Up, Down, Left and Right navigation buttons that move the
383 editor exactly one chunk in that direction.
387 editor exactly one chunk in that direction.