@rpgjs/client 5.0.0-beta.7 → 5.0.0-beta.9

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 (158) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/Game/AnimationManager.js.map +1 -1
  3. package/dist/Game/Event.js.map +1 -1
  4. package/dist/Game/Map.d.ts +9 -1
  5. package/dist/Game/Map.js +63 -5
  6. package/dist/Game/Map.js.map +1 -1
  7. package/dist/Game/Object.d.ts +17 -9
  8. package/dist/Game/Object.js +1 -12
  9. package/dist/Game/Object.js.map +1 -1
  10. package/dist/Game/Player.js.map +1 -1
  11. package/dist/Gui/Gui.d.ts +17 -4
  12. package/dist/Gui/Gui.js +64 -34
  13. package/dist/Gui/Gui.js.map +1 -1
  14. package/dist/Gui/Gui.spec.d.ts +1 -0
  15. package/dist/Gui/NotificationManager.js.map +1 -1
  16. package/dist/Resource.js +1 -1
  17. package/dist/Resource.js.map +1 -1
  18. package/dist/RpgClient.d.ts +35 -2
  19. package/dist/RpgClientEngine.d.ts +41 -5
  20. package/dist/RpgClientEngine.js +50 -5
  21. package/dist/RpgClientEngine.js.map +1 -1
  22. package/dist/Sound.js.map +1 -1
  23. package/dist/_virtual/{_@oxc-project_runtime@0.128.0 → _@oxc-project_runtime@0.130.0}/helpers/decorate.js +1 -1
  24. package/dist/_virtual/{_@oxc-project_runtime@0.128.0 → _@oxc-project_runtime@0.130.0}/helpers/decorateMetadata.js +1 -1
  25. package/dist/components/animations/animation.ce.js.map +1 -1
  26. package/dist/components/animations/hit.ce.js.map +1 -1
  27. package/dist/components/animations/index.js.map +1 -1
  28. package/dist/components/character.ce.js +259 -5
  29. package/dist/components/character.ce.js.map +1 -1
  30. package/dist/components/dynamics/bar.ce.js +96 -0
  31. package/dist/components/dynamics/bar.ce.js.map +1 -0
  32. package/dist/components/dynamics/image.ce.js +23 -0
  33. package/dist/components/dynamics/image.ce.js.map +1 -0
  34. package/dist/components/dynamics/parse-value.d.ts +3 -0
  35. package/dist/components/dynamics/parse-value.js +51 -35
  36. package/dist/components/dynamics/parse-value.js.map +1 -1
  37. package/dist/components/dynamics/parse-value.spec.d.ts +1 -0
  38. package/dist/components/dynamics/shape-utils.d.ts +16 -0
  39. package/dist/components/dynamics/shape-utils.js +73 -0
  40. package/dist/components/dynamics/shape-utils.js.map +1 -0
  41. package/dist/components/dynamics/shape-utils.spec.d.ts +1 -0
  42. package/dist/components/dynamics/shape.ce.js +83 -0
  43. package/dist/components/dynamics/shape.ce.js.map +1 -0
  44. package/dist/components/dynamics/text.ce.js +28 -41
  45. package/dist/components/dynamics/text.ce.js.map +1 -1
  46. package/dist/components/gui/box.ce.js.map +1 -1
  47. package/dist/components/gui/dialogbox/index.ce.js +3 -3
  48. package/dist/components/gui/dialogbox/index.ce.js.map +1 -1
  49. package/dist/components/gui/gameover.ce.js +1 -1
  50. package/dist/components/gui/gameover.ce.js.map +1 -1
  51. package/dist/components/gui/hud/hud.ce.js +1 -1
  52. package/dist/components/gui/hud/hud.ce.js.map +1 -1
  53. package/dist/components/gui/menu/equip-menu.ce.js.map +1 -1
  54. package/dist/components/gui/menu/exit-menu.ce.js.map +1 -1
  55. package/dist/components/gui/menu/items-menu.ce.js.map +1 -1
  56. package/dist/components/gui/menu/main-menu.ce.js.map +1 -1
  57. package/dist/components/gui/menu/options-menu.ce.js.map +1 -1
  58. package/dist/components/gui/menu/skills-menu.ce.js.map +1 -1
  59. package/dist/components/gui/mobile/index.js.map +1 -1
  60. package/dist/components/gui/mobile/mobile.ce.js.map +1 -1
  61. package/dist/components/gui/notification/notification.ce.js.map +1 -1
  62. package/dist/components/gui/save-load.ce.js.map +1 -1
  63. package/dist/components/gui/shop/shop.ce.js +1 -1
  64. package/dist/components/gui/shop/shop.ce.js.map +1 -1
  65. package/dist/components/gui/title-screen.ce.js +2 -2
  66. package/dist/components/gui/title-screen.ce.js.map +1 -1
  67. package/dist/components/player-components-utils.d.ts +67 -0
  68. package/dist/components/player-components-utils.js +162 -0
  69. package/dist/components/player-components-utils.js.map +1 -0
  70. package/dist/components/player-components-utils.spec.d.ts +1 -0
  71. package/dist/components/player-components.ce.js +188 -0
  72. package/dist/components/player-components.ce.js.map +1 -0
  73. package/dist/components/prebuilt/hp-bar.ce.js.map +1 -1
  74. package/dist/components/prebuilt/light-halo.ce.js.map +1 -1
  75. package/dist/components/scenes/canvas.ce.js +147 -4
  76. package/dist/components/scenes/canvas.ce.js.map +1 -1
  77. package/dist/components/scenes/draw-map.ce.js +2 -8
  78. package/dist/components/scenes/draw-map.ce.js.map +1 -1
  79. package/dist/components/scenes/event-layer.ce.js.map +1 -1
  80. package/dist/core/inject.js +1 -1
  81. package/dist/core/inject.js.map +1 -1
  82. package/dist/core/setup.js +1 -1
  83. package/dist/core/setup.js.map +1 -1
  84. package/dist/decorators/spritesheet.d.ts +1 -0
  85. package/dist/decorators/spritesheet.js +11 -0
  86. package/dist/decorators/spritesheet.js.map +1 -0
  87. package/dist/index.d.ts +1 -0
  88. package/dist/index.js +3 -2
  89. package/dist/module.js +4 -1
  90. package/dist/module.js.map +1 -1
  91. package/dist/node_modules/.pnpm/{@signe_di@2.10.0 → @signe_di@3.0.1}/node_modules/@signe/di/dist/index.js +1 -1
  92. package/dist/node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js.map +1 -0
  93. package/dist/node_modules/.pnpm/{@signe_reactive@2.9.2 → @signe_reactive@3.0.1}/node_modules/@signe/reactive/dist/index.js +15 -3
  94. package/dist/node_modules/.pnpm/@signe_reactive@3.0.1/node_modules/@signe/reactive/dist/index.js.map +1 -0
  95. package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/chunk-EUXUH3YW.js +13 -0
  96. package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/chunk-EUXUH3YW.js.map +1 -0
  97. package/dist/node_modules/.pnpm/{@signe_room@2.10.0 → @signe_room@3.0.1}/node_modules/@signe/room/dist/index.js +124 -39
  98. package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js.map +1 -0
  99. package/dist/node_modules/.pnpm/{@signe_sync@2.10.0 → @signe_sync@3.0.1}/node_modules/@signe/sync/dist/client/index.js +1 -1
  100. package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/client/index.js.map +1 -0
  101. package/dist/node_modules/.pnpm/{@signe_sync@2.10.0 → @signe_sync@3.0.1}/node_modules/@signe/sync/dist/index.js +36 -13
  102. package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/index.js.map +1 -0
  103. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -1
  104. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -1
  105. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -1
  106. package/dist/presets/animation.js.map +1 -1
  107. package/dist/presets/faceset.js.map +1 -1
  108. package/dist/presets/icon.js.map +1 -1
  109. package/dist/presets/index.js.map +1 -1
  110. package/dist/presets/lpc.js.map +1 -1
  111. package/dist/presets/rmspritesheet.js.map +1 -1
  112. package/dist/services/AbstractSocket.js.map +1 -1
  113. package/dist/services/keyboardControls.js.map +1 -1
  114. package/dist/services/loadMap.d.ts +6 -0
  115. package/dist/services/loadMap.js +1 -1
  116. package/dist/services/loadMap.js.map +1 -1
  117. package/dist/services/mmorpg.js +7 -3
  118. package/dist/services/mmorpg.js.map +1 -1
  119. package/dist/services/save.js.map +1 -1
  120. package/dist/services/standalone.js +1 -1
  121. package/dist/services/standalone.js.map +1 -1
  122. package/dist/utils/getEntityProp.js.map +1 -1
  123. package/package.json +10 -10
  124. package/src/Game/Map.ts +91 -2
  125. package/src/Game/Object.ts +22 -35
  126. package/src/Gui/Gui.spec.ts +273 -0
  127. package/src/Gui/Gui.ts +105 -50
  128. package/src/Resource.ts +1 -2
  129. package/src/RpgClient.ts +36 -2
  130. package/src/RpgClientEngine.ts +74 -11
  131. package/src/components/character.ce +318 -9
  132. package/src/components/dynamics/bar.ce +87 -0
  133. package/src/components/dynamics/image.ce +20 -0
  134. package/src/components/dynamics/parse-value.spec.ts +41 -0
  135. package/src/components/dynamics/parse-value.ts +102 -37
  136. package/src/components/dynamics/shape-utils.spec.ts +46 -0
  137. package/src/components/dynamics/shape-utils.ts +61 -0
  138. package/src/components/dynamics/shape.ce +89 -0
  139. package/src/components/dynamics/text.ce +34 -149
  140. package/src/components/player-components-utils.spec.ts +109 -0
  141. package/src/components/player-components-utils.ts +205 -0
  142. package/src/components/player-components.ce +221 -0
  143. package/src/components/scenes/canvas.ce +165 -6
  144. package/src/components/scenes/draw-map.ce +2 -15
  145. package/src/components/scenes/event-layer.ce +1 -2
  146. package/src/core/setup.ts +2 -2
  147. package/src/decorators/spritesheet.ts +8 -0
  148. package/src/index.ts +1 -0
  149. package/src/module.ts +5 -1
  150. package/src/services/loadMap.ts +2 -0
  151. package/src/services/mmorpg.ts +8 -2
  152. package/dist/node_modules/.pnpm/@signe_di@2.10.0/node_modules/@signe/di/dist/index.js.map +0 -1
  153. package/dist/node_modules/.pnpm/@signe_reactive@2.10.0/node_modules/@signe/reactive/dist/index.js +0 -45
  154. package/dist/node_modules/.pnpm/@signe_reactive@2.10.0/node_modules/@signe/reactive/dist/index.js.map +0 -1
  155. package/dist/node_modules/.pnpm/@signe_reactive@2.9.2/node_modules/@signe/reactive/dist/index.js.map +0 -1
  156. package/dist/node_modules/.pnpm/@signe_room@2.10.0/node_modules/@signe/room/dist/index.js.map +0 -1
  157. package/dist/node_modules/.pnpm/@signe_sync@2.10.0/node_modules/@signe/sync/dist/client/index.js.map +0 -1
  158. package/dist/node_modules/.pnpm/@signe_sync@2.10.0/node_modules/@signe/sync/dist/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"animation.js","names":[],"sources":["../../src/presets/animation.ts"],"sourcesContent":["/**\n * Creates an animation spritesheet preset with automatic frame generation\n * \n * This function generates animation frames based on the provided width and height dimensions.\n * It creates a sequence of frames that progresses through the spritesheet from left to right,\n * top to bottom, with each frame having a 10ms time increment.\n * \n * @param {number} framesWidth - The number of frames horizontally in the spritesheet\n * @param {number} framesHeight - The number of frames vertically in the spritesheet\n * @returns {Object} Animation preset configuration object\n * \n * @example\n * ```javascript\n * // For a 4x4 spritesheet\n * const preset = AnimationSpritesheetPreset(4, 4);\n * // This will generate 16 frames with coordinates from (0,0) to (3,3)\n * ```\n */\nexport const AnimationSpritesheetPreset = (framesWidth: number, framesHeight: number) => {\n \n const animations: Array<{ time: number; frameX: number; frameY: number }> = [];\n\n for (let y = 0; y < framesHeight; y++) {\n for (let x = 0; x < framesWidth; x++) {\n const frameIndex = y * framesWidth + x;\n animations.push({ \n time: frameIndex * 10, \n frameX: x, \n frameY: y \n });\n }\n }\n \n return {\n framesWidth,\n framesHeight,\n textures: {\n default: {\n animations: () => [\n animations\n ],\n }\n }\n };\n};\n "],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,8BAA8B,aAAqB,iBAAyB;CAErF,MAAM,aAAsE,EAAE;CAE9E,KAAK,IAAI,IAAI,GAAG,IAAI,cAAc,KAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,KAAK;EAClC,MAAM,aAAa,IAAI,cAAc;EACrC,WAAW,KAAK;GACZ,MAAM,aAAa;GACnB,QAAQ;GACR,QAAQ;GACX,CAAC;;CAIV,OAAO;EACH;EACA;EACA,UAAU,EACN,SAAS,EACL,kBAAkB,CACd,WACH,EACJ,EACJ;EACJ"}
