@rpgjs/client 5.0.0-beta.25 → 5.0.0-beta.26

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/Game/Map.d.ts +1 -0
  3. package/dist/Game/Map.js +5 -0
  4. package/dist/Game/Map.js.map +1 -1
  5. package/dist/RpgClient.d.ts +2 -1
  6. package/dist/RpgClientEngine.d.ts +76 -0
  7. package/dist/RpgClientEngine.js +59 -4
  8. package/dist/RpgClientEngine.js.map +1 -1
  9. package/dist/components/scenes/draw-map.ce.js +5 -2
  10. package/dist/components/scenes/draw-map.ce.js.map +1 -1
  11. package/dist/components/scenes/weather-lifecycle-compat.d.ts +0 -0
  12. package/dist/components/scenes/weather-lifecycle-compat.js +11 -0
  13. package/dist/components/scenes/weather-lifecycle-compat.js.map +1 -0
  14. package/dist/components/scenes/weather-tick-lifecycle.d.ts +17 -0
  15. package/dist/components/scenes/weather-tick-lifecycle.js +44 -0
  16. package/dist/components/scenes/weather-tick-lifecycle.js.map +1 -0
  17. package/dist/components/scenes/weather-tick-lifecycle.spec.d.ts +1 -0
  18. package/dist/i18n.d.ts +1 -0
  19. package/dist/i18n.js +1 -0
  20. package/dist/i18n.js.map +1 -1
  21. package/dist/index.d.ts +2 -0
  22. package/dist/index.js +3 -1
  23. package/dist/services/loadMap.d.ts +10 -2
  24. package/dist/services/loadMap.js +2 -1
  25. package/dist/services/loadMap.js.map +1 -1
  26. package/dist/services/mapStreaming.d.ts +85 -0
  27. package/dist/services/mapStreaming.js +210 -0
  28. package/dist/services/mapStreaming.js.map +1 -0
  29. package/dist/services/mapStreaming.spec.d.ts +1 -0
  30. package/dist/services/mmorpg.d.ts +6 -0
  31. package/dist/services/mmorpg.js +2 -2
  32. package/dist/services/mmorpg.js.map +1 -1
  33. package/package.json +3 -3
  34. package/src/Game/Map.ts +7 -0
  35. package/src/RpgClient.ts +2 -1
  36. package/src/RpgClientEngine.ts +147 -6
  37. package/src/components/scenes/draw-map.ce +4 -1
  38. package/src/components/scenes/weather-lifecycle-compat.ts +8 -0
  39. package/src/components/scenes/weather-tick-lifecycle.spec.ts +60 -0
  40. package/src/components/scenes/weather-tick-lifecycle.ts +69 -0
  41. package/src/i18n.spec.ts +2 -1
  42. package/src/i18n.ts +1 -0
  43. package/src/index.ts +2 -0
  44. package/src/services/loadMap.ts +9 -2
  45. package/src/services/mapStreaming.spec.ts +240 -0
  46. package/src/services/mapStreaming.ts +275 -0
  47. package/src/services/mmorpg.ts +15 -2
@@ -1,4 +1,5 @@
1
1
  import { inject } from "../../core/inject.js";
2
+ import "./weather-lifecycle-compat.js";
2
3
  import { RpgClientEngine } from "../../RpgClientEngine.js";
3
4
  import { Container, computed, cond, h, loop, useDefineEmits, useDefineProps, useProps } from "canvasengine";
4
5
  import { Weather } from "@canvasengine/presets";
