@kvyverse/world-runtime 0.4.2 → 0.6.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.
@@ -17,7 +17,7 @@ var PointerLockCameraControls = class extends Object3DBehaviour {
17
17
  _detach;
18
18
  onEnable() {
19
19
  const env = this.modules.env;
20
- this._canBeLocked = env.prod && !env.isMobile;
20
+ this._canBeLocked = !env.dev && !env.isMobile;
21
21
  this._isMobile = env.isMobile;
22
22
  const dom = this.ctx.renderer.domElement;
23
23
  const lock = () => {
@@ -26,6 +26,7 @@ export declare class WorldRuntime implements RuntimeApi {
26
26
  /** Reverse index for `getUrl(resource)` — play mode resolves objects too. */
27
27
  private readonly _pathByResource;
28
28
  private _ctx;
29
+ private _starter;
29
30
  private _bloom;
30
31
  private _scriptContext;
31
32
  constructor(definition: RuntimeDefinitionSlice, options: LoadWorldOptions);
@@ -35,6 +36,8 @@ export declare class WorldRuntime implements RuntimeApi {
35
36
  get ctx(): ThreeContext;
36
37
  /** @internal Set by bootstrap. */
37
38
  setContext(ctx: ThreeContext): void;
39
+ /** @internal Set by bootstrap — backs `world.addModules` (register before start). */
40
+ setStarter(starter: ThreeStart): void;
38
41
  /** @internal World bloom, if enabled in the renderer config. */
39
42
  setBloom(bloom: SceneBloom): void;
40
43
  /** @internal Libs (config + required by modules/behaviours) and externals. */
package/dist/index.js CHANGED
@@ -551,15 +551,17 @@ function isMobileDevice() {
551
551
  //#endregion
552
552
  //#region packages/world-runtime/src/modules/EnvModule.ts
553
553
  var EnvModule = class extends ContextModule {
554
- dev = true;
555
- prod = true;
556
554
  mode;
555
+ dev;
556
+ prod;
557
+ selfHosted;
557
558
  isMobile;
558
559
  constructor(mode) {
559
560
  super();
560
561
  this.mode = mode;
561
562
  this.dev = mode === "dev";
562
563
  this.prod = mode === "prod";
564
+ this.selfHosted = mode === "selfhosted";
563
565
  this.isMobile = isMobileDevice();
564
566
  }
565
567
  };
@@ -945,7 +947,7 @@ var entries = [
945
947
  {
946
948
  uuid: "pointerlockcameracontrols",
947
949
  name: "PointerLockCameraController",
948
- load: () => loadDefault(import("./PointerLockCameraControls-DYxxMeSw.js"))
950
+ load: () => loadDefault(import("./PointerLockCameraControls-DIK3cVmo.js"))
949
951
  },
950
952
  {
951
953
  uuid: "simplewasdmovement",
@@ -1332,6 +1334,7 @@ var WorldRuntime = class {
1332
1334
  /** Reverse index for `getUrl(resource)` — play mode resolves objects too. */
1333
1335
  _pathByResource = /* @__PURE__ */ new Map();
1334
1336
  _ctx = null;
1337
+ _starter = null;
1335
1338
  _bloom = null;
1336
1339
  _scriptContext = null;
1337
1340
  constructor(definition, options) {
@@ -1352,6 +1355,10 @@ var WorldRuntime = class {
1352
1355
  setContext(ctx) {
1353
1356
  this._ctx = ctx;
1354
1357
  }
1358
+ /** @internal Set by bootstrap — backs `world.addModules` (register before start). */
1359
+ setStarter(starter) {
1360
+ this._starter = starter;
1361
+ }
1355
1362
  /** @internal World bloom, if enabled in the renderer config. */
1356
1363
  setBloom(bloom) {
1357
1364
  this._bloom = bloom;
@@ -1538,7 +1545,11 @@ var WorldRuntime = class {
1538
1545
  stores: this.stores,
1539
1546
  rendering: { get bloom() {
1540
1547
  return runtime.bloomApi;
1541
- } }
1548
+ } },
1549
+ addModules: (modules) => {
1550
+ if (!runtime._starter) throw new Error("world.addModules is only available in the entry script (main.ts), before the world starts.");
1551
+ runtime._starter.addModules(modules);
1552
+ }
1542
1553
  },
1543
1554
  modules: lazyProxy(() => runtime.ctx.modules),
1544
1555
  require: this.require,
@@ -1566,7 +1577,7 @@ function isAbsoluteUrl(url) {
1566
1577
  }
1567
1578
  //#endregion
1568
1579
  //#region packages/world-runtime/src/version.gen.ts
1569
- var RUNTIME_VERSION = "0.4.2";
1580
+ var RUNTIME_VERSION = "0.6.0";
1570
1581
  //#endregion
1571
1582
  //#region packages/world-runtime/src/version.ts
1572
1583
  /**
@@ -1604,6 +1615,7 @@ async function bootstrapWorld(definition, options) {
1604
1615
  runtime.reportProgress("Initializing 3D context");
1605
1616
  const world = await createWorld(definition, runtime);
1606
1617
  runtime.setContext(world.ctx);
1618
+ runtime.setStarter(world);
1607
1619
  await runtime.applyRequiredPatches(world);
1608
1620
  runtime.reportProgress("Applying scene settings");
1609
1621
  definition.applySceneSettings?.(runtime, world.ctx.scene);
@@ -1632,7 +1644,7 @@ async function createWorld(definition, runtime) {
1632
1644
  scene: new THREE.Scene(),
1633
1645
  autoInitRenderer: false
1634
1646
  }, runtime);
1635
- world.addModules(await createWorldModules("prod", {
1647
+ world.addModules(await createWorldModules("selfhosted", {
1636
1648
  addons: runtime.addons,
1637
1649
  modules: runtime.definition.addons?.modules
1638
1650
  }));
@@ -1,11 +1,13 @@
1
1
  import { ContextModule } from "three-start";
2
2
  import type { EnvModuleApi } from "./contracts/env.module-api";
3
- /** Where the world runs: `dev` — testplay from the editor, `prod` — the game. */
3
+ /** Where the world runs: `dev` — editor testplay, `prod` — platform game,
4
+ * `selfhosted` — self-hosted export. */
4
5
  export type EnvMode = EnvModuleApi["mode"];
5
6
  export declare class EnvModule extends ContextModule implements EnvModuleApi {
6
- dev: boolean;
7
- prod: boolean;
8
- mode: EnvMode;
9
- isMobile: boolean;
7
+ readonly mode: EnvMode;
8
+ readonly dev: boolean;
9
+ readonly prod: boolean;
10
+ readonly selfHosted: boolean;
11
+ readonly isMobile: boolean;
10
12
  constructor(mode: EnvMode);
11
13
  }
@@ -1,7 +1,16 @@
1
- /** Public API of the `env` module — environment flags (dev/prod, mobile). */
1
+ /**
2
+ * Public API of the `env` module — where the world runs. Exactly one of
3
+ * `dev`/`prod`/`selfHosted` is true, matching `mode`. For "any real run, not
4
+ * editor testplay" use `!env.dev`.
5
+ */
2
6
  export interface EnvModuleApi {
7
+ /** Editor testplay run. */
3
8
  readonly dev: boolean;
9
+ /** Published game on the Kvyverse platform. */
4
10
  readonly prod: boolean;
5
- readonly mode: "dev" | "prod";
11
+ /** Self-hosted export, running outside the Kvyverse platform. */
12
+ readonly selfHosted: boolean;
13
+ /** Precise runtime context. */
14
+ readonly mode: "dev" | "prod" | "selfhosted";
6
15
  readonly isMobile: boolean;
7
16
  }
@@ -1 +1 @@
1
- export declare const RUNTIME_VERSION = "0.4.2";
1
+ export declare const RUNTIME_VERSION = "0.6.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kvyverse/world-runtime",
3
- "version": "0.4.2",
3
+ "version": "0.6.0",
4
4
  "description": "Runtime for worlds exported from the Kvyverse platform for self-hosting",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "author": "Vladislav Kruteniuk",