@al8b/runtime 0.1.12 → 0.1.14
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/dist/assets/index.d.mts +0 -1
- package/dist/assets/index.d.ts +0 -1
- package/dist/assets/loader.d.mts +0 -1
- package/dist/assets/loader.d.ts +0 -1
- package/dist/browser/index.js +780 -2681
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.min.js +27 -39
- package/dist/core/api-factory.d.mts +1 -5
- package/dist/core/api-factory.d.ts +1 -5
- package/dist/core/api-factory.js +17 -38
- package/dist/core/api-factory.js.map +1 -1
- package/dist/core/api-factory.mjs +18 -38
- package/dist/core/api-factory.mjs.map +1 -1
- package/dist/core/controller.d.mts +0 -5
- package/dist/core/controller.d.ts +0 -5
- package/dist/core/controller.js +23 -98
- package/dist/core/controller.js.map +1 -1
- package/dist/core/controller.mjs +24 -99
- package/dist/core/controller.mjs.map +1 -1
- package/dist/core/debug-logger.d.mts +0 -1
- package/dist/core/debug-logger.d.ts +0 -1
- package/dist/core/error-handler.d.mts +1 -2
- package/dist/core/error-handler.d.ts +1 -2
- package/dist/core/error-handler.js +2 -17
- package/dist/core/error-handler.js.map +1 -1
- package/dist/core/error-handler.mjs +2 -17
- package/dist/core/error-handler.mjs.map +1 -1
- package/dist/core/index.d.mts +0 -2
- package/dist/core/index.d.ts +0 -2
- package/dist/core/index.js +23 -98
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +24 -99
- package/dist/core/index.mjs.map +1 -1
- package/dist/hot-reload/index.d.mts +0 -1
- package/dist/hot-reload/index.d.ts +0 -1
- package/dist/hot-reload/index.js.map +1 -1
- package/dist/hot-reload/index.mjs.map +1 -1
- package/dist/hot-reload/updater.d.mts +0 -1
- package/dist/hot-reload/updater.d.ts +0 -1
- package/dist/hot-reload/updater.js.map +1 -1
- package/dist/hot-reload/updater.mjs.map +1 -1
- package/dist/index.d.mts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +23 -98
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -99
- package/dist/index.mjs.map +1 -1
- package/dist/types/bridge.d.mts +0 -4
- package/dist/types/bridge.d.ts +0 -4
- package/dist/types/bridge.js.map +1 -1
- package/dist/types/index.d.mts +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/runtime.d.mts +13 -2
- package/dist/types/runtime.d.ts +13 -2
- package/dist/types/runtime.js.map +1 -1
- package/package.json +46 -50
package/dist/core/controller.js
CHANGED
|
@@ -27,7 +27,6 @@ __export(controller_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(controller_exports);
|
|
28
28
|
var import_audio3 = require("@al8b/audio");
|
|
29
29
|
var import_player = require("@al8b/player");
|
|
30
|
-
var import_scene = require("@al8b/scene");
|
|
31
30
|
var import_screen = require("@al8b/screen");
|
|
32
31
|
var import_time = require("@al8b/time");
|
|
33
32
|
var import_vm2 = require("@al8b/vm");
|
|
@@ -748,29 +747,14 @@ function shallowEqual(obj1, obj2) {
|
|
|
748
747
|
__name(shallowEqual, "shallowEqual");
|
|
749
748
|
|
|
750
749
|
// src/core/error-handler.ts
|
|
751
|
-
var import_diagnostics = require("@al8b/diagnostics");
|
|
752
750
|
function formatRuntimeError(error) {
|
|
753
751
|
if (error.code || error.context || error.suggestions) {
|
|
754
752
|
return error;
|
|
755
753
|
}
|
|
756
|
-
const code = error.code || "E2005";
|
|
757
|
-
const diagnostic = (0, import_diagnostics.createDiagnostic)(code, {
|
|
758
|
-
file: error.file,
|
|
759
|
-
line: error.line,
|
|
760
|
-
column: error.column,
|
|
761
|
-
context: error.context,
|
|
762
|
-
suggestions: error.suggestions,
|
|
763
|
-
related: error.related,
|
|
764
|
-
stackTrace: error.stackTrace,
|
|
765
|
-
data: {
|
|
766
|
-
error: error.error || error.message
|
|
767
|
-
}
|
|
768
|
-
});
|
|
769
|
-
const formattedMessage = (0, import_diagnostics.formatForBrowser)(diagnostic);
|
|
770
754
|
return {
|
|
771
755
|
...error,
|
|
772
|
-
|
|
773
|
-
formatted:
|
|
756
|
+
code: error.code || "E2005",
|
|
757
|
+
formatted: error.message || String(error)
|
|
774
758
|
};
|
|
775
759
|
}
|
|
776
760
|
__name(formatRuntimeError, "formatRuntimeError");
|
|
@@ -1002,12 +986,6 @@ function createRuntimeGlobalApi(context) {
|
|
|
1002
986
|
session,
|
|
1003
987
|
memory,
|
|
1004
988
|
system: context.system.getAPI(),
|
|
1005
|
-
scene: /* @__PURE__ */ __name((name, definition) => {
|
|
1006
|
-
const convertedDefinition = convertSceneDefinition(asSceneDefinition(definition), context.getVM(), context.listener);
|
|
1007
|
-
context.sceneManager.registerScene(name, convertedDefinition);
|
|
1008
|
-
}, "scene"),
|
|
1009
|
-
route: /* @__PURE__ */ __name((path, sceneName) => context.sceneManager.registerRoute(path, sceneName), "route"),
|
|
1010
|
-
router: context.sceneManager.router.getInterface(),
|
|
1011
989
|
Image: import_image.Image,
|
|
1012
990
|
Sprite: import_sprites.Sprite,
|
|
1013
991
|
TileMap: import_map.TileMap,
|
|
@@ -1018,40 +996,27 @@ function createRuntimeGlobalApi(context) {
|
|
|
1018
996
|
};
|
|
1019
997
|
}
|
|
1020
998
|
__name(createRuntimeGlobalApi, "createRuntimeGlobalApi");
|
|
1021
|
-
function convertSceneDefinition(definition, vm, listener) {
|
|
1022
|
-
if (!vm?.runner?.main_thread?.processor) {
|
|
1023
|
-
listener.log?.("[RuntimeController] VM not ready for scene conversion. Scene functions may not work correctly.");
|
|
1024
|
-
return definition;
|
|
1025
|
-
}
|
|
1026
|
-
const processor = vm.runner.main_thread.processor;
|
|
1027
|
-
const context = vm.context;
|
|
1028
|
-
const converted = {};
|
|
1029
|
-
for (const [key, value] of Object.entries(definition)) {
|
|
1030
|
-
if (value instanceof import_vm.Routine) {
|
|
1031
|
-
converted[key] = processor.routineAsFunction(value, context);
|
|
1032
|
-
continue;
|
|
1033
|
-
}
|
|
1034
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
1035
|
-
converted[key] = convertSceneDefinition(value, vm, listener);
|
|
1036
|
-
continue;
|
|
1037
|
-
}
|
|
1038
|
-
converted[key] = value;
|
|
1039
|
-
}
|
|
1040
|
-
return converted;
|
|
1041
|
-
}
|
|
1042
|
-
__name(convertSceneDefinition, "convertSceneDefinition");
|
|
1043
|
-
function asSceneDefinition(definition) {
|
|
1044
|
-
if (!definition || typeof definition !== "object" || Array.isArray(definition)) {
|
|
1045
|
-
throw new Error("Scene definition must be an object.");
|
|
1046
|
-
}
|
|
1047
|
-
return definition;
|
|
1048
|
-
}
|
|
1049
|
-
__name(asSceneDefinition, "asSceneDefinition");
|
|
1050
999
|
function cloneValue(value) {
|
|
1051
1000
|
if (value == null) {
|
|
1052
1001
|
return value;
|
|
1053
1002
|
}
|
|
1054
|
-
|
|
1003
|
+
if (value instanceof Date) {
|
|
1004
|
+
return new Date(value);
|
|
1005
|
+
}
|
|
1006
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
1007
|
+
return value;
|
|
1008
|
+
}
|
|
1009
|
+
if (Array.isArray(value)) {
|
|
1010
|
+
return value.map((entry) => cloneValue(entry));
|
|
1011
|
+
}
|
|
1012
|
+
if (typeof value === "object") {
|
|
1013
|
+
const clone = {};
|
|
1014
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
1015
|
+
clone[key] = cloneValue(entry);
|
|
1016
|
+
}
|
|
1017
|
+
return clone;
|
|
1018
|
+
}
|
|
1019
|
+
return null;
|
|
1055
1020
|
}
|
|
1056
1021
|
__name(cloneValue, "cloneValue");
|
|
1057
1022
|
|
|
@@ -1084,7 +1049,6 @@ var RuntimeControllerImpl = class {
|
|
|
1084
1049
|
input;
|
|
1085
1050
|
system;
|
|
1086
1051
|
playerService;
|
|
1087
|
-
sceneManager;
|
|
1088
1052
|
vm = null;
|
|
1089
1053
|
timeMachine = null;
|
|
1090
1054
|
constructor(options = {}) {
|
|
@@ -1111,7 +1075,6 @@ var RuntimeControllerImpl = class {
|
|
|
1111
1075
|
this.system.getAPI().update_rate = rate;
|
|
1112
1076
|
}, "setUpdateRate")
|
|
1113
1077
|
});
|
|
1114
|
-
this.sceneManager = new import_scene.SceneManager();
|
|
1115
1078
|
this.assetLoader = new AssetLoader(options.url || "", options.resources || {}, this.audio, this.listener);
|
|
1116
1079
|
this.logStep("RuntimeController constructed", {
|
|
1117
1080
|
width: this.screen.width,
|
|
@@ -1199,15 +1162,10 @@ var RuntimeControllerImpl = class {
|
|
|
1199
1162
|
}
|
|
1200
1163
|
exportSnapshot() {
|
|
1201
1164
|
const global = this.vm?.context?.global;
|
|
1202
|
-
const routerState = this.sceneManager.router.getState();
|
|
1203
1165
|
return {
|
|
1204
1166
|
version: 1,
|
|
1205
1167
|
global: global ? serializeGlobalSnapshot(global) : {},
|
|
1206
1168
|
session: this.getSession(),
|
|
1207
|
-
router: {
|
|
1208
|
-
path: routerState.path,
|
|
1209
|
-
sceneName: this.sceneManager.getCurrentSceneName()
|
|
1210
|
-
},
|
|
1211
1169
|
system: {
|
|
1212
1170
|
updateRate: this.system.getAPI().update_rate
|
|
1213
1171
|
}
|
|
@@ -1223,11 +1181,6 @@ var RuntimeControllerImpl = class {
|
|
|
1223
1181
|
if (snapshot.session) {
|
|
1224
1182
|
this.sessionSnapshot = cloneSnapshot(snapshot.session);
|
|
1225
1183
|
}
|
|
1226
|
-
if (snapshot.router.path) {
|
|
1227
|
-
this.sceneManager.router.replace(snapshot.router.path);
|
|
1228
|
-
} else if (snapshot.router.sceneName) {
|
|
1229
|
-
this.sceneManager.setActiveScene(snapshot.router.sceneName);
|
|
1230
|
-
}
|
|
1231
1184
|
}
|
|
1232
1185
|
updateSource(file, src, reinit = false) {
|
|
1233
1186
|
if (!this.sourceUpdater) return false;
|
|
@@ -1281,7 +1234,6 @@ var RuntimeControllerImpl = class {
|
|
|
1281
1234
|
input: this.input,
|
|
1282
1235
|
system: this.system,
|
|
1283
1236
|
playerService: this.playerService,
|
|
1284
|
-
sceneManager: this.sceneManager,
|
|
1285
1237
|
assets: this.assetRegistry,
|
|
1286
1238
|
bridge: this.options.bridge,
|
|
1287
1239
|
getVM: /* @__PURE__ */ __name(() => this.vm, "getVM"),
|
|
@@ -1305,7 +1257,6 @@ var RuntimeControllerImpl = class {
|
|
|
1305
1257
|
});
|
|
1306
1258
|
});
|
|
1307
1259
|
this.loadPrograms();
|
|
1308
|
-
this.initializeScenesAndRouter();
|
|
1309
1260
|
this.emitBridgeEvent("runtime.started", {});
|
|
1310
1261
|
}
|
|
1311
1262
|
loadPrograms() {
|
|
@@ -1359,21 +1310,6 @@ var RuntimeControllerImpl = class {
|
|
|
1359
1310
|
});
|
|
1360
1311
|
}
|
|
1361
1312
|
}
|
|
1362
|
-
initializeScenesAndRouter() {
|
|
1363
|
-
const registeredScenes = this.sceneManager.registry.getNames();
|
|
1364
|
-
this.logStep("router: initializing", {
|
|
1365
|
-
registeredScenes: registeredScenes.length,
|
|
1366
|
-
sceneNames: registeredScenes
|
|
1367
|
-
});
|
|
1368
|
-
this.sceneManager.router.init();
|
|
1369
|
-
const activeScene = this.sceneManager.hasActiveScene() ? this.sceneManager.getCurrentSceneName?.() || "unknown" : null;
|
|
1370
|
-
const routerState = this.sceneManager.router.getState();
|
|
1371
|
-
this.logStep("router: initialized", {
|
|
1372
|
-
activeScene: activeScene || "none",
|
|
1373
|
-
path: routerState.path,
|
|
1374
|
-
hasActiveScene: this.sceneManager.hasActiveScene()
|
|
1375
|
-
});
|
|
1376
|
-
}
|
|
1377
1313
|
startGameLoop() {
|
|
1378
1314
|
this.logStep("loop: creating game loop");
|
|
1379
1315
|
this.gameLoop = new GameLoop({
|
|
@@ -1427,12 +1363,8 @@ var RuntimeControllerImpl = class {
|
|
|
1427
1363
|
this.updateGameLoopUpdateRate();
|
|
1428
1364
|
}
|
|
1429
1365
|
try {
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
} else {
|
|
1433
|
-
this.vm.call("update");
|
|
1434
|
-
this.vm.runner.tick();
|
|
1435
|
-
}
|
|
1366
|
+
this.vm.call("update");
|
|
1367
|
+
this.vm.runner.tick();
|
|
1436
1368
|
if (this.vm.error_info) {
|
|
1437
1369
|
const err = Object.assign({}, this.vm.error_info);
|
|
1438
1370
|
err.type = "update";
|
|
@@ -1451,12 +1383,8 @@ var RuntimeControllerImpl = class {
|
|
|
1451
1383
|
try {
|
|
1452
1384
|
this.screen.initDraw();
|
|
1453
1385
|
this.screen.updateInterface();
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
} else {
|
|
1457
|
-
this.vm.call("draw");
|
|
1458
|
-
this.vm.runner.tick();
|
|
1459
|
-
}
|
|
1386
|
+
this.vm.call("draw");
|
|
1387
|
+
this.vm.runner.tick();
|
|
1460
1388
|
reportWarnings(this.vm, this.listener);
|
|
1461
1389
|
if (this.vm.error_info) {
|
|
1462
1390
|
const err = Object.assign({}, this.vm.error_info);
|
|
@@ -1682,8 +1610,6 @@ var RuntimeControllerImpl = class {
|
|
|
1682
1610
|
this.frameCount = 0;
|
|
1683
1611
|
this.lastUpdateRate = -1;
|
|
1684
1612
|
this.isStopped = false;
|
|
1685
|
-
this.sceneManager.registry.clear();
|
|
1686
|
-
this.sceneManager.routeManager.clear();
|
|
1687
1613
|
}
|
|
1688
1614
|
logStep(message, payload) {
|
|
1689
1615
|
if (!this.options.debug?.lifecycle) return;
|
|
@@ -1769,7 +1695,6 @@ function isRuntimeSnapshot(value) {
|
|
|
1769
1695
|
if (!isRecord(value)) return false;
|
|
1770
1696
|
if (value.version !== 1) return false;
|
|
1771
1697
|
if (!isRecord(value.global)) return false;
|
|
1772
|
-
if (!("router" in value)) return false;
|
|
1773
1698
|
if (!("session" in value)) return false;
|
|
1774
1699
|
return true;
|
|
1775
1700
|
}
|