@rpgjs/client 5.0.0-alpha.10 → 5.0.0-alpha.12

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 (90) hide show
  1. package/dist/Game/Map.d.ts +4 -0
  2. package/dist/Gui/Gui.d.ts +128 -5
  3. package/dist/RpgClient.d.ts +35 -5
  4. package/dist/RpgClientEngine.d.ts +3 -0
  5. package/dist/components/gui/index.d.ts +3 -3
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +7 -5
  8. package/dist/index.js.map +1 -1
  9. package/dist/index10.js +150 -4
  10. package/dist/index10.js.map +1 -1
  11. package/dist/index11.js +20 -7
  12. package/dist/index11.js.map +1 -1
  13. package/dist/index12.js +6 -8
  14. package/dist/index12.js.map +1 -1
  15. package/dist/index13.js +11 -14
  16. package/dist/index13.js.map +1 -1
  17. package/dist/index14.js +8 -100
  18. package/dist/index14.js.map +1 -1
  19. package/dist/index15.js +141 -35
  20. package/dist/index15.js.map +1 -1
  21. package/dist/index16.js +42 -0
  22. package/dist/index16.js.map +1 -1
  23. package/dist/index17.js +48 -7
  24. package/dist/index17.js.map +1 -1
  25. package/dist/index18.js +5 -383
  26. package/dist/index18.js.map +1 -1
  27. package/dist/index19.js +384 -28
  28. package/dist/index19.js.map +1 -1
  29. package/dist/index2.js +32 -13
  30. package/dist/index2.js.map +1 -1
  31. package/dist/index20.js +31 -17
  32. package/dist/index20.js.map +1 -1
  33. package/dist/index21.js +17 -2413
  34. package/dist/index21.js.map +1 -1
  35. package/dist/index22.js +2587 -88
  36. package/dist/index22.js.map +1 -1
  37. package/dist/index23.js +108 -103
  38. package/dist/index23.js.map +1 -1
  39. package/dist/index29.js +22 -3
  40. package/dist/index29.js.map +1 -1
  41. package/dist/index3.js +2 -2
  42. package/dist/index30.js +1 -318
  43. package/dist/index30.js.map +1 -1
  44. package/dist/index31.js +332 -24
  45. package/dist/index31.js.map +1 -1
  46. package/dist/index32.js +24 -8
  47. package/dist/index32.js.map +1 -1
  48. package/dist/index33.js +4 -4
  49. package/dist/index33.js.map +1 -1
  50. package/dist/index34.js +8 -9
  51. package/dist/index34.js.map +1 -1
  52. package/dist/index35.js +9 -4400
  53. package/dist/index35.js.map +1 -1
  54. package/dist/index36.js +4394 -307
  55. package/dist/index36.js.map +1 -1
  56. package/dist/index37.js +307 -165
  57. package/dist/index37.js.map +1 -1
  58. package/dist/index38.js +162 -489
  59. package/dist/index38.js.map +1 -1
  60. package/dist/index39.js +496 -56
  61. package/dist/index39.js.map +1 -1
  62. package/dist/index4.js +2 -2
  63. package/dist/index40.js +67 -10
  64. package/dist/index40.js.map +1 -1
  65. package/dist/index41.js +16 -78
  66. package/dist/index41.js.map +1 -1
  67. package/dist/index42.js +96 -0
  68. package/dist/index42.js.map +1 -0
  69. package/dist/index9.js +228 -14
  70. package/dist/index9.js.map +1 -1
  71. package/dist/presets/faceset.d.ts +30 -0
  72. package/dist/presets/index.d.ts +1 -0
  73. package/dist/services/mmorpg.d.ts +1 -1
  74. package/dist/services/standalone.d.ts +1 -1
  75. package/package.json +7 -5
  76. package/src/Game/AnimationManager.ts +1 -0
  77. package/src/Game/Map.ts +9 -1
  78. package/src/Game/Object.ts +28 -6
  79. package/src/Gui/Gui.ts +300 -17
  80. package/src/RpgClient.ts +36 -5
  81. package/src/RpgClientEngine.ts +32 -9
  82. package/src/components/character.ce +11 -9
  83. package/src/components/gui/box.ce +17 -0
  84. package/src/components/gui/dialogbox/index.ce +74 -35
  85. package/src/components/gui/dialogbox/selection.ce +16 -1
  86. package/src/components/gui/index.ts +3 -4
  87. package/src/components/scenes/event-layer.ce +6 -0
  88. package/src/index.ts +3 -1
  89. package/src/presets/faceset.ts +60 -0
  90. package/src/presets/index.ts +3 -1
