@awesome-flow/ecs 0.1.0 → 0.3.0

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.js CHANGED
@@ -1,21 +1,15 @@
1
- // src/ecs/ecs-flow-context.ts
1
+ // src/abstract/ecs-flow-context.ts
2
2
  import { createContext } from "react";
3
- var EcsFlowContext = createContext({
4
- ecsFlowRepository: null,
5
- entityRepository: null,
6
- entityEventsManager: null,
7
- entityUpdateCounter: null,
8
- systemsModuleRepository: null
9
- });
3
+ var EcsFlowContext = createContext(null);
10
4
 
11
5
  // src/utils/id-generator.ts
12
- var IdGenerator = class {
6
+ var EcsIdGenerator = class {
13
7
  static entityProxy(proxy) {
14
8
  return `${proxy.entityType}:${proxy.entityUid}`;
15
9
  }
16
10
  };
17
11
 
18
- // src/ecs/ecs-flow-repository.ts
12
+ // src/abstract/ecs-flow-repository.ts
19
13
  var EcsFlowRepository = class {
20
14
  nodes;
21
15
  constructor() {
@@ -31,20 +25,20 @@ var EcsFlowRepository = class {
31
25
  return this.nodes.get(entityType.toString());
32
26
  }
33
27
  addEntityNode(node) {
34
- this.nodes.set(IdGenerator.entityProxy(node.data.entity), node);
28
+ this.nodes.set(EcsIdGenerator.entityProxy(node.data.entity), node);
35
29
  }
36
30
  getEntityNode(entity) {
37
- return this.nodes.get(IdGenerator.entityProxy(entity));
31
+ return this.nodes.get(EcsIdGenerator.entityProxy(entity));
38
32
  }
39
33
  listAllNodes() {
40
34
  return Array.from(this.nodes.values());
41
35
  }
42
36
  };
43
37
 
44
- // src/ecs/flow-ecs-state.tsx
38
+ // src/flow/flow-ecs-state.tsx
45
39
  import { useEffect as useEffect7, useContext as useContext10, useState as useState3 } from "react";
46
40
 
47
- // src/ecs/flow-ecs-auto-layout.tsx
41
+ // src/flow/flow-ecs-auto-layout.tsx
48
42
  import { FlowContext } from "@awesome-flow/core/abstract";
49
43
  import Dagre from "@dagrejs/dagre";
50
44
  import { useReactFlow } from "@xyflow/react";
@@ -102,19 +96,23 @@ function FlowEcsAutoLayout(props) {
102
96
  }
103
97
  var flow_ecs_auto_layout_default = FlowEcsAutoLayout;
104
98
 
105
- // src/ecs/flow-ecs-entities.tsx
99
+ // src/flow/flow-ecs-entities.tsx
106
100
  import { FlowContext as FlowContext4 } from "@awesome-flow/core/abstract";
107
101
  import { useContext as useContext8, useEffect as useEffect5, useState as useState2 } from "react";
108
102
 
109
103
  // src/nodes/node-systems-module.tsx
110
104
  import { NodeContainer } from "@awesome-flow/core/layout";
111
105
  import { useContext as useContext2 } from "react";
106
+ import { Badge as Badge3 } from "@mantine/core";
112
107
 
113
108
  // src/layout/systems-module-layout.tsx
114
109
  import { SystemType } from "@awesome-ecs/abstract/systems";
115
110
  import { Accordion as Accordion2, Text } from "@mantine/core";
116
111
  import { useMemo as useMemo3 } from "react";
117
112
 
113
+ // src/components/pipeline-middleware-list.tsx
114
+ import { Accordion, Badge as Badge2, Stack } from "@mantine/core";
115
+
118
116
  // src/components/badge-list.tsx
119
117
  import { Badge } from "@mantine/core";
120
118
  import { memo as memo2 } from "react";
@@ -140,7 +138,6 @@ function BadgeList(props) {
140
138
  var badge_list_default = memo2(BadgeList);
141
139
 
142
140
  // src/components/pipeline-middleware-list.tsx
143
- import { Accordion, Badge as Badge2, Stack } from "@mantine/core";
144
141
  import { jsx as jsx3, jsxs } from "react/jsx-runtime";
145
142
  function PipelineMiddlewareList(props) {
146
143
  let middleware = [];
@@ -162,7 +159,7 @@ import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-run
162
159
  function SystemsModuleLayout(props) {
163
160
  const { module } = props;
164
161
  const runtimeContext = module["runtimeContext"];
165
- const systemContext = runtimeContext.systemContext;
162
+ const { systemContext } = runtimeContext;
166
163
  const { status } = useMemo3(() => {
167
164
  return systemContext.runtime;
168
165
  }, [systemContext.runtime.status]);
@@ -186,7 +183,6 @@ function SystemsModuleLayout(props) {
186
183
  var systems_module_layout_default = SystemsModuleLayout;
187
184
 
188
185
  // src/nodes/node-systems-module.tsx
189
- import { Badge as Badge3 } from "@mantine/core";
190
186
  import { jsx as jsx5 } from "react/jsx-runtime";
191
187
  function SystemsModuleNode({ id, data, selected, type }) {
192
188
  const { systemsModuleRepository } = useContext2(EcsFlowContext);
@@ -196,9 +192,8 @@ function SystemsModuleNode({ id, data, selected, type }) {
196
192
  {
197
193
  id,
198
194
  selected,
199
- handles: data.handles,
195
+ data,
200
196
  title: /* @__PURE__ */ jsx5(Badge3, { fullWidth: true, color: "indigo", variant: "transparent", children: /* @__PURE__ */ jsx5(formatter_camel_case_default, { value: data.entityType }) }),
201
- templateId: data.templateId,
202
197
  type,
203
198
  children: /* @__PURE__ */ jsx5(systems_module_layout_default, { type: data.entityType, module })
204
199
  }
@@ -209,7 +204,7 @@ var node_systems_module_default = SystemsModuleNode;
209
204
  // src/nodes/node-entity.tsx
210
205
  import { NodeContainer as NodeContainer2 } from "@awesome-flow/core/layout";
211
206
  import { Badge as Badge9 } from "@mantine/core";
212
- import { useContext as useContext5, useMemo as useMemo8 } from "react";
207
+ import { useContext as useContext5, useMemo as useMemo6 } from "react";
213
208
 
214
209
  // src/layout/entity-layout.tsx
215
210
  import { Accordion as Accordion6, Badge as Badge8, Divider, Group } from "@mantine/core";
@@ -220,17 +215,17 @@ import { memo as memo5 } from "react";
220
215
 
221
216
  // src/components/entity-component-inspector.tsx
222
217
  import { Box, Button, Collapse } from "@mantine/core";
223
- import { memo as memo4, useMemo as useMemo6 } from "react";
218
+ import { memo as memo4, useMemo as useMemo5 } from "react";
224
219
  import { useDisclosure } from "@mantine/hooks";
225
220
 
226
221
  // src/components/object-inspector.tsx
227
222
  import { useComputedColorScheme } from "@mantine/core";
228
- import { memo as memo3, useMemo as useMemo5 } from "react";
223
+ import { memo as memo3, useMemo as useMemo4 } from "react";
229
224
  import { Inspector } from "react-inspector";
230
225
  import { jsx as jsx6 } from "react/jsx-runtime";
231
226
  function ObjectInspector(props) {
232
227
  const colorScheme = useComputedColorScheme();
233
- const theme = useMemo5(
228
+ const theme = useMemo4(
234
229
  () => colorScheme === "dark" ? "chromeDark" : "chromeLight",
235
230
  [colorScheme]
236
231
  );
@@ -242,7 +237,7 @@ var object_inspector_default = memo3(ObjectInspector);
242
237
  import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
243
238
  function EntityComponentInspector(props) {
244
239
  const [opened, { toggle }] = useDisclosure(false);
245
- const buttonColor = useMemo6(() => opened ? "light" : "indigo", [opened]);
240
+ const buttonColor = useMemo5(() => opened ? "light" : "indigo", [opened]);
246
241
  return /* @__PURE__ */ jsxs3(Box, { children: [
247
242
  /* @__PURE__ */ jsx7(Button, { variant: "outline", size: "xs", onClick: toggle, color: buttonColor, fullWidth: true, children: props.component.componentType }),
248
243
  /* @__PURE__ */ jsx7(Collapse, { in: opened, children: opened && /* @__PURE__ */ jsx7(object_inspector_default, { data: props.component }) })
@@ -267,7 +262,7 @@ import { memo as memo6 } from "react";
267
262
  import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
268
263
  function EntityProxyList(props) {
269
264
  const proxies = Array.from(props.entity.proxies.values()).map((c) => c.values());
270
- const items = proxies.map((p) => Array.from(p).map((k) => IdGenerator.entityProxy(k))).flat();
265
+ const items = proxies.map((p) => Array.from(p).map((k) => EcsIdGenerator.entityProxy(k))).flat();
271
266
  return /* @__PURE__ */ jsxs5(Accordion4.Item, { value: "proxies", children: [
272
267
  /* @__PURE__ */ jsx9(Accordion4.Control, { children: /* @__PURE__ */ jsx9(Badge5, { fullWidth: true, variant: "light", rightSection: items.length, children: "Proxies" }) }),
273
268
  /* @__PURE__ */ jsx9(Accordion4.Panel, { children: /* @__PURE__ */ jsx9(Stack3, { children: /* @__PURE__ */ jsx9(badge_list_default, { items, badge: { variant: "outline" } }) }) })
@@ -336,15 +331,14 @@ var entity_layout_default = EntityLayout;
336
331
  import { jsx as jsx13 } from "react/jsx-runtime";
337
332
  function EntityNode({ id, data, selected, type }) {
338
333
  const { entityRepository } = useContext5(EcsFlowContext);
339
- const entity = useMemo8(() => entityRepository.get(data.entity), [data.entity]);
334
+ const entity = useMemo6(() => entityRepository.get(data.entity), [data.entity]);
340
335
  return /* @__PURE__ */ jsx13(
341
336
  NodeContainer2,
342
337
  {
343
338
  id,
344
339
  selected,
345
- handles: data.handles,
340
+ data,
346
341
  title: /* @__PURE__ */ jsx13(Badge9, { fullWidth: true, variant: "transparent", children: /* @__PURE__ */ jsx13(formatter_camel_case_default, { value: entity.myProxy.entityType }) }),
347
- templateId: data.templateId,
348
342
  type,
349
343
  children: /* @__PURE__ */ jsx13(entity_layout_default, { entity })
350
344
  }
@@ -352,7 +346,88 @@ function EntityNode({ id, data, selected, type }) {
352
346
  }
353
347
  var node_entity_default = EntityNode;
354
348
 
355
- // src/node-types.ts
349
+ // src/templates/template-entity-node.ts
350
+ import { IDGenerator } from "@awesome-flow/core/utils";
351
+ import { Position } from "@xyflow/react";
352
+
353
+ // src/abstract/handle-types.ts
354
+ var EcsHandleDataType = /* @__PURE__ */ ((EcsHandleDataType2) => {
355
+ EcsHandleDataType2[EcsHandleDataType2["proxy"] = 1] = "proxy";
356
+ EcsHandleDataType2[EcsHandleDataType2["module"] = 2] = "module";
357
+ return EcsHandleDataType2;
358
+ })(EcsHandleDataType || {});
359
+
360
+ // src/templates/template-entity-node.ts
361
+ var EntityNodeTemplate = class {
362
+ create() {
363
+ const data = {
364
+ title: "Entity",
365
+ entity: null
366
+ };
367
+ return {
368
+ id: IDGenerator.template(),
369
+ removable: false,
370
+ type: "entity-node" /* entity */,
371
+ data,
372
+ handles: [
373
+ {
374
+ dataType: 1 /* proxy */,
375
+ position: Position.Left,
376
+ connection: "target",
377
+ disabled: true
378
+ },
379
+ {
380
+ dataType: 1 /* proxy */,
381
+ position: Position.Right,
382
+ connection: "source",
383
+ disabled: true
384
+ }
385
+ ]
386
+ };
387
+ }
388
+ isHandleAllowed() {
389
+ return false;
390
+ }
391
+ getHandleAllowedDataType() {
392
+ return 1 /* proxy */;
393
+ }
394
+ };
395
+
396
+ // src/templates/template-systems-module.ts
397
+ import { IDGenerator as IDGenerator2 } from "@awesome-flow/core/utils";
398
+ import { Position as Position2 } from "@xyflow/react";
399
+ var SystemsModuleNodeTemplate = class {
400
+ create() {
401
+ const data = {
402
+ title: "Systems Module",
403
+ entityType: null,
404
+ handles: null,
405
+ templateId: null
406
+ };
407
+ return {
408
+ id: IDGenerator2.template(),
409
+ removable: false,
410
+ type: "systems-module-node" /* systemsModule */,
411
+ data,
412
+ handles: [
413
+ {
414
+ dataType: 2 /* module */,
415
+ position: Position2.Left,
416
+ connection: "target",
417
+ disabled: true
418
+ }
419
+ ]
420
+ };
421
+ }
422
+ isHandleAllowed() {
423
+ return false;
424
+ }
425
+ getHandleAllowedDataType() {
426
+ return 2 /* module */;
427
+ }
428
+ };
429
+
430
+ // src/abstract/node-types.ts
356
431
  var EcsNodeType = /* @__PURE__ */ ((EcsNodeType2) => {
357
432
  EcsNodeType2["systemsModule"] = "systems-module-node";
358
433
  EcsNodeType2["entity"] = "entity-node";
@@ -362,8 +437,12 @@ var ecsNodeTypes = {
362
437
  ["systems-module-node" /* systemsModule */]: node_systems_module_default,
363
438
  ["entity-node" /* entity */]: node_entity_default
364
439
  };
440
+ var ecsNodeTemplates = {
441
+ ["entity-node" /* entity */]: new EntityNodeTemplate(),
442
+ ["systems-module-node" /* systemsModule */]: new SystemsModuleNodeTemplate()
443
+ };
365
444
 
366
- // src/ecs/flow-ecs-edge-proxies.tsx
445
+ // src/flow/flow-ecs-edge-proxies.tsx
367
446
  import { useContext as useContext6, useEffect as useEffect3 } from "react";
368
447
  import { FlowContext as FlowContext2 } from "@awesome-flow/core/abstract";
369
448
  import { Fragment as Fragment5, jsx as jsx14 } from "react/jsx-runtime";
@@ -374,13 +453,13 @@ function FlowEcsEdgeProxies(props) {
374
453
  const { ecsFlowRepository, entityRepository } = useContext6(EcsFlowContext);
375
454
  useEffect3(() => {
376
455
  for (const node of nodesToConnect) {
377
- const sourceHandle = node.data.handles.find((h) => h.type === "source");
456
+ const sourceHandle = node.data.handles.find((h) => h.connection === "source");
378
457
  const entity = entityRepository.get(node.data.entity);
379
458
  for (const [, proxyMap] of entity.proxies) {
380
459
  for (const proxy of proxyMap.values()) {
381
460
  const proxyNode = ecsFlowRepository.getEntityNode(proxy);
382
461
  if (proxyNode) {
383
- const targetHandle = proxyNode.data.handles.find((h) => h.type === "target");
462
+ const targetHandle = proxyNode.data.handles.find((h) => h.connection === "target");
384
463
  onConnect({
385
464
  source: node.id,
386
465
  target: proxyNode.id,
@@ -396,7 +475,7 @@ function FlowEcsEdgeProxies(props) {
396
475
  }
397
476
  var flow_ecs_edge_proxies_default = FlowEcsEdgeProxies;
398
477
 
399
- // src/ecs/flow-ecs-edge-modules.tsx
478
+ // src/flow/flow-ecs-edge-modules.tsx
400
479
  import { useContext as useContext7, useEffect as useEffect4 } from "react";
401
480
  import { FlowContext as FlowContext3 } from "@awesome-flow/core/abstract";
402
481
  import { Fragment as Fragment6, jsx as jsx15 } from "react/jsx-runtime";
@@ -407,10 +486,10 @@ function FlowEcsEdgeModules(props) {
407
486
  const { ecsFlowRepository, entityRepository } = useContext7(EcsFlowContext);
408
487
  useEffect4(() => {
409
488
  for (const node of nodesToConnect) {
410
- const sourceHandle = node.data.handles.find((h) => h.type === "source");
489
+ const sourceHandle = node.data.handles.find((h) => h.connection === "source");
411
490
  const entity = entityRepository.get(node.data.entity);
412
491
  const systemModule = ecsFlowRepository.getSystemModuleNode(entity.myProxy.entityType);
413
- const targetHandle = systemModule?.data.handles.find((h) => h.type === "target");
492
+ const targetHandle = systemModule?.data.handles.find((h) => h.connection === "target");
414
493
  if (targetHandle) {
415
494
  onConnect({
416
495
  source: node.id,
@@ -418,7 +497,6 @@ function FlowEcsEdgeModules(props) {
418
497
  sourceHandle: sourceHandle.id,
419
498
  targetHandle: targetHandle.id
420
499
  });
421
- console.log("CONNECTING MODULE", node.id, systemModule.id);
422
500
  }
423
501
  }
424
502
  }, [nodesToConnect]);
@@ -426,7 +504,7 @@ function FlowEcsEdgeModules(props) {
426
504
  }
427
505
  var flow_ecs_edge_modules_default = FlowEcsEdgeModules;
428
506
 
429
- // src/ecs/flow-ecs-entities.tsx
507
+ // src/flow/flow-ecs-entities.tsx
430
508
  import { Fragment as Fragment7, jsx as jsx16, jsxs as jsxs9 } from "react/jsx-runtime";
431
509
  function FlowEcsEntities() {
432
510
  const context = useContext8(FlowContext4);
@@ -456,7 +534,7 @@ function FlowEcsEntities() {
456
534
  }
457
535
  var flow_ecs_entities_default = FlowEcsEntities;
458
536
 
459
- // src/ecs/flow-ecs-modules.tsx
537
+ // src/flow/flow-ecs-modules.tsx
460
538
  import { useEffect as useEffect6, useContext as useContext9 } from "react";
461
539
  import { FlowContext as FlowContext5 } from "@awesome-flow/core/abstract";
462
540
  import { Fragment as Fragment8, jsx as jsx17 } from "react/jsx-runtime";
@@ -488,7 +566,7 @@ function FlowEcsModules() {
488
566
  }
489
567
  var flow_ecs_modules_default = FlowEcsModules;
490
568
 
491
- // src/ecs/flow-ecs-state.tsx
569
+ // src/flow/flow-ecs-state.tsx
492
570
  import { Fragment as Fragment9, jsx as jsx18, jsxs as jsxs10 } from "react/jsx-runtime";
493
571
  function FlowEcsState(props) {
494
572
  const [, setUpdates] = useState3(0);
@@ -509,87 +587,6 @@ function FlowEcsState(props) {
509
587
  ] });
510
588
  }
511
589
  var flow_ecs_state_default = FlowEcsState;
512
-
513
- // src/templates/template-entity-node.ts
514
- import { IDGenerator } from "@awesome-flow/core/utils";
515
-
516
- // src/handle-types.ts
517
- var EcsHandleDataType = /* @__PURE__ */ ((EcsHandleDataType2) => {
518
- EcsHandleDataType2[EcsHandleDataType2["proxy"] = 1] = "proxy";
519
- EcsHandleDataType2[EcsHandleDataType2["module"] = 2] = "module";
520
- return EcsHandleDataType2;
521
- })(EcsHandleDataType || {});
522
-
523
- // src/templates/template-entity-node.ts
524
- import { Position } from "@xyflow/react";
525
- var EntityNodeTemplate = class {
526
- create() {
527
- const data = {
528
- title: "Entity",
529
- entity: null
530
- };
531
- return {
532
- id: IDGenerator.template(),
533
- removable: false,
534
- type: "entity-node" /* entity */,
535
- data,
536
- handles: [
537
- {
538
- dataType: 1 /* proxy */,
539
- position: Position.Left,
540
- type: "target",
541
- disabled: true
542
- },
543
- {
544
- dataType: 1 /* proxy */,
545
- position: Position.Right,
546
- type: "source",
547
- disabled: true
548
- }
549
- ]
550
- };
551
- }
552
- isHandleAllowed() {
553
- return false;
554
- }
555
- getHandleAllowedDataType() {
556
- return void 0;
557
- }
558
- };
559
-
560
- // src/templates/template-systems-module.ts
561
- import { IDGenerator as IDGenerator2 } from "@awesome-flow/core/utils";
562
- import { Position as Position2 } from "@xyflow/react";
563
- var SystemsModuleNodeTemplate = class {
564
- create() {
565
- const data = {
566
- title: "Systems Module",
567
- entityType: null,
568
- handles: null,
569
- templateId: null
570
- };
571
- return {
572
- id: IDGenerator2.template(),
573
- removable: false,
574
- type: "systems-module-node" /* systemsModule */,
575
- data,
576
- handles: [
577
- {
578
- dataType: 2 /* module */,
579
- position: Position2.Left,
580
- type: "target",
581
- disabled: true
582
- }
583
- ]
584
- };
585
- }
586
- isHandleAllowed() {
587
- return false;
588
- }
589
- getHandleAllowedDataType() {
590
- return void 0;
591
- }
592
- };
593
590
  export {
594
591
  EcsFlowContext,
595
592
  EcsFlowRepository,
@@ -600,6 +597,7 @@ export {
600
597
  flow_ecs_state_default as FlowEcsState,
601
598
  node_systems_module_default as SystemsModuleNode,
602
599
  SystemsModuleNodeTemplate,
600
+ ecsNodeTemplates,
603
601
  ecsNodeTypes
604
602
  };
605
603
  //# sourceMappingURL=index.js.map