@rpgjs/client 4.3.0 → 5.0.0-alpha.1

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 (323) 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 +316 -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 +91 -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/index39.js +20 -0
  79. package/dist/index39.js.map +1 -0
  80. package/dist/index4.js +54 -0
  81. package/dist/index4.js.map +1 -0
  82. package/dist/index5.js +15 -0
  83. package/dist/index5.js.map +1 -0
  84. package/dist/index6.js +17 -0
  85. package/dist/index6.js.map +1 -0
  86. package/dist/index7.js +31 -0
  87. package/dist/index7.js.map +1 -0
  88. package/dist/index8.js +90 -0
  89. package/dist/index8.js.map +1 -0
  90. package/dist/index9.js +76 -0
  91. package/dist/index9.js.map +1 -0
  92. package/dist/module.d.ts +14 -0
  93. package/dist/presets/index.d.ts +22 -0
  94. package/{lib/Presets/AnimationSpritesheet.d.ts → dist/presets/rmspritesheet.d.ts} +6 -2
  95. package/dist/services/AbstractSocket.d.ts +15 -0
  96. package/dist/services/loadMap.d.ts +14 -0
  97. package/dist/services/mmorpg.d.ts +32 -0
  98. package/dist/services/standalone.d.ts +34 -0
  99. package/package.json +25 -41
  100. package/src/Game/EffectManager.ts +20 -0
  101. package/src/Game/Event.ts +5 -0
  102. package/src/Game/Map.ts +10 -0
  103. package/src/Game/Object.ts +16 -0
  104. package/src/Game/Player.ts +5 -0
  105. package/src/Gui/Gui.ts +80 -533
  106. package/src/RpgClient.ts +9 -5
  107. package/src/RpgClientEngine.ts +135 -818
  108. package/src/components/character.ce +104 -0
  109. package/src/components/effects/animation.ce +19 -0
  110. package/src/components/effects/hit.ce +87 -0
  111. package/src/components/effects/index.ts +7 -0
  112. package/src/components/gui/dialogbox/index.ce +194 -0
  113. package/src/components/gui/dialogbox/itemMenu.ce +23 -0
  114. package/src/components/gui/dialogbox/selection.ce +67 -0
  115. package/src/components/gui/index.ts +5 -0
  116. package/src/components/index.ts +3 -0
  117. package/src/components/scenes/canvas.ce +51 -0
  118. package/src/components/scenes/draw-map.ce +56 -0
  119. package/src/components/scenes/element-map.ce +23 -0
  120. package/src/components/scenes/event-layer.ce +20 -0
  121. package/src/core/inject.ts +17 -0
  122. package/src/core/setup.ts +18 -0
  123. package/src/index.ts +13 -29
  124. package/src/module.ts +93 -0
  125. package/src/presets/index.ts +5 -0
  126. package/src/{Presets/AnimationSpritesheet.ts → presets/rmspritesheet.ts} +4 -5
  127. package/src/services/AbstractSocket.ts +14 -0
  128. package/src/services/loadMap.ts +33 -0
  129. package/src/services/mmorpg.ts +64 -0
  130. package/src/services/standalone.ts +101 -0
  131. package/src/types/canvas-engine.d.ts +26 -0
  132. package/tsconfig.json +8 -3
  133. package/vite.config.ts +34 -0
  134. package/CHANGELOG.md +0 -189
  135. package/LICENSE +0 -19
  136. package/browser/React-ece4b906.js +0 -195
  137. package/browser/index-ba657126.js +0 -44229
  138. package/browser/manifest.json +0 -21
  139. package/browser/rpg.client.js +0 -40
  140. package/browser/rpg.client.umd.cjs +0 -44456
  141. package/lib/Components/AbstractComponent.d.ts +0 -32
  142. package/lib/Components/AbstractComponent.js +0 -93
  143. package/lib/Components/AbstractComponent.js.map +0 -1
  144. package/lib/Components/BarComponent.d.ts +0 -21
  145. package/lib/Components/BarComponent.js +0 -169
  146. package/lib/Components/BarComponent.js.map +0 -1
  147. package/lib/Components/Component.d.ts +0 -124
  148. package/lib/Components/Component.js +0 -425
  149. package/lib/Components/Component.js.map +0 -1
  150. package/lib/Components/DebugComponent.d.ts +0 -11
  151. package/lib/Components/DebugComponent.js +0 -32
  152. package/lib/Components/DebugComponent.js.map +0 -1
  153. package/lib/Components/ImageComponent.d.ts +0 -11
  154. package/lib/Components/ImageComponent.js +0 -30
  155. package/lib/Components/ImageComponent.js.map +0 -1
  156. package/lib/Components/ShapeComponent.d.ts +0 -11
  157. package/lib/Components/ShapeComponent.js +0 -57
  158. package/lib/Components/ShapeComponent.js.map +0 -1
  159. package/lib/Components/TextComponent.d.ts +0 -11
  160. package/lib/Components/TextComponent.js +0 -35
  161. package/lib/Components/TextComponent.js.map +0 -1
  162. package/lib/Components/TileComponent.d.ts +0 -10
  163. package/lib/Components/TileComponent.js +0 -40
  164. package/lib/Components/TileComponent.js.map +0 -1
  165. package/lib/Effects/Animation.d.ts +0 -55
  166. package/lib/Effects/Animation.js +0 -233
  167. package/lib/Effects/Animation.js.map +0 -1
  168. package/lib/Effects/AnimationCharacter.d.ts +0 -7
  169. package/lib/Effects/AnimationCharacter.js +0 -9
  170. package/lib/Effects/AnimationCharacter.js.map +0 -1
  171. package/lib/Effects/Spinner.d.ts +0 -7
  172. package/lib/Effects/Spinner.js +0 -18
  173. package/lib/Effects/Spinner.js.map +0 -1
  174. package/lib/Effects/Timeline.d.ts +0 -151
  175. package/lib/Effects/Timeline.js +0 -369
  176. package/lib/Effects/Timeline.js.map +0 -1
  177. package/lib/Effects/TransitionScene.d.ts +0 -18
  178. package/lib/Effects/TransitionScene.js +0 -50
  179. package/lib/Effects/TransitionScene.js.map +0 -1
  180. package/lib/GameEngine.d.ts +0 -68
  181. package/lib/GameEngine.js +0 -254
  182. package/lib/GameEngine.js.map +0 -1
  183. package/lib/Gui/Gui.d.ts +0 -110
  184. package/lib/Gui/Gui.js +0 -489
  185. package/lib/Gui/Gui.js.map +0 -1
  186. package/lib/Gui/React.d.ts +0 -28
  187. package/lib/Gui/React.js +0 -147
  188. package/lib/Gui/React.js.map +0 -1
  189. package/lib/Gui/Vue.d.ts +0 -13
  190. package/lib/Gui/Vue.js +0 -114
  191. package/lib/Gui/Vue.js.map +0 -1
  192. package/lib/Interfaces/Character.d.ts +0 -6
  193. package/lib/Interfaces/Character.js +0 -2
  194. package/lib/Interfaces/Character.js.map +0 -1
  195. package/lib/Interfaces/Scene.d.ts +0 -10
  196. package/lib/Interfaces/Scene.js +0 -2
  197. package/lib/Interfaces/Scene.js.map +0 -1
  198. package/lib/KeyboardControls.d.ts +0 -367
  199. package/lib/KeyboardControls.js +0 -714
  200. package/lib/KeyboardControls.js.map +0 -1
  201. package/lib/Logger.d.ts +0 -1
  202. package/lib/Logger.js +0 -4
  203. package/lib/Logger.js.map +0 -1
  204. package/lib/Presets/AnimationSpritesheet.js +0 -39
  205. package/lib/Presets/AnimationSpritesheet.js.map +0 -1
  206. package/lib/Presets/Scene.d.ts +0 -3
  207. package/lib/Presets/Scene.js +0 -5
  208. package/lib/Presets/Scene.js.map +0 -1
  209. package/lib/Renderer.d.ts +0 -62
  210. package/lib/Renderer.js +0 -300
  211. package/lib/Renderer.js.map +0 -1
  212. package/lib/Resources.d.ts +0 -22
  213. package/lib/Resources.js +0 -38
  214. package/lib/Resources.js.map +0 -1
  215. package/lib/RpgClient.js +0 -2
  216. package/lib/RpgClient.js.map +0 -1
  217. package/lib/RpgClientEngine.d.ts +0 -257
  218. package/lib/RpgClientEngine.js +0 -677
  219. package/lib/RpgClientEngine.js.map +0 -1
  220. package/lib/Scene/EventLayer.d.ts +0 -4
  221. package/lib/Scene/EventLayer.js +0 -8
  222. package/lib/Scene/EventLayer.js.map +0 -1
  223. package/lib/Scene/Map.d.ts +0 -109
  224. package/lib/Scene/Map.js +0 -319
  225. package/lib/Scene/Map.js.map +0 -1
  226. package/lib/Scene/Scene.d.ts +0 -184
  227. package/lib/Scene/Scene.js +0 -250
  228. package/lib/Scene/Scene.js.map +0 -1
  229. package/lib/Scene/SceneData.d.ts +0 -4
  230. package/lib/Scene/SceneData.js +0 -8
  231. package/lib/Scene/SceneData.js.map +0 -1
  232. package/lib/Sound/RpgSound.d.ts +0 -11
  233. package/lib/Sound/RpgSound.js +0 -46
  234. package/lib/Sound/RpgSound.js.map +0 -1
  235. package/lib/Sound/Sound.d.ts +0 -78
  236. package/lib/Sound/Sound.js +0 -12
  237. package/lib/Sound/Sound.js.map +0 -1
  238. package/lib/Sound/Sounds.d.ts +0 -2
  239. package/lib/Sound/Sounds.js +0 -6
  240. package/lib/Sound/Sounds.js.map +0 -1
  241. package/lib/Sprite/Character.d.ts +0 -18
  242. package/lib/Sprite/Character.js +0 -131
  243. package/lib/Sprite/Character.js.map +0 -1
  244. package/lib/Sprite/Player.d.ts +0 -3
  245. package/lib/Sprite/Player.js +0 -4
  246. package/lib/Sprite/Player.js.map +0 -1
  247. package/lib/Sprite/Spritesheet.d.ts +0 -365
  248. package/lib/Sprite/Spritesheet.js +0 -13
  249. package/lib/Sprite/Spritesheet.js.map +0 -1
  250. package/lib/Sprite/Spritesheets.d.ts +0 -3
  251. package/lib/Sprite/Spritesheets.js +0 -6
  252. package/lib/Sprite/Spritesheets.js.map +0 -1
  253. package/lib/Tilemap/CommonLayer.d.ts +0 -10
  254. package/lib/Tilemap/CommonLayer.js +0 -17
  255. package/lib/Tilemap/CommonLayer.js.map +0 -1
  256. package/lib/Tilemap/ImageLayer.d.ts +0 -4
  257. package/lib/Tilemap/ImageLayer.js +0 -16
  258. package/lib/Tilemap/ImageLayer.js.map +0 -1
  259. package/lib/Tilemap/Tile.d.ts +0 -21
  260. package/lib/Tilemap/Tile.js +0 -67
  261. package/lib/Tilemap/Tile.js.map +0 -1
  262. package/lib/Tilemap/TileLayer.d.ts +0 -13
  263. package/lib/Tilemap/TileLayer.js +0 -122
  264. package/lib/Tilemap/TileLayer.js.map +0 -1
  265. package/lib/Tilemap/TileSet.d.ts +0 -7
  266. package/lib/Tilemap/TileSet.js +0 -24
  267. package/lib/Tilemap/TileSet.js.map +0 -1
  268. package/lib/Tilemap/index.d.ts +0 -28
  269. package/lib/Tilemap/index.js +0 -151
  270. package/lib/Tilemap/index.js.map +0 -1
  271. package/lib/clientEntryPoint.d.ts +0 -89
  272. package/lib/clientEntryPoint.js +0 -48
  273. package/lib/clientEntryPoint.js.map +0 -1
  274. package/lib/index.d.ts +0 -26
  275. package/lib/index.js +0 -27
  276. package/lib/index.js.map +0 -1
  277. package/lib/inject.d.ts +0 -23
  278. package/lib/inject.js +0 -30
  279. package/lib/inject.js.map +0 -1
  280. package/rpg.toml +0 -14
  281. package/src/Components/AbstractComponent.ts +0 -120
  282. package/src/Components/BarComponent.ts +0 -181
  283. package/src/Components/Component.ts +0 -515
  284. package/src/Components/DebugComponent.ts +0 -36
  285. package/src/Components/ImageComponent.ts +0 -30
  286. package/src/Components/ShapeComponent.ts +0 -64
  287. package/src/Components/TextComponent.ts +0 -33
  288. package/src/Components/TileComponent.ts +0 -43
  289. package/src/Effects/Animation.ts +0 -310
  290. package/src/Effects/AnimationCharacter.ts +0 -7
  291. package/src/Effects/Spinner.ts +0 -19
  292. package/src/Effects/Timeline.ts +0 -378
  293. package/src/Effects/TransitionScene.ts +0 -59
  294. package/src/GameEngine.ts +0 -289
  295. package/src/Gui/React.ts +0 -193
  296. package/src/Gui/Vue.ts +0 -154
  297. package/src/Interfaces/Character.ts +0 -7
  298. package/src/Interfaces/Scene.ts +0 -9
  299. package/src/KeyboardControls.ts +0 -748
  300. package/src/Logger.ts +0 -3
  301. package/src/Presets/Scene.ts +0 -3
  302. package/src/Renderer.ts +0 -334
  303. package/src/Resources.ts +0 -39
  304. package/src/Scene/EventLayer.ts +0 -9
  305. package/src/Scene/Map.ts +0 -402
  306. package/src/Scene/Scene.ts +0 -305
  307. package/src/Scene/SceneData.ts +0 -13
  308. package/src/Sound/RpgSound.ts +0 -50
  309. package/src/Sound/Sound.ts +0 -91
  310. package/src/Sound/Sounds.ts +0 -7
  311. package/src/Sprite/Character.ts +0 -157
  312. package/src/Sprite/Player.ts +0 -3
  313. package/src/Sprite/Spritesheet.ts +0 -392
  314. package/src/Sprite/Spritesheets.ts +0 -8
  315. package/src/Tilemap/CommonLayer.ts +0 -20
  316. package/src/Tilemap/ImageLayer.ts +0 -20
  317. package/src/Tilemap/Tile.ts +0 -80
  318. package/src/Tilemap/TileLayer.ts +0 -142
  319. package/src/Tilemap/TileSet.ts +0 -40
  320. package/src/Tilemap/index.ts +0 -175
  321. package/src/clientEntryPoint.ts +0 -150
  322. package/src/inject.ts +0 -34
  323. package/src/types/howler.d.ts +0 -73
