@rpgjs/client 4.3.0 → 5.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (321) hide show
  1. package/dist/Game/EffectManager.d.ts +5 -0
  2. package/dist/Game/Event.d.ts +4 -0
  3. package/dist/Game/Map.d.ts +7 -0
  4. package/dist/Game/Player.d.ts +4 -0
  5. package/dist/Gui/Gui.d.ts +23 -0
  6. package/{lib → dist}/RpgClient.d.ts +9 -6
  7. package/dist/RpgClientEngine.d.ts +43 -0
  8. package/dist/components/effects/index.d.ts +4 -0
  9. package/dist/components/gui/index.d.ts +3 -0
  10. package/dist/components/index.d.ts +2 -0
  11. package/dist/core/inject.d.ts +5 -0
  12. package/dist/core/setup.d.ts +6 -0
  13. package/dist/index.d.ts +13 -0
  14. package/dist/index.js +13 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/index10.js +8 -0
  17. package/dist/index10.js.map +1 -0
  18. package/dist/index11.js +10 -0
  19. package/dist/index11.js.map +1 -0
  20. package/dist/index12.js +8 -0
  21. package/dist/index12.js.map +1 -0
  22. package/dist/index13.js +17 -0
  23. package/dist/index13.js.map +1 -0
  24. package/dist/index14.js +50 -0
  25. package/dist/index14.js.map +1 -0
  26. package/dist/index15.js +191 -0
  27. package/dist/index15.js.map +1 -0
  28. package/dist/index16.js +9 -0
  29. package/dist/index16.js.map +1 -0
  30. package/dist/index17.js +387 -0
  31. package/dist/index17.js.map +1 -0
  32. package/dist/index18.js +31 -0
  33. package/dist/index18.js.map +1 -0
  34. package/dist/index19.js +24 -0
  35. package/dist/index19.js.map +1 -0
  36. package/dist/index2.js +112 -0
  37. package/dist/index2.js.map +1 -0
  38. package/dist/index20.js +2421 -0
  39. package/dist/index20.js.map +1 -0
  40. package/dist/index21.js +114 -0
  41. package/dist/index21.js.map +1 -0
  42. package/dist/index22.js +109 -0
  43. package/dist/index22.js.map +1 -0
  44. package/dist/index23.js +71 -0
  45. package/dist/index23.js.map +1 -0
  46. package/dist/index24.js +21 -0
  47. package/dist/index24.js.map +1 -0
  48. package/dist/index25.js +41 -0
  49. package/dist/index25.js.map +1 -0
  50. package/dist/index26.js +5 -0
  51. package/dist/index26.js.map +1 -0
  52. package/dist/index27.js +322 -0
  53. package/dist/index27.js.map +1 -0
  54. package/dist/index28.js +25 -0
  55. package/dist/index28.js.map +1 -0
  56. package/dist/index29.js +11 -0
  57. package/dist/index29.js.map +1 -0
  58. package/dist/index3.js +87 -0
  59. package/dist/index3.js.map +1 -0
  60. package/dist/index30.js +11 -0
  61. package/dist/index30.js.map +1 -0
  62. package/dist/index31.js +174 -0
  63. package/dist/index31.js.map +1 -0
  64. package/dist/index32.js +501 -0
  65. package/dist/index32.js.map +1 -0
  66. package/dist/index33.js +12 -0
  67. package/dist/index33.js.map +1 -0
  68. package/dist/index34.js +4403 -0
  69. package/dist/index34.js.map +1 -0
  70. package/dist/index35.js +91 -0
  71. package/dist/index35.js.map +1 -0
  72. package/dist/index36.js +61 -0
  73. package/dist/index36.js.map +1 -0
  74. package/dist/index37.js +20 -0
  75. package/dist/index37.js.map +1 -0
  76. package/dist/index38.js +20 -0
  77. package/dist/index38.js.map +1 -0
  78. package/dist/index4.js +54 -0
  79. package/dist/index4.js.map +1 -0
  80. package/dist/index5.js +15 -0
  81. package/dist/index5.js.map +1 -0
  82. package/dist/index6.js +17 -0
  83. package/dist/index6.js.map +1 -0
  84. package/dist/index7.js +31 -0
  85. package/dist/index7.js.map +1 -0
  86. package/dist/index8.js +90 -0
  87. package/dist/index8.js.map +1 -0
  88. package/dist/index9.js +76 -0
  89. package/dist/index9.js.map +1 -0
  90. package/dist/module.d.ts +14 -0
  91. package/dist/presets/index.d.ts +22 -0
  92. package/{lib/Presets/AnimationSpritesheet.d.ts → dist/presets/rmspritesheet.d.ts} +6 -2
  93. package/dist/services/AbstractSocket.d.ts +15 -0
  94. package/dist/services/loadMap.d.ts +14 -0
  95. package/dist/services/mmorpg.d.ts +32 -0
  96. package/dist/services/standalone.d.ts +34 -0
  97. package/package.json +25 -41
  98. package/src/Game/EffectManager.ts +20 -0
  99. package/src/Game/Event.ts +5 -0
  100. package/src/Game/Map.ts +10 -0
  101. package/src/Game/Object.ts +16 -0
  102. package/src/Game/Player.ts +5 -0
  103. package/src/Gui/Gui.ts +80 -533
  104. package/src/RpgClient.ts +9 -5
  105. package/src/RpgClientEngine.ts +135 -818
  106. package/src/components/character.ce +104 -0
  107. package/src/components/effects/animation.ce +19 -0
  108. package/src/components/effects/hit.ce +87 -0
  109. package/src/components/effects/index.ts +7 -0
  110. package/src/components/gui/dialogbox/index.ce +194 -0
  111. package/src/components/gui/dialogbox/itemMenu.ce +23 -0
  112. package/src/components/gui/dialogbox/selection.ce +67 -0
  113. package/src/components/gui/index.ts +5 -0
  114. package/src/components/index.ts +3 -0
  115. package/src/components/scenes/canvas.ce +51 -0
  116. package/src/components/scenes/draw-map.ce +56 -0
  117. package/src/components/scenes/element-map.ce +23 -0
  118. package/src/components/scenes/event-layer.ce +20 -0
  119. package/src/core/inject.ts +17 -0
  120. package/src/core/setup.ts +18 -0
  121. package/src/index.ts +13 -29
  122. package/src/module.ts +93 -0
  123. package/src/presets/index.ts +5 -0
  124. package/src/{Presets/AnimationSpritesheet.ts → presets/rmspritesheet.ts} +4 -5
  125. package/src/services/AbstractSocket.ts +14 -0
  126. package/src/services/loadMap.ts +33 -0
  127. package/src/services/mmorpg.ts +64 -0
  128. package/src/services/standalone.ts +101 -0
  129. package/src/types/canvas-engine.d.ts +26 -0
  130. package/tsconfig.json +8 -3
  131. package/vite.config.ts +34 -0
  132. package/CHANGELOG.md +0 -189
  133. package/LICENSE +0 -19
  134. package/browser/React-ece4b906.js +0 -195
  135. package/browser/index-ba657126.js +0 -44229
  136. package/browser/manifest.json +0 -21
  137. package/browser/rpg.client.js +0 -40
  138. package/browser/rpg.client.umd.cjs +0 -44456
  139. package/lib/Components/AbstractComponent.d.ts +0 -32
  140. package/lib/Components/AbstractComponent.js +0 -93
  141. package/lib/Components/AbstractComponent.js.map +0 -1
  142. package/lib/Components/BarComponent.d.ts +0 -21
  143. package/lib/Components/BarComponent.js +0 -169
  144. package/lib/Components/BarComponent.js.map +0 -1
  145. package/lib/Components/Component.d.ts +0 -124
  146. package/lib/Components/Component.js +0 -425
  147. package/lib/Components/Component.js.map +0 -1
  148. package/lib/Components/DebugComponent.d.ts +0 -11
  149. package/lib/Components/DebugComponent.js +0 -32
  150. package/lib/Components/DebugComponent.js.map +0 -1
  151. package/lib/Components/ImageComponent.d.ts +0 -11
  152. package/lib/Components/ImageComponent.js +0 -30
  153. package/lib/Components/ImageComponent.js.map +0 -1
  154. package/lib/Components/ShapeComponent.d.ts +0 -11
  155. package/lib/Components/ShapeComponent.js +0 -57
  156. package/lib/Components/ShapeComponent.js.map +0 -1
  157. package/lib/Components/TextComponent.d.ts +0 -11
  158. package/lib/Components/TextComponent.js +0 -35
  159. package/lib/Components/TextComponent.js.map +0 -1
  160. package/lib/Components/TileComponent.d.ts +0 -10
  161. package/lib/Components/TileComponent.js +0 -40
  162. package/lib/Components/TileComponent.js.map +0 -1
  163. package/lib/Effects/Animation.d.ts +0 -55
  164. package/lib/Effects/Animation.js +0 -233
  165. package/lib/Effects/Animation.js.map +0 -1
  166. package/lib/Effects/AnimationCharacter.d.ts +0 -7
  167. package/lib/Effects/AnimationCharacter.js +0 -9
  168. package/lib/Effects/AnimationCharacter.js.map +0 -1
  169. package/lib/Effects/Spinner.d.ts +0 -7
  170. package/lib/Effects/Spinner.js +0 -18
  171. package/lib/Effects/Spinner.js.map +0 -1
  172. package/lib/Effects/Timeline.d.ts +0 -151
  173. package/lib/Effects/Timeline.js +0 -369
  174. package/lib/Effects/Timeline.js.map +0 -1
  175. package/lib/Effects/TransitionScene.d.ts +0 -18
  176. package/lib/Effects/TransitionScene.js +0 -50
  177. package/lib/Effects/TransitionScene.js.map +0 -1
  178. package/lib/GameEngine.d.ts +0 -68
  179. package/lib/GameEngine.js +0 -254
  180. package/lib/GameEngine.js.map +0 -1
  181. package/lib/Gui/Gui.d.ts +0 -110
  182. package/lib/Gui/Gui.js +0 -489
  183. package/lib/Gui/Gui.js.map +0 -1
  184. package/lib/Gui/React.d.ts +0 -28
  185. package/lib/Gui/React.js +0 -147
  186. package/lib/Gui/React.js.map +0 -1
  187. package/lib/Gui/Vue.d.ts +0 -13
  188. package/lib/Gui/Vue.js +0 -114
  189. package/lib/Gui/Vue.js.map +0 -1
  190. package/lib/Interfaces/Character.d.ts +0 -6
  191. package/lib/Interfaces/Character.js +0 -2
  192. package/lib/Interfaces/Character.js.map +0 -1
  193. package/lib/Interfaces/Scene.d.ts +0 -10
  194. package/lib/Interfaces/Scene.js +0 -2
  195. package/lib/Interfaces/Scene.js.map +0 -1
  196. package/lib/KeyboardControls.d.ts +0 -367
  197. package/lib/KeyboardControls.js +0 -714
  198. package/lib/KeyboardControls.js.map +0 -1
  199. package/lib/Logger.d.ts +0 -1
  200. package/lib/Logger.js +0 -4
  201. package/lib/Logger.js.map +0 -1
  202. package/lib/Presets/AnimationSpritesheet.js +0 -39
  203. package/lib/Presets/AnimationSpritesheet.js.map +0 -1
  204. package/lib/Presets/Scene.d.ts +0 -3
  205. package/lib/Presets/Scene.js +0 -5
  206. package/lib/Presets/Scene.js.map +0 -1
  207. package/lib/Renderer.d.ts +0 -62
  208. package/lib/Renderer.js +0 -300
  209. package/lib/Renderer.js.map +0 -1
  210. package/lib/Resources.d.ts +0 -22
  211. package/lib/Resources.js +0 -38
  212. package/lib/Resources.js.map +0 -1
  213. package/lib/RpgClient.js +0 -2
  214. package/lib/RpgClient.js.map +0 -1
  215. package/lib/RpgClientEngine.d.ts +0 -257
  216. package/lib/RpgClientEngine.js +0 -677
  217. package/lib/RpgClientEngine.js.map +0 -1
  218. package/lib/Scene/EventLayer.d.ts +0 -4
  219. package/lib/Scene/EventLayer.js +0 -8
  220. package/lib/Scene/EventLayer.js.map +0 -1
  221. package/lib/Scene/Map.d.ts +0 -109
  222. package/lib/Scene/Map.js +0 -319
  223. package/lib/Scene/Map.js.map +0 -1
  224. package/lib/Scene/Scene.d.ts +0 -184
  225. package/lib/Scene/Scene.js +0 -250
  226. package/lib/Scene/Scene.js.map +0 -1
  227. package/lib/Scene/SceneData.d.ts +0 -4
  228. package/lib/Scene/SceneData.js +0 -8
  229. package/lib/Scene/SceneData.js.map +0 -1
  230. package/lib/Sound/RpgSound.d.ts +0 -11
  231. package/lib/Sound/RpgSound.js +0 -46
  232. package/lib/Sound/RpgSound.js.map +0 -1
  233. package/lib/Sound/Sound.d.ts +0 -78
  234. package/lib/Sound/Sound.js +0 -12
  235. package/lib/Sound/Sound.js.map +0 -1
  236. package/lib/Sound/Sounds.d.ts +0 -2
  237. package/lib/Sound/Sounds.js +0 -6
  238. package/lib/Sound/Sounds.js.map +0 -1
  239. package/lib/Sprite/Character.d.ts +0 -18
  240. package/lib/Sprite/Character.js +0 -131
  241. package/lib/Sprite/Character.js.map +0 -1
  242. package/lib/Sprite/Player.d.ts +0 -3
  243. package/lib/Sprite/Player.js +0 -4
  244. package/lib/Sprite/Player.js.map +0 -1
  245. package/lib/Sprite/Spritesheet.d.ts +0 -365
  246. package/lib/Sprite/Spritesheet.js +0 -13
  247. package/lib/Sprite/Spritesheet.js.map +0 -1
  248. package/lib/Sprite/Spritesheets.d.ts +0 -3
  249. package/lib/Sprite/Spritesheets.js +0 -6
  250. package/lib/Sprite/Spritesheets.js.map +0 -1
  251. package/lib/Tilemap/CommonLayer.d.ts +0 -10
  252. package/lib/Tilemap/CommonLayer.js +0 -17
  253. package/lib/Tilemap/CommonLayer.js.map +0 -1
  254. package/lib/Tilemap/ImageLayer.d.ts +0 -4
  255. package/lib/Tilemap/ImageLayer.js +0 -16
  256. package/lib/Tilemap/ImageLayer.js.map +0 -1
  257. package/lib/Tilemap/Tile.d.ts +0 -21
  258. package/lib/Tilemap/Tile.js +0 -67
  259. package/lib/Tilemap/Tile.js.map +0 -1
  260. package/lib/Tilemap/TileLayer.d.ts +0 -13
  261. package/lib/Tilemap/TileLayer.js +0 -122
  262. package/lib/Tilemap/TileLayer.js.map +0 -1
  263. package/lib/Tilemap/TileSet.d.ts +0 -7
  264. package/lib/Tilemap/TileSet.js +0 -24
  265. package/lib/Tilemap/TileSet.js.map +0 -1
  266. package/lib/Tilemap/index.d.ts +0 -28
  267. package/lib/Tilemap/index.js +0 -151
  268. package/lib/Tilemap/index.js.map +0 -1
  269. package/lib/clientEntryPoint.d.ts +0 -89
  270. package/lib/clientEntryPoint.js +0 -48
  271. package/lib/clientEntryPoint.js.map +0 -1
  272. package/lib/index.d.ts +0 -26
  273. package/lib/index.js +0 -27
  274. package/lib/index.js.map +0 -1
  275. package/lib/inject.d.ts +0 -23
  276. package/lib/inject.js +0 -30
  277. package/lib/inject.js.map +0 -1
  278. package/rpg.toml +0 -14
  279. package/src/Components/AbstractComponent.ts +0 -120
  280. package/src/Components/BarComponent.ts +0 -181
  281. package/src/Components/Component.ts +0 -515
  282. package/src/Components/DebugComponent.ts +0 -36
  283. package/src/Components/ImageComponent.ts +0 -30
  284. package/src/Components/ShapeComponent.ts +0 -64
  285. package/src/Components/TextComponent.ts +0 -33
  286. package/src/Components/TileComponent.ts +0 -43
  287. package/src/Effects/Animation.ts +0 -310
  288. package/src/Effects/AnimationCharacter.ts +0 -7
  289. package/src/Effects/Spinner.ts +0 -19
  290. package/src/Effects/Timeline.ts +0 -378
  291. package/src/Effects/TransitionScene.ts +0 -59
  292. package/src/GameEngine.ts +0 -289
  293. package/src/Gui/React.ts +0 -193
  294. package/src/Gui/Vue.ts +0 -154
  295. package/src/Interfaces/Character.ts +0 -7
  296. package/src/Interfaces/Scene.ts +0 -9
  297. package/src/KeyboardControls.ts +0 -748
  298. package/src/Logger.ts +0 -3
  299. package/src/Presets/Scene.ts +0 -3
  300. package/src/Renderer.ts +0 -334
  301. package/src/Resources.ts +0 -39
  302. package/src/Scene/EventLayer.ts +0 -9
  303. package/src/Scene/Map.ts +0 -402
  304. package/src/Scene/Scene.ts +0 -305
  305. package/src/Scene/SceneData.ts +0 -13
  306. package/src/Sound/RpgSound.ts +0 -50
  307. package/src/Sound/Sound.ts +0 -91
  308. package/src/Sound/Sounds.ts +0 -7
  309. package/src/Sprite/Character.ts +0 -157
  310. package/src/Sprite/Player.ts +0 -3
  311. package/src/Sprite/Spritesheet.ts +0 -392
  312. package/src/Sprite/Spritesheets.ts +0 -8
  313. package/src/Tilemap/CommonLayer.ts +0 -20
  314. package/src/Tilemap/ImageLayer.ts +0 -20
  315. package/src/Tilemap/Tile.ts +0 -80
  316. package/src/Tilemap/TileLayer.ts +0 -142
  317. package/src/Tilemap/TileSet.ts +0 -40
  318. package/src/Tilemap/index.ts +0 -175
  319. package/src/clientEntryPoint.ts +0 -150
  320. package/src/inject.ts +0 -34
  321. package/src/types/howler.d.ts +0 -73
