@rpgjs/client 4.2.2 → 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 -42
  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 -534
  104. package/src/RpgClient.ts +9 -5
  105. package/src/RpgClientEngine.ts +135 -815
  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 -177
  133. package/LICENSE +0 -19
  134. package/browser/React-f6f9b1de.js +0 -157
  135. package/browser/index-e74a289f.js +0 -44225
  136. package/browser/manifest.json +0 -21
  137. package/browser/rpg.client.js +0 -40
  138. package/browser/rpg.client.umd.cjs +0 -44414
  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 -490
  183. package/lib/Gui/Gui.js.map +0 -1
  184. package/lib/Gui/React.d.ts +0 -15
  185. package/lib/Gui/React.js +0 -113
  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 -674
  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 -145
  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
@@ -0,0 +1,104 @@
1
+ <Container x y zIndex={y} viewportFollow={isMe} controls>
2
+ <Particle emit={@emitParticleTrigger} settings={@particleSettings} zIndex={1000} name={particleName} />
3
+ @for (graphicId of graphics) {
4
+ <Sprite sheet={@sheet(@graphicId)} direction tint />
5
+ }
6
+ <!-- <Ellipse
7
+ x={shadow.@x}
8
+ y={shadow.@y}
9
+ width={shadow.@width}
10
+ height={shadow.@height}
11
+ color="black"
12
+ blur={10}
13
+ alpha={0.5}
14
+ /> -->
15
+ </Container>
16
+
17
+ <script>
18
+ import { signal, effect, mount, computed } from "canvasengine";
19
+ import { Particle } from "@canvasengine/presets";
20
+ import { GameEngineToken } from "@rpgjs/common";
21
+ import { RpgClientEngine } from "../RpgClientEngine";
22
+ import { inject } from "../core/inject";
23
+ import { Direction } from "@rpgjs/common";
24
+ import Hit from "./effects/hit.ce";
25
+
26
+ const { object, id, isMe } = defineProps();
27
+
28
+ const client = inject(RpgClientEngine);
29
+
30
+ const spritesheets = client.spritesheets;
31
+
32
+ const x = object.x;
33
+ const y = object.y;
34
+ const tint = object.tint;
35
+ const direction = object.direction;
36
+ const animationName = object.animationName;
37
+ const emitParticleTrigger = object.emitParticleTrigger;
38
+ const particleSettings = client.particleSettings;
39
+ const particleName = object.particleName;
40
+ const graphics = object.graphics;
41
+
42
+ const hitbox = object.hitbox;
43
+ const widthShadow = 10;
44
+ const shadow = computed(() => ({
45
+ x: hitbox().w / 2,
46
+ y: hitbox().h - (hitbox().h / 2),
47
+ width: hitbox().w + widthShadow,
48
+ height: hitbox().h,
49
+ }))
50
+ const canControls = () => isMe() && object.canMove()
51
+ const keyboardControls = client.globalConfig.keyboardControls;
52
+
53
+ const controls = signal({
54
+ down: {
55
+ repeat: true,
56
+ bind: keyboardControls.down,
57
+ keyDown() {
58
+ if (canControls()) client.processInput({ input: Direction.Down })
59
+ },
60
+ },
61
+ up: {
62
+ repeat: true,
63
+ bind: keyboardControls.up,
64
+ keyDown() {
65
+ if (canControls()) client.processInput({ input: Direction.Up })
66
+ },
67
+ },
68
+ left: {
69
+ repeat: true,
70
+ bind: keyboardControls.left,
71
+ keyDown() {
72
+ if (canControls()) client.processInput({ input: Direction.Left })
73
+ },
74
+ },
75
+ right: {
76
+ repeat: true,
77
+ bind: keyboardControls.right,
78
+ keyDown() {
79
+ if (canControls()) client.processInput({ input: Direction.Right })
80
+ },
81
+ },
82
+ action: {
83
+ bind: keyboardControls.action,
84
+ keyDown() {
85
+ if (canControls()) {
86
+ client.processAction({ action: 'action' })
87
+ // particleName.set('hit')
88
+ // emitParticleTrigger.start()
89
+ // object.flash('red')
90
+ }
91
+ },
92
+ },
93
+ });
94
+
95
+ const sheet = (graphicId) => {
96
+ return {
97
+ definition: spritesheets.get(graphicId),
98
+ playing: animationName,
99
+ params: {
100
+ direction
101
+ },
102
+ };
103
+ }
104
+ </script>
@@ -0,0 +1,19 @@
1
+ <Sprite sheet x y anchor={0.5} />
2
+
3
+ <script>
4
+ import { signal } from "canvasengine";
5
+ import { RpgClientEngine } from "../../RpgClientEngine";
6
+ import { inject } from "../../core/inject";
7
+
8
+ const { x, y, name, onFinish } = defineProps();
9
+
10
+ const client = inject(RpgClientEngine);
11
+ const spritesheets = client.spritesheets;
12
+
13
+ const sheet = {
14
+ definition: spritesheets.get(name()),
15
+ playing: 'default',
16
+ onFinish
17
+ };
18
+
19
+ </script>
@@ -0,0 +1,87 @@
1
+ <Text x y zIndex={10000} color scale size={30} text />
2
+
3
+ <script>
4
+ import { animatedSignal, mount, signal, tick } from "canvasengine";
5
+ import { Direction } from "@rpgjs/common";
6
+ const {
7
+ text,
8
+ direction,
9
+ onFinish,
10
+ duration,
11
+ color,
12
+ x: positionX,
13
+ y: positionY
14
+ } = defineProps({
15
+ duration: {
16
+ default: 1000
17
+ },
18
+ color: {
19
+ default: 'black'
20
+ }
21
+ });
22
+
23
+ const scale = animatedSignal(1, {
24
+ duration: duration(),
25
+ });
26
+
27
+ // Generate random initial position
28
+ const randomPosition = () => Math.floor(Math.random() * 60);
29
+ const initialY = randomPosition();
30
+ const x = signal(positionX());
31
+ const y = signal(positionY() - initialY);
32
+
33
+ // Initial velocity
34
+ let velocityX = 0;
35
+ let velocityY = 0;
36
+
37
+ // Set initial velocity based on direction
38
+ const speed = 200;
39
+ switch (direction()) {
40
+ case Direction.Left:
41
+ velocityX = speed;
42
+ break;
43
+ case Direction.Right:
44
+ velocityX = -speed;
45
+ break;
46
+ case Direction.Up:
47
+ velocityY = speed;
48
+ break;
49
+ case Direction.Down:
50
+ velocityY = -speed;
51
+ break;
52
+ }
53
+
54
+ // Add some randomness to the velocity
55
+ velocityX += (Math.random() - 0.5) * 100;
56
+ velocityY += (Math.random() - 0.5) * 100;
57
+
58
+ const gravity = 500; // Gravity effect
59
+ const deceleration = 0.98; // Deceleration factor
60
+
61
+ mount(() => {
62
+ scale.set(0.1);
63
+ });
64
+
65
+ let elapsedTime = 0;
66
+
67
+ tick(({ deltaTime }) => {
68
+ elapsedTime += deltaTime;
69
+
70
+ if (elapsedTime < duration()) {
71
+ // Update position
72
+ x.update((x) => x + (velocityX * deltaTime) / 1000);
73
+ y.update((y) => y + (velocityY * deltaTime) / 1000);
74
+
75
+ // Apply gravity
76
+ velocityY += (gravity * deltaTime) / 1000;
77
+
78
+ // Apply deceleration
79
+ velocityX *= deceleration;
80
+ velocityY *= deceleration;
81
+ } else {
82
+ if (onFinish) {
83
+ onFinish();
84
+ }
85
+ }
86
+ });
87
+ </script>
@@ -0,0 +1,7 @@
1
+ import Hit from "./hit.ce";
2
+ import Animation from "./animation.ce";
3
+
4
+ export const PrebuiltEffects = {
5
+ Hit,
6
+ Animation
7
+ }
@@ -0,0 +1,194 @@
1
+ <Container justifyContent="center" alignItems="center" width="100%" height="100%">
2
+ <Container
3
+ ref="dialogbox"
4
+ scale={{ x: scaleX }}
5
+ anchor={[0.5, 0.5]}
6
+ width={700}
7
+ height
8
+ controls
9
+ positionType="absolute"
10
+ bottom={10}
11
+ >
12
+ <Rect width={700} height={250} color="#1a1a2e" />
13
+ <Rect
14
+ x={0}
15
+ y={0}
16
+ width={700}
17
+ height
18
+ color="#1a1a2e"
19
+ alpha={0.9}
20
+ borderRadius={10}
21
+ border
22
+ shadow
23
+ />
24
+ <Container
25
+ flexDirection="row"
26
+ width={700}
27
+ height
28
+ alpha={contentOpacity}
29
+ >
30
+ <Container flexDirection="column">
31
+ <Text
32
+ text
33
+ color="#fff"
34
+ fontSize={18}
35
+ margin={40}
36
+ typewriter
37
+ style={textStyle}
38
+ />
39
+ @if (visibleSelection) {
40
+ <Selection selectedIndex={0} items={choices} onSelect />
41
+ }
42
+ </Container>
43
+ </Container>
44
+ </Container>
45
+
46
+
47
+ </Container>
48
+ <script>
49
+ import Selection from './selection.ce'
50
+
51
+ import {
52
+ animatedSignal,
53
+ computed,
54
+ effect,
55
+ signal,
56
+ trigger,
57
+ mount
58
+ } from "canvasengine";
59
+
60
+ import { inject } from "../../../core/inject";
61
+ import { RpgClientEngine } from "../../../RpgClientEngine";
62
+
63
+ const {
64
+ message,
65
+ choices: _choices,
66
+ onFinish,
67
+ onInteraction
68
+ } = defineProps();
69
+
70
+ const client = inject(RpgClientEngine);
71
+ const keyboardControls = client.globalConfig.keyboardControls;
72
+
73
+ client.stopProcessingInput = true;
74
+ let isDestroyed = false;
75
+
76
+ const texts = [message()]
77
+ const height = signal(250);
78
+ const isTextCompleted = signal(false);
79
+
80
+ const drawSpeaker = (g) => {
81
+ g.beginFill(0xffa500); // Orange color
82
+ g.lineStyle(2, 0x000000); // Black border
83
+ g.moveTo(0, 0);
84
+ g.lineTo(70, 0);
85
+ g.lineTo(80, 15);
86
+ g.lineTo(70, 30);
87
+ g.lineTo(0, 30);
88
+ g.lineTo(0, 0);
89
+ g.endFill();
90
+ };
91
+
92
+ const border = signal({ width: 5, color: "#595971" });
93
+ const shadow = signal({ color: "#000", blur: 10, offsetX: 10, offsetY: 10 });
94
+
95
+ const contentOpacity = animatedSignal(0, {
96
+ duration: 1000,
97
+ });
98
+
99
+ const scaleX = animatedSignal(0, {
100
+ duration: 500,
101
+ });
102
+
103
+ scaleX.set(1);
104
+ contentOpacity.set(1);
105
+
106
+ const currentTextIndex = signal(0);
107
+ const currentText = computed(() => texts?.[currentTextIndex()] ?? '');
108
+ const isChoiceDisplayed = signal(false);
109
+
110
+ const text = computed(() => {
111
+ const current = currentText();
112
+ return typeof current === "string" ? current : current.text;
113
+ });
114
+
115
+ const choices = computed(() => {
116
+ //const current = currentText();
117
+ //return typeof current === "string" ? null : current.choices;
118
+ return _choices;
119
+ });
120
+
121
+ const visibleSelection = computed(() => isChoiceDisplayed() && choices().length != 0)
122
+
123
+ const triggerSkip = trigger();
124
+
125
+ const typewriter = {
126
+ speed: 0.3,
127
+ skip: triggerSkip,
128
+ onComplete: () => {
129
+ isTextCompleted.set(true);
130
+ }
131
+ }
132
+
133
+ const textStyle = {
134
+ wordWrap: true,
135
+ wordWrapWidth: 700 - 256 - 80
136
+ }
137
+
138
+ const face = signal({ x: 0, y: 0, width: 256, height: 256 });
139
+
140
+ mount((element) => {
141
+ const [dialogbox] = element.props.children
142
+ return () => {
143
+ dialogbox.directives.controls.onDestroy()
144
+ isDestroyed = true;
145
+ // Wait destroy is finished before start processing input
146
+ setTimeout(() => {
147
+ client.stopProcessingInput = false;
148
+ }, 500)
149
+ }
150
+ })
151
+
152
+ const controls = signal({
153
+ next: {
154
+ bind: keyboardControls.action,
155
+ keyDown(e) {
156
+ if (isDestroyed) return;
157
+ if (isChoiceDisplayed()) {
158
+ // If choices are displayed, do nothing (wait for selection)
159
+ return;
160
+ }
161
+
162
+ // If text is still typing, just skip (fast forward) the animation
163
+ if (!isTextCompleted()) {
164
+ triggerSkip.start();
165
+ isTextCompleted.set(true);
166
+ }
167
+ else {
168
+ const isFinished = currentTextIndex() === texts.length - 1;
169
+ currentTextIndex.update((index) => {
170
+ if (index < texts.length - 1) {
171
+ return index + 1;
172
+ }
173
+ return index;
174
+ });
175
+ isChoiceDisplayed.set(false);
176
+ isTextCompleted.set(false);
177
+ if (isFinished && onFinish) {
178
+ onFinish();
179
+ }
180
+ }
181
+ },
182
+ },
183
+ });
184
+
185
+ const onSelect = (index) => {
186
+ onFinish(index);
187
+ }
188
+
189
+ effect(() => {
190
+ if (choices().length != 0) {
191
+ isChoiceDisplayed.set(true);
192
+ }
193
+ });
194
+ </script>
@@ -0,0 +1,23 @@
1
+ <Container>
2
+ <Rect width height color="#595971" alpha visible={isSelected} />
3
+ <Container flexDirection="row" alignItems="center" justifyContent="center">
4
+ <Text text color="#fff" fontSize={18} margin={10} />
5
+ </Container>
6
+ </Container>
7
+
8
+ <script>
9
+ import { animatedSignal } from "canvasengine";
10
+
11
+ const { text, isSelected } = defineProps();
12
+
13
+ const alpha = animatedSignal(1, {
14
+ repeatType: "reverse",
15
+ duration: 500,
16
+ repeat: Infinity,
17
+ });
18
+
19
+ alpha.set(0.5);
20
+
21
+ const height = 40;
22
+ const width = 256;
23
+ </script>
@@ -0,0 +1,67 @@
1
+ <Container controls flexDirection="column" margin={[0, 0, 0, 50]}>
2
+ @for ((item,index) of items) {
3
+ <ItemMenu text={@item.@text} isSelected={@selected(@index)} />
4
+ }
5
+ </Container>
6
+
7
+ <script>
8
+ import { signal, computed, mount } from "canvasengine";
9
+ import ItemMenu from "./itemMenu.ce";
10
+ import { RpgClientEngine } from "../../../RpgClientEngine";
11
+ import { inject } from "../../../core/inject";
12
+
13
+ const {
14
+ items,
15
+ wrapAround,
16
+ onSelect,
17
+ selectedIndex,
18
+ } = defineProps();
19
+
20
+ const client = inject(RpgClientEngine);
21
+ const keyboardControls = client.globalConfig.keyboardControls;
22
+
23
+ const selected = (index) => {
24
+ return computed(() => {
25
+ return index === selectedIndex();
26
+ })
27
+ }
28
+
29
+ mount((element) => {
30
+ return () => {
31
+ element.directives.controls.onDestroy()
32
+ }
33
+ })
34
+
35
+ const controls = signal({
36
+ down: {
37
+ bind: keyboardControls.down,
38
+ keyDown() {
39
+ selectedIndex.update((currentIndex) => {
40
+ if (wrapAround) {
41
+ return (currentIndex + 1) % items().length;
42
+ } else {
43
+ return Math.min(currentIndex + 1, items().length - 1);
44
+ }
45
+ });
46
+ },
47
+ },
48
+ up: {
49
+ bind: keyboardControls.up,
50
+ keyDown() {
51
+ selectedIndex.update((currentIndex) => {
52
+ if (wrapAround) {
53
+ return (currentIndex - 1 + items().length) % items().length;
54
+ } else {
55
+ return Math.max(currentIndex - 1, 0);
56
+ }
57
+ });
58
+ },
59
+ },
60
+ enter: {
61
+ bind: keyboardControls.action,
62
+ keyDown() {
63
+ onSelect?.(selectedIndex());
64
+ },
65
+ },
66
+ });
67
+ </script>
@@ -0,0 +1,5 @@
1
+ import Dialogbox from "./dialogbox/index.ce";
2
+
3
+ export const PrebuiltGui = {
4
+ Dialogbox
5
+ }
@@ -0,0 +1,3 @@
1
+ import EventLayerComponent from "./scenes/event-layer.ce";
2
+
3
+ export { EventLayerComponent }
@@ -0,0 +1,51 @@
1
+ <Canvas width={@engine.width} height={@engine.height}>
2
+ <Viewport worldWidth worldHeight clamp>
3
+ @if (sceneData) {
4
+ <SceneMap />
5
+ }
6
+ </Viewport>
7
+ @for (gui of gui) {
8
+ <Container display="flex">
9
+ @if (gui.display) {
10
+ <gui.component ...gui.data() onFinish={(data) => {
11
+ onGuiFinish(gui, data)
12
+ }} onInteraction={(name, data) => {
13
+ onGuiInteraction(gui, name, data)
14
+ }} />
15
+ }
16
+ </Container>
17
+ }
18
+ </Canvas>
19
+
20
+ <script>
21
+ import { signal, computed, effect } from "canvasengine";
22
+ import { inject } from "../../core/inject";
23
+ import { RpgClientEngine } from "../../RpgClientEngine";
24
+ import SceneMap from './draw-map.ce'
25
+ import { RpgGui } from "../../Gui/Gui";
26
+
27
+ const engine = inject(RpgClientEngine);
28
+ const guiService = inject(RpgGui);
29
+ const sceneData = engine.sceneMap.data
30
+ const gui = guiService.gui
31
+ const worldWidth = computed(() => sceneData()?.width)
32
+ const worldHeight = computed(() => sceneData()?.height)
33
+
34
+ effect(() => {
35
+ if (sceneData() && !sceneData().component) {
36
+ throw new Error("Warning ! You need to define a component for the scene. Use provideLoadMap() to define a component for the scene.")
37
+ }
38
+ })
39
+
40
+ const onGuiFinish = (gui, data) => {
41
+ guiService.guiClose(gui.name, data)
42
+ }
43
+
44
+ const onGuiInteraction = (gui, name, data) => {
45
+ guiService.guiInteraction(gui.name, name, data)
46
+ }
47
+
48
+ const clamp = {
49
+ direction: "all"
50
+ }
51
+ </script>
@@ -0,0 +1,56 @@
1
+ <Container sound={backgroundMusic} >
2
+ <Container sound={backgroundAmbientSound} />
3
+
4
+ <!-- <Sprite image={map.@fullImage} scale /> -->
5
+
6
+ <sceneComponent() data={map.@data} />
7
+
8
+ <!-- <Container sortableChildren={true}>
9
+ @for (obj of middleLayer) {
10
+ <ElementMap ...obj image={map.@gridImage} scale />
11
+ }
12
+
13
+ @for ((event,id) of events) {
14
+ <Character id={id} object={event} isMe={false} />
15
+ }
16
+
17
+ @for ((player,id) of players) {
18
+ <Character id={id} object={player} isMe={true} />
19
+ }
20
+ </Container> -->
21
+
22
+ @for (effect of effects) {
23
+ <Container>
24
+ @for (animation of effect.current) {
25
+ <effect.component ...animation />
26
+ }
27
+ </Container>
28
+ }
29
+ </Container>
30
+
31
+ <script>
32
+ import { effect, signal, computed, mount } from 'canvasengine'
33
+ import { inject } from "../../core/inject";
34
+ import { RpgClientEngine } from "../../RpgClientEngine";
35
+
36
+ const engine = inject(RpgClientEngine);
37
+ const effects = engine.effects
38
+ const map = engine.sceneMap.data
39
+ const sceneComponent = computed(() => map()?.component)
40
+ const mapParams = map().params
41
+ const animations = engine.sceneMap.animations
42
+ const backgroundMusic = { src: mapParams?.backgroundMusic, autoplay: true, loop: true }
43
+ const backgroundAmbientSound = { src: mapParams?.backgroundAmbientSound, autoplay: true, loop: true }
44
+
45
+ const data = signal(map().data)
46
+ // const middleLayer = computed(() => data().filter(obj => obj.layer === 1))
47
+ // const topLayer = computed(() => data().filter(obj => obj.layer === 2))
48
+
49
+ const scale = mapParams?.scale || 1
50
+ const worldWidth = (mapParams?.width || 2048) * scale
51
+ const worldHeight = (mapParams?.height || 2048) * scale
52
+
53
+ const clamp = {
54
+ direction: "all"
55
+ }
56
+ </script>
@@ -0,0 +1,23 @@
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
+
@@ -0,0 +1,20 @@
1
+ <Container sortableChildren={true}>
2
+ @for ((event,id) of events) {
3
+ <Character id={id} object={event} isMe={false} />
4
+ }
5
+
6
+ @for ((player,id) of players) {
7
+ <Character id={id} object={player} isMe={true} />
8
+ }
9
+ </Container>
10
+
11
+ <script>
12
+ import { effect, signal, computed, mount } from 'canvasengine'
13
+ import { inject } from "../../core/inject";
14
+ import { RpgClientEngine } from "../../RpgClientEngine";
15
+ import Character from "../character.ce";
16
+
17
+ const engine = inject(RpgClientEngine);
18
+ const players = engine.sceneMap.players
19
+ const events = engine.sceneMap.events
20
+ </script>
@@ -0,0 +1,17 @@
1
+ import { Context, inject as injector } from "@signe/di";
2
+
3
+ export let context: Context | null = null
4
+
5
+ export function inject<T>(service: (new (...args: any[]) => T) | string, _context?: Context): T {
6
+ const c = _context ?? context
7
+ if (!c) throw new Error("Context is not set. use setInject() to set the context");
8
+ return injector(c, service);
9
+ }
10
+
11
+ export function setInject(_context: Context) {
12
+ context = _context;
13
+ }
14
+
15
+ export function clearInject() {
16
+ context = null
17
+ }