kiosko-plugin-doom 0.0.0-stage → 0.2.0
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/LICENSE +339 -0
- package/README.md +121 -2
- package/dist/engine.js +2772 -0
- package/dist/index.js +595 -0
- package/docs/attract.jpg +0 -0
- package/docs/stack.jpg +0 -0
- package/kiosko-manifest.json +87 -0
- package/package.json +69 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
import { createRequire as __pluginRequire } from 'node:module'; const require = __pluginRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { defineInterlude, definePlugin, t } from "@kiosko/sdk";
|
|
5
|
+
|
|
6
|
+
// src/engine.ts
|
|
7
|
+
import { fork } from "node:child_process";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
function childPath() {
|
|
10
|
+
const here = import.meta.url;
|
|
11
|
+
return fileURLToPath(new URL(here.endsWith(".ts") ? "./engine-child.ts" : "./engine.js", here));
|
|
12
|
+
}
|
|
13
|
+
var Engine = class _Engine {
|
|
14
|
+
child;
|
|
15
|
+
waiting = null;
|
|
16
|
+
idle = null;
|
|
17
|
+
exitMessage = null;
|
|
18
|
+
width = 0;
|
|
19
|
+
height = 0;
|
|
20
|
+
o;
|
|
21
|
+
constructor(o) {
|
|
22
|
+
this.o = o;
|
|
23
|
+
this.child = fork(childPath(), [], {
|
|
24
|
+
serialization: "advanced",
|
|
25
|
+
stdio: ["ignore", "ignore", "pipe", "ipc"]
|
|
26
|
+
});
|
|
27
|
+
this.child.unref();
|
|
28
|
+
this.child.channel?.unref();
|
|
29
|
+
this.child.stderr?.unref?.();
|
|
30
|
+
let stderr = "";
|
|
31
|
+
this.child.stderr?.on("data", (b) => stderr = (stderr + b.toString()).slice(-2e3));
|
|
32
|
+
this.child.on("message", (m) => {
|
|
33
|
+
if (m.type === "exit") this.exitMessage = m.message;
|
|
34
|
+
const w = this.waiting;
|
|
35
|
+
if (!w) return;
|
|
36
|
+
this.waiting = null;
|
|
37
|
+
this.child.channel?.unref();
|
|
38
|
+
clearTimeout(w.timer);
|
|
39
|
+
if (m.type === "exit") w.reject(new Error(m.message));
|
|
40
|
+
else w.resolve(m);
|
|
41
|
+
});
|
|
42
|
+
this.child.on("exit", (code, signal) => {
|
|
43
|
+
this.exitMessage ??= `engine process ended (${signal ?? code})${stderr ? `: ${stderr.trim().split("\n").slice(-3).join(" | ")}` : ""}`;
|
|
44
|
+
const w = this.waiting;
|
|
45
|
+
this.waiting = null;
|
|
46
|
+
if (w) {
|
|
47
|
+
clearTimeout(w.timer);
|
|
48
|
+
w.reject(new Error(this.exitMessage));
|
|
49
|
+
}
|
|
50
|
+
if (this.idle) clearTimeout(this.idle);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** Forks the engine and loads the WAD. */
|
|
54
|
+
static async start(o) {
|
|
55
|
+
const e = new _Engine({ wad: o.wad, args: o.args ?? [], idleMs: o.idleMs ?? 1e4, timeoutMs: o.timeoutMs ?? 15e3 });
|
|
56
|
+
try {
|
|
57
|
+
const ready = await e.ask({ type: "start", wad: o.wad, args: o.args ?? [] });
|
|
58
|
+
if (ready.type !== "ready") throw new Error(`unexpected ${ready.type}`);
|
|
59
|
+
e.width = ready.width;
|
|
60
|
+
e.height = ready.height;
|
|
61
|
+
e.touch();
|
|
62
|
+
return e;
|
|
63
|
+
} catch (err) {
|
|
64
|
+
e.close();
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
get alive() {
|
|
69
|
+
return this.child.exitCode === null && this.child.signalCode === null && this.exitMessage === null;
|
|
70
|
+
}
|
|
71
|
+
/** Runs the game up to `ms` since it started and returns that frame. */
|
|
72
|
+
async frame(ms) {
|
|
73
|
+
this.touch();
|
|
74
|
+
const m = await this.ask({ type: "frame", ms });
|
|
75
|
+
if (m.type !== "frame") throw new Error(`unexpected ${m.type}`);
|
|
76
|
+
return { ms: m.ms, width: this.width, height: this.height, pixels: m.pixels, state: m.state };
|
|
77
|
+
}
|
|
78
|
+
key(pressed, key) {
|
|
79
|
+
if (this.alive) this.child.send({ type: "key", pressed, key });
|
|
80
|
+
}
|
|
81
|
+
close() {
|
|
82
|
+
if (this.idle) clearTimeout(this.idle);
|
|
83
|
+
this.idle = null;
|
|
84
|
+
if (this.child.exitCode === null && this.child.signalCode === null) this.child.kill();
|
|
85
|
+
}
|
|
86
|
+
touch() {
|
|
87
|
+
if (this.idle) clearTimeout(this.idle);
|
|
88
|
+
this.idle = setTimeout(() => this.close(), this.o.idleMs);
|
|
89
|
+
this.idle.unref();
|
|
90
|
+
}
|
|
91
|
+
ask(m) {
|
|
92
|
+
if (!this.alive) return Promise.reject(new Error(this.exitMessage ?? "engine stopped"));
|
|
93
|
+
if (this.waiting) return Promise.reject(new Error("engine busy"));
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const timer = setTimeout(() => {
|
|
96
|
+
this.waiting = null;
|
|
97
|
+
this.child.channel?.unref();
|
|
98
|
+
reject(new Error(`engine did not answer ${m.type} in ${this.o.timeoutMs} ms`));
|
|
99
|
+
this.close();
|
|
100
|
+
}, this.o.timeoutMs);
|
|
101
|
+
this.waiting = { resolve, reject, timer };
|
|
102
|
+
this.child.channel?.ref();
|
|
103
|
+
this.child.send(m);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/protocol.ts
|
|
109
|
+
var STATE = {
|
|
110
|
+
gamestate: 0,
|
|
111
|
+
demoplayback: 1,
|
|
112
|
+
episode: 2,
|
|
113
|
+
map: 3,
|
|
114
|
+
leveltime: 4,
|
|
115
|
+
health: 5,
|
|
116
|
+
armor: 6,
|
|
117
|
+
weapon: 7,
|
|
118
|
+
ammo: 8,
|
|
119
|
+
kills: 9,
|
|
120
|
+
totalKills: 10,
|
|
121
|
+
items: 11,
|
|
122
|
+
totalItems: 12,
|
|
123
|
+
secrets: 13,
|
|
124
|
+
totalSecrets: 14,
|
|
125
|
+
gamemode: 15
|
|
126
|
+
};
|
|
127
|
+
var KEYS = {
|
|
128
|
+
right: 174,
|
|
129
|
+
left: 172,
|
|
130
|
+
up: 173,
|
|
131
|
+
down: 175,
|
|
132
|
+
strafeLeft: 160,
|
|
133
|
+
strafeRight: 161,
|
|
134
|
+
use: 162,
|
|
135
|
+
fire: 163,
|
|
136
|
+
escape: 27,
|
|
137
|
+
enter: 13,
|
|
138
|
+
tab: 9,
|
|
139
|
+
shift: 128 + 54
|
|
140
|
+
};
|
|
141
|
+
var PAD_TO_DOOM = {
|
|
142
|
+
up: KEYS.up,
|
|
143
|
+
down: KEYS.down,
|
|
144
|
+
left: KEYS.left,
|
|
145
|
+
right: KEYS.right,
|
|
146
|
+
a: KEYS.fire,
|
|
147
|
+
b: KEYS.use,
|
|
148
|
+
l: KEYS.strafeLeft,
|
|
149
|
+
r: KEYS.strafeRight,
|
|
150
|
+
y: KEYS.shift,
|
|
151
|
+
x: KEYS.enter,
|
|
152
|
+
start: KEYS.escape,
|
|
153
|
+
select: KEYS.tab
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// src/hud.ts
|
|
157
|
+
var GS_LEVEL = 0;
|
|
158
|
+
var COMMERCIAL = 2;
|
|
159
|
+
var MIN_SIDE = 220;
|
|
160
|
+
function sides(width, height, game) {
|
|
161
|
+
const pad = Math.round(Math.min(height * 0.08, game.x * 0.08));
|
|
162
|
+
const w = game.x - pad * 2;
|
|
163
|
+
if (w < MIN_SIDE) return null;
|
|
164
|
+
return {
|
|
165
|
+
left: { x: pad, y: pad, w, h: height - pad * 2 },
|
|
166
|
+
right: { x: game.x + game.w + pad, y: pad, w, h: height - pad * 2 }
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
var mapName = (s) => s[STATE.gamemode] === COMMERCIAL ? `MAP${String(s[STATE.map]).padStart(2, "0")}` : `E${s[STATE.episode]}M${s[STATE.map]}`;
|
|
170
|
+
var levelTime = (tics) => {
|
|
171
|
+
const s = Math.floor(Math.max(0, tics) / 35);
|
|
172
|
+
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
|
|
173
|
+
};
|
|
174
|
+
var WEAPONS = [
|
|
175
|
+
{ en: "Fist", es: "Pu\xF1o", de: "Faust", "zh-Hans": "\u62F3\u5934", "zh-Hant": "\u62F3\u982D" },
|
|
176
|
+
{ en: "Pistol", es: "Pistola", de: "Pistole", "zh-Hans": "\u624B\u67AA", "zh-Hant": "\u624B\u69CD" },
|
|
177
|
+
{ en: "Shotgun", es: "Escopeta", de: "Schrotflinte", "zh-Hans": "\u9730\u5F39\u67AA", "zh-Hant": "\u9730\u5F48\u69CD" },
|
|
178
|
+
{ en: "Chaingun", es: "Ametralladora", de: "Maschinengewehr", "zh-Hans": "\u673A\u67AA", "zh-Hant": "\u6A5F\u69CD" },
|
|
179
|
+
{ en: "Rocket launcher", es: "Lanzacohetes", de: "Raketenwerfer", "zh-Hans": "\u706B\u7BAD\u7B52", "zh-Hant": "\u706B\u7BAD\u7B52" },
|
|
180
|
+
{ en: "Plasma rifle", es: "Rifle de plasma", de: "Plasmagewehr", "zh-Hans": "\u7B49\u79BB\u5B50\u67AA", "zh-Hant": "\u96FB\u6F3F\u69CD" },
|
|
181
|
+
{ en: "BFG", es: "BFG", de: "BFG", "zh-Hans": "BFG", "zh-Hant": "BFG" },
|
|
182
|
+
{ en: "Chainsaw", es: "Motosierra", de: "Kettens\xE4ge", "zh-Hans": "\u7535\u952F", "zh-Hant": "\u96FB\u92F8" },
|
|
183
|
+
{ en: "Super shotgun", es: "Escopeta doble", de: "Doppelflinte", "zh-Hans": "\u53CC\u7BA1\u9730\u5F39\u67AA", "zh-Hant": "\u96D9\u7BA1\u9730\u5F48\u69CD" }
|
|
184
|
+
];
|
|
185
|
+
var font = (size, family) => `${Math.round(size)}px "${family}"`;
|
|
186
|
+
function label(g, theme, text, x, y, size, align = "left") {
|
|
187
|
+
g.font = font(size, theme.fonts.sansBold);
|
|
188
|
+
g.fillStyle = theme.colors.inkFaint;
|
|
189
|
+
g.textAlign = align;
|
|
190
|
+
g.fillText(text.toUpperCase(), x, y);
|
|
191
|
+
}
|
|
192
|
+
function progress(g, theme, name, n, total, b) {
|
|
193
|
+
const c = theme.colors;
|
|
194
|
+
const size = b.h * 0.42;
|
|
195
|
+
g.textBaseline = "alphabetic";
|
|
196
|
+
g.font = font(size, theme.fonts.sans);
|
|
197
|
+
g.fillStyle = c.inkDim;
|
|
198
|
+
g.textAlign = "left";
|
|
199
|
+
g.fillText(name, b.x, b.y + size);
|
|
200
|
+
g.font = font(size, theme.fonts.monoBold);
|
|
201
|
+
g.fillStyle = c.ink;
|
|
202
|
+
g.textAlign = "right";
|
|
203
|
+
g.fillText(total > 0 ? `${n} / ${total}` : `${n}`, b.x + b.w, b.y + size);
|
|
204
|
+
const barY = b.y + size * 1.45;
|
|
205
|
+
const barH = Math.max(3, b.h * 0.12);
|
|
206
|
+
g.fillStyle = c.surfaceEdge;
|
|
207
|
+
g.fillRect(b.x, barY, b.w, barH);
|
|
208
|
+
if (total > 0) {
|
|
209
|
+
g.fillStyle = n >= total ? c.ok : c.accent;
|
|
210
|
+
g.fillRect(b.x, barY, b.w * Math.min(n, total) / total, barH);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function drawHud(g, theme, say, state, box, wad) {
|
|
214
|
+
const c = theme.colors;
|
|
215
|
+
const { left: L, right: R } = box;
|
|
216
|
+
g.save();
|
|
217
|
+
g.textBaseline = "alphabetic";
|
|
218
|
+
if (state[STATE.gamestate] !== GS_LEVEL) {
|
|
219
|
+
const size = L.h * 0.09;
|
|
220
|
+
label(g, theme, say({ en: "Now playing", es: "En pantalla", de: "L\xE4uft gerade", "zh-Hans": "\u6B63\u5728\u64AD\u653E", "zh-Hant": "\u6B63\u5728\u64AD\u653E" }), L.x, L.y + L.h / 2 - size * 0.6, size * 0.6);
|
|
221
|
+
g.font = font(size, theme.fonts.sansBold);
|
|
222
|
+
g.fillStyle = c.inkDim;
|
|
223
|
+
g.textAlign = "left";
|
|
224
|
+
g.fillText(wad, L.x, L.y + L.h / 2 + size * 0.7, L.w);
|
|
225
|
+
g.restore();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const big = L.h * 0.3;
|
|
229
|
+
label(g, theme, say({ en: "Map", es: "Mapa", de: "Karte", "zh-Hans": "\u5730\u56FE", "zh-Hant": "\u5730\u5716" }), L.x, L.y + big * 0.32, big * 0.22);
|
|
230
|
+
g.font = font(big, theme.fonts.monoBold);
|
|
231
|
+
g.fillStyle = c.ink;
|
|
232
|
+
g.textAlign = "left";
|
|
233
|
+
g.fillText(mapName(state), L.x, L.y + big * 1.2);
|
|
234
|
+
g.font = font(big * 0.42, theme.fonts.mono);
|
|
235
|
+
g.fillStyle = c.inkDim;
|
|
236
|
+
g.textAlign = "right";
|
|
237
|
+
g.fillText(levelTime(state[STATE.leveltime]), L.x + L.w, L.y + big * 1.2);
|
|
238
|
+
const rows = [
|
|
239
|
+
[say({ en: "Kills", es: "Enemigos", de: "Gegner", "zh-Hans": "\u51FB\u6740", "zh-Hant": "\u64CA\u6BBA" }), state[STATE.kills], state[STATE.totalKills]],
|
|
240
|
+
[say({ en: "Items", es: "Objetos", de: "Gegenst\xE4nde", "zh-Hans": "\u7269\u54C1", "zh-Hant": "\u7269\u54C1" }), state[STATE.items], state[STATE.totalItems]],
|
|
241
|
+
[say({ en: "Secrets", es: "Secretos", de: "Geheimnisse", "zh-Hans": "\u79D8\u5BC6", "zh-Hant": "\u79D8\u5BC6" }), state[STATE.secrets], state[STATE.totalSecrets]]
|
|
242
|
+
];
|
|
243
|
+
const top = L.y + big * 1.55;
|
|
244
|
+
const rowH = (L.y + L.h - top) / rows.length;
|
|
245
|
+
rows.forEach(([name, n, total], i) => progress(g, theme, name, n, total, { x: L.x, y: top + rowH * i, w: L.w, h: rowH * 0.92 }));
|
|
246
|
+
const health = state[STATE.health];
|
|
247
|
+
const healthColor = health <= 25 ? c.alert : health <= 50 ? c.warn : c.ink;
|
|
248
|
+
const hs = R.h * 0.44;
|
|
249
|
+
label(g, theme, say({ en: "Health", es: "Salud", de: "Gesundheit", "zh-Hans": "\u751F\u547D", "zh-Hant": "\u751F\u547D" }), R.x + R.w, R.y + hs * 0.22, hs * 0.16, "right");
|
|
250
|
+
g.font = font(hs, theme.fonts.monoBold);
|
|
251
|
+
g.fillStyle = healthColor;
|
|
252
|
+
g.textAlign = "right";
|
|
253
|
+
g.fillText(`${health}%`, R.x + R.w, R.y + hs * 1.12);
|
|
254
|
+
const small = R.h * 0.2;
|
|
255
|
+
const y2 = R.y + R.h - small * 0.25;
|
|
256
|
+
label(g, theme, say({ en: "Armour", es: "Armadura", de: "R\xFCstung", "zh-Hans": "\u62A4\u7532", "zh-Hant": "\u8B77\u7532" }), R.x, y2 - small * 1.05, small * 0.36);
|
|
257
|
+
g.font = font(small, theme.fonts.monoBold);
|
|
258
|
+
g.fillStyle = c.ink;
|
|
259
|
+
g.textAlign = "left";
|
|
260
|
+
g.fillText(`${state[STATE.armor]}%`, R.x, y2);
|
|
261
|
+
const weapon = WEAPONS[state[STATE.weapon]];
|
|
262
|
+
const ammo = state[STATE.ammo];
|
|
263
|
+
if (weapon) label(g, theme, say(weapon), R.x + R.w, y2 - small * 1.05, small * 0.36, "right");
|
|
264
|
+
g.font = font(small, theme.fonts.monoBold);
|
|
265
|
+
g.fillStyle = ammo >= 0 && ammo <= 10 ? c.warn : c.ink;
|
|
266
|
+
g.textAlign = "right";
|
|
267
|
+
g.fillText(ammo >= 0 ? String(ammo) : "\u221E", R.x + R.w, y2);
|
|
268
|
+
g.restore();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// src/shared.ts
|
|
272
|
+
var TIC_MS = 1e3 / 35;
|
|
273
|
+
var games = /* @__PURE__ */ new Map();
|
|
274
|
+
var SharedGame = class _SharedGame {
|
|
275
|
+
users = 0;
|
|
276
|
+
t0 = 0;
|
|
277
|
+
last = null;
|
|
278
|
+
inflight = null;
|
|
279
|
+
engine;
|
|
280
|
+
id;
|
|
281
|
+
constructor(engine, id) {
|
|
282
|
+
this.engine = engine;
|
|
283
|
+
this.id = id;
|
|
284
|
+
}
|
|
285
|
+
/** The game for `key` (the WAD), started with `start` if there is none running. */
|
|
286
|
+
static async join(key, start) {
|
|
287
|
+
let pending = games.get(key);
|
|
288
|
+
if (pending) {
|
|
289
|
+
const game2 = await pending.catch(() => null);
|
|
290
|
+
if (!game2 || !game2.engine.alive) pending = void 0;
|
|
291
|
+
}
|
|
292
|
+
if (!pending) {
|
|
293
|
+
pending = start().then((e) => new _SharedGame(e, key));
|
|
294
|
+
games.set(key, pending);
|
|
295
|
+
pending.catch(() => games.delete(key));
|
|
296
|
+
}
|
|
297
|
+
const game = await pending;
|
|
298
|
+
game.users++;
|
|
299
|
+
return game;
|
|
300
|
+
}
|
|
301
|
+
/** The frame for `now` (wall time): the clock starts with the first screen to ask. */
|
|
302
|
+
async frame(now) {
|
|
303
|
+
if (!this.t0) this.t0 = now;
|
|
304
|
+
const ms = now - this.t0;
|
|
305
|
+
if (this.last && ms >= this.last.ms && ms - this.last.ms < TIC_MS) return this.last;
|
|
306
|
+
if (this.inflight) return this.inflight;
|
|
307
|
+
this.inflight = this.engine.frame(ms).finally(() => this.inflight = null);
|
|
308
|
+
this.last = await this.inflight;
|
|
309
|
+
return this.last;
|
|
310
|
+
}
|
|
311
|
+
/** A key to the game (someone playing it from the Play page). */
|
|
312
|
+
key(pressed, key) {
|
|
313
|
+
this.engine.key(pressed, key);
|
|
314
|
+
}
|
|
315
|
+
/** A screen is done with it; the last one stops the engine. */
|
|
316
|
+
leave() {
|
|
317
|
+
this.users = Math.max(0, this.users - 1);
|
|
318
|
+
if (this.users > 0) return;
|
|
319
|
+
this.engine.close();
|
|
320
|
+
void games.get(this.id)?.then((g) => g === this && games.delete(this.id));
|
|
321
|
+
}
|
|
322
|
+
get playing() {
|
|
323
|
+
return this.users;
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// src/wad.ts
|
|
328
|
+
import { createHash } from "node:crypto";
|
|
329
|
+
import { existsSync } from "node:fs";
|
|
330
|
+
import { mkdir, open, rename, rm, writeFile } from "node:fs/promises";
|
|
331
|
+
import { join } from "node:path";
|
|
332
|
+
import { inflateRawSync } from "node:zlib";
|
|
333
|
+
var FREEDOOM = {
|
|
334
|
+
version: "0.13.0",
|
|
335
|
+
url: "https://github.com/freedoom/freedoom/releases/download/v0.13.0/freedoom-0.13.0.zip",
|
|
336
|
+
/** From the release's signed freedoom-0.13.0-CHECKSUM. */
|
|
337
|
+
zipSha256: "3f9b264f3e3ce503b4fb7f6bdcb1f419d93c7b546f4df3e874dd878db9688f59",
|
|
338
|
+
wad: "freedoom1.wad",
|
|
339
|
+
wadSha256: "7323bcc168c5a45ff10749b339960e98314740a734c30d4b9f3337001f9e703d",
|
|
340
|
+
/** Files taken from the zip (its licence goes with the WAD). */
|
|
341
|
+
keep: ["freedoom1.wad", "COPYING.txt"]
|
|
342
|
+
};
|
|
343
|
+
var freedoomDir = (dataDir) => join(dataDir, `freedoom-${FREEDOOM.version}`);
|
|
344
|
+
function unzip(zip, want) {
|
|
345
|
+
const b = Buffer.from(zip.buffer, zip.byteOffset, zip.byteLength);
|
|
346
|
+
let eocd = -1;
|
|
347
|
+
for (let i = b.length - 22; i >= Math.max(0, b.length - 22 - 65535); i--) {
|
|
348
|
+
if (b.readUInt32LE(i) === 101010256) {
|
|
349
|
+
eocd = i;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (eocd < 0) throw new Error("not a zip file");
|
|
354
|
+
const entries = b.readUInt16LE(eocd + 10);
|
|
355
|
+
let p = b.readUInt32LE(eocd + 16);
|
|
356
|
+
const out = /* @__PURE__ */ new Map();
|
|
357
|
+
for (let n = 0; n < entries; n++) {
|
|
358
|
+
if (b.readUInt32LE(p) !== 33639248) throw new Error("broken zip directory");
|
|
359
|
+
const method = b.readUInt16LE(p + 10);
|
|
360
|
+
const size = b.readUInt32LE(p + 20);
|
|
361
|
+
const nameLen = b.readUInt16LE(p + 28);
|
|
362
|
+
const extraLen = b.readUInt16LE(p + 30);
|
|
363
|
+
const commentLen = b.readUInt16LE(p + 32);
|
|
364
|
+
const local = b.readUInt32LE(p + 42);
|
|
365
|
+
const name = b.toString("utf8", p + 46, p + 46 + nameLen);
|
|
366
|
+
p += 46 + nameLen + extraLen + commentLen;
|
|
367
|
+
if (!want(name)) continue;
|
|
368
|
+
if (b.readUInt32LE(local) !== 67324752) throw new Error(`broken zip entry ${name}`);
|
|
369
|
+
const start = local + 30 + b.readUInt16LE(local + 26) + b.readUInt16LE(local + 28);
|
|
370
|
+
const data = b.subarray(start, start + size);
|
|
371
|
+
if (method === 0) out.set(name, Buffer.from(data));
|
|
372
|
+
else if (method === 8) out.set(name, inflateRawSync(data));
|
|
373
|
+
else throw new Error(`zip method ${method} not supported (${name})`);
|
|
374
|
+
}
|
|
375
|
+
return out;
|
|
376
|
+
}
|
|
377
|
+
var sha256 = (b) => createHash("sha256").update(b).digest("hex");
|
|
378
|
+
var downloading = null;
|
|
379
|
+
var lastError = null;
|
|
380
|
+
function freedoom(dataDir, log, get = fetch) {
|
|
381
|
+
const dir = freedoomDir(dataDir);
|
|
382
|
+
const path = join(dir, FREEDOOM.wad);
|
|
383
|
+
if (existsSync(path)) return { ready: true, path, name: `Freedoom ${FREEDOOM.version}` };
|
|
384
|
+
if (!downloading) {
|
|
385
|
+
lastError = null;
|
|
386
|
+
log(`downloading Freedoom ${FREEDOOM.version} (24 MB) from GitHub`);
|
|
387
|
+
downloading = downloadFreedoom(dir, get).then(() => log(`Freedoom ${FREEDOOM.version} ready in ${dir}`)).catch((err) => {
|
|
388
|
+
lastError = err instanceof Error ? err.message : String(err);
|
|
389
|
+
log(`Freedoom download failed: ${lastError}`);
|
|
390
|
+
}).finally(() => downloading = null);
|
|
391
|
+
}
|
|
392
|
+
return { ready: false, downloading: true, reason: lastError ?? `downloading Freedoom ${FREEDOOM.version}` };
|
|
393
|
+
}
|
|
394
|
+
async function downloadFreedoom(dir, get = fetch) {
|
|
395
|
+
const res = await get(FREEDOOM.url, { redirect: "follow", signal: AbortSignal.timeout(10 * 6e4) });
|
|
396
|
+
if (!res.ok) throw new Error(`HTTP ${res.status} for ${FREEDOOM.url}`);
|
|
397
|
+
const zip = new Uint8Array(await res.arrayBuffer());
|
|
398
|
+
if (sha256(zip) !== FREEDOOM.zipSha256) throw new Error("the Freedoom zip does not match its published SHA-256");
|
|
399
|
+
const files = unzip(zip, (name) => FREEDOOM.keep.includes(name.split("/").pop()));
|
|
400
|
+
const wad = [...files].find(([n]) => n.endsWith(`/${FREEDOOM.wad}`) || n === FREEDOOM.wad)?.[1];
|
|
401
|
+
if (!wad || sha256(wad) !== FREEDOOM.wadSha256) throw new Error(`${FREEDOOM.wad} missing or not the expected one`);
|
|
402
|
+
const tmp = `${dir}.part`;
|
|
403
|
+
await rm(tmp, { recursive: true, force: true });
|
|
404
|
+
await mkdir(tmp, { recursive: true });
|
|
405
|
+
for (const [name, data] of files) await writeFile(join(tmp, name.split("/").pop()), data);
|
|
406
|
+
await rm(dir, { recursive: true, force: true });
|
|
407
|
+
await rename(tmp, dir);
|
|
408
|
+
}
|
|
409
|
+
async function hasMapLumps(path) {
|
|
410
|
+
const f = await open(path, "r");
|
|
411
|
+
try {
|
|
412
|
+
const head = Buffer.alloc(12);
|
|
413
|
+
await f.read(head, 0, 12, 0);
|
|
414
|
+
const count = head.readInt32LE(4);
|
|
415
|
+
const at = head.readInt32LE(8);
|
|
416
|
+
const dir = Buffer.alloc(Math.max(0, Math.min(count, 1e5)) * 16);
|
|
417
|
+
await f.read(dir, 0, dir.length, at);
|
|
418
|
+
for (let i = 0; i < dir.length; i += 16) if (dir.toString("latin1", i + 8, i + 16).replace(/\0.*$/, "") === "MAP01") return true;
|
|
419
|
+
return false;
|
|
420
|
+
} finally {
|
|
421
|
+
await f.close();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
async function ownWad(path) {
|
|
425
|
+
if (!existsSync(path)) return { ready: false, reason: `${path} not found` };
|
|
426
|
+
const f = await open(path, "r");
|
|
427
|
+
const head = Buffer.alloc(4);
|
|
428
|
+
try {
|
|
429
|
+
await f.read(head, 0, 4, 0);
|
|
430
|
+
} finally {
|
|
431
|
+
await f.close();
|
|
432
|
+
}
|
|
433
|
+
if (head.toString("latin1") !== "IWAD") return { ready: false, reason: `${path} is not an IWAD (${JSON.stringify(head.toString("latin1"))})` };
|
|
434
|
+
return { ready: true, path, name: path.split(/[\\/]/).pop() };
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// src/index.ts
|
|
438
|
+
var ASPECT = 4 / 3;
|
|
439
|
+
function viewport(width, height, aspect = ASPECT) {
|
|
440
|
+
const w = Math.min(width, Math.round(height * aspect));
|
|
441
|
+
const h = Math.min(height, Math.round(w / aspect));
|
|
442
|
+
return { x: Math.round((width - w) / 2), y: Math.round((height - h) / 2), w, h };
|
|
443
|
+
}
|
|
444
|
+
async function playArgs(wad) {
|
|
445
|
+
return ["-skill", "3", "-warp", ...await hasMapLumps(wad) ? ["1"] : ["1", "1"]];
|
|
446
|
+
}
|
|
447
|
+
function stackOf(o) {
|
|
448
|
+
const panels = Math.max(1, Math.min(3, Math.round(o.panels ?? 1)));
|
|
449
|
+
return { panels, row: Math.max(1, Math.min(panels, Math.round(o.row ?? 1))) };
|
|
450
|
+
}
|
|
451
|
+
var MAX_FRAMES = 600 * 30;
|
|
452
|
+
var attract = defineInterlude({
|
|
453
|
+
id: "attract",
|
|
454
|
+
name: { en: "Doom demos", es: "Demos de Doom", de: "Doom-Demos", "zh-Hans": "Doom \u6F14\u793A", "zh-Hant": "Doom \u793A\u7BC4" },
|
|
455
|
+
description: {
|
|
456
|
+
en: "The game plays its own recorded demos between title screens, with no one at the controls. Freedoom by default (free levels and art, downloaded once, 24 MB); your own IWAD if you have one.",
|
|
457
|
+
es: "El juego reproduce sus propias demos grabadas entre pantallas de t\xEDtulo, sin nadie a los mandos. Freedoom por defecto (niveles y gr\xE1ficos libres, se descarga una vez, 24 MB); tu propio IWAD si tienes uno.",
|
|
458
|
+
de: "Das Spiel zeigt seine eigenen aufgezeichneten Demos zwischen den Titelbildern, ganz ohne Steuerung. Standardm\xE4\xDFig Freedoom (freie Level und Grafiken, einmal heruntergeladen, 24 MB); dein eigenes IWAD, falls du eines hast.",
|
|
459
|
+
"zh-Hans": "\u6E38\u620F\u5728\u6807\u9898\u753B\u9762\u4E4B\u95F4\u81EA\u52A8\u64AD\u653E\u5F55\u5236\u597D\u7684\u6F14\u793A\uFF0C\u65E0\u9700\u64CD\u4F5C\u3002\u9ED8\u8BA4\u4F7F\u7528 Freedoom\uFF08\u514D\u8D39\u5173\u5361\u548C\u7F8E\u672F\uFF0C\u53EA\u4E0B\u8F7D\u4E00\u6B21\uFF0C24 MB\uFF09\uFF1B\u4E5F\u53EF\u4EE5\u7528\u4F60\u81EA\u5DF1\u7684 IWAD\u3002",
|
|
460
|
+
"zh-Hant": "\u904A\u6232\u5728\u6A19\u984C\u756B\u9762\u4E4B\u9593\u81EA\u52D5\u64AD\u653E\u9304\u88FD\u597D\u7684\u793A\u7BC4\uFF0C\u7121\u9700\u64CD\u4F5C\u3002\u9810\u8A2D\u4F7F\u7528 Freedoom\uFF08\u514D\u8CBB\u95DC\u5361\u548C\u7F8E\u8853\uFF0C\u53EA\u4E0B\u8F09\u4E00\u6B21\uFF0C24 MB\uFF09\uFF1B\u4E5F\u53EF\u4EE5\u7528\u4F60\u81EA\u5DF1\u7684 IWAD\u3002"
|
|
461
|
+
},
|
|
462
|
+
icon: "gamepad-2",
|
|
463
|
+
fps: 30,
|
|
464
|
+
// It can be played: the editor's Play page offers it (Kiosko 0.2.7 and later).
|
|
465
|
+
...{ input: true },
|
|
466
|
+
options: t.object({
|
|
467
|
+
wad: t.string({
|
|
468
|
+
default: "",
|
|
469
|
+
format: "path",
|
|
470
|
+
risk: "path",
|
|
471
|
+
label: { en: "IWAD", es: "IWAD", de: "IWAD", "zh-Hans": "IWAD", "zh-Hant": "IWAD" },
|
|
472
|
+
help: {
|
|
473
|
+
en: "A game data file of your own (doom1.wad, DOOM.WAD, DOOM2.WAD\u2026). Empty: Freedoom.",
|
|
474
|
+
es: "Un archivo de datos del juego tuyo (doom1.wad, DOOM.WAD, DOOM2.WAD\u2026). Vac\xEDo: Freedoom.",
|
|
475
|
+
de: "Eine eigene Spieldatendatei (doom1.wad, DOOM.WAD, DOOM2.WAD\u2026). Leer: Freedoom.",
|
|
476
|
+
"zh-Hans": "\u4F60\u81EA\u5DF1\u7684\u6E38\u620F\u6570\u636E\u6587\u4EF6\uFF08doom1.wad\u3001DOOM.WAD\u3001DOOM2.WAD\u2026\uFF09\u3002\u7559\u7A7A\uFF1AFreedoom\u3002",
|
|
477
|
+
"zh-Hant": "\u4F60\u81EA\u5DF1\u7684\u904A\u6232\u8CC7\u6599\u6A94\uFF08doom1.wad\u3001DOOM.WAD\u3001DOOM2.WAD\u2026\uFF09\u3002\u7559\u7A7A\uFF1AFreedoom\u3002"
|
|
478
|
+
},
|
|
479
|
+
placeholder: "~/games/doom1.wad"
|
|
480
|
+
}),
|
|
481
|
+
panels: t.integer({
|
|
482
|
+
default: 1,
|
|
483
|
+
min: 1,
|
|
484
|
+
max: 3,
|
|
485
|
+
label: { en: "Panels in the stack", es: "Paneles de la pila", de: "Panels im Stapel", "zh-Hans": "\u5806\u53E0\u7684\u9762\u677F\u6570", "zh-Hant": "\u5806\u758A\u7684\u9762\u677F\u6578" },
|
|
486
|
+
help: {
|
|
487
|
+
en: "Panels stacked one on top of the other that show one game between them (three 1920\xD7462 bars are nearly 4:3). Give each screen this interlude, at the same times, with its row.",
|
|
488
|
+
es: "Paneles apilados uno encima de otro que muestran una sola partida entre todos (tres barras de 1920\xD7462 son casi 4:3). Pon este interludio en cada pantalla, a las mismas horas, con su fila.",
|
|
489
|
+
de: "\xDCbereinander gestapelte Panels, die gemeinsam ein Spiel zeigen (drei 1920\xD7462-Leisten sind fast 4:3). Gib jedem Bildschirm dieses Zwischenspiel zu denselben Zeiten, mit seiner Reihe.",
|
|
490
|
+
"zh-Hans": "\u4E0A\u4E0B\u5806\u53E0\u3001\u5171\u540C\u663E\u793A\u540C\u4E00\u5C40\u6E38\u620F\u7684\u9762\u677F\u6570\uFF08\u4E09\u5757 1920\xD7462 \u957F\u6761\u5C4F\u63A5\u8FD1 4:3\uFF09\u3002\u5728\u6BCF\u5757\u5C4F\u5E55\u4E0A\u8BBE\u7F6E\u8FD9\u4E2A\u63D2\u66F2\uFF0C\u65F6\u95F4\u76F8\u540C\uFF0C\u5E76\u9009\u62E9\u5404\u81EA\u7684\u884C\u3002",
|
|
491
|
+
"zh-Hant": "\u4E0A\u4E0B\u5806\u758A\u3001\u5171\u540C\u986F\u793A\u540C\u4E00\u5C40\u904A\u6232\u7684\u9762\u677F\u6578\uFF08\u4E09\u584A 1920\xD7462 \u9577\u689D\u87A2\u5E55\u63A5\u8FD1 4:3\uFF09\u3002\u5728\u6BCF\u584A\u87A2\u5E55\u4E0A\u8A2D\u5B9A\u9019\u500B\u63D2\u66F2\uFF0C\u6642\u9593\u76F8\u540C\uFF0C\u4E26\u9078\u64C7\u5404\u81EA\u7684\u5217\u3002"
|
|
492
|
+
}
|
|
493
|
+
}),
|
|
494
|
+
row: t.integer({
|
|
495
|
+
default: 1,
|
|
496
|
+
min: 1,
|
|
497
|
+
max: 3,
|
|
498
|
+
label: { en: "Row in the stack", es: "Fila en la pila", de: "Reihe im Stapel", "zh-Hans": "\u5728\u5806\u53E0\u4E2D\u7684\u884C", "zh-Hant": "\u5728\u5806\u758A\u4E2D\u7684\u5217" },
|
|
499
|
+
help: {
|
|
500
|
+
en: "Which of the stacked panels this screen is: 1 is the top one.",
|
|
501
|
+
es: "Cu\xE1l de los paneles apilados es esta pantalla: 1 es el de arriba.",
|
|
502
|
+
de: "Welches der gestapelten Panels dieser Bildschirm ist: 1 ist das oberste.",
|
|
503
|
+
"zh-Hans": "\u8FD9\u5757\u5C4F\u5E55\u662F\u5806\u53E0\u4E2D\u7684\u54EA\u4E00\u5757\uFF1A1 \u4E3A\u6700\u4E0A\u9762\u3002",
|
|
504
|
+
"zh-Hant": "\u9019\u584A\u87A2\u5E55\u662F\u5806\u758A\u4E2D\u7684\u54EA\u4E00\u584A\uFF1A1 \u70BA\u6700\u4E0A\u9762\u3002"
|
|
505
|
+
}
|
|
506
|
+
}),
|
|
507
|
+
showStats: t.boolean({
|
|
508
|
+
default: true,
|
|
509
|
+
label: { en: "Show the game\u2019s numbers beside it", es: "Mostrar los datos de la partida a los lados", de: "Spielwerte daneben zeigen", "zh-Hans": "\u5728\u4E24\u4FA7\u663E\u793A\u6E38\u620F\u6570\u636E", "zh-Hant": "\u5728\u5169\u5074\u986F\u793A\u904A\u6232\u8CC7\u6599" },
|
|
510
|
+
help: {
|
|
511
|
+
en: "On a wide panel: the map, time, kills, items and secrets on the left; health, armour and ammo on the right.",
|
|
512
|
+
es: "En un panel ancho: el mapa, el tiempo, los enemigos, objetos y secretos a la izquierda; la salud, la armadura y la munici\xF3n a la derecha.",
|
|
513
|
+
de: "Auf einem breiten Panel: Karte, Zeit, Gegner, Gegenst\xE4nde und Geheimnisse links; Gesundheit, R\xFCstung und Munition rechts.",
|
|
514
|
+
"zh-Hans": "\u5728\u5BBD\u5C4F\u9762\u677F\u4E0A\uFF1A\u5DE6\u4FA7\u663E\u793A\u5730\u56FE\u3001\u65F6\u95F4\u3001\u51FB\u6740\u3001\u7269\u54C1\u548C\u79D8\u5BC6\uFF1B\u53F3\u4FA7\u663E\u793A\u751F\u547D\u3001\u62A4\u7532\u548C\u5F39\u836F\u3002",
|
|
515
|
+
"zh-Hant": "\u5728\u5BEC\u87A2\u5E55\u9762\u677F\u4E0A\uFF1A\u5DE6\u5074\u986F\u793A\u5730\u5716\u3001\u6642\u9593\u3001\u64CA\u6BBA\u3001\u7269\u54C1\u8207\u79D8\u5BC6\uFF1B\u53F3\u5074\u986F\u793A\u751F\u547D\u3001\u8B77\u7532\u8207\u5F48\u85E5\u3002"
|
|
516
|
+
}
|
|
517
|
+
})
|
|
518
|
+
}),
|
|
519
|
+
async prepare(ctx) {
|
|
520
|
+
const say = (msg) => ctx.log(`doom: ${msg}`);
|
|
521
|
+
const wadPath = ctx.options.wad.trim().replace(/^~(?=$|[\\/])/, process.env.HOME ?? process.env.USERPROFILE ?? "~");
|
|
522
|
+
const wad = wadPath ? await ownWad(wadPath) : freedoom(ctx.dataDir, say);
|
|
523
|
+
if (!wad.ready) {
|
|
524
|
+
say(`not playing: ${wad.reason}`);
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
const input = ctx.input;
|
|
528
|
+
const game = input ? await SharedGame.join(`${wad.path}#play`, async () => Engine.start({ wad: wad.path, args: await playArgs(wad.path) })) : await SharedGame.join(wad.path, () => Engine.start({ wad: wad.path }));
|
|
529
|
+
const { panels, row: rowOption } = input ? { panels: 1, row: 1 } : stackOf(ctx.options);
|
|
530
|
+
if (input) {
|
|
531
|
+
input.on((e) => {
|
|
532
|
+
const key = PAD_TO_DOOM[e.key];
|
|
533
|
+
if (key !== void 0) game.key(e.pressed, key);
|
|
534
|
+
});
|
|
535
|
+
say(`${wad.name}: a game being played from the Play page`);
|
|
536
|
+
} else say(panels > 1 ? `playing the demos of ${wad.name}, row ${rowOption} of a stack of ${panels}` : `playing the demos of ${wad.name}`);
|
|
537
|
+
const small = ctx.canvas.createCanvas(game.engine.width, game.engine.height);
|
|
538
|
+
const sg = small.getContext("2d");
|
|
539
|
+
const image = sg.createImageData(game.engine.width, game.engine.height);
|
|
540
|
+
const view = viewport(ctx.width, ctx.height * panels);
|
|
541
|
+
const shift = (rowOption - 1) * ctx.height;
|
|
542
|
+
const hud = ctx.options.showStats && panels === 1 ? sides(ctx.width, ctx.height, view) : null;
|
|
543
|
+
let left = false;
|
|
544
|
+
return {
|
|
545
|
+
// Played: for as long as someone presses buttons (Kiosko ends it after a minute without).
|
|
546
|
+
frames: input ? Infinity : MAX_FRAMES,
|
|
547
|
+
async draw(g, i) {
|
|
548
|
+
const f = await game.frame(Date.now());
|
|
549
|
+
image.data.set(f.pixels);
|
|
550
|
+
sg.putImageData(image, 0, 0);
|
|
551
|
+
g.fillStyle = hud ? ctx.theme.colors.bg : "#000";
|
|
552
|
+
g.fillRect(0, 0, ctx.width, ctx.height);
|
|
553
|
+
g.imageSmoothingEnabled = false;
|
|
554
|
+
g.drawImage(small, view.x, view.y - shift, view.w, view.h);
|
|
555
|
+
if (hud) drawHud(g, ctx.theme, ctx.t, f.state, hud, wad.name);
|
|
556
|
+
if (i >= MAX_FRAMES - 1 && !left) {
|
|
557
|
+
left = true;
|
|
558
|
+
game.leave();
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
var index_default = definePlugin({
|
|
565
|
+
id: "doom",
|
|
566
|
+
name: { en: "Doom", es: "Doom", de: "Doom", "zh-Hans": "Doom", "zh-Hant": "Doom" },
|
|
567
|
+
version: "0.2.0",
|
|
568
|
+
description: {
|
|
569
|
+
en: "Doom on your panel: the game plays its own demos as an interlude. The engine (doomgeneric, GPL) runs in a process of its own; the levels are Freedoom unless you bring your own IWAD.",
|
|
570
|
+
es: "Doom en tu panel: el juego reproduce sus propias demos como interludio. El motor (doomgeneric, GPL) corre en un proceso propio; los niveles son de Freedoom salvo que pongas tu propio IWAD.",
|
|
571
|
+
de: "Doom auf deinem Panel: Das Spiel zeigt seine eigenen Demos als Zwischenspiel. Die Engine (doomgeneric, GPL) l\xE4uft in einem eigenen Prozess; die Level sind Freedoom, au\xDFer du bringst dein eigenes IWAD mit.",
|
|
572
|
+
"zh-Hans": "\u5728\u9762\u677F\u4E0A\u8FD0\u884C Doom\uFF1A\u6E38\u620F\u628A\u81EA\u5DF1\u7684\u6F14\u793A\u4F5C\u4E3A\u63D2\u66F2\u64AD\u653E\u3002\u5F15\u64CE\uFF08doomgeneric\uFF0CGPL\uFF09\u5728\u72EC\u7ACB\u8FDB\u7A0B\u4E2D\u8FD0\u884C\uFF1B\u5173\u5361\u9ED8\u8BA4\u6765\u81EA Freedoom\uFF0C\u4E5F\u53EF\u4F7F\u7528\u4F60\u81EA\u5DF1\u7684 IWAD\u3002",
|
|
573
|
+
"zh-Hant": "\u5728\u9762\u677F\u4E0A\u57F7\u884C Doom\uFF1A\u904A\u6232\u628A\u81EA\u5DF1\u7684\u793A\u7BC4\u7576\u4F5C\u63D2\u66F2\u64AD\u653E\u3002\u5F15\u64CE\uFF08doomgeneric\uFF0CGPL\uFF09\u5728\u7368\u7ACB\u884C\u7A0B\u4E2D\u57F7\u884C\uFF1B\u95DC\u5361\u9810\u8A2D\u4F86\u81EA Freedoom\uFF0C\u4E5F\u53EF\u4F7F\u7528\u4F60\u81EA\u5DF1\u7684 IWAD\u3002"
|
|
574
|
+
},
|
|
575
|
+
author: "Loksly",
|
|
576
|
+
license: "GPL-2.0-or-later",
|
|
577
|
+
homepage: "https://github.com/kiosko-lcd/kiosko-plugin-doom#readme",
|
|
578
|
+
repository: "https://github.com/kiosko-lcd/kiosko-plugin-doom",
|
|
579
|
+
sdk: "^0.2.0",
|
|
580
|
+
languages: ["en", "es", "de", "zh-Hant", "zh-Hans"],
|
|
581
|
+
permissions: {
|
|
582
|
+
network: ["github.com", "release-assets.githubusercontent.com"],
|
|
583
|
+
exec: ["node"],
|
|
584
|
+
files: ["user"]
|
|
585
|
+
},
|
|
586
|
+
interludes: [attract]
|
|
587
|
+
});
|
|
588
|
+
export {
|
|
589
|
+
ASPECT,
|
|
590
|
+
attract,
|
|
591
|
+
index_default as default,
|
|
592
|
+
playArgs,
|
|
593
|
+
stackOf,
|
|
594
|
+
viewport
|
|
595
|
+
};
|
package/docs/attract.jpg
ADDED
|
Binary file
|
package/docs/stack.jpg
ADDED
|
Binary file
|