@@ -1,43 +0,0 @@
1
- import { TileComponentObject } from "@rpgjs/types"
2
- import { SceneMap } from "../Scene/Map"
3
- import Tile from "../Tilemap/Tile"
4
- import TileLayer from "../Tilemap/TileLayer"
5
- import { AbstractComponent, CellInfo } from "./AbstractComponent"
6
- import { Container } from "pixi.js"
7
-
8
- export class TileComponent extends AbstractComponent<TileComponentObject, Container> {
9
- static readonly id: string = 'tile'
10
- cacheParams: string[] = []
11
- gid: number = 0
12
-
13
- onInit(cell: CellInfo) {
14
- this.cell = cell
15
- if (typeof this.value == 'number') {
16
- this.gid = this.value
17
- } else {
18
- this.gid = this.value.gid
19
- }
20
- this.updateRender({})
21
- super.onInit(cell)
22
- }
23
-
24
- updateRender(object: any) {
25
- this.removeChildren()
26
- const height = typeof this.value != 'number' ? this.getValue(object, this.value.height) : null ?? this.cell?.height ?? 0
27
- const width = typeof this.value != 'number' ? this.getValue(object, this.value.width) : null ?? this.cell?.width ?? 0
28
- const scene = this.component.getScene<SceneMap>()
29
- const tilemap = scene.tilemap
30
- const tileset = TileLayer.findTileSet(
31
- this.gid,
32
- tilemap.tilesets
33
- )
34
- if (tileset) {
35
- const tile = new Tile({
36
- gid: this.gid
37
- } as any, tileset)
38
- tile.width = width ?? 0
39
- tile.height = height ?? 0
40
- this.addChild(tile)
41
- }
42
- }
43
- }
@@ -1,310 +0,0 @@
1
- import { Utils } from '@rpgjs/common'
2
- import { spritesheets } from '../Sprite/Spritesheets'
3
- import { SpritesheetOptions, TextureOptions, AnimationFrames, FrameOptions, TransformOptions } from '../Sprite/Spritesheet'
4
- import { log } from '../Logger'
5
- import { RpgSound } from '../Sound/RpgSound'
6
- import { RpgComponent } from '../Components/Component'
7
- import { Sprite, Container, Texture, Rectangle } from 'pixi.js'
8
- import { Animation as AnimationEnum } from './AnimationCharacter'
9
- import { BehaviorSubject, Observable } from 'rxjs'
10
-
11
- const { isFunction, arrayEquals } = Utils
12
-
13
- type Image = { image: string }
14
-
15
- type TextureOptionsMerging = TextureOptions & {
16
- spriteWidth: number
17
- spriteHeight: number
18
- sound?: string
19
- } & Image & TransformOptions
20
-
21
- type FrameOptionsMerging = TextureOptionsMerging & FrameOptions
22
- type SpritesheetOptionsMerging = TextureOptionsMerging & SpritesheetOptions
23
- type TransformOptionsAsArray = Pick<TransformOptions, 'anchor' | 'scale' | 'skew' | 'pivot'>
24
-
25
- type AnimationDataFrames = {
26
- container: Container,
27
- sprites: FrameOptionsMerging[],
28
- frames: Texture[][],
29
- name: string,
30
- animations: AnimationFrames,
31
- params: any[],
32
- data: TextureOptionsMerging
33
- }
34
-
35
- export class Animation extends Sprite {
36
- private _attachTo: RpgComponent | undefined
37
- public hitbox: { w: number, h: number }
38
- public applyTransform: (
39
- frame: FrameOptionsMerging,
40
- data: TextureOptionsMerging,
41
- spritesheet: SpritesheetOptionsMerging
42
- ) => Partial<FrameOptionsMerging>
43
- private spritesheet: SpritesheetOptionsMerging
44
- private currentAnimation: AnimationDataFrames | null = null
45
- private time: number = 0
46
- private frameIndex: number = 0
47
- private animations: Map<string, AnimationDataFrames> = new Map()
48
- private _animation$: BehaviorSubject<Sprite | null> = new BehaviorSubject(null as any)
49
- readonly animation$: Observable<Sprite | null> = this._animation$.asObservable()
50
-
51
- onFinish: () => void
52
-
53
- get attachTo(): RpgComponent | undefined {
54
- return this._attachTo
55
- }
56
-
57
- set attachTo(component: RpgComponent | undefined) {
58
- if (!component) return
59
- component.animationIsPlaying = true
60
- this._attachTo = component
61
- }
62
-
63
- constructor(public id: string) {
64
- super()
65
- this.spritesheet = spritesheets.get(this.id)
66
- if (!this.spritesheet) {
67
- throw log(`Impossible to find the ${this.id} spritesheet. Did you put the right name or create the spritesheet?`)
68
- }
69
- this.createAnimations()
70
- }
71
-
72
- private createTextures(options: Required<TextureOptionsMerging>): Texture[][] {
73
- const { width, height, framesHeight, framesWidth, image, offset } = options
74
- const { baseTexture } = Texture.from(image)
75
- const spriteWidth = options.spriteWidth
76
- const spriteHeight = options.spriteHeight
77
- const frames: Texture[][] = []
78
- const offsetX = (offset && offset.x) || 0
79
- const offsetY = (offset && offset.y) || 0
80
- for (let i = 0; i < framesHeight; i++) {
81
- frames[i] = []
82
- for (let j = 0; j < framesWidth; j++) {
83
- const rectX = j * spriteWidth + offsetX
84
- const rectY = i * spriteHeight + offsetY
85
- if (rectY > height) {
86
- throw log(`Warning, there is a problem with the height of the "${this.id}" spritesheet. When cutting into frames, the frame exceeds the height of the image.`)
87
- }
88
- if (rectX > width) {
89
- throw log(`Warning, there is a problem with the width of the "${this.id}" spritesheet. When cutting into frames, the frame exceeds the width of the image.`)
90
- }
91
- frames[i].push(
92
- new Texture(baseTexture, new Rectangle(rectX, rectY, spriteWidth, spriteHeight))
93
- )
94
- }
95
- }
96
- return frames
97
- }
98
-
99
- private createAnimations() {
100
- const { textures } = this.spritesheet
101
- if (!textures) {
102
- return
103
- }
104
- for (let animationName in textures) {
105
- const props: (keyof TextureOptionsMerging)[] = ['width', 'height', 'framesHeight', 'framesWidth', 'rectWidth', 'rectHeight', 'offset', 'image', 'sound']
106
- const parentObj = props
107
- .reduce((prev, val) => ({ ...prev, [val]: this.spritesheet[val] }), {})
108
- const optionsTextures: TextureOptionsMerging = {
109
- ...parentObj,
110
- ...textures[animationName]
111
- } as any
112
- const { rectWidth, width = 0, framesWidth = 1, rectHeight, height = 0, framesHeight = 1 } = optionsTextures
113
- optionsTextures.spriteWidth = rectWidth ? rectWidth : width / framesWidth
114
- optionsTextures.spriteHeight = rectHeight ? rectHeight : height / framesHeight
115
- this.animations.set(animationName, {
116
- container: new Sprite(),
117
- frames: this.createTextures(optionsTextures as Required<TextureOptionsMerging>),
118
- name: animationName,
119
- animations: textures[animationName].animations,
120
- params: [],
121
- data: optionsTextures,
122
- sprites: []
123
- })
124
- }
125
- }
126
-
127
- private getSpriteSize(name: 'spriteHeight' | 'spriteWidth'): number {
128
- return this.animations.get(this.currentAnimation?.name || AnimationEnum.Stand)?.data[name] || 0
129
- }
130
-
131
- getSpriteHeight(): number {
132
- return this.getSpriteSize('spriteHeight')
133
- }
134
-
135
- getSpriteWidth(): number {
136
- return this.getSpriteSize('spriteWidth')
137
- }
138
-
139
- has(name: string): boolean {
140
- return this.animations.has(name)
141
- }
142
-
143
- get(name: string): AnimationDataFrames {
144
- return this.animations.get(name) as AnimationDataFrames
145
- }
146
-
147
- isPlaying(name?: string): boolean {
148
- if (!name) return !!this.currentAnimation
149
- if (this.currentAnimation == null) return false
150
- return this.currentAnimation.name == name
151
- }
152
-
153
- stop() {
154
- this.currentAnimation = null
155
- this.parent?.removeChild(this)
156
- }
157
-
158
- play(name: string, params: any[] = []) {
159
- const animParams = this.currentAnimation?.params
160
-
161
- if (this.isPlaying(name) && arrayEquals(params, animParams || [])) return
162
-
163
- const animation = this.get(name)
164
-
165
- if (!animation) {
166
- throw new Error(`Impossible to play the ${name} animation because it doesn't exist on the ${this.id} spritesheet`)
167
- }
168
-
169
- this.removeChildren()
170
- animation.sprites = []
171
- this.currentAnimation = animation
172
- this.currentAnimation.params = params
173
- this.time = 0
174
- this.frameIndex = 0
175
-
176
- let animations: any = animation.animations;
177
- animations = isFunction(animations) ? (animations as Function)(...params) : animations
178
-
179
- this.currentAnimation.container = new Container()
180
-
181
- for (let container of (animations as FrameOptionsMerging[][])) {
182
- const sprite = new Sprite()
183
- for (let frame of container) {
184
- this.currentAnimation.sprites.push(frame)
185
- }
186
- this.currentAnimation.container.addChild(sprite)
187
- }
188
-
189
- const sound = this.currentAnimation.data.sound
190
-
191
- if (sound) {
192
- RpgSound.get(sound).play()
193
- }
194
-
195
- this.addChild(this.currentAnimation.container)
196
- // Updates immediately to avoid flickering
197
- this.update(1)
198
- }
199
-
200
- update(deltaRatio: number) {
201
- if (!this.isPlaying() || !this.currentAnimation) return
202
-
203
- const { frames, container, sprites, data } = this.currentAnimation
204
- let frame = sprites[this.frameIndex]
205
- const nextFrame = sprites[this.frameIndex + 1]
206
-
207
- if (this.attachTo) {
208
- const sprite = this.attachTo
209
- const pos = sprite?.getPositionsOfGraphic('middle')
210
- if (pos) {
211
- container.x = pos.x
212
- container.y = pos.y
213
- }
214
- }
215
-
216
- for (let _sprite of container.children) {
217
- const sprite = _sprite as Sprite
218
-
219
- if (!frame || frame.frameY == undefined || frame.frameX == undefined) {
220
- continue
221
- }
222
-
223
- sprite.texture = frames[frame.frameY][frame.frameX]
224
-
225
- const getVal = <T extends keyof TransformOptions>(prop: T): TransformOptions[T] | undefined =>
226
- frame[prop] || data[prop] || this.spritesheet[prop]
227
-
228
- const applyTransform = <T extends keyof TransformOptionsAsArray>(prop: T): void => {
229
- const val = getVal<T>(prop)
230
- if (val) {
231
- sprite[prop as string].set(...val!)
232
- }
233
- }
234
-
235
- function applyTransformValue<T extends keyof TransformOptions>(prop: T);
236
- function applyTransformValue<T extends keyof TransformOptions>(prop: string, alias: T);
237
- function applyTransformValue<T extends keyof TransformOptions>(prop: T, alias?: T): void {
238
- const optionProp = alias || prop
239
- const val = getVal<T>(optionProp)
240
- if (val !== undefined) {
241
- sprite[prop as string] = val
242
- }
243
- }
244
-
245
- if (this.applyTransform) {
246
- frame = {
247
- ...frame,
248
- ...this.applyTransform(frame, data, this.spritesheet)
249
- }
250
-
251
- }
252
-
253
- const realSize = getVal<'spriteRealSize'>('spriteRealSize')
254
- const heightOfSprite = typeof realSize == 'number' ? realSize : realSize?.height
255
- const widthOfSprite = typeof realSize == 'number' ? realSize : realSize?.width
256
-
257
- const applyAnchorBySize = () => {
258
- if (heightOfSprite && this.hitbox) {
259
- const { spriteWidth, spriteHeight } = data
260
- const w = ((spriteWidth - this.hitbox.w) / 2) / spriteWidth
261
- const gap = (spriteHeight - heightOfSprite) / 2
262
- const h = (spriteHeight - this.hitbox.h - gap) / spriteHeight
263
- sprite.anchor.set(w, h)
264
- }
265
- }
266
-
267
- if (frame.sound) {
268
- RpgSound.get(frame.sound).play()
269
- }
270
-
271
- applyAnchorBySize()
272
-
273
- applyTransform('anchor')
274
- applyTransform('scale')
275
- applyTransform('skew')
276
- applyTransform('pivot')
277
-
278
- applyTransformValue('alpha', 'opacity')
279
- applyTransformValue('x')
280
- applyTransformValue('y')
281
- applyTransformValue('angle')
282
- applyTransformValue('rotation')
283
- applyTransformValue('visible')
284
-
285
- this._animation$.next({
286
- spriteWidth: widthOfSprite || sprite.width,
287
- spriteHeight: heightOfSprite || sprite.height,
288
- anchor: sprite.anchor,
289
- width: getVal<any>('spriteWidth'),
290
- height: getVal<any>('spriteHeight')
291
- } as any)
292
- }
293
-
294
- if (!nextFrame) {
295
- this.time = 0
296
- this.frameIndex = 0
297
- if (this.attachTo) {
298
- this.attachTo.animationIsPlaying = false
299
- }
300
- if (this.onFinish) this.onFinish()
301
- return
302
- }
303
-
304
- this.time += deltaRatio
305
-
306
- if (this.time >= nextFrame.time) {
307
- this.frameIndex++
308
- }
309
- }
310
- }
@@ -1,7 +0,0 @@
1
- export enum Animation {
2
- Stand = 'stand',
3
- Walk = 'walk',
4
- Attack = 'attack',
5
- Defense = 'defense',
6
- Skill = 'skill'
7
- }
@@ -1,19 +0,0 @@
1
- import { RpgClientEngine } from "../RpgClientEngine";
2
- import { Graphics, Renderer } from "pixi.js";
3
-
4
- export class SpinnerGraphic extends Graphics {
5
- constructor(private clientEngine: RpgClientEngine) {
6
- super()
7
- }
8
-
9
- render(renderer: Renderer) {
10
- super.render(renderer)
11
- this.rotation += 0.12;
12
- const percent = Math.abs(Math.sin(Date.now() / 1000))
13
- this
14
- .clear()
15
- .lineStyle(4, 0xffffff, 1)
16
- .moveTo(40, 0)
17
- .arc(0, 0, 40, 0, Math.PI * 2 * percent, false)
18
- }
19
- }