package/dist/index23.js CHANGED
@@ -1,109 +1,114 @@
1
- import { useProps, useDefineProps, signal, animatedSignal, computed, trigger, mount, effect, h, Container, Rect, cond, Text } from 'canvasengine';
2
- import component$1 from './index39.js';
3
- import { inject } from './index6.js';
4
- import { RpgClientEngine } from './index2.js';
1
+ import { __name } from './index30.js';
2
+ import { load } from './index19.js';
3
+ import { PartySocket } from './index38.js';
4
+ import './index39.js';
5
5
 
6
- function component($$props) {
7
- useProps($$props);
8
- const defineProps = useDefineProps($$props);
9
- var _a = defineProps(), message = _a.message, _choices = _a.choices, onFinish = _a.onFinish; _a.onInteraction;
10
- var client = inject(RpgClientEngine);
11
- var keyboardControls = client.globalConfig.keyboardControls;
12
- client.stopProcessingInput = true;
13
- var isDestroyed = false;
14
- var texts = [message()];
15
- var height = signal(250);
16
- var isTextCompleted = signal(false);
17
- var border = signal({ width: 5, color: "#595971" });
18
- var shadow = signal({ color: "#000", blur: 10, offsetX: 10, offsetY: 10 });
19
- var contentOpacity = animatedSignal(0, {
20
- duration: 1000,
21
- });
22
- var scaleX = animatedSignal(0, {
23
- duration: 500,
24
- });
25
- scaleX.set(1);
26
- contentOpacity.set(1);
27
- var currentTextIndex = signal(0);
28
- var currentText = computed(function () { var _a; return (_a = texts === null || texts === void 0 ? void 0 : texts[currentTextIndex()]) !== null && _a !== void 0 ? _a : ''; });
29
- var isChoiceDisplayed = signal(false);
30
- var text = computed(function () {
31
- var current = currentText();
32
- return typeof current === "string" ? current : current.text;
33
- });
34
- var choices = computed(function () {
35
- //const current = currentText();
36
- //return typeof current === "string" ? null : current.choices;
37
- return _choices;
38
- });
39
- var visibleSelection = computed(function () { return isChoiceDisplayed() && choices().length != 0; });
40
- var triggerSkip = trigger();
41
- var typewriter = {
42
- speed: 0.3,
43
- skip: triggerSkip,
44
- onComplete: function () {
45
- isTextCompleted.set(true);
6
+ function createConnection(options, roomInstance) {
7
+ const conn = new PartySocket(options);
8
+ conn.addEventListener("message", (event) => {
9
+ const object = JSON.parse(event.data);
10
+ switch (object.type) {
11
+ case "sync":
12
+ load(roomInstance, object.value, true);
13
+ break;
46
14
  }
47
- };
48
- var textStyle = {
49
- wordWrap: true,
50
- wordWrapWidth: 700 - 256 - 80
51
- };
52
- signal({ x: 0, y: 0, width: 256, height: 256 });
53
- mount(function (element) {
54
- var dialogbox = element.props.children[0];
55
- return function () {
56
- dialogbox.directives.controls.onDestroy();
57
- isDestroyed = true;
58
- // Wait destroy is finished before start processing input
59
- setTimeout(function () {
60
- client.stopProcessingInput = false;
61
- }, 500);
62
- };
63
- });
64
- var controls = signal({
65
- next: {
66
- bind: keyboardControls.action,
67
- keyDown: function (e) {
68
- if (isDestroyed)
69
- return;
70
- if (isChoiceDisplayed()) {
71
- // If choices are displayed, do nothing (wait for selection)
72
- return;
73
- }
74
- // If text is still typing, just skip (fast forward) the animation
75
- if (!isTextCompleted()) {
76
- triggerSkip.start();
77
- isTextCompleted.set(true);
78
- }
79
- else {
80
- var isFinished = currentTextIndex() === texts.length - 1;
81
- currentTextIndex.update(function (index) {
82
- if (index < texts.length - 1) {
83
- return index + 1;
84
- }
85
- return index;
86
- });
87
- isChoiceDisplayed.set(false);
88
- isTextCompleted.set(false);
89
- if (isFinished && onFinish) {
90
- onFinish();
91
- }
92
- }
15
+ });
16
+ return {
17
+ emit: /* @__PURE__ */ __name((key, value) => {
18
+ conn.send(JSON.stringify({
19
+ action: key,
20
+ value
21
+ }));
22
+ }, "emit"),
23
+ on: /* @__PURE__ */ __name((key, cb) => {
24
+ conn.addEventListener("message", (event) => {
25
+ const object = JSON.parse(event.data);
26
+ if (object.type === key) {
27
+ cb(object.value);
28
+ }
29
+ });
30
+ }, "on"),
31
+ off: /* @__PURE__ */ __name((key, cb) => {
32
+ conn.removeEventListener("message", (event) => {
33
+ const object = JSON.parse(event.data);
34
+ if (object.type === key) {
35
+ cb(object.value);
36
+ }
37
+ });
38
+ }, "off"),
39
+ close: /* @__PURE__ */ __name(() => conn.close(), "close"),
40
+ conn
41
+ };
42
+ }
43
+ __name(createConnection, "createConnection");
44
+ async function connectionRoom(options, roomInstance) {
45
+ return createConnection(options, roomInstance);
46
+ }
47
+ __name(connectionRoom, "connectionRoom");
48
+ async function connectionWorld(options, roomInstance) {
49
+ const shardInfo = await getOptimalShard(options);
50
+ const result = createConnection({
51
+ ...options,
52
+ party: "shard",
53
+ room: shardInfo.url
54
+ }, roomInstance);
55
+ return {
56
+ ...result,
57
+ shardInfo
58
+ };
59
+ }
60
+ __name(connectionWorld, "connectionWorld");
61
+ async function getOptimalShard(worldOptions) {
62
+ const {
63
+ host,
64
+ room,
65
+ worldId = "world-default",
66
+ retryCount = 3,
67
+ retryDelay = 1e3,
68
+ autoCreate = true
69
+ // Default to true for auto-creation
70
+ } = worldOptions;
71
+ let attempts = 0;
72
+ const url = new URL(`${host}/parties/world/${encodeURIComponent(worldId)}/connect`);
73
+ const requestUrl = url.toString();
74
+ while (attempts < retryCount) {
75
+ try {
76
+ const response = await fetch(requestUrl, {
77
+ method: "POST",
78
+ headers: {
79
+ "Content-Type": "application/json"
93
80
  },
94
- },
95
- });
96
- var onSelect = function (index) {
97
- onFinish(index);
98
- };
99
- effect(function () {
100
- if (choices().length != 0) {
101
- isChoiceDisplayed.set(true);
102
- }
103
- });
104
- let $this = h(Container, { justifyContent: 'center', alignItems: 'center', width: '100%', height: '100%' }, h(Container, { ref: 'dialogbox', scale: { x: scaleX }, anchor: [0.5, 0.5], width: 700, height, controls, positionType: 'absolute', bottom: 10 }, [h(Rect, { width: 700, height: 250, color: '#1a1a2e' }), h(Rect, { x: 0, y: 0, width: 700, height, color: '#1a1a2e', alpha: 0.9, borderRadius: 10, border, shadow }), h(Container, { flexDirection: 'row', width: 700, height, alpha: contentOpacity }, h(Container, { flexDirection: 'column' }, [h(Text, { text, color: '#fff', fontSize: 18, margin: 40, typewriter, style: textStyle }), cond(visibleSelection, () => h(component$1, { selectedIndex: 0, items: choices, onSelect }))]))]));
105
- return $this
81
+ body: JSON.stringify({
82
+ roomId: room,
83
+ autoCreate
84
+ })
85
+ });
86
+ if (!response.ok) {
87
+ const errorData = await response.json().catch(() => ({
88
+ error: "Unknown error"
89
+ }));
90
+ throw new Error(`World service returned ${response.status}: ${errorData.error || "Unknown error"}`);
91
+ }
92
+ const data = await response.json();
93
+ if (!data.url || !data.shardId) {
94
+ throw new Error("Invalid response from World service: missing url or shardId");
106
95
  }
96
+ return {
97
+ shardId: data.shardId,
98
+ url: data.url
99
+ };
100
+ } catch (error) {
101
+ attempts++;
102
+ if (attempts >= retryCount) {
103
+ throw error;
104
+ }
105
+ console.warn(`Failed to get shard (attempt ${attempts}/${retryCount}). Retrying in ${retryDelay}ms...`);
106
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
107
+ }
108
+ }
109
+ throw new Error("Failed to get shard after all retry attempts");
110
+ }
111
+ __name(getOptimalShard, "getOptimalShard");
107
112
 
108
- export { component as default };
113
+ export { PartySocket, connectionRoom, connectionWorld };
109
114
  //# sourceMappingURL=index23.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index23.js","sources":["../src/components/gui/dialogbox/index.ce"],"sourcesContent":["<Container justifyContent=\"center\" alignItems=\"center\" width=\"100%\" height=\"100%\">\n <Container\n ref=\"dialogbox\"\n scale={{ x: scaleX }}\n anchor={[0.5, 0.5]}\n width={700}\n height\n controls\n positionType=\"absolute\"\n bottom={10}\n >\n <Rect width={700} height={250} color=\"#1a1a2e\" />\n <Rect\n x={0}\n y={0}\n width={700}\n height\n color=\"#1a1a2e\"\n alpha={0.9}\n borderRadius={10}\n border\n shadow\n />\n <Container\n flexDirection=\"row\"\n width={700}\n height\n alpha={contentOpacity}\n >\n <Container flexDirection=\"column\">\n <Text\n text\n color=\"#fff\"\n fontSize={18}\n margin={40}\n typewriter\n style={textStyle}\n />\n @if (visibleSelection) {\n <Selection selectedIndex={0} items={choices} onSelect />\n }\n </Container>\n </Container>\n</Container> \n\n \n</Container>\n<script>\n import Selection from './selection.ce'\n\n import {\n animatedSignal,\n computed,\n effect,\n signal,\n trigger,\n mount\n } from \"canvasengine\";\n\n import { inject } from \"../../../core/inject\";\n import { RpgClientEngine } from \"../../../RpgClientEngine\";\n\n const {\n message,\n choices: _choices,\n onFinish,\n onInteraction\n } = defineProps();\n\n const client = inject(RpgClientEngine);\n const keyboardControls = client.globalConfig.keyboardControls;\n\n client.stopProcessingInput = true;\n let isDestroyed = false;\n\n const texts = [message()]\n const height = signal(250);\n const isTextCompleted = signal(false);\n\n const drawSpeaker = (g) => {\n g.beginFill(0xffa500); // Orange color\n g.lineStyle(2, 0x000000); // Black border\n g.moveTo(0, 0);\n g.lineTo(70, 0);\n g.lineTo(80, 15);\n g.lineTo(70, 30);\n g.lineTo(0, 30);\n g.lineTo(0, 0);\n g.endFill();\n };\n\n const border = signal({ width: 5, color: \"#595971\" });\n const shadow = signal({ color: \"#000\", blur: 10, offsetX: 10, offsetY: 10 });\n\n const contentOpacity = animatedSignal(0, {\n duration: 1000,\n });\n\n const scaleX = animatedSignal(0, {\n duration: 500,\n });\n\n scaleX.set(1);\n contentOpacity.set(1);\n\n const currentTextIndex = signal(0);\n const currentText = computed(() => texts?.[currentTextIndex()] ?? '');\n const isChoiceDisplayed = signal(false);\n\n const text = computed(() => {\n const current = currentText();\n return typeof current === \"string\" ? current : current.text;\n });\n\n const choices = computed(() => {\n //const current = currentText();\n //return typeof current === \"string\" ? null : current.choices;\n return _choices;\n });\n\n const visibleSelection = computed(() => isChoiceDisplayed() && choices().length != 0)\n\n const triggerSkip = trigger();\n\n const typewriter = {\n speed: 0.3,\n skip: triggerSkip,\n onComplete: () => {\n isTextCompleted.set(true);\n }\n }\n\n const textStyle = {\n wordWrap: true,\n wordWrapWidth: 700 - 256 - 80\n }\n\n const face = signal({ x: 0, y: 0, width: 256, height: 256 });\n\n mount((element) => {\n const [dialogbox] = element.props.children\n return () => {\n dialogbox.directives.controls.onDestroy()\n isDestroyed = true;\n // Wait destroy is finished before start processing input\n setTimeout(() => {\n client.stopProcessingInput = false;\n }, 500)\n }\n })\n\n const controls = signal({\n next: {\n bind: keyboardControls.action,\n keyDown(e) {\n if (isDestroyed) return;\n if (isChoiceDisplayed()) {\n // If choices are displayed, do nothing (wait for selection)\n return;\n }\n\n // If text is still typing, just skip (fast forward) the animation\n if (!isTextCompleted()) {\n triggerSkip.start();\n isTextCompleted.set(true);\n }\n else {\n const isFinished = currentTextIndex() === texts.length - 1;\n currentTextIndex.update((index) => {\n if (index < texts.length - 1) {\n return index + 1;\n }\n return index;\n });\n isChoiceDisplayed.set(false);\n isTextCompleted.set(false);\n if (isFinished && onFinish) {\n onFinish();\n } \n }\n },\n },\n });\n\n const onSelect = (index) => {\n onFinish(index);\n }\n \n effect(() => {\n if (choices().length != 0) {\n isChoiceDisplayed.set(true);\n }\n });\n</script>"],"names":["Selection"],"mappings":";;;;;AAWqB,SAAS,SAAS,CAAC,OAAO,EAAE;AACjD,QAAuB,QAAQ,CAAC,OAAO;AACvC,QAAQ,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO;AAClD,QAAW,IAAC,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,QAAQ,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAiB,EAAE,CAAC;AACxH,IAAI,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC;AACpC,IAAI,gBAAgB,GAAG,MAAM,CAAC,YAAY,CAAC,gBAAgB;AAC3D,MAAM,CAAC,mBAAmB,GAAG,IAAI;AACjC,IAAI,WAAW,GAAG,KAAK;AACvB,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC;AACvB,IAAI,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC;AACxB,IAAI,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC;AAYnC,IAAI,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AACnD,IAAI,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE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CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAACA,WAAS,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjuB,QAAQ,OAAO;AACf;;;;"}
1
+ {"version":3,"file":"index23.js","sources":["../../../node_modules/.pnpm/@signe+sync@2.4.0/node_modules/@signe/sync/dist/client/index.js"],"sourcesContent":["import {\n __name\n} from \"../chunk-7QVYU63E.js\";\n\n// src/client/index.ts\nimport { load } from \"@signe/sync\";\nimport PartySocket from \"partysocket\";\nfunction createConnection(options, roomInstance) {\n const conn = new PartySocket(options);\n conn.addEventListener(\"message\", (event) => {\n const object = JSON.parse(event.data);\n switch (object.type) {\n case \"sync\":\n load(roomInstance, object.value, true);\n break;\n }\n });\n return {\n emit: /* @__PURE__ */ __name((key, value) => {\n conn.send(JSON.stringify({\n action: key,\n value\n }));\n }, \"emit\"),\n on: /* @__PURE__ */ __name((key, cb) => {\n conn.addEventListener(\"message\", (event) => {\n const object = JSON.parse(event.data);\n if (object.type === key) {\n cb(object.value);\n }\n });\n }, \"on\"),\n off: /* @__PURE__ */ __name((key, cb) => {\n conn.removeEventListener(\"message\", (event) => {\n const object = JSON.parse(event.data);\n if (object.type === key) {\n cb(object.value);\n }\n });\n }, \"off\"),\n close: /* @__PURE__ */ __name(() => conn.close(), \"close\"),\n conn\n };\n}\n__name(createConnection, \"createConnection\");\nasync function connectionRoom(options, roomInstance) {\n return createConnection(options, roomInstance);\n}\n__name(connectionRoom, \"connectionRoom\");\nasync function connectionWorld(options, roomInstance) {\n const shardInfo = await getOptimalShard(options);\n const result = createConnection({\n ...options,\n party: \"shard\",\n room: shardInfo.url\n }, roomInstance);\n return {\n ...result,\n shardInfo\n };\n}\n__name(connectionWorld, \"connectionWorld\");\nasync function getOptimalShard(worldOptions) {\n const {\n host,\n room,\n worldId = \"world-default\",\n retryCount = 3,\n retryDelay = 1e3,\n autoCreate = true\n // Default to true for auto-creation\n } = worldOptions;\n let attempts = 0;\n const url = new URL(`${host}/parties/world/${encodeURIComponent(worldId)}/connect`);\n const requestUrl = url.toString();\n while (attempts < retryCount) {\n try {\n const response = await fetch(requestUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify({\n roomId: room,\n autoCreate\n })\n });\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({\n error: \"Unknown error\"\n }));\n throw new Error(`World service returned ${response.status}: ${errorData.error || \"Unknown error\"}`);\n }\n const data = await response.json();\n if (!data.url || !data.shardId) {\n throw new Error(\"Invalid response from World service: missing url or shardId\");\n }\n return {\n shardId: data.shardId,\n url: data.url\n };\n } catch (error) {\n attempts++;\n if (attempts >= retryCount) {\n throw error;\n }\n console.warn(`Failed to get shard (attempt ${attempts}/${retryCount}). Retrying in ${retryDelay}ms...`);\n await new Promise((resolve) => setTimeout(resolve, retryDelay));\n }\n }\n throw new Error(\"Failed to get shard after all retry attempts\");\n}\n__name(getOptimalShard, \"getOptimalShard\");\nexport {\n PartySocket,\n connectionRoom,\n connectionWorld\n};\n//# sourceMappingURL=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AAQ,MAAM,KAAK;AACnB;AACA,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,6BAA6B,EAAE,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC,eAAe,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;AAC7G,MAAM,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACrE;AACA;AACA,EAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;AACjE;AACA,MAAM,CAAC,eAAe,EAAE,iBAAiB,CAAC;;;;","x_google_ignoreList":[0]}
package/dist/index29.js CHANGED
@@ -1,5 +1,24 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
+ const FacesetPreset = (options, framesWidth, framesHeight, expressions) => {
2
+ const textures = {};
3
+ Object.keys(expressions).forEach((expressionName) => {
4
+ const [frameX, frameY] = expressions[expressionName];
5
+ textures[expressionName] = {
6
+ animations: () => [
7
+ [{
8
+ time: 0,
9
+ frameX,
10
+ frameY
11
+ }]
12
+ ]
13
+ };
14
+ });
15
+ return {
16
+ ...options,
17
+ framesWidth,
18
+ framesHeight,
19
+ textures
20
+ };
21
+ };
3
22
 
4
- export { __name };
23
+ export { FacesetPreset };
5
24
  //# sourceMappingURL=index29.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index29.js","sources":["../../../node_modules/.pnpm/@signe+sync@2.3.3/node_modules/@signe/sync/dist/chunk-7QVYU63E.js"],"sourcesContent":["var __defProp = Object.defineProperty;\nvar __name = (target, value) => __defProp(target, \"name\", { value, configurable: true });\n\nexport {\n __name\n};\n//# sourceMappingURL=chunk-7QVYU63E.js.map"],"names":[],"mappings":"AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc;AAClC,IAAC,MAAM,GAAG,CAAC,MAAM,EAAE,KAAK,KAAK,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE;;;;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"index29.js","sources":["../src/presets/faceset.ts"],"sourcesContent":["/**\n * Creates a faceset preset for character expressions\n * \n * This preset allows you to define multiple facial expressions for a character,\n * where each expression corresponds to a specific frame position (frameX, frameY)\n * within a single faceset texture. Each expression is defined by its position\n * in the faceset grid.\n * \n * @param options - Object containing the faceset configuration\n * @param framesWidth - Number of frames horizontally in the faceset texture\n * @param framesHeight - Number of frames vertically in the faceset texture\n * @param expressions - Object mapping expression names to their frame positions as tuples [frameX, frameY]\n * @returns Faceset configuration with animations for each expression\n * \n * @example\n * ```typescript\n * const faceset = FacesetPreset({\n * id: \"facesetId\",\n * image: \"faceset.png\",\n * width: 1024,\n * height: 1024,\n * }, 4, 2, {\n * happy: [0, 0],\n * sad: [1, 0],\n * angry: [2, 0],\n * surprised: [3, 0]\n * });\n * ```\n */\nexport const FacesetPreset = (\n options: any,\n framesWidth: number, \n framesHeight: number,\n expressions: Record<string, [number, number]>,\n) => {\n \n const textures: Record<string, any> = {};\n \n // Create texture configuration for each expression\n Object.keys(expressions).forEach((expressionName) => {\n const [frameX, frameY] = expressions[expressionName];\n textures[expressionName] = {\n animations: () => [\n [{ \n time: 0, \n frameX: frameX, \n frameY: frameY \n }]\n ],\n };\n });\n \n return {\n ...options,\n framesWidth,\n framesHeight,\n textures\n };\n};\n "],"names":[],"mappings":"AA6BO,MAAM,aAAgB,GAAA,CACzB,OACA,EAAA,WAAA,EACA,cACA,WACC,KAAA;AAED,EAAA,MAAM,WAAgC,EAAC;AAGvC,EAAA,MAAA,CAAO,IAAK,CAAA,WAAW,CAAE,CAAA,OAAA,CAAQ,CAAC,cAAmB,KAAA;AACjD,IAAA,MAAM,CAAC,MAAA,EAAQ,MAAM,CAAA,GAAI,YAAY,cAAc,CAAA;AACnD,IAAA,QAAA,CAAS,cAAc,CAAI,GAAA;AAAA,MACvB,YAAY,MAAM;AAAA,QACd,CAAC;AAAA,UACG,IAAM,EAAA,CAAA;AAAA,UACN,MAAA;AAAA,UACA;AAAA,SACH;AAAA;AACL,KACJ;AAAA,GACH,CAAA;AAED,EAAO,OAAA;AAAA,IACH,GAAG,OAAA;AAAA,IACH,WAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACJ;AACJ;;;;"}
package/dist/index3.js CHANGED
@@ -1,5 +1,5 @@
1
- import { WebSocketToken, AbstractWebsocket } from './index17.js';
2
- import { ServerIo, ClientIo } from './index21.js';
1
+ import { WebSocketToken, AbstractWebsocket } from './index18.js';
2
+ import { ServerIo, ClientIo } from './index22.js';
3
3
  import { RpgClientEngine } from './index2.js';
4
4
  import { UpdateMapToken, UpdateMapService } from '@rpgjs/common';
5
5
  import { RpgGui } from './index9.js';
package/dist/index30.js CHANGED
@@ -1,322 +1,5 @@
1
- import { BehaviorSubject, filter, combineLatest, map, finalize } from 'rxjs';
2
-
3
1
  var __defProp = Object.defineProperty;
4
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
- var ArraySubject = class extends BehaviorSubject {
6
- static {
7
- __name(this, "ArraySubject");
8
- }
9
- _items = [];
10
- constructor(items = []) {
11
- super({
12
- type: "init",
13
- items
14
- });
15
- this.createProxy(items);
16
- }
17
- createProxy(items) {
18
- this._items = new Proxy(items, {
19
- get: /* @__PURE__ */ __name((target, prop, receiver) => {
20
- const origMethod = target[prop];
21
- if (typeof origMethod === "function") {
22
- return (...args) => {
23
- let changeType = "update";
24
- let index = void 0;
25
- let isMutateFn = false;
26
- let itemsToEmit = [];
27
- let changeSplice = true;
28
- switch (prop) {
29
- case "push":
30
- index = target.length;
31
- changeType = "add";
32
- isMutateFn = true;
33
- break;
34
- case "pop":
35
- index = target.length - 1;
36
- changeType = "remove";
37
- isMutateFn = true;
38
- break;
39
- case "unshift":
40
- index = 0;
41
- changeType = "add";
42
- isMutateFn = true;
43
- break;
44
- case "shift":
45
- index = 0;
46
- changeType = "remove";
47
- isMutateFn = true;
48
- break;
49
- case "splice":
50
- index = args[0];
51
- const deleteCount = args[1];
52
- const newItems = args.slice(2);
53
- itemsToEmit = newItems;
54
- if (deleteCount > 0 && newItems.length === 0) {
55
- changeType = "remove";
56
- } else if (deleteCount === 0 && newItems.length > 0) {
57
- changeType = "add";
58
- } else if (deleteCount === 0 && newItems.length === 0) {
59
- changeSplice = false;
60
- } else {
61
- changeType = "update";
62
- }
63
- isMutateFn = true;
64
- break;
65
- }
66
- const result = origMethod.apply(target, args);
67
- if (isMutateFn && changeSplice) {
68
- if (prop === "splice") {
69
- this.next({
70
- type: changeType,
71
- index,
72
- items: itemsToEmit
73
- });
74
- } else {
75
- this.next({
76
- type: changeType,
77
- index,
78
- items: args
79
- });
80
- }
81
- }
82
- return result;
83
- };
84
- }
85
- return Reflect.get(target, prop, receiver);
86
- }, "get"),
87
- set: /* @__PURE__ */ __name((target, prop, value) => {
88
- const index = !isNaN(Number(prop)) ? Number(prop) : void 0;
89
- target[prop] = value;
90
- this.next({
91
- type: "update",
92
- index,
93
- items: [
94
- value
95
- ]
96
- });
97
- return true;
98
- }, "set")
99
- });
100
- }
101
- get items() {
102
- return this._items;
103
- }
104
- set items(newItems) {
105
- this.createProxy(newItems);
106
- this.next({
107
- type: "reset",
108
- items: newItems
109
- });
110
- }
111
- };
112
- var isArraySubject = /* @__PURE__ */ __name((value) => {
113
- return "_items" in value;
114
- }, "isArraySubject");
115
- var ObjectSubject = class extends BehaviorSubject {
116
- static {
117
- __name(this, "ObjectSubject");
118
- }
119
- _obj;
120
- constructor(obj = {}) {
121
- super({
122
- type: "init",
123
- value: obj
124
- });
125
- this.createProxy(obj);
126
- }
127
- createProxy(obj) {
128
- this._obj = new Proxy(obj, {
129
- get: /* @__PURE__ */ __name((target, prop, receiver) => {
130
- return Reflect.get(target, prop, receiver);
131
- }, "get"),
132
- set: /* @__PURE__ */ __name((target, prop, value, receiver) => {
133
- const key = prop;
134
- const changeType = key in target ? "update" : "add";
135
- target[key] = value;
136
- this.next({
137
- type: changeType,
138
- key,
139
- value
140
- });
141
- return true;
142
- }, "set"),
143
- deleteProperty: /* @__PURE__ */ __name((target, prop) => {
144
- const key = prop;
145
- if (key in target) {
146
- const value = target[key];
147
- delete target[key];
148
- this.next({
149
- type: "remove",
150
- key,
151
- value
152
- });
153
- return true;
154
- }
155
- return false;
156
- }, "deleteProperty")
157
- });
158
- }
159
- get obj() {
160
- return this._obj;
161
- }
162
- set obj(newObj) {
163
- this.createProxy(newObj);
164
- this.next({
165
- type: "reset",
166
- value: newObj
167
- });
168
- }
169
- };
170
- var isObjectSubject = /* @__PURE__ */ __name((value) => {
171
- return "_obj" in value;
172
- }, "isObjectSubject");
173
- var getGlobalReactiveStore = /* @__PURE__ */ __name(() => {
174
- const globalKey = "__REACTIVE_STORE__";
175
- if (typeof globalThis !== "undefined") {
176
- if (!globalThis[globalKey]) {
177
- globalThis[globalKey] = {
178
- currentDependencyTracker: null,
179
- currentSubscriptionsTracker: null
180
- };
181
- }
182
- return globalThis[globalKey];
183
- }
184
- let globalObj;
185
- if (typeof window !== "undefined") {
186
- globalObj = window;
187
- } else if (typeof process !== "undefined" && process.versions && process.versions.node) {
188
- globalObj = Function("return this")();
189
- } else if (typeof self !== "undefined") {
190
- globalObj = self;
191
- } else {
192
- console.warn("Unable to find global object, using local instance");
193
- return {
194
- currentDependencyTracker: null,
195
- currentSubscriptionsTracker: null
196
- };
197
- }
198
- if (!globalObj[globalKey]) {
199
- globalObj[globalKey] = {
200
- currentDependencyTracker: null,
201
- currentSubscriptionsTracker: null
202
- };
203
- }
204
- return globalObj[globalKey];
205
- }, "getGlobalReactiveStore");
206
- var reactiveStore = getGlobalReactiveStore();
207
- var trackDependency = /* @__PURE__ */ __name((signal2) => {
208
- if (reactiveStore.currentDependencyTracker) {
209
- reactiveStore.currentDependencyTracker(signal2);
210
- }
211
- }, "trackDependency");
212
- function signal(defaultValue) {
213
- let subject;
214
- if (Array.isArray(defaultValue)) {
215
- subject = new ArraySubject(defaultValue);
216
- } else if (typeof defaultValue === "object" && defaultValue !== null) {
217
- subject = new ObjectSubject(defaultValue);
218
- } else {
219
- subject = new BehaviorSubject(defaultValue);
220
- }
221
- const getValue = /* @__PURE__ */ __name(() => {
222
- if (subject instanceof ArraySubject) {
223
- return subject.items;
224
- } else if (subject instanceof ObjectSubject) {
225
- return subject.obj;
226
- }
227
- return subject.value;
228
- }, "getValue");
229
- const fn = /* @__PURE__ */ __name(function() {
230
- trackDependency(fn);
231
- return getValue();
232
- }, "fn");
233
- fn.set = (value) => {
234
- if (subject instanceof ArraySubject) {
235
- subject.items = value;
236
- } else if (subject instanceof ObjectSubject) {
237
- subject.obj = value;
238
- } else {
239
- subject.next(value);
240
- }
241
- };
242
- fn._isFrozen = false;
243
- fn.freeze = () => {
244
- fn._isFrozen = true;
245
- };
246
- fn.unfreeze = () => {
247
- fn._isFrozen = false;
248
- if (subject instanceof ArraySubject) {
249
- subject.next({
250
- type: "init",
251
- items: subject.items
252
- });
253
- } else if (subject instanceof ObjectSubject) {
254
- subject.next({
255
- type: "init",
256
- value: subject.obj
257
- });
258
- } else {
259
- subject.next(subject.value);
260
- }
261
- };
262
- fn.mutate = (mutateFn) => {
263
- const value = getValue();
264
- mutateFn(value);
265
- };
266
- fn.update = (updateFn) => {
267
- const updatedValue = updateFn(getValue());
268
- fn.set(updatedValue);
269
- };
270
- fn.observable = subject.asObservable().pipe(filter(() => !fn._isFrozen));
271
- fn._subject = subject;
272
- return fn;
273
- }
274
- __name(signal, "signal");
275
- function isSignal(value) {
276
- return !!(value && value.observable);
277
- }
278
- __name(isSignal, "isSignal");
279
- function isComputed(value) {
280
- return isSignal(value) && !!value.dependencies;
281
- }
282
- __name(isComputed, "isComputed");
283
- function computed(computeFunction, disposableFn) {
284
- const dependencies = /* @__PURE__ */ new Set();
285
- let init = true;
286
- let lastComputedValue;
287
- const previousTracker = reactiveStore.currentDependencyTracker;
288
- reactiveStore.currentDependencyTracker = (signal2) => {
289
- dependencies.add(signal2);
290
- };
291
- lastComputedValue = computeFunction();
292
- if (computeFunction["isEffect"]) {
293
- disposableFn = lastComputedValue;
294
- }
295
- reactiveStore.currentDependencyTracker = previousTracker;
296
- const computedObservable = combineLatest([
297
- ...dependencies
298
- ].map((signal2) => signal2.observable)).pipe(filter(() => !init), map(() => computeFunction()), finalize(() => disposableFn?.()));
299
- const fn = /* @__PURE__ */ __name(function() {
300
- trackDependency(fn);
301
- return lastComputedValue;
302
- }, "fn");
303
- fn.observable = computedObservable;
304
- fn.subscription = computedObservable.subscribe((value) => {
305
- lastComputedValue = value;
306
- });
307
- fn.dependencies = dependencies;
308
- reactiveStore.currentSubscriptionsTracker?.(fn.subscription);
309
- init = false;
310
- return fn;
311
- }
312
- __name(computed, "computed");
313
-
314
- // src/effect.ts
315
- function effect(fn) {
316
- fn["isEffect"] = true;
317
- return computed(fn);
318
- }
319
- __name(effect, "effect");
320
3
 
321
- export { ArraySubject, ObjectSubject, computed, effect, isArraySubject, isComputed, isObjectSubject, isSignal, signal };
4
+ export { __name };
322
5
  //# sourceMappingURL=index30.js.map