@rpgjs/client 5.0.0-alpha.0 → 5.0.0-alpha.10

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 (114) hide show
  1. package/dist/Game/AnimationManager.d.ts +8 -0
  2. package/dist/RpgClient.d.ts +99 -68
  3. package/dist/RpgClientEngine.d.ts +86 -4
  4. package/dist/components/animations/index.d.ts +4 -0
  5. package/dist/components/index.d.ts +2 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.js +2 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/index10.js +1 -1
  10. package/dist/index11.js +4 -4
  11. package/dist/index11.js.map +1 -1
  12. package/dist/index12.js +6 -2
  13. package/dist/index12.js.map +1 -1
  14. package/dist/index13.js +2 -2
  15. package/dist/index13.js.map +1 -1
  16. package/dist/index14.js +95 -35
  17. package/dist/index14.js.map +1 -1
  18. package/dist/index15.js +45 -186
  19. package/dist/index15.js.map +1 -1
  20. package/dist/index16.js +187 -5
  21. package/dist/index16.js.map +1 -1
  22. package/dist/index17.js +5 -383
  23. package/dist/index17.js.map +1 -1
  24. package/dist/index18.js +384 -28
  25. package/dist/index18.js.map +1 -1
  26. package/dist/index19.js +24 -17
  27. package/dist/index19.js.map +1 -1
  28. package/dist/index2.js +147 -25
  29. package/dist/index2.js.map +1 -1
  30. package/dist/index20.js +16 -2413
  31. package/dist/index20.js.map +1 -1
  32. package/dist/index21.js +2395 -88
  33. package/dist/index21.js.map +1 -1
  34. package/dist/index22.js +108 -103
  35. package/dist/index22.js.map +1 -1
  36. package/dist/index23.js +95 -57
  37. package/dist/index23.js.map +1 -1
  38. package/dist/index24.js +62 -12
  39. package/dist/index24.js.map +1 -1
  40. package/dist/index25.js +18 -37
  41. package/dist/index25.js.map +1 -1
  42. package/dist/index26.js +25 -3
  43. package/dist/index26.js.map +1 -1
  44. package/dist/index27.js +87 -314
  45. package/dist/index27.js.map +1 -1
  46. package/dist/index28.js +37 -21
  47. package/dist/index28.js.map +1 -1
  48. package/dist/index29.js +3 -9
  49. package/dist/index29.js.map +1 -1
  50. package/dist/index3.js +2 -2
  51. package/dist/index30.js +317 -6
  52. package/dist/index30.js.map +1 -1
  53. package/dist/index31.js +24 -171
  54. package/dist/index31.js.map +1 -1
  55. package/dist/index32.js +7 -497
  56. package/dist/index32.js.map +1 -1
  57. package/dist/index33.js +8 -9
  58. package/dist/index33.js.map +1 -1
  59. package/dist/index34.js +9 -4400
  60. package/dist/index34.js.map +1 -1
  61. package/dist/index35.js +4397 -85
  62. package/dist/index35.js.map +1 -1
  63. package/dist/index36.js +310 -55
  64. package/dist/index36.js.map +1 -1
  65. package/dist/index37.js +169 -15
  66. package/dist/index37.js.map +1 -1
  67. package/dist/index38.js +496 -15
  68. package/dist/index38.js.map +1 -1
  69. package/dist/index39.js +61 -0
  70. package/dist/index39.js.map +1 -0
  71. package/dist/index4.js +18 -5
  72. package/dist/index4.js.map +1 -1
  73. package/dist/index40.js +20 -0
  74. package/dist/index40.js.map +1 -0
  75. package/dist/index41.js +82 -0
  76. package/dist/index41.js.map +1 -0
  77. package/dist/index5.js +2 -1
  78. package/dist/index5.js.map +1 -1
  79. package/dist/index6.js +1 -1
  80. package/dist/index7.js +10 -2
  81. package/dist/index7.js.map +1 -1
  82. package/dist/index8.js +24 -6
  83. package/dist/index8.js.map +1 -1
  84. package/dist/index9.js +2 -2
  85. package/dist/presets/animation.d.ts +31 -0
  86. package/dist/presets/index.d.ts +102 -0
  87. package/dist/presets/lpc.d.ts +89 -0
  88. package/dist/services/loadMap.d.ts +123 -2
  89. package/dist/services/mmorpg.d.ts +7 -3
  90. package/package.json +14 -12
  91. package/src/Game/{EffectManager.ts → AnimationManager.ts} +2 -2
  92. package/src/Game/Object.ts +69 -0
  93. package/src/RpgClient.ts +101 -67
  94. package/src/RpgClientEngine.ts +159 -24
  95. package/src/components/{effects → animations}/animation.ce +3 -5
  96. package/src/components/{effects → animations}/index.ts +1 -1
  97. package/src/components/character.ce +74 -33
  98. package/src/components/index.ts +2 -1
  99. package/src/components/scenes/draw-map.ce +6 -23
  100. package/src/components/scenes/event-layer.ce +3 -3
  101. package/src/core/setup.ts +2 -0
  102. package/src/index.ts +1 -1
  103. package/src/module.ts +23 -5
  104. package/src/presets/animation.ts +46 -0
  105. package/src/presets/index.ts +5 -1
  106. package/src/presets/lpc.ts +108 -0
  107. package/src/services/loadMap.ts +131 -2
  108. package/src/services/mmorpg.ts +20 -4
  109. package/tsconfig.json +1 -1
  110. package/vite.config.ts +1 -1
  111. package/dist/Game/EffectManager.d.ts +0 -5
  112. package/dist/components/effects/index.d.ts +0 -4
  113. package/src/components/scenes/element-map.ce +0 -23
  114. /package/src/components/{effects → animations}/hit.ce +0 -0
