samengine 1.9.0 → 1.10.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 +201 -0
- package/README.md +203 -0
- package/dist/config/buildconfig.d.ts +146 -0
- package/dist/config/buildconfig.js +115 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.js +1 -0
- package/dist/core.d.ts +17 -0
- package/dist/core.js +24 -0
- package/dist/html.d.ts +29 -0
- package/dist/html.js +20 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -2
- package/dist/input.d.ts +51 -0
- package/dist/input.js +44 -3
- package/dist/keys.d.ts +6 -0
- package/dist/keys.js +6 -2
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +8 -1
- package/dist/nonbrowser/getversion.d.ts +13 -0
- package/dist/nonbrowser/getversion.js +35 -0
- package/dist/nonbrowser/ghresolver.d.ts +1 -0
- package/dist/nonbrowser/ghresolver.js +7 -0
- package/dist/nonbrowser/index.d.ts +9 -0
- package/dist/nonbrowser/index.js +9 -0
- package/dist/nonbrowser/internal/buildhelper.d.ts +42 -0
- package/dist/nonbrowser/internal/buildhelper.js +144 -0
- package/dist/nonbrowser/internal/cli/argparser.d.ts +20 -0
- package/dist/nonbrowser/internal/cli/argparser.js +36 -0
- package/dist/nonbrowser/internal/cli/main.d.ts +13 -0
- package/dist/nonbrowser/internal/cli/main.js +262 -0
- package/dist/nonbrowser/internal/config.d.ts +9 -0
- package/dist/nonbrowser/internal/config.js +40 -0
- package/dist/nonbrowser/internal/exporthtml.d.ts +37 -0
- package/dist/nonbrowser/internal/exporthtml.js +622 -0
- package/dist/nonbrowser/internal/projcreator/downloadZip.d.ts +4 -0
- package/dist/nonbrowser/internal/projcreator/downloadZip.js +83 -0
- package/dist/nonbrowser/internal/projcreator/main.d.ts +1 -0
- package/dist/nonbrowser/internal/projcreator/main.js +81 -0
- package/dist/nonbrowser/utils.d.ts +8 -0
- package/dist/nonbrowser/utils.js +18 -0
- package/dist/physics/collision.d.ts +33 -0
- package/dist/physics/collision.js +27 -0
- package/dist/physics/physicsEngine.d.ts +18 -0
- package/dist/physics/physicsEngine.js +18 -0
- package/dist/physics/physicsObject.d.ts +20 -0
- package/dist/physics/physicsObject.js +20 -0
- package/dist/renderer.d.ts +85 -2
- package/dist/renderer.js +86 -7
- package/dist/samegui/index.d.ts +49 -0
- package/dist/samegui/index.js +137 -0
- package/dist/save.d.ts +30 -0
- package/dist/save.js +25 -0
- package/dist/sound/audioplayer.d.ts +39 -0
- package/dist/sound/audioplayer.js +39 -5
- package/dist/storage/index.d.ts +57 -0
- package/dist/storage/index.js +89 -0
- package/dist/text/index.d.ts +14 -0
- package/dist/text/index.js +58 -0
- package/dist/texture.d.ts +100 -0
- package/dist/texture.js +75 -41
- package/dist/types/button.d.ts +25 -0
- package/dist/types/button.js +22 -0
- package/dist/types/circle.d.ts +26 -0
- package/dist/types/circle.js +21 -7
- package/dist/types/color.d.ts +17 -0
- package/dist/types/color.js +11 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/rectangle.d.ts +29 -0
- package/dist/types/rectangle.js +23 -6
- package/dist/types/triangle.d.ts +23 -0
- package/dist/types/triangle.js +20 -6
- package/dist/types/vector2d.d.ts +42 -0
- package/dist/types/vector2d.js +39 -11
- package/dist/types/vector3d.d.ts +38 -0
- package/dist/types/vector3d.js +35 -11
- package/dist/utils/index.d.ts +13 -4
- package/dist/utils/index.js +26 -2
- package/dist/utils/logger/index.d.ts +24 -0
- package/dist/utils/logger/index.js +44 -0
- package/dist/utils/math.d.ts +18 -0
- package/dist/utils/math.js +18 -4
- package/package.json +40 -10
- package/dist/utils/jsonc-parser.d.ts +0 -4
- package/dist/utils/jsonc-parser.js +0 -166
- package/dist/utils/markdown.d.ts +0 -41
- package/dist/utils/markdown.js +0 -699
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses CLI arguments from `process.argv`.
|
|
3
|
+
*
|
|
4
|
+
* Unknown arguments are reported as warnings instead of crashing the process, so
|
|
5
|
+
* the CLI stays forgiving while still making mistakes visible.
|
|
6
|
+
*/
|
|
7
|
+
export function parseArgs() {
|
|
8
|
+
const args = process.argv.slice(2);
|
|
9
|
+
const options = { release: false, singlefile: false, newProject: false, empty: false, help: false };
|
|
10
|
+
for (let i = 0; i < args.length; i++) {
|
|
11
|
+
const arg = args[i];
|
|
12
|
+
switch (arg) {
|
|
13
|
+
case "--release":
|
|
14
|
+
case "-r":
|
|
15
|
+
options.release = true;
|
|
16
|
+
break;
|
|
17
|
+
case "create":
|
|
18
|
+
case "new":
|
|
19
|
+
case "--new":
|
|
20
|
+
case "-n":
|
|
21
|
+
case "--new-empty":
|
|
22
|
+
options.newProject = true;
|
|
23
|
+
break;
|
|
24
|
+
case "help":
|
|
25
|
+
case "h":
|
|
26
|
+
case "-h":
|
|
27
|
+
case "--help":
|
|
28
|
+
options.help = true;
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
console.warn(`⚠️ Unknown Argument: ${arg}`);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return options;
|
|
36
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CLI entry point for `samengine-build`.
|
|
4
|
+
*
|
|
5
|
+
* High-level flow:
|
|
6
|
+
* 1. Parse CLI arguments.
|
|
7
|
+
* 2. Optionally create a new project.
|
|
8
|
+
* 3. Load `samengine.config.ts`.
|
|
9
|
+
* 4. Bundle the game with esbuild.
|
|
10
|
+
* 5. Generate HTML and handle resources.
|
|
11
|
+
* 6. In development mode, start a local server and watch for changes.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CLI entry point for `samengine-build`.
|
|
4
|
+
*
|
|
5
|
+
* High-level flow:
|
|
6
|
+
* 1. Parse CLI arguments.
|
|
7
|
+
* 2. Optionally create a new project.
|
|
8
|
+
* 3. Load `samengine.config.ts`.
|
|
9
|
+
* 4. Bundle the game with esbuild.
|
|
10
|
+
* 5. Generate HTML and handle resources.
|
|
11
|
+
* 6. In development mode, start a local server and watch for changes.
|
|
12
|
+
*/
|
|
13
|
+
import { build as esbuild } from "esbuild";
|
|
14
|
+
import { createServer } from "http";
|
|
15
|
+
import { readFile, writeFile, mkdir, rm } from "fs/promises";
|
|
16
|
+
import { watch, watchFile } from "fs";
|
|
17
|
+
import path from "path";
|
|
18
|
+
import { WebSocketServer } from "ws";
|
|
19
|
+
import { copyFolder, flog, getContentType, scanResourcesAsDataURIs, filterResourcesByUsage } from "./../buildhelper.js";
|
|
20
|
+
import { GetDefaultHTML, GetSingleFileHTML, getVersion } from "../exporthtml.js";
|
|
21
|
+
import { loadUserConfig } from "./../config.js";
|
|
22
|
+
import { compressHTML } from "../../index.js";
|
|
23
|
+
import { parseArgs } from "./argparser.js";
|
|
24
|
+
import { run as runCreateProject } from "../projcreator/main.js";
|
|
25
|
+
// ================= HELP ============
|
|
26
|
+
/**
|
|
27
|
+
* Function to print Help
|
|
28
|
+
*/
|
|
29
|
+
function showHelp() {
|
|
30
|
+
console.log(`
|
|
31
|
+
███████╗ █████╗ ███╗ ███╗███████╗███╗ ██╗ ██████╗ ██╗███╗ ██╗███████╗
|
|
32
|
+
██╔════╝██╔══██╗████╗ ████║██╔════╝████╗ ██║██╔════╝ ██║████╗ ██║██╔════╝
|
|
33
|
+
███████╗███████║██╔████╔██║█████╗ ██╔██╗ ██║██║ ███╗██║██╔██╗ ██║█████╗
|
|
34
|
+
╚════██║██╔══██║██║╚██╔╝██║██╔══╝ ██║╚██╗██║██║ ██║██║██║╚██╗██║██╔══╝
|
|
35
|
+
███████║██║ ██║██║ ╚═╝ ██║███████╗██║ ╚████║╚██████╔╝██║██║ ╚████║███████╗
|
|
36
|
+
╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝╚══════╝
|
|
37
|
+
|
|
38
|
+
CLI Tool for samengine
|
|
39
|
+
|
|
40
|
+
Usage:
|
|
41
|
+
-r, --release build the project in Release Mode
|
|
42
|
+
create create a new project
|
|
43
|
+
help Show this menu
|
|
44
|
+
|
|
45
|
+
More: samfile
|
|
46
|
+
use with @shadowdara/samtool
|
|
47
|
+
Install: npm i @shadowdara/samtool
|
|
48
|
+
`);
|
|
49
|
+
}
|
|
50
|
+
// ================= BUILD =================
|
|
51
|
+
/**
|
|
52
|
+
* Creates a build runner for one config object and one build mode.
|
|
53
|
+
*
|
|
54
|
+
* The returned `build` function owns the esbuild call, generated HTML, resource
|
|
55
|
+
* copying or embedding, release minification, and metadata comments. Dev builds
|
|
56
|
+
* keep source maps; release builds clean the output directory first.
|
|
57
|
+
*/
|
|
58
|
+
function createBuilder(config, isRelease) {
|
|
59
|
+
// Ensure that the Directories are created
|
|
60
|
+
mkdir("resources", { recursive: true });
|
|
61
|
+
mkdir("game", { recursive: true });
|
|
62
|
+
async function build() {
|
|
63
|
+
try {
|
|
64
|
+
flog("🔄 Building project...");
|
|
65
|
+
if (isRelease)
|
|
66
|
+
await rm(`./${config.outdir}`, { recursive: true, force: true });
|
|
67
|
+
await esbuild({
|
|
68
|
+
entryPoints: [`./game/${config.entryname}`],
|
|
69
|
+
outdir: `./${config.outdir}`,
|
|
70
|
+
bundle: true,
|
|
71
|
+
platform: "browser",
|
|
72
|
+
minify: isRelease,
|
|
73
|
+
sourcemap: !isRelease,
|
|
74
|
+
define: { "import.meta.env.DEV": JSON.stringify(!isRelease) },
|
|
75
|
+
});
|
|
76
|
+
if (isRelease && config.releaseMode.singlefile || !isRelease && config.devMode.singlefile) {
|
|
77
|
+
// Single-file export
|
|
78
|
+
const bundledJsPath = path.join(".", config.outdir, `${config.entryname.replace(/\.[^.]*$/, "")}.js`);
|
|
79
|
+
const bundledJsContent = await readFile(bundledJsPath, "utf-8");
|
|
80
|
+
// Scan resources and convert to data URIs
|
|
81
|
+
let resourcesMap = await scanResourcesAsDataURIs("./resources");
|
|
82
|
+
// Filter resources by usage in the bundled code
|
|
83
|
+
resourcesMap = filterResourcesByUsage(bundledJsContent, resourcesMap);
|
|
84
|
+
let html = GetSingleFileHTML(config, bundledJsContent, resourcesMap);
|
|
85
|
+
if (isRelease)
|
|
86
|
+
html = await compressHTML(html);
|
|
87
|
+
// Add comment at the beginning after minification
|
|
88
|
+
const htmlComment = `<!-- Game made with samengine v${getVersion()} - https://github.com/Shadowdara/samengine ${config.gameauthor} (Game Author) -->\n`;
|
|
89
|
+
html = htmlComment + html;
|
|
90
|
+
await writeFile(`./${config.outdir}/index.html`, html);
|
|
91
|
+
// Delete the JS File
|
|
92
|
+
await rm(`./${config.outdir}/main.js`, { recursive: true, force: true });
|
|
93
|
+
flog("✅ Single-file export created!");
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// Multi-file export (original behavior)
|
|
97
|
+
let html = GetDefaultHTML(config, isRelease);
|
|
98
|
+
if (isRelease)
|
|
99
|
+
html = await compressHTML(html);
|
|
100
|
+
// Add HTML comment at the beginning after minification
|
|
101
|
+
const htmlComment = `<!-- Game made with samengine v${getVersion()} - https://www.npmjs.com/samengine ${config.gameauthor} (Game Author) -->\n`;
|
|
102
|
+
html = htmlComment + html;
|
|
103
|
+
await writeFile(`./${config.outdir}/index.html`, html);
|
|
104
|
+
// Add JS comment at the beginning of JS files
|
|
105
|
+
const jsComment = `// Game made with samengine v${getVersion()} - https://www.npmjs.com/samengine by ${config.gameauthor} (Game Author)\n`;
|
|
106
|
+
const jsPath = path.join(".", config.outdir, `${config.entryname.replace(/\.[^.]*$/, "")}.js`);
|
|
107
|
+
let jsContent = await readFile(jsPath, "utf-8");
|
|
108
|
+
jsContent = jsComment + jsContent;
|
|
109
|
+
await writeFile(jsPath, jsContent);
|
|
110
|
+
await copyFolder("./resources", `./${config.outdir}/resources`);
|
|
111
|
+
flog("✅ Build finished!");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
flog(`❌ Build failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return { build };
|
|
119
|
+
}
|
|
120
|
+
// ================= SERVER & RELOAD =================
|
|
121
|
+
/**
|
|
122
|
+
* Starts the local development server for the configured output directory.
|
|
123
|
+
*
|
|
124
|
+
* Static files are served from `config.outdir`. A WebSocket server is attached
|
|
125
|
+
* to the same HTTP server so future rebuilds can notify connected browsers.
|
|
126
|
+
*/
|
|
127
|
+
function createDevServer(config) {
|
|
128
|
+
const sockets = new Set();
|
|
129
|
+
const server = createServer(async (req, res) => {
|
|
130
|
+
const url = req.url || "/";
|
|
131
|
+
const filePath = path.join(process.cwd(), `${config.outdir}`, url === "/" ? "index.html" : url);
|
|
132
|
+
try {
|
|
133
|
+
const file = await readFile(filePath);
|
|
134
|
+
res.writeHead(200, { "Content-Type": getContentType(filePath) });
|
|
135
|
+
res.end(file);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
res.writeHead(404);
|
|
139
|
+
res.end("Not Found");
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const wss = new WebSocketServer({ server });
|
|
143
|
+
wss.on("connection", (ws) => {
|
|
144
|
+
sockets.add(ws);
|
|
145
|
+
ws.on("close", () => sockets.delete(ws));
|
|
146
|
+
});
|
|
147
|
+
function startListening(port) {
|
|
148
|
+
server.listen(port);
|
|
149
|
+
server.on("listening", () => {
|
|
150
|
+
flog(`🚀 Dev Server running on http://localhost:${port}`);
|
|
151
|
+
});
|
|
152
|
+
server.on("error", (err) => {
|
|
153
|
+
if (err.code === "EADDRINUSE") {
|
|
154
|
+
flog(`⚠️ Port ${port} is already in use, trying ${port + 1}...`);
|
|
155
|
+
startListening(port + 1);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
throw err;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
startListening(config.dev_server_port);
|
|
163
|
+
function reloadClients() {
|
|
164
|
+
flog("🔄 Browser reload...");
|
|
165
|
+
sockets.forEach((ws) => ws.send("reload"));
|
|
166
|
+
}
|
|
167
|
+
function stop() {
|
|
168
|
+
flog("🛑 Stopping dev server...");
|
|
169
|
+
sockets.forEach(ws => ws.close());
|
|
170
|
+
wss.close();
|
|
171
|
+
server.close();
|
|
172
|
+
}
|
|
173
|
+
return { reloadClients, stop };
|
|
174
|
+
}
|
|
175
|
+
// ================= WATCHER =================
|
|
176
|
+
/**
|
|
177
|
+
* Watches the `resources` and `game` folders recursively.
|
|
178
|
+
*
|
|
179
|
+
* The watcher delegates rebuild scheduling to `onChange`. The main function
|
|
180
|
+
* serializes rebuilds so multiple file-system events do not run overlapping
|
|
181
|
+
* builds.
|
|
182
|
+
*/
|
|
183
|
+
async function startWatcher(onChange) {
|
|
184
|
+
await mkdir("resources", { recursive: true });
|
|
185
|
+
await mkdir("game", { recursive: true });
|
|
186
|
+
["resources", "game"].forEach((dir) => {
|
|
187
|
+
watch(dir, { recursive: true }, async () => {
|
|
188
|
+
flog(`📁 Change noticed in ${dir}`);
|
|
189
|
+
await onChange();
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
flog("👀 Watcher active...");
|
|
193
|
+
}
|
|
194
|
+
// ================= CLI APP =================
|
|
195
|
+
/**
|
|
196
|
+
* Runs the CLI application.
|
|
197
|
+
*
|
|
198
|
+
* Development mode starts with one build, then creates a server and watchers.
|
|
199
|
+
* Config changes trigger a full restart because output folder, port, menu, or
|
|
200
|
+
* other generated HTML settings may have changed.
|
|
201
|
+
*/
|
|
202
|
+
async function main() {
|
|
203
|
+
const args = parseArgs();
|
|
204
|
+
if (args.newProject) {
|
|
205
|
+
await runCreateProject();
|
|
206
|
+
process.exit(0);
|
|
207
|
+
}
|
|
208
|
+
if (args.help) {
|
|
209
|
+
showHelp();
|
|
210
|
+
process.exit(0);
|
|
211
|
+
}
|
|
212
|
+
const config = await loadUserConfig();
|
|
213
|
+
let builder = createBuilder(config, args.release);
|
|
214
|
+
let isBuilding = false;
|
|
215
|
+
let pendingRestart = false;
|
|
216
|
+
async function restart() {
|
|
217
|
+
if (isBuilding) {
|
|
218
|
+
pendingRestart = true;
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
isBuilding = true;
|
|
222
|
+
do {
|
|
223
|
+
pendingRestart = false;
|
|
224
|
+
try {
|
|
225
|
+
// Load the New Config
|
|
226
|
+
const newConfig = await loadUserConfig();
|
|
227
|
+
// Dev Server Stoppen
|
|
228
|
+
devServer?.stop();
|
|
229
|
+
// Create new Dev Server
|
|
230
|
+
devServer = createDevServer(newConfig);
|
|
231
|
+
// New Builder (use the new Config)
|
|
232
|
+
builder = createBuilder(newConfig, args.release);
|
|
233
|
+
await builder.build();
|
|
234
|
+
devServer?.reloadClients();
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
flog(`❌ Rebuild failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
238
|
+
}
|
|
239
|
+
} while (pendingRestart);
|
|
240
|
+
isBuilding = false;
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
await builder.build();
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
flog(`❌ Initial build failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
247
|
+
}
|
|
248
|
+
let devServer = null;
|
|
249
|
+
// Only start the Dev Server in Release Mode
|
|
250
|
+
if (!args.release) {
|
|
251
|
+
devServer = createDevServer(config);
|
|
252
|
+
// Watch the config separately because changing it can require a server restart.
|
|
253
|
+
watchFile("samengine.config.ts", { interval: 300 }, async () => {
|
|
254
|
+
flog("⚙️ Config file changed → full restart");
|
|
255
|
+
await restart();
|
|
256
|
+
});
|
|
257
|
+
await startWatcher(restart);
|
|
258
|
+
}
|
|
259
|
+
// Dev or Release Mode
|
|
260
|
+
flog(`Build finished! Mode: ${args.release ? "Release" : "Dev"}`);
|
|
261
|
+
}
|
|
262
|
+
main();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loads `samengine.config.ts` from the current project directory.
|
|
3
|
+
*
|
|
4
|
+
* Node cannot import TypeScript config files directly, so the file is bundled to
|
|
5
|
+
* `.samengine/config.mjs` with esbuild first. The generated file is then loaded
|
|
6
|
+
* through a dynamic ESM import. A timestamp query parameter bypasses Node's
|
|
7
|
+
* import cache, which lets the watch mode see changed config values immediately.
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadUserConfig(): Promise<any>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { build } from "esbuild";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { pathToFileURL } from "url";
|
|
4
|
+
import fs from "fs/promises";
|
|
5
|
+
/**
|
|
6
|
+
* Loads `samengine.config.ts` from the current project directory.
|
|
7
|
+
*
|
|
8
|
+
* Node cannot import TypeScript config files directly, so the file is bundled to
|
|
9
|
+
* `.samengine/config.mjs` with esbuild first. The generated file is then loaded
|
|
10
|
+
* through a dynamic ESM import. A timestamp query parameter bypasses Node's
|
|
11
|
+
* import cache, which lets the watch mode see changed config values immediately.
|
|
12
|
+
*/
|
|
13
|
+
export async function loadUserConfig() {
|
|
14
|
+
const root = process.cwd();
|
|
15
|
+
const configPath = path.resolve(root, "samengine.config.ts");
|
|
16
|
+
const outDir = path.resolve(root, ".samengine");
|
|
17
|
+
const outfile = path.join(outDir, "config.mjs");
|
|
18
|
+
try {
|
|
19
|
+
// ensure folder exists
|
|
20
|
+
await fs.mkdir(outDir, { recursive: true });
|
|
21
|
+
// 🔥 bundle TS → JS
|
|
22
|
+
await build({
|
|
23
|
+
entryPoints: [configPath],
|
|
24
|
+
outfile,
|
|
25
|
+
bundle: true,
|
|
26
|
+
platform: "node",
|
|
27
|
+
format: "esm",
|
|
28
|
+
});
|
|
29
|
+
// 🔥 import compiled file
|
|
30
|
+
const mod = await import(pathToFileURL(outfile).href + `?t=${Date.now()}`);
|
|
31
|
+
const config = typeof mod.default === "function"
|
|
32
|
+
? await mod.default()
|
|
33
|
+
: mod.default;
|
|
34
|
+
return config;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
console.error(e);
|
|
38
|
+
throw new Error("❌ Could not load samengine.config.ts: " + configPath);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML generation for samengine-build.
|
|
3
|
+
*
|
|
4
|
+
* This module creates the complete `index.html` written into the output folder.
|
|
5
|
+
* There are two build shapes:
|
|
6
|
+
*
|
|
7
|
+
* - `GetDefaultHTML` creates a normal multi-file page that imports the bundled
|
|
8
|
+
* game JavaScript after the player clicks the start button.
|
|
9
|
+
* - `GetSingleFileHTML` embeds the bundled JavaScript and optional resource
|
|
10
|
+
* Data URIs directly into one HTML document.
|
|
11
|
+
*/
|
|
12
|
+
import type { buildconfig } from "../../config/buildconfig.js";
|
|
13
|
+
/**
|
|
14
|
+
* Function to get the samengine Version
|
|
15
|
+
*
|
|
16
|
+
* @deprecated WARN Function should not be used outside samengine. Use getPackageVersion instead!
|
|
17
|
+
*/
|
|
18
|
+
export declare function getVersion(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a complete single-file HTML document.
|
|
21
|
+
*
|
|
22
|
+
* `bundledJsContent` is the already bundled game code from esbuild.
|
|
23
|
+
* `resourcesMap` contains optional Data URIs that are exposed through
|
|
24
|
+
* `window.__resources`, `window.__getResource`, and `window.__loadResource`.
|
|
25
|
+
*
|
|
26
|
+
* The bundled game is wrapped in `window.__initializeGame` so it does not run
|
|
27
|
+
* until the player clicks the start button. This allows the generated page to
|
|
28
|
+
* show the start screen, unlock audio, and remove temporary UI first.
|
|
29
|
+
*/
|
|
30
|
+
export declare function GetSingleFileHTML(config: buildconfig, bundledJsContent: string, resourcesMap?: Record<string, string>): string;
|
|
31
|
+
/**
|
|
32
|
+
* Creates the normal multi-file HTML document.
|
|
33
|
+
*
|
|
34
|
+
* This page contains the generated start screen and optional menu UI. The game
|
|
35
|
+
* bundle is loaded with a dynamic import only after the start button is clicked.
|
|
36
|
+
*/
|
|
37
|
+
export declare function GetDefaultHTML(config: buildconfig, releasemode: boolean): string;
|