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