@@ -0,0 +1,108 @@
1
+ import { Animation, Direction } from "@rpgjs/common";
2
+
3
+ export const LPCSpritesheetPreset = (options: {
4
+ id: string;
5
+ imageSource: string;
6
+ width: number;
7
+ height: number;
8
+ ratio?: number;
9
+ }) => {
10
+ const ratio = options.ratio ?? 1;
11
+
12
+ const frameY = (direction: Direction) => {
13
+ return {
14
+ [Direction.Down]: 2,
15
+ [Direction.Left]: 1,
16
+ [Direction.Right]: 3,
17
+ [Direction.Up]: 0,
18
+ }[direction];
19
+ };
20
+
21
+ const stand = (direction: Direction) => [
22
+ { time: 0, frameX: 0, frameY: frameY(direction) },
23
+ ];
24
+ const anim = (
25
+ direction: Direction,
26
+ framesWidth: number,
27
+ speed: number = 5
28
+ ) => {
29
+ const array: any = [];
30
+ for (let i = 0; i < framesWidth; i++) {
31
+ array.push({ time: i * speed, frameX: i, frameY: frameY(direction) });
32
+ }
33
+ return array;
34
+ };
35
+
36
+ return {
37
+ id: options.id,
38
+ image: options.imageSource,
39
+ width: options.width,
40
+ height: options.height,
41
+ opacity: 1,
42
+ rectWidth: 64 * ratio,
43
+ rectHeight: 64 * ratio,
44
+ framesWidth: 6,
45
+ framesHeight: 4,
46
+ spriteRealSize: {
47
+ width: 48 * ratio,
48
+ height: 52 * ratio,
49
+ },
50
+ textures: {
51
+ [Animation.Stand]: {
52
+ offset: {
53
+ x: 0,
54
+ y: 512 * ratio,
55
+ },
56
+ animations: ({ direction }) => [stand(direction)],
57
+ },
58
+ [Animation.Walk]: {
59
+ offset: {
60
+ x: 0,
61
+ y: 512 * ratio,
62
+ },
63
+ framesWidth: 9,
64
+ framesHeight: 4,
65
+ animations: ({ direction }) => [anim(direction, 9)],
66
+ },
67
+ [Animation.Attack]: {
68
+ offset: {
69
+ x: 0,
70
+ y: 768 * ratio,
71
+ },
72
+ framesWidth: 6,
73
+ framesHeight: 4,
74
+ animations: ({ direction }) => [anim(direction, 6, 3)],
75
+ },
76
+ [Animation.Skill]: {
77
+ framesWidth: 7,
78
+ framesHeight: 4,
79
+ animations: ({ direction }) => [anim(direction, 7, 3)],
80
+ },
81
+ attack2: {
82
+ offset: {
83
+ x: 0,
84
+ y: 256 * ratio,
85
+ },
86
+ framesWidth: 7,
87
+ framesHeight: 8,
88
+ animations: ({ direction }) => [anim(direction, 7, 3)],
89
+ },
90
+ ...(options.height > 3000
91
+ ? {
92
+ attack3: {
93
+ offset: {
94
+ x: 0,
95
+ y: 5568 - 288 * 4,
96
+ },
97
+ rectWidth: 288,
98
+ rectHeight: 288,
99
+ framesWidth: 6,
100
+ framesHeight: 4,
101
+ animations: ({ direction }) => [anim(direction, 6, 3)],
102
+ },
103
+ }
104
+ : {}),
105
+ },
106
+ };
107
+ };
108
+
@@ -3,12 +3,45 @@ import { UpdateMapToken, UpdateMapService } from "@rpgjs/common";
3
3
 
