@rpgjs/client 5.0.0-beta.11 → 5.0.0-beta.13
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.
- package/CHANGELOG.md +19 -0
- package/dist/Game/AnimationManager.d.ts +1 -0
- package/dist/Game/AnimationManager.js +3 -0
- package/dist/Game/AnimationManager.js.map +1 -1
- package/dist/Game/ClientVisuals.d.ts +61 -0
- package/dist/Game/ClientVisuals.js +96 -0
- package/dist/Game/ClientVisuals.js.map +1 -0
- package/dist/Game/ClientVisuals.spec.d.ts +1 -0
- package/dist/Game/EventComponentResolver.d.ts +16 -0
- package/dist/Game/EventComponentResolver.js +52 -0
- package/dist/Game/EventComponentResolver.js.map +1 -0
- package/dist/Game/EventComponentResolver.spec.d.ts +1 -0
- package/dist/Game/Map.js +9 -0
- package/dist/Game/Map.js.map +1 -1
- package/dist/Game/Object.d.ts +2 -0
- package/dist/Game/Object.js +22 -8
- package/dist/Game/Object.js.map +1 -1
- package/dist/Game/Object.spec.d.ts +1 -0
- package/dist/Game/ProjectileManager.d.ts +11 -2
- package/dist/Game/ProjectileManager.js +19 -2
- package/dist/Game/ProjectileManager.js.map +1 -1
- package/dist/Gui/Gui.d.ts +3 -2
- package/dist/Gui/Gui.js +18 -6
- package/dist/Gui/Gui.js.map +1 -1
- package/dist/RpgClient.d.ts +85 -1
- package/dist/RpgClientEngine.d.ts +77 -2
- package/dist/RpgClientEngine.js +290 -31
- package/dist/RpgClientEngine.js.map +1 -1
- package/dist/components/animations/fx.ce.js +58 -0
- package/dist/components/animations/fx.ce.js.map +1 -0
- package/dist/components/animations/index.d.ts +1 -0
- package/dist/components/animations/index.js +3 -1
- package/dist/components/animations/index.js.map +1 -1
- package/dist/components/character.ce.js +192 -19
- package/dist/components/character.ce.js.map +1 -1
- package/dist/components/gui/dialogbox/index.ce.js +27 -12
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -1
- package/dist/components/gui/gameover.ce.js +4 -3
- package/dist/components/gui/gameover.ce.js.map +1 -1
- package/dist/components/gui/menu/equip-menu.ce.js +9 -8
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/exit-menu.ce.js +7 -5
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/items-menu.ce.js +8 -7
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/main-menu.ce.js +12 -11
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/options-menu.ce.js +7 -5
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/skills-menu.ce.js +4 -2
- package/dist/components/gui/menu/skills-menu.ce.js.map +1 -1
- package/dist/components/gui/notification/notification.ce.js +4 -1
- package/dist/components/gui/notification/notification.ce.js.map +1 -1
- package/dist/components/gui/save-load.ce.js +10 -9
- package/dist/components/gui/save-load.ce.js.map +1 -1
- package/dist/components/gui/shop/shop.ce.js +17 -16
- package/dist/components/gui/shop/shop.ce.js.map +1 -1
- package/dist/components/gui/title-screen.ce.js +4 -3
- package/dist/components/gui/title-screen.ce.js.map +1 -1
- package/dist/components/interaction-components.ce.js +20 -0
- package/dist/components/interaction-components.ce.js.map +1 -0
- package/dist/components/scenes/canvas.ce.js +12 -7
- package/dist/components/scenes/canvas.ce.js.map +1 -1
- package/dist/components/scenes/draw-map.ce.js +18 -13
- package/dist/components/scenes/draw-map.ce.js.map +1 -1
- package/dist/i18n.d.ts +55 -0
- package/dist/i18n.js +60 -0
- package/dist/i18n.js.map +1 -0
- package/dist/i18n.spec.d.ts +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -2
- package/dist/module.js +30 -3
- package/dist/module.js.map +1 -1
- package/dist/services/actionInput.d.ts +3 -1
- package/dist/services/actionInput.js +33 -1
- package/dist/services/actionInput.js.map +1 -1
- package/dist/services/interactions.d.ts +159 -0
- package/dist/services/interactions.js +460 -0
- package/dist/services/interactions.js.map +1 -0
- package/dist/services/interactions.spec.d.ts +1 -0
- package/dist/services/keyboardControls.d.ts +1 -0
- package/dist/services/keyboardControls.js +1 -0
- package/dist/services/keyboardControls.js.map +1 -1
- package/dist/services/standalone.d.ts +3 -1
- package/dist/services/standalone.js +31 -13
- package/dist/services/standalone.js.map +1 -1
- package/dist/utils/mapId.d.ts +1 -0
- package/dist/utils/mapId.js +6 -0
- package/dist/utils/mapId.js.map +1 -0
- package/package.json +4 -4
- package/src/Game/AnimationManager.ts +4 -0
- package/src/Game/ClientVisuals.spec.ts +56 -0
- package/src/Game/ClientVisuals.ts +184 -0
- package/src/Game/EventComponentResolver.spec.ts +84 -0
- package/src/Game/EventComponentResolver.ts +74 -0
- package/src/Game/Map.ts +10 -0
- package/src/Game/Object.spec.ts +59 -0
- package/src/Game/Object.ts +36 -12
- package/src/Game/ProjectileManager.spec.ts +111 -0
- package/src/Game/ProjectileManager.ts +24 -2
- package/src/Gui/Gui.spec.ts +67 -0
- package/src/Gui/Gui.ts +24 -7
- package/src/RpgClient.ts +96 -1
- package/src/RpgClientEngine.ts +378 -45
- package/src/components/animations/fx.ce +101 -0
- package/src/components/animations/index.ts +4 -2
- package/src/components/character.ce +243 -17
- package/src/components/gui/dialogbox/index.ce +35 -14
- package/src/components/gui/gameover.ce +4 -3
- package/src/components/gui/menu/equip-menu.ce +9 -8
- package/src/components/gui/menu/exit-menu.ce +4 -3
- package/src/components/gui/menu/items-menu.ce +8 -7
- package/src/components/gui/menu/main-menu.ce +12 -11
- package/src/components/gui/menu/options-menu.ce +4 -3
- package/src/components/gui/menu/skills-menu.ce +2 -1
- package/src/components/gui/notification/notification.ce +7 -1
- package/src/components/gui/save-load.ce +11 -10
- package/src/components/gui/shop/shop.ce +17 -16
- package/src/components/gui/title-screen.ce +4 -3
- package/src/components/interaction-components.ce +23 -0
- package/src/components/scenes/canvas.ce +12 -7
- package/src/components/scenes/draw-map.ce +16 -5
- package/src/i18n.spec.ts +39 -0
- package/src/i18n.ts +59 -0
- package/src/index.ts +3 -0
- package/src/module.ts +43 -10
- package/src/services/actionInput.spec.ts +54 -0
- package/src/services/actionInput.ts +68 -1
- package/src/services/interactions.spec.ts +175 -0
- package/src/services/interactions.ts +722 -0
- package/src/services/keyboardControls.ts +2 -1
- package/src/services/standalone.ts +39 -10
- package/src/utils/mapId.ts +2 -0
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { I18nConfig } from '@rpgjs/common';
|
|
2
|
+
export declare const RpgClientBuiltinI18n: {
|
|
3
|
+
en: {
|
|
4
|
+
"rpg.menu.title": string;
|
|
5
|
+
"rpg.menu.status": string;
|
|
6
|
+
"rpg.menu.level": string;
|
|
7
|
+
"rpg.menu.gold": string;
|
|
8
|
+
"rpg.menu.parameters": string;
|
|
9
|
+
"rpg.menu.items": string;
|
|
10
|
+
"rpg.menu.skills": string;
|
|
11
|
+
"rpg.menu.equip": string;
|
|
12
|
+
"rpg.menu.options": string;
|
|
13
|
+
"rpg.menu.save": string;
|
|
14
|
+
"rpg.menu.exit": string;
|
|
15
|
+
"rpg.menu.weapons": string;
|
|
16
|
+
"rpg.menu.armor": string;
|
|
17
|
+
"rpg.menu.use": string;
|
|
18
|
+
"rpg.menu.cancel": string;
|
|
19
|
+
"rpg.menu.unequip": string;
|
|
20
|
+
"rpg.menu.remove-equipment": string;
|
|
21
|
+
"rpg.menu.empty": string;
|
|
22
|
+
"rpg.menu.leave-game": string;
|
|
23
|
+
"rpg.menu.exit-help": string;
|
|
24
|
+
"rpg.menu.options-help": string;
|
|
25
|
+
"rpg.save.title": string;
|
|
26
|
+
"rpg.save.subtitle": string;
|
|
27
|
+
"rpg.load.title": string;
|
|
28
|
+
"rpg.load.subtitle": string;
|
|
29
|
+
"rpg.save.auto": string;
|
|
30
|
+
"rpg.save.slot": string;
|
|
31
|
+
"rpg.save.empty-slot": string;
|
|
32
|
+
"rpg.save.level": string;
|
|
33
|
+
"rpg.save.exp": string;
|
|
34
|
+
"rpg.save.map": string;
|
|
35
|
+
"rpg.save.date": string;
|
|
36
|
+
"rpg.title.default": string;
|
|
37
|
+
"rpg.title.start": string;
|
|
38
|
+
"rpg.title.load": string;
|
|
39
|
+
"rpg.gameover.title": string;
|
|
40
|
+
"rpg.gameover.title-screen": string;
|
|
41
|
+
"rpg.gameover.load-game": string;
|
|
42
|
+
"rpg.shop.default-message": string;
|
|
43
|
+
"rpg.shop.choose-action": string;
|
|
44
|
+
"rpg.shop.buy": string;
|
|
45
|
+
"rpg.shop.sell": string;
|
|
46
|
+
"rpg.shop.back": string;
|
|
47
|
+
"rpg.shop.equipped": string;
|
|
48
|
+
"rpg.shop.already-equipped": string;
|
|
49
|
+
"rpg.shop.qty": string;
|
|
50
|
+
"rpg.shop.available": string;
|
|
51
|
+
"rpg.shop.quantity": string;
|
|
52
|
+
"rpg.shop.total": string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export declare function provideI18n(config?: I18nConfig): import('@signe/di').FactoryProvider;
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createI18nProvider } from "@rpgjs/common";
|
|
2
|
+
//#region src/i18n.ts
|
|
3
|
+
var RpgClientBuiltinI18n = { en: {
|
|
4
|
+
"rpg.menu.title": "Menu",
|
|
5
|
+
"rpg.menu.status": "Status",
|
|
6
|
+
"rpg.menu.level": "Level",
|
|
7
|
+
"rpg.menu.gold": "Gold",
|
|
8
|
+
"rpg.menu.parameters": "Parameters",
|
|
9
|
+
"rpg.menu.items": "Items",
|
|
10
|
+
"rpg.menu.skills": "Skills",
|
|
11
|
+
"rpg.menu.equip": "Equip",
|
|
12
|
+
"rpg.menu.options": "Options",
|
|
13
|
+
"rpg.menu.save": "Save",
|
|
14
|
+
"rpg.menu.exit": "Exit",
|
|
15
|
+
"rpg.menu.weapons": "Weapons",
|
|
16
|
+
"rpg.menu.armor": "Armor",
|
|
17
|
+
"rpg.menu.use": "Use",
|
|
18
|
+
"rpg.menu.cancel": "Cancel",
|
|
19
|
+
"rpg.menu.unequip": "Unequip",
|
|
20
|
+
"rpg.menu.remove-equipment": "Remove the current equipment",
|
|
21
|
+
"rpg.menu.empty": "Empty",
|
|
22
|
+
"rpg.menu.leave-game": "Leave the game?",
|
|
23
|
+
"rpg.menu.exit-help": "Press Action to confirm or Escape to go back.",
|
|
24
|
+
"rpg.menu.options-help": "Configure your preferences here.",
|
|
25
|
+
"rpg.save.title": "Save Game",
|
|
26
|
+
"rpg.save.subtitle": "Choose a slot to overwrite or create.",
|
|
27
|
+
"rpg.load.title": "Load Game",
|
|
28
|
+
"rpg.load.subtitle": "Select a slot to load your progress.",
|
|
29
|
+
"rpg.save.auto": "Auto Save",
|
|
30
|
+
"rpg.save.slot": "Slot {index}",
|
|
31
|
+
"rpg.save.empty-slot": "Empty Slot",
|
|
32
|
+
"rpg.save.level": "Level",
|
|
33
|
+
"rpg.save.exp": "Exp",
|
|
34
|
+
"rpg.save.map": "Map",
|
|
35
|
+
"rpg.save.date": "Date",
|
|
36
|
+
"rpg.title.default": "RPG",
|
|
37
|
+
"rpg.title.start": "Start",
|
|
38
|
+
"rpg.title.load": "Load",
|
|
39
|
+
"rpg.gameover.title": "Game Over",
|
|
40
|
+
"rpg.gameover.title-screen": "Title Screen",
|
|
41
|
+
"rpg.gameover.load-game": "Load Game",
|
|
42
|
+
"rpg.shop.default-message": "Welcome to my shop!",
|
|
43
|
+
"rpg.shop.choose-action": "Choose an action",
|
|
44
|
+
"rpg.shop.buy": "Buy",
|
|
45
|
+
"rpg.shop.sell": "Sell",
|
|
46
|
+
"rpg.shop.back": "Back",
|
|
47
|
+
"rpg.shop.equipped": "Equipped",
|
|
48
|
+
"rpg.shop.already-equipped": "Already equipped",
|
|
49
|
+
"rpg.shop.qty": "Qty",
|
|
50
|
+
"rpg.shop.available": "Available",
|
|
51
|
+
"rpg.shop.quantity": "Quantity",
|
|
52
|
+
"rpg.shop.total": "Total"
|
|
53
|
+
} };
|
|
54
|
+
function provideI18n(config = {}) {
|
|
55
|
+
return createI18nProvider(config);
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { RpgClientBuiltinI18n, provideI18n };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=i18n.js.map
|
package/dist/i18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.js","names":[],"sources":["../src/i18n.ts"],"sourcesContent":["import { createI18nProvider, type I18nConfig } from \"@rpgjs/common\";\n\nexport const RpgClientBuiltinI18n = {\n en: {\n \"rpg.menu.title\": \"Menu\",\n \"rpg.menu.status\": \"Status\",\n \"rpg.menu.level\": \"Level\",\n \"rpg.menu.gold\": \"Gold\",\n \"rpg.menu.parameters\": \"Parameters\",\n \"rpg.menu.items\": \"Items\",\n \"rpg.menu.skills\": \"Skills\",\n \"rpg.menu.equip\": \"Equip\",\n \"rpg.menu.options\": \"Options\",\n \"rpg.menu.save\": \"Save\",\n \"rpg.menu.exit\": \"Exit\",\n \"rpg.menu.weapons\": \"Weapons\",\n \"rpg.menu.armor\": \"Armor\",\n \"rpg.menu.use\": \"Use\",\n \"rpg.menu.cancel\": \"Cancel\",\n \"rpg.menu.unequip\": \"Unequip\",\n \"rpg.menu.remove-equipment\": \"Remove the current equipment\",\n \"rpg.menu.empty\": \"Empty\",\n \"rpg.menu.leave-game\": \"Leave the game?\",\n \"rpg.menu.exit-help\": \"Press Action to confirm or Escape to go back.\",\n \"rpg.menu.options-help\": \"Configure your preferences here.\",\n \"rpg.save.title\": \"Save Game\",\n \"rpg.save.subtitle\": \"Choose a slot to overwrite or create.\",\n \"rpg.load.title\": \"Load Game\",\n \"rpg.load.subtitle\": \"Select a slot to load your progress.\",\n \"rpg.save.auto\": \"Auto Save\",\n \"rpg.save.slot\": \"Slot {index}\",\n \"rpg.save.empty-slot\": \"Empty Slot\",\n \"rpg.save.level\": \"Level\",\n \"rpg.save.exp\": \"Exp\",\n \"rpg.save.map\": \"Map\",\n \"rpg.save.date\": \"Date\",\n \"rpg.title.default\": \"RPG\",\n \"rpg.title.start\": \"Start\",\n \"rpg.title.load\": \"Load\",\n \"rpg.gameover.title\": \"Game Over\",\n \"rpg.gameover.title-screen\": \"Title Screen\",\n \"rpg.gameover.load-game\": \"Load Game\",\n \"rpg.shop.default-message\": \"Welcome to my shop!\",\n \"rpg.shop.choose-action\": \"Choose an action\",\n \"rpg.shop.buy\": \"Buy\",\n \"rpg.shop.sell\": \"Sell\",\n \"rpg.shop.back\": \"Back\",\n \"rpg.shop.equipped\": \"Equipped\",\n \"rpg.shop.already-equipped\": \"Already equipped\",\n \"rpg.shop.qty\": \"Qty\",\n \"rpg.shop.available\": \"Available\",\n \"rpg.shop.quantity\": \"Quantity\",\n \"rpg.shop.total\": \"Total\",\n },\n};\n\nexport function provideI18n(config: I18nConfig = {}) {\n return createI18nProvider(config);\n}\n"],"mappings":";;AAEA,IAAa,uBAAuB,EAClC,IAAI;CACF,kBAAkB;CAClB,mBAAmB;CACnB,kBAAkB;CAClB,iBAAiB;CACjB,uBAAuB;CACvB,kBAAkB;CAClB,mBAAmB;CACnB,kBAAkB;CAClB,oBAAoB;CACpB,iBAAiB;CACjB,iBAAiB;CACjB,oBAAoB;CACpB,kBAAkB;CAClB,gBAAgB;CAChB,mBAAmB;CACnB,oBAAoB;CACpB,6BAA6B;CAC7B,kBAAkB;CAClB,uBAAuB;CACvB,sBAAsB;CACtB,yBAAyB;CACzB,kBAAkB;CAClB,qBAAqB;CACrB,kBAAkB;CAClB,qBAAqB;CACrB,iBAAiB;CACjB,iBAAiB;CACjB,uBAAuB;CACvB,kBAAkB;CAClB,gBAAgB;CAChB,gBAAgB;CAChB,iBAAiB;CACjB,qBAAqB;CACrB,mBAAmB;CACnB,kBAAkB;CAClB,sBAAsB;CACtB,6BAA6B;CAC7B,0BAA0B;CAC1B,4BAA4B;CAC5B,0BAA0B;CAC1B,gBAAgB;CAChB,iBAAiB;CACjB,iBAAiB;CACjB,qBAAqB;CACrB,6BAA6B;CAC7B,gBAAgB;CAChB,sBAAsB;CACtB,qBAAqB;CACrB,kBAAkB;AACpB,EACF;AAEA,SAAgB,YAAY,SAAqB,CAAC,GAAG;CACnD,OAAO,mBAAmB,MAAM;AAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './core/inject';
|
|
|
8
8
|
export * from './services/loadMap';
|
|
9
9
|
export * from './services/actionInput';
|
|
10
10
|
export * from './services/pointerContext';
|
|
11
|
+
export * from './services/interactions';
|
|
11
12
|
export * from './module';
|
|
12
13
|
export * from './Gui/Gui';
|
|
13
14
|
export * from './components/gui';
|
|
@@ -27,5 +28,7 @@ export { RpgClientObject } from './Game/Object';
|
|
|
27
28
|
export { RpgClientPlayer } from './Game/Player';
|
|
28
29
|
export { RpgClientEvent } from './Game/Event';
|
|
29
30
|
export * from './Game/ProjectileManager';
|
|
31
|
+
export * from './Game/ClientVisuals';
|
|
30
32
|
export { withMobile } from './components/gui/mobile';
|
|
31
33
|
export * from './services/AbstractSocket';
|
|
34
|
+
export * from './i18n';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context } from "./node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js";
|
|
2
2
|
import { clearInject, context, inject, setInject } from "./core/inject.js";
|
|
3
3
|
import { AbstractWebsocket, WebSocketToken } from "./services/AbstractSocket.js";
|
|
4
|
-
import { getKeyboardControlBind, isKeyboardActionConfig, normalizeActionInput, resolveKeyboardActionInput } from "./services/actionInput.js";
|
|
4
|
+
import { getKeyboardControlBind, isKeyboardActionConfig, keyboardEventMatchesBind, normalizeActionInput, resolveKeyboardActionInput, resolveKeyboardDirectionInput } from "./services/actionInput.js";
|
|
5
5
|
import __ce_component$2 from "./components/gui/dialogbox/index.ce.js";
|
|
6
6
|
import __ce_component from "./components/gui/box.ce.js";
|
|
7
7
|
import __ce_component$16 from "./components/gui/shop/shop.ce.js";
|
|
@@ -30,7 +30,10 @@ import { RpgClientEvent } from "./Game/Event.js";
|
|
|
30
30
|
import { GlobalConfigToken, provideClientGlobalConfig, provideClientModules, provideGlobalConfig } from "./module.js";
|
|
31
31
|
import { PrebuiltComponentAnimations } from "./components/animations/index.js";
|
|
32
32
|
import { ProjectileManager } from "./Game/ProjectileManager.js";
|
|
33
|
+
import { ClientVisualRegistry } from "./Game/ClientVisuals.js";
|
|
33
34
|
import { createClientPointerContext } from "./services/pointerContext.js";
|
|
35
|
+
import { RpgClientInteractions, dragToTile, draggable, hoverPopover, selectable } from "./services/interactions.js";
|
|
36
|
+
import { RpgClientBuiltinI18n, provideI18n } from "./i18n.js";
|
|
34
37
|
import { RpgClientEngine } from "./RpgClientEngine.js";
|
|
35
38
|
import { Control } from "./services/keyboardControls.js";
|
|
36
39
|
import { provideRpg } from "./services/standalone.js";
|
|
@@ -46,4 +49,4 @@ import "./components/index.js";
|
|
|
46
49
|
import { Spritesheet } from "./decorators/spritesheet.js";
|
|
47
50
|
import { withMobile } from "./components/gui/mobile/index.js";
|
|
48
51
|
import { Input, KeyboardControls } from "canvasengine";
|
|
49
|
-
export { AbstractWebsocket, __ce_component as BoxComponent, BridgeWebsocket, __ce_component$1 as CharacterComponent, Context, Control, __ce_component$2 as DialogboxComponent, __ce_component$3 as EquipMenuComponent, __ce_component$4 as EventLayerComponent, __ce_component$5 as ExitMenuComponent, __ce_component$6 as GameoverComponent, GlobalConfigToken, __ce_component$7 as HpBar, __ce_component$8 as HudComponent, Input, __ce_component$9 as ItemsMenuComponent, KeyboardControls, __ce_component$10 as LightHalo, LoadMapService, LoadMapToken, __ce_component$11 as MainMenuComponent, __ce_component$12 as NotificationComponent, __ce_component$13 as OptionsMenuComponent, PrebuiltComponentAnimations, Presets, ProjectileManager, RpgClientEngine, RpgClientEvent, RpgClientObject, RpgClientPlayer, RpgGui, RpgResource, RpgSound, SaveClientService, SaveClientToken, __ce_component$14 as SaveLoadComponent, __ce_component$15 as SceneMap, __ce_component$16 as ShopComponent, __ce_component$17 as SkillsMenuComponent, Sound, Spritesheet, __ce_component$18 as TitleScreenComponent, WebSocketToken, clearInject, context, createClientPointerContext, getEntityProp, getKeyboardControlBind, getSoundMetadata, inject, isKeyboardActionConfig, normalizeActionInput, provideClientGlobalConfig, provideClientModules, provideGlobalConfig, provideLoadMap, provideMmorpg, provideRpg, provideSaveClient, resolveKeyboardActionInput, setInject, startGame, withMobile };
|
|
52
|
+
export { AbstractWebsocket, __ce_component as BoxComponent, BridgeWebsocket, __ce_component$1 as CharacterComponent, ClientVisualRegistry, Context, Control, __ce_component$2 as DialogboxComponent, __ce_component$3 as EquipMenuComponent, __ce_component$4 as EventLayerComponent, __ce_component$5 as ExitMenuComponent, __ce_component$6 as GameoverComponent, GlobalConfigToken, __ce_component$7 as HpBar, __ce_component$8 as HudComponent, Input, __ce_component$9 as ItemsMenuComponent, KeyboardControls, __ce_component$10 as LightHalo, LoadMapService, LoadMapToken, __ce_component$11 as MainMenuComponent, __ce_component$12 as NotificationComponent, __ce_component$13 as OptionsMenuComponent, PrebuiltComponentAnimations, Presets, ProjectileManager, RpgClientBuiltinI18n, RpgClientEngine, RpgClientEvent, RpgClientInteractions, RpgClientObject, RpgClientPlayer, RpgGui, RpgResource, RpgSound, SaveClientService, SaveClientToken, __ce_component$14 as SaveLoadComponent, __ce_component$15 as SceneMap, __ce_component$16 as ShopComponent, __ce_component$17 as SkillsMenuComponent, Sound, Spritesheet, __ce_component$18 as TitleScreenComponent, WebSocketToken, clearInject, context, createClientPointerContext, dragToTile, draggable, getEntityProp, getKeyboardControlBind, getSoundMetadata, hoverPopover, inject, isKeyboardActionConfig, keyboardEventMatchesBind, normalizeActionInput, provideClientGlobalConfig, provideClientModules, provideGlobalConfig, provideI18n, provideLoadMap, provideMmorpg, provideRpg, provideSaveClient, resolveKeyboardActionInput, resolveKeyboardDirectionInput, selectable, setInject, startGame, withMobile };
|
package/dist/module.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { inject } from "./node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js";
|
|
2
2
|
import { RpgGui } from "./Gui/Gui.js";
|
|
3
3
|
import { getSoundMetadata } from "./Sound.js";
|
|
4
|
-
import { findModules, provideModules } from "@rpgjs/common";
|
|
4
|
+
import { findModules, provideModules, registerI18nMessages } from "@rpgjs/common";
|
|
5
5
|
//#region src/module.ts
|
|
6
6
|
/**
|
|
7
7
|
* Provides client modules configuration to Dependency Injection
|
|
@@ -49,6 +49,7 @@ function provideClientModules(modules) {
|
|
|
49
49
|
module = moduleObj;
|
|
50
50
|
}
|
|
51
51
|
if ("client" in module) module = module.client;
|
|
52
|
+
if (module.i18n) registerI18nMessages(context, module.i18n, "client-module", 10);
|
|
52
53
|
if (module.spritesheets) {
|
|
53
54
|
const spritesheets = [...module.spritesheets];
|
|
54
55
|
module.spritesheets = { load: (engine) => {
|
|
@@ -112,6 +113,12 @@ function provideClientModules(modules) {
|
|
|
112
113
|
});
|
|
113
114
|
} };
|
|
114
115
|
}
|
|
116
|
+
if (module.clientVisuals) {
|
|
117
|
+
const clientVisuals = { ...module.clientVisuals };
|
|
118
|
+
module.clientVisuals = { load: (engine) => {
|
|
119
|
+
engine.registerClientVisuals(clientVisuals);
|
|
120
|
+
} };
|
|
121
|
+
}
|
|
115
122
|
if (module.projectiles) {
|
|
116
123
|
const projectiles = { ...module.projectiles };
|
|
117
124
|
module.projectiles = {
|
|
@@ -123,6 +130,23 @@ function provideClientModules(modules) {
|
|
|
123
130
|
}
|
|
124
131
|
};
|
|
125
132
|
}
|
|
133
|
+
if (module.interactions) {
|
|
134
|
+
const interactions = module.interactions;
|
|
135
|
+
module.interactions = {
|
|
136
|
+
...interactions,
|
|
137
|
+
load: (engine) => {
|
|
138
|
+
if (typeof interactions === "function") {
|
|
139
|
+
interactions(engine);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
interactions.load?.(engine);
|
|
143
|
+
interactions.setup?.(engine);
|
|
144
|
+
if (Array.isArray(interactions.use)) interactions.use.forEach(([matcher, behavior]) => {
|
|
145
|
+
engine.interactions.use(matcher, behavior);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
126
150
|
if (module.transitions) {
|
|
127
151
|
const transitions = [...module.transitions];
|
|
128
152
|
module.transitions = { load: (engine) => {
|
|
@@ -158,6 +182,7 @@ function provideClientModules(modules) {
|
|
|
158
182
|
if (sprite.components) Object.entries(sprite.components).forEach(([id, component]) => {
|
|
159
183
|
engine.registerSpriteComponent(id, component);
|
|
160
184
|
});
|
|
185
|
+
if (sprite.eventComponent) engine.addEventComponentResolver(sprite.eventComponent);
|
|
161
186
|
}
|
|
162
187
|
};
|
|
163
188
|
}
|
|
@@ -174,13 +199,15 @@ function provideGlobalConfig(config) {
|
|
|
174
199
|
};
|
|
175
200
|
}
|
|
176
201
|
function provideClientGlobalConfig(config = {}) {
|
|
177
|
-
|
|
202
|
+
config.keyboardControls = {
|
|
178
203
|
up: "up",
|
|
179
204
|
down: "down",
|
|
180
205
|
left: "left",
|
|
181
206
|
right: "right",
|
|
182
207
|
action: "space",
|
|
183
|
-
|
|
208
|
+
dash: "shift",
|
|
209
|
+
escape: "escape",
|
|
210
|
+
...config.keyboardControls ?? {}
|
|
184
211
|
};
|
|
185
212
|
return provideGlobalConfig(config);
|
|
186
213
|
}
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","names":[],"sources":["../src/module.ts"],"sourcesContent":["import { findModules, provideModules } from \"@rpgjs/common\";\nimport { FactoryProvider } from \"@signe/di\";\nimport { RpgClientEngine } from \"./RpgClientEngine\";\nimport { RpgClient } from \"./RpgClient\";\nimport { inject } from \"@signe/di\";\nimport { RpgGui } from \"./Gui/Gui\";\nimport { getSoundMetadata } from \"./Sound\";\n\n/**\n * Type for client modules that can be either:\n * - An object implementing RpgClient interface\n * - A class decorated with @RpgModule decorator\n */\nexport type RpgClientModule = RpgClient | (new () => any);\n\n/**\n * Provides client modules configuration to Dependency Injection\n * \n * This function accepts an array of client modules that can be either:\n * - Objects implementing the RpgClient interface\n * - Classes decorated with the @RpgModule decorator (which will be instantiated)\n * \n * @param modules - Array of client modules (objects or classes)\n * @returns FactoryProvider configuration for DI\n * @example\n * ```ts\n * // Using an object\n * provideClientModules([\n * {\n * engine: {\n * onConnected(engine) {\n * console.log('Client connected')\n * }\n * }\n * }\n * ])\n * \n * // Using a decorated class\n * @RpgModule<RpgClient>({\n * engine: {\n * onStart(engine) {\n * console.log('Client started')\n * }\n * }\n * })\n * class MyClientModule {}\n * \n * provideClientModules([MyClientModule])\n * ```\n */\nexport function provideClientModules(modules: RpgClientModule[]): FactoryProvider {\n return provideModules(modules, \"client\", (modules, context) => {\n const mainModuleClient = findModules(context, 'Client')\n modules = [...mainModuleClient, ...modules]\n modules = modules.map((module) => {\n // If module is a class (constructor function), instantiate it\n // The RpgModule decorator adds properties to the prototype, which will be accessible via the instance\n if (typeof module === 'function') {\n const instance = new module() as any;\n // Copy all enumerable properties (including from prototype) to a plain object\n const moduleObj: any = {};\n for (const key in instance) {\n moduleObj[key] = instance[key];\n }\n module = moduleObj;\n }\n if ('client' in module) {\n module = module.client as any;\n }\n if (module.spritesheets) {\n const spritesheets = [...module.spritesheets];\n module.spritesheets = {\n load: (engine: RpgClientEngine) => {\n spritesheets.forEach((spritesheet) => {\n engine.addSpriteSheet(spritesheet);\n });\n },\n };\n }\n if (module.spritesheetResolver) {\n const resolver = module.spritesheetResolver;\n module.spritesheetResolver = {\n load: (engine: RpgClientEngine) => {\n engine.setSpritesheetResolver(resolver);\n },\n };\n }\n if (module.sounds) {\n const sounds = [...module.sounds];\n module.sounds = {\n load: (engine: RpgClientEngine) => {\n sounds.forEach((sound) => {\n // Check if it's a class decorated with @Sound\n if (typeof sound === 'function' || (sound && sound.constructor && sound.constructor !== Object)) {\n const metadata = getSoundMetadata(sound);\n if (metadata) {\n // Handle single sound\n if (metadata.id && metadata.sound) {\n engine.addSound({\n id: metadata.id,\n src: metadata.sound,\n loop: metadata.loop,\n volume: metadata.volume,\n });\n }\n // Handle multiple sounds\n if (metadata.sounds) {\n Object.entries(metadata.sounds).forEach(([soundId, soundSrc]) => {\n engine.addSound({\n id: soundId,\n src: soundSrc,\n loop: metadata.loop,\n volume: metadata.volume,\n });\n });\n }\n } else {\n // Not a decorated class, treat as regular sound object\n engine.addSound(sound);\n }\n } else {\n // Regular sound object\n engine.addSound(sound);\n }\n });\n },\n };\n }\n if (module.soundResolver) {\n const resolver = module.soundResolver;\n module.soundResolver = {\n load: (engine: RpgClientEngine) => {\n engine.setSoundResolver(resolver);\n },\n };\n }\n if (module.gui) {\n const gui = [...module.gui];\n module.gui = {\n load: (engine: RpgClientEngine) => {\n const guiService = inject(engine.context, RpgGui) as RpgGui;\n gui.forEach((gui) => {\n guiService.add(gui);\n });\n },\n };\n }\n if (module.componentAnimations) {\n const componentAnimations = [...module.componentAnimations];\n module.componentAnimations = {\n load: (engine: RpgClientEngine) => {\n componentAnimations.forEach((componentAnimation) => {\n engine.addComponentAnimation(componentAnimation);\n });\n },\n };\n }\n if (module.projectiles) {\n const projectiles = { ...module.projectiles };\n module.projectiles = {\n ...projectiles,\n load: (engine: RpgClientEngine) => {\n if (projectiles.components) {\n Object.entries(projectiles.components).forEach(([type, component]) => {\n engine.registerProjectileComponent(type, component);\n });\n }\n },\n };\n }\n if (module.transitions) {\n const transitions = [...module.transitions];\n module.transitions = {\n load: (engine: RpgClientEngine) => {\n const guiService = inject(engine.context, RpgGui) as RpgGui;\n transitions.forEach((transition) => {\n guiService.add({\n name: transition.id,\n component: transition.component,\n data: transition.props || {}\n });\n });\n },\n };\n }\n if (module.particles) {\n const particles = [...module.particles];\n module.particles = {\n load: (engine: RpgClientEngine) => {\n particles.forEach((particle) => {\n engine.addParticle(particle);\n });\n },\n };\n }\n if (module.sprite) {\n const sprite = {...module.sprite};\n module.sprite = {\n ...sprite,\n load: (engine: RpgClientEngine) => {\n if (sprite.componentsBehind) {\n sprite.componentsBehind.forEach((component) => {\n engine.addSpriteComponentBehind(component);\n });\n }\n if (sprite.componentsInFront) {\n sprite.componentsInFront.forEach((component) => {\n engine.addSpriteComponentInFront(component);\n });\n }\n if (sprite.components) {\n Object.entries(sprite.components).forEach(([id, component]) => {\n engine.registerSpriteComponent(id, component);\n });\n }\n },\n };\n }\n return module;\n });\n return modules\n });\n}\n\nexport const GlobalConfigToken = \"GlobalConfigToken\";\n\nexport function provideGlobalConfig(config: any) {\n return {\n provide: GlobalConfigToken,\n useValue: config ?? {},\n };\n}\n\nexport function provideClientGlobalConfig(config: any = {}) {\n if (!config.keyboardControls) {\n config.keyboardControls = {\n up: 'up',\n down: 'down',\n left: 'left',\n right: 'right',\n action: 'space',\n escape: 'escape'\n }\n }\n return provideGlobalConfig(config)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,qBAAqB,SAA6C;CAChF,OAAO,eAAe,SAAS,WAAW,SAAS,YAAY;EAE7D,UAAU,CAAC,GADc,YAAY,SAAS,QAChC,GAAkB,GAAG,OAAO;EAC1C,UAAU,QAAQ,KAAK,WAAW;GAGhC,IAAI,OAAO,WAAW,YAAY;IAChC,MAAM,WAAW,IAAI,OAAO;IAE5B,MAAM,YAAiB,CAAC;IACxB,KAAK,MAAM,OAAO,UAChB,UAAU,OAAO,SAAS;IAE5B,SAAS;GACX;GACA,IAAI,YAAY,QACd,SAAS,OAAO;GAElB,IAAI,OAAO,cAAc;IACvB,MAAM,eAAe,CAAC,GAAG,OAAO,YAAY;IAC5C,OAAO,eAAe,EACpB,OAAO,WAA4B;KACjC,aAAa,SAAS,gBAAgB;MACpC,OAAO,eAAe,WAAW;KACnC,CAAC;IACH,EACF;GACF;GACA,IAAI,OAAO,qBAAqB;IAC9B,MAAM,WAAW,OAAO;IACxB,OAA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T,CAAC;AACH;AAEA,IAAa,oBAAoB;AAEjC,SAAgB,oBAAoB,QAAa;CAC/C,OAAO;EACL,SAAS;EACT,UAAU,UAAU,CAAC;CACvB;AACF;AAEA,SAAgB,0BAA0B,SAAc,CAAC,GAAG;CAC1D,IAAI,CAAC,OAAO,kBACV,OAAO,mBAAmB;EACxB,IAAI;EACJ,MAAM;EACN,MAAM;EACN,OAAO;EACP,QAAQ;EACR,QAAQ;CACV;CAEF,OAAO,oBAAoB,MAAM;AACnC"}
|
|
1
|
+
{"version":3,"file":"module.js","names":[],"sources":["../src/module.ts"],"sourcesContent":["import { findModules, provideModules, registerI18nMessages } from \"@rpgjs/common\";\nimport { FactoryProvider } from \"@signe/di\";\nimport { RpgClientEngine } from \"./RpgClientEngine\";\nimport { RpgClient } from \"./RpgClient\";\nimport { inject } from \"@signe/di\";\nimport { RpgGui } from \"./Gui/Gui\";\nimport { getSoundMetadata } from \"./Sound\";\n\n/**\n * Type for client modules that can be either:\n * - An object implementing RpgClient interface\n * - A class decorated with @RpgModule decorator\n */\nexport type RpgClientModule = RpgClient | (new () => any);\n\n/**\n * Provides client modules configuration to Dependency Injection\n * \n * This function accepts an array of client modules that can be either:\n * - Objects implementing the RpgClient interface\n * - Classes decorated with the @RpgModule decorator (which will be instantiated)\n * \n * @param modules - Array of client modules (objects or classes)\n * @returns FactoryProvider configuration for DI\n * @example\n * ```ts\n * // Using an object\n * provideClientModules([\n * {\n * engine: {\n * onConnected(engine) {\n * console.log('Client connected')\n * }\n * }\n * }\n * ])\n * \n * // Using a decorated class\n * @RpgModule<RpgClient>({\n * engine: {\n * onStart(engine) {\n * console.log('Client started')\n * }\n * }\n * })\n * class MyClientModule {}\n * \n * provideClientModules([MyClientModule])\n * ```\n */\nexport function provideClientModules(modules: RpgClientModule[]): FactoryProvider {\n return provideModules(modules, \"client\", (modules, context) => {\n const mainModuleClient = findModules(context, 'Client')\n modules = [...mainModuleClient, ...modules]\n modules = modules.map((module) => {\n // If module is a class (constructor function), instantiate it\n // The RpgModule decorator adds properties to the prototype, which will be accessible via the instance\n if (typeof module === 'function') {\n const instance = new module() as any;\n // Copy all enumerable properties (including from prototype) to a plain object\n const moduleObj: any = {};\n for (const key in instance) {\n moduleObj[key] = instance[key];\n }\n module = moduleObj;\n }\n if ('client' in module) {\n module = module.client as any;\n }\n if (module.i18n) {\n registerI18nMessages(context, module.i18n, \"client-module\", 10);\n }\n if (module.spritesheets) {\n const spritesheets = [...module.spritesheets];\n module.spritesheets = {\n load: (engine: RpgClientEngine) => {\n spritesheets.forEach((spritesheet) => {\n engine.addSpriteSheet(spritesheet);\n });\n },\n };\n }\n if (module.spritesheetResolver) {\n const resolver = module.spritesheetResolver;\n module.spritesheetResolver = {\n load: (engine: RpgClientEngine) => {\n engine.setSpritesheetResolver(resolver);\n },\n };\n }\n if (module.sounds) {\n const sounds = [...module.sounds];\n module.sounds = {\n load: (engine: RpgClientEngine) => {\n sounds.forEach((sound) => {\n // Check if it's a class decorated with @Sound\n if (typeof sound === 'function' || (sound && sound.constructor && sound.constructor !== Object)) {\n const metadata = getSoundMetadata(sound);\n if (metadata) {\n // Handle single sound\n if (metadata.id && metadata.sound) {\n engine.addSound({\n id: metadata.id,\n src: metadata.sound,\n loop: metadata.loop,\n volume: metadata.volume,\n });\n }\n // Handle multiple sounds\n if (metadata.sounds) {\n Object.entries(metadata.sounds).forEach(([soundId, soundSrc]) => {\n engine.addSound({\n id: soundId,\n src: soundSrc,\n loop: metadata.loop,\n volume: metadata.volume,\n });\n });\n }\n } else {\n // Not a decorated class, treat as regular sound object\n engine.addSound(sound);\n }\n } else {\n // Regular sound object\n engine.addSound(sound);\n }\n });\n },\n };\n }\n if (module.soundResolver) {\n const resolver = module.soundResolver;\n module.soundResolver = {\n load: (engine: RpgClientEngine) => {\n engine.setSoundResolver(resolver);\n },\n };\n }\n if (module.gui) {\n const gui = [...module.gui];\n module.gui = {\n load: (engine: RpgClientEngine) => {\n const guiService = inject(engine.context, RpgGui) as RpgGui;\n gui.forEach((gui) => {\n guiService.add(gui);\n });\n },\n };\n }\n if (module.componentAnimations) {\n const componentAnimations = [...module.componentAnimations];\n module.componentAnimations = {\n load: (engine: RpgClientEngine) => {\n componentAnimations.forEach((componentAnimation) => {\n engine.addComponentAnimation(componentAnimation);\n });\n },\n };\n }\n if (module.clientVisuals) {\n const clientVisuals = { ...module.clientVisuals };\n module.clientVisuals = {\n load: (engine: RpgClientEngine) => {\n engine.registerClientVisuals(clientVisuals);\n },\n };\n }\n if (module.projectiles) {\n const projectiles = { ...module.projectiles };\n module.projectiles = {\n ...projectiles,\n load: (engine: RpgClientEngine) => {\n if (projectiles.components) {\n Object.entries(projectiles.components).forEach(([type, component]) => {\n engine.registerProjectileComponent(type, component);\n });\n }\n },\n };\n }\n if (module.interactions) {\n const interactions = module.interactions;\n module.interactions = {\n ...interactions,\n load: (engine: RpgClientEngine) => {\n if (typeof interactions === \"function\") {\n interactions(engine);\n return;\n }\n interactions.load?.(engine);\n interactions.setup?.(engine);\n if (Array.isArray(interactions.use)) {\n interactions.use.forEach(([matcher, behavior]) => {\n engine.interactions.use(matcher, behavior);\n });\n }\n },\n };\n }\n if (module.transitions) {\n const transitions = [...module.transitions];\n module.transitions = {\n load: (engine: RpgClientEngine) => {\n const guiService = inject(engine.context, RpgGui) as RpgGui;\n transitions.forEach((transition) => {\n guiService.add({\n name: transition.id,\n component: transition.component,\n data: transition.props || {}\n });\n });\n },\n };\n }\n if (module.particles) {\n const particles = [...module.particles];\n module.particles = {\n load: (engine: RpgClientEngine) => {\n particles.forEach((particle) => {\n engine.addParticle(particle);\n });\n },\n };\n }\n if (module.sprite) {\n const sprite = {...module.sprite};\n module.sprite = {\n ...sprite,\n load: (engine: RpgClientEngine) => {\n if (sprite.componentsBehind) {\n sprite.componentsBehind.forEach((component) => {\n engine.addSpriteComponentBehind(component);\n });\n }\n if (sprite.componentsInFront) {\n sprite.componentsInFront.forEach((component) => {\n engine.addSpriteComponentInFront(component);\n });\n }\n if (sprite.components) {\n Object.entries(sprite.components).forEach(([id, component]) => {\n engine.registerSpriteComponent(id, component);\n });\n }\n if (sprite.eventComponent) {\n engine.addEventComponentResolver(sprite.eventComponent);\n }\n },\n };\n }\n return module;\n });\n return modules\n });\n}\n\nexport const GlobalConfigToken = \"GlobalConfigToken\";\n\nexport function provideGlobalConfig(config: any) {\n return {\n provide: GlobalConfigToken,\n useValue: config ?? {},\n };\n}\n\nexport function provideClientGlobalConfig(config: any = {}) {\n config.keyboardControls = {\n up: 'up',\n down: 'down',\n left: 'left',\n right: 'right',\n action: 'space',\n dash: 'shift',\n escape: 'escape',\n ...(config.keyboardControls ?? {}),\n }\n return provideGlobalConfig(config)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,qBAAqB,SAA6C;CAChF,OAAO,eAAe,SAAS,WAAW,SAAS,YAAY;EAE7D,UAAU,CAAC,GADc,YAAY,SAAS,QAChC,GAAkB,GAAG,OAAO;EAC1C,UAAU,QAAQ,KAAK,WAAW;GAGhC,IAAI,OAAO,WAAW,YAAY;IAChC,MAAM,WAAW,IAAI,OAAO;IAE5B,MAAM,YAAiB,CAAC;IACxB,KAAK,MAAM,OAAO,UAChB,UAAU,OAAO,SAAS;IAE5B,SAAS;GACX;GACA,IAAI,YAAY,QACd,SAAS,OAAO;GAElB,IAAI,OAAO,MACT,qBAAqB,SAAS,OAAO,MAAM,iBAAiB,EAAE;GAEhE,IAAI,OAAO,cAAc;IACvB,MAAM,eAAe,CAAC,GAAG,OAAO,YAAY;IAC5C,OAAO,eAAe,EACpB,OAAO,WAA4B;KACjC,aAAa,SAAS,gBAAgB;MACpC,OAAO,eAAe,WAAW;KACnC,CAAC;IACH,EACF;GACF;GACA,IAAI,OAAO,qBAAqB;IAC9B,MAAM,WAAW,OAAO;IACxB,OAAO,sBAAsB,EAC3B,OAAO,WAA4B;KACjC,OAAO,uBAAuB,QAAQ;IACxC,EACF;GACF;GACA,IAAI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G,OAAO,OAAM;IAChC,OAAO,SAAS;KACd,GAAG;KACH,OAAO,WAA4B;MACjC,IAAI,OAAO,kBACT,OAAO,iBAAiB,SAAS,cAAc;OAC7C,OAAO,yBAAyB,SAAS;MAC3C,CAAC;MAEH,IAAI,OAAO,mBACT,OAAO,kBAAkB,SAAS,cAAc;OAC9C,OAAO,0BAA0B,SAAS;MAC5C,CAAC;MAEH,IAAI,OAAO,YACT,OAAO,QAAQ,OAAO,UAAU,EAAE,SAAS,CAAC,IAAI,eAAe;OAC7D,OAAO,wBAAwB,IAAI,SAAS;MAC9C,CAAC;MAEH,IAAI,OAAO,gBACT,OAAO,0BAA0B,OAAO,cAAc;KAE1D;IACF;GACF;GACA,OAAO;EACT,CAAC;EACD,OAAO;CACT,CAAC;AACH;AAEA,IAAa,oBAAoB;AAEjC,SAAgB,oBAAoB,QAAa;CAC/C,OAAO;EACL,SAAS;EACT,UAAU,UAAU,CAAC;CACvB;AACF;AAEA,SAAgB,0BAA0B,SAAc,CAAC,GAAG;CAC1D,OAAO,mBAAmB;EACxB,IAAI;EACJ,MAAM;EACN,MAAM;EACN,OAAO;EACP,QAAQ;EACR,MAAM;EACN,QAAQ;EACR,GAAI,OAAO,oBAAoB,CAAC;CAClC;CACA,OAAO,oBAAoB,MAAM;AACnC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RpgActionInput, RpgActionName } from '@rpgjs/common';
|
|
1
|
+
import { Direction, RpgActionInput, RpgActionName } from '@rpgjs/common';
|
|
2
2
|
export type KeyboardActionDataResolver<TClient = any, TSprite = any> = (client: TClient, sprite: TSprite) => any;
|
|
3
3
|
export interface KeyboardActionConfig<TClient = any, TSprite = any> {
|
|
4
4
|
bind: any;
|
|
@@ -9,4 +9,6 @@ export declare function normalizeActionInput(action: RpgActionName, data?: any):
|
|
|
9
9
|
export declare function normalizeActionInput(action: RpgActionInput): RpgActionInput;
|
|
10
10
|
export declare function isKeyboardActionConfig(value: any): value is KeyboardActionConfig;
|
|
11
11
|
export declare function getKeyboardControlBind(control: any): any;
|
|
12
|
+
export declare function keyboardEventMatchesBind(event: KeyboardEvent, bind: any): boolean;
|
|
12
13
|
export declare function resolveKeyboardActionInput(control: any, client: any, sprite: any, defaultAction?: RpgActionName): RpgActionInput;
|
|
14
|
+
export declare function resolveKeyboardDirectionInput(event: KeyboardEvent, keyboardControls: any): Direction | undefined;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Direction } from "@rpgjs/common";
|
|
1
2
|
//#region src/services/actionInput.ts
|
|
2
3
|
function normalizeActionInput(action, data) {
|
|
3
4
|
if (typeof action === "object") return action;
|
|
@@ -12,6 +13,28 @@ function isKeyboardActionConfig(value) {
|
|
|
12
13
|
function getKeyboardControlBind(control) {
|
|
13
14
|
return isKeyboardActionConfig(control) ? control.bind : control;
|
|
14
15
|
}
|
|
16
|
+
var KEY_CODE_NAMES = {
|
|
17
|
+
32: "space",
|
|
18
|
+
27: "escape",
|
|
19
|
+
37: "left",
|
|
20
|
+
38: "up",
|
|
21
|
+
39: "right",
|
|
22
|
+
40: "down"
|
|
23
|
+
};
|
|
24
|
+
var normalizeKeyboardName = (value) => {
|
|
25
|
+
if (typeof value !== "string") return void 0;
|
|
26
|
+
const normalized = value.toLowerCase();
|
|
27
|
+
if (normalized === " " || normalized === "spacebar" || normalized === "space") return "space";
|
|
28
|
+
if (normalized.startsWith("arrow")) return normalized.slice(5);
|
|
29
|
+
return normalized;
|
|
30
|
+
};
|
|
31
|
+
function keyboardEventMatchesBind(event, bind) {
|
|
32
|
+
if (Array.isArray(bind)) return bind.some((item) => keyboardEventMatchesBind(event, item));
|
|
33
|
+
if (typeof bind === "number") return event.keyCode === bind;
|
|
34
|
+
const expected = normalizeKeyboardName(bind);
|
|
35
|
+
if (!expected) return false;
|
|
36
|
+
return normalizeKeyboardName(event.key) === expected || normalizeKeyboardName(event.code) === expected || KEY_CODE_NAMES[event.keyCode] === expected;
|
|
37
|
+
}
|
|
15
38
|
function resolveKeyboardActionInput(control, client, sprite, defaultAction = "action") {
|
|
16
39
|
if (!isKeyboardActionConfig(control)) return { action: defaultAction };
|
|
17
40
|
const action = control.action ?? defaultAction;
|
|
@@ -21,7 +44,16 @@ function resolveKeyboardActionInput(control, client, sprite, defaultAction = "ac
|
|
|
21
44
|
data
|
|
22
45
|
};
|
|
23
46
|
}
|
|
47
|
+
function resolveKeyboardDirectionInput(event, keyboardControls) {
|
|
48
|
+
const directions = [
|
|
49
|
+
[keyboardControls?.up, Direction.Up],
|
|
50
|
+
[keyboardControls?.down, Direction.Down],
|
|
51
|
+
[keyboardControls?.left, Direction.Left],
|
|
52
|
+
[keyboardControls?.right, Direction.Right]
|
|
53
|
+
];
|
|
54
|
+
for (const [control, direction] of directions) if (keyboardEventMatchesBind(event, getKeyboardControlBind(control))) return direction;
|
|
55
|
+
}
|
|
24
56
|
//#endregion
|
|
25
|
-
export { getKeyboardControlBind, isKeyboardActionConfig, normalizeActionInput, resolveKeyboardActionInput };
|
|
57
|
+
export { getKeyboardControlBind, isKeyboardActionConfig, keyboardEventMatchesBind, normalizeActionInput, resolveKeyboardActionInput, resolveKeyboardDirectionInput };
|
|
26
58
|
|
|
27
59
|
//# sourceMappingURL=actionInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionInput.js","names":[],"sources":["../../src/services/actionInput.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"actionInput.js","names":[],"sources":["../../src/services/actionInput.ts"],"sourcesContent":["import { Direction, type RpgActionInput, type RpgActionName } from \"@rpgjs/common\";\n\nexport type KeyboardActionDataResolver<TClient = any, TSprite = any> = (\n client: TClient,\n sprite: TSprite,\n) => any;\n\nexport interface KeyboardActionConfig<TClient = any, TSprite = any> {\n bind: any;\n action?: RpgActionName;\n data?: any | KeyboardActionDataResolver<TClient, TSprite>;\n}\n\nexport function normalizeActionInput(action: RpgActionName, data?: any): RpgActionInput;\nexport function normalizeActionInput(action: RpgActionInput): RpgActionInput;\nexport function normalizeActionInput(action: RpgActionName | RpgActionInput, data?: any): RpgActionInput {\n if (typeof action === \"object\") {\n return action;\n }\n return data === undefined\n ? { action }\n : { action, data };\n}\n\nexport function isKeyboardActionConfig(value: any): value is KeyboardActionConfig {\n return value !== null\n && typeof value === \"object\"\n && Object.prototype.hasOwnProperty.call(value, \"bind\");\n}\n\nexport function getKeyboardControlBind(control: any): any {\n return isKeyboardActionConfig(control) ? control.bind : control;\n}\n\nconst KEY_CODE_NAMES: Record<number, string> = {\n 32: \"space\",\n 27: \"escape\",\n 37: \"left\",\n 38: \"up\",\n 39: \"right\",\n 40: \"down\",\n};\n\nconst normalizeKeyboardName = (value: unknown): string | undefined => {\n if (typeof value !== \"string\") return undefined;\n const normalized = value.toLowerCase();\n if (\n normalized === \" \" ||\n normalized === \"spacebar\" ||\n normalized === \"space\"\n ) {\n return \"space\";\n }\n if (normalized.startsWith(\"arrow\")) {\n return normalized.slice(\"arrow\".length);\n }\n return normalized;\n};\n\nexport function keyboardEventMatchesBind(\n event: KeyboardEvent,\n bind: any\n): boolean {\n if (Array.isArray(bind)) {\n return bind.some(item => keyboardEventMatchesBind(event, item));\n }\n\n if (typeof bind === \"number\") {\n return event.keyCode === bind;\n }\n\n const expected = normalizeKeyboardName(bind);\n if (!expected) return false;\n\n return (\n normalizeKeyboardName(event.key) === expected ||\n normalizeKeyboardName(event.code) === expected ||\n KEY_CODE_NAMES[event.keyCode] === expected\n );\n}\n\nexport function resolveKeyboardActionInput(\n control: any,\n client: any,\n sprite: any,\n defaultAction: RpgActionName = \"action\",\n): RpgActionInput {\n if (!isKeyboardActionConfig(control)) {\n return { action: defaultAction };\n }\n\n const action = control.action ?? defaultAction;\n const data = typeof control.data === \"function\"\n ? control.data(client, sprite)\n : control.data;\n\n return data === undefined\n ? { action }\n : { action, data };\n}\n\nexport function resolveKeyboardDirectionInput(\n event: KeyboardEvent,\n keyboardControls: any\n): Direction | undefined {\n const directions: Array<[any, Direction]> = [\n [keyboardControls?.up, Direction.Up],\n [keyboardControls?.down, Direction.Down],\n [keyboardControls?.left, Direction.Left],\n [keyboardControls?.right, Direction.Right],\n ];\n\n for (const [control, direction] of directions) {\n if (keyboardEventMatchesBind(event, getKeyboardControlBind(control))) {\n return direction;\n }\n }\n\n return undefined;\n}\n"],"mappings":";;AAeA,SAAgB,qBAAqB,QAAwC,MAA4B;CACvG,IAAI,OAAO,WAAW,UACpB,OAAO;CAET,OAAO,SAAS,KAAA,IACZ,EAAE,OAAO,IACT;EAAE;EAAQ;CAAK;AACrB;AAEA,SAAgB,uBAAuB,OAA2C;CAChF,OAAO,UAAU,QACZ,OAAO,UAAU,YACjB,OAAO,UAAU,eAAe,KAAK,OAAO,MAAM;AACzD;AAEA,SAAgB,uBAAuB,SAAmB;CACxD,OAAO,uBAAuB,OAAO,IAAI,QAAQ,OAAO;AAC1D;AAEA,IAAM,iBAAyC;CAC7C,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,IAAM,yBAAyB,UAAuC;CACpE,IAAI,OAAO,UAAU,UAAU,OAAO,KAAA;CACtC,MAAM,aAAa,MAAM,YAAY;CACrC,IACE,eAAe,OACf,eAAe,cACf,eAAe,SAEf,OAAO;CAET,IAAI,WAAW,WAAW,OAAO,GAC/B,OAAO,WAAW,MAAM,CAAc;CAExC,OAAO;AACT;AAEA,SAAgB,yBACd,OACA,MACS;CACT,IAAI,MAAM,QAAQ,IAAI,GACpB,OAAO,KAAK,MAAK,SAAQ,yBAAyB,OAAO,IAAI,CAAC;CAGhE,IAAI,OAAO,SAAS,UAClB,OAAO,MAAM,YAAY;CAG3B,MAAM,WAAW,sBAAsB,IAAI;CAC3C,IAAI,CAAC,UAAU,OAAO;CAEtB,OACE,sBAAsB,MAAM,GAAG,MAAM,YACrC,sBAAsB,MAAM,IAAI,MAAM,YACtC,eAAe,MAAM,aAAa;AAEtC;AAEA,SAAgB,2BACd,SACA,QACA,QACA,gBAA+B,UACf;CAChB,IAAI,CAAC,uBAAuB,OAAO,GACjC,OAAO,EAAE,QAAQ,cAAc;CAGjC,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,OAAO,OAAO,QAAQ,SAAS,aACjC,QAAQ,KAAK,QAAQ,MAAM,IAC3B,QAAQ;CAEZ,OAAO,SAAS,KAAA,IACZ,EAAE,OAAO,IACT;EAAE;EAAQ;CAAK;AACrB;AAEA,SAAgB,8BACd,OACA,kBACuB;CACvB,MAAM,aAAsC;EAC1C,CAAC,kBAAkB,IAAI,UAAU,EAAE;EACnC,CAAC,kBAAkB,MAAM,UAAU,IAAI;EACvC,CAAC,kBAAkB,MAAM,UAAU,IAAI;EACvC,CAAC,kBAAkB,OAAO,UAAU,KAAK;CAC3C;CAEA,KAAK,MAAM,CAAC,SAAS,cAAc,YACjC,IAAI,yBAAyB,OAAO,uBAAuB,OAAO,CAAC,GACjE,OAAO;AAKb"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { RpgActionInput, RpgActionName } from '@rpgjs/common';
|
|
2
|
+
import { RpgClientEngine } from '../RpgClientEngine';
|
|
3
|
+
export type RpgInteractionEventName = "pointerenter" | "pointerleave" | "pointerover" | "pointerout" | "pointerdown" | "pointerup" | "pointermove" | "click" | "dragstart" | "dragmove" | "drop" | "cancel";
|
|
4
|
+
export type RpgInteractionPosition = {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
};
|
|
8
|
+
export type RpgInteractionBounds = {
|
|
9
|
+
left: number;
|
|
10
|
+
top: number;
|
|
11
|
+
right: number;
|
|
12
|
+
bottom: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
centerX: number;
|
|
16
|
+
centerY: number;
|
|
17
|
+
contains(point: RpgInteractionPosition | null | undefined): boolean;
|
|
18
|
+
};
|
|
19
|
+
export type RpgInteractionBoundsSet = {
|
|
20
|
+
bounds?: RpgInteractionBounds;
|
|
21
|
+
hitbox?: RpgInteractionBounds;
|
|
22
|
+
graphic?: RpgInteractionBounds;
|
|
23
|
+
[key: string]: RpgInteractionBounds | undefined;
|
|
24
|
+
};
|
|
25
|
+
export type RpgInteractionTile = {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
worldX: number;
|
|
29
|
+
worldY: number;
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
};
|
|
33
|
+
export type RpgInteractionState = {
|
|
34
|
+
hovered: boolean;
|
|
35
|
+
pressed: boolean;
|
|
36
|
+
selected: boolean;
|
|
37
|
+
dragging: boolean;
|
|
38
|
+
data: Record<string, any>;
|
|
39
|
+
overlays: Record<string, RpgInteractionOverlay>;
|
|
40
|
+
};
|
|
41
|
+
export type RpgInteractionOverlay = {
|
|
42
|
+
component: any;
|
|
43
|
+
props?: Record<string, any>;
|
|
44
|
+
};
|
|
45
|
+
export type RpgInteractionMatcher = string | ((ctx: RpgInteractionMatcherContext) => boolean);
|
|
46
|
+
export type RpgInteractionMatcherContext = {
|
|
47
|
+
client: RpgClientEngine;
|
|
48
|
+
target: any;
|
|
49
|
+
sprite: any;
|
|
50
|
+
};
|
|
51
|
+
export type RpgInteractionHandler = (ctx: RpgInteractionContext) => void;
|
|
52
|
+
export type RpgInteractionBehavior = {
|
|
53
|
+
component?: any;
|
|
54
|
+
props?: Record<string, any> | ((ctx: RpgInteractionContext) => Record<string, any>);
|
|
55
|
+
dependencies?: any[] | ((ctx: RpgInteractionContext) => any[]);
|
|
56
|
+
cursor?: string | ((ctx: RpgInteractionContext) => string | undefined);
|
|
57
|
+
hitTest?: (ctx: RpgInteractionContext) => boolean;
|
|
58
|
+
pointerenter?: RpgInteractionHandler;
|
|
59
|
+
pointerleave?: RpgInteractionHandler;
|
|
60
|
+
pointerover?: RpgInteractionHandler;
|
|
61
|
+
pointerout?: RpgInteractionHandler;
|
|
62
|
+
pointerdown?: RpgInteractionHandler;
|
|
63
|
+
pointerup?: RpgInteractionHandler;
|
|
64
|
+
pointermove?: RpgInteractionHandler;
|
|
65
|
+
click?: RpgInteractionHandler;
|
|
66
|
+
dragstart?: RpgInteractionHandler;
|
|
67
|
+
dragmove?: RpgInteractionHandler;
|
|
68
|
+
drop?: RpgInteractionHandler;
|
|
69
|
+
cancel?: RpgInteractionHandler;
|
|
70
|
+
};
|
|
71
|
+
export type RpgInteractionComponentEntry = {
|
|
72
|
+
component: any;
|
|
73
|
+
props: Record<string, any>;
|
|
74
|
+
dependencies: any[];
|
|
75
|
+
};
|
|
76
|
+
export type RpgInteractionContext = {
|
|
77
|
+
client: RpgClientEngine;
|
|
78
|
+
target: any;
|
|
79
|
+
sprite: any;
|
|
80
|
+
event?: any;
|
|
81
|
+
behavior: RpgInteractionBehavior;
|
|
82
|
+
behaviorId: string;
|
|
83
|
+
pointer: {
|
|
84
|
+
screen(): RpgInteractionPosition | null;
|
|
85
|
+
world(): RpgInteractionPosition | null;
|
|
86
|
+
tile(): RpgInteractionTile | null;
|
|
87
|
+
};
|
|
88
|
+
bounds(kind?: string): RpgInteractionBounds;
|
|
89
|
+
state: {
|
|
90
|
+
value(): RpgInteractionState;
|
|
91
|
+
get<T = any>(key: string): T | undefined;
|
|
92
|
+
set(key: string, value: any): void;
|
|
93
|
+
patch(patch: Partial<Omit<RpgInteractionState, "data" | "overlays">>): void;
|
|
94
|
+
};
|
|
95
|
+
overlay: {
|
|
96
|
+
render(component: any, props?: Record<string, any>): void;
|
|
97
|
+
update(props?: Record<string, any>): void;
|
|
98
|
+
clear(): void;
|
|
99
|
+
};
|
|
100
|
+
select(selected?: boolean): void;
|
|
101
|
+
action(action: RpgActionName, data?: any): void;
|
|
102
|
+
action(input: RpgActionInput): void;
|
|
103
|
+
cancel(): void;
|
|
104
|
+
};
|
|
105
|
+
type InteractionEventInput = {
|
|
106
|
+
event?: any;
|
|
107
|
+
bounds?: RpgInteractionBoundsSet;
|
|
108
|
+
};
|
|
109
|
+
export declare class RpgClientInteractions {
|
|
110
|
+
private client;
|
|
111
|
+
private registrations;
|
|
112
|
+
private states;
|
|
113
|
+
private activeDrag?;
|
|
114
|
+
private nextId;
|
|
115
|
+
constructor(client: RpgClientEngine);
|
|
116
|
+
use(matcher: RpgInteractionMatcher, behavior: RpgInteractionBehavior | any): () => void;
|
|
117
|
+
getState(sprite: any): RpgInteractionState;
|
|
118
|
+
getRenderedComponents(sprite: any, bounds?: RpgInteractionBoundsSet): RpgInteractionComponentEntry[];
|
|
119
|
+
cursorFor(sprite: any, bounds?: RpgInteractionBoundsSet): string | undefined;
|
|
120
|
+
handle(sprite: any, type: RpgInteractionEventName, input?: InteractionEventInput): void;
|
|
121
|
+
handlePointerMove(event?: any): void;
|
|
122
|
+
handlePointerUp(event?: any): void;
|
|
123
|
+
cancelDrag(event?: any): void;
|
|
124
|
+
private getMatches;
|
|
125
|
+
private matches;
|
|
126
|
+
private createContext;
|
|
127
|
+
private callHandler;
|
|
128
|
+
private passesHitTest;
|
|
129
|
+
private isDraggable;
|
|
130
|
+
private defaultComponentProps;
|
|
131
|
+
private resolveProps;
|
|
132
|
+
private resolveDependencies;
|
|
133
|
+
private getSpriteId;
|
|
134
|
+
private patchState;
|
|
135
|
+
private patchStateData;
|
|
136
|
+
private patchOverlay;
|
|
137
|
+
private updateOverlay;
|
|
138
|
+
private clearOverlay;
|
|
139
|
+
private getPointerTile;
|
|
140
|
+
}
|
|
141
|
+
export declare function hoverPopover(component: any, props?: Record<string, any>): RpgInteractionBehavior;
|
|
142
|
+
export declare function selectable(options?: {
|
|
143
|
+
cursor?: string;
|
|
144
|
+
onSelect?: RpgInteractionHandler;
|
|
145
|
+
}): RpgInteractionBehavior;
|
|
146
|
+
export declare function draggable(options?: {
|
|
147
|
+
cursor?: string;
|
|
148
|
+
start?: RpgInteractionHandler;
|
|
149
|
+
move?: RpgInteractionHandler;
|
|
150
|
+
drop?: RpgInteractionHandler;
|
|
151
|
+
cancel?: RpgInteractionHandler;
|
|
152
|
+
}): RpgInteractionBehavior;
|
|
153
|
+
export declare function dragToTile(options: {
|
|
154
|
+
action?: RpgActionName;
|
|
155
|
+
data?: (ctx: RpgInteractionContext) => any;
|
|
156
|
+
onDrop?: RpgInteractionHandler;
|
|
157
|
+
cursor?: string;
|
|
158
|
+
}): RpgInteractionBehavior;
|
|
159
|
+
export {};
|