@@ -1,748 +0,0 @@
1
- import { DefaultInput, Direction, InjectContext, Input, Utils } from '@rpgjs/common'
2
- import { ControlOptions, Controls } from '@rpgjs/types';
3
- import { RpgClientEngine } from './RpgClientEngine';
4
-
5
- // keyboard handling
6
- const keyCodeTable = {
7
- 3: 'break',
8
- 8: 'backspace', // backspace / delete
9
- 9: 'tab',
10
- 12: 'clear',
11
- 13: 'enter',
12
- 16: 'shift',
13
- 17: 'ctrl',
14
- 18: 'alt',
15
- 19: 'pause/break',
16
- 20: 'caps lock',
17
- 27: 'escape',
18
- 28: 'conversion',
19
- 29: 'non-conversion',
20
- 32: 'space',
21
- 33: 'page up',
22
- 34: 'page down',
23
- 35: 'end',
24
- 36: 'home',
25
- 37: Direction.Left,
26
- 38: Direction.Up,
27
- 39: Direction.Right,
28
- 40: Direction.Down,
29
- 41: 'select',
30
- 42: 'print',
31
- 43: 'execute',
32
- 44: 'Print Screen',
33
- 45: 'insert',
34
- 46: 'delete',
35
- 48: 'n0',
36
- 49: 'n1',
37
- 50: 'n2',
38
- 51: 'n3',
39
- 52: 'n4',
40
- 53: 'n5',
41
- 54: 'n6',
42
- 55: 'n7',
43
- 56: 'n8',
44
- 57: 'n9',
45
- 58: ':',
46
- 59: 'semicolon (firefox), equals',
47
- 60: '<',
48
- 61: 'equals (firefox)',
49
- 63: 'ß',
50
- 64: '@',
51
- 65: 'a',
52
- 66: 'b',
53
- 67: 'c',
54
- 68: 'd',
55
- 69: 'e',
56
- 70: 'f',
57
- 71: 'g',
58
- 72: 'h',
59
- 73: 'i',
60
- 74: 'j',
61
- 75: 'k',
62
- 76: 'l',
63
- 77: 'm',
64
- 78: 'n',
65
- 79: 'o',
66
- 80: 'p',
67
- 81: 'q',
68
- 82: 'r',
69
- 83: 's',
70
- 84: 't',
71
- 85: 'u',
72
- 86: 'v',
73
- 87: 'w',
74
- 88: 'x',
75
- 89: 'y',
76
- 90: 'z',
77
- 91: 'Windows Key / Left ⌘ / Chromebook Search key',
78
- 92: 'right window key',
79
- 93: 'Windows Menu / Right ⌘',
80
- 96: 'numpad 0',
81
- 97: 'numpad 1',
82
- 98: 'numpad 2',
83
- 99: 'numpad 3',
84
- 100: 'numpad 4',
85
- 101: 'numpad 5',
86
- 102: 'numpad 6',
87
- 103: 'numpad 7',
88
- 104: 'numpad 8',
89
- 105: 'numpad 9',
90
- 106: 'multiply',
91
- 107: 'add',
92
- 108: 'numpad period (firefox)',
93
- 109: 'subtract',
94
- 110: 'decimal point',
95
- 111: 'divide',
96
- 112: 'f1',
97
- 113: 'f2',
98
- 114: 'f3',
99
- 115: 'f4',
100
- 116: 'f5',
101
- 117: 'f6',
102
- 118: 'f7',
103
- 119: 'f8',
104
- 120: 'f9',
105
- 121: 'f10',
106
- 122: 'f11',
107
- 123: 'f12',
108
- 124: 'f13',
109
- 125: 'f14',
110
- 126: 'f15',
111
- 127: 'f16',
112
- 128: 'f17',
113
- 129: 'f18',
114
- 130: 'f19',
115
- 131: 'f20',
116
- 132: 'f21',
117
- 133: 'f22',
118
- 134: 'f23',
119
- 135: 'f24',
120
- 144: 'num lock',
121
- 145: 'scroll lock',
122
- 160: '^',
123
- 161: '!',
124
- 163: '#',
125
- 164: '$',
126
- 165: 'ù',
127
- 166: 'page backward',
128
- 167: 'page forward',
129
- 169: 'closing paren (AZERTY)',
130
- 170: '*',
131
- 171: '~ + * key',
132
- 173: 'minus (firefox), mute/unmute',
133
- 174: 'decrease volume level',
134
- 175: 'increase volume level',
135
- 176: 'next',
136
- 177: 'previous',
137
- 178: 'stop',
138
- 179: 'play/pause',
139
- 180: 'e-mail',
140
- 181: 'mute/unmute (firefox)',
141
- 182: 'decrease volume level (firefox)',
142
- 183: 'increase volume level (firefox)',
143
- 186: 'semi-colon / ñ',
144
- 187: 'equal sign',
145
- 188: 'comma',
146
- 189: 'dash',
147
- 190: 'period',
148
- 191: 'forward slash / ç',
149
- 192: 'grave accent / ñ / æ',
150
- 193: '?, / or °',
151
- 194: 'numpad period (chrome)',
152
- 219: 'open bracket',
153
- 220: 'back slash',
154
- 221: 'close bracket / å',
155
- 222: 'single quote / ø',
156
- 223: '`',
157
- 224: 'left or right ⌘ key (firefox)',
158
- 225: 'altgr',
159
- 226: '< /git >',
160
- 230: 'GNOME Compose Key',
161
- 231: 'ç',
162
- 233: 'XF86Forward',
163
- 234: 'XF86Back',
164
- 240: 'alphanumeric',
165
- 242: 'hiragana/katakana',
166
- 243: 'half-width/full-width',
167
- 244: 'kanji',
168
- 255: 'toggle touchpad'
169
- };
170
-
171
- const directionCode = {
172
- [Direction.Up]: 1,
173
- [Direction.Right]: 2,
174
- [Direction.Down]: 3,
175
- [Direction.Left]: 4
176
- }
177
-
178
- const { isArray } = Utils
179
-
180
- const inverse = (obj) => {
181
- const newObj = {}
182
- for (let key in obj) {
183
- const val = obj[key]
184
- newObj[val] = key
185
- }
186
- return newObj
187
- }
188
-
189
- const inverseKeyCodeTable = inverse(keyCodeTable)
190
-
191
- type BoundKey = { actionName: string, options: ControlOptions, parameters?: any }
192
-
193
- export class KeyboardControls {
194
- private clientEngine: RpgClientEngine = this.context.inject(RpgClientEngine)
195
-
196
- private keyState: {
197
- [keyName: string]: {
198
- isDown: boolean,
199
- count: number
200
- } | null
201
- } = {}
202
- private boundKeys: {
203
- [keyName: string]: BoundKey
204
- } = {}
205
- private stop: boolean = false
206
- private lastKeyPressed: number | null = null
207
- private _controlsOptions: Controls = {}
208
-
209
- constructor(private context: InjectContext) {
210
- const { globalConfig } = this.clientEngine
211
- this.setupListeners();
212
- this.setInputs({
213
- ...DefaultInput,
214
- ...(globalConfig.inputs || {})
215
- })
216
- }
217
-
218
- /** @internal */
219
- preStep() {
220
- //this.directionToAngle()
221
- if (this.stop) return
222
- const boundKeys = Object.keys(this.boundKeys)
223
- const applyInput = (keyName: string) => {
224
- const keyState = this.keyState[keyName]
225
- if (!keyState) return
226
- const { isDown, count } = keyState
227
- if (isDown) {
228
- const { repeat, method } = this.boundKeys[keyName].options
229
- if ((repeat || count == 0)) {
230
- let parameters = this.boundKeys[keyName].parameters
231
- if (typeof parameters === "function") {
232
- parameters = parameters();
233
- }
234
- if (method) {
235
- method(this.boundKeys[keyName])
236
- }
237
- else {
238
- this.clientEngine.sendInput(this.boundKeys[keyName].actionName)
239
- }
240
- this.keyState[keyName]!.count++
241
- }
242
- }
243
- }
244
- for (let keyName of boundKeys) {
245
- applyInput(keyName)
246
- }
247
- }
248
-
249
- // TODO, merge direction
250
- private directionToAngle() {
251
- let directionVal = 0
252
- let nbFound = 0
253
- for (let keyName of Object.keys(this.boundKeys)) {
254
- if (this.keyState[keyName]?.isDown) {
255
- if (directionCode[keyName]) {
256
- this.keyState[keyName] = null
257
- directionVal += directionCode[keyName]
258
- nbFound++
259
- }
260
- }
261
- }
262
- if (!nbFound) return
263
-
264
- const index = directionVal / nbFound
265
-
266
- if (this.keyState[index] !== null) {
267
- this.keyState[index] = {
268
- count: 0,
269
- isDown: true
270
- }
271
- }
272
-
273
- this.keyState[index]!.isDown = true
274
- }
275
-
276
- private setupListeners() {
277
- document.addEventListener('keydown', (e) => { this.onKeyChange(e, true); });
278
- document.addEventListener('keyup', (e) => { this.onKeyChange(e, false); });
279
- }
280
-
281
- private bindKey(keys: Input | Input[], actionName: string, options: ControlOptions, parameters?: object) {
282
- if (!isArray(keys)) keys = [keys] as Input[]
283
- const keyOptions = Object.assign({
284
- repeat: false
285
- }, options);
286
- (keys as Input[]).forEach(keyName => {
287
- this.boundKeys[keyName] = { actionName, options: keyOptions, parameters }
288
- })
289
- }
290
-
291
- private applyKeyDown(name: string) {
292
- const code = inverseKeyCodeTable[name]
293
- const e: any = new Event('keydown')
294
- e.keyCode = code
295
- this.onKeyChange(e, true)
296
- }
297
-
298
- private applyKeyUp(name: string) {
299
- const code = inverseKeyCodeTable[name]
300
- const e: any = new Event('keyup')
301
- e.keyCode = code
302
- this.onKeyChange(e, false)
303
- }
304
-
305
- private applyKeyPress(name: string): Promise<void> {
306
- return new Promise((resolve: any) => {
307
- this.applyKeyDown(name)
308
- setTimeout(() => {
309
- this.applyKeyUp(name)
310
- resolve()
311
- }, 200)
312
- })
313
- }
314
-
315
- private onKeyChange(e: KeyboardEvent, isDown: boolean) {
316
- e = e || window.event;
317
-
318
- const keyName: string = keyCodeTable[e.keyCode];
319
-
320
- if (keyName && this.boundKeys[keyName]) {
321
- if (this.keyState[keyName] == null) {
322
- this.keyState[keyName] = {
323
- count: 0,
324
- isDown: true
325
- };
326
- }
327
- this.keyState[keyName]!.isDown = isDown;
328
-
329
- // key up, reset press count
330
- if (!isDown) {
331
- this.keyState[keyName]!.count = 0
332
- }
333
-
334
- // keep reference to the last key pressed to avoid duplicates
335
- this.lastKeyPressed = isDown ? e.keyCode : null;
336
- }
337
-
338
- if (isDown) this.clientEngine.keyChange.next(keyName)
339
- }
340
-
341
- /**
342
- * From the name of the entry, we retrieve the control information
343
- *
344
- * ```ts
345
- * import { Input, inject, KeyboardControls } from '@rpgjs/client'
346
- *
347
- * const controls = inject(KeyboardControls)
348
- * controls.getControl(Input.Enter)
349
-
350
- * if (control) {
351
- * console.log(control.actionName) // action
352
- * }
353
- * ```
354
- * @title Get Control
355
- * @method getControl(inputName)
356
- * @param {string} inputName
357
- * @returns { { actionName: string, options: any } | undefined }
358
- * @memberof KeyboardControls
359
- */
360
- getControl(inputName: string): BoundKey | undefined {
361
- return this.boundKeys[inputName]
362
- }
363
-
364
- /**
365
- * Returns all controls
366
- *
367
- * @method getControls()
368
- * @since 4.2.0
369
- * @returns { { [key: string]: BoundKey } }
370
- * @memberof KeyboardControls
371
- */
372
- getControls(): { [key: string]: BoundKey } {
373
- return this.boundKeys
374
- }
375
-
376
- /**
377
- * Triggers an input according to the name of the control
378
- *
379
- * ```ts
380
- * import { Control, inject, KeyboardControls } from '@rpgjs/client'
381
- *
382
- * const controls = inject(KeyboardControls)
383
- * controls.applyControl(Control.Action)
384
- * ```
385
- *
386
- * You can put a second parameter or indicate on whether the key is pressed or released
387
- *
388
- * ```ts
389
- * import { Control, inject, KeyboardControls } from '@rpgjs/client'
390
- *
391
- * const controls = inject(KeyboardControls)
392
- * controls.applyControl(Control.Up, true) // keydown
393
- * controls.applyControl(Control.Up, false) // keyup
394
- * ```
395
- * @title Apply Control
396
- * @method applyControl(controlName,isDown)
397
- * @param {string} controlName
398
- * @param {boolean} [isDown]
399
- * @returns {Promise<void>}
400
- * @memberof KeyboardControls
401
- */
402
- async applyControl(controlName: string | number, isDown?: boolean | undefined): Promise<void> {
403
- const control = this._controlsOptions[controlName]
404
- if (control) {
405
- const input = isArray(control.bind) ? control.bind[0] : control.bind
406
- if (isDown === undefined) {
407
- await this.applyKeyPress(input as string)
408
- }
409
- else if (isDown) {
410
- this.applyKeyDown(input as string)
411
- }
412
- else {
413
- this.applyKeyUp(input as string)
414
- }
415
- }
416
- }
417
-
418
- /**
419
- * Stop listening to the inputs. Pressing a key won't do anything
420
- *
421
- * @title Stop Inputs
422
- * @method stopInputs()
423
- * @returns {void}
424
- * @memberof KeyboardControls
425
- */
426
- stopInputs() {
427
- this.stop = true
428
- }
429
-
430
- /**
431
- * Listen to the inputs again
432
- *
433
- * @title Listen Inputs
434
- * @method listenInputs()
435
- * @returns {void}
436
- * @memberof KeyboardControls
437
- */
438
- listenInputs() {
439
- this.stop = false
440
- this.keyState = {}
441
- }
442
-
443
- /**
444
- * Assign custom inputs to the scene
445
- *
446
- * The object is the following:
447
- *
448
- * * the key of the object is the name of the control. Either it is existing controls (Up, Dow, Left, Right, Action, Back) or customized controls
449
- * * The value is an object representing control information:
450
- * * repeat {boolean} The key can be held down to repeat the action. (false by default)
451
- * * bind {string | string[]} To which key is linked the control
452
- * * method {Function} Function to be triggered. If you do not set this property, the name of the control is sent directly to the server.
453
- * * delay {object|number} (since v3.2.0) Indicates how long (in milliseconds) the player can press the key again to perform the action
454
- * * delay.duration
455
- * * delay.otherControls {string | string[]} Indicates the other controls that will also have the delay at the same time
456
- *
457
- * ```ts
458
- * import { Control, Input, inject, KeyboardControls } from '@rpgjs/client'
459
- *
460
- * const controls = inject(KeyboardControls)
461
- * controls.setInputs({
462
- [Control.Up]: {
463
- repeat: true,
464
- bind: Input.Up
465
- },
466
- [Control.Down]: {
467
- repeat: true,
468
- bind: Input.Down
469
- },
470
- [Control.Right]: {
471
- repeat: true,
472
- bind: Input.Right
473
- },
474
- [Control.Left]: {
475
- repeat: true,
476
- bind: Input.Left
477
- },
478
- [Control.Action]: {
479
- bind: [Input.Space, Input.Enter]
480
- },
481
- [Control.Back]: {
482
- bind: Input.Escape
483
- },
484
-
485
- // The myscustom1 control is sent to the server when the A key is pressed.
486
- mycustom1: {
487
- bind: Input.A
488
- },
489
-
490
- // the myAction method is executed when the B key is pressed
491
- mycustom2: {
492
- bind: Input.B,
493
- method({ actionName }) {
494
- console.log('cool', actionName)
495
- }
496
- },
497
-
498
- // The player can redo the action after 400ms
499
- mycustom3: {
500
- bind: Input.C,
501
- delay: 400 // ms
502
- },
503
-
504
- // The player can redo the action (mycustom4) and the directions after 400ms
505
- mycustom4: {
506
- bind: Input.C,
507
- delay: {
508
- duration: 400,
509
- otherControls: [Control.Up, Control.Down, Control.Left, Control.Right]
510
- }
511
- }
512
- })
513
- *
514
- * ```
515
- * @enum {string} Control
516
- *
517
- * Control.Up | up
518
- * Control.Down | down
519
- * Control.Left | left
520
- * Control.Right | right
521
- * Control.Action | action
522
- * Control.Back | back
523
- *
524
- * @enum {string} Mouse Event
525
- *
526
- * click | Click
527
- * dblclick | Double Click
528
- * mousedown | Mouse Down
529
- * mouseup | Mouse Up
530
- * mouseover | Mouse Over
531
- * mousemove | Mouse Move
532
- * mouseout | Mouse Out
533
- * contextmenu | Context Menu
534
- *
535
- *
536
- * @enum {string} Input
537
- *
538
- * break | Pause
539
- * backspace | Backspace / Delete
540
- * tab | Tab
541
- * clear | Clear
542
- * enter | Enter
543
- * shift | Shift
544
- * ctrl | Control
545
- * alt | Alt
546
- * pause/break | Pause / Break
547
- * caps lock | Caps Lock
548
- * escape | Escape
549
- * conversion | Conversion
550
- * non-conversion | Non-conversion
551
- * space | Space
552
- * page up | Page Up
553
- * page down | Page Down
554
- * end | End
555
- * home | Home
556
- * left | Left Arrow
557
- * up | Up Arrow
558
- * right | Right Arrow
559
- * down | Down Arrow
560
- * select | Select
561
- * print | Print
562
- * execute | Execute
563
- * Print Screen | Print Screen
564
- * insert | Insert
565
- * delete | Delete
566
- * n0 | 0
567
- * n1 | 1
568
- * n2 | 2
569
- * n3 | 3
570
- * n4 | 4
571
- * n5 | 5
572
- * n6 | 6
573
- * n7 | 7
574
- * n8 | 8
575
- * n9 | 9
576
- * : | Colon
577
- * semicolon (firefox), equals | Semicolon (Firefox), Equals
578
- * < | Less Than
579
- * equals (firefox) | Equals (Firefox)
580
- * ß | Eszett
581
- * @ | At
582
- * a | A
583
- * b | B
584
- * c | C
585
- * d | D
586
- * e | E
587
- * f | F
588
- * g | G
589
- * h | H
590
- * i | I
591
- * j | J
592
- * k | K
593
- * l | L
594
- * m | M
595
- * n | N
596
- * o | O
597
- * p | P
598
- * q | Q
599
- * r | R
600
- * s | S
601
- * t | T
602
- * u | U
603
- * v | V
604
- * w | W
605
- * x | X
606
- * y | Y
607
- * z | Z
608
- * Windows Key / Left ⌘ / Chromebook Search key | Windows Key / Left Command ⌘ / Chromebook Search Key
609
- * right window key | Right Windows Key
610
- * Windows Menu / Right ⌘ | Windows Menu / Right Command ⌘
611
- * numpad 0 | Numpad 0
612
- * numpad 1 | Numpad 1
613
- * numpad 2 | Numpad 2
614
- * numpad 3 | Numpad 3
615
- * numpad 4 | Numpad 4
616
- * numpad 5 | Numpad 5
617
- * numpad 6 | Numpad 6
618
- * numpad 7 | Numpad 7
619
- * numpad 8 | Numpad 8
620
- * numpad 9 | Numpad 9
621
- * multiply | Multiply
622
- * add | Add
623
- * numpad period (firefox) | Numpad Period (Firefox)
624
- * subtract | Subtract
625
- * decimal point | Decimal Point
626
- * divide | Divide
627
- * f1 | F1
628
- * f2 | F2
629
- * f3 | F3
630
- * f4 | F4
631
- * f5 | F5
632
- * f6 | F6
633
- * f7 | F7
634
- * f8 | F8
635
- * f9 | F9
636
- * f10 | F10
637
- * f11 | F11
638
- * f12 | F12
639
- * f13 | F13
640
- * f14 | F14
641
- * f15 | F15
642
- * f16 | F16
643
- * f17 | F17
644
- * f18 | F18
645
- * f19 | F19
646
- * f20 | F20
647
- * f21 | F21
648
- * f22 | F22
649
- * f23 | F23
650
- * f24 | F24
651
- * num lock | Num Lock
652
- * scroll lock | Scroll Lock
653
- * ^ | Caret
654
- * ! | Exclamation Point
655
- * # | Hash
656
- * $ | Dollar Sign
657
- * ù | Grave Accent U
658
- * page backward | Page Backward
659
- * page forward | Page Forward
660
- * closing paren (AZERTY) | Closing Parenthesis (AZERTY)
661
- * * | Asterisk
662
- * ~ + * key | Tilde + Asterisk Key
663
- * minus (firefox), mute/unmute | Minus (Firefox), Mute/Unmute
664
- * decrease volume level | Decrease Volume Level
665
- * increase volume level | Increase Volume Level
666
- * next | Next
667
- * previous | Previous
668
- * stop | Stop
669
- * play/pause | Play/Pause
670
- * e-mail | Email
671
- * mute/unmute (firefox) | Mute/Unmute (Firefox)
672
- * decrease volume level (firefox) | Decrease Volume Level (Firefox)
673
- * increase volume level (firefox) | Increase Volume Level (Firefox)
674
- * semi-colon / ñ | Semicolon / ñ
675
- * equal sign | Equal Sign
676
- * comma | Comma
677
- * dash | Dash
678
- * period | Period
679
- * forward slash / ç | Forward Slash / ç
680
- * grave accent / ñ / æ | Grave Accent / ñ / æ
681
- * ?, / or ° | ?, / or °
682
- * numpad period (chrome) | Numpad Period (Chrome)
683
- * open bracket | Open Bracket
684
- * back slash | Backslash
685
- * close bracket / å | Close Bracket / å
686
- * single quote / ø | Single Quote / ø
687
- * \` | Backtick
688
- * left or right ⌘ key (firefox) | Left or Right Command Key (Firefox)
689
- * altgr | AltGr
690
- * < /git > | < /git >
691
- * GNOME Compose Key | GNOME Compose Key
692
- * ç | ç
693
- * XF86Forward | XF86Forward
694
- * XF86Back | XF86Back
695
- * alphanumeric | Alphanumeric
696
- * hiragana/katakana | Hiragana/Katakana
697
- * half-width/full-width | Half-Width/Full-Width
698
- * kanji | Kanji
699
- * toggle touchpad | Toggle Touchpad
700
- *
701
- * @title Set Inputs
702
- * @method setInputs(inputs)
703
- * @param {object} inputs
704
- * @memberof KeyboardControls
705
- */
706
- setInputs(inputs: Controls) {
707
- if (!inputs) return
708
- this.boundKeys = {}
709
- let inputsTransformed: any = {}
710
- for (let control in inputs) {
711
- const bind = inputs[control].bind
712
- const transformBind = Array.isArray(bind) ? bind.map((b) => this.transformDirectionInNumber(b)) : this.transformDirectionInNumber(bind)
713
- inputsTransformed[this.transformDirectionInNumber(control)] = {
714
- ...inputs[control],
715
- bind: transformBind
716
- }
717
- }
718
- for (let control in inputsTransformed) {
719
- const option = inputsTransformed[control]
720
- const { method, bind } = option
721
- if (method) {
722
- option.method = method
723
- }
724
- let inputsKey: any = bind
725
- if (!isArray(inputsKey)) {
726
- inputsKey = [bind]
727
- }
728
- for (let input of inputsKey) {
729
- this.bindKey(input, control, option)
730
- }
731
- }
732
- this._controlsOptions = inputsTransformed
733
- }
734
-
735
- get options(): Controls {
736
- return this._controlsOptions
737
- }
738
-
739
- private transformDirectionInNumber(direction: any): any {
740
- switch (direction) {
741
- case 'up': return 1
742
- case 'down': return 3
743
- case 'left': return 4
744
- case 'right': return 2
745
- }
746
- return direction
747
- }
748
- }