vibedgames 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/assets/align-framing.py +242 -0
- package/assets/render-model.py +406 -0
- package/assets/tilemap-editor.html +630 -0
- package/dist/THIRD_PARTY_NOTICES.txt +2 -2
- package/dist/{chunk-56OY4TEP.js → chunk-2SBBKY5C.js} +1361 -4493
- package/dist/{chunk-FC233UKH.js → chunk-2ZKS7V72.js} +16 -16
- package/dist/chunk-37LLKM73.js +124 -0
- package/dist/{chunk-BMTHAVMS.js → chunk-3HGBIUM5.js} +22 -19
- package/dist/chunk-3UGGMFJJ.js +22 -0
- package/dist/{chunk-3HUWAJQH.js → chunk-42K3BJJH.js} +93 -76
- package/dist/{chunk-ST5FC2W3.js → chunk-43P4U7CB.js} +20 -11
- package/dist/chunk-4RYTTD4D.js +53 -0
- package/dist/{chunk-WSRIF6K4.js → chunk-4UU622RK.js} +5 -4
- package/dist/chunk-52E6EKZV.js +72 -0
- package/dist/chunk-6IUFHPMV.js +62 -0
- package/dist/chunk-6KXXZXSO.js +475 -0
- package/dist/chunk-72KHWZMN.js +87 -0
- package/dist/{chunk-ZCYWDKYP.js → chunk-A556KALN.js} +14 -13
- package/dist/{chunk-UFR6G6BL.js → chunk-ABTUEIRC.js} +554 -254
- package/dist/chunk-ALPTHSUT.js +132 -0
- package/dist/{chunk-PEUP4MZR.js → chunk-AWJNAGPE.js} +6 -3
- package/dist/chunk-BJAN3RMY.js +48 -0
- package/dist/{chunk-HNRVSBRK.js → chunk-BN3Q7UEC.js} +20 -17
- package/dist/chunk-BZOMEG3X.js +412 -0
- package/dist/{chunk-ZYCSYJWX.js → chunk-COSLGSVO.js} +14 -24
- package/dist/{chunk-KZBZNTM4.js → chunk-CTY2WZQK.js} +9 -13
- package/dist/chunk-DH6WPL3X.js +47 -0
- package/dist/chunk-DPLFCKXP.js +80 -0
- package/dist/{chunk-K2U7L4RU.js → chunk-E3FJUPLT.js} +15 -21
- package/dist/chunk-E7NDOZ27.js +428 -0
- package/dist/{chunk-TBQ5BU3Q.js → chunk-F42QKWBB.js} +18 -18
- package/dist/chunk-F4J6XCHT.js +73 -0
- package/dist/chunk-FB3UDZAV.js +168 -0
- package/dist/chunk-FJXPMA63.js +48 -0
- package/dist/chunk-FNJL6Z5C.js +71 -0
- package/dist/chunk-G63MXDX2.js +45 -0
- package/dist/{chunk-VFFOT7KD.js → chunk-G66HRVDW.js} +1 -1
- package/dist/{chunk-AXTLPJ2F.js → chunk-H2C4QUTG.js} +8 -7
- package/dist/{chunk-H3IPLBXQ.js → chunk-HRKVAXNN.js} +17 -14
- package/dist/chunk-HSCTPDEU.js +126 -0
- package/dist/{chunk-UXCWSWWX.js → chunk-HSMG6U7J.js} +8 -7
- package/dist/chunk-I5LELJSK.js +22 -0
- package/dist/{chunk-7CXMMC5S.js → chunk-JN4WZCR7.js} +5 -4
- package/dist/{chunk-7QZSDU52.js → chunk-K36EOII3.js} +5 -4
- package/dist/chunk-KLFBAFXD.js +25 -0
- package/dist/{chunk-355VG7EO.js → chunk-LONQWRTR.js} +107 -77
- package/dist/{chunk-Z5TFZQ5U.js → chunk-LORGE2NB.js} +68 -62
- package/dist/{chunk-LY2GQ32S.js → chunk-MEAO33XW.js} +22 -20
- package/dist/{chunk-OD2MNYXD.js → chunk-MR5KIFI7.js} +23 -22
- package/dist/{chunk-2VUUMXAQ.js → chunk-N2UHAQXC.js} +18 -11
- package/dist/chunk-NG2X3SMF.js +91 -0
- package/dist/chunk-OFJIG4K3.js +6482 -0
- package/dist/chunk-P74GTK23.js +91 -0
- package/dist/chunk-PKM3JOKQ.js +62 -0
- package/dist/{chunk-NDHXM4PL.js → chunk-Q3XQPNF6.js} +12 -12
- package/dist/{chunk-RXHTGX7C.js → chunk-Q5NZNXJE.js} +6 -10
- package/dist/chunk-QEKVZ7BX.js +57 -0
- package/dist/chunk-QNWCBPVO.js +215 -0
- package/dist/{chunk-US6QZICZ.js → chunk-RPJR3S5S.js} +32 -18
- package/dist/chunk-RPSUFZAG.js +3307 -0
- package/dist/chunk-RRI23NK2.js +40 -0
- package/dist/{chunk-6EWHKL7Z.js → chunk-SXYQL4GK.js} +7 -6
- package/dist/{chunk-ZI6PKVXG.js → chunk-TMPBGXT4.js} +6 -5
- package/dist/{chunk-UZM6OSW5.js → chunk-UPHB5HWO.js} +15 -13
- package/dist/chunk-UTSSDFQL.js +64 -0
- package/dist/chunk-V5ADM3WC.js +741 -0
- package/dist/{chunk-25BAMW5X.js → chunk-VIEKOGKG.js} +18 -2
- package/dist/chunk-VUV5U4J5.js +117 -0
- package/dist/{chunk-LXS3NJYD.js → chunk-VZEJ2ZHE.js} +14 -15
- package/dist/chunk-W2QPNAZ3.js +58 -0
- package/dist/chunk-YLUB6252.js +45 -0
- package/dist/{chunk-Z4Z24FWO.js → chunk-YNCYMWER.js} +8 -5
- package/dist/chunk-YXOGRERG.js +91 -0
- package/dist/index.js +39 -36
- package/package.json +31 -16
- package/templates/none/src/main.ts +4 -0
- package/templates/none/vite.config.ts +0 -2
- package/templates/phaser/src/main.ts +0 -1
- package/templates/phaser/src/scenes/game-scene.ts +10 -8
- package/templates/phaser/vite.config.ts +0 -2
- package/templates/react-r3f/src/app.tsx +3 -1
- package/templates/react-r3f/src/main.tsx +1 -0
- package/templates/react-r3f/vite.config.ts +0 -2
- package/templates/threejs/src/main.ts +10 -1
- package/templates/threejs/vite.config.ts +0 -2
- package/LICENSE +0 -21
- package/dist/chunk-J6PKNPI2.js +0 -26
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Tilemap Editor</title>
|
|
7
|
+
<!-- Empty, so the browser doesn't request a favicon the server would (correctly) refuse. -->
|
|
8
|
+
<link rel="icon" href="data:," />
|
|
9
|
+
<style>
|
|
10
|
+
:root {
|
|
11
|
+
--bg: #0f1114;
|
|
12
|
+
--panel: #15171a;
|
|
13
|
+
--line: #2a2f36;
|
|
14
|
+
--ink: #e8e8e8;
|
|
15
|
+
--dim: #9aa4b0;
|
|
16
|
+
--accent: #5ec8f5;
|
|
17
|
+
--warn: #f5a25e;
|
|
18
|
+
color-scheme: dark;
|
|
19
|
+
}
|
|
20
|
+
* {
|
|
21
|
+
box-sizing: border-box;
|
|
22
|
+
}
|
|
23
|
+
body {
|
|
24
|
+
margin: 0;
|
|
25
|
+
height: 100vh;
|
|
26
|
+
display: grid;
|
|
27
|
+
grid-template-columns: minmax(280px, 26vw) 1fr;
|
|
28
|
+
background: var(--bg);
|
|
29
|
+
color: var(--ink);
|
|
30
|
+
font:
|
|
31
|
+
13px/1.45 ui-monospace,
|
|
32
|
+
SFMono-Regular,
|
|
33
|
+
Menlo,
|
|
34
|
+
monospace;
|
|
35
|
+
}
|
|
36
|
+
aside,
|
|
37
|
+
main {
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-direction: column;
|
|
40
|
+
min-width: 0;
|
|
41
|
+
min-height: 0;
|
|
42
|
+
padding: 10px;
|
|
43
|
+
gap: 8px;
|
|
44
|
+
}
|
|
45
|
+
aside {
|
|
46
|
+
background: var(--panel);
|
|
47
|
+
border-right: 1px solid var(--line);
|
|
48
|
+
}
|
|
49
|
+
.row {
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
gap: 6px;
|
|
53
|
+
flex-wrap: wrap;
|
|
54
|
+
}
|
|
55
|
+
label {
|
|
56
|
+
color: var(--dim);
|
|
57
|
+
}
|
|
58
|
+
select,
|
|
59
|
+
input,
|
|
60
|
+
button {
|
|
61
|
+
font: inherit;
|
|
62
|
+
background: #1c2026;
|
|
63
|
+
color: var(--ink);
|
|
64
|
+
border: 1px solid var(--line);
|
|
65
|
+
border-radius: 4px;
|
|
66
|
+
padding: 4px 7px;
|
|
67
|
+
}
|
|
68
|
+
button:hover:not(:disabled) {
|
|
69
|
+
border-color: var(--accent);
|
|
70
|
+
cursor: pointer;
|
|
71
|
+
}
|
|
72
|
+
button:disabled {
|
|
73
|
+
opacity: 0.5;
|
|
74
|
+
}
|
|
75
|
+
input[type="text"] {
|
|
76
|
+
flex: 1;
|
|
77
|
+
min-width: 8ch;
|
|
78
|
+
}
|
|
79
|
+
.surface {
|
|
80
|
+
flex: 1;
|
|
81
|
+
min-height: 0;
|
|
82
|
+
overflow: auto;
|
|
83
|
+
background: #0b0d10;
|
|
84
|
+
border: 1px solid var(--line);
|
|
85
|
+
border-radius: 4px;
|
|
86
|
+
}
|
|
87
|
+
canvas {
|
|
88
|
+
display: block;
|
|
89
|
+
image-rendering: pixelated;
|
|
90
|
+
}
|
|
91
|
+
#status,
|
|
92
|
+
#message {
|
|
93
|
+
color: var(--dim);
|
|
94
|
+
white-space: pre-wrap;
|
|
95
|
+
word-break: break-all;
|
|
96
|
+
}
|
|
97
|
+
#message.error {
|
|
98
|
+
color: var(--warn);
|
|
99
|
+
}
|
|
100
|
+
kbd {
|
|
101
|
+
color: var(--ink);
|
|
102
|
+
}
|
|
103
|
+
details summary {
|
|
104
|
+
cursor: pointer;
|
|
105
|
+
color: var(--dim);
|
|
106
|
+
}
|
|
107
|
+
dl {
|
|
108
|
+
margin: 6px 0 0;
|
|
109
|
+
display: grid;
|
|
110
|
+
grid-template-columns: max-content 1fr;
|
|
111
|
+
gap: 2px 10px;
|
|
112
|
+
}
|
|
113
|
+
dt {
|
|
114
|
+
color: var(--accent);
|
|
115
|
+
}
|
|
116
|
+
dd {
|
|
117
|
+
margin: 0;
|
|
118
|
+
color: var(--dim);
|
|
119
|
+
}
|
|
120
|
+
</style>
|
|
121
|
+
</head>
|
|
122
|
+
<body>
|
|
123
|
+
<aside>
|
|
124
|
+
<div class="row">
|
|
125
|
+
<label for="tileset">Tileset</label>
|
|
126
|
+
<select id="tileset"></select>
|
|
127
|
+
</div>
|
|
128
|
+
<div class="surface"><canvas id="palette"></canvas></div>
|
|
129
|
+
<div class="row">
|
|
130
|
+
<button id="grid-toggle" type="button">Grid</button>
|
|
131
|
+
<button id="zoom-out" type="button">−</button>
|
|
132
|
+
<button id="zoom-in" type="button">+</button>
|
|
133
|
+
<button id="new-map" type="button">New</button>
|
|
134
|
+
</div>
|
|
135
|
+
<div class="row">
|
|
136
|
+
<input id="path" type="text" spellcheck="false" />
|
|
137
|
+
<button id="save" type="button">Save</button>
|
|
138
|
+
<button id="load" type="button">Load</button>
|
|
139
|
+
</div>
|
|
140
|
+
<details open>
|
|
141
|
+
<summary>Keys</summary>
|
|
142
|
+
<dl>
|
|
143
|
+
<dt>Arrows</dt>
|
|
144
|
+
<dd>move cursor</dd>
|
|
145
|
+
<dt>WASD</dt>
|
|
146
|
+
<dd>move palette selection</dd>
|
|
147
|
+
<dt>Space / Enter</dt>
|
|
148
|
+
<dd>paint</dd>
|
|
149
|
+
<dt>X / Backspace</dt>
|
|
150
|
+
<dd>erase</dd>
|
|
151
|
+
<dt>[ / ]</dt>
|
|
152
|
+
<dd>switch tileset</dd>
|
|
153
|
+
<dt>+ / −</dt>
|
|
154
|
+
<dd>zoom map</dd>
|
|
155
|
+
<dt>G</dt>
|
|
156
|
+
<dd>grid</dd>
|
|
157
|
+
<dt>N</dt>
|
|
158
|
+
<dd>new map</dd>
|
|
159
|
+
<dt>F5 / Ctrl-S</dt>
|
|
160
|
+
<dd>save</dd>
|
|
161
|
+
<dt>F9 / Ctrl-L</dt>
|
|
162
|
+
<dd>reload</dd>
|
|
163
|
+
<dt>Mouse</dt>
|
|
164
|
+
<dd>left paint, right erase, drag to stroke</dd>
|
|
165
|
+
</dl>
|
|
166
|
+
</details>
|
|
167
|
+
<div id="message"></div>
|
|
168
|
+
</aside>
|
|
169
|
+
|
|
170
|
+
<main>
|
|
171
|
+
<div id="status"></div>
|
|
172
|
+
<div class="surface"><canvas id="map"></canvas></div>
|
|
173
|
+
</main>
|
|
174
|
+
|
|
175
|
+
<script type="module">
|
|
176
|
+
const token = new URLSearchParams(location.search).get("t") ?? "";
|
|
177
|
+
|
|
178
|
+
/** Every request carries the token as a header, which a cross-origin page can't set. */
|
|
179
|
+
async function api(path, init = {}) {
|
|
180
|
+
const response = await fetch(path, {
|
|
181
|
+
...init,
|
|
182
|
+
headers: { ...(init.headers ?? {}), "x-editor-token": token },
|
|
183
|
+
});
|
|
184
|
+
const body = await response.json();
|
|
185
|
+
if (!response.ok) throw new Error(body.error ?? `${response.status}`);
|
|
186
|
+
return body;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const el = (id) => document.getElementById(id);
|
|
190
|
+
const paletteCanvas = el("palette");
|
|
191
|
+
const mapCanvas = el("map");
|
|
192
|
+
const paletteCtx = paletteCanvas.getContext("2d");
|
|
193
|
+
const mapCtx = mapCanvas.getContext("2d");
|
|
194
|
+
|
|
195
|
+
const state = {
|
|
196
|
+
tilesetNames: [],
|
|
197
|
+
tileset: null,
|
|
198
|
+
sheet: null,
|
|
199
|
+
map: { width: 0, height: 0, data: [] },
|
|
200
|
+
mapPath: null,
|
|
201
|
+
cursor: { x: 0, y: 0 },
|
|
202
|
+
selection: { col: 0, row: 0 },
|
|
203
|
+
paletteScale: 3,
|
|
204
|
+
mapScale: 3,
|
|
205
|
+
grid: true,
|
|
206
|
+
dirty: false,
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
function say(text, isError = false) {
|
|
210
|
+
const node = el("message");
|
|
211
|
+
node.textContent = text;
|
|
212
|
+
node.className = isError ? "error" : "";
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Source rect of a tile in the sheet — margin and spacing are the whole point. */
|
|
216
|
+
function tileRect(id) {
|
|
217
|
+
const t = state.tileset;
|
|
218
|
+
const index = id - 1;
|
|
219
|
+
const row = Math.floor(index / t.columns);
|
|
220
|
+
const col = index - row * t.columns;
|
|
221
|
+
return {
|
|
222
|
+
x: t.margin + col * (t.tileWidth + t.spacing),
|
|
223
|
+
y: t.margin + row * (t.tileHeight + t.spacing),
|
|
224
|
+
w: t.tileWidth,
|
|
225
|
+
h: t.tileHeight,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const tileIdAt = (col, row) =>
|
|
230
|
+
col < 0 || row < 0 || col >= state.tileset.columns || row >= state.tileset.rows
|
|
231
|
+
? 0
|
|
232
|
+
: row * state.tileset.columns + col + 1;
|
|
233
|
+
|
|
234
|
+
const selectedTileId = () => tileIdAt(state.selection.col, state.selection.row);
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* A two-tone box: dark outside, bright inside. A single stroke
|
|
238
|
+
* disappears against a tile that happens to share its colour, and the
|
|
239
|
+
* selection has to stay findable on any tileset.
|
|
240
|
+
*/
|
|
241
|
+
function marker(ctx, x, y, w, h, color) {
|
|
242
|
+
ctx.lineWidth = 2;
|
|
243
|
+
ctx.strokeStyle = "rgba(0,0,0,0.85)";
|
|
244
|
+
ctx.strokeRect(x + 1, y + 1, w - 2, h - 2);
|
|
245
|
+
ctx.strokeStyle = color;
|
|
246
|
+
ctx.strokeRect(x + 3, y + 3, w - 6, h - 6);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function drawGrid(ctx, cols, rows, cell, width, height) {
|
|
250
|
+
if (!state.grid) return;
|
|
251
|
+
ctx.strokeStyle = "rgba(120,140,160,0.35)";
|
|
252
|
+
ctx.lineWidth = 1;
|
|
253
|
+
ctx.beginPath();
|
|
254
|
+
for (let c = 0; c <= cols; c += 1) {
|
|
255
|
+
const x = Math.round(c * cell) + 0.5;
|
|
256
|
+
ctx.moveTo(x, 0);
|
|
257
|
+
ctx.lineTo(x, height);
|
|
258
|
+
}
|
|
259
|
+
for (let r = 0; r <= rows; r += 1) {
|
|
260
|
+
const y = Math.round(r * cell) + 0.5;
|
|
261
|
+
ctx.moveTo(0, y);
|
|
262
|
+
ctx.lineTo(width, y);
|
|
263
|
+
}
|
|
264
|
+
ctx.stroke();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function drawPalette() {
|
|
268
|
+
const t = state.tileset;
|
|
269
|
+
if (!t || !state.sheet) return;
|
|
270
|
+
const cellW = t.tileWidth * state.paletteScale;
|
|
271
|
+
const cellH = t.tileHeight * state.paletteScale;
|
|
272
|
+
paletteCanvas.width = t.columns * cellW;
|
|
273
|
+
paletteCanvas.height = t.rows * cellH;
|
|
274
|
+
|
|
275
|
+
paletteCtx.imageSmoothingEnabled = false;
|
|
276
|
+
paletteCtx.clearRect(0, 0, paletteCanvas.width, paletteCanvas.height);
|
|
277
|
+
|
|
278
|
+
for (let row = 0; row < t.rows; row += 1) {
|
|
279
|
+
for (let col = 0; col < t.columns; col += 1) {
|
|
280
|
+
const src = tileRect(tileIdAt(col, row));
|
|
281
|
+
paletteCtx.drawImage(
|
|
282
|
+
state.sheet,
|
|
283
|
+
src.x,
|
|
284
|
+
src.y,
|
|
285
|
+
src.w,
|
|
286
|
+
src.h,
|
|
287
|
+
col * cellW,
|
|
288
|
+
row * cellH,
|
|
289
|
+
cellW,
|
|
290
|
+
cellH,
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
drawGrid(paletteCtx, t.columns, t.rows, cellW, paletteCanvas.width, paletteCanvas.height);
|
|
296
|
+
|
|
297
|
+
marker(
|
|
298
|
+
paletteCtx,
|
|
299
|
+
state.selection.col * cellW,
|
|
300
|
+
state.selection.row * cellH,
|
|
301
|
+
cellW,
|
|
302
|
+
cellH,
|
|
303
|
+
"#5ec8f5",
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function drawMap() {
|
|
308
|
+
const t = state.tileset;
|
|
309
|
+
if (!t || !state.sheet) return;
|
|
310
|
+
const cellW = t.tileWidth * state.mapScale;
|
|
311
|
+
const cellH = t.tileHeight * state.mapScale;
|
|
312
|
+
mapCanvas.width = state.map.width * cellW;
|
|
313
|
+
mapCanvas.height = state.map.height * cellH;
|
|
314
|
+
|
|
315
|
+
mapCtx.imageSmoothingEnabled = false;
|
|
316
|
+
mapCtx.clearRect(0, 0, mapCanvas.width, mapCanvas.height);
|
|
317
|
+
|
|
318
|
+
for (let y = 0; y < state.map.height; y += 1) {
|
|
319
|
+
for (let x = 0; x < state.map.width; x += 1) {
|
|
320
|
+
const id = state.map.data[y][x];
|
|
321
|
+
if (id <= 0 || id > t.columns * t.rows) continue;
|
|
322
|
+
const src = tileRect(id);
|
|
323
|
+
mapCtx.drawImage(
|
|
324
|
+
state.sheet,
|
|
325
|
+
src.x,
|
|
326
|
+
src.y,
|
|
327
|
+
src.w,
|
|
328
|
+
src.h,
|
|
329
|
+
x * cellW,
|
|
330
|
+
y * cellH,
|
|
331
|
+
cellW,
|
|
332
|
+
cellH,
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
drawGrid(
|
|
338
|
+
mapCtx,
|
|
339
|
+
state.map.width,
|
|
340
|
+
state.map.height,
|
|
341
|
+
cellW,
|
|
342
|
+
mapCanvas.width,
|
|
343
|
+
mapCanvas.height,
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
marker(mapCtx, state.cursor.x * cellW, state.cursor.y * cellH, cellW, cellH, "#f5a25e");
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function drawStatus() {
|
|
350
|
+
const t = state.tileset;
|
|
351
|
+
el("status").textContent =
|
|
352
|
+
`${t.name} ${t.columns}×${t.rows} tiles of ${t.tileWidth}×${t.tileHeight}` +
|
|
353
|
+
` · map ${state.map.width}×${state.map.height} @${state.mapScale}×` +
|
|
354
|
+
` · cursor ${state.cursor.x},${state.cursor.y}` +
|
|
355
|
+
` · tile #${selectedTileId()}` +
|
|
356
|
+
(state.dirty ? " · unsaved" : "");
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const redraw = () => {
|
|
360
|
+
drawPalette();
|
|
361
|
+
drawMap();
|
|
362
|
+
drawStatus();
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
function loadSheet(name) {
|
|
366
|
+
return new Promise((done, failed) => {
|
|
367
|
+
const image = new Image();
|
|
368
|
+
image.onload = () => done(image);
|
|
369
|
+
image.onerror = () => failed(new Error(`Could not load the sheet for ${name}`));
|
|
370
|
+
image.src = `/api/sheet?name=${encodeURIComponent(name)}&t=${encodeURIComponent(token)}`;
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
async function selectTileset(name) {
|
|
375
|
+
state.tileset = await api(`/api/tileset?name=${encodeURIComponent(name)}`);
|
|
376
|
+
state.sheet = await loadSheet(name);
|
|
377
|
+
state.selection.col = Math.min(state.selection.col, state.tileset.columns - 1);
|
|
378
|
+
state.selection.row = Math.min(state.selection.row, state.tileset.rows - 1);
|
|
379
|
+
el("tileset").value = name;
|
|
380
|
+
say(`Tileset: ${name} — ${state.tileset.path}`);
|
|
381
|
+
redraw();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function paint(erase = false) {
|
|
385
|
+
const { x, y } = state.cursor;
|
|
386
|
+
const next = erase ? 0 : selectedTileId();
|
|
387
|
+
if (state.map.data[y][x] === next) return;
|
|
388
|
+
state.map.data[y][x] = next;
|
|
389
|
+
state.dirty = true;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function cellFromEvent(event) {
|
|
393
|
+
const rect = mapCanvas.getBoundingClientRect();
|
|
394
|
+
const t = state.tileset;
|
|
395
|
+
return {
|
|
396
|
+
x: Math.floor((event.clientX - rect.left) / (t.tileWidth * state.mapScale)),
|
|
397
|
+
y: Math.floor((event.clientY - rect.top) / (t.tileHeight * state.mapScale)),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function applyAt(event, erase) {
|
|
402
|
+
const { x, y } = cellFromEvent(event);
|
|
403
|
+
if (x < 0 || y < 0 || x >= state.map.width || y >= state.map.height) return;
|
|
404
|
+
state.cursor = { x, y };
|
|
405
|
+
paint(erase);
|
|
406
|
+
redraw();
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
async function save() {
|
|
410
|
+
const path = el("path").value.trim();
|
|
411
|
+
try {
|
|
412
|
+
const result = await api("/api/save", {
|
|
413
|
+
method: "POST",
|
|
414
|
+
headers: { "content-type": "application/json" },
|
|
415
|
+
body: JSON.stringify({
|
|
416
|
+
path,
|
|
417
|
+
tileset: state.tileset.name,
|
|
418
|
+
width: state.map.width,
|
|
419
|
+
height: state.map.height,
|
|
420
|
+
data: state.map.data,
|
|
421
|
+
}),
|
|
422
|
+
});
|
|
423
|
+
state.mapPath = result.path;
|
|
424
|
+
state.dirty = false;
|
|
425
|
+
say(`Saved ${result.path}`);
|
|
426
|
+
drawStatus();
|
|
427
|
+
} catch (error) {
|
|
428
|
+
say(String(error.message ?? error), true);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
async function load() {
|
|
433
|
+
const path = el("path").value.trim();
|
|
434
|
+
try {
|
|
435
|
+
const result = await api(`/api/load?path=${encodeURIComponent(path)}`);
|
|
436
|
+
state.map = { width: result.width, height: result.height, data: result.data };
|
|
437
|
+
state.cursor.x = Math.min(state.cursor.x, result.width - 1);
|
|
438
|
+
state.cursor.y = Math.min(state.cursor.y, result.height - 1);
|
|
439
|
+
state.mapPath = result.path;
|
|
440
|
+
state.dirty = false;
|
|
441
|
+
if (result.tileset && state.tilesetNames.includes(result.tileset)) {
|
|
442
|
+
await selectTileset(result.tileset);
|
|
443
|
+
}
|
|
444
|
+
say(`Loaded ${result.path}`);
|
|
445
|
+
redraw();
|
|
446
|
+
} catch (error) {
|
|
447
|
+
say(String(error.message ?? error), true);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function newMap() {
|
|
452
|
+
state.map.data = Array.from({ length: state.map.height }, () =>
|
|
453
|
+
new Array(state.map.width).fill(0),
|
|
454
|
+
);
|
|
455
|
+
state.dirty = true;
|
|
456
|
+
say(`New map: ${state.map.width}×${state.map.height}`);
|
|
457
|
+
redraw();
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function cycleTileset(delta) {
|
|
461
|
+
const at = state.tilesetNames.indexOf(state.tileset.name);
|
|
462
|
+
const next =
|
|
463
|
+
state.tilesetNames[(at + delta + state.tilesetNames.length) % state.tilesetNames.length];
|
|
464
|
+
void selectTileset(next);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function zoom(delta) {
|
|
468
|
+
state.mapScale = Math.max(1, Math.min(10, state.mapScale + delta));
|
|
469
|
+
redraw();
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// ---- wiring -----------------------------------------------------------
|
|
473
|
+
|
|
474
|
+
paletteCanvas.addEventListener("mousedown", (event) => {
|
|
475
|
+
const rect = paletteCanvas.getBoundingClientRect();
|
|
476
|
+
const t = state.tileset;
|
|
477
|
+
const col = Math.floor((event.clientX - rect.left) / (t.tileWidth * state.paletteScale));
|
|
478
|
+
const row = Math.floor((event.clientY - rect.top) / (t.tileHeight * state.paletteScale));
|
|
479
|
+
if (col < 0 || row < 0 || col >= t.columns || row >= t.rows) return;
|
|
480
|
+
state.selection = { col, row };
|
|
481
|
+
redraw();
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
let stroking = 0;
|
|
485
|
+
mapCanvas.addEventListener("contextmenu", (event) => event.preventDefault());
|
|
486
|
+
mapCanvas.addEventListener("mousedown", (event) => {
|
|
487
|
+
event.preventDefault();
|
|
488
|
+
stroking = event.button === 2 ? 2 : 1;
|
|
489
|
+
applyAt(event, stroking === 2);
|
|
490
|
+
});
|
|
491
|
+
mapCanvas.addEventListener("mousemove", (event) => {
|
|
492
|
+
if (stroking) applyAt(event, stroking === 2);
|
|
493
|
+
});
|
|
494
|
+
window.addEventListener("mouseup", () => {
|
|
495
|
+
stroking = 0;
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
el("tileset").addEventListener("change", (event) => void selectTileset(event.target.value));
|
|
499
|
+
el("grid-toggle").addEventListener("click", () => {
|
|
500
|
+
state.grid = !state.grid;
|
|
501
|
+
redraw();
|
|
502
|
+
});
|
|
503
|
+
el("zoom-in").addEventListener("click", () => zoom(1));
|
|
504
|
+
el("zoom-out").addEventListener("click", () => zoom(-1));
|
|
505
|
+
el("new-map").addEventListener("click", newMap);
|
|
506
|
+
el("save").addEventListener("click", () => void save());
|
|
507
|
+
el("load").addEventListener("click", () => void load());
|
|
508
|
+
|
|
509
|
+
window.addEventListener("keydown", (event) => {
|
|
510
|
+
if (event.target instanceof HTMLInputElement) return;
|
|
511
|
+
|
|
512
|
+
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "s") {
|
|
513
|
+
event.preventDefault();
|
|
514
|
+
void save();
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "l") {
|
|
518
|
+
event.preventDefault();
|
|
519
|
+
void load();
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
if (event.ctrlKey || event.metaKey || event.altKey) return;
|
|
523
|
+
|
|
524
|
+
const key = event.key;
|
|
525
|
+
const handled = () => {
|
|
526
|
+
event.preventDefault();
|
|
527
|
+
redraw();
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
switch (key) {
|
|
531
|
+
case "ArrowLeft":
|
|
532
|
+
state.cursor.x = Math.max(0, state.cursor.x - 1);
|
|
533
|
+
return handled();
|
|
534
|
+
case "ArrowRight":
|
|
535
|
+
state.cursor.x = Math.min(state.map.width - 1, state.cursor.x + 1);
|
|
536
|
+
return handled();
|
|
537
|
+
case "ArrowUp":
|
|
538
|
+
state.cursor.y = Math.max(0, state.cursor.y - 1);
|
|
539
|
+
return handled();
|
|
540
|
+
case "ArrowDown":
|
|
541
|
+
state.cursor.y = Math.min(state.map.height - 1, state.cursor.y + 1);
|
|
542
|
+
return handled();
|
|
543
|
+
case " ":
|
|
544
|
+
case "Enter":
|
|
545
|
+
paint(false);
|
|
546
|
+
return handled();
|
|
547
|
+
case "x":
|
|
548
|
+
case "X":
|
|
549
|
+
case "Backspace":
|
|
550
|
+
case "Delete":
|
|
551
|
+
paint(true);
|
|
552
|
+
return handled();
|
|
553
|
+
case "F5":
|
|
554
|
+
event.preventDefault();
|
|
555
|
+
void save();
|
|
556
|
+
return;
|
|
557
|
+
case "F9":
|
|
558
|
+
event.preventDefault();
|
|
559
|
+
void load();
|
|
560
|
+
return;
|
|
561
|
+
case "[":
|
|
562
|
+
event.preventDefault();
|
|
563
|
+
return cycleTileset(-1);
|
|
564
|
+
case "]":
|
|
565
|
+
event.preventDefault();
|
|
566
|
+
return cycleTileset(1);
|
|
567
|
+
case "+":
|
|
568
|
+
case "=":
|
|
569
|
+
event.preventDefault();
|
|
570
|
+
return zoom(1);
|
|
571
|
+
case "-":
|
|
572
|
+
case "_":
|
|
573
|
+
event.preventDefault();
|
|
574
|
+
return zoom(-1);
|
|
575
|
+
default:
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const t = state.tileset;
|
|
580
|
+
switch (key.toLowerCase()) {
|
|
581
|
+
case "a":
|
|
582
|
+
state.selection.col = Math.max(0, state.selection.col - 1);
|
|
583
|
+
return handled();
|
|
584
|
+
case "d":
|
|
585
|
+
state.selection.col = Math.min(t.columns - 1, state.selection.col + 1);
|
|
586
|
+
return handled();
|
|
587
|
+
case "w":
|
|
588
|
+
state.selection.row = Math.max(0, state.selection.row - 1);
|
|
589
|
+
return handled();
|
|
590
|
+
case "s":
|
|
591
|
+
state.selection.row = Math.min(t.rows - 1, state.selection.row + 1);
|
|
592
|
+
return handled();
|
|
593
|
+
case "g":
|
|
594
|
+
state.grid = !state.grid;
|
|
595
|
+
return handled();
|
|
596
|
+
case "n":
|
|
597
|
+
event.preventDefault();
|
|
598
|
+
return newMap();
|
|
599
|
+
default:
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
window.addEventListener("beforeunload", (event) => {
|
|
605
|
+
if (state.dirty) event.preventDefault();
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
// ---- boot -------------------------------------------------------------
|
|
609
|
+
|
|
610
|
+
try {
|
|
611
|
+
const initial = await api("/api/state");
|
|
612
|
+
state.tilesetNames = initial.tilesetNames;
|
|
613
|
+
state.map = {
|
|
614
|
+
width: initial.map.width,
|
|
615
|
+
height: initial.map.height,
|
|
616
|
+
data: initial.map.data,
|
|
617
|
+
};
|
|
618
|
+
state.mapPath = initial.mapPath;
|
|
619
|
+
el("path").value = initial.mapPath ?? "tilemap.json";
|
|
620
|
+
el("tileset").replaceChildren(
|
|
621
|
+
...initial.tilesetNames.map((name) => new Option(name, name)),
|
|
622
|
+
);
|
|
623
|
+
await selectTileset(initial.tileset.name);
|
|
624
|
+
say(`Manifest: ${initial.manifestPath}`);
|
|
625
|
+
} catch (error) {
|
|
626
|
+
say(`Could not start: ${error.message ?? error}`, true);
|
|
627
|
+
}
|
|
628
|
+
</script>
|
|
629
|
+
</body>
|
|
630
|
+
</html>
|
|
@@ -261,7 +261,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
261
261
|
SOFTWARE.
|
|
262
262
|
|
|
263
263
|
========================================================================
|
|
264
|
-
ignore@7.0.
|
|
264
|
+
ignore@7.0.16 (MIT)
|
|
265
265
|
========================================================================
|
|
266
266
|
|
|
267
267
|
Licensed MIT; the package ships no licence file.
|
|
@@ -329,7 +329,7 @@ The above copyright notice and this permission notice shall be included in all c
|
|
|
329
329
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
330
330
|
|
|
331
331
|
========================================================================
|
|
332
|
-
tar@7.5.
|
|
332
|
+
tar@7.5.23 (BlueOak-1.0.0)
|
|
333
333
|
========================================================================
|
|
334
334
|
|
|
335
335
|
# Blue Oak Model License
|