Download environments/games/web/engine/load.js from THUSI-Lab/GameDojo: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/datasets/THUSI-Lab/GameDojo/resolve/main/environments/games/web/engine/load.js
- Command line
-
hf download hf://datasets/THUSI-Lab/GameDojo/environments/games/web/engine/load.js
-
curl -L -o load.js https://huggingface.co/datasets/THUSI-Lab/GameDojo/resolve/main/environments/games/web/engine/load.js
1.11 kB
| // Node loader for one game: runs every <script> of <gameDir>/index.html in page order, minus the browser-only | |
| // UI (engine/input.js, engine/app.js), so Node and the browser execute the same files in the same order. | |
| // One game per process: games share the BB global (BB.ARENA, BB.VIEW, ...). | |
| // usage: var BB = require('<web>/engine/load.js')(gameDir) | |
| var path = require('path'), fs = require('fs'); | |
| var BROWSER_ONLY = /(^|\/)engine\/(input|app)\.js$/; | |
| function scripts(gameDir) { | |
| var html = fs.readFileSync(path.join(gameDir, 'index.html'), 'utf8'), out = [], re = /<script src="([^"]+)"/g, m; | |
| while ((m = re.exec(html))) if (!BROWSER_ONLY.test(m[1])) out.push(m[1]); | |
| return out; | |
| } | |
| function load(gameDir) { | |
| gameDir = path.resolve(gameDir); | |
| if (globalThis.BB && globalThis.BB.GAME_DIR && globalThis.BB.GAME_DIR !== gameDir) throw new Error('one game per process: ' + globalThis.BB.GAME_DIR + ' already loaded'); | |
| scripts(gameDir).forEach(function (s) { require(path.join(gameDir, s)); }); | |
| globalThis.BB.GAME_DIR = gameDir; | |
| return globalThis.BB; | |
| } | |
| load.scripts = scripts; | |
| module.exports = load; | |