@@ -12,6 +13,8 @@ function component($$props) {
12
13
  const componentAnimations = engine.componentAnimations;
13
14
  const projectiles = engine.projectiles.current;
14
15
  const map = engine.sceneMap?.data;
16
+ const emptySceneData = { params: {} };
17
+ const emptySceneParams = {};
15
18
  const sceneComponent = computed(() => map()?.component);
16
19
  const weather = engine.sceneMap.weather;
17
20
  const backgroundMusic = computed(() => {
@@ -73,8 +76,8 @@ function component($$props) {
73
76
  cond(computed(() => backgroundMusic()), () => h(Container, { sound: computed(() => backgroundMusic()) })),
74
77
  cond(computed(() => backgroundAmbientSound()), () => h(Container, { sound: computed(() => backgroundAmbientSound()) })),
75
78
  h(Container, null, cond(computed(() => map() && sceneComponent()), () => h(sceneComponent(), {
76
- data: computed(() => map().data),
77
- params: computed(() => map().params)
79
+ data: computed(() => map()?.data ?? emptySceneData),
80
+ params: computed(() => map()?.params ?? emptySceneParams)
78
81
  }))),
79
82
  loop(children, (child) => h(child)),
80
83
  loop(componentAnimations, (componentAnimation) => h(Container, null, loop(componentAnimation.current, (animation) => h(componentAnimation.component, animation)))),
@@ -1 +1 @@
1
- {"version":3,"file":"draw-map.ce.js","names":[],"sources":["../../../src/components/scenes/draw-map.ce"],"sourcesContent":["<Container shake={shakeConfig} freeze={engine.gamePause}>\n @if (backgroundMusic()) {\n <Container sound={backgroundMusic()} />\n }\n\n @if (backgroundAmbientSound()) {\n <Container sound={backgroundAmbientSound()} />\n }\n\n <Container>\n @if (map() && sceneComponent()) {\n <sceneComponent() data={map().data} params={map().params} />\n }\n </Container>\n\n @for (child of children) {\n <child />\n }\n\n @for (componentAnimation of componentAnimations) {\n <Container>\n @for (animation of componentAnimation.current) {\n <componentAnimation.component ...animation />\n }\n </Container>\n }\n\n <Container sortableChildren={true}>\n @for (projectile of projectiles() ; track projectile.props.id) {\n <projectile.component ...projectile.props />\n }\n </Container>\n\n @if (weatherProps()) {\n <Weather ...weatherProps() />\n }\n</Container>\n\n<script>\n import { computed, effect } from 'canvasengine'\n import { inject } from \"../../core/inject\";\n import { RpgClientEngine } from \"../../RpgClientEngine\";\n import { Weather } from '@canvasengine/presets'\n\n const { children } = defineProps()\n const engine = inject(RpgClientEngine);\n const componentAnimations = engine.componentAnimations\n const projectiles = engine.projectiles.current\n const map = engine.sceneMap?.data\n const sceneComponent = computed(() => map()?.component)\n const weather = engine.sceneMap.weather\n const backgroundMusic = computed(() => {\n const src = map()?.params?.backgroundMusic\n return src ? { src, autoplay: true, loop: true } : undefined\n })\n const backgroundAmbientSound = computed(() => {\n const src = map()?.params?.backgroundAmbientSound\n return src ? { src, autoplay: true, loop: true } : undefined\n })\n\n const shakeConfig = {\n trigger: engine.mapShakeTrigger,\n intensity: 10,\n duration: 500,\n frequency: 10,\n direction: 'both'\n }\n\n const weatherProps = computed(() => {\n const state = weather?.()\n if (!state) {\n return null\n }\n const validEffects = ['rain', 'snow', 'fog', 'cloud']\n if (!validEffects.includes(state.effect)) {\n return null\n }\n const params = state.params ?? {}\n return {\n effect: state.effect,\n speed: params.speed,\n windDirection: params.windDirection,\n windStrength: params.windStrength,\n density: params.density,\n maxDrops: params.maxDrops,\n height: params.height,\n scale: params.scale,\n sunIntensity: params.sunIntensity,\n sunAngle: params.sunAngle,\n raySpread: params.raySpread,\n rayTwinkle: params.rayTwinkle,\n rayTwinkleSpeed: params.rayTwinkleSpeed,\n zIndex: params.zIndex ?? 1000,\n alpha: params.alpha,\n blendMode: params.blendMode,\n }\n })\n</script>\n"],"mappings":";;;;;AASG,SAAS,UAAA,SAAA;CACM,SAAc,OAAI;CAC7B,MAAA,cAAqB,eAAc,OAAQ;CAC9C,eAAA,OAAA;CACA,MAAS,EAAA,aAAA,YAAA;;CAEb,MAAM,sBAAqB,OAAA;CAC3B,MAAK,cAAO,OAAA,YAAA;CACZ,MAAE,MAAA,OAAA,UAAA;;CAEF,MAAM,UAAE,OAAA,SAAsB;CAC9B,MAAK,kBAAS,eAAA;EACV,MAAM,MAAE,IAAA,GAAU,QAAG;EACrB,OAAK,MAAA;GAAA;GAAA,UAAmB;GAAY,MAAC;EAAU,IAAC,KAAA;CACpD,CAAC;CACD,MAAM,yBAAS,eAAA;EACb,MAAA,MAAA,IAAA,GAAA,QAAA;;;;;;CAEF,CAAC;CACD,MAAK,cAAe;EAChB,SAAG,OAAW;EACd,WAAA;EACA,UAAS;;EAEV,WAAI;CACP;CACA,MAAE,eAAA,eAAA;EACA,MAAA,QAAS,UAAA;cAEJ,OAAA;EAGH,IAAA,CAAA;GADsB;GAAQ;GAAK;GAAO;EACjC,EAAA,SAAkB,MAAM,MAAM,GACvC,OAAS;EAET,MAAM,SAAE,MAAa,UAAA,CAAW;EAChC,OAAM;GACN,QAAM,MAAA;GACN,OAAM,OAAY;GAClB,eAAmB,OAAA;GACnB,cAAM,OAAiB;GACvB,SAAa,OAAG;GAChB,UAAM,OAAe;GACnB,QAAU,OAAO;GACjB,OAAO,OAAQ;GAChB,cAAA,OAAA;GACD,UAAM,OAAA;GACJ,WAAY,OAAO;GACnB,YAAc,OAAM;GACrB,iBAAA,OAAA;;GAED,OAAM,OAAY;GAChB,WAAS,OAAO;EAClB;CACJ,CAAC;CAEK,OADa,EAAA,WAAA;EAAA,OAAA;EAAA,QAAA,OAAA;CAAA,GAAA;EAAA,KAAA,eAAA,gBAAA,CAAA,SAAA,EAAA,WAAA,EAAA,OAAA,eAAA,gBAAA,CAAA,EAAA,CAAA,CAAA;EAAA,KAAA,eAAA,uBAAA,CAAA,SAAA,EAAA,WAAA,EAAA,OAAA,eAAA,uBAAA,CAAA,EAAA,CAAA,CAAA;EAAA,EAAA,WAAA,MAAA,KAAA,eAAA,IAAA,KAAA,eAAA,CAAA,SAAA,EAAA,eAAA,GAAA;GAAA,MAAA,eAAA,IAAA,EAAA,IAAA;GAAA,QAAA,eAAA,IAAA,EAAA,MAAA;EAAA,CAAA,CAAA,CAAA;EAAA,KAAA,WAAA,UAAA,EAAA,KAAA,CAAA;EAAA,KAAA,sBAAA,uBAAA,EAAA,WAAA,MAAA,KAAA,mBAAA,UAAA,cAAA,EAAA,mBAAA,WAAA,SAAA,CAAA,CAAA,CAAA;EAAA,EAAA,WAAA,EAAA,kBAAA,KAAA,GAAA,KAAA,eAAA,YAAA,CAAA,IAAA,eAAA,EAAA,WAAA,WAAA,WAAA,KAAA,GAAA,EAAA,QAAA,eAAA,WAAA,MAAA,GAAA,CAAA,CAAA;EAAA,KAAA,eAAA,aAAA,CAAA,SAAA,EAAA,SAAA,aAAA,CAAA,CAAA;CAAA,CACD;AACd;AAEA,IAAM,iBAAe"}
1
+ {"version":3,"file":"draw-map.ce.js","names":[],"sources":["../../../src/components/scenes/draw-map.ce"],"sourcesContent":["<Container shake={shakeConfig} freeze={engine.gamePause}>\n @if (backgroundMusic()) {\n <Container sound={backgroundMusic()} />\n }\n\n @if (backgroundAmbientSound()) {\n <Container sound={backgroundAmbientSound()} />\n }\n\n <Container>\n @if (map() && sceneComponent()) {\n <sceneComponent() data={map()?.data ?? emptySceneData} params={map()?.params ?? emptySceneParams} />\n }\n </Container>\n\n @for (child of children) {\n <child />\n }\n\n @for (componentAnimation of componentAnimations) {\n <Container>\n @for (animation of componentAnimation.current) {\n <componentAnimation.component ...animation />\n }\n </Container>\n }\n\n <Container sortableChildren={true}>\n @for (projectile of projectiles() ; track projectile.props.id) {\n <projectile.component ...projectile.props />\n }\n </Container>\n\n @if (weatherProps()) {\n <Weather ...weatherProps() />\n }\n</Container>\n\n<script>\n import { computed, effect } from 'canvasengine'\n import './weather-lifecycle-compat'\n import { inject } from \"../../core/inject\";\n import { RpgClientEngine } from \"../../RpgClientEngine\";\n import { Weather } from '@canvasengine/presets'\n\n const { children } = defineProps()\n const engine = inject(RpgClientEngine);\n const componentAnimations = engine.componentAnimations\n const projectiles = engine.projectiles.current\n const map = engine.sceneMap?.data\n const emptySceneData = { params: {} }\n const emptySceneParams = {}\n const sceneComponent = computed(() => map()?.component)\n const weather = engine.sceneMap.weather\n const backgroundMusic = computed(() => {\n const src = map()?.params?.backgroundMusic\n return src ? { src, autoplay: true, loop: true } : undefined\n })\n const backgroundAmbientSound = computed(() => {\n const src = map()?.params?.backgroundAmbientSound\n return src ? { src, autoplay: true, loop: true } : undefined\n })\n\n const shakeConfig = {\n trigger: engine.mapShakeTrigger,\n intensity: 10,\n duration: 500,\n frequency: 10,\n direction: 'both'\n }\n\n const weatherProps = computed(() => {\n const state = weather?.()\n if (!state) {\n return null\n }\n const validEffects = ['rain', 'snow', 'fog', 'cloud']\n if (!validEffects.includes(state.effect)) {\n return null\n }\n const params = state.params ?? {}\n return {\n effect: state.effect,\n speed: params.speed,\n windDirection: params.windDirection,\n windStrength: params.windStrength,\n density: params.density,\n maxDrops: params.maxDrops,\n height: params.height,\n scale: params.scale,\n sunIntensity: params.sunIntensity,\n sunAngle: params.sunAngle,\n raySpread: params.raySpread,\n rayTwinkle: params.rayTwinkle,\n rayTwinkleSpeed: params.rayTwinkleSpeed,\n zIndex: params.zIndex ?? 1000,\n alpha: params.alpha,\n blendMode: params.blendMode,\n }\n })\n</script>\n"],"mappings":";;;;;;AAUK,SAAU,UAAG,SAAgB;CACX,SAAO,OAAO;CACjC,MAAA,cAAA,eAAA,OAAA;CACS,eAAA,OAAA;;CAEb,MAAM,SAAQ,OAAG,eAAU;CAC3B,MAAK,sBAAO,OAAA;CACZ,MAAE,cAAA,OAAA,YAAA;;CAEF,MAAM,iBAAE,EAAA,QAAsB,CAAA,EAAA;CAC9B,MAAK,mBAAS,CAAA;CACd,MAAM,iBAAgB,eAAG,IAAA,GAAmB,SAAS;CACrD,MAAM,UAAG,OAAA,SAAmB;CAC5B,MAAM,kBAAA,eAAA;EACF,MAAE,MAAS,IAAA,GAAA,QAAA;EACb,OAAA,MAAA;GAAA;GAAA,UAAA;GAAA,MAAA;EAAA,IAAA,KAAA;;CAEF,MAAG,yBAA4B,eAAK;EAChC,MAAM,MAAA,IAAU,GAAG,QAAC;EACpB,OAAG,MAAU;GAAC;GAAA,UAAa;GAAA,MAAW;EAAO,IAAA,KAAA;CACjD,CAAC;CACD,MAAI,cAAS;;EAEV,WAAI;EACH,UAAU;EACZ,WAAA;EACA,WAAS;;CAEX,MAAC,eAAM,eAAA;EACH,MAAM,QAAG,UAAU;EACnB,IAAA,CAAA,OACA,OAAS;;GAEU;GAAO;GAAY;GAAC;4BAEvC,OAAQ;EAER,MAAM,SAAA,MAAA,UAAsB,CAAA;EAC5B,OAAM;GACN,QAAY,MAAM;GAClB,OAAM,OAAA;GACN,eAAM,OAAoB;GAC1B,cAAM,OAAiB;GACvB,SAAa,OAAG;GAChB,UAAM,OAAe;GACnB,QAAU,OAAO;GACjB,OAAO,OAAQ;GAChB,cAAA,OAAA;GACD,UAAM,OAAA;GACJ,WAAY,OAAO;GACnB,YAAc,OAAM;GACrB,iBAAA,OAAA;;GAED,OAAM,OAAY;GAChB,WAAS,OAAO;EAClB;CACJ,CAAC;CAEK,OADa,EAAA,WAAA;EAAA,OAAA;EAAA,QAAA,OAAA;CAAA,GAAA;EAAA,KAAA,eAAA,gBAAA,CAAA,SAAA,EAAA,WAAA,EAAA,OAAA,eAAA,gBAAA,CAAA,EAAA,CAAA,CAAA;EAAA,KAAA,eAAA,uBAAA,CAAA,SAAA,EAAA,WAAA,EAAA,OAAA,eAAA,uBAAA,CAAA,EAAA,CAAA,CAAA;EAAA,EAAA,WAAA,MAAA,KAAA,eAAA,IAAA,KAAA,eAAA,CAAA,SAAA,EAAA,eAAA,GAAA;GAAA,MAAA,eAAA,IAAA,GAAA,QAAA,cAAA;GAAA,QAAA,eAAA,IAAA,GAAA,UAAA,gBAAA;EAAA,CAAA,CAAA,CAAA;EAAA,KAAA,WAAA,UAAA,EAAA,KAAA,CAAA;EAAA,KAAA,sBAAA,uBAAA,EAAA,WAAA,MAAA,KAAA,mBAAA,UAAA,cAAA,EAAA,mBAAA,WAAA,SAAA,CAAA,CAAA,CAAA;EAAA,EAAA,WAAA,EAAA,kBAAA,KAAA,GAAA,KAAA,eAAA,YAAA,CAAA,IAAA,eAAA,EAAA,WAAA,WAAA,WAAA,KAAA,GAAA,EAAA,QAAA,eAAA,WAAA,MAAA,GAAA,CAAA,CAAA;EAAA,KAAA,eAAA,aAAA,CAAA,SAAA,EAAA,SAAA,aAAA,CAAA,CAAA;CAAA,CACD;AACd;AAEA,IAAM,iBAAe"}
@@ -0,0 +1,11 @@
1
+ import { patchWeatherTickLifecycle } from "./weather-tick-lifecycle.js";
2
+ import { createComponent } from "canvasengine";
3
+ import "@canvasengine/presets";
4
+ //#region src/components/scenes/weather-lifecycle-compat.ts
5
+ for (const tag of ["RainTextureLayer", "RainImpactLayer"]) {
6
+ const probe = createComponent(tag);
7
+ patchWeatherTickLifecycle(Object.getPrototypeOf(probe.componentInstance));
8
+ }
9
+ //#endregion
10
+
11
+ //# sourceMappingURL=weather-lifecycle-compat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"weather-lifecycle-compat.js","names":[],"sources":["../../../src/components/scenes/weather-lifecycle-compat.ts"],"sourcesContent":["import \"@canvasengine/presets\";\nimport { createComponent } from \"canvasengine\";\nimport { patchWeatherTickLifecycle } from \"./weather-tick-lifecycle\";\n\nfor (const tag of [\"RainTextureLayer\", \"RainImpactLayer\"]) {\n const probe = createComponent(tag);\n patchWeatherTickLifecycle(Object.getPrototypeOf(probe.componentInstance));\n}\n"],"mappings":";;;;AAIA,KAAK,MAAM,OAAO,CAAC,oBAAoB,iBAAiB,GAAG;CACzD,MAAM,QAAQ,gBAAgB,GAAG;CACjC,0BAA0B,OAAO,eAAe,MAAM,iBAAiB,CAAC;AAC1E"}
@@ -0,0 +1,17 @@
1
+ declare const PATCHED: unique symbol;
2
+ type TickSubscriptionPrototype = {
3
+ [PATCHED]?: boolean;
4
+ onMount?: (...args: any[]) => unknown;
5
+ onDestroy?: (...args: any[]) => unknown;
6
+ };
7
+ /**
8
+ * CanvasEngine presets 2.0.0 can finish mounting a rain layer after that layer
9
+ * has already been destroyed. The late mount then leaves a tick subscription
10
+ * operating on a destroyed Pixi object. It can also overwrite an existing
11
+ * subscription when mounts overlap.
12
+ *
13
+ * Keep this compatibility patch local to the affected preset prototypes. It
14
+ * can be removed once the preset owns the same lifecycle guarantees.
15
+ */
16
+ export declare function patchWeatherTickLifecycle(prototype: TickSubscriptionPrototype): void;
17
+ export {};
@@ -0,0 +1,44 @@
1
+ //#region src/components/scenes/weather-tick-lifecycle.ts
2
+ var PATCHED = Symbol.for("@rpgjs/client/weather-tick-lifecycle-patched");
3
+ var DISPOSED = Symbol("weather-tick-lifecycle-disposed");
4
+ var MOUNT_QUEUE = Symbol("weather-tick-lifecycle-mount-queue");
5
+ function stopTickSubscription(instance) {
6
+ instance.tickSubscription?.unsubscribe?.();
7
+ instance.tickSubscription = void 0;
8
+ }
9
+ /**
10
+ * CanvasEngine presets 2.0.0 can finish mounting a rain layer after that layer
11
+ * has already been destroyed. The late mount then leaves a tick subscription
12
+ * operating on a destroyed Pixi object. It can also overwrite an existing
13
+ * subscription when mounts overlap.
14
+ *
15
+ * Keep this compatibility patch local to the affected preset prototypes. It
16
+ * can be removed once the preset owns the same lifecycle guarantees.
17
+ */
18
+ function patchWeatherTickLifecycle(prototype) {
19
+ if (!prototype || prototype[PATCHED]) return;
20
+ const originalOnMount = prototype.onMount;
21
+ const originalOnDestroy = prototype.onDestroy;
22
+ if (!originalOnMount || !originalOnDestroy) return;
23
+ Object.defineProperty(prototype, PATCHED, { value: true });
24
+ prototype.onMount = function(...args) {
25
+ const mount = async () => {
26
+ if (this[DISPOSED] || this.destroyed) return;
27
+ stopTickSubscription(this);
28
+ await originalOnMount.apply(this, args);
29
+ if (this[DISPOSED] || this.destroyed) stopTickSubscription(this);
30
+ };
31
+ const pendingMount = (this[MOUNT_QUEUE] ?? Promise.resolve()).catch(() => void 0).then(mount);
32
+ this[MOUNT_QUEUE] = pendingMount;
33
+ return pendingMount;
34
+ };
35
+ prototype.onDestroy = function(...args) {
36
+ this[DISPOSED] = true;
37
+ stopTickSubscription(this);
38
+ return originalOnDestroy.apply(this, args);
39
+ };
40
+ }
41
+ //#endregion
42
+ export { patchWeatherTickLifecycle };
43
+
44
+ //# sourceMappingURL=weather-tick-lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"weather-tick-lifecycle.js","names":[],"sources":["../../../src/components/scenes/weather-tick-lifecycle.ts"],"sourcesContent":["const PATCHED = Symbol.for(\"@rpgjs/client/weather-tick-lifecycle-patched\");\nconst DISPOSED = Symbol(\"weather-tick-lifecycle-disposed\");\nconst MOUNT_QUEUE = Symbol(\"weather-tick-lifecycle-mount-queue\");\n\ntype TickSubscription = {\n unsubscribe?: () => void;\n};\n\ntype TickSubscriptionInstance = {\n destroyed?: boolean;\n tickSubscription?: TickSubscription;\n [DISPOSED]?: boolean;\n [MOUNT_QUEUE]?: Promise<void>;\n};\n\ntype TickSubscriptionPrototype = {\n [PATCHED]?: boolean;\n onMount?: (...args: any[]) => unknown;\n onDestroy?: (...args: any[]) => unknown;\n};\n\nfunction stopTickSubscription(instance: TickSubscriptionInstance) {\n instance.tickSubscription?.unsubscribe?.();\n instance.tickSubscription = undefined;\n}\n\n/**\n * CanvasEngine presets 2.0.0 can finish mounting a rain layer after that layer\n * has already been destroyed. The late mount then leaves a tick subscription\n * operating on a destroyed Pixi object. It can also overwrite an existing\n * subscription when mounts overlap.\n *\n * Keep this compatibility patch local to the affected preset prototypes. It\n * can be removed once the preset owns the same lifecycle guarantees.\n */\nexport function patchWeatherTickLifecycle(prototype: TickSubscriptionPrototype) {\n if (!prototype || prototype[PATCHED]) return;\n\n const originalOnMount = prototype.onMount;\n const originalOnDestroy = prototype.onDestroy;\n if (!originalOnMount || !originalOnDestroy) return;\n\n Object.defineProperty(prototype, PATCHED, { value: true });\n\n prototype.onMount = function (this: TickSubscriptionInstance, ...args: any[]) {\n const mount = async () => {\n if (this[DISPOSED] || this.destroyed) return;\n\n stopTickSubscription(this);\n await originalOnMount.apply(this, args);\n\n if (this[DISPOSED] || this.destroyed) {\n stopTickSubscription(this);\n }\n };\n\n const pendingMount = (this[MOUNT_QUEUE] ?? Promise.resolve())\n .catch(() => undefined)\n .then(mount);\n this[MOUNT_QUEUE] = pendingMount;\n return pendingMount;\n };\n\n prototype.onDestroy = function (this: TickSubscriptionInstance, ...args: any[]) {\n this[DISPOSED] = true;\n stopTickSubscription(this);\n return originalOnDestroy.apply(this, args);\n };\n}\n"],"mappings":";AAAA,IAAM,UAAU,OAAO,IAAI,8CAA8C;AACzE,IAAM,WAAW,OAAO,iCAAiC;AACzD,IAAM,cAAc,OAAO,oCAAoC;AAmB/D,SAAS,qBAAqB,UAAoC;CAChE,SAAS,kBAAkB,cAAc;CACzC,SAAS,mBAAmB,KAAA;AAC9B;;;;;;;;;;AAWA,SAAgB,0BAA0B,WAAsC;CAC9E,IAAI,CAAC,aAAa,UAAU,UAAU;CAEtC,MAAM,kBAAkB,UAAU;CAClC,MAAM,oBAAoB,UAAU;CACpC,IAAI,CAAC,mBAAmB,CAAC,mBAAmB;CAE5C,OAAO,eAAe,WAAW,SAAS,EAAE,OAAO,KAAK,CAAC;CAEzD,UAAU,UAAU,SAA0C,GAAG,MAAa;EAC5E,MAAM,QAAQ,YAAY;GACxB,IAAI,KAAK,aAAa,KAAK,WAAW;GAEtC,qBAAqB,IAAI;GACzB,MAAM,gBAAgB,MAAM,MAAM,IAAI;GAEtC,IAAI,KAAK,aAAa,KAAK,WACzB,qBAAqB,IAAI;EAE7B;EAEA,MAAM,gBAAgB,KAAK,gBAAgB,QAAQ,QAAQ,GACxD,YAAY,KAAA,CAAS,EACrB,KAAK,KAAK;EACb,KAAK,eAAe;EACpB,OAAO;CACT;CAEA,UAAU,YAAY,SAA0C,GAAG,MAAa;EAC9E,KAAK,YAAY;EACjB,qBAAqB,IAAI;EACzB,OAAO,kBAAkB,MAAM,MAAM,IAAI;CAC3C;AACF"}
package/dist/i18n.d.ts CHANGED
@@ -50,6 +50,7 @@ export declare const RpgClientBuiltinI18n: {
50
50
  "rpg.input.error.min-length": string;
51
51
  "rpg.input.error.max-length": string;
52
52
  "rpg.input.error.email": string;
53
+ "rpg.transition.loading": string;
53
54
  "rpg.shop.default-message": string;
54
55
  "rpg.shop.choose-action": string;
55
56
  "rpg.shop.buy": string;
package/dist/i18n.js CHANGED
@@ -50,6 +50,7 @@ var RpgClientBuiltinI18n = { en: {
50
50
  "rpg.input.error.min-length": "Enter at least {minLength} characters.",
51
51
  "rpg.input.error.max-length": "Enter no more than {maxLength} characters.",
52
52
  "rpg.input.error.email": "Enter a valid email address.",
53
+ "rpg.transition.loading": "Loading area…",
53
54
  "rpg.shop.default-message": "Welcome to my shop!",
54
55
  "rpg.shop.choose-action": "Choose an action",
55
56
  "rpg.shop.buy": "Buy",
package/dist/i18n.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.js","names":[],"sources":["../src/i18n.ts"],"sourcesContent":["import { createI18nProvider, type I18nConfig } from \"@rpgjs/common\";\n\nexport const RpgClientBuiltinI18n = {\n en: {\n \"rpg.menu.title\": \"Menu\",\n \"rpg.menu.status\": \"Status\",\n \"rpg.menu.level\": \"Level\",\n \"rpg.menu.gold\": \"Gold\",\n \"rpg.menu.parameters\": \"Parameters\",\n \"rpg.menu.items\": \"Items\",\n \"rpg.menu.skills\": \"Skills\",\n \"rpg.menu.equip\": \"Equip\",\n \"rpg.menu.options\": \"Options\",\n \"rpg.menu.save\": \"Save\",\n \"rpg.menu.exit\": \"Exit\",\n \"rpg.menu.weapons\": \"Weapons\",\n \"rpg.menu.armor\": \"Armor\",\n \"rpg.menu.use\": \"Use\",\n \"rpg.menu.cancel\": \"Cancel\",\n \"rpg.menu.unequip\": \"Unequip\",\n \"rpg.menu.remove-equipment\": \"Remove the current equipment\",\n \"rpg.menu.empty\": \"Empty\",\n \"rpg.menu.leave-game\": \"Leave the game?\",\n \"rpg.menu.exit-help\": \"Press Action to confirm or Escape to go back.\",\n \"rpg.menu.options-help\": \"Configure your preferences here.\",\n \"rpg.save.title\": \"Save Game\",\n \"rpg.save.subtitle\": \"Choose a slot to overwrite or create.\",\n \"rpg.load.title\": \"Load Game\",\n \"rpg.load.subtitle\": \"Select a slot to load your progress.\",\n \"rpg.save.auto\": \"Auto Save\",\n \"rpg.save.slot\": \"Slot {index}\",\n \"rpg.save.empty-slot\": \"Empty Slot\",\n \"rpg.save.level\": \"Level\",\n \"rpg.save.exp\": \"Exp\",\n \"rpg.save.map\": \"Map\",\n \"rpg.save.date\": \"Date\",\n \"rpg.title.default\": \"RPG\",\n \"rpg.title.start\": \"Start\",\n \"rpg.title.load\": \"Load\",\n \"rpg.gameover.title\": \"Game Over\",\n \"rpg.gameover.title-screen\": \"Title Screen\",\n \"rpg.gameover.load-game\": \"Load Game\",\n \"rpg.input.confirm\": \"Confirm\",\n \"rpg.input.cancel\": \"Cancel\",\n \"rpg.input.error.invalid\": \"Invalid value.\",\n \"rpg.input.error.required\": \"A value is required.\",\n \"rpg.input.error.number\": \"Enter a valid number.\",\n \"rpg.input.error.min\": \"The value must be at least {min}.\",\n \"rpg.input.error.max\": \"The value must be at most {max}.\",\n \"rpg.input.error.step\": \"The value must use increments of {step}.\",\n \"rpg.input.error.min-length\": \"Enter at least {minLength} characters.\",\n \"rpg.input.error.max-length\": \"Enter no more than {maxLength} characters.\",\n \"rpg.input.error.email\": \"Enter a valid email address.\",\n \"rpg.shop.default-message\": \"Welcome to my shop!\",\n \"rpg.shop.choose-action\": \"Choose an action\",\n \"rpg.shop.buy\": \"Buy\",\n \"rpg.shop.sell\": \"Sell\",\n \"rpg.shop.back\": \"Back\",\n \"rpg.shop.equipped\": \"Equipped\",\n \"rpg.shop.already-equipped\": \"Already equipped\",\n \"rpg.shop.qty\": \"Qty\",\n \"rpg.shop.available\": \"Available\",\n \"rpg.shop.quantity\": \"Quantity\",\n \"rpg.shop.total\": \"Total\",\n },\n};\n\nexport function provideI18n(config: I18nConfig = {}) {\n return createI18nProvider(config);\n}\n"],"mappings":";;AAEA,IAAa,uBAAuB,EAClC,IAAI;CACF,kBAAkB;CAClB,mBAAmB;CACnB,kBAAkB;CAClB,iBAAiB;CACjB,uBAAuB;CACvB,kBAAkB;CAClB,mBAAmB;CACnB,kBAAkB;CAClB,oBAAoB;CACpB,iBAAiB;CACjB,iBAAiB;CACjB,oBAAoB;CACpB,kBAAkB;CAClB,gBAAgB;CAChB,mBAAmB;CACnB,oBAAoB;CACpB,6BAA6B;CAC7B,kBAAkB;CAClB,uBAAuB;CACvB,sBAAsB;CACtB,yBAAyB;CACzB,kBAAkB;CAClB,qBAAqB;CACrB,kBAAkB;CAClB,qBAAqB;CACrB,iBAAiB;CACjB,iBAAiB;CACjB,uBAAuB;CACvB,kBAAkB;CAClB,gBAAgB;CAChB,gBAAgB;CAChB,iBAAiB;CACjB,qBAAqB;CACrB,mBAAmB;CACnB,kBAAkB;CAClB,sBAAsB;CACtB,6BAA6B;CAC7B,0BAA0B;CAC1B,qBAAqB;CACrB,oBAAoB;CACpB,2BAA2B;CAC3B,4BAA4B;CAC5B,0BAA0B;CAC1B,uBAAuB;CACvB,uBAAuB;CACvB,wBAAwB;CACxB,8BAA8B;CAC9B,8BAA8B;CAC9B,yBAAyB;CACzB,4BAA4B;CAC5B,0BAA0B;CAC1B,gBAAgB;CAChB,iBAAiB;CACjB,iBAAiB;CACjB,qBAAqB;CACrB,6BAA6B;CAC7B,gBAAgB;CAChB,sBAAsB;CACtB,qBAAqB;CACrB,kBAAkB;AACpB,EACF;AAEA,SAAgB,YAAY,SAAqB,CAAC,GAAG;CACnD,OAAO,mBAAmB,MAAM;AAClC"}
1
+ {"version":3,"file":"i18n.js","names":[],"sources":["../src/i18n.ts"],"sourcesContent":["import { createI18nProvider, type I18nConfig } from \"@rpgjs/common\";\n\nexport const RpgClientBuiltinI18n = {\n en: {\n \"rpg.menu.title\": \"Menu\",\n \"rpg.menu.status\": \"Status\",\n \"rpg.menu.level\": \"Level\",\n \"rpg.menu.gold\": \"Gold\",\n \"rpg.menu.parameters\": \"Parameters\",\n \"rpg.menu.items\": \"Items\",\n \"rpg.menu.skills\": \"Skills\",\n \"rpg.menu.equip\": \"Equip\",\n \"rpg.menu.options\": \"Options\",\n \"rpg.menu.save\": \"Save\",\n \"rpg.menu.exit\": \"Exit\",\n \"rpg.menu.weapons\": \"Weapons\",\n \"rpg.menu.armor\": \"Armor\",\n \"rpg.menu.use\": \"Use\",\n \"rpg.menu.cancel\": \"Cancel\",\n \"rpg.menu.unequip\": \"Unequip\",\n \"rpg.menu.remove-equipment\": \"Remove the current equipment\",\n \"rpg.menu.empty\": \"Empty\",\n \"rpg.menu.leave-game\": \"Leave the game?\",\n \"rpg.menu.exit-help\": \"Press Action to confirm or Escape to go back.\",\n \"rpg.menu.options-help\": \"Configure your preferences here.\",\n \"rpg.save.title\": \"Save Game\",\n \"rpg.save.subtitle\": \"Choose a slot to overwrite or create.\",\n \"rpg.load.title\": \"Load Game\",\n \"rpg.load.subtitle\": \"Select a slot to load your progress.\",\n \"rpg.save.auto\": \"Auto Save\",\n \"rpg.save.slot\": \"Slot {index}\",\n \"rpg.save.empty-slot\": \"Empty Slot\",\n \"rpg.save.level\": \"Level\",\n \"rpg.save.exp\": \"Exp\",\n \"rpg.save.map\": \"Map\",\n \"rpg.save.date\": \"Date\",\n \"rpg.title.default\": \"RPG\",\n \"rpg.title.start\": \"Start\",\n \"rpg.title.load\": \"Load\",\n \"rpg.gameover.title\": \"Game Over\",\n \"rpg.gameover.title-screen\": \"Title Screen\",\n \"rpg.gameover.load-game\": \"Load Game\",\n \"rpg.input.confirm\": \"Confirm\",\n \"rpg.input.cancel\": \"Cancel\",\n \"rpg.input.error.invalid\": \"Invalid value.\",\n \"rpg.input.error.required\": \"A value is required.\",\n \"rpg.input.error.number\": \"Enter a valid number.\",\n \"rpg.input.error.min\": \"The value must be at least {min}.\",\n \"rpg.input.error.max\": \"The value must be at most {max}.\",\n \"rpg.input.error.step\": \"The value must use increments of {step}.\",\n \"rpg.input.error.min-length\": \"Enter at least {minLength} characters.\",\n \"rpg.input.error.max-length\": \"Enter no more than {maxLength} characters.\",\n \"rpg.input.error.email\": \"Enter a valid email address.\",\n \"rpg.transition.loading\": \"Loading area…\",\n \"rpg.shop.default-message\": \"Welcome to my shop!\",\n \"rpg.shop.choose-action\": \"Choose an action\",\n \"rpg.shop.buy\": \"Buy\",\n \"rpg.shop.sell\": \"Sell\",\n \"rpg.shop.back\": \"Back\",\n \"rpg.shop.equipped\": \"Equipped\",\n \"rpg.shop.already-equipped\": \"Already equipped\",\n \"rpg.shop.qty\": \"Qty\",\n \"rpg.shop.available\": \"Available\",\n \"rpg.shop.quantity\": \"Quantity\",\n \"rpg.shop.total\": \"Total\",\n },\n};\n\nexport function provideI18n(config: I18nConfig = {}) {\n return createI18nProvider(config);\n}\n"],"mappings":";;AAEA,IAAa,uBAAuB,EAClC,IAAI;CACF,kBAAkB;CAClB,mBAAmB;CACnB,kBAAkB;CAClB,iBAAiB;CACjB,uBAAuB;CACvB,kBAAkB;CAClB,mBAAmB;CACnB,kBAAkB;CAClB,oBAAoB;CACpB,iBAAiB;CACjB,iBAAiB;CACjB,oBAAoB;CACpB,kBAAkB;CAClB,gBAAgB;CAChB,mBAAmB;CACnB,oBAAoB;CACpB,6BAA6B;CAC7B,kBAAkB;CAClB,uBAAuB;CACvB,sBAAsB;CACtB,yBAAyB;CACzB,kBAAkB;CAClB,qBAAqB;CACrB,kBAAkB;CAClB,qBAAqB;CACrB,iBAAiB;CACjB,iBAAiB;CACjB,uBAAuB;CACvB,kBAAkB;CAClB,gBAAgB;CAChB,gBAAgB;CAChB,iBAAiB;CACjB,qBAAqB;CACrB,mBAAmB;CACnB,kBAAkB;CAClB,sBAAsB;CACtB,6BAA6B;CAC7B,0BAA0B;CAC1B,qBAAqB;CACrB,oBAAoB;CACpB,2BAA2B;CAC3B,4BAA4B;CAC5B,0BAA0B;CAC1B,uBAAuB;CACvB,uBAAuB;CACvB,wBAAwB;CACxB,8BAA8B;CAC9B,8BAA8B;CAC9B,yBAAyB;CACzB,0BAA0B;CAC1B,4BAA4B;CAC5B,0BAA0B;CAC1B,gBAAgB;CAChB,iBAAiB;CACjB,iBAAiB;CACjB,qBAAqB;CACrB,6BAA6B;CAC7B,gBAAgB;CAChB,sBAAsB;CACtB,qBAAqB;CACrB,kBAAkB;AACpB,EACF;AAEA,SAAgB,YAAY,SAAqB,CAAC,GAAG;CACnD,OAAO,mBAAmB,MAAM;AAClC"}
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from './core/setup';
7
7
  export * from './core/inject';
8
8
  export * from './services/loadMap';
9
9
  export * from './services/actionInput';
10
+ export * from './services/mapStreaming';
10
11
  export * from './services/pointerContext';
11
12
  export * from './services/interactions';
12
13
  export * from './module';
@@ -24,6 +25,7 @@ export * from './utils/getEntityProp';
24
25
  export { Context } from '@signe/di';
25
26
  export { KeyboardControls, Input } from 'canvasengine';
26
27
  export { Control } from './services/keyboardControls';
28
+ export { defineModule } from '@rpgjs/common';
27
29
  export { RpgClientObject } from './Game/Object';
28
30
  export { RpgClientPlayer } from './Game/Player';
29
31
  export { RpgClientEvent } from './Game/Event';
package/dist/index.js CHANGED
@@ -41,6 +41,7 @@ import { Control } from "./services/keyboardControls.js";
41
41
  import { provideRpg } from "./services/standalone.js";
42
42
  import { BridgeWebsocket, provideMmorpg } from "./services/mmorpg.js";
43
43
  import { startGame } from "./core/setup.js";
44
+ import { MapStreamClientController, provideClientMapStreaming } from "./services/mapStreaming.js";
44
45
  import __ce_component$7 from "./components/prebuilt/hp-bar.ce.js";
45
46
  import __ce_component$12 from "./components/prebuilt/light-halo.ce.js";
46
47
  import "./components/prebuilt/index.js";
@@ -51,4 +52,5 @@ import "./components/index.js";
51
52
  import { Spritesheet } from "./decorators/spritesheet.js";
52
53
  import { withMobile } from "./components/gui/mobile/index.js";
53
54
  import { Input, KeyboardControls } from "canvasengine";
54
- export { AbstractWebsocket, __ce_component as BoxComponent, BridgeWebsocket, __ce_component$1 as CharacterComponent, ClientVisualRegistry, Context, Control, __ce_component$2 as DialogboxComponent, __ce_component$3 as EquipMenuComponent, __ce_component$4 as EventLayerComponent, __ce_component$5 as ExitMenuComponent, __ce_component$6 as GameoverComponent, GlobalConfigToken, __ce_component$7 as HpBar, __ce_component$8 as HudComponent, Input, __ce_component$9 as InputComponent, __ce_component$10 as InputFieldComponent, __ce_component$11 as ItemsMenuComponent, KeyboardControls, __ce_component$12 as LightHalo, LoadMapService, LoadMapToken, __ce_component$13 as MainMenuComponent, __ce_component$14 as NotificationComponent, __ce_component$15 as OptionsMenuComponent, PrebuiltComponentAnimations, Presets, ProjectileManager, RpgClientBuiltinI18n, RpgClientEngine, RpgClientEvent, RpgClientInteractions, RpgClientObject, RpgClientPlayer, RpgGui, RpgResource, RpgSound, SaveClientService, SaveClientToken, __ce_component$16 as SaveLoadComponent, __ce_component$17 as SceneMap, __ce_component$18 as ShopComponent, __ce_component$19 as SkillsMenuComponent, Sound, Spritesheet, __ce_component$20 as TitleScreenComponent, WebSocketToken, clearInject, context, createClientPointerContext, dragToTile, draggable, getEntityProp, getKeyboardControlBind, getSoundMetadata, hoverPopover, inject, isKeyboardActionConfig, keyboardEventMatchesBind, normalizeActionInput, provideClientGlobalConfig, provideClientModules, provideGlobalConfig, provideI18n, provideLoadMap, provideMmorpg, provideRpg, provideSaveClient, resolveKeyboardActionInput, resolveKeyboardDirectionInput, selectable, setInject, startGame, withMobile };
55
+ import { defineModule } from "@rpgjs/common";
56
+ export { AbstractWebsocket, __ce_component as BoxComponent, BridgeWebsocket, __ce_component$1 as CharacterComponent, ClientVisualRegistry, Context, Control, __ce_component$2 as DialogboxComponent, __ce_component$3 as EquipMenuComponent, __ce_component$4 as EventLayerComponent, __ce_component$5 as ExitMenuComponent, __ce_component$6 as GameoverComponent, GlobalConfigToken, __ce_component$7 as HpBar, __ce_component$8 as HudComponent, Input, __ce_component$9 as InputComponent, __ce_component$10 as InputFieldComponent, __ce_component$11 as ItemsMenuComponent, KeyboardControls, __ce_component$12 as LightHalo, LoadMapService, LoadMapToken, __ce_component$13 as MainMenuComponent, MapStreamClientController, __ce_component$14 as NotificationComponent, __ce_component$15 as OptionsMenuComponent, PrebuiltComponentAnimations, Presets, ProjectileManager, RpgClientBuiltinI18n, RpgClientEngine, RpgClientEvent, RpgClientInteractions, RpgClientObject, RpgClientPlayer, RpgGui, RpgResource, RpgSound, SaveClientService, SaveClientToken, __ce_component$16 as SaveLoadComponent, __ce_component$17 as SceneMap, __ce_component$18 as ShopComponent, __ce_component$19 as SkillsMenuComponent, Sound, Spritesheet, __ce_component$20 as TitleScreenComponent, WebSocketToken, clearInject, context, createClientPointerContext, defineModule, dragToTile, draggable, getEntityProp, getKeyboardControlBind, getSoundMetadata, hoverPopover, inject, isKeyboardActionConfig, keyboardEventMatchesBind, normalizeActionInput, provideClientGlobalConfig, provideClientMapStreaming, provideClientModules, provideGlobalConfig, provideI18n, provideLoadMap, provideMmorpg, provideRpg, provideSaveClient, resolveKeyboardActionInput, resolveKeyboardDirectionInput, selectable, setInject, startGame, withMobile };
@@ -1,5 +1,6 @@
1
1
  import { Context } from '@signe/di';
2
2
  import { LightingState } from '@rpgjs/common';
3
+ import { RpgClientMap } from '../Game/Map';
3
4
  export declare const LoadMapToken = "LoadMapToken";
4
5
  /**
5
6
  * Represents the structure of map data that should be returned by the load map callback.
@@ -7,7 +8,7 @@ export declare const LoadMapToken = "LoadMapToken";
7
8
  *
8
9
  * @interface MapData
9
10
  */
10
- type MapData = {
11
+ export type MapData = {
11
12
  /** Raw map data that will be passed to the map component */
12
13
  data: any;
13
14
  /** CanvasEngine component that will render the map */
@@ -28,6 +29,13 @@ type MapData = {
28
29
  id?: string;
29
30
  /** Optional initial lighting state for the loaded map */
30
31
  lighting?: LightingState | null;
32
+ /** Optional render parameters passed to the map component. */
33
+ params?: Record<string, unknown>;
34
+ /** Internal controller used by a progressive map provider. */
35
+ streamController?: {
36
+ attach(map: RpgClientMap): void;
37
+ detach(): void;
38
+ };
31
39
  };
32
40
  /**
33
41
  * Callback function type for loading map data.
@@ -44,6 +52,7 @@ export declare class LoadMapService {
44
52
  private options;
45
53
  private updateMapService;
46
54
  constructor(context: Context, options: LoadMapOptions);
55
+ initialize(): void;
47
56
  load(mapId: string): Promise<MapData>;
48
57
  }
49
58
  /**
@@ -141,4 +150,3 @@ export declare function provideLoadMap(options: LoadMapOptions): {
141
150
  provide: string;
142
151
  useFactory: (context: Context) => void;
143
152
  }[];
144
- export {};
@@ -7,9 +7,10 @@ var LoadMapService = class {
7
7
  this.context = context;
8
8
  this.options = options;
9
9
  if (context["side"] === "server") return;
10
- this.updateMapService = inject(context, UpdateMapToken);
11
10
  }
11
+ initialize() {}
12
12
  async load(mapId) {
13
+ this.updateMapService ??= inject(this.context, UpdateMapToken);
13
14
  const map = await this.options(mapId.replace("map-", ""));
14
15
  await this.updateMapService.update(map);
15
16
  return map;
@@ -1 +1 @@
1
- {"version":3,"file":"loadMap.js","names":[],"sources":["../../src/services/loadMap.ts"],"sourcesContent":["import { Context, inject } from \"@signe/di\";\nimport { UpdateMapToken, UpdateMapService, type LightingState } from \"@rpgjs/common\";\n\nexport const LoadMapToken = 'LoadMapToken'\n\n/**\n * Represents the structure of map data that should be returned by the load map callback.\n * This interface defines all the properties that can be provided when loading a custom map.\n * \n * @interface MapData\n */\ntype MapData = {\n /** Raw map data that will be passed to the map component */\n data: any;\n /** CanvasEngine component that will render the map */\n component: any;\n /** Optional map width in pixels, used for viewport calculations */\n width?: number;\n /** Optional map height in pixels, used for viewport calculations */\n height?: number;\n /** Optional map events data (NPCs, interactive objects, etc.) */\n events?: any;\n /** Optional named positions, for example Tiled point objects used by changeMap(\"map\", \"name\") */\n positions?: Record<string, { x: number; y: number; z?: number }>;\n /** Optional map identifier, defaults to the mapId parameter if not provided */\n id?: string;\n /** Optional initial lighting state for the loaded map */\n lighting?: LightingState | null;\n}\n\n/**\n * Callback function type for loading map data.\n * This function receives a map ID and should return either a MapData object directly\n * or a Promise that resolves to a MapData object.\n * \n * @callback LoadMapOptions\n * @param {string} mapId - The identifier of the map to load\n * @returns {Promise<MapData> | MapData} The map data object or a promise resolving to it\n */\nexport type LoadMapOptions = (mapId: string) => Promise<MapData> | MapData \n\nexport class LoadMapService {\n private updateMapService: UpdateMapService;\n\n constructor(private context: Context, private options: LoadMapOptions) {\n if (context['side'] === 'server') {\n return\n }\n this.updateMapService = inject(context, UpdateMapToken);\n }\n\n async load(mapId: string) {\n const map = await this.options(mapId.replace('map-', ''))\n await this.updateMapService.update(map);\n return map;\n }\n}\n\n/**\n * Creates a dependency injection configuration for custom map loading on the client side.\n * \n * This function allows you to customize how maps are loaded and displayed by providing\n * a callback that defines custom map data and rendering components. It's designed to work\n * with the RPG-JS dependency injection system and enables integration of custom map formats\n * like Tiled TMX files or any other map data structure.\n * \n * The function sets up the necessary service providers for map loading, including:\n * - UpdateMapToken: Handles map updates in the client context\n * - LoadMapToken: Provides the LoadMapService with your custom loading logic\n * \n * **Design Concept:**\n * The function follows the provider pattern, creating a modular way to inject custom\n * map loading behavior into the RPG-JS client engine. It separates the concern of\n * map data fetching from map rendering, allowing developers to focus on their specific\n * map format while leveraging the engine's rendering capabilities.\n * \n * @param {LoadMapOptions} options - Callback function that handles map loading logic\n * @returns {Array<Object>} Array of dependency injection provider configurations\n * \n * @example\n * ```typescript\n * import { provideLoadMap } from '@rpgjs/client'\n * import { createModule } from '@rpgjs/common'\n * import MyTiledMapComponent from './MyTiledMapComponent.ce'\n * \n * // Basic usage with JSON map data\n * export function provideCustomMap() {\n * return createModule(\"CustomMap\", [\n * provideLoadMap(async (mapId) => {\n * const response = await fetch(`/maps/${mapId}.json`)\n * const mapData = await response.json()\n * \n * return {\n * data: mapData,\n * component: MyTiledMapComponent,\n * width: mapData.width,\n * height: mapData.height,\n * events: mapData.events\n * }\n * })\n * ])\n * }\n * \n * // Advanced usage with Tiled TMX files\n * export function provideTiledMap() {\n * return createModule(\"TiledMap\", [\n * provideLoadMap(async (mapId) => {\n * // Load TMX file\n * const tmxResponse = await fetch(`/tiled/${mapId}.tmx`)\n * const tmxData = await tmxResponse.text()\n * \n * // Parse TMX data (using a TMX parser)\n * const parsedMap = parseTMX(tmxData)\n * \n * return {\n * data: parsedMap,\n * component: TiledMapRenderer,\n * width: parsedMap.width * parsedMap.tilewidth,\n * height: parsedMap.height * parsedMap.tileheight,\n * events: parsedMap.objectGroups?.find(g => g.name === 'events')?.objects\n * }\n * })\n * ])\n * }\n * \n * // Synchronous usage for static maps\n * export function provideStaticMap() {\n * return createModule(\"StaticMap\", [\n * provideLoadMap((mapId) => {\n * const staticMaps = {\n * 'town': { tiles: [...], npcs: [...] },\n * 'dungeon': { tiles: [...], monsters: [...] }\n * }\n * \n * return {\n * data: staticMaps[mapId],\n * component: StaticMapComponent,\n * width: 800,\n * height: 600\n * }\n * })\n * ])\n * }\n * ```\n * \n * @since 4.0.0\n * @see {@link LoadMapOptions} for callback function signature\n * @see {@link MapData} for return data structure\n */\nexport function provideLoadMap(options: LoadMapOptions) {\n return [\n {\n provide: UpdateMapToken,\n useFactory: (context: Context) => {\n if (context['side'] === 'client') {\n console.warn('UpdateMapToken is not overridden')\n }\n return\n },\n },\n {\n provide: LoadMapToken,\n useFactory: (context: Context) => new LoadMapService(context, options),\n },\n ];\n}\n"],"mappings":";;;AAGA,IAAa,eAAe;AAsC5B,IAAa,iBAAb,MAA4B;CAG1B,YAAY,SAA0B,SAAiC;EAAnD,KAAA,UAAA;EAA0B,KAAA,UAAA;EAC5C,IAAI,QAAQ,YAAY,UACtB;EAEF,KAAK,mBAAmB,OAAO,SAAS,cAAc;CACxD;CAEA,MAAM,KAAK,OAAe;EACxB,MAAM,MAAM,MAAM,KAAK,QAAQ,MAAM,QAAQ,QAAQ,EAAE,CAAC;EACxD,MAAM,KAAK,iBAAiB,OAAO,GAAG;EACtC,OAAO;CACT;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,SAAgB,eAAe,SAAyB;CACtD,OAAO,CACL;EACE,SAAS;EACT,aAAa,YAAqB;GAChC,IAAI,QAAQ,YAAY,UACtB,QAAQ,KAAK,kCAAkC;EAGnD;CACF,GACA;EACE,SAAS;EACT,aAAa,YAAqB,IAAI,eAAe,SAAS,OAAO;CACvE,CACF;AACF"}
1
+ {"version":3,"file":"loadMap.js","names":[],"sources":["../../src/services/loadMap.ts"],"sourcesContent":["import { Context, inject } from \"@signe/di\";\nimport { UpdateMapToken, UpdateMapService, type LightingState } from \"@rpgjs/common\";\nimport type { RpgClientMap } from \"../Game/Map\";\n\nexport const LoadMapToken = 'LoadMapToken'\n\n/**\n * Represents the structure of map data that should be returned by the load map callback.\n * This interface defines all the properties that can be provided when loading a custom map.\n * \n * @interface MapData\n */\nexport type MapData = {\n /** Raw map data that will be passed to the map component */\n data: any;\n /** CanvasEngine component that will render the map */\n component: any;\n /** Optional map width in pixels, used for viewport calculations */\n width?: number;\n /** Optional map height in pixels, used for viewport calculations */\n height?: number;\n /** Optional map events data (NPCs, interactive objects, etc.) */\n events?: any;\n /** Optional named positions, for example Tiled point objects used by changeMap(\"map\", \"name\") */\n positions?: Record<string, { x: number; y: number; z?: number }>;\n /** Optional map identifier, defaults to the mapId parameter if not provided */\n id?: string;\n /** Optional initial lighting state for the loaded map */\n lighting?: LightingState | null;\n /** Optional render parameters passed to the map component. */\n params?: Record<string, unknown>;\n /** Internal controller used by a progressive map provider. */\n streamController?: { attach(map: RpgClientMap): void; detach(): void };\n}\n\n/**\n * Callback function type for loading map data.\n * This function receives a map ID and should return either a MapData object directly\n * or a Promise that resolves to a MapData object.\n * \n * @callback LoadMapOptions\n * @param {string} mapId - The identifier of the map to load\n * @returns {Promise<MapData> | MapData} The map data object or a promise resolving to it\n */\nexport type LoadMapOptions = (mapId: string) => Promise<MapData> | MapData \n\nexport class LoadMapService {\n private updateMapService: UpdateMapService;\n\n constructor(private context: Context, private options: LoadMapOptions) {\n if (context['side'] === 'server') {\n return\n }\n }\n\n initialize(): void {}\n\n async load(mapId: string) {\n this.updateMapService ??= inject(this.context, UpdateMapToken);\n const map = await this.options(mapId.replace('map-', ''))\n await this.updateMapService.update(map);\n return map;\n }\n}\n\n/**\n * Creates a dependency injection configuration for custom map loading on the client side.\n * \n * This function allows you to customize how maps are loaded and displayed by providing\n * a callback that defines custom map data and rendering components. It's designed to work\n * with the RPG-JS dependency injection system and enables integration of custom map formats\n * like Tiled TMX files or any other map data structure.\n * \n * The function sets up the necessary service providers for map loading, including:\n * - UpdateMapToken: Handles map updates in the client context\n * - LoadMapToken: Provides the LoadMapService with your custom loading logic\n * \n * **Design Concept:**\n * The function follows the provider pattern, creating a modular way to inject custom\n * map loading behavior into the RPG-JS client engine. It separates the concern of\n * map data fetching from map rendering, allowing developers to focus on their specific\n * map format while leveraging the engine's rendering capabilities.\n * \n * @param {LoadMapOptions} options - Callback function that handles map loading logic\n * @returns {Array<Object>} Array of dependency injection provider configurations\n * \n * @example\n * ```typescript\n * import { provideLoadMap } from '@rpgjs/client'\n * import { createModule } from '@rpgjs/common'\n * import MyTiledMapComponent from './MyTiledMapComponent.ce'\n * \n * // Basic usage with JSON map data\n * export function provideCustomMap() {\n * return createModule(\"CustomMap\", [\n * provideLoadMap(async (mapId) => {\n * const response = await fetch(`/maps/${mapId}.json`)\n * const mapData = await response.json()\n * \n * return {\n * data: mapData,\n * component: MyTiledMapComponent,\n * width: mapData.width,\n * height: mapData.height,\n * events: mapData.events\n * }\n * })\n * ])\n * }\n * \n * // Advanced usage with Tiled TMX files\n * export function provideTiledMap() {\n * return createModule(\"TiledMap\", [\n * provideLoadMap(async (mapId) => {\n * // Load TMX file\n * const tmxResponse = await fetch(`/tiled/${mapId}.tmx`)\n * const tmxData = await tmxResponse.text()\n * \n * // Parse TMX data (using a TMX parser)\n * const parsedMap = parseTMX(tmxData)\n * \n * return {\n * data: parsedMap,\n * component: TiledMapRenderer,\n * width: parsedMap.width * parsedMap.tilewidth,\n * height: parsedMap.height * parsedMap.tileheight,\n * events: parsedMap.objectGroups?.find(g => g.name === 'events')?.objects\n * }\n * })\n * ])\n * }\n * \n * // Synchronous usage for static maps\n * export function provideStaticMap() {\n * return createModule(\"StaticMap\", [\n * provideLoadMap((mapId) => {\n * const staticMaps = {\n * 'town': { tiles: [...], npcs: [...] },\n * 'dungeon': { tiles: [...], monsters: [...] }\n * }\n * \n * return {\n * data: staticMaps[mapId],\n * component: StaticMapComponent,\n * width: 800,\n * height: 600\n * }\n * })\n * ])\n * }\n * ```\n * \n * @since 4.0.0\n * @see {@link LoadMapOptions} for callback function signature\n * @see {@link MapData} for return data structure\n */\nexport function provideLoadMap(options: LoadMapOptions) {\n return [\n {\n provide: UpdateMapToken,\n useFactory: (context: Context) => {\n if (context['side'] === 'client') {\n console.warn('UpdateMapToken is not overridden')\n }\n return\n },\n },\n {\n provide: LoadMapToken,\n useFactory: (context: Context) => new LoadMapService(context, options),\n },\n ];\n}\n"],"mappings":";;;AAIA,IAAa,eAAe;AA0C5B,IAAa,iBAAb,MAA4B;CAG1B,YAAY,SAA0B,SAAiC;EAAnD,KAAA,UAAA;EAA0B,KAAA,UAAA;EAC5C,IAAI,QAAQ,YAAY,UACtB;CAEJ;CAEA,aAAmB,CAAC;CAEpB,MAAM,KAAK,OAAe;EACxB,KAAK,qBAAqB,OAAO,KAAK,SAAS,cAAc;EAC7D,MAAM,MAAM,MAAM,KAAK,QAAQ,MAAM,QAAQ,QAAQ,EAAE,CAAC;EACxD,MAAM,KAAK,iBAAiB,OAAO,GAAG;EACtC,OAAO;CACT;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,SAAgB,eAAe,SAAyB;CACtD,OAAO,CACL;EACE,SAAS;EACT,aAAa,YAAqB;GAChC,IAAI,QAAQ,YAAY,UACtB,QAAQ,KAAK,kCAAkC;EAGnD;CACF,GACA;EACE,SAAS;EACT,aAAa,YAAqB,IAAI,eAAe,SAAS,OAAO;CACvE,CACF;AACF"}
@@ -0,0 +1,85 @@
1
+ import { Context } from '@signe/di';
2
+ import { MapChunkHitbox, MapStreamChunk, MapStreamManifest, MapStreamPacket } from '@rpgjs/common';
3
+ import { MapData, LoadMapOptions } from './loadMap';
4
+ export interface ClientMapStreamingAdapter<TManifestData = unknown, TChunkData = unknown, TState = unknown> {
5
+ /** CanvasEngine component that renders the provider-specific state. */
6
+ component: unknown;
7
+ /** Create empty client render state from public manifest data. */
8
+ createState(manifest: MapStreamManifest<TManifestData>): TState;
9
+ /** Apply one disclosed render chunk to the state. */
10
+ applyChunk(state: TState, chunk: MapStreamChunk<TChunkData>): void;
11
+ /** Remove one chunk that left the retention window. */
12
+ removeChunk(state: TState, key: string): void;
13
+ /** Return the serializable/component-ready map value exposed to CanvasEngine. */
14
+ getData(state: TState): unknown;
15
+ /** Optionally derive component parameters from the public manifest. */
16
+ getParams?(manifest: MapStreamManifest<TManifestData>): Record<string, unknown>;
17
+ }
18
+ export interface ClientMapStreamingOptions<TManifestData = unknown, TChunkData = unknown, TState = unknown> {
19
+ /** Format adapter paired with the server compiler. */
20
+ adapter: ClientMapStreamingAdapter<TManifestData, TChunkData, TState>;
21
+ /** Optional direct loader used only by standalone RPG mode. */
22
+ directLoad?: LoadMapOptions;
23
+ /** Maximum wait for the initial authoritative manifest. Defaults to 10 seconds. */
24
+ timeoutMs?: number;
25
+ }
26
+ type StreamingPhysicsMap = {
27
+ data: {
28
+ (): MapData | null;
29
+ set(value: MapData): void;
30
+ };
31
+ replaceStreamedStaticHitboxes(namespace: string, hitboxes: MapChunkHitbox[]): void;
32
+ clearStreamedStaticHitboxes(namespace: string): void;
33
+ };
34
+ export declare class MapStreamClientController<TManifestData, TChunkData, TState> {
35
+ private readonly adapter;
36
+ private state;
37
+ private manifest;
38
+ private readonly chunks;
39
+ private attachedMap?;
40
+ constructor(adapter: ClientMapStreamingAdapter<TManifestData, TChunkData, TState>, manifest: MapStreamManifest<TManifestData>);
41
+ get revision(): string;
42
+ reset(manifest: MapStreamManifest<TManifestData>): void;
43
+ receive(packet: MapStreamPacket<TManifestData, TChunkData>): void;
44
+ toMapData(): MapData;
45
+ attach(map: StreamingPhysicsMap): void;
46
+ detach(): void;
47
+ private publish;
48
+ private updatePredictionBoundary;
49
+ }
50
+ declare class MapStreamingLoadMapService<TManifestData, TChunkData, TState> {
51
+ private readonly context;
52
+ private readonly options;
53
+ private socket?;
54
+ private stream?;
55
+ private updateMap?;
56
+ constructor(context: Context, options: ClientMapStreamingOptions<TManifestData, TChunkData, TState>);
57
+ initialize(): void;
58
+ load(mapId: string): Promise<MapData>;
59
+ }
60
+ /**
61
+ * Provide a transport-neutral client map loader backed by authoritative chunks.
62
+ * Standalone mode may keep a direct loader while MMORPG mode never fetches the
63
+ * private source map.
64
+ *
65
+ * @param options - Client adapter, optional standalone loader, and timeout.
66
+ * @returns Dependency-injection providers for the RPGJS map loader.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * provideClientMapStreaming({
71
+ * adapter: {
72
+ * component: MyMap,
73
+ * createState: (manifest) => ({ manifest, chunks: new Map() }),
74
+ * applyChunk: (state, chunk) => state.chunks.set(chunk.key, chunk.renderData),
75
+ * removeChunk: (state, key) => state.chunks.delete(key),
76
+ * getData: (state) => state,
77
+ * },
78
+ * })
79
+ * ```
80
+ */
81
+ export declare function provideClientMapStreaming<TManifestData, TChunkData, TState>(options: ClientMapStreamingOptions<TManifestData, TChunkData, TState>): {
82
+ provide: string;
83
+ useFactory: (context: Context) => MapStreamingLoadMapService<TManifestData, TChunkData, TState>;
84
+ }[];
85
+ export {};
@@ -0,0 +1,210 @@
1
+ import { inject } from "../node_modules/.pnpm/@signe_di@3.1.0/node_modules/@signe/di/dist/index.js";
2
+ import { WebSocketToken } from "./AbstractSocket.js";
3
+ import { LoadMapToken } from "./loadMap.js";
4
+ import { MAP_STREAM_EVENT, MAP_STREAM_REQUEST_EVENT, UpdateMapToken } from "@rpgjs/common";
5
+ //#region src/services/mapStreaming.ts
6
+ var MapStreamClientController = class {
7
+ constructor(adapter, manifest) {
8
+ this.adapter = adapter;
9
+ this.chunks = /* @__PURE__ */ new Map();
10
+ this.manifest = manifest;
11
+ this.state = adapter.createState(manifest);
12
+ }
13
+ get revision() {
14
+ return this.manifest.revision;
15
+ }
16
+ reset(manifest) {
17
+ const attachedMap = this.attachedMap;
18
+ this.detach();
19
+ this.manifest = manifest;
20
+ this.state = this.adapter.createState(manifest);
21
+ this.chunks.clear();
22
+ this.attachedMap = attachedMap;
23
+ }
24
+ receive(packet) {
25
+ for (const key of packet.removed) {
26
+ this.chunks.delete(key);
27
+ this.adapter.removeChunk(this.state, key);
28
+ this.attachedMap?.clearStreamedStaticHitboxes(key);
29
+ }
30
+ for (const chunk of packet.chunks) {
31
+ this.chunks.set(chunk.key, chunk);
32
+ this.adapter.applyChunk(this.state, chunk);
33
+ this.attachedMap?.replaceStreamedStaticHitboxes(chunk.key, chunk.hitboxes);
34
+ }
35
+ this.publish();
36
+ }
37
+ toMapData() {
38
+ return {
39
+ id: this.manifest.mapId,
40
+ width: this.manifest.width,
41
+ height: this.manifest.height,
42
+ data: this.adapter.getData(this.state),
43
+ component: this.adapter.component,
44
+ params: this.adapter.getParams?.(this.manifest),
45
+ streamController: this
46
+ };
47
+ }
48
+ attach(map) {
49
+ this.attachedMap = map;
50
+ for (const chunk of this.chunks.values()) map.replaceStreamedStaticHitboxes(chunk.key, chunk.hitboxes);
51
+ this.updatePredictionBoundary();
52
+ }
53
+ detach() {
54
+ if (!this.attachedMap) return;
55
+ for (const key of this.chunks.keys()) this.attachedMap.clearStreamedStaticHitboxes(key);
56
+ this.attachedMap.clearStreamedStaticHitboxes("__boundary__");
57
+ this.attachedMap = void 0;
58
+ }
59
+ publish() {
60
+ if (!this.attachedMap) return;
61
+ const current = this.attachedMap.data();
62
+ if (current) this.attachedMap.data.set({
63
+ ...current,
64
+ data: this.adapter.getData(this.state)
65
+ });
66
+ this.updatePredictionBoundary();
67
+ }
68
+ updatePredictionBoundary() {
69
+ const map = this.attachedMap;
70
+ if (!map) return;
71
+ if (this.chunks.size === 0) {
72
+ map.clearStreamedStaticHitboxes("__boundary__");
73
+ return;
74
+ }
75
+ const chunks = [...this.chunks.values()];
76
+ const left = Math.min(...chunks.map((chunk) => chunk.bounds.x));
77
+ const top = Math.min(...chunks.map((chunk) => chunk.bounds.y));
78
+ const right = Math.max(...chunks.map((chunk) => chunk.bounds.x + chunk.bounds.width));
79
+ const bottom = Math.max(...chunks.map((chunk) => chunk.bounds.y + chunk.bounds.height));
80
+ const thickness = 2;
81
+ const barriers = [];
82
+ if (left > 0) barriers.push({
83
+ x: left - thickness,
84
+ y: top,
85
+ width: thickness,
86
+ height: bottom - top
87
+ });
88
+ if (top > 0) barriers.push({
89
+ x: left,
90
+ y: top - thickness,
91
+ width: right - left,
92
+ height: thickness
93
+ });
94
+ if (right < this.manifest.width) barriers.push({
95
+ x: right,
96
+ y: top,
97
+ width: thickness,
98
+ height: bottom - top
99
+ });
100
+ if (bottom < this.manifest.height) barriers.push({
101
+ x: left,
102
+ y: bottom,
103
+ width: right - left,
104
+ height: thickness
105
+ });
106
+ map.replaceStreamedStaticHitboxes("__boundary__", barriers);
107
+ }
108
+ };
109
+ var MapStreamingClientService = class {
110
+ constructor(socket, options) {
111
+ this.socket = socket;
112
+ this.options = options;
113
+ this.controllers = /* @__PURE__ */ new Map();
114
+ this.waiters = /* @__PURE__ */ new Map();
115
+ socket.on(MAP_STREAM_EVENT, (packet) => this.receive(packet));
116
+ }
117
+ async load(mapId) {
118
+ const normalizedId = mapId.replace(/^map-/, "");
119
+ const existing = this.controllers.get(normalizedId);
120
+ if (existing) {
121
+ this.socket.emit(MAP_STREAM_REQUEST_EVENT, { mapId: normalizedId });
122
+ return existing.toMapData();
123
+ }
124
+ const shouldRequest = !this.waiters.has(normalizedId);
125
+ const controllerPromise = new Promise((resolve, reject) => {
126
+ const timeoutMs = Math.max(1, this.options.timeoutMs ?? 1e4);
127
+ const waiter = {
128
+ resolve,
129
+ reject,
130
+ timer: void 0
131
+ };
132
+ waiter.timer = setTimeout(() => {
133
+ const remaining = (this.waiters.get(normalizedId) ?? []).filter((entry) => entry !== waiter);
134
+ if (remaining.length > 0) this.waiters.set(normalizedId, remaining);
135
+ else this.waiters.delete(normalizedId);
136
+ reject(/* @__PURE__ */ new Error(`Map stream '${normalizedId}' was not received after ${timeoutMs}ms`));
137
+ }, timeoutMs);
138
+ const waiters = this.waiters.get(normalizedId) ?? [];
139
+ waiters.push(waiter);
140
+ this.waiters.set(normalizedId, waiters);
141
+ });
142
+ if (shouldRequest) this.socket.emit(MAP_STREAM_REQUEST_EVENT, { mapId: normalizedId });
143
+ return (await controllerPromise).toMapData();
144
+ }
145
+ receive(packet) {
146
+ if (!packet || typeof packet.mapId !== "string") return;
147
+ const mapId = packet.mapId.replace(/^map-/, "");
148
+ let controller = this.controllers.get(mapId);
149
+ if (!controller) {
150
+ if (!packet.manifest) return;
151
+ controller = new MapStreamClientController(this.options.adapter, packet.manifest);
152
+ this.controllers.set(mapId, controller);
153
+ } else if (packet.manifest && controller.revision !== packet.manifest.revision) controller.reset(packet.manifest);
154
+ controller.receive(packet);
155
+ (this.waiters.get(mapId) ?? []).forEach((waiter) => {
156
+ clearTimeout(waiter.timer);
157
+ waiter.resolve(controller);
158
+ });
159
+ this.waiters.delete(mapId);
160
+ }
161
+ };
162
+ var MapStreamingLoadMapService = class {
163
+ constructor(context, options) {
164
+ this.context = context;
165
+ this.options = options;
166
+ }
167
+ initialize() {
168
+ if (this.stream) return;
169
+ this.socket = inject(this.context, WebSocketToken);
170
+ this.stream = new MapStreamingClientService(this.socket, this.options);
171
+ }
172
+ async load(mapId) {
173
+ this.initialize();
174
+ const map = this.socket?.mode === "standalone" && this.options.directLoad ? await this.options.directLoad(mapId.replace(/^map-/, "")) : await this.stream.load(mapId);
175
+ this.updateMap ??= inject(this.context, UpdateMapToken);
176
+ await this.updateMap.update(map);
177
+ return map;
178
+ }
179
+ };
180
+ /**
181
+ * Provide a transport-neutral client map loader backed by authoritative chunks.
182
+ * Standalone mode may keep a direct loader while MMORPG mode never fetches the
183
+ * private source map.
184
+ *
185
+ * @param options - Client adapter, optional standalone loader, and timeout.
186
+ * @returns Dependency-injection providers for the RPGJS map loader.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * provideClientMapStreaming({
191
+ * adapter: {
192
+ * component: MyMap,
193
+ * createState: (manifest) => ({ manifest, chunks: new Map() }),
194
+ * applyChunk: (state, chunk) => state.chunks.set(chunk.key, chunk.renderData),
195
+ * removeChunk: (state, key) => state.chunks.delete(key),
196
+ * getData: (state) => state,
197
+ * },
198
+ * })
199
+ * ```
200
+ */
201
+ function provideClientMapStreaming(options) {
202
+ return [{
203
+ provide: LoadMapToken,
204
+ useFactory: (context) => new MapStreamingLoadMapService(context, options)
205
+ }];
206
+ }
207
+ //#endregion
208
+ export { MapStreamClientController, provideClientMapStreaming };
209
+
210
+ //# sourceMappingURL=mapStreaming.js.map