@jack120/test 0.2.0 → 0.2.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 (57) hide show
  1. package/dist/index.d.ts +1140 -0
  2. package/package.json +4 -1
  3. package/.gitmodules +0 -3
  4. package/.prettierrc +0 -6
  5. package/.vscode/c_cpp_properties.json +0 -14
  6. package/.vscode/launch.json +0 -24
  7. package/.vscode/settings.json +0 -8
  8. package/CMakeLists.txt +0 -52
  9. package/adamas-config.json +0 -5
  10. package/external/CMakeLists.txt +0 -1
  11. package/external/Unity-NodeJS-RPC/CMakeLists.txt +0 -13
  12. package/external/Unity-NodeJS-RPC/README.md +0 -1
  13. package/external/Unity-NodeJS-RPC/RpcClient.cpp +0 -265
  14. package/external/Unity-NodeJS-RPC/include/RpcClient.h +0 -118
  15. package/external/Unity-NodeJS-RPC/main.cpp +0 -76
  16. package/external/Unity-NodeJS-RPC/nlohmann/json.hpp +0 -25526
  17. package/external/Unity-NodeJS-RPC/server/Program.cs +0 -52
  18. package/external/Unity-NodeJS-RPC/server/json.cs +0 -66
  19. package/external/Unity-NodeJS-RPC/server/rpc.cs +0 -369
  20. package/external/Unity-NodeJS-RPC/server/sample1.csproj +0 -10
  21. package/external/Unity-NodeJS-RPC/server/sample1.sln +0 -24
  22. package/external/Unity-NodeJS-RPC/server/unity/RpcUnity.cs.txt +0 -60
  23. package/index.ts +0 -36
  24. package/library/adamas-types.d.ts +0 -70
  25. package/library/debug.ts +0 -7
  26. package/library/device.ts +0 -279
  27. package/library/entity.ts +0 -35
  28. package/library/index.ts +0 -19
  29. package/library/interaction/interaction.ts +0 -281
  30. package/library/networking/state-sync.ts +0 -62
  31. package/library/physics/collider.ts +0 -252
  32. package/library/physics/rigidbody.ts +0 -119
  33. package/library/render/camera.ts +0 -172
  34. package/library/render/light.ts +0 -169
  35. package/library/render/material.ts +0 -258
  36. package/library/render/mesh.ts +0 -208
  37. package/library/render/primitives.ts +0 -76
  38. package/library/render/renderable.ts +0 -137
  39. package/library/render/renderer.ts +0 -124
  40. package/library/render/scene.ts +0 -89
  41. package/library/render/texture.ts +0 -247
  42. package/library/render/transform.ts +0 -259
  43. package/library/rpc.ts +0 -81
  44. package/library/utilities/base64.ts +0 -63
  45. package/loader-template.ts +0 -419
  46. package/native.cc +0 -111
  47. package/project.adamas.json +0 -457
  48. package/rusk.glb +0 -0
  49. package/samples/device-sample.ts +0 -30
  50. package/samples/interaction-sample.ts +0 -134
  51. package/samples/physics-sample.ts +0 -39
  52. package/samples/rendering-sample.ts +0 -88
  53. package/samples/spawn-cube.ts +0 -422
  54. package/samples/state-sync-sample.ts +0 -25
  55. package/tsconfig.json +0 -20
  56. /package/{library → dist}/native-bindings-osx.node +0 -0
  57. /package/{library → dist}/native-bindings-win.node +0 -0
