@dcl/react-ecs 0.0.1-3379451953.commit-41b47e2 → 0.0.1-3381668097.commit-01e37d6

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/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+
2
+
1
3
  export declare const CANVAS_ROOT_ENTITY = 7;
2
4
 
3
5
  export declare type Children = any;
@@ -28,6 +30,13 @@ export declare type EcsElements = {
28
30
  entity: Partial<Omit<EntityComponents, 'onClick'> & CommonProps>;
29
31
  };
30
32
 
33
+ /**
34
+ * @public
35
+ */
36
+ declare type Entity = number & {
37
+ [entitySymbol]: true;
38
+ };
39
+
31
40
  export declare type EntityComponents = {
32
41
  uiTransform: PBUiTransform;
33
42
  uiText: PBUiText;
@@ -44,12 +53,70 @@ export declare type EntityPropTypes = {
44
53
  uiBackground?: UiBackgroundProps;
45
54
  };
46
55
 
56
+ declare const entitySymbol: unique symbol;
57
+
58
+ declare type EventsSystem = typeof EventsSystem;
59
+
60
+ declare namespace EventsSystem {
61
+ type Callback = (event: PBPointerEventsResult_PointerCommand) => void | Promise<void>;
62
+ type Options = {
63
+ button?: InputAction;
64
+ hoverText?: string;
65
+ maxDistance?: number;
66
+ };
67
+ /**
68
+ * @public
69
+ * Remove the callback for onPointerDown event
70
+ * @param entity Entity where the callback was attached
71
+ */
72
+ function removeOnPointerDown(entity: Entity): void;
73
+ /**
74
+ * @public
75
+ * Remove the callback for onPointerUp event
76
+ * @param entity Entity where the callback was attached
77
+ */
78
+ function removeOnPointerUp(entity: Entity): void;
79
+ /**
80
+ * @public
81
+ * Execute callback when the user press the InputButton pointing at the entity
82
+ * @param entity Entity to attach the callback
83
+ * @param cb Function to execute when click fires
84
+ * @param opts Opts to trigger Feedback and Button
85
+ */
86
+ function onPointerDown(entity: Entity, cb: Callback, opts?: Options): void;
87
+ /**
88
+ * @public
89
+ * Execute callback when the user releases the InputButton pointing at the entity
90
+ * @param entity Entity to attach the callback
91
+ * @param cb Function to execute when click fires
92
+ * @param opts Opts to trigger Feedback and Button
93
+ */
94
+ function onPointerUp(entity: Entity, cb: Callback, opts?: Options): void;
95
+ }
96
+
47
97
  export declare enum Font {
48
98
  F_LIBERATION_SANS = 0,
49
99
  F_SANS_SERIF = 1,
50
100
  UNRECOGNIZED = -1
51
101
  }
52
102
 
103
+ declare const enum InputAction {
104
+ IA_POINTER = 0,
105
+ IA_PRIMARY = 1,
106
+ IA_SECONDARY = 2,
107
+ IA_ANY = 3,
108
+ IA_FORWARD = 4,
109
+ IA_BACKWARD = 5,
110
+ IA_RIGHT = 6,
111
+ IA_LEFT = 7,
112
+ IA_JUMP = 8,
113
+ IA_WALK = 9,
114
+ IA_ACTION_3 = 10,
115
+ IA_ACTION_4 = 11,
116
+ IA_ACTION_5 = 12,
117
+ IA_ACTION_6 = 13
118
+ }
119
+
53
120
  export declare const isListener: (key: string) => key is "onClick";
54
121
 
55
122
  export declare namespace JSX {
@@ -66,7 +133,19 @@ export declare type Listeners = {
66
133
  onClick?: OnClick;
67
134
  };
68
135
 
69
- export declare type OnClick = () => Promise<void> | void;
136
+ export declare type OnClick = EventsSystem.Callback;
137
+
138
+ /** this message represents a pointer event, used both for UP and DOWN actions */
139
+ declare interface PBPointerEventsResult_PointerCommand {
140
+ /** identifier of the input */
141
+ button: InputAction;
142
+ hit: RaycastHit | undefined;
143
+ state: PointerEventType;
144
+ /** could be a Lamport timestamp */
145
+ timestamp: number;
146
+ /** if the input is analog then we store it here */
147
+ analog?: number | undefined;
148
+ }
70
149
 
71
150
  export declare interface PBUiBackground {
72
151
  /** default=(0.0, 0.0, 0.0, 0.0) */
@@ -146,6 +225,13 @@ export declare interface PBUiTransform {
146
225
  borderBottom: number;
147
226
  }
148
227
 
228
+ declare const enum PointerEventType {
229
+ PET_UP = 0,
230
+ PET_DOWN = 1,
231
+ PET_HOVER_ENTER = 2,
232
+ PET_HOVER_LEAVE = 3
233
+ }
234
+
149
235
  /**
150
236
  * @public
151
237
  */
@@ -158,6 +244,17 @@ export declare type Position = {
158
244
 
159
245
  export declare type PositionUnit = `${number}px` | `${number}%` | number;
160
246
 
247
+ /** Position will be relative to the scene */
248
+ declare interface RaycastHit {
249
+ position: Vector3_2 | undefined;
250
+ origin: Vector3_2 | undefined;
251
+ direction: Vector3_2 | undefined;
252
+ normalHit: Vector3_2 | undefined;
253
+ length: number;
254
+ meshName?: string | undefined;
255
+ entityId?: number | undefined;
256
+ }
257
+
161
258
  declare namespace ReactEcs {
162
259
  namespace JSX {
163
260
  interface Element {
@@ -228,6 +325,12 @@ export declare interface UiTransformProps {
228
325
  overflow?: YGOverflow;
229
326
  }
230
327
 
328
+ declare interface Vector3_2 {
329
+ x: number;
330
+ y: number;
331
+ z: number;
332
+ }
333
+
231
334
  export declare enum YGAlign {
232
335
  YGA_AUTO = 0,
233
336
  YGA_FLEX_START = 1,