1
+ {"version":3,"file":"animation.js","names":[],"sources":["../../src/presets/animation.ts"],"sourcesContent":["/**\n * Creates an animation spritesheet preset with automatic frame generation\n * \n * This function generates animation frames based on the provided width and height dimensions.\n * It creates a sequence of frames that progresses through the spritesheet from left to right,\n * top to bottom, with each frame having a 10ms time increment.\n * \n * @param {number} framesWidth - The number of frames horizontally in the spritesheet\n * @param {number} framesHeight - The number of frames vertically in the spritesheet\n * @returns {Object} Animation preset configuration object\n * \n * @example\n * ```javascript\n * // For a 4x4 spritesheet\n * const preset = AnimationSpritesheetPreset(4, 4);\n * // This will generate 16 frames with coordinates from (0,0) to (3,3)\n * ```\n */\nexport const AnimationSpritesheetPreset = (framesWidth: number, framesHeight: number) => {\n \n const animations: Array<{ time: number; frameX: number; frameY: number }> = [];\n\n for (let y = 0; y < framesHeight; y++) {\n for (let x = 0; x < framesWidth; x++) {\n const frameIndex = y * framesWidth + x;\n animations.push({ \n time: frameIndex * 10, \n frameX: x, \n frameY: y \n });\n }\n }\n \n return {\n framesWidth,\n framesHeight,\n textures: {\n default: {\n animations: () => [\n animations\n ],\n }\n }\n };\n};\n "],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,8BAA8B,aAAqB,iBAAyB;CAErF,MAAM,aAAsE,CAAC;CAE7E,KAAK,IAAI,IAAI,GAAG,IAAI,cAAc,KAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,KAAK;EAClC,MAAM,aAAa,IAAI,cAAc;EACrC,WAAW,KAAK;GACZ,MAAM,aAAa;GACnB,QAAQ;GACR,QAAQ;EACZ,CAAC;CACL;CAGJ,OAAO;EACH;EACA;EACA,UAAU,EACN,SAAS,EACL,kBAAkB,CACd,UACJ,EACJ,EACJ;CACJ;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"faceset.js","names":[],"sources":["../../src/presets/faceset.ts"],"sourcesContent":["/**\n * Creates a faceset preset for character expressions\n * \n * This preset allows you to define multiple facial expressions for a character,\n * where each expression corresponds to a specific frame position (frameX, frameY)\n * within a single faceset texture. Each expression is defined by its position\n * in the faceset grid.\n * \n * @param options - Object containing the faceset configuration\n * @param framesWidth - Number of frames horizontally in the faceset texture\n * @param framesHeight - Number of frames vertically in the faceset texture\n * @param expressions - Object mapping expression names to their frame positions as tuples [frameX, frameY]\n * @returns Faceset configuration with animations for each expression\n * \n * @example\n * ```typescript\n * const faceset = FacesetPreset({\n * id: \"facesetId\",\n * image: \"faceset.png\",\n * width: 1024,\n * height: 1024,\n * }, 4, 2, {\n * happy: [0, 0],\n * sad: [1, 0],\n * angry: [2, 0],\n * surprised: [3, 0]\n * });\n * ```\n */\nexport const FacesetPreset = (\n options: any,\n framesWidth: number, \n framesHeight: number,\n expressions: Record<string, [number, number]>,\n) => {\n \n const textures: Record<string, any> = {};\n \n // Create texture configuration for each expression\n Object.keys(expressions).forEach((expressionName) => {\n const [frameX, frameY] = expressions[expressionName];\n textures[expressionName] = {\n animations: () => [\n [{ \n time: 0, \n frameX: frameX, \n frameY: frameY \n }]\n ],\n };\n });\n \n return {\n ...options,\n framesWidth,\n framesHeight,\n textures\n };\n};\n "],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,iBACT,SACA,aACA,cACA,gBACC;CAED,MAAM,WAAgC,EAAE;CAGxC,OAAO,KAAK,YAAY,CAAC,SAAS,mBAAmB;EACjD,MAAM,CAAC,QAAQ,UAAU,YAAY;EACrC,SAAS,kBAAkB,EACvB,kBAAkB,CACd,CAAC;GACG,MAAM;GACE;GACA;GACX,CAAC,CACL,EACJ;GACH;CAEF,OAAO;EACH,GAAG;EACH;EACA;EACA;EACH"}
1
+ {"version":3,"file":"faceset.js","names":[],"sources":["../../src/presets/faceset.ts"],"sourcesContent":["/**\n * Creates a faceset preset for character expressions\n * \n * This preset allows you to define multiple facial expressions for a character,\n * where each expression corresponds to a specific frame position (frameX, frameY)\n * within a single faceset texture. Each expression is defined by its position\n * in the faceset grid.\n * \n * @param options - Object containing the faceset configuration\n * @param framesWidth - Number of frames horizontally in the faceset texture\n * @param framesHeight - Number of frames vertically in the faceset texture\n * @param expressions - Object mapping expression names to their frame positions as tuples [frameX, frameY]\n * @returns Faceset configuration with animations for each expression\n * \n * @example\n * ```typescript\n * const faceset = FacesetPreset({\n * id: \"facesetId\",\n * image: \"faceset.png\",\n * width: 1024,\n * height: 1024,\n * }, 4, 2, {\n * happy: [0, 0],\n * sad: [1, 0],\n * angry: [2, 0],\n * surprised: [3, 0]\n * });\n * ```\n */\nexport const FacesetPreset = (\n options: any,\n framesWidth: number, \n framesHeight: number,\n expressions: Record<string, [number, number]>,\n) => {\n \n const textures: Record<string, any> = {};\n \n // Create texture configuration for each expression\n Object.keys(expressions).forEach((expressionName) => {\n const [frameX, frameY] = expressions[expressionName];\n textures[expressionName] = {\n animations: () => [\n [{ \n time: 0, \n frameX: frameX, \n frameY: frameY \n }]\n ],\n };\n });\n \n return {\n ...options,\n framesWidth,\n framesHeight,\n textures\n };\n};\n "],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,iBACT,SACA,aACA,cACA,gBACC;CAED,MAAM,WAAgC,CAAC;CAGvC,OAAO,KAAK,WAAW,EAAE,SAAS,mBAAmB;EACjD,MAAM,CAAC,QAAQ,UAAU,YAAY;EACrC,SAAS,kBAAkB,EACvB,kBAAkB,CACd,CAAC;GACG,MAAM;GACE;GACA;EACZ,CAAC,CACL,EACJ;CACJ,CAAC;CAED,OAAO;EACH,GAAG;EACH;EACA;EACA;CACJ;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"icon.js","names":[],"sources":["../../src/presets/icon.ts"],"sourcesContent":["export const IconPreset = (options: {\n image: string;\n framesWidth: number;\n framesHeight: number;\n id: string;\n}) => {\n return {\n textures: {\n default: {\n animations: () => [\n [{ time: 0, frameX: 0, frameY: 0 }]\n ]\n }\n },\n ...options\n }\n}"],"mappings":";AAAA,IAAa,cAAc,YAKrB;CACF,OAAO;EACH,UAAU,EACN,SAAS,EACL,kBAAkB,CACd,CAAC;GAAE,MAAM;GAAG,QAAQ;GAAG,QAAQ;GAAG,CAAC,CACtC,EACJ,EACJ;EACD,GAAG;EACN"}
1
+ {"version":3,"file":"icon.js","names":[],"sources":["../../src/presets/icon.ts"],"sourcesContent":["export const IconPreset = (options: {\n image: string;\n framesWidth: number;\n framesHeight: number;\n id: string;\n}) => {\n return {\n textures: {\n default: {\n animations: () => [\n [{ time: 0, frameX: 0, frameY: 0 }]\n ]\n }\n },\n ...options\n }\n}"],"mappings":";AAAA,IAAa,cAAc,YAKrB;CACF,OAAO;EACH,UAAU,EACN,SAAS,EACL,kBAAkB,CACd,CAAC;GAAE,MAAM;GAAG,QAAQ;GAAG,QAAQ;EAAE,CAAC,CACtC,EACJ,EACJ;EACA,GAAG;CACP;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/presets/index.ts"],"sourcesContent":["import { AnimationSpritesheetPreset } from \"./animation\";\nimport { LPCSpritesheetPreset } from \"./lpc\";\nimport { RMSpritesheet } from \"./rmspritesheet\";\nimport { FacesetPreset } from \"./faceset\";\nimport { IconPreset } from \"./icon\";\n\nexport const Presets = {\n RMSpritesheet,\n LPCSpritesheetPreset,\n AnimationSpritesheetPreset,\n FacesetPreset,\n IconPreset\n}"],"mappings":";;;;;;AAMA,IAAa,UAAU;CACnB;CACA;CACA;CACA;CACA"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/presets/index.ts"],"sourcesContent":["import { AnimationSpritesheetPreset } from \"./animation\";\nimport { LPCSpritesheetPreset } from \"./lpc\";\nimport { RMSpritesheet } from \"./rmspritesheet\";\nimport { FacesetPreset } from \"./faceset\";\nimport { IconPreset } from \"./icon\";\n\nexport const Presets = {\n RMSpritesheet,\n LPCSpritesheetPreset,\n AnimationSpritesheetPreset,\n FacesetPreset,\n IconPreset\n}"],"mappings":";;;;;;AAMA,IAAa,UAAU;CACnB;CACA;CACA;CACA;CACA;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"lpc.js","names":[],"sources":["../../src/presets/lpc.ts"],"sourcesContent":["import { Animation, Direction } from \"@rpgjs/common\";\n\nexport const LPCSpritesheetPreset = (options: {\n id: string;\n imageSource: string;\n width: number;\n height: number;\n ratio?: number;\n }) => {\n const ratio = options.ratio ?? 1;\n\n const frameY = (direction: Direction) => {\n return {\n [Direction.Down]: 2,\n [Direction.Left]: 1,\n [Direction.Right]: 3,\n [Direction.Up]: 0,\n }[direction];\n };\n \n const stand = (direction: Direction) => [\n { time: 0, frameX: 0, frameY: frameY(direction) },\n ];\n const anim = (\n direction: Direction,\n framesWidth: number,\n speed: number = 5\n ) => {\n const array: any = [];\n for (let i = 0; i < framesWidth; i++) {\n array.push({ time: i * speed, frameX: i, frameY: frameY(direction) });\n }\n return array;\n };\n \n return {\n id: options.id,\n image: options.imageSource,\n width: options.width,\n height: options.height,\n opacity: 1,\n rectWidth: 64 * ratio,\n rectHeight: 64 * ratio,\n framesWidth: 6,\n framesHeight: 4,\n spriteRealSize: {\n width: 48 * ratio,\n height: 52 * ratio,\n },\n textures: {\n [Animation.Stand]: {\n offset: {\n x: 0,\n y: 512 * ratio,\n },\n animations: ({ direction }) => [stand(direction)],\n },\n [Animation.Walk]: {\n offset: {\n x: 0,\n y: 512 * ratio,\n },\n framesWidth: 9,\n framesHeight: 4,\n animations: ({ direction }) => [anim(direction, 9)],\n },\n [Animation.Attack]: {\n offset: {\n x: 0,\n y: 768 * ratio,\n },\n framesWidth: 6,\n framesHeight: 4,\n animations: ({ direction }) => [anim(direction, 6, 3)],\n },\n [Animation.Skill]: {\n framesWidth: 7,\n framesHeight: 4,\n animations: ({ direction }) => [anim(direction, 7, 3)],\n },\n attack2: {\n offset: {\n x: 0,\n y: 256 * ratio,\n },\n framesWidth: 7,\n framesHeight: 8,\n animations: ({ direction }) => [anim(direction, 7, 3)],\n },\n ...(options.height > 3000\n ? {\n attack3: {\n offset: {\n x: 0,\n y: 5568 - 288 * 4,\n },\n rectWidth: 288,\n rectHeight: 288,\n framesWidth: 6,\n framesHeight: 4,\n animations: ({ direction }) => [anim(direction, 6, 3)],\n },\n }\n : {}),\n },\n };\n };\n "],"mappings":";;AAEA,IAAa,wBAAwB,YAM7B;CACJ,MAAM,QAAQ,QAAQ,SAAS;CAE/B,MAAM,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Ac;IACd,aAAa,EAAE,gBAAgB,CAAC,KAAK,WAAW,GAAG,EAAE,CAAC;IACvD;GACD,GAAI,QAAQ,SAAS,MACjB,EACE,SAAS;IACP,QAAQ;KACN,GAAG;KACH,GAAG,OAAO,MAAM;KACjB;IACD,WAAW;IACX,YAAY;IACZ,aAAa;IACb,cAAc;IACd,aAAa,EAAE,gBAAgB,CAAC,KAAK,WAAW,GAAG,EAAE,CAAC;IACvD,EACF,GACD,EAAE;GACP;EACF"}
1
+ {"version":3,"file":"lpc.js","names":[],"sources":["../../src/presets/lpc.ts"],"sourcesContent":["import { Animation, Direction } from \"@rpgjs/common\";\n\nexport const LPCSpritesheetPreset = (options: {\n id: string;\n imageSource: string;\n width: number;\n height: number;\n ratio?: number;\n }) => {\n const ratio = options.ratio ?? 1;\n\n const frameY = (direction: Direction) => {\n return {\n [Direction.Down]: 2,\n [Direction.Left]: 1,\n [Direction.Right]: 3,\n [Direction.Up]: 0,\n }[direction];\n };\n \n const stand = (direction: Direction) => [\n { time: 0, frameX: 0, frameY: frameY(direction) },\n ];\n const anim = (\n direction: Direction,\n framesWidth: number,\n speed: number = 5\n ) => {\n const array: any = [];\n for (let i = 0; i < framesWidth; i++) {\n array.push({ time: i * speed, frameX: i, frameY: frameY(direction) });\n }\n return array;\n };\n \n return {\n id: options.id,\n image: options.imageSource,\n width: options.width,\n height: options.height,\n opacity: 1,\n rectWidth: 64 * ratio,\n rectHeight: 64 * ratio,\n framesWidth: 6,\n framesHeight: 4,\n spriteRealSize: {\n width: 48 * ratio,\n height: 52 * ratio,\n },\n textures: {\n [Animation.Stand]: {\n offset: {\n x: 0,\n y: 512 * ratio,\n },\n animations: ({ direction }) => [stand(direction)],\n },\n [Animation.Walk]: {\n offset: {\n x: 0,\n y: 512 * ratio,\n },\n framesWidth: 9,\n framesHeight: 4,\n animations: ({ direction }) => [anim(direction, 9)],\n },\n [Animation.Attack]: {\n offset: {\n x: 0,\n y: 768 * ratio,\n },\n framesWidth: 6,\n framesHeight: 4,\n animations: ({ direction }) => [anim(direction, 6, 3)],\n },\n [Animation.Skill]: {\n framesWidth: 7,\n framesHeight: 4,\n animations: ({ direction }) => [anim(direction, 7, 3)],\n },\n attack2: {\n offset: {\n x: 0,\n y: 256 * ratio,\n },\n framesWidth: 7,\n framesHeight: 8,\n animations: ({ direction }) => [anim(direction, 7, 3)],\n },\n ...(options.height > 3000\n ? {\n attack3: {\n offset: {\n x: 0,\n y: 5568 - 288 * 4,\n },\n rectWidth: 288,\n rectHeight: 288,\n framesWidth: 6,\n framesHeight: 4,\n animations: ({ direction }) => [anim(direction, 6, 3)],\n },\n }\n : {}),\n },\n };\n };\n "],"mappings":";;AAEA,IAAa,wBAAwB,YAM7B;CACJ,MAAM,QAAQ,QAAQ,SAAS;CAE/B,MAAM,UAAU,cAAyB;EACvC,OAAO;IACJ,UAAU,OAAO;IACjB,UAAU,OAAO;IACjB,UAAU,QAAQ;IAClB,UAAU,KAAK;EAClB,EAAE;CACJ;CAEA,MAAM,SAAS,cAAyB,CACtC;EAAE,MAAM;EAAG,QAAQ;EAAG,QAAQ,OAAO,SAAS;CAAE,CAClD;CACA,MAAM,QACJ,WACA,aACA,QAAgB,MACb;EACH,MAAM,QAAa,CAAC;EACpB,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,KAC/B,MAAM,KAAK;GAAE,MAAM,IAAI;GAAO,QAAQ;GAAG,QAAQ,OAAO,SAAS;EAAE,CAAC;EAEtE,OAAO;CACT;CAEA,OAAO;EACL,IAAI,QAAQ;EACZ,OAAO,QAAQ;EACf,OAAO,QAAQ;EACf,QAAQ,QAAQ;EAChB,SAAS;EACT,WAAW,KAAK;EAChB,YAAY,KAAK;EACjB,aAAa;EACb,cAAc;EACd,gBAAgB;GACd,OAAO,KAAK;GACZ,QAAQ,KAAK;EACf;EACA,UAAU;IACP,UAAU,QAAQ;IACjB,QAAQ;KACN,GAAG;KACH,GAAG,MAAM;IACX;IACA,aAAa,EAAE,gBAAgB,CAAC,MAAM,SAAS,CAAC;GAClD;IACC,UAAU,OAAO;IAChB,QAAQ;KACN,GAAG;KACH,GAAG,MAAM;IACX;IACA,aAAa;IACb,cAAc;IACd,aAAa,EAAE,gBAAgB,CAAC,KAAK,WAAW,CAAC,CAAC;GACpD;IACC,UAAU,SAAS;IAClB,QAAQ;KACN,GAAG;KACH,GAAG,MAAM;IACX;IACA,aAAa;IACb,cAAc;IACd,aAAa,EAAE,gBAAgB,CAAC,KAAK,WAAW,GAAG,CAAC,CAAC;GACvD;IACC,UAAU,QAAQ;IACjB,aAAa;IACb,cAAc;IACd,aAAa,EAAE,gBAAgB,CAAC,KAAK,WAAW,GAAG,CAAC,CAAC;GACvD;GACA,SAAS;IACP,QAAQ;KACN,GAAG;KACH,GAAG,MAAM;IACX;IACA,aAAa;IACb,cAAc;IACd,aAAa,EAAE,gBAAgB,CAAC,KAAK,WAAW,GAAG,CAAC,CAAC;GACvD;GACA,GAAI,QAAQ,SAAS,MACjB,EACE,SAAS;IACP,QAAQ;KACN,GAAG;KACH,GAAG,OAAO,MAAM;IAClB;IACA,WAAW;IACX,YAAY;IACZ,aAAa;IACb,cAAc;IACd,aAAa,EAAE,gBAAgB,CAAC,KAAK,WAAW,GAAG,CAAC,CAAC;GACvD,EACF,IACA,CAAC;EACP;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"rmspritesheet.js","names":[],"sources":["../../src/presets/rmspritesheet.ts"],"sourcesContent":["import { Direction, Animation } from '@rpgjs/common'\n\nexport const RMSpritesheet = (framesWidth: number, framesHeight: number, frameStand: number = 1) => {\n\n if (framesWidth <= frameStand) {\n frameStand = framesWidth - 1\n }\n\n const frameY = direction => {\n const gap = Math.max(4 - framesHeight, 0)\n return {\n [Direction.Down]: 0,\n [Direction.Left]: Math.max(0, 1 - gap),\n [Direction.Right]: Math.max(0, 2 - gap),\n [Direction.Up]: Math.max(0, 3 - gap)\n }[direction]\n }\n\n const stand = (direction: number) => [{ time: 0, frameX: frameStand, frameY: frameY(direction) }]\n const walk = direction => {\n const array: any = []\n const durationFrame = 10\n for (let i = 0; i < framesWidth; i++) {\n array.push({ time: i * durationFrame, frameX: i, frameY: frameY(direction) })\n }\n array.push({ time: array[array.length - 1].time + durationFrame })\n return array\n }\n\n return {\n textures: {\n [Animation.Stand]: {\n animations: ({direction}) => [stand(direction)]\n },\n [Animation.Walk]: {\n animations: ({direction}) => [walk(direction)]\n }\n },\n framesHeight,\n framesWidth\n }\n}"],"mappings":";;AAEA,IAAa,iBAAiB,aAAqB,cAAsB,aAAqB,MAAM;CAEhG,IAAI,eAAe,YACf,aAAa,cAAc;CAG/B,MAAM,UAAS,cAAa;EACxB,MAAM,MAAM,KAAK,IAAI,IAAI,cAAc,EAAE;EACzC,OAAO;IACF,UAAU,OAAO;IACjB,UAAU,OAAO,KAAK,IAAI,GAAG,IAAI,IAAI;IACrC,UAAU,QAAQ,KAAK,IAAI,GAAG,IAAI,IAAI;IACtC,UAAU,KAAK,KAAK,IAAI,GAAG,IAAI,IAAI;GACvC,CAAC;;CAGN,MAAM,SAAS,cAAsB,CAAC;EAAE,MAAM;EAAG,QAAQ;EAAY,QAAQ,OAAO,UAAU;EAAE,CAAC;CACjG,MAAM,QAAO,cAAa;EACtB,MAAM,QAAa,EAAE;EACrB,MAAM,gBAAgB;EACtB,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,KAC7B,MAAM,KAAK;GAAE,MAAM,IAAI;GAAe,QAAQ;GAAG,QAAQ,OAAO,UAAU;GAAE,CAAC;EAEjF,MAAM,KAAK,EAAE,MAAM,MAAM,MAAM,SAAS,GAAG,OAAO,eAAe,CAAC;EAClE,OAAO;;CAGX,OAAO;EACH,UAAU;IACL,UAAU,QAAQ,EACf,aAAa,EAAC,gBAAe,CAAC,MAAM,UAAU,CAAC,EAClD;IACA,UAAU,OAAO,EACd,aAAa,EAAC,gBAAe,CAAC,KAAK,UAAU,CAAC,EACjD;GACJ;EACD;EACA;EACH"}
1
+ {"version":3,"file":"rmspritesheet.js","names":[],"sources":["../../src/presets/rmspritesheet.ts"],"sourcesContent":["import { Direction, Animation } from '@rpgjs/common'\n\nexport const RMSpritesheet = (framesWidth: number, framesHeight: number, frameStand: number = 1) => {\n\n if (framesWidth <= frameStand) {\n frameStand = framesWidth - 1\n }\n\n const frameY = direction => {\n const gap = Math.max(4 - framesHeight, 0)\n return {\n [Direction.Down]: 0,\n [Direction.Left]: Math.max(0, 1 - gap),\n [Direction.Right]: Math.max(0, 2 - gap),\n [Direction.Up]: Math.max(0, 3 - gap)\n }[direction]\n }\n\n const stand = (direction: number) => [{ time: 0, frameX: frameStand, frameY: frameY(direction) }]\n const walk = direction => {\n const array: any = []\n const durationFrame = 10\n for (let i = 0; i < framesWidth; i++) {\n array.push({ time: i * durationFrame, frameX: i, frameY: frameY(direction) })\n }\n array.push({ time: array[array.length - 1].time + durationFrame })\n return array\n }\n\n return {\n textures: {\n [Animation.Stand]: {\n animations: ({direction}) => [stand(direction)]\n },\n [Animation.Walk]: {\n animations: ({direction}) => [walk(direction)]\n }\n },\n framesHeight,\n framesWidth\n }\n}"],"mappings":";;AAEA,IAAa,iBAAiB,aAAqB,cAAsB,aAAqB,MAAM;CAEhG,IAAI,eAAe,YACf,aAAa,cAAc;CAG/B,MAAM,UAAS,cAAa;EACxB,MAAM,MAAM,KAAK,IAAI,IAAI,cAAc,CAAC;EACxC,OAAO;IACF,UAAU,OAAO;IACjB,UAAU,OAAO,KAAK,IAAI,GAAG,IAAI,GAAG;IACpC,UAAU,QAAQ,KAAK,IAAI,GAAG,IAAI,GAAG;IACrC,UAAU,KAAK,KAAK,IAAI,GAAG,IAAI,GAAG;EACvC,EAAE;CACN;CAEA,MAAM,SAAS,cAAsB,CAAC;EAAE,MAAM;EAAG,QAAQ;EAAY,QAAQ,OAAO,SAAS;CAAE,CAAC;CAChG,MAAM,QAAO,cAAa;EACtB,MAAM,QAAa,CAAC;EACpB,MAAM,gBAAgB;EACtB,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,KAC7B,MAAM,KAAK;GAAE,MAAM,IAAI;GAAe,QAAQ;GAAG,QAAQ,OAAO,SAAS;EAAE,CAAC;EAEhF,MAAM,KAAK,EAAE,MAAM,MAAM,MAAM,SAAS,GAAG,OAAO,cAAc,CAAC;EACjE,OAAO;CACX;CAEA,OAAO;EACH,UAAU;IACL,UAAU,QAAQ,EACf,aAAa,EAAC,gBAAe,CAAC,MAAM,SAAS,CAAC,EAClD;IACC,UAAU,OAAO,EACd,aAAa,EAAC,gBAAe,CAAC,KAAK,SAAS,CAAC,EACjD;EACJ;EACA;EACA;CACJ;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractSocket.js","names":[],"sources":["../../src/services/AbstractSocket.ts"],"sourcesContent":["import { Context } from \"@signe/di\";\n\nexport const WebSocketToken = \"websocket\";\n\nexport type SocketQueryValue = string | null | undefined;\nexport type SocketQuery = Record<string, SocketQueryValue>;\nexport type SocketUpdateProperties = {\n room: string;\n host?: string;\n query?: SocketQuery;\n};\n\nexport abstract class AbstractWebsocket {\n constructor(protected context: Context) {}\n\n abstract connection(listeners?: (data: any) => void): Promise<void>;\n abstract emit(event: string, data: any): void;\n abstract on(event: string, callback: (data: any) => void): void;\n abstract off(event: string, callback: (data: any) => void): void;\n abstract updateProperties(params: SocketUpdateProperties): void;\n abstract reconnect(listeners?: (data: any) => void): Promise<void>;\n}\n"],"mappings":";AAEA,IAAa,iBAAiB;AAU9B,IAAsB,oBAAtB,MAAwC;CACtC,YAAY,SAA4B;EAAlB,KAAA,UAAA"}
1
+ {"version":3,"file":"AbstractSocket.js","names":[],"sources":["../../src/services/AbstractSocket.ts"],"sourcesContent":["import { Context } from \"@signe/di\";\n\nexport const WebSocketToken = \"websocket\";\n\nexport type SocketQueryValue = string | null | undefined;\nexport type SocketQuery = Record<string, SocketQueryValue>;\nexport type SocketUpdateProperties = {\n room: string;\n host?: string;\n query?: SocketQuery;\n};\n\nexport abstract class AbstractWebsocket {\n constructor(protected context: Context) {}\n\n abstract connection(listeners?: (data: any) => void): Promise<void>;\n abstract emit(event: string, data: any): void;\n abstract on(event: string, callback: (data: any) => void): void;\n abstract off(event: string, callback: (data: any) => void): void;\n abstract updateProperties(params: SocketUpdateProperties): void;\n abstract reconnect(listeners?: (data: any) => void): Promise<void>;\n}\n"],"mappings":";AAEA,IAAa,iBAAiB;AAU9B,IAAsB,oBAAtB,MAAwC;CACtC,YAAY,SAA4B;EAAlB,KAAA,UAAA;CAAmB;AAQ3C"}
@@ -1 +1 @@
1
- {"version":3,"file":"keyboardControls.js","names":[],"sources":["../../src/services/keyboardControls.ts"],"sourcesContent":["import { KeyboardControls } from \"canvasengine\";\n\nexport enum Control {\n Action = 'action',\n Attack = 'attack',\n Defense = 'defense',\n Skill = 'skill',\n Back = 'back',\n Up = 1,\n Down = 3,\n Right = 2,\n Left = 4\n}\n\nexport function provideKeyboardControls() {\n return {\n provide: 'KeyboardControls',\n useValue: null,\n };\n}"],"mappings":";AAEA,IAAY,UAAL,yBAAA,SAAA;CACL,QAAA,YAAS;CACT,QAAA,YAAS;CACT,QAAA,aAAU;CACV,QAAA,WAAQ;CACR,QAAA,UAAO;CACP,QAAA,QAAA,QAAK,KAAA;CACL,QAAA,QAAA,UAAO,KAAA;CACP,QAAA,QAAA,WAAQ,KAAA;CACR,QAAA,QAAA,UAAO,KAAA;;KACR;AAED,SAAgB,0BAA0B;CACxC,OAAO;EACL,SAAS;EACT,UAAU;EACX"}
1
+ {"version":3,"file":"keyboardControls.js","names":[],"sources":["../../src/services/keyboardControls.ts"],"sourcesContent":["import { KeyboardControls } from \"canvasengine\";\n\nexport enum Control {\n Action = 'action',\n Attack = 'attack',\n Defense = 'defense',\n Skill = 'skill',\n Back = 'back',\n Up = 1,\n Down = 3,\n Right = 2,\n Left = 4\n}\n\nexport function provideKeyboardControls() {\n return {\n provide: 'KeyboardControls',\n useValue: null,\n };\n}"],"mappings":";AAEA,IAAY,UAAL,yBAAA,SAAA;CACL,QAAA,YAAA;CACA,QAAA,YAAA;CACA,QAAA,aAAA;CACA,QAAA,WAAA;CACA,QAAA,UAAA;CACA,QAAA,QAAA,QAAA,KAAA;CACA,QAAA,QAAA,UAAA,KAAA;CACA,QAAA,QAAA,WAAA,KAAA;CACA,QAAA,QAAA,UAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AAEA,SAAgB,0BAA0B;CACxC,OAAO;EACL,SAAS;EACT,UAAU;CACZ;AACF"}
@@ -17,6 +17,12 @@ type MapData = {
17
17
  height?: number;
18
18
  /** Optional map events data (NPCs, interactive objects, etc.) */
19
19
  events?: any;
20
+ /** Optional named positions, for example Tiled point objects used by changeMap("map", "name") */
21
+ positions?: Record<string, {
22
+ x: number;
23
+ y: number;
24
+ z?: number;
25
+ }>;
20
26
  /** Optional map identifier, defaults to the mapId parameter if not provided */
21
27
  id?: string;
22
28
  };
@@ -1,4 +1,4 @@
1
- import { inject } from "../node_modules/.pnpm/@signe_di@2.10.0/node_modules/@signe/di/dist/index.js";
1
+ import { inject } from "../node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js";
2
2
  import { UpdateMapToken } from "@rpgjs/common";
3
3
  //#region src/services/loadMap.ts
4
4
  var LoadMapToken = "LoadMapToken";
@@ -1 +1 @@
1
- {"version":3,"file":"loadMap.js","names":[],"sources":["../../src/services/loadMap.ts"],"sourcesContent":["import { Context, inject } from \"@signe/di\";\nimport { UpdateMapToken, UpdateMapService } 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 map identifier, defaults to the mapId parameter if not provided */\n id?: string;\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;AAkC5B,IAAa,iBAAb,MAA4B;CAG1B,YAAY,SAA0B,SAAiC;EAAnD,KAAA,UAAA;EAA0B,KAAA,UAAA;EAC5C,IAAI,QAAQ,YAAY,UACtB;EAEF,KAAK,mBAAmB,OAAO,SAAS,eAAe;;CAGzD,MAAM,KAAK,OAAe;EACxB,MAAM,MAAM,MAAM,KAAK,QAAQ,MAAM,QAAQ,QAAQ,GAAG,CAAC;EACzD,MAAM,KAAK,iBAAiB,OAAO,IAAI;EACvC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FX,SAAgB,eAAe,SAAyB;CACtD,OAAO,CACL;EACE,SAAS;EACT,aAAa,YAAqB;GAChC,IAAI,QAAQ,YAAY,UACtB,QAAQ,KAAK,mCAAmC;;EAIrD,EACD;EACE,SAAS;EACT,aAAa,YAAqB,IAAI,eAAe,SAAS,QAAQ;EACvE,CACF"}
1
+ {"version":3,"file":"loadMap.js","names":[],"sources":["../../src/services/loadMap.ts"],"sourcesContent":["import { Context, inject } from \"@signe/di\";\nimport { UpdateMapToken, UpdateMapService } 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}\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;AAoC5B,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"}
@@ -3,7 +3,7 @@ import { provideSaveClient } from "./save.js";
3
3
  import { RpgGui } from "../Gui/Gui.js";
4
4
  import { RpgClientEngine } from "../RpgClientEngine.js";
5
5
  import { provideKeyboardControls } from "./keyboardControls.js";
6
- import { connectionRoom } from "../node_modules/.pnpm/@signe_sync@2.10.0/node_modules/@signe/sync/dist/client/index.js";
6
+ import { connectionRoom } from "../node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/client/index.js";
7
7
  import { UpdateMapService, UpdateMapToken } from "@rpgjs/common";
8
8
  //#region src/services/mmorpg.ts
9
9
  var BridgeWebsocket = class extends AbstractWebsocket {
@@ -34,7 +34,8 @@ var BridgeWebsocket = class extends AbstractWebsocket {
34
34
  this.socket = await connectionRoom({
35
35
  host,
36
36
  room: this.targetRoom,
37
- id: this.privateId
37
+ id: this.privateId,
38
+ query: { id: this.privateId }
38
39
  }, instance);
39
40
  listeners?.(this.socket);
40
41
  this.pendingOn.forEach(({ event, callback }) => this.socket.on(event, callback));
@@ -64,7 +65,10 @@ var BridgeWebsocket = class extends AbstractWebsocket {
64
65
  room,
65
66
  id: this.privateId,
66
67
  host: host || this.options.host || window.location.host,
67
- query
68
+ query: {
69
+ ...query,
70
+ id: this.privateId
71
+ }
68
72
  });
69
73
  }
70
74
  waitForNextOpen(conn, timeoutMs = 1e4) {
@@ -1 +1 @@
1
- {"version":3,"file":"mmorpg.js","names":[],"sources":["../../src/services/mmorpg.ts"],"sourcesContent":["import { Context } from \"@signe/di\";\nimport { connectionRoom } from \"@signe/sync/client\";\nimport { RpgGui } from \"../Gui/Gui\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport { AbstractWebsocket, SocketUpdateProperties, WebSocketToken } from \"./AbstractSocket\";\nimport { UpdateMapService, UpdateMapToken } from \"@rpgjs/common\";\nimport { provideKeyboardControls } from \"./keyboardControls\";\nimport { provideSaveClient } from \"./save\";\n\ninterface MmorpgOptions {\n host?: string;\n connectionId?: string;\n connectionIdScope?: \"local\" | \"session\" | \"ephemeral\";\n}\n\nclass BridgeWebsocket extends AbstractWebsocket {\n private socket: any;\n private privateId: string;\n private pendingOn: Array<{ event: string; callback: (data: any) => void }> = [];\n private targetRoom = \"lobby-1\";\n\n constructor(protected context: Context, private options: MmorpgOptions = {}) {\n super(context);\n this.privateId = this.resolveConnectionId();\n }\n\n private resolveConnectionId(): string {\n if (this.options.connectionId) {\n return this.options.connectionId;\n }\n\n const scope = this.options.connectionIdScope ?? \"local\";\n const key = \"rpgjs-user-id\";\n\n if (scope === \"ephemeral\") {\n return crypto.randomUUID();\n }\n\n const storage =\n scope === \"session\"\n ? window.sessionStorage\n : window.localStorage;\n\n const existing = storage.getItem(key);\n if (existing) {\n return existing;\n }\n\n const id = crypto.randomUUID();\n storage.setItem(key, id);\n return id;\n }\n\n async connection(listeners?: (data: any) => void) {\n // tmp\n class Room {\n \n }\n const instance = new Room()\n const host = this.options.host || window.location.host;\n this.socket = await connectionRoom({\n host,\n room: this.targetRoom,\n id: this.privateId\n }, instance)\n\n listeners?.(this.socket)\n this.pendingOn.forEach(({ event, callback }) => this.socket.on(event, callback));\n this.pendingOn = [];\n }\n\n on(key: string, callback: (data: any) => void) {\n if (!this.socket) {\n this.pendingOn.push({ event: key, callback });\n return;\n }\n this.socket.on(key, callback);\n }\n\n off(event: string, callback: (data: any) => void) {\n if (!this.socket) return;\n this.socket.off(event, callback);\n }\n\n emit(event: string, data: any) {\n this.socket.emit(event, data);\n }\n\n updateProperties({ room, host, query }: SocketUpdateProperties) {\n if (!this.socket?.conn) return;\n this.targetRoom = room;\n this.socket.conn.updateProperties({\n room,\n id: this.privateId,\n host: host || this.options.host || window.location.host,\n query,\n })\n }\n\n private waitForNextOpen(conn: any, timeoutMs = 10000): Promise<void> {\n return new Promise((resolve, reject) => {\n let timeoutId: number | undefined;\n const onOpen = () => {\n cleanup();\n resolve();\n };\n const onError = () => {\n cleanup();\n reject(new Error(\"WebSocket reconnect failed\"));\n };\n const cleanup = () => {\n conn.removeEventListener(\"open\", onOpen);\n conn.removeEventListener(\"error\", onError);\n if (timeoutId !== undefined) {\n window.clearTimeout(timeoutId);\n }\n };\n\n conn.addEventListener(\"open\", onOpen);\n conn.addEventListener(\"error\", onError);\n timeoutId = window.setTimeout(() => {\n cleanup();\n reject(new Error(\"WebSocket reconnect timeout\"));\n }, timeoutMs);\n });\n }\n\n async reconnect(_listeners?: (data: any) => void): Promise<void> {\n if (!this.socket?.conn) return;\n const conn = this.socket.conn;\n const opened = this.waitForNextOpen(conn);\n conn.reconnect();\n await opened;\n }\n\n getCurrentRoom(): string {\n return this.targetRoom || this.socket?.conn?.room || \"lobby-1\";\n }\n}\n\nclass UpdateMapStandaloneService extends UpdateMapService {\n constructor(protected context: Context, private _options: MmorpgOptions) {\n super(context);\n }\n\n async update(_map: any) {\n // In MMORPG mode, clients are untrusted and must not push map definitions.\n // Map bootstrap/update is handled server-side by @rpgjs/vite.\n return;\n }\n}\n\nexport function provideMmorpg(options: MmorpgOptions) {\n return [\n {\n provide: WebSocketToken,\n useFactory: (context: Context) => new BridgeWebsocket(context, options),\n },\n {\n provide: UpdateMapToken,\n useFactory: (context: Context) => new UpdateMapStandaloneService(context, options),\n },\n provideKeyboardControls(),\n provideSaveClient(),\n RpgGui,\n RpgClientEngine,\n ];\n}\n"],"mappings":";;;;;;;;AAeA,IAAM,kBAAN,cAA8B,kBAAkB;CAM9C,YAAY,SAA4B,UAAiC,EAAE,EAAE;EAC3E,MAAM,QAAQ;EADM,KAAA,UAAA;EAA0B,KAAA,UAAA;mBAH6B,EAAE;oBAC1D;EAInB,KAAK,YAAY,KAAK,qBAAqB;;CAG7C,sBAAsC;EACpC,IAAI,KAAK,QAAQ,cACf,OAAO,KAAK,QAAQ;EAGtB,MAAM,QAAQ,KAAK,QAAQ,qBAAqB;EAChD,MAAM,MAAM;EAEZ,IAAI,UAAU,aACZ,OAAO,OAAO,YAAY;EAG5B,MAAM,UACJ,UAAU,YACN,OAAO,iBACP,OAAO;EAEb,MAAM,WAAW,QAAQ,QAAQ,IAAI;EACrC,IAAI,UACF,OAAO;EAGT,MA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AAQ;IAC1C,IAAI,cAAc,KAAA,GAChB,OAAO,aAAa,UAAU;;GAIlC,KAAK,iBAAiB,QAAQ,OAAO;GACrC,KAAK,iBAAiB,SAAS,QAAQ;GACvC,YAAY,OAAO,iBAAiB;IAClC,SAAS;IACT,uBAAO,IAAI,MAAM,8BAA8B,CAAC;MAC/C,UAAU;IACb;;CAGJ,MAAM,UAAU,YAAiD;EAC/D,IAAI,CAAC,KAAK,QAAQ,MAAM;EACxB,MAAM,OAAO,KAAK,OAAO;EACzB,MAAM,SAAS,KAAK,gBAAgB,KAAK;EACzC,KAAK,WAAW;EAChB,MAAM;;CAGR,iBAAyB;EACvB,OAAO,KAAK,cAAc,KAAK,QAAQ,MAAM,QAAQ;;;AAIzD,IAAM,6BAAN,cAAyC,iBAAiB;CACxD,YAAY,SAA4B,UAAiC;EACvE,MAAM,QAAQ;EADM,KAAA,UAAA;EAA0B,KAAA,WAAA;;CAIhD,MAAM,OAAO,MAAW;;AAO1B,SAAgB,cAAc,SAAwB;CACpD,OAAO;EACL;GACE,SAAS;GACT,aAAa,YAAqB,IAAI,gBAAgB,SAAS,QAAQ;GACxE;EACD;GACE,SAAS;GACT,aAAa,YAAqB,IAAI,2BAA2B,SAAS,QAAQ;GACnF;EACD,yBAAyB;EACzB,mBAAmB;EACnB;EACA;EACD"}
1
+ {"version":3,"file":"mmorpg.js","names":[],"sources":["../../src/services/mmorpg.ts"],"sourcesContent":["import { Context } from \"@signe/di\";\nimport { connectionRoom } from \"@signe/sync/client\";\nimport { RpgGui } from \"../Gui/Gui\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport { AbstractWebsocket, SocketUpdateProperties, WebSocketToken } from \"./AbstractSocket\";\nimport { UpdateMapService, UpdateMapToken } from \"@rpgjs/common\";\nimport { provideKeyboardControls } from \"./keyboardControls\";\nimport { provideSaveClient } from \"./save\";\n\ninterface MmorpgOptions {\n host?: string;\n connectionId?: string;\n connectionIdScope?: \"local\" | \"session\" | \"ephemeral\";\n}\n\nclass BridgeWebsocket extends AbstractWebsocket {\n private socket: any;\n private privateId: string;\n private pendingOn: Array<{ event: string; callback: (data: any) => void }> = [];\n private targetRoom = \"lobby-1\";\n\n constructor(protected context: Context, private options: MmorpgOptions = {}) {\n super(context);\n this.privateId = this.resolveConnectionId();\n }\n\n private resolveConnectionId(): string {\n if (this.options.connectionId) {\n return this.options.connectionId;\n }\n\n const scope = this.options.connectionIdScope ?? \"local\";\n const key = \"rpgjs-user-id\";\n\n if (scope === \"ephemeral\") {\n return crypto.randomUUID();\n }\n\n const storage =\n scope === \"session\"\n ? window.sessionStorage\n : window.localStorage;\n\n const existing = storage.getItem(key);\n if (existing) {\n return existing;\n }\n\n const id = crypto.randomUUID();\n storage.setItem(key, id);\n return id;\n }\n\n async connection(listeners?: (data: any) => void) {\n // tmp\n class Room {\n \n }\n const instance = new Room()\n const host = this.options.host || window.location.host;\n this.socket = await connectionRoom({\n host,\n room: this.targetRoom,\n id: this.privateId,\n query: {\n id: this.privateId,\n },\n }, instance)\n\n listeners?.(this.socket)\n this.pendingOn.forEach(({ event, callback }) => this.socket.on(event, callback));\n this.pendingOn = [];\n }\n\n on(key: string, callback: (data: any) => void) {\n if (!this.socket) {\n this.pendingOn.push({ event: key, callback });\n return;\n }\n this.socket.on(key, callback);\n }\n\n off(event: string, callback: (data: any) => void) {\n if (!this.socket) return;\n this.socket.off(event, callback);\n }\n\n emit(event: string, data: any) {\n this.socket.emit(event, data);\n }\n\n updateProperties({ room, host, query }: SocketUpdateProperties) {\n if (!this.socket?.conn) return;\n this.targetRoom = room;\n this.socket.conn.updateProperties({\n room,\n id: this.privateId,\n host: host || this.options.host || window.location.host,\n query: {\n ...query,\n id: this.privateId,\n },\n })\n }\n\n private waitForNextOpen(conn: any, timeoutMs = 10000): Promise<void> {\n return new Promise((resolve, reject) => {\n let timeoutId: number | undefined;\n const onOpen = () => {\n cleanup();\n resolve();\n };\n const onError = () => {\n cleanup();\n reject(new Error(\"WebSocket reconnect failed\"));\n };\n const cleanup = () => {\n conn.removeEventListener(\"open\", onOpen);\n conn.removeEventListener(\"error\", onError);\n if (timeoutId !== undefined) {\n window.clearTimeout(timeoutId);\n }\n };\n\n conn.addEventListener(\"open\", onOpen);\n conn.addEventListener(\"error\", onError);\n timeoutId = window.setTimeout(() => {\n cleanup();\n reject(new Error(\"WebSocket reconnect timeout\"));\n }, timeoutMs);\n });\n }\n\n async reconnect(_listeners?: (data: any) => void): Promise<void> {\n if (!this.socket?.conn) return;\n const conn = this.socket.conn;\n const opened = this.waitForNextOpen(conn);\n conn.reconnect();\n await opened;\n }\n\n getCurrentRoom(): string {\n return this.targetRoom || this.socket?.conn?.room || \"lobby-1\";\n }\n}\n\nclass UpdateMapStandaloneService extends UpdateMapService {\n constructor(protected context: Context, private _options: MmorpgOptions) {\n super(context);\n }\n\n async update(_map: any) {\n // In MMORPG mode, clients are untrusted and must not push map definitions.\n // Map bootstrap/update is handled server-side by @rpgjs/vite.\n return;\n }\n}\n\nexport function provideMmorpg(options: MmorpgOptions) {\n return [\n {\n provide: WebSocketToken,\n useFactory: (context: Context) => new BridgeWebsocket(context, options),\n },\n {\n provide: UpdateMapToken,\n useFactory: (context: Context) => new UpdateMapStandaloneService(context, options),\n },\n provideKeyboardControls(),\n provideSaveClient(),\n RpgGui,\n RpgClientEngine,\n ];\n}\n"],"mappings":";;;;;;;;AAeA,IAAM,kBAAN,cAA8B,kBAAkB;CAM9C,YAAY,SAA4B,UAAiC,CAAC,GAAG;EAC3E,MAAM,OAAO;EADO,KAAA,UAAA;EAA0B,KAAA,UAAA;mBAH6B,CAAC;oBACzD;EAInB,KAAK,YAAY,KAAK,oBAAoB;CAC5C;CAEA,sBAAsC;EACpC,IAAI,KAAK,QAAQ,cACf,OAAO,KAAK,QAAQ;EAGtB,MAAM,QAAQ,KAAK,QAAQ,qBAAqB;EAChD,MAAM,MAAM;EAEZ,IAAI,UAAU,aACZ,OAAO,OAAO,WAAW;EAG3B,MAAM,UACJ,UAAU,YAC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ACJ,MAAM,eAAe;IACnB,QAAQ;IACR,QAAQ;GACV;GACA,MAAM,gBAAgB;IACpB,QAAQ;IACR,uBAAO,IAAI,MAAM,4BAA4B,CAAC;GAChD;GACA,MAAM,gBAAgB;IACpB,KAAK,oBAAoB,QAAQ,MAAM;IACvC,KAAK,oBAAoB,SAAS,OAAO;IACzC,IAAI,cAAc,KAAA,GAChB,OAAO,aAAa,SAAS;GAEjC;GAEA,KAAK,iBAAiB,QAAQ,MAAM;GACpC,KAAK,iBAAiB,SAAS,OAAO;GACtC,YAAY,OAAO,iBAAiB;IAClC,QAAQ;IACR,uBAAO,IAAI,MAAM,6BAA6B,CAAC;GACjD,GAAG,SAAS;EACd,CAAC;CACH;CAEA,MAAM,UAAU,YAAiD;EAC/D,IAAI,CAAC,KAAK,QAAQ,MAAM;EACxB,MAAM,OAAO,KAAK,OAAO;EACzB,MAAM,SAAS,KAAK,gBAAgB,IAAI;EACxC,KAAK,UAAU;EACf,MAAM;CACR;CAEA,iBAAyB;EACvB,OAAO,KAAK,cAAc,KAAK,QAAQ,MAAM,QAAQ;CACvD;AACF;AAEA,IAAM,6BAAN,cAAyC,iBAAiB;CACxD,YAAY,SAA4B,UAAiC;EACvE,MAAM,OAAO;EADO,KAAA,UAAA;EAA0B,KAAA,WAAA;CAEhD;CAEA,MAAM,OAAO,MAAW,CAIxB;AACF;AAEA,SAAgB,cAAc,SAAwB;CACpD,OAAO;EACL;GACE,SAAS;GACT,aAAa,YAAqB,IAAI,gBAAgB,SAAS,OAAO;EACxE;EACA;GACE,SAAS;GACT,aAAa,YAAqB,IAAI,2BAA2B,SAAS,OAAO;EACnF;EACA,wBAAwB;EACxB,kBAAkB;EAClB;EACA;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"save.js","names":[],"sources":["../../src/services/save.ts"],"sourcesContent":["import type { SaveSlotList, SaveSlotMeta } from \"@rpgjs/common\";\nimport { inject } from \"../core/inject\";\nimport { AbstractWebsocket, WebSocketToken } from \"./AbstractSocket\";\n\nexport const SaveClientToken = \"SaveClientToken\";\n\ntype SaveListResult = {\n requestId: string;\n slots: SaveSlotList;\n};\n\ntype SaveSaveResult = {\n requestId: string;\n index: number;\n slots: SaveSlotList;\n};\n\ntype SaveLoadResult = {\n requestId: string;\n index: number;\n ok: boolean;\n slot?: SaveSlotMeta;\n};\n\ntype SaveErrorResult = {\n requestId: string;\n message: string;\n};\n\ntype PendingRequest = {\n resolve: (value: any) => void;\n reject: (error: Error) => void;\n};\n\nexport class SaveClientService {\n private webSocket: AbstractWebsocket = inject(WebSocketToken);\n private pending: Map<string, PendingRequest> = new Map();\n private requestCounter = 0;\n\n initialize() {\n const saveListResult = (data: SaveListResult) => this.resolveRequest(data.requestId, data);\n const saveSaveResult = (data: SaveSaveResult) => this.resolveRequest(data.requestId, data);\n const saveLoadResult = (data: SaveLoadResult) => this.resolveRequest(data.requestId, data);\n const saveErrorResult = (data: SaveErrorResult) => this.rejectRequest(data.requestId, data.message);\n this.webSocket.off(\"save.list.result\", saveListResult);\n this.webSocket.off(\"save.save.result\", saveSaveResult);\n this.webSocket.off(\"save.load.result\", saveLoadResult);\n this.webSocket.off(\"save.error\", saveErrorResult);\n this.webSocket.on(\"save.list.result\", saveListResult);\n this.webSocket.on(\"save.save.result\", saveSaveResult);\n this.webSocket.on(\"save.load.result\", saveLoadResult);\n this.webSocket.on(\"save.error\", saveErrorResult);\n }\n\n listSlots(): Promise<SaveSlotList> {\n return this.request<SaveListResult>(\"save.list\", {}).then((result) => result.slots);\n }\n\n saveSlot(index: number, meta: SaveSlotMeta = {}): Promise<SaveSlotList> {\n return this.request<SaveSaveResult>(\"save.save\", { index, meta }).then((result) => result.slots);\n }\n\n loadSlot(index: number): Promise<boolean> {\n return this.request<SaveLoadResult>(\"save.load\", { index }).then((result) => result.ok);\n }\n\n private request<T>(event: string, payload: Record<string, any>): Promise<T> {\n return new Promise((resolve, reject) => {\n if (!this.webSocket) {\n this.initialize();\n }\n const requestId = this.nextRequestId();\n this.pending.set(requestId, { resolve, reject });\n this.webSocket?.emit(event, { requestId, ...payload });\n });\n }\n\n private resolveRequest(requestId: string, result: any) {\n const pending = this.pending.get(requestId);\n if (!pending) return;\n this.pending.delete(requestId);\n pending.resolve(result);\n }\n\n private rejectRequest(requestId: string, message: string) {\n const pending = this.pending.get(requestId);\n if (!pending) return;\n this.pending.delete(requestId);\n pending.reject(new Error(message));\n }\n\n private nextRequestId(): string {\n this.requestCounter += 1;\n return `${Date.now()}-${this.requestCounter}`;\n }\n}\n\nexport function provideSaveClient() {\n return {\n provide: SaveClientService,\n useClass: SaveClientService,\n };\n}\n"],"mappings":";;;AAIA,IAAa,kBAAkB;AA8B/B,IAAa,oBAAb,MAA+B;;mBACU,OAAO,eAAe;iCACd,IAAI,KAAK;wBAC/B;;CAEzB,aAAa;EACX,MAAM,kBAAkB,SAAyB,KAAK,eAAe,KAAK,WAAW,KAAK;EAC1F,MAAM,kBAAkB,SAAyB,KAAK,eAAe,KAAK,WAAW,KAAK;EAC1F,MAAM,kBAAkB,SAAyB,KAAK,eAAe,KAAK,WAAW,KAAK;EAC1F,MAAM,mBAAmB,SAA0B,KAAK,cAAc,KAAK,WAAW,KAAK,QAAQ;EACnG,KAAK,UAAU,IAAI,oBAAoB,eAAe;EACtD,KAAK,UAAU,IAAI,oBAAoB,eAAe;EACtD,KAAK,UAAU,IAAI,oBAAoB,eAAe;EACtD,KAAK,UAAU,IAAI,cAAc,gBAAgB;EACjD,KAAK,UAAU,GAAG,oBAAoB,eAAe;EACrD,KAAK,UAAU,GAAG,oBAAoB,eAAe;EACrD,KAAK,UAAU,GAAG,oBAAoB,eAAe;EACrD,KAAK,UAAU,GAAG,cAAc,gBAAgB;;CAGlD,YAAmC;EACjC,OAAO,KAAK,QAAwB,aAAa,EAAE,CAAC,CAAC,MAAM,WAAW,OAAO,MAAM;;CAGrF,SAAS,OAAe,OAAqB,EAAE,EAAyB;EACtE,OAAO,KAAK,QAAwB,aAAa;GAAE;GAAO;GAAM,CAAC,CAAC,MAAM,WAAW,OAAO,MAAM;;CAGlG,SAAS,OAAiC;EACxC,OAAO,KAAK,QAAwB,aAAa,EAAE,OAAO,CAAC,CAAC,MAAM,WAAW,OAAO,GAAG;;CAGzF,QAAmB,OAAe,SAA0C;EAC1E,OAAO,IAAI,SAAS,SAAS,WAAW;GACtC,IAAI,CAAC,KAAK,WACR,KAAK,YAAY;GAEnB,MAAM,YAAY,KAAK,eAAe;GACtC,KAAK,QAAQ,IAAI,WAAW;IAAE;IAAS;IAAQ,CAAC;GAChD,KAAK,WAAW,KAAK,OAAO;IAAE;IAAW,GAAG;IAAS,CAAC;IACtD;;CAGJ,eAAuB,WAAmB,QAAa;EACrD,MAAM,UAAU,KAAK,QAAQ,IAAI,UAAU;EAC3C,IAAI,CAAC,SAAS;EACd,KAAK,QAAQ,OAAO,UAAU;EAC9B,QAAQ,QAAQ,OAAO;;CAGzB,cAAsB,WAAmB,SAAiB;EACxD,MAAM,UAAU,KAAK,QAAQ,IAAI,UAAU;EAC3C,IAAI,CAAC,SAAS;EACd,KAAK,QAAQ,OAAO,UAAU;EAC9B,QAAQ,OAAO,IAAI,MAAM,QAAQ,CAAC;;CAGpC,gBAAgC;EAC9B,KAAK,kBAAkB;EACvB,OAAO,GAAG,KAAK,KAAK,CAAC,GAAG,KAAK;;;AAIjC,SAAgB,oBAAoB;CAClC,OAAO;EACL,SAAS;EACT,UAAU;EACX"}
1
+ {"version":3,"file":"save.js","names":[],"sources":["../../src/services/save.ts"],"sourcesContent":["import type { SaveSlotList, SaveSlotMeta } from \"@rpgjs/common\";\nimport { inject } from \"../core/inject\";\nimport { AbstractWebsocket, WebSocketToken } from \"./AbstractSocket\";\n\nexport const SaveClientToken = \"SaveClientToken\";\n\ntype SaveListResult = {\n requestId: string;\n slots: SaveSlotList;\n};\n\ntype SaveSaveResult = {\n requestId: string;\n index: number;\n slots: SaveSlotList;\n};\n\ntype SaveLoadResult = {\n requestId: string;\n index: number;\n ok: boolean;\n slot?: SaveSlotMeta;\n};\n\ntype SaveErrorResult = {\n requestId: string;\n message: string;\n};\n\ntype PendingRequest = {\n resolve: (value: any) => void;\n reject: (error: Error) => void;\n};\n\nexport class SaveClientService {\n private webSocket: AbstractWebsocket = inject(WebSocketToken);\n private pending: Map<string, PendingRequest> = new Map();\n private requestCounter = 0;\n\n initialize() {\n const saveListResult = (data: SaveListResult) => this.resolveRequest(data.requestId, data);\n const saveSaveResult = (data: SaveSaveResult) => this.resolveRequest(data.requestId, data);\n const saveLoadResult = (data: SaveLoadResult) => this.resolveRequest(data.requestId, data);\n const saveErrorResult = (data: SaveErrorResult) => this.rejectRequest(data.requestId, data.message);\n this.webSocket.off(\"save.list.result\", saveListResult);\n this.webSocket.off(\"save.save.result\", saveSaveResult);\n this.webSocket.off(\"save.load.result\", saveLoadResult);\n this.webSocket.off(\"save.error\", saveErrorResult);\n this.webSocket.on(\"save.list.result\", saveListResult);\n this.webSocket.on(\"save.save.result\", saveSaveResult);\n this.webSocket.on(\"save.load.result\", saveLoadResult);\n this.webSocket.on(\"save.error\", saveErrorResult);\n }\n\n listSlots(): Promise<SaveSlotList> {\n return this.request<SaveListResult>(\"save.list\", {}).then((result) => result.slots);\n }\n\n saveSlot(index: number, meta: SaveSlotMeta = {}): Promise<SaveSlotList> {\n return this.request<SaveSaveResult>(\"save.save\", { index, meta }).then((result) => result.slots);\n }\n\n loadSlot(index: number): Promise<boolean> {\n return this.request<SaveLoadResult>(\"save.load\", { index }).then((result) => result.ok);\n }\n\n private request<T>(event: string, payload: Record<string, any>): Promise<T> {\n return new Promise((resolve, reject) => {\n if (!this.webSocket) {\n this.initialize();\n }\n const requestId = this.nextRequestId();\n this.pending.set(requestId, { resolve, reject });\n this.webSocket?.emit(event, { requestId, ...payload });\n });\n }\n\n private resolveRequest(requestId: string, result: any) {\n const pending = this.pending.get(requestId);\n if (!pending) return;\n this.pending.delete(requestId);\n pending.resolve(result);\n }\n\n private rejectRequest(requestId: string, message: string) {\n const pending = this.pending.get(requestId);\n if (!pending) return;\n this.pending.delete(requestId);\n pending.reject(new Error(message));\n }\n\n private nextRequestId(): string {\n this.requestCounter += 1;\n return `${Date.now()}-${this.requestCounter}`;\n }\n}\n\nexport function provideSaveClient() {\n return {\n provide: SaveClientService,\n useClass: SaveClientService,\n };\n}\n"],"mappings":";;;AAIA,IAAa,kBAAkB;AA8B/B,IAAa,oBAAb,MAA+B;;mBACU,OAAO,cAAc;iCACb,IAAI,IAAI;wBAC9B;;CAEzB,aAAa;EACX,MAAM,kBAAkB,SAAyB,KAAK,eAAe,KAAK,WAAW,IAAI;EACzF,MAAM,kBAAkB,SAAyB,KAAK,eAAe,KAAK,WAAW,IAAI;EACzF,MAAM,kBAAkB,SAAyB,KAAK,eAAe,KAAK,WAAW,IAAI;EACzF,MAAM,mBAAmB,SAA0B,KAAK,cAAc,KAAK,WAAW,KAAK,OAAO;EAClG,KAAK,UAAU,IAAI,oBAAoB,cAAc;EACrD,KAAK,UAAU,IAAI,oBAAoB,cAAc;EACrD,KAAK,UAAU,IAAI,oBAAoB,cAAc;EACrD,KAAK,UAAU,IAAI,cAAc,eAAe;EAChD,KAAK,UAAU,GAAG,oBAAoB,cAAc;EACpD,KAAK,UAAU,GAAG,oBAAoB,cAAc;EACpD,KAAK,UAAU,GAAG,oBAAoB,cAAc;EACpD,KAAK,UAAU,GAAG,cAAc,eAAe;CACjD;CAEA,YAAmC;EACjC,OAAO,KAAK,QAAwB,aAAa,CAAC,CAAC,EAAE,MAAM,WAAW,OAAO,KAAK;CACpF;CAEA,SAAS,OAAe,OAAqB,CAAC,GAA0B;EACtE,OAAO,KAAK,QAAwB,aAAa;GAAE;GAAO;EAAK,CAAC,EAAE,MAAM,WAAW,OAAO,KAAK;CACjG;CAEA,SAAS,OAAiC;EACxC,OAAO,KAAK,QAAwB,aAAa,EAAE,MAAM,CAAC,EAAE,MAAM,WAAW,OAAO,EAAE;CACxF;CAEA,QAAmB,OAAe,SAA0C;EAC1E,OAAO,IAAI,SAAS,SAAS,WAAW;GACtC,IAAI,CAAC,KAAK,WACR,KAAK,WAAW;GAElB,MAAM,YAAY,KAAK,cAAc;GACrC,KAAK,QAAQ,IAAI,WAAW;IAAE;IAAS;GAAO,CAAC;GAC/C,KAAK,WAAW,KAAK,OAAO;IAAE;IAAW,GAAG;GAAQ,CAAC;EACvD,CAAC;CACH;CAEA,eAAuB,WAAmB,QAAa;EACrD,MAAM,UAAU,KAAK,QAAQ,IAAI,SAAS;EAC1C,IAAI,CAAC,SAAS;EACd,KAAK,QAAQ,OAAO,SAAS;EAC7B,QAAQ,QAAQ,MAAM;CACxB;CAEA,cAAsB,WAAmB,SAAiB;EACxD,MAAM,UAAU,KAAK,QAAQ,IAAI,SAAS;EAC1C,IAAI,CAAC,SAAS;EACd,KAAK,QAAQ,OAAO,SAAS;EAC7B,QAAQ,OAAO,IAAI,MAAM,OAAO,CAAC;CACnC;CAEA,gBAAgC;EAC9B,KAAK,kBAAkB;EACvB,OAAO,GAAG,KAAK,IAAI,EAAE,GAAG,KAAK;CAC/B;AACF;AAEA,SAAgB,oBAAoB;CAClC,OAAO;EACL,SAAS;EACT,UAAU;CACZ;AACF"}
@@ -2,7 +2,7 @@ import { AbstractWebsocket, WebSocketToken } from "./AbstractSocket.js";
2
2
  import { provideSaveClient } from "./save.js";
3
3
  import { RpgGui } from "../Gui/Gui.js";
4
4
  import { RpgClientEngine } from "../RpgClientEngine.js";
5
- import { ClientIo, ServerIo } from "../node_modules/.pnpm/@signe_room@2.10.0/node_modules/@signe/room/dist/index.js";
5
+ import { ClientIo, ServerIo } from "../node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js";
6
6
  import { provideKeyboardControls } from "./keyboardControls.js";
7
7
  import { UpdateMapService, UpdateMapToken } from "@rpgjs/common";
8
8
  //#region src/services/standalone.ts
@@ -1 +1 @@
1
- {"version":3,"file":"standalone.js","names":[],"sources":["../../src/services/standalone.ts"],"sourcesContent":["import { AbstractWebsocket, SocketUpdateProperties, WebSocketToken } from \"./AbstractSocket\";\nimport { ClientIo, ServerIo } from \"@signe/room\";\nimport { Context } from \"@signe/di\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport { UpdateMapService, UpdateMapToken } from \"@rpgjs/common\";\nimport { LoadMapToken } from \"./loadMap\";\nimport { RpgGui } from \"../Gui/Gui\";\nimport { provideKeyboardControls } from \"./keyboardControls\";\nimport { provideSaveClient } from \"./save\";\n\ntype ServerIo = any;\ntype ClientIo = any;\n\ninterface StandaloneOptions {\n env?: Record<string, any>;\n}\n\nclass BridgeWebsocket extends AbstractWebsocket {\n private room: ServerIo;\n private socket: ClientIo;\n private pendingOn: Array<{ event: string; callback: (data: any) => void }> = [];\n private rooms = {\n partyFn: async (roomId: string) => {\n this.room = new ServerIo(roomId, this.rooms);\n const server = new this.server(this.room)\n await server.onStart();\n await server.subRoom.onStart()\n this.context.set('server', server)\n return server\n },\n env: {}\n }\n private serverInstance: any;\n\n constructor(protected context: Context, private server: any, options: StandaloneOptions = {}) {\n super(context);\n // fake room\n this.rooms.env = options.env || {};\n this.room = new ServerIo(\"lobby-1\", this.rooms);\n }\n\n async connection(listeners?: (data: any) => void) {\n this.serverInstance = new this.server(this.room);\n await this.serverInstance.onStart();\n await this.serverInstance.subRoom.onStart()\n this.context.set('server', this.serverInstance)\n return this._connection(listeners)\n }\n\n private async _connection(listeners?: (data: any) => void) {\n this.serverInstance = this.context.get('server')\n this.socket = new ClientIo(this.serverInstance, 'player-client-id');\n const url = new URL('http://localhost')\n const request = new Request(url.toString(), {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json'\n }\n })\n listeners?.(this.socket)\n await this.serverInstance.onConnect(this.socket.conn as any, { request } as any);\n this.room.clients.set(this.socket.id, this.socket);\n this.pendingOn.forEach(({ event, callback }) => this.socket.addEventListener(event, callback));\n this.pendingOn = [];\n return this.socket\n }\n\n on(key: string, callback: (data: any) => void) {\n const handler = (event) => {\n const object = JSON.parse(event);\n if (object.type === key) {\n callback(object.value);\n }\n };\n if (!this.socket) {\n this.pendingOn.push({ event: \"message\", callback: handler });\n return;\n }\n this.socket.addEventListener(\"message\", handler);\n }\n\n off(event: string, callback: (data: any) => void) {\n if (!this.socket) return;\n this.socket.removeEventListener(event, callback);\n }\n\n emit(event: string, data: any) {\n this.socket.send({\n action: event,\n value: data,\n });\n }\n\n /**\n * Update underlying connection properties before a reconnect\n *\n * Design\n * - Dynamically register a factory for the requested room to ensure a fresh server instance\n * - Swap the internal ServerIo to target the new room\n *\n * @param params - Properties to update\n * @param params.room - The target room id (e.g. `map-simplemap2`)\n *\n * @example\n * ```ts\n * websocket.updateProperties({ room: 'map-simplemap2' })\n * await websocket.reconnect()\n * ```\n */\n updateProperties(_params: SocketUpdateProperties) {\n // empty\n }\n\n /**\n * Reconnect the client to the current Party room\n *\n * Design\n * - Must be called after `updateProperties()` when switching rooms\n * - Rebuilds the client <-> server bridge and re-triggers connection listeners\n *\n * @param listeners - Optional callback to re-bind event handlers on the new socket\n *\n * @example\n * ```ts\n * websocket.updateProperties({ room: 'map-dungeon' })\n * await websocket.reconnect((socket) => {\n * // re-bind events here\n * })\n * ```\n */\n async reconnect(listeners?: (data: any) => void): Promise<void> {\n await this._connection((socket) => {\n listeners?.(socket)\n })\n }\n\n getServer() {\n return this.serverInstance\n }\n\n getSocket() {\n return this.socket\n }\n}\n\nclass UpdateMapStandaloneService extends UpdateMapService {\n private server: any;\n\n /**\n * Update the current room map data on the server side\n *\n * Design\n * - Uses the in-memory server instance stored in context (standalone mode)\n * - Builds a local HTTP-like request to the current Party room endpoint\n *\n * @param map - The map payload to apply on the server\n *\n * @example\n * ```ts\n * await updateMapService.update({ width: 1024, height: 768, events: [] })\n * ```\n */\n async update(map: any) {\n this.server = this.context.get('server')\n const roomId = this.server?.room?.id ?? 'lobby-1'\n const req = {\n url: `http://localhost/parties/main/${roomId}/map/update`,\n method: 'POST',\n headers: new Headers({}),\n json: async () => {\n return map;\n }\n };\n await this.server.onRequest(req)\n }\n}\n\nexport function provideRpg(server: any, options: StandaloneOptions = {}) {\n return [\n {\n provide: WebSocketToken,\n useFactory: (context: Context) => new BridgeWebsocket(context, server, options),\n },\n {\n provide: UpdateMapToken,\n useClass: UpdateMapStandaloneService,\n },\n provideKeyboardControls(),\n provideSaveClient(),\n RpgGui,\n RpgClientEngine,\n ];\n}\n"],"mappings":";;;;;;;;AAiBA,IAAM,kBAAN,cAA8B,kBAAkB;CAiB9C,YAAY,SAA4B,QAAqB,UAA6B,EAAE,EAAE;EAC5F,MAAM,QAAQ;EADM,KAAA,UAAA;EAA0B,KAAA,SAAA;mBAd6B,EAAE;eAC/D;GACd,SAAS,OAAO,WAAmB;IACjC,KAAK,OAAO,IAAI,SAAS,QAAQ,KAAK,MAAM;IAC5C,MAAM,SAAS,IAAI,KAAK,OAAO,KAAK,KAAK;IACzC,MAAM,OAAO,SAAS;IACtB,MAAM,OAAO,QAAQ,SAAS;IAC9B,KAAK,QAAQ,IAAI,UAAU,OAAO;IAClC,OAAO;;GAET,KAAK,EAAE;GACR;EAMC,KAAK,MAAM,MAAM,QAAQ,OAAO,EAAE;EAClC,KAAK,OAAO,IAAI,SAAS,WAAW,KAAK,MAAM;;CAGjD,MAAM,WAAW,WAAiC;EAChD,KAAK,iBAAiB,IAAI,KAAK,OAAO,KAAK,KAAK;EAChD,MAAM,KAAK,eAAe,SAAS;EACnC,MAAM,KAAK,eAAe,QAAQ,SAAS;EAC3C,KAAK,QAAQ,IAAI,UAAU,KAAK,eAAe;EAC/C,OAAO,KAAK,YAAY,UAAU;;CAGpC,MAAc,YAAY,WAAiC;EACzD,KAAK,iBAAiB,KAAK,QAAQ,IAAI,SAAS;EAChD,KAAK,SAAS,IAAI,SAAS,KAAK,gBAAgB,mBAAmB;EACnE,MAAM,MAAM,IAAI,IAAI,mBAAmB;EACvC,MAAM,UAAU,IAAI,QAAQ,IAAI,UAAU,EAAE;GAC1C,QAAQ;GACR,SAAS,EACP,gBAAgB,oBACjB;GACF,CAAC;E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AAM,KAAK,OAAO,UAAU,IAAI;;;AAIpC,SAAgB,WAAW,QAAa,UAA6B,EAAE,EAAE;CACvE,OAAO;EACL;GACE,SAAS;GACT,aAAa,YAAqB,IAAI,gBAAgB,SAAS,QAAQ,QAAQ;GAChF;EACD;GACE,SAAS;GACT,UAAU;GACX;EACD,yBAAyB;EACzB,mBAAmB;EACnB;EACA;EACD"}
1
+ {"version":3,"file":"standalone.js","names":[],"sources":["../../src/services/standalone.ts"],"sourcesContent":["import { AbstractWebsocket, SocketUpdateProperties, WebSocketToken } from \"./AbstractSocket\";\nimport { ClientIo, ServerIo } from \"@signe/room\";\nimport { Context } from \"@signe/di\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport { UpdateMapService, UpdateMapToken } from \"@rpgjs/common\";\nimport { LoadMapToken } from \"./loadMap\";\nimport { RpgGui } from \"../Gui/Gui\";\nimport { provideKeyboardControls } from \"./keyboardControls\";\nimport { provideSaveClient } from \"./save\";\n\ntype ServerIo = any;\ntype ClientIo = any;\n\ninterface StandaloneOptions {\n env?: Record<string, any>;\n}\n\nclass BridgeWebsocket extends AbstractWebsocket {\n private room: ServerIo;\n private socket: ClientIo;\n private pendingOn: Array<{ event: string; callback: (data: any) => void }> = [];\n private rooms = {\n partyFn: async (roomId: string) => {\n this.room = new ServerIo(roomId, this.rooms);\n const server = new this.server(this.room)\n await server.onStart();\n await server.subRoom.onStart()\n this.context.set('server', server)\n return server\n },\n env: {}\n }\n private serverInstance: any;\n\n constructor(protected context: Context, private server: any, options: StandaloneOptions = {}) {\n super(context);\n // fake room\n this.rooms.env = options.env || {};\n this.room = new ServerIo(\"lobby-1\", this.rooms);\n }\n\n async connection(listeners?: (data: any) => void) {\n this.serverInstance = new this.server(this.room);\n await this.serverInstance.onStart();\n await this.serverInstance.subRoom.onStart()\n this.context.set('server', this.serverInstance)\n return this._connection(listeners)\n }\n\n private async _connection(listeners?: (data: any) => void) {\n this.serverInstance = this.context.get('server')\n this.socket = new ClientIo(this.serverInstance, 'player-client-id');\n const url = new URL('http://localhost')\n const request = new Request(url.toString(), {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json'\n }\n })\n listeners?.(this.socket)\n await this.serverInstance.onConnect(this.socket.conn as any, { request } as any);\n this.room.clients.set(this.socket.id, this.socket);\n this.pendingOn.forEach(({ event, callback }) => this.socket.addEventListener(event, callback));\n this.pendingOn = [];\n return this.socket\n }\n\n on(key: string, callback: (data: any) => void) {\n const handler = (event) => {\n const object = JSON.parse(event);\n if (object.type === key) {\n callback(object.value);\n }\n };\n if (!this.socket) {\n this.pendingOn.push({ event: \"message\", callback: handler });\n return;\n }\n this.socket.addEventListener(\"message\", handler);\n }\n\n off(event: string, callback: (data: any) => void) {\n if (!this.socket) return;\n this.socket.removeEventListener(event, callback);\n }\n\n emit(event: string, data: any) {\n this.socket.send({\n action: event,\n value: data,\n });\n }\n\n /**\n * Update underlying connection properties before a reconnect\n *\n * Design\n * - Dynamically register a factory for the requested room to ensure a fresh server instance\n * - Swap the internal ServerIo to target the new room\n *\n * @param params - Properties to update\n * @param params.room - The target room id (e.g. `map-simplemap2`)\n *\n * @example\n * ```ts\n * websocket.updateProperties({ room: 'map-simplemap2' })\n * await websocket.reconnect()\n * ```\n */\n updateProperties(_params: SocketUpdateProperties) {\n // empty\n }\n\n /**\n * Reconnect the client to the current Party room\n *\n * Design\n * - Must be called after `updateProperties()` when switching rooms\n * - Rebuilds the client <-> server bridge and re-triggers connection listeners\n *\n * @param listeners - Optional callback to re-bind event handlers on the new socket\n *\n * @example\n * ```ts\n * websocket.updateProperties({ room: 'map-dungeon' })\n * await websocket.reconnect((socket) => {\n * // re-bind events here\n * })\n * ```\n */\n async reconnect(listeners?: (data: any) => void): Promise<void> {\n await this._connection((socket) => {\n listeners?.(socket)\n })\n }\n\n getServer() {\n return this.serverInstance\n }\n\n getSocket() {\n return this.socket\n }\n}\n\nclass UpdateMapStandaloneService extends UpdateMapService {\n private server: any;\n\n /**\n * Update the current room map data on the server side\n *\n * Design\n * - Uses the in-memory server instance stored in context (standalone mode)\n * - Builds a local HTTP-like request to the current Party room endpoint\n *\n * @param map - The map payload to apply on the server\n *\n * @example\n * ```ts\n * await updateMapService.update({ width: 1024, height: 768, events: [] })\n * ```\n */\n async update(map: any) {\n this.server = this.context.get('server')\n const roomId = this.server?.room?.id ?? 'lobby-1'\n const req = {\n url: `http://localhost/parties/main/${roomId}/map/update`,\n method: 'POST',\n headers: new Headers({}),\n json: async () => {\n return map;\n }\n };\n await this.server.onRequest(req)\n }\n}\n\nexport function provideRpg(server: any, options: StandaloneOptions = {}) {\n return [\n {\n provide: WebSocketToken,\n useFactory: (context: Context) => new BridgeWebsocket(context, server, options),\n },\n {\n provide: UpdateMapToken,\n useClass: UpdateMapStandaloneService,\n },\n provideKeyboardControls(),\n provideSaveClient(),\n RpgGui,\n RpgClientEngine,\n ];\n}\n"],"mappings":";;;;;;;;AAiBA,IAAM,kBAAN,cAA8B,kBAAkB;CAiB9C,YAAY,SAA4B,QAAqB,UAA6B,CAAC,GAAG;EAC5F,MAAM,OAAO;EADO,KAAA,UAAA;EAA0B,KAAA,SAAA;mBAd6B,CAAC;eAC9D;GACd,SAAS,OAAO,WAAmB;IACjC,KAAK,OAAO,IAAI,SAAS,QAAQ,KAAK,KAAK;IAC3C,MAAM,SAAS,IAAI,KAAK,OAAO,KAAK,IAAI;IACxC,MAAM,OAAO,QAAQ;IACrB,MAAM,OAAO,QAAQ,QAAQ;IAC7B,KAAK,QAAQ,IAAI,UAAU,MAAM;IACjC,OAAO;GACT;GACA,KAAK,CAAC;EACR;EAME,KAAK,MAAM,MAAM,QAAQ,OAAO,CAAC;EACjC,KAAK,OAAO,IAAI,SAAS,WAAW,KAAK,KAAK;CAChD;CAEA,MAAM,WAAW,WAAiC;EAChD,KAAK,iBAAiB,IAAI,KAAK,OAAO,KAAK,IAAI;EAC/C,MAAM,KAAK,eAAe,QAAQ;EAClC,MAAM,KAAK,eAAe,QAAQ,QAAQ;EAC1C,KA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;GACjC,YAAY,MAAM;EACpB,CAAC;CACH;CAEA,YAAY;EACV,OAAO,KAAK;CACd;CAEA,YAAY;EACV,OAAO,KAAK;CACd;AACF;AAEA,IAAM,6BAAN,cAAyC,iBAAiB;;;;;;;;;;;;;;;CAiBxD,MAAM,OAAO,KAAU;EACrB,KAAK,SAAS,KAAK,QAAQ,IAAI,QAAQ;EAEvC,MAAM,MAAM;GACV,KAAK,iCAFQ,KAAK,QAAQ,MAAM,MAAM,UAEO;GAC7C,QAAQ;GACR,SAAS,IAAI,QAAQ,CAAC,CAAC;GACvB,MAAM,YAAY;IAChB,OAAO;GACT;EACF;EACA,MAAM,KAAK,OAAO,UAAU,GAAG;CACjC;AACF;AAEA,SAAgB,WAAW,QAAa,UAA6B,CAAC,GAAG;CACvE,OAAO;EACL;GACE,SAAS;GACT,aAAa,YAAqB,IAAI,gBAAgB,SAAS,QAAQ,OAAO;EAChF;EACA;GACE,SAAS;GACT,UAAU;EACZ;EACA,wBAAwB;EACxB,kBAAkB;EAClB;EACA;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"getEntityProp.js","names":[],"sources":["../../src/utils/getEntityProp.ts"],"sourcesContent":["import { computed, Signal } from \"canvasengine\";\nimport { RpgClientObject } from \"../Game/Object\";\n\nconst BUILTIN_PARAM_KEYS = [\n \"maxHp\",\n \"maxSp\",\n \"atk\",\n \"pdef\",\n \"sdef\",\n \"str\",\n \"agi\",\n \"int\",\n \"dex\",\n] as const;\n\ntype BuiltInParamKey = typeof BUILTIN_PARAM_KEYS[number];\ntype ParamPropKey = `params.${BuiltInParamKey}` | `params.${string}`;\n\nconst entityPropMap = {\n level: (entity: RpgClientObject) => entity._level(),\n exp: (entity: RpgClientObject) => entity._exp(),\n gold: (entity: RpgClientObject) => entity._gold(),\n hp: (entity: RpgClientObject) => entity.hpSignal(),\n sp: (entity: RpgClientObject) => entity.spSignal(),\n name: (entity: RpgClientObject) => entity.name(),\n type: (entity: RpgClientObject) => entity.type(),\n x: (entity: RpgClientObject) => entity.x(),\n y: (entity: RpgClientObject) => entity.y(),\n z: (entity: RpgClientObject) => entity.z(),\n tint: (entity: RpgClientObject) => entity.tint(),\n direction: (entity: RpgClientObject) => entity.direction(),\n speed: (entity: RpgClientObject) => entity.speed(),\n hitbox: (entity: RpgClientObject) => entity.hitbox(),\n animation: (entity: RpgClientObject) => entity.animationName(),\n canMove: (entity: RpgClientObject) => entity.canMove(),\n graphics: (entity: RpgClientObject) => entity.graphics(),\n items: (entity: RpgClientObject) => entity.items(),\n equipments: (entity: RpgClientObject) => entity.equipments(),\n states: (entity: RpgClientObject) => entity.states(),\n skills: (entity: RpgClientObject) => entity.skills(),\n effects: (entity: RpgClientObject) => entity._effects(),\n componentsTop: (entity: RpgClientObject) => entity.componentsTop(),\n componentsBottom: (entity: RpgClientObject) => entity.componentsBottom(),\n componentsCenter: (entity: RpgClientObject) => entity.componentsCenter(),\n componentsLeft: (entity: RpgClientObject) => entity.componentsLeft(),\n componentsRight: (entity: RpgClientObject) => entity.componentsRight(),\n} as const;\n\ntype EntityPropMap = typeof entityPropMap;\ntype EntityPropKey = keyof EntityPropMap | ParamPropKey;\ntype EntityPropValue<K extends EntityPropKey> = K extends keyof EntityPropMap\n ? ReturnType<EntityPropMap[K]>\n : K extends `params.${string}`\n ? number | undefined\n : never;\n\nconst isSignal = <T>(value: unknown): value is Signal<T> =>\n typeof value === \"function\";\n\nconst toSignal = <T>(value: Signal<T> | T): Signal<T> =>\n isSignal<T>(value) ? value : computed(() => value);\n\nexport const getEntityProp = <K extends EntityPropKey>(\n entity: Signal<RpgClientObject | undefined> | RpgClientObject | undefined,\n key: K\n): Signal<EntityPropValue<K>> => {\n const entitySignal = toSignal(entity);\n\n return computed(() => {\n const current = entitySignal();\n if (!current) {\n return undefined as EntityPropValue<K>;\n }\n\n if (Object.prototype.hasOwnProperty.call(entityPropMap, key)) {\n const getter = entityPropMap[key as keyof EntityPropMap];\n return getter(current) as EntityPropValue<K>;\n }\n\n if (key.startsWith(\"params.\")) {\n const paramKey = key.slice(\"params.\".length);\n return current._param?.()?.[paramKey] as EntityPropValue<K>;\n }\n\n return undefined as EntityPropValue<K>;\n });\n};\n"],"mappings":";;AAkBA,IAAM,gBAAgB;CACpB,QAAQ,WAA4B,OAAO,QAAQ;CACnD,MAAM,WAA4B,OAAO,MAAM;CAC/C,OAAO,WAA4B,OAAO,OAAO;CACjD,KAAK,WAA4B,OAAO,UAAU;CAClD,KAAK,WAA4B,OAAO,UAAU;CAClD,OAAO,WAA4B,OAAO,MAAM;CAChD,OAAO,WAA4B,OAAO,MAAM;CAChD,IAAI,WAA4B,OAAO,GAAG;CAC1C,IAAI,WAA4B,OAAO,GAAG;CAC1C,IAAI,WAA4B,OAAO,GAAG;CAC1C,OAAO,WAA4B,OAAO,MAAM;CAChD,YAAY,WAA4B,OAAO,WAAW;CAC1D,QAAQ,WAA4B,OAAO,OAAO;CAClD,SAAS,WAA4B,OAAO,QAAQ;CACpD,YAAY,WAA4B,OAAO,eAAe;CAC9D,UAAU,WAA4B,OAAO,SAAS;CACtD,WAAW,WAA4B,OAAO,UAAU;CACxD,QAAQ,WAA4B,OAAO,OAAO;CAClD,aAAa,WAA4B,OAAO,YAAY;CAC5D,SAAS,WAA4B,OAAO,QAAQ;CACpD,SAAS,WAA4B,OAAO,QAAQ;CACpD,UAAU,WAA4B,OAAO,UAAU;CACvD,gBAAgB,WAA4B,OAAO,eAAe;CAClE,mBAAmB,WAA4B,OAAO,kBAAkB;CACxE,mBAAmB,WAA4B,OAAO,kBAAkB;CACxE,iBAAiB,WAA4B,OAAO,gBAAgB;CACpE,kBAAkB,WAA4B,OAAO,iBAAiB;CACvE;AAUD,IAAM,YAAe,UACnB,OAAO,UAAU;AAEnB,IAAM,YAAe,UACnB,SAAY,MAAM,GAAG,QAAQ,eAAe,MAAM;AAEpD,IAAa,iBACX,QACA,QAC+B;CAC/B,MAAM,eAAe,SAAS,OAAO;CAErC,OAAO,eAAe;EACpB,MAAM,UAAU,cAAc;EAC9B,IAAI,CAAC,SACH;EAGF,IAAI,OAAO,UAAU,eAAe,KAAK,eAAe,IAAI,EAAE;GAC5D,MAAM,SAAS,cAAc;GAC7B,OAAO,OAAO,QAAQ;;EAGxB,IAAI,IAAI,WAAW,UAAU,EAAE;GAC7B,MAAM,WAAW,IAAI,MAAM,EAAiB;GAC5C,OAAO,QAAQ,UAAU,GAAG;;GAI9B"}
1
+ {"version":3,"file":"getEntityProp.js","names":[],"sources":["../../src/utils/getEntityProp.ts"],"sourcesContent":["import { computed, Signal } from \"canvasengine\";\nimport { RpgClientObject } from \"../Game/Object\";\n\nconst BUILTIN_PARAM_KEYS = [\n \"maxHp\",\n \"maxSp\",\n \"atk\",\n \"pdef\",\n \"sdef\",\n \"str\",\n \"agi\",\n \"int\",\n \"dex\",\n] as const;\n\ntype BuiltInParamKey = typeof BUILTIN_PARAM_KEYS[number];\ntype ParamPropKey = `params.${BuiltInParamKey}` | `params.${string}`;\n\nconst entityPropMap = {\n level: (entity: RpgClientObject) => entity._level(),\n exp: (entity: RpgClientObject) => entity._exp(),\n gold: (entity: RpgClientObject) => entity._gold(),\n hp: (entity: RpgClientObject) => entity.hpSignal(),\n sp: (entity: RpgClientObject) => entity.spSignal(),\n name: (entity: RpgClientObject) => entity.name(),\n type: (entity: RpgClientObject) => entity.type(),\n x: (entity: RpgClientObject) => entity.x(),\n y: (entity: RpgClientObject) => entity.y(),\n z: (entity: RpgClientObject) => entity.z(),\n tint: (entity: RpgClientObject) => entity.tint(),\n direction: (entity: RpgClientObject) => entity.direction(),\n speed: (entity: RpgClientObject) => entity.speed(),\n hitbox: (entity: RpgClientObject) => entity.hitbox(),\n animation: (entity: RpgClientObject) => entity.animationName(),\n canMove: (entity: RpgClientObject) => entity.canMove(),\n graphics: (entity: RpgClientObject) => entity.graphics(),\n items: (entity: RpgClientObject) => entity.items(),\n equipments: (entity: RpgClientObject) => entity.equipments(),\n states: (entity: RpgClientObject) => entity.states(),\n skills: (entity: RpgClientObject) => entity.skills(),\n effects: (entity: RpgClientObject) => entity._effects(),\n componentsTop: (entity: RpgClientObject) => entity.componentsTop(),\n componentsBottom: (entity: RpgClientObject) => entity.componentsBottom(),\n componentsCenter: (entity: RpgClientObject) => entity.componentsCenter(),\n componentsLeft: (entity: RpgClientObject) => entity.componentsLeft(),\n componentsRight: (entity: RpgClientObject) => entity.componentsRight(),\n} as const;\n\ntype EntityPropMap = typeof entityPropMap;\ntype EntityPropKey = keyof EntityPropMap | ParamPropKey;\ntype EntityPropValue<K extends EntityPropKey> = K extends keyof EntityPropMap\n ? ReturnType<EntityPropMap[K]>\n : K extends `params.${string}`\n ? number | undefined\n : never;\n\nconst isSignal = <T>(value: unknown): value is Signal<T> =>\n typeof value === \"function\";\n\nconst toSignal = <T>(value: Signal<T> | T): Signal<T> =>\n isSignal<T>(value) ? value : computed(() => value);\n\nexport const getEntityProp = <K extends EntityPropKey>(\n entity: Signal<RpgClientObject | undefined> | RpgClientObject | undefined,\n key: K\n): Signal<EntityPropValue<K>> => {\n const entitySignal = toSignal(entity);\n\n return computed(() => {\n const current = entitySignal();\n if (!current) {\n return undefined as EntityPropValue<K>;\n }\n\n if (Object.prototype.hasOwnProperty.call(entityPropMap, key)) {\n const getter = entityPropMap[key as keyof EntityPropMap];\n return getter(current) as EntityPropValue<K>;\n }\n\n if (key.startsWith(\"params.\")) {\n const paramKey = key.slice(\"params.\".length);\n return current._param?.()?.[paramKey] as EntityPropValue<K>;\n }\n\n return undefined as EntityPropValue<K>;\n });\n};\n"],"mappings":";;AAkBA,IAAM,gBAAgB;CACpB,QAAQ,WAA4B,OAAO,OAAO;CAClD,MAAM,WAA4B,OAAO,KAAK;CAC9C,OAAO,WAA4B,OAAO,MAAM;CAChD,KAAK,WAA4B,OAAO,SAAS;CACjD,KAAK,WAA4B,OAAO,SAAS;CACjD,OAAO,WAA4B,OAAO,KAAK;CAC/C,OAAO,WAA4B,OAAO,KAAK;CAC/C,IAAI,WAA4B,OAAO,EAAE;C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creating RPG/MMORPG games",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -22,20 +22,20 @@
22
22
  "pixi.js": "^8.9.2"
23
23
  },
24
24
  "dependencies": {
25
- "@rpgjs/common": "5.0.0-beta.7",
26
- "@rpgjs/server": "5.0.0-beta.7",
27
- "@rpgjs/ui-css": "5.0.0-beta.7",
28
- "@signe/di": "2.10.0",
29
- "@signe/room": "2.10.0",
30
- "@signe/sync": "2.10.0",
25
+ "@rpgjs/common": "5.0.0-beta.9",
26
+ "@rpgjs/server": "5.0.0-beta.9",
27
+ "@rpgjs/ui-css": "5.0.0-beta.9",
28
+ "@signe/di": "3.0.1",
29
+ "@signe/room": "3.0.1",
30
+ "@signe/sync": "3.0.1",
31
31
  "pixi-filters": "^6.1.5",
32
32
  "rxjs": "^7.8.2"
33
33
  },
34
34
  "devDependencies": {
35
- "@canvasengine/compiler": "2.0.0-beta.61",
36
- "vite": "^8.0.11",
35
+ "@canvasengine/compiler": "2.0.0-rc.1",
36
+ "vite": "^8.0.13",
37
37
  "vite-plugin-dts": "^5.0.0",
38
- "vitest": "^4.1.5"
38
+ "vitest": "^4.1.6"
39
39
  },
40
40
  "type": "module",
41
41
  "scripts": {
package/src/Game/Map.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import {
2
2
  RpgCommonMap,
3
+ cloneLightingState,
4
+ normalizeLightingState,
5
+ type LightSpot,
6
+ type LightingState,
3
7
  type WeatherState,
4
8
  type MapPhysicsInitContext,
5
9
  type MapPhysicsEntityContext,
@@ -11,6 +15,15 @@ import { RpgClientEvent } from "./Event";
11
15
  import { RpgClientEngine } from "../RpgClientEngine";
12
16
  import { inject } from "../core/inject";
13
17
 
18
+ type TestGlobalScope = typeof globalThis & {
19
+ process?: {
20
+ env?: {
21
+ TEST?: string;
22
+ };
23
+ };
24
+ __RPGJS_TEST__?: boolean;
25
+ };
26
+
14
27
  export class RpgClientMap extends RpgCommonMap<any> {
15
28
  engine: RpgClientEngine = inject(RpgClientEngine)
16
29
  @users(RpgClientPlayer) players = signal<Record<string, RpgClientPlayer>>({});
@@ -18,19 +31,43 @@ export class RpgClientMap extends RpgCommonMap<any> {
18
31
  currentPlayer = computed(() => this.players()[this.engine.playerIdSignal()!])
19
32
  weatherState = signal<WeatherState | null>(null);
20
33
  localWeatherOverride = signal<WeatherState | null>(null);
34
+ lightingState = signal<LightingState | null>(null);
35
+ localLightSpots = signal<Record<string, LightSpot>>({});
21
36
  weather = computed<WeatherState | null>(() => {
22
37
  const local = this.localWeatherOverride()
23
38
  const state = this.weatherState()
24
39
  return local ?? state
25
40
  });
41
+ lighting = computed<LightingState | null>(() => {
42
+ const state = cloneLightingState(this.lightingState());
43
+ const localSpots = Object.entries(this.localLightSpots()).map(([id, spot]) => ({
44
+ ...spot,
45
+ id: spot.id ?? id,
46
+ }));
47
+
48
+ if (!state && localSpots.length === 0) {
49
+ return null;
50
+ }
51
+
52
+ const next: LightingState = { ...(state ?? {}) };
53
+ if (!state?.ambient) {
54
+ delete next.ambient;
55
+ }
56
+ next.spots = [
57
+ ...(state?.spots ?? []),
58
+ ...localSpots,
59
+ ];
60
+ return next;
61
+ });
26
62
  private manualClientPhysicsTick = false;
27
63
  private readonly isTestEnvironment: boolean;
28
64
 
29
65
  constructor() {
30
66
  super();
31
67
  // Détecter l'environnement de test
32
- const isTest = (typeof process !== 'undefined' && process.env?.TEST === 'true')
33
- || (typeof window !== 'undefined' && (window as any).__RPGJS_TEST__ === true);
68
+ const testGlobal = globalThis as TestGlobalScope;
69
+ const isTest = testGlobal.process?.env?.TEST === 'true'
70
+ || testGlobal.__RPGJS_TEST__ === true;
34
71
  this.isTestEnvironment = isTest;
35
72
  if (isTest) {
36
73
  this.autoTickEnabled = false;
@@ -58,6 +95,8 @@ export class RpgClientMap extends RpgCommonMap<any> {
58
95
  this.events.set({})
59
96
  this.weatherState.set(null);
60
97
  this.localWeatherOverride.set(null);
98
+ this.lightingState.set(null);
99
+ this.localLightSpots.set({});
61
100
  this.clearPhysic()
62
101
  }
63
102
 
@@ -73,6 +112,56 @@ export class RpgClientMap extends RpgCommonMap<any> {
73
112
  this.localWeatherOverride.set(null);
74
113
  }
75
114
 
115
+ getLighting(): LightingState | null {
116
+ return this.lighting();
117
+ }
118
+
119
+ addLightSpot(id: string, spot: LightSpot): void {
120
+ const normalized = normalizeLightingState({ spots: [{ ...spot, id }] });
121
+ const nextSpot = normalized?.spots?.[0];
122
+ if (!nextSpot) {
123
+ return;
124
+ }
125
+ this.localLightSpots.update((spots) => ({
126
+ ...spots,
127
+ [id]: nextSpot,
128
+ }));
129
+ }
130
+
131
+ patchLightSpot(id: string, patch: Partial<LightSpot>): void {
132
+ this.localLightSpots.update((spots) => {
133
+ const current = spots[id];
134
+ if (!current) {
135
+ return spots;
136
+ }
137
+ return {
138
+ ...spots,
139
+ [id]: {
140
+ ...current,
141
+ ...patch,
142
+ id,
143
+ x: patch.x ?? current.x,
144
+ y: patch.y ?? current.y,
145
+ },
146
+ };
147
+ });
148
+ }
149
+
150
+ removeLightSpot(id: string): void {
151
+ this.localLightSpots.update((spots) => {
152
+ if (!(id in spots)) {
153
+ return spots;
154
+ }
155
+ const next = { ...spots };
156
+ delete next[id];
157
+ return next;
158
+ });
159
+ }
160
+
161
+ clearLightSpots(): void {
162
+ this.localLightSpots.set({});
163
+ }
164
+
76
165
  stepClientPhysics(deltaMs: number): number {
77
166
  if (!this.manualClientPhysicsTick) {
78
167
  return 0;
@@ -1,14 +1,8 @@
1
1
  import { Hooks, ModulesToken, RpgCommonPlayer } from "@rpgjs/common";
2
- import { trigger, signal, effect } from "canvasengine";
3
- import { filter, from, map, of, Subscription, switchMap } from "rxjs";
2
+ import { trigger, signal, type Trigger } from "canvasengine";
3
+ import { from, map, of, Subscription, switchMap } from "rxjs";
4
4
  import { inject } from "../core/inject";
5
5
  import { RpgClientEngine } from "../RpgClientEngine";
6
- import TextComponent from "../components/dynamics/text.ce";
7
-
8
- const DYNAMIC_COMPONENTS = {
9
- text: TextComponent,
10
- }
11
-
12
6
  type Frame = { x: number; y: number; ts: number };
13
7
 
14
8
  type AnimationRestoreOptions = {
@@ -17,6 +11,24 @@ type AnimationRestoreOptions = {
17
11
  timeoutMs?: number;
18
12
  };
19
13
 
14
+ type FlashType = 'alpha' | 'tint' | 'both';
15
+
16
+ type FlashOptions = {
17
+ type?: FlashType;
18
+ duration?: number;
19
+ cycles?: number;
20
+ alpha?: number;
21
+ tint?: number | string;
22
+ };
23
+
24
+ type FlashTriggerOptions = Omit<FlashOptions, "tint"> & {
25
+ tint: number;
26
+ };
27
+
28
+ type ConfigurableTrigger<T> = Omit<Trigger<T>, "start"> & {
29
+ start(config?: T): Promise<void>;
30
+ };
31
+
20
32
  export abstract class RpgClientObject extends RpgCommonPlayer {
21
33
  abstract _type: string;
22
34
  emitParticleTrigger = trigger();
@@ -26,8 +38,7 @@ export abstract class RpgClientObject extends RpgCommonPlayer {
26
38
  _param = signal({});
27
39
  frames: Frame[] = [];
28
40
  graphicsSignals = signal<any[]>([]);
29
- _component = {} // temporary component memory
30
- flashTrigger = trigger();
41
+ flashTrigger: ConfigurableTrigger<FlashTriggerOptions> = trigger<FlashTriggerOptions>();
31
42
  private animationRestoreState?: {
32
43
  animationName: string;
33
44
  graphics: any[];
@@ -58,24 +69,6 @@ export abstract class RpgClientObject extends RpgCommonPlayer {
58
69
  this.graphicsSignals.set(sheets);
59
70
  });
60
71
 
61
- this.componentsTop.observable
62
- .pipe(
63
- filter(value => value !== null && value !== undefined),
64
- map((value) => typeof value === 'string' ? JSON.parse(value) : value),
65
- )
66
- .subscribe(({components}) => {
67
- for (const component of components) {
68
- for (const [key, value] of Object.entries(component)) {
69
- this._component = value as any; // temporary component memory
70
- console.log(value)
71
- const type = (value as any).type as keyof typeof DYNAMIC_COMPONENTS;
72
- if (DYNAMIC_COMPONENTS[type]) {
73
- this.engine.addSpriteComponentInFront(DYNAMIC_COMPONENTS[type]);
74
- }
75
- }
76
- }
77
- });
78
-
79
72
  this.engine.tick
80
73
  .pipe
81
74
  //throttleTime(10)
@@ -192,13 +185,7 @@ export abstract class RpgClientObject extends RpgCommonPlayer {
192
185
  * });
193
186
  * ```
194
187
  */
195
- flash(options?: {
196
- type?: 'alpha' | 'tint' | 'both';
197
- duration?: number;
198
- cycles?: number;
199
- alpha?: number;
200
- tint?: number | string;
201
- }): void {
188
+ flash(options?: FlashOptions): void {
202
189
  const flashOptions = {
203
190
  type: options?.type || 'alpha',
204
191
  duration: options?.duration ?? 300,