4
4
  export const LoadMapToken = 'LoadMapToken'
5
5
 
6
- export type LoadMapOptions = (mapId: string) => Promise<void>
6
+ /**
7
+ * Represents the structure of map data that should be returned by the load map callback.
8
+ * This interface defines all the properties that can be provided when loading a custom map.
9
+ *
10
+ * @interface MapData
11
+ */
12
+ type MapData = {
13
+ /** Raw map data that will be passed to the map component */
14
+ data: any;
15
+ /** CanvasEngine component that will render the map */
16
+ component: any;
17
+ /** Optional map width in pixels, used for viewport calculations */
18
+ width?: number;
19
+ /** Optional map height in pixels, used for viewport calculations */
20
+ height?: number;
21
+ /** Optional map events data (NPCs, interactive objects, etc.) */
22
+ events?: any;
23
+ /** Optional map identifier, defaults to the mapId parameter if not provided */
24
+ id?: string;
25
+ }
26
+
27
+ /**
28
+ * Callback function type for loading map data.
29
+ * This function receives a map ID and should return either a MapData object directly
30
+ * or a Promise that resolves to a MapData object.
31
+ *
32
+ * @callback LoadMapOptions
33
+ * @param {string} mapId - The identifier of the map to load
34
+ * @returns {Promise<MapData> | MapData} The map data object or a promise resolving to it
35
+ */
36
+ export type LoadMapOptions = (mapId: string) => Promise<MapData> | MapData
7
37
 
8
38
  export class LoadMapService {
9
39
  private updateMapService: UpdateMapService;
10
40
 
11
41
  constructor(private context: Context, private options: LoadMapOptions) {
42
+ if (context['side'] === 'server') {
43
+ return
44
+ }
12
45
  this.updateMapService = inject(context, UpdateMapToken);
13
46
  }
14
47
 
@@ -19,11 +52,107 @@ export class LoadMapService {
19
52
  }
20
53
  }
21
54
 