package/library/device.ts DELETED
@@ -1,279 +0,0 @@
1
- import { RpcClient } from "./rpc";
2
-
3
- export class Device {
4
- // Local positions (relative to XR Origin)
5
- static GetLeftPosition() {
6
- return JSON.parse(RpcClient.Call("XRI Left/Position", {}));
7
- }
8
- static GetLeftRotation() {
9
- return JSON.parse(RpcClient.Call("XRI Left/Rotation", {}));
10
- }
11
- static GetLeftThumbstick() {
12
- return JSON.parse(RpcClient.Call("XRI Left/Thumbstick", {}));
13
- }
14
- static GetLeftSelect() {
15
- return JSON.parse(RpcClient.Call("XRI Left Interaction/Select Value", {}));
16
- }
17
- static GetLeftActivate() {
18
- return JSON.parse(
19
- RpcClient.Call("XRI Left Interaction/Activate Value", {}),
20
- );
21
- }
22
- static GetLeftTurn() {
23
- return JSON.parse(RpcClient.Call("XRI Left Locomotion/Turn", {}));
24
- }
25
- static GetLeftSnapTurn() {
26
- return JSON.parse(RpcClient.Call("XRI Left Locomotion/Snap Turn", {}));
27
- }
28
- static GetLeftMove() {
29
- return JSON.parse(RpcClient.Call("XRI Left Locomotion/Move", {}));
30
- }
31
- static GetLeftGrabMove() {
32
- return JSON.parse(RpcClient.Call("XRI Left Locomotion/Grab Move", {}));
33
- }
34
- static GetRightPosition() {
35
- return JSON.parse(RpcClient.Call("XRI Right/Position", {}));
36
- }
37
- static GetRightRotation() {
38
- return JSON.parse(RpcClient.Call("XRI Right/Rotation", {}));
39
- }
40
- static GetRightThumbstick() {
41
- return JSON.parse(RpcClient.Call("XRI Right/Thumbstick", {}));
42
- }
43
- static GetRightSelect() {
44
- return JSON.parse(RpcClient.Call("XRI Right Interaction/Select Value", {}));
45
- }
46
- static GetRightActivate() {
47
- return JSON.parse(
48
- RpcClient.Call("XRI Right Interaction/Activate Value", {}),
49
- );
50
- }
51
- static GetRightTurn() {
52
- return JSON.parse(RpcClient.Call("XRI Right Locomotion/Turn", {}));
53
- }
54
- static GetRightSnapTurn() {
55
- return JSON.parse(RpcClient.Call("XRI Right Locomotion/Snap Turn", {}));
56
- }
57
- static GetRightMove() {
58
- return JSON.parse(RpcClient.Call("XRI Right Locomotion/Move", {}));
59
- }
60
- static GetRightGrabMove() {
61
- return JSON.parse(RpcClient.Call("XRI Right Locomotion/Grab Move", {}));
62
- }
63
- static GetHeadPosition() {
64
- return JSON.parse(RpcClient.Call("XRI Head/Position", {}));
65
- }
66
- static GetHeadRotation() {
67
- return JSON.parse(RpcClient.Call("XRI Head/Rotation", {}));
68
- }
69
-
70
- // World positions (absolute positions in world space)
71
- static GetLeftWorldPosition() {
72
- return JSON.parse(RpcClient.Call("XRI Left/WorldPosition", {}));
73
- }
74
- static GetLeftWorldRotation() {
75
- return JSON.parse(RpcClient.Call("XRI Left/WorldRotation", {}));
76
- }
77
- static GetRightWorldPosition() {
78
- return JSON.parse(RpcClient.Call("XRI Right/WorldPosition", {}));
79
- }
80
- static GetRightWorldRotation() {
81
- return JSON.parse(RpcClient.Call("XRI Right/WorldRotation", {}));
82
- }
83
- static GetHeadWorldPosition() {
84
- return JSON.parse(RpcClient.Call("XRI Head/WorldPosition", {}));
85
- }
86
- static GetHeadWorldRotation() {
87
- return JSON.parse(RpcClient.Call("XRI Head/WorldRotation", {}));
88
- }
89
- }
90
-
91
- export class XRSystem {
92
- static KEYCODE = Object.freeze({
93
- /* pose type */
94
- LEFT_EYE: "Left Eye",
95
- RIGHT_EYE: "Right Eye",
96
-
97
- LEFT_AIM: "Left Aim",
98
- RIGHT_AIM: "Right Aim",
99
- LEFT_GRIP: "Left Grip",
100
- RIGHT_GRIP: "Right Grip",
101
-
102
- /* number type */
103
- LEFT_SQUEEZE: "Left Squeeze",
104
- RIGHT_SQUEEZE: "Right Squeeze",
105
- LEFT_TRIGGER: "Left Trigger",
106
- RIGHT_TRIGGER: "Right Trigger",
107
-
108
- LEFT_THUMBSTICK_X: "Left Thumbstick X",
109
- RIGHT_THUMBSTICK_X: "Right Thumbstick X",
110
- LEFT_THUMBSTICK_Y: "Left Thumbstick Y",
111
- RIGHT_THUMBSTICK_Y: "Right Thumbstick Y",
112
-
113
- /* boolean type */
114
- LEFT_TRIGGER_TOUCH: "Left Trigger Touch",
115
- RIGHT_TRIGGER_TOUCH: "Right Trigger Touch",
116
- LEFT_THUMBSTICK_CLICK: "Left Thumbstick Click",
117
- RIGHT_THUMBSTICK_CLICK: "Right Thumbstick Click",
118
- LEFT_THUMBSTICK_TOUCH: "Left Thumbstick Touch",
119
- RIGHT_THUMBSTICK_TOUCH: "Right Thumbstick Touch",
120
-
121
- LEFT_X_CLICK: "Left X Click",
122
- LEFT_X_TOUCH: "Left X Touch",
123
- LEFT_Y_CLICK: "Left Y Click",
124
- LEFT_Y_TOUCH: "Left Y Touch",
125
- LEFT_MENU_CLICK: "Left Menu Click",
126
-
127
- RIGHT_A_CLICK: "Right A Click",
128
- RIGHT_A_TOUCH: "Right A Touch",
129
- RIGHT_B_CLIKC: "Right B Click",
130
- RIGHT_B_TOUCH: "Right B Touch",
131
- RIGHT_SYSTEM_CLICK: "Right System Click",
132
- });
133
- }
134
-
135
- export class Keyboard {
136
- static MOUSE = Object.freeze({
137
- BUTTON_LEFT: 0,
138
- BUTTON_RIGHT: 1,
139
- BUTTON_MIDDLE: 2,
140
- });
141
-
142
- static KEYCODE = Object.freeze({
143
- SPACE: 32,
144
- APOSTROPHE: 39 /* ' */,
145
- COMMA: 44 /* , */,
146
- MINUS: 45 /* - */,
147
- PERIOD: 46 /* . */,
148
- SLASH: 47 /* / */,
149
- NUM_0: 48,
150
- NUM_1: 49,
151
- NUM_2: 50,
152
- NUM_3: 51,
153
- NUM_4: 52,
154
- NUM_5: 53,
155
- NUM_6: 54,
156
- NUM_7: 55,
157
- NUM_8: 56,
158
- NUM_9: 57,
159
- SEMICOLON: 59 /* ; */,
160
- EQUAL: 61 /* = */,
161
- A: 65,
162
- B: 66,
163
- C: 67,
164
- D: 68,
165
- E: 69,
166
- F: 70,
167
- G: 71,
168
- H: 72,
169
- I: 73,
170
- J: 74,
171
- K: 75,
172
- L: 76,
173
- M: 77,
174
- N: 78,
175
- O: 79,
176
- P: 80,
177
- Q: 81,
178
- R: 82,
179
- S: 83,
180
- T: 84,
181
- U: 85,
182
- V: 86,
183
- W: 87,
184
- X: 88,
185
- Y: 89,
186
- Z: 90,
187
- LEFT_BRACKET: 91 /* [ */,
188
- BACKSLASH: 92 /* \ */,
189
- RIGHT_BRACKET: 93 /* ] */,
190
- GRAVE_ACCENT: 96 /* ` */,
191
- WORLD_1: 161 /* non-US #1 */,
192
- WORLD_2: 162 /* non-US #2 */,
193
- ESCAPE: 256,
194
- ENTER: 257,
195
- TAB: 258,
196
- BACKSPACE: 259,
197
- INSERT: 260,
198
- DELETE: 261,
199
- RIGHT: 262,
200
- LEFT: 263,
201
- DOWN: 264,
202
- UP: 265,
203
- PAGE_UP: 266,
204
- PAGE_DOWN: 267,
205
- HOME: 268,
206
- END: 269,
207
- CAPS_LOCK: 280,
208
- SCROLL_LOCK: 281,
209
- NUM_LOCK: 282,
210
- PRINT_SCREEN: 283,
211
- PAUSE: 284,
212
- F1: 290,
213
- F2: 291,
214
- F3: 292,
215
- F4: 293,
216
- F5: 294,
217
- F6: 295,
218
- F7: 296,
219
- F8: 297,
220
- F9: 298,
221
- F10: 299,
222
- F11: 300,
223
- F12: 301,
224
- F13: 302,
225
- F14: 303,
226
- F15: 304,
227
- F16: 305,
228
- F17: 306,
229
- F18: 307,
230
- F19: 308,
231
- F20: 309,
232
- F21: 310,
233
- F22: 311,
234
- F23: 312,
235
- F24: 313,
236
- F25: 314,
237
- KP_0: 320,
238
- KP_1: 321,
239
- KP_2: 322,
240
- KP_3: 323,
241
- KP_4: 324,
242
- KP_5: 325,
243
- KP_6: 326,
244
- KP_7: 327,
245
- KP_8: 328,
246
- KP_9: 329,
247
- KP_DECIMAL: 330,
248
- KP_DIVIDE: 331,
249
- KP_MULTIPLY: 332,
250
- KP_SUBTRACT: 333,
251
- KP_ADD: 334,
252
- KP_ENTER: 335,
253
- KP_EQUAL: 336,
254
- LEFT_SHIFT: 340,
255
- LEFT_CONTROL: 341,
256
- LEFT_ALT: 342,
257
- LEFT_SUPER: 343,
258
- RIGHT_SHIFT: 344,
259
- RIGHT_CONTROL: 345,
260
- RIGHT_ALT: 346,
261
- RIGHT_SUPER: 347,
262
- MENU: 348,
263
- });
264
-
265
- static ACTION = Object.freeze({
266
- RELEASE: 0,
267
- PRESS: 1,
268
- REPEAT: 2,
269
- });
270
-
271
- static MODIFIER = Object.freeze({
272
- SHIFT: 1,
273
- CONTROL: 2,
274
- ALT: 4,
275
- SUPER: 8,
276
- CAPS_LOCK: 16,
277
- NUM_LOCK: 32,
278
- });
279
- }
package/library/entity.ts DELETED
@@ -1,35 +0,0 @@
1
- import { RpcClient } from "./rpc";
2
-
3
- export type Entity = number;
4
-
5
- export class EntityManager {
6
- /**
7
- * Create a new Entity
8
- * @returns {Entity}
9
- */
10
- static Create(name: string): Entity {
11
- return Number(
12
- RpcClient.Call("Entity_Create", {
13
- name,
14
- clientId: RpcClient.GetClientId(),
15
- }),
16
- );
17
- }
18
-
19
- /**
20
- * Destroys an Entity.
21
- * @param {Entity} entity
22
- * @returns {Boolean} If entity is destroyed successfully
23
- */
24
- static Destroy(entityHandle: Entity): boolean {
25
- return Boolean(RpcClient.Call("Entity_Destroy", { entityHandle }));
26
- }
27
-
28
- static SetName(entityHandle: Entity, name: string): boolean {
29
- return Boolean(RpcClient.Call("Entity_SetName", { entityHandle, name }));
30
- }
31
-
32
- static GetName(entityHandle: Entity): string {
33
- return RpcClient.Call("Entity_GetName", { entityHandle });
34
- }
35
- }
package/library/index.ts DELETED
@@ -1,19 +0,0 @@
1
- export * from "./rpc";
2
- export * from "./debug";
3
- export * from "./device";
4
- export * from "./entity";
5
- export * from "./interaction/interaction";
6
- export * from "./networking/state-sync";
7
- export * from "./physics/collider";
8
- export * from "./physics/rigidbody";
9
- export * from "./render/camera";
10
- export * from "./render/light";
11
- export * from "./render/material";
12
- export * from "./render/mesh";
13
- export * from "./render/primitives";
14
- export * from "./render/renderable";
15
- export * from "./render/renderer";
16
- export * from "./render/scene";
17
- export * from "./render/texture";
18
- export * from "./render/transform";
19
- export * from "./utilities/base64";
@@ -1,281 +0,0 @@
1
- import { Entity } from "../entity";
2
- import { RpcClient } from "../rpc";
3
-
4
- /**
5
- * Provides a static interface for managing XR grab interactable components
6
- * on entities via RPC. This includes lifecycle management, configuration of
7
- * grab behaviors (position, rotation, scale), and interaction event callbacks.
8
- */
9
- export class GrabInteractableManager {
10
- /**
11
- * Creates a grab interactable component for the specified entity.
12
- * All colliders added before this component is add are used to detect grabbing
13
- * @param entityHandle The entity to attach the grab interactable to.
14
- * @returns A handle representing the newly created grab interactable.
15
- */
16
- static Create(entityHandle: Entity): boolean {
17
- return Boolean(
18
- RpcClient.Call("GrabInteractableAPI_Create", {
19
- entityHandle,
20
- }),
21
- );
22
- }
23
-
24
- /**
25
- * Destroys the grab interactable component on the given entity.
26
- * @param entityHandle The entity whose grab interactable should be destroyed.
27
- * @returns True if the component was successfully destroyed.
28
- */
29
- static Destroy(entityHandle: Entity): boolean {
30
- return Boolean(
31
- RpcClient.Call("GrabInteractableAPI_Destroy", {
32
- entityHandle,
33
- }),
34
- );
35
- }
36
-
37
- /**
38
- * Checks if the specified entity has a grab interactable component.
39
- * @param entityHandle The entity to check.
40
- * @returns True if the component exists.
41
- */
42
- static HasComponent(entityHandle: Entity): boolean {
43
- return Boolean(
44
- RpcClient.Call("GrabInteractableAPI_HasComponent", {
45
- entityHandle,
46
- }),
47
- );
48
- }
49
-
50
- /**
51
- * Gets whether the grab interactable tracks position.
52
- * @param entityHandle The target entity.
53
- * @returns True if position tracking is enabled.
54
- */
55
- static GetTrackPosition(entityHandle: Entity): boolean {
56
- return Boolean(
57
- RpcClient.Call("GrabInteractableAPI_GetTrackPosition", {
58
- entityHandle,
59
- }),
60
- );
61
- }
62
-
63
- /**
64
- * Enables or disables position tracking on the grab interactable.
65
- * @param entityHandle The target entity.
66
- * @param isTracking Whether to enable position tracking.
67
- * @returns True if the change was applied.
68
- */
69
- static SetTrackPosition(entityHandle: Entity, isTracking: boolean): boolean {
70
- return Boolean(
71
- RpcClient.Call("GrabInteractableAPI_SetTrackPosition", {
72
- entityHandle,
73
- isTracking,
74
- }),
75
- );
76
- }
77
-
78
- /**
79
- * Gets whether the grab interactable tracks rotation.
80
- * @param entityHandle The target entity.
81
- * @returns True if rotation tracking is enabled.
82
- */
83
- static GetTrackRotation(entityHandle: Entity): boolean {
84
- return JSON.parse(
85
- RpcClient.Call("GrabInteractableAPI_GetTrackRotation", {
86
- entityHandle,
87
- }),
88
- );
89
- }
90
-
91
- /**
92
- * Enables or disables rotation tracking on the grab interactable.
93
- * @param entityHandle The target entity.
94
- * @param isTracking Whether to enable rotation tracking.
95
- * @returns True if the change was applied.
96
- */
97
- static SetTrackRotation(entityHandle: Entity, isTracking: boolean): boolean {
98
- return JSON.parse(
99
- RpcClient.Call("GrabInteractableAPI_SetTrackRotation", {
100
- entityHandle,
101
- isTracking,
102
- }),
103
- );
104
- }
105
-
106
- /**
107
- * Gets whether the grab interactable tracks scale.
108
- * @param entityHandle The target entity.
109
- * @returns True if scale tracking is enabled.
110
- */
111
- static GetTrackScale(entityHandle: Entity): boolean {
112
- return Boolean(
113
- RpcClient.Call("GrabInteractableAPI_GetTrackScale", {
114
- entityHandle,
115
- }),
116
- );
117
- }
118
-
119
- /**
120
- * Enables or disables scale tracking on the grab interactable.
121
- * @param entityHandle The target entity.
122
- * @param isTracking Whether to enable scale tracking.
123
- * @returns True if the change was applied.
124
- */
125
- static SetTrackScale(entityHandle: Entity, isTracking: boolean): boolean {
126
- return Boolean(
127
- RpcClient.Call("GrabInteractableAPI_SetTrackScale", {
128
- entityHandle,
129
- isTracking,
130
- }),
131
- );
132
- }
133
-
134
- /**
135
- * Gets whether the object should apply physics-based throw on detach.
136
- * @param entityHandle The target entity.
137
- * @returns True if throw-on-detach is enabled.
138
- */
139
- static GetThrowOnDetach(entityHandle: Entity): boolean {
140
- return Boolean(
141
- RpcClient.Call("GrabInteractableAPI_GetThrowOnDetach", {
142
- entityHandle,
143
- }),
144
- );
145
- }
146
-
147
- /**
148
- * Enables or disables physics-based throwing on detach.
149
- * @param entityHandle The target entity.
150
- * @param enable Whether to enable throw-on-detach.
151
- * @returns True if the setting was successfully changed.
152
- */
153
- static SetThrowOnDetach(entityHandle: Entity, enable: boolean): boolean {
154
- return Boolean(
155
- RpcClient.Call("GrabInteractableAPI_SetThrowOnDetach", {
156
- entityHandle,
157
- enable,
158
- }),
159
- );
160
- }
161
-
162
- /**
163
- * Gets the currently attached entity handle, if any.
164
- * @param entityHandle The entity whose attachment is being queried.
165
- * @returns True if the query was successful. The actual value is assumed returned via RPC side effect or callback.
166
- */
167
- static GetAttachEntity(entityHandle: Entity): boolean {
168
- return Boolean(
169
- RpcClient.Call("GrabInteractableAPI_GetAttachEntity", {
170
- entityHandle,
171
- }),
172
- );
173
- }
174
-
175
- /**
176
- * Sets the entity that should be used as the attachment target for this grab interactable.
177
- * @param entityHandle The source grab interactable entity.
178
- * @param attachEntityHandle The target entity to attach to.
179
- * @returns True if the attachment was successfully updated.
180
- */
181
- static SetAttachEntity(
182
- entityHandle: Entity,
183
- attachEntityHandle: Entity,
184
- ): boolean {
185
- return Boolean(
186
- RpcClient.Call("GrabInteractableAPI_SetAttachEntity", {
187
- entityHandle,
188
- attachEntityHandle,
189
- }),
190
- );
191
- }
192
-
193
- /**
194
- * Registers a callback to be invoked when the object is selected (grabbed).
195
- * @param entityHandle The entity to observe.
196
- * @param onSelectEntered Callback function to invoke on select enter.
197
- * @returns True if the callback was registered successfully.
198
- */
199
- static AddSelectEnteredCallback(
200
- entityHandle: Entity,
201
- onSelectEntered: (
202
- interactableEntity: Entity,
203
- interactorEntity: Entity,
204
- ) => void,
205
- ): boolean {
206
- return Boolean(
207
- RpcClient.Call("GrabInteractableAPI_AddSelectEnteredCallback", {
208
- entityHandle,
209
- onSelectEntered: (args: any) => {
210
- onSelectEntered(args.interactableEntity, args.interactorEntity);
211
- },
212
- }),
213
- );
214
- }
215
-
216
- /**
217
- * Registers a callback to be invoked when the object is released (deselected).
218
- * @param entityHandle The entity to observe.
219
- * @param onSelectExited Callback function to invoke on select exit.
220
- * @returns True if the callback was registered successfully.
221
- */
222
- static AddSelectExitedCallback(
223
- entityHandle: Entity,
224
- onSelectExited: (
225
- interactableEntity: Entity,
226
- interactorEntity: Entity,
227
- ) => void,
228
- ): boolean {
229
- return Boolean(
230
- RpcClient.Call("GrabInteractableAPI_AddSelectExitedCallback", {
231
- entityHandle,
232
- onSelectExited: (args: any) => {
233
- onSelectExited(args.interactableEntity, args.interactorEntity);
234
- },
235
- }),
236
- );
237
- }
238
-
239
- /**
240
- * Registers a callback to be invoked when the object is activated (e.g. trigger pressed).
241
- * @param entityHandle The entity to observe.
242
- * @param onActivated Callback function to invoke on activation.
243
- * @returns True if the callback was registered successfully.
244
- */
245
- static AddActivatedCallback(
246
- entityHandle: Entity,
247
- onActivated: (interactableEntity: Entity, interactorEntity: Entity) => void,
248
- ): boolean {
249
- return Boolean(
250
- RpcClient.Call("GrabInteractableAPI_AddActivatedCallback", {
251
- entityHandle,
252
- onActivated: (args: any) => {
253
- onActivated(args.interactableEntity, args.interactorEntity);
254
- },
255
- }),
256
- );
257
- }
258
-
259
- /**
260
- * Registers a callback to be invoked when the object is deactivated (e.g. trigger released).
261
- * @param entityHandle The entity to observe.
262
- * @param onDeactivated Callback function to invoke on deactivation.
263
- * @returns True if the callback was registered successfully.
264
- */
265
- static AddDeactivatedCallback(
266
- entityHandle: Entity,
267
- onDeactivated: (
268
- interactableEntity: Entity,
269
- interactorEntity: Entity,
270
- ) => void,
271
- ): boolean {
272
- return Boolean(
273
- RpcClient.Call("GrabInteractableAPI_AddDeactivatedCallback", {
274
- entityHandle,
275
- onDeactivated: (args: any) => {
276
- onDeactivated(args.interactableEntity, args.interactorEntity);
277
- },
278
- }),
279
- );
280
- }
281
- }
@@ -1,62 +0,0 @@
1
- import { RpcClient } from "../rpc";
2
-
3
- export class StateSync {
4
- static stateMap = new Map<string, object>(); // holds all proxies by key
5
-
6
- static GetNetworkID(): string {
7
- return RpcClient.Call("_Main::GetNetworkPrefabIdByPid", {
8
- pid: process.pid,
9
- });
10
- }
11
-
12
- static CreateNetworkState<T extends object>(
13
- key: string,
14
- initial: T,
15
- onStateChange: (prop: string, value: any) => void = () => {},
16
- ): T {
17
- const internalState = structuredClone(initial); // deep clone to decouple
18
-
19
- StateSync.stateMap.set(key, internalState);
20
- const proxy = new Proxy(internalState, {
21
- get(target, prop) {
22
- return Reflect.get(target, prop);
23
- },
24
- set(target, prop, value) {
25
- Reflect.set(target, prop, value);
26
- RpcClient.Call("_RPC::BroadcastState", {
27
- networkId: StateSync.GetNetworkID(),
28
- key: key,
29
- payload: JSON.stringify({ prop, value }),
30
- });
31
- return true;
32
- },
33
- });
34
-
35
- // Subscribe to external changes
36
- RpcClient.Call("_RPC::AddNewState", {
37
- networkId: StateSync.GetNetworkID(),
38
- key: key,
39
- onReceived: (jsonObject: any) => {
40
- console.log("onReceived: " + jsonObject.data);
41
- const internalState = StateSync.stateMap.get(key);
42
- if (!internalState) return;
43
-
44
- const { prop, value } = JSON.parse(jsonObject.data);
45
- (internalState as any)[prop] = value;
46
- onStateChange(prop, value);
47
- },
48
- });
49
-
50
- return proxy as T;
51
- }
52
-
53
- static IsStateAuthority(): boolean {
54
- return RpcClient.Call("_RPC:IsStateAuthority", {
55
- networkId: StateSync.GetNetworkID(),
56
- }) as boolean;
57
- }
58
-
59
- static GetPlayerId(): number {
60
- return RpcClient.Call("Multiplayer_GetPlayerId", {}) as number;
61
- }
62
- }