55
+ /**
56
+ * Creates a dependency injection configuration for custom map loading on the client side.
57
+ *
58
+ * This function allows you to customize how maps are loaded and displayed by providing
59
+ * a callback that defines custom map data and rendering components. It's designed to work
60
+ * with the RPG-JS dependency injection system and enables integration of custom map formats
61
+ * like Tiled TMX files or any other map data structure.
62
+ *
63
+ * The function sets up the necessary service providers for map loading, including:
64
+ * - UpdateMapToken: Handles map updates in the client context
65
+ * - LoadMapToken: Provides the LoadMapService with your custom loading logic
66
+ *
67
+ * **Design Concept:**
68
+ * The function follows the provider pattern, creating a modular way to inject custom
69
+ * map loading behavior into the RPG-JS client engine. It separates the concern of
70
+ * map data fetching from map rendering, allowing developers to focus on their specific
71
+ * map format while leveraging the engine's rendering capabilities.
72
+ *
73
+ * @param {LoadMapOptions} options - Callback function that handles map loading logic
74
+ * @returns {Array<Object>} Array of dependency injection provider configurations
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * import { provideLoadMap } from '@rpgjs/client'
79
+ * import { createModule } from '@rpgjs/common'
80
+ * import MyTiledMapComponent from './MyTiledMapComponent.ce'
81
+ *
82
+ * // Basic usage with JSON map data
83
+ * export function provideCustomMap() {
84
+ * return createModule("CustomMap", [
85
+ * provideLoadMap(async (mapId) => {
86
+ * const response = await fetch(`/maps/${mapId}.json`)
87
+ * const mapData = await response.json()
88
+ *
89
+ * return {
90
+ * data: mapData,
91
+ * component: MyTiledMapComponent,
92
+ * width: mapData.width,
93
+ * height: mapData.height,
94
+ * events: mapData.events
95
+ * }
96
+ * })
97
+ * ])
98
+ * }
99
+ *
100
+ * // Advanced usage with Tiled TMX files
101
+ * export function provideTiledMap() {
102
+ * return createModule("TiledMap", [
103
+ * provideLoadMap(async (mapId) => {
104
+ * // Load TMX file
105
+ * const tmxResponse = await fetch(`/tiled/${mapId}.tmx`)
106
+ * const tmxData = await tmxResponse.text()
107
+ *
108
+ * // Parse TMX data (using a TMX parser)
109
+ * const parsedMap = parseTMX(tmxData)
110
+ *
111
+ * return {
112
+ * data: parsedMap,
113
+ * component: TiledMapRenderer,
114
+ * width: parsedMap.width * parsedMap.tilewidth,
115
+ * height: parsedMap.height * parsedMap.tileheight,
116
+ * events: parsedMap.objectGroups?.find(g => g.name === 'events')?.objects
117
+ * }
118
+ * })
119
+ * ])
120
+ * }
121
+ *
122
+ * // Synchronous usage for static maps
123
+ * export function provideStaticMap() {
124
+ * return createModule("StaticMap", [
125
+ * provideLoadMap((mapId) => {
126
+ * const staticMaps = {
127
+ * 'town': { tiles: [...], npcs: [...] },
128
+ * 'dungeon': { tiles: [...], monsters: [...] }
129
+ * }
130
+ *
131
+ * return {
132
+ * data: staticMaps[mapId],
133
+ * component: StaticMapComponent,
134
+ * width: 800,
135
+ * height: 600
136
+ * }
137
+ * })
138
+ * ])
139
+ * }
140
+ * ```
141
+ *
142
+ * @since 4.0.0
143
+ * @see {@link LoadMapOptions} for callback function signature
144
+ * @see {@link MapData} for return data structure
145
+ */
22
146
  export function provideLoadMap(options: LoadMapOptions) {
23
147
  return [
24
148
  {
25
149
  provide: UpdateMapToken,
26
- useFactory: (context: Context) => console.warn('UpdateMapToken is not overridden'),
150
+ useFactory: (context: Context) => {
151
+ if (context['side'] === 'client') {
152
+ console.warn('UpdateMapToken is not overridden')
153
+ }
154
+ return
155
+ },
27
156
  },
28
157
  {
29
158
  provide: LoadMapToken,
@@ -6,23 +6,28 @@ import { AbstractWebsocket, WebSocketToken } from "./AbstractSocket";
6
6
  import { UpdateMapService, UpdateMapToken } from "@rpgjs/common";
7
7
 
8
8
  interface MmorpgOptions {
9
- host: string;
9
+ host?: string;
10
10
  }
11
11
 
12
12
  class BridgeWebsocket extends AbstractWebsocket {
13
13
  private socket: any;
14
14
 
15
- constructor(protected context: Context, private options: MmorpgOptions) {
15
+ constructor(protected context: Context, private options: MmorpgOptions = {}) {
16
16
  super(context);
17
17
  }
18
18
 
19
- async connection() {
19
+ async connection(listeners?: (data: any) => void) {
20
20
  // tmp
21
21
  class Room {
22
22
 
23
23
  }
24
24
  const instance = new Room()
25
- this.socket = await connectionRoom(this.options, instance)
25
+ this.socket = await connectionRoom({
26
+ host: this.options.host || window.location.host,
27
+ room: "lobby-1",
28
+ }, instance)
29
+
30
+ listeners?.(this.socket)
26
31
  }
27
32
 
28
33
  on(key: string, callback: (data: any) => void) {
@@ -36,6 +41,17 @@ class BridgeWebsocket extends AbstractWebsocket {
36
41
  emit(event: string, data: any) {
37
42
  this.socket.emit(event, data);
38
43
  }
44
+
45
+ updateProperties({ room }: { room: any }) {
46
+ this.socket.conn.updateProperties({
47
+ room: room,
48
+ host: this.options.host
49
+ })
50
+ }
51
+
52
+ async reconnect(listeners?: (data: any) => void) {
53
+ this.socket.conn.reconnect()
54
+ }
39
55
  }
40
56
 
41
57
  class UpdateMapStandaloneService extends UpdateMapService {
package/tsconfig.json CHANGED
@@ -30,6 +30,6 @@
30
30
  ],
31
31
  "typeRoots": [
32
32
  "node_modules/@types",
33
- "src/types"
33
+ "node_modules/@rpgjs/client"
34
34
  ],
35
35
  }
package/vite.config.ts CHANGED
@@ -24,7 +24,7 @@ export default defineConfig({
24
24
  fileName: 'index'
25
25
  },
26
26
  rollupOptions: {
27
- external: [/@rpgjs/, 'esbuild', 'canvasengine', '@canvasengine/presets', 'rxjs'],
27
+ external: [/@rpgjs/, 'esbuild', 'canvasengine', '@canvasengine/presets', 'rxjs', 'pixi.js'],
28
28
  output: {
29
29
  preserveModules: true,
30
30
  preserveModulesRoot: 'src'
@@ -1,5 +0,0 @@
1
- import { RpgCommonPlayer } from '@rpgjs/common';
2
- export declare class EffectManager {
3
- current: import('canvasengine').WritableArraySignal<any[]>;
4
- displayEffect(params: any, player: RpgCommonPlayer): void;
5
- }
@@ -1,4 +0,0 @@
1
- export declare const PrebuiltEffects: {
2
- Hit: any;
3
- Animation: any;
4
- };
@@ -1,23 +0,0 @@
1
- <Sprite image rectangle x y zIndex />
2
-
3
- <script>
4
- const {
5
- image,
6
- rect,
7
- drawIn,
8
- id,
9
- } = defineProps()
10
-
11
- const rectangle = {
12
- x: rect[0],
13
- y: rect[1],
14
- width: rect[2],
15
- height: rect[3]
16
- }
17
-
18
- const x = drawIn[0]
19
- const y = drawIn[1]
20
-
21
- const zIndex = y + rectangle.height
22
- </script>
23
-
File without changes