@awesome-flow/ecs 0.6.0 → 0.7.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.
package/dist/index.js CHANGED
@@ -1,527 +1 @@
1
- // src/abstract/ecs-flow-context.ts
2
- import { createContext } from "react";
3
- var EcsFlowContext = createContext(null);
4
-
5
- // src/utils/id-generator.ts
6
- var EcsIdGenerator = class {
7
- static entityProxy(proxy) {
8
- return `${proxy.entityType}:${proxy.entityUid}`;
9
- }
10
- };
11
-
12
- // src/abstract/ecs-flow-repository.ts
13
- var EcsFlowRepository = class {
14
- nodes;
15
- constructor() {
16
- this.nodes = /* @__PURE__ */ new Map();
17
- }
18
- get sizeNodes() {
19
- return this.nodes.size;
20
- }
21
- addSystemModuleNode(node) {
22
- this.nodes.set(node.data.entityType.toString(), node);
23
- }
24
- getSystemModuleNode(entityType) {
25
- return this.nodes.get(entityType.toString());
26
- }
27
- addEntityNode(node) {
28
- this.nodes.set(EcsIdGenerator.entityProxy(node.data.entity), node);
29
- }
30
- getEntityNode(entity) {
31
- return this.nodes.get(EcsIdGenerator.entityProxy(entity));
32
- }
33
- listAllNodes() {
34
- return Array.from(this.nodes.values());
35
- }
36
- };
37
-
38
- // src/abstract/handle-types.ts
39
- var EcsHandleDataType = /* @__PURE__ */ ((EcsHandleDataType2) => {
40
- EcsHandleDataType2["proxy"] = "proxy";
41
- EcsHandleDataType2["module"] = "module";
42
- return EcsHandleDataType2;
43
- })(EcsHandleDataType || {});
44
-
45
- // src/nodes/node-systems-module.tsx
46
- import { NodeContainer } from "@awesome-flow/core/layout";
47
- import { useContext } from "react";
48
- import { Badge as Badge3 } from "@mantine/core";
49
-
50
- // src/layout/systems-module-layout.tsx
51
- import { SystemType } from "@awesome-ecs/abstract/systems";
52
- import { Accordion as Accordion2, Text } from "@mantine/core";
53
- import { useMemo as useMemo2 } from "react";
54
-
55
- // src/components/pipeline-middleware-list.tsx
56
- import { Accordion, Badge as Badge2, Stack } from "@mantine/core";
57
-
58
- // src/components/badge-list.tsx
59
- import { Badge } from "@mantine/core";
60
- import { memo as memo2 } from "react";
61
-
62
- // src/components/formatter-camel-case.tsx
63
- import { memo, useMemo } from "react";
64
- function CamelCaseFormatter(props) {
65
- const value = useMemo(
66
- () => props.value?.toString().replace(/([a-z])([A-Z])/g, "$1 $2"),
67
- [props.value]
68
- );
69
- return value;
70
- }
71
- var formatter_camel_case_default = memo(CamelCaseFormatter);
72
-
73
- // src/components/badge-list.tsx
74
- import { jsx } from "react/jsx-runtime";
75
- function BadgeList(props) {
76
- return props.items.map((value, i) => {
77
- return /* @__PURE__ */ jsx(Badge, { ...props.badge || [], children: /* @__PURE__ */ jsx(formatter_camel_case_default, { value }) }, i);
78
- });
79
- }
80
- var badge_list_default = memo2(BadgeList);
81
-
82
- // src/components/pipeline-middleware-list.tsx
83
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
84
- function PipelineMiddlewareList(props) {
85
- let middleware = [];
86
- if (props.pipeline) {
87
- middleware = props.pipeline["middleware"];
88
- }
89
- const components = middleware.map((m) => {
90
- return m.name || m.constructor.name;
91
- });
92
- return /* @__PURE__ */ jsxs(Accordion.Item, { value: props.label, children: [
93
- /* @__PURE__ */ jsx2(Accordion.Control, { children: /* @__PURE__ */ jsx2(Badge2, { fullWidth: true, variant: "light", rightSection: components.length, children: props.label }) }),
94
- /* @__PURE__ */ jsx2(Accordion.Panel, { children: /* @__PURE__ */ jsx2(Stack, { children: /* @__PURE__ */ jsx2(badge_list_default, { items: components, badge: { variant: "outline" } }) }) })
95
- ] }, props.label);
96
- }
97
- var pipeline_middleware_list_default = PipelineMiddlewareList;
98
-
99
- // src/layout/systems-module-layout.tsx
100
- import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
101
- function SystemsModuleLayout(props) {
102
- const { module } = props;
103
- const runtimeContext = module["runtimeContext"];
104
- const { systemContext } = runtimeContext;
105
- const { status } = useMemo2(() => {
106
- return systemContext.runtime;
107
- }, [systemContext.runtime.status]);
108
- const init = runtimeContext.systemPipelines.get(SystemType.initialize);
109
- const update = runtimeContext.systemPipelines.get(SystemType.update);
110
- const render = runtimeContext.systemPipelines.get(SystemType.render);
111
- const sync = runtimeContext.systemPipelines.get(SystemType.sync);
112
- return /* @__PURE__ */ jsxs2(Fragment, { children: [
113
- /* @__PURE__ */ jsxs2(Text, { children: [
114
- "Status: ",
115
- status
116
- ] }),
117
- /* @__PURE__ */ jsxs2(Accordion2, { children: [
118
- init && /* @__PURE__ */ jsx3(pipeline_middleware_list_default, { pipeline: init, label: "Initialize" }),
119
- update && /* @__PURE__ */ jsx3(pipeline_middleware_list_default, { pipeline: update, label: "Update" }),
120
- render && /* @__PURE__ */ jsx3(pipeline_middleware_list_default, { pipeline: render, label: "Render" }),
121
- sync && /* @__PURE__ */ jsx3(pipeline_middleware_list_default, { pipeline: sync, label: "Sync" })
122
- ] })
123
- ] });
124
- }
125
- var systems_module_layout_default = SystemsModuleLayout;
126
-
127
- // src/nodes/node-systems-module.tsx
128
- import { jsx as jsx4 } from "react/jsx-runtime";
129
- function SystemsModuleNode({ id, data, selected, type }) {
130
- const { systemsModuleRepository } = useContext(EcsFlowContext);
131
- const module = systemsModuleRepository.get(data.entityType);
132
- return /* @__PURE__ */ jsx4(
133
- NodeContainer,
134
- {
135
- id,
136
- selected,
137
- data,
138
- title: /* @__PURE__ */ jsx4(Badge3, { fullWidth: true, color: "indigo", variant: "transparent", children: /* @__PURE__ */ jsx4(formatter_camel_case_default, { value: data.entityType }) }),
139
- type,
140
- children: /* @__PURE__ */ jsx4(systems_module_layout_default, { type: data.entityType, module })
141
- }
142
- );
143
- }
144
- var node_systems_module_default = SystemsModuleNode;
145
-
146
- // src/nodes/node-entity.tsx
147
- import { NodeContainer as NodeContainer2 } from "@awesome-flow/core/layout";
148
- import { Badge as Badge9 } from "@mantine/core";
149
- import { useContext as useContext4, useMemo as useMemo5 } from "react";
150
-
151
- // src/layout/entity-layout.tsx
152
- import { Accordion as Accordion6, Badge as Badge8, Divider, Group } from "@mantine/core";
153
-
154
- // src/components/entity-component-list.tsx
155
- import { Accordion as Accordion3, Badge as Badge4, Stack as Stack2 } from "@mantine/core";
156
- import { memo as memo5 } from "react";
157
-
158
- // src/components/entity-component-inspector.tsx
159
- import { Box, Button, Collapse } from "@mantine/core";
160
- import { memo as memo4, useMemo as useMemo4 } from "react";
161
- import { useDisclosure } from "@mantine/hooks";
162
-
163
- // src/components/object-inspector.tsx
164
- import { useComputedColorScheme } from "@mantine/core";
165
- import { memo as memo3, useMemo as useMemo3 } from "react";
166
- import { Inspector } from "react-inspector";
167
- import { jsx as jsx5 } from "react/jsx-runtime";
168
- function ObjectInspector(props) {
169
- const colorScheme = useComputedColorScheme();
170
- const theme = useMemo3(
171
- () => colorScheme === "dark" ? "chromeDark" : "chromeLight",
172
- [colorScheme]
173
- );
174
- return /* @__PURE__ */ jsx5(Inspector, { table: false, theme, data: props.data });
175
- }
176
- var object_inspector_default = memo3(ObjectInspector);
177
-
178
- // src/components/entity-component-inspector.tsx
179
- import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
180
- function EntityComponentInspector(props) {
181
- const [opened, { toggle }] = useDisclosure(false);
182
- const buttonColor = useMemo4(() => opened ? "light" : "indigo", [opened]);
183
- return /* @__PURE__ */ jsxs3(Box, { children: [
184
- /* @__PURE__ */ jsx6(Button, { variant: "outline", size: "xs", onClick: toggle, color: buttonColor, fullWidth: true, children: props.component.componentType }),
185
- /* @__PURE__ */ jsx6(Collapse, { in: opened, children: opened && /* @__PURE__ */ jsx6(object_inspector_default, { data: props.component }) })
186
- ] });
187
- }
188
- var entity_component_inspector_default = memo4(EntityComponentInspector);
189
-
190
- // src/components/entity-component-list.tsx
191
- import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
192
- function EntityComponentList(props) {
193
- const components = Array.from(props.entity.components.values());
194
- return /* @__PURE__ */ jsxs4(Accordion3.Item, { value: "components", children: [
195
- /* @__PURE__ */ jsx7(Accordion3.Control, { children: /* @__PURE__ */ jsx7(Badge4, { fullWidth: true, variant: "light", rightSection: components.length, children: "Components" }) }),
196
- /* @__PURE__ */ jsx7(Accordion3.Panel, { children: /* @__PURE__ */ jsx7(Stack2, { children: components.map((c, i) => /* @__PURE__ */ jsx7(entity_component_inspector_default, { component: c }, i)) }) })
197
- ] }, "components");
198
- }
199
- var entity_component_list_default = memo5(EntityComponentList);
200
-
201
- // src/components/entity-proxy-list.tsx
202
- import { Accordion as Accordion4, Badge as Badge5, Stack as Stack3 } from "@mantine/core";
203
- import { memo as memo6 } from "react";
204
- import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
205
- function EntityProxyList(props) {
206
- const proxies = Array.from(props.entity.proxies.values()).map((c) => c.values());
207
- const items = proxies.map((p) => Array.from(p).map((k) => EcsIdGenerator.entityProxy(k))).flat();
208
- return /* @__PURE__ */ jsxs5(Accordion4.Item, { value: "proxies", children: [
209
- /* @__PURE__ */ jsx8(Accordion4.Control, { children: /* @__PURE__ */ jsx8(Badge5, { fullWidth: true, variant: "light", rightSection: items.length, children: "Proxies" }) }),
210
- /* @__PURE__ */ jsx8(Accordion4.Panel, { children: /* @__PURE__ */ jsx8(Stack3, { children: /* @__PURE__ */ jsx8(badge_list_default, { items, badge: { variant: "outline" } }) }) })
211
- ] }, "proxies");
212
- }
213
- var entity_proxy_list_default = memo6(EntityProxyList);
214
-
215
- // src/components/entity-subscription-list.tsx
216
- import { Accordion as Accordion5, Badge as Badge6, Stack as Stack4 } from "@mantine/core";
217
- import { memo as memo7, useContext as useContext2 } from "react";
218
- import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
219
- function EntitySubscriptionList(props) {
220
- const { entityEventsManager } = useContext2(EcsFlowContext);
221
- const subscriptions = entityEventsManager.getSubscriptionsForEntity(props.entity.myProxy);
222
- return /* @__PURE__ */ jsxs6(Accordion5.Item, { value: "subscriptions", children: [
223
- /* @__PURE__ */ jsx9(Accordion5.Control, { children: /* @__PURE__ */ jsx9(Badge6, { fullWidth: true, variant: "light", rightSection: subscriptions.length, children: "Events" }) }),
224
- /* @__PURE__ */ jsx9(Accordion5.Panel, { children: /* @__PURE__ */ jsx9(Stack4, { children: /* @__PURE__ */ jsx9(badge_list_default, { items: subscriptions, badge: { variant: "outline" } }) }) })
225
- ] }, "subscriptions");
226
- }
227
- var entity_subscription_list_default = memo7(EntitySubscriptionList);
228
-
229
- // src/components/entity-update-counter.tsx
230
- import { Badge as Badge7 } from "@mantine/core";
231
- import { memo as memo8, useContext as useContext3, useEffect, useState } from "react";
232
- import { Fragment as Fragment2, jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
233
- function EntityUpdateCounter(props) {
234
- const [, setRefresh] = useState(0);
235
- const { entityUpdateCounter } = useContext3(EcsFlowContext);
236
- const updates = entityUpdateCounter.getUpdateCount(props.entityUid) || 0;
237
- const removes = entityUpdateCounter.getRemoveCount(props.entityUid) || 0;
238
- useEffect(() => {
239
- const interval = setInterval(() => {
240
- setRefresh((refresh) => refresh + 1);
241
- }, 1e3);
242
- return () => {
243
- console.log("CLEAR INTERVAL");
244
- clearInterval(interval);
245
- };
246
- }, []);
247
- return /* @__PURE__ */ jsxs7(Fragment2, { children: [
248
- /* @__PURE__ */ jsx10(Badge7, { variant: "light", children: updates }),
249
- /* @__PURE__ */ jsx10(Badge7, { variant: "light", color: "orange", children: removes })
250
- ] });
251
- }
252
- var entity_update_counter_default = memo8(EntityUpdateCounter);
253
-
254
- // src/layout/entity-layout.tsx
255
- import { Fragment as Fragment3, jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
256
- function EntityLayout({ entity }) {
257
- return /* @__PURE__ */ jsxs8(Fragment3, { children: [
258
- /* @__PURE__ */ jsxs8(Group, { children: [
259
- /* @__PURE__ */ jsx11(Badge8, { variant: "outline", color: "orange", children: entity.myProxy.entityUid }),
260
- /* @__PURE__ */ jsx11(entity_update_counter_default, { entityUid: entity.myProxy.entityUid })
261
- ] }),
262
- /* @__PURE__ */ jsx11(Divider, { my: 5 }),
263
- /* @__PURE__ */ jsxs8(Accordion6, { children: [
264
- /* @__PURE__ */ jsx11(entity_component_list_default, { entity }),
265
- /* @__PURE__ */ jsx11(entity_proxy_list_default, { entity }),
266
- /* @__PURE__ */ jsx11(entity_subscription_list_default, { entity })
267
- ] })
268
- ] });
269
- }
270
- var entity_layout_default = EntityLayout;
271
-
272
- // src/nodes/node-entity.tsx
273
- import { jsx as jsx12 } from "react/jsx-runtime";
274
- function EntityNode({ id, data, selected, type }) {
275
- const { entityRepository } = useContext4(EcsFlowContext);
276
- const entity = useMemo5(() => entityRepository.get(data.entity), [data.entity]);
277
- return /* @__PURE__ */ jsx12(
278
- NodeContainer2,
279
- {
280
- id,
281
- selected,
282
- data,
283
- title: /* @__PURE__ */ jsx12(Badge9, { fullWidth: true, variant: "transparent", children: /* @__PURE__ */ jsx12(formatter_camel_case_default, { value: entity.myProxy.entityType }) }),
284
- type,
285
- children: /* @__PURE__ */ jsx12(entity_layout_default, { entity })
286
- }
287
- );
288
- }
289
- var node_entity_default = EntityNode;
290
-
291
- // src/templates/template-entity-node.ts
292
- import { Position } from "@xyflow/react";
293
-
294
- // src/abstract/templates.ts
295
- var EcsTemplateGroup = /* @__PURE__ */ ((EcsTemplateGroup2) => {
296
- EcsTemplateGroup2["ecs"] = "ECS";
297
- return EcsTemplateGroup2;
298
- })(EcsTemplateGroup || {});
299
-
300
- // src/templates/template-entity-node.ts
301
- var EntityNodeTemplate = class {
302
- template = {
303
- type: "entity-node" /* entity */,
304
- group: "ECS" /* ecs */,
305
- data: {
306
- title: "Entity",
307
- entity: null
308
- },
309
- handles: [
310
- {
311
- dataType: "proxy" /* proxy */,
312
- position: Position.Left,
313
- connection: "target",
314
- disabled: true
315
- },
316
- {
317
- dataType: "proxy" /* proxy */,
318
- position: Position.Right,
319
- connection: "source",
320
- disabled: true
321
- }
322
- ]
323
- };
324
- };
325
-
326
- // src/templates/template-systems-module.ts
327
- import { Position as Position2 } from "@xyflow/react";
328
- var SystemsModuleNodeTemplate = class {
329
- template = {
330
- type: "systems-module-node" /* systemsModule */,
331
- group: "ECS" /* ecs */,
332
- data: {
333
- title: "Systems Module",
334
- entityType: null
335
- },
336
- handles: [
337
- {
338
- dataType: "module" /* module */,
339
- position: Position2.Left,
340
- connection: "target",
341
- disabled: true
342
- }
343
- ]
344
- };
345
- };
346
-
347
- // src/abstract/node-types.ts
348
- var EcsNodeType = /* @__PURE__ */ ((EcsNodeType2) => {
349
- EcsNodeType2["systemsModule"] = "systems-module-node";
350
- EcsNodeType2["entity"] = "entity-node";
351
- return EcsNodeType2;
352
- })(EcsNodeType || {});
353
- var ecsNodeTypes = {
354
- ["systems-module-node" /* systemsModule */]: node_systems_module_default,
355
- ["entity-node" /* entity */]: node_entity_default
356
- };
357
- var ecsNodeTemplates = {
358
- ["entity-node" /* entity */]: new EntityNodeTemplate(),
359
- ["systems-module-node" /* systemsModule */]: new SystemsModuleNodeTemplate()
360
- };
361
-
362
- // src/flow/flow-ecs-state.tsx
363
- import { useEffect as useEffect6, useState as useState3, memo as memo9, useContext as useContext9 } from "react";
364
-
365
- // src/flow/flow-ecs-entities.tsx
366
- import { FlowContext } from "@awesome-flow/core/abstract";
367
- import { useContext as useContext7, useEffect as useEffect4, useState as useState2 } from "react";
368
- import { useFlowStore as useFlowStore3 } from "@awesome-flow/core/hooks";
369
-
370
- // src/flow/flow-ecs-edge-proxies.tsx
371
- import { useContext as useContext5, useEffect as useEffect2 } from "react";
372
- import { useFlowStore } from "@awesome-flow/core/hooks";
373
- import { Fragment as Fragment4, jsx as jsx13 } from "react/jsx-runtime";
374
- function FlowEcsEdgeProxies(props) {
375
- const { nodesToConnect } = props;
376
- const onConnect = useFlowStore((state) => state.onConnect);
377
- const { ecsFlowRepository, entityRepository } = useContext5(EcsFlowContext);
378
- useEffect2(() => {
379
- for (const node of nodesToConnect) {
380
- const sourceHandle = node.data.handles.find((h) => h.connection === "source");
381
- const entity = entityRepository.get(node.data.entity);
382
- for (const [, proxyMap] of entity.proxies) {
383
- for (const proxy of proxyMap.values()) {
384
- const proxyNode = ecsFlowRepository.getEntityNode(proxy);
385
- if (proxyNode) {
386
- const targetHandle = proxyNode.data.handles.find((h) => h.connection === "target");
387
- onConnect({
388
- source: node.id,
389
- target: proxyNode.id,
390
- sourceHandle: sourceHandle.id,
391
- targetHandle: targetHandle.id
392
- });
393
- }
394
- }
395
- }
396
- }
397
- }, [nodesToConnect]);
398
- return /* @__PURE__ */ jsx13(Fragment4, {});
399
- }
400
- var flow_ecs_edge_proxies_default = FlowEcsEdgeProxies;
401
-
402
- // src/flow/flow-ecs-edge-modules.tsx
403
- import { useContext as useContext6, useEffect as useEffect3 } from "react";
404
- import { useFlowStore as useFlowStore2 } from "@awesome-flow/core/hooks";
405
- import { Fragment as Fragment5, jsx as jsx14 } from "react/jsx-runtime";
406
- function FlowEcsEdgeModules(props) {
407
- const { nodesToConnect } = props;
408
- const onConnect = useFlowStore2((state) => state.onConnect);
409
- const { ecsFlowRepository, entityRepository } = useContext6(EcsFlowContext);
410
- useEffect3(() => {
411
- for (const node of nodesToConnect) {
412
- const sourceHandle = node.data.handles.find((h) => h.connection === "source");
413
- const entity = entityRepository.get(node.data.entity);
414
- const systemModule = ecsFlowRepository.getSystemModuleNode(entity.myProxy.entityType);
415
- const targetHandle = systemModule?.data.handles.find((h) => h.connection === "target");
416
- if (targetHandle) {
417
- onConnect({
418
- source: node.id,
419
- target: systemModule.id,
420
- sourceHandle: sourceHandle.id,
421
- targetHandle: targetHandle.id
422
- });
423
- }
424
- }
425
- }, [nodesToConnect]);
426
- return /* @__PURE__ */ jsx14(Fragment5, {});
427
- }
428
- var flow_ecs_edge_modules_default = FlowEcsEdgeModules;
429
-
430
- // src/flow/flow-ecs-entities.tsx
431
- import { Fragment as Fragment6, jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
432
- function FlowEcsEntities() {
433
- const { nodeFactory } = useContext7(FlowContext);
434
- const addNodes = useFlowStore3((state) => state.addNodes);
435
- const { ecsFlowRepository, entityRepository } = useContext7(EcsFlowContext);
436
- const [entityNodes, setEntityNodes] = useState2([]);
437
- useEffect4(() => {
438
- const entities = entityRepository.listAll();
439
- const nodes = [];
440
- for (const entity of entities) {
441
- if (ecsFlowRepository.getEntityNode(entity.myProxy)) {
442
- continue;
443
- }
444
- const node = nodeFactory.createNodeFromType("entity-node" /* entity */);
445
- node.data.entity = entity.myProxy;
446
- node.position = { x: 0, y: 0 };
447
- ecsFlowRepository.addEntityNode(node);
448
- nodes.push(node);
449
- }
450
- setEntityNodes(nodes);
451
- addNodes(nodes);
452
- }, [entityRepository.size]);
453
- return /* @__PURE__ */ jsxs9(Fragment6, { children: [
454
- /* @__PURE__ */ jsx15(flow_ecs_edge_proxies_default, { nodesToConnect: entityNodes }),
455
- /* @__PURE__ */ jsx15(flow_ecs_edge_modules_default, { nodesToConnect: entityNodes })
456
- ] });
457
- }
458
- var flow_ecs_entities_default = FlowEcsEntities;
459
-
460
- // src/flow/flow-ecs-modules.tsx
461
- import { useEffect as useEffect5, useContext as useContext8 } from "react";
462
- import { FlowContext as FlowContext2 } from "@awesome-flow/core/abstract";
463
- import { useFlowStore as useFlowStore4 } from "@awesome-flow/core/hooks";
464
- import { Fragment as Fragment7, jsx as jsx16 } from "react/jsx-runtime";
465
- function FlowEcsModules() {
466
- const { nodeFactory } = useContext8(FlowContext2);
467
- const addNodes = useFlowStore4((state) => state.addNodes);
468
- const { ecsFlowRepository, systemsModuleRepository } = useContext8(EcsFlowContext);
469
- useEffect5(() => {
470
- const modules = Array.from(systemsModuleRepository.list()).filter((m) => !!m);
471
- const keys = Array.from(modules.values()).map((v) => v[0]);
472
- const nodesToAdd = [];
473
- for (const element of keys) {
474
- if (ecsFlowRepository.getSystemModuleNode(element)) {
475
- continue;
476
- }
477
- const node = nodeFactory.createNodeFromType("systems-module-node" /* systemsModule */);
478
- node.data.entityType = element;
479
- node.position = { x: 0, y: 0 };
480
- ecsFlowRepository.addSystemModuleNode(node);
481
- nodesToAdd.push(node);
482
- }
483
- if (nodesToAdd.length) {
484
- addNodes(nodesToAdd);
485
- }
486
- }, [systemsModuleRepository.size]);
487
- return /* @__PURE__ */ jsx16(Fragment7, {});
488
- }
489
- var flow_ecs_modules_default = FlowEcsModules;
490
-
491
- // src/flow/flow-ecs-state.tsx
492
- import { FlowAutoLayout } from "@awesome-flow/core/canvas";
493
- import { Fragment as Fragment8, jsx as jsx17, jsxs as jsxs10 } from "react/jsx-runtime";
494
- function FlowEcsState(props) {
495
- const [, setUpdates] = useState3(0);
496
- const [refreshLayout, setRefreshLayout] = useState3(false);
497
- const { ecsFlowRepository } = useContext9(EcsFlowContext);
498
- useEffect6(() => {
499
- setRefreshLayout(true);
500
- }, [ecsFlowRepository.sizeNodes]);
501
- useEffect6(() => {
502
- setInterval(() => {
503
- setUpdates((updates) => updates + 1);
504
- }, 1e3);
505
- }, []);
506
- return /* @__PURE__ */ jsxs10(Fragment8, { children: [
507
- props.showSystemModules && /* @__PURE__ */ jsx17(flow_ecs_modules_default, {}),
508
- props.showEntities && /* @__PURE__ */ jsx17(flow_ecs_entities_default, {}),
509
- props.autoLayout && /* @__PURE__ */ jsx17(FlowAutoLayout, { refreshLayout })
510
- ] });
511
- }
512
- var flow_ecs_state_default = memo9(FlowEcsState);
513
- export {
514
- EcsFlowContext,
515
- EcsFlowRepository,
516
- EcsHandleDataType,
517
- EcsNodeType,
518
- EcsTemplateGroup,
519
- node_entity_default as EntityNode,
520
- EntityNodeTemplate,
521
- flow_ecs_state_default as FlowEcsState,
522
- node_systems_module_default as SystemsModuleNode,
523
- SystemsModuleNodeTemplate,
524
- ecsNodeTemplates,
525
- ecsNodeTypes
526
- };
527
- //# sourceMappingURL=index.js.map
1
+ import{createContext as pt}from"react";var s=pt(null);var y=class{static entityProxy(t){return`${t.entityType}:${t.entityUid}`}};var W=class{nodes;constructor(){this.nodes=new Map}get sizeNodes(){return this.nodes.size}addSystemModuleNode(t){this.nodes.set(t.data.entityType.toString(),t)}getSystemModuleNode(t){return this.nodes.get(t.toString())}addEntityNode(t){this.nodes.set(y.entityProxy(t.data.entity),t)}getEntityNode(t){return this.nodes.get(y.entityProxy(t))}listAllNodes(){return Array.from(this.nodes.values())}};var T=(e=>(e.proxy="proxy",e.module="module",e))(T||{});import{NodeContainer as so}from"@awesome-flow/core/layout";import{Badge as mo}from"@mantine/core";import{useContext as ao,useMemo as po}from"react";import{memo as lt,useMemo as yt}from"react";function ct(o){return yt(()=>o.value?.toString().replace(/([a-z])([A-Z])/g,"$1 $2"),[o.value])}var c=lt(ct);import{Accordion as to,Badge as oo,Divider as eo,Group as no}from"@mantine/core";import{Accordion as R,Badge as Tt,Stack as vt}from"@mantine/core";import{memo as Rt}from"react";import{Box as Ct,Button as Pt,Collapse as St}from"@mantine/core";import{useDisclosure as It}from"@mantine/hooks";import{memo as Mt,useMemo as wt}from"react";import{useComputedColorScheme as ut}from"@mantine/core";import{memo as ft,useMemo as Et}from"react";import{Inspector as xt}from"react-inspector";import{jsx as Nt}from"react/jsx-runtime";function gt(o){let t=ut(),e=Et(()=>t==="dark"?"chromeDark":"chromeLight",[t]);return Nt(xt,{table:!1,theme:e,data:o.data})}var G=ft(gt);import{jsx as v,jsxs as ht}from"react/jsx-runtime";function Ft(o){let[t,{toggle:e}]=It(!1),n=wt(()=>t?"light":"indigo",[t]);return ht(Ct,{children:[v(Pt,{variant:"outline",size:"xs",onClick:e,color:n,fullWidth:!0,children:o.component.componentType}),v(St,{in:t,children:t&&v(G,{data:o.component})})]})}var O=Mt(Ft);import{jsx as E,jsxs as bt}from"react/jsx-runtime";function Lt(o){let t=Array.from(o.entity.components.values());return bt(R.Item,{value:"components",children:[E(R.Control,{children:E(Tt,{fullWidth:!0,variant:"light",rightSection:t.length,children:"Components"})}),E(R.Panel,{children:E(vt,{children:t.map((e,n)=>E(O,{component:e},n))})})]},"components")}var $=Rt(Lt);import{Accordion as L,Badge as Ut,Stack as kt}from"@mantine/core";import{memo as zt}from"react";import{Badge as At}from"@mantine/core";import{memo as Bt}from"react";import{jsx as V}from"react/jsx-runtime";function Dt(o){return o.items.map((t,e)=>V(At,{...o.badge||[],children:V(c,{value:t})},e))}var u=Bt(Dt);import{jsx as x,jsxs as Wt}from"react/jsx-runtime";function Ht(o){let e=Array.from(o.entity.proxies.values()).map(n=>n.values()).map(n=>Array.from(n).map(i=>y.entityProxy(i))).flat();return Wt(L.Item,{value:"proxies",children:[x(L.Control,{children:x(Ut,{fullWidth:!0,variant:"light",rightSection:e.length,children:"Proxies"})}),x(L.Panel,{children:x(kt,{children:x(u,{items:e,badge:{variant:"outline"}})})})]},"proxies")}var Z=zt(Ht);import{Accordion as b,Badge as Gt,Stack as Ot}from"@mantine/core";import{memo as $t,useContext as Vt}from"react";import{jsx as g,jsxs as qt}from"react/jsx-runtime";function Zt(o){let{entityEventsManager:t}=Vt(s),e=t.getSubscriptionsForEntity(o.entity.myProxy);return qt(b.Item,{value:"subscriptions",children:[g(b.Control,{children:g(Gt,{fullWidth:!0,variant:"light",rightSection:e.length,children:"Events"})}),g(b.Panel,{children:g(Ot,{children:g(u,{items:e,badge:{variant:"outline"}})})})]},"subscriptions")}var q=$t(Zt);import{Badge as J}from"@mantine/core";import{memo as Jt,useContext as Kt,useEffect as Qt,useState as Xt}from"react";import{Fragment as _t,jsx as K,jsxs as jt}from"react/jsx-runtime";function Yt(o){let[,t]=Xt(0),{entityUpdateCounter:e}=Kt(s),n=e.getUpdateCount(o.entityUid)||0,i=e.getRemoveCount(o.entityUid)||0;return Qt(()=>{let r=setInterval(()=>{t(a=>a+1)},1e3);return()=>{console.log("CLEAR INTERVAL"),clearInterval(r)}},[]),jt(_t,{children:[K(J,{variant:"light",children:n}),K(J,{variant:"light",color:"orange",children:i})]})}var Q=Jt(Yt);import{Fragment as io,jsx as f,jsxs as A}from"react/jsx-runtime";function ro({entity:o}){return A(io,{children:[A(no,{children:[f(oo,{variant:"outline",color:"orange",children:o.myProxy.entityUid}),f(Q,{entityUid:o.myProxy.entityUid})]}),f(eo,{my:5}),A(to,{children:[f($,{entity:o}),f(Z,{entity:o}),f(q,{entity:o})]})]})}var X=ro;import{jsx as S}from"react/jsx-runtime";function lo({id:o,data:t,selected:e,type:n}){let{entityRepository:i}=ao(s),r=po(()=>i.get(t.entity),[t.entity]);return S(so,{id:o,selected:e,data:t,title:S(mo,{fullWidth:!0,variant:"transparent",children:S(c,{value:r.myProxy.entityType})}),type:n,children:S(X,{entity:r})})}var B=lo;import{NodeContainer as Po}from"@awesome-flow/core/layout";import{Badge as So}from"@mantine/core";import{useContext as Io}from"react";import{SystemType as I}from"@awesome-ecs/abstract/systems";import{Accordion as Eo,Text as xo}from"@mantine/core";import{useMemo as go}from"react";import{Accordion as D,Badge as yo,Stack as co}from"@mantine/core";import{jsx as N,jsxs as fo}from"react/jsx-runtime";function uo(o){let t=[];o.pipeline&&(t=o.pipeline.middleware);let e=t.map(n=>n.name||n.constructor.name);return fo(D.Item,{value:o.label,children:[N(D.Control,{children:N(yo,{fullWidth:!0,variant:"light",rightSection:e.length,children:o.label})}),N(D.Panel,{children:N(co,{children:N(u,{items:e,badge:{variant:"outline"}})})})]},o.label)}var C=uo;import{Fragment as Co,jsx as M,jsxs as U}from"react/jsx-runtime";function No(o){let{module:t}=o,e=t.runtimeContext,{systemContext:n}=e,{status:i}=go(()=>n.runtime,[n.runtime.status]),r=e.systemPipelines.get(I.initialize),a=e.systemPipelines.get(I.update),m=e.systemPipelines.get(I.render),d=e.systemPipelines.get(I.sync);return U(Co,{children:[U(xo,{children:["Status: ",i]}),U(Eo,{children:[r&&M(C,{pipeline:r,label:"Initialize"}),a&&M(C,{pipeline:a,label:"Update"}),m&&M(C,{pipeline:m,label:"Render"}),d&&M(C,{pipeline:d,label:"Sync"})]})]})}var Y=No;import{jsx as w}from"react/jsx-runtime";function Mo({id:o,data:t,selected:e,type:n}){let{systemsModuleRepository:i}=Io(s),r=i.get(t.entityType);return w(Po,{id:o,selected:e,data:t,title:w(So,{fullWidth:!0,color:"indigo",variant:"transparent",children:w(c,{value:t.entityType})}),type:n,children:w(Y,{type:t.entityType,module:r})})}var k=Mo;import{Position as _}from"@xyflow/react";var z=(t=>(t.ecs="ECS",t))(z||{});var F=class{template={type:"entity-node",group:"ECS",data:{title:"Entity",entity:null},handles:[{dataType:"proxy",position:_.Left,connection:"target",disabled:!0},{dataType:"proxy",position:_.Right,connection:"source",disabled:!0}]}};import{Position as wo}from"@xyflow/react";var h=class{template={type:"systems-module-node",group:"ECS",data:{title:"Systems Module",entityType:null},handles:[{dataType:"module",position:wo.Left,connection:"target",disabled:!0}]}};var P=(e=>(e.systemsModule="systems-module-node",e.entity="entity-node",e))(P||{}),Kn={"systems-module-node":k,"entity-node":B},Qn={"entity-node":new F,"systems-module-node":new h};import{FlowAutoLayout as Yo}from"@awesome-flow/core/canvas";import{memo as _o,useContext as jo,useEffect as st,useState as mt}from"react";import{FlowContext as zo}from"@awesome-flow/core/abstract";import{useFlowStore as Ho}from"@awesome-flow/core/hooks";import{useContext as ot,useEffect as Wo,useState as Go}from"react";import{useFlowStore as Fo}from"@awesome-flow/core/hooks";import{useContext as ho,useEffect as To}from"react";import{Fragment as Ro,jsx as Lo}from"react/jsx-runtime";function vo(o){let{nodesToConnect:t}=o,e=Fo(r=>r.onConnect),{ecsFlowRepository:n,entityRepository:i}=ho(s);return To(()=>{for(let r of t){let a=r.data.handles.find(l=>l.connection==="source"),m=i.get(r.data.entity),d=n.getSystemModuleNode(m.myProxy.entityType),p=d?.data.handles.find(l=>l.connection==="target");p&&e({source:r.id,target:d.id,sourceHandle:a.id,targetHandle:p.id})}},[t]),Lo(Ro,{})}var j=vo;import{useFlowStore as bo}from"@awesome-flow/core/hooks";import{useContext as Ao,useEffect as Bo}from"react";import{Fragment as Uo,jsx as ko}from"react/jsx-runtime";function Do(o){let{nodesToConnect:t}=o,e=bo(r=>r.onConnect),{ecsFlowRepository:n,entityRepository:i}=Ao(s);return Bo(()=>{for(let r of t){let a=r.data.handles.find(d=>d.connection==="source"),m=i.get(r.data.entity);for(let[,d]of m.proxies)for(let p of d.values()){let l=n.getEntityNode(p);if(l){let dt=l.data.handles.find(at=>at.connection==="target");e({source:r.id,target:l.id,sourceHandle:a.id,targetHandle:dt.id})}}}},[t]),ko(Uo,{})}var tt=Do;import{Fragment as $o,jsx as et,jsxs as Vo}from"react/jsx-runtime";function Oo(){let{nodeFactory:o}=ot(zo),t=Ho(a=>a.addNodes),{ecsFlowRepository:e,entityRepository:n}=ot(s),[i,r]=Go([]);return Wo(()=>{let a=n.listAll(),m=[];for(let d of a){if(e.getEntityNode(d.myProxy))continue;let p=o.createNodeFromType("entity-node");p.data.entity=d.myProxy,p.position={x:0,y:0},e.addEntityNode(p),m.push(p)}r(m),t(m)},[n.size]),Vo($o,{children:[et(tt,{nodesToConnect:i}),et(j,{nodesToConnect:i})]})}var nt=Oo;import{FlowContext as Zo}from"@awesome-flow/core/abstract";import{useFlowStore as qo}from"@awesome-flow/core/hooks";import{useContext as rt,useEffect as Jo}from"react";import{Fragment as Qo,jsx as Xo}from"react/jsx-runtime";function Ko(){let{nodeFactory:o}=rt(Zo),t=qo(i=>i.addNodes),{ecsFlowRepository:e,systemsModuleRepository:n}=rt(s);return Jo(()=>{let i=Array.from(n.list()).filter(m=>!!m),r=Array.from(i.values()).map(m=>m[0]),a=[];for(let m of r){if(e.getSystemModuleNode(m))continue;let d=o.createNodeFromType("systems-module-node");d.data.entityType=m,d.position={x:0,y:0},e.addSystemModuleNode(d),a.push(d)}a.length&&t(a)},[n.size]),Xo(Qo,{})}var it=Ko;import{Fragment as ee,jsx as H,jsxs as ne}from"react/jsx-runtime";function te(o){let[,t]=mt(0),[e,n]=mt(!1),{ecsFlowRepository:i}=jo(s);return st(()=>{n(!0)},[i.sizeNodes]),st(()=>{setInterval(()=>{t(r=>r+1)},1e3)},[]),ne(ee,{children:[o.showSystemModules&&H(it,{}),o.showEntities&&H(nt,{}),o.autoLayout&&H(Yo,{refreshLayout:e})]})}var oe=_o(te);export{s as EcsFlowContext,W as EcsFlowRepository,T as EcsHandleDataType,P as EcsNodeType,z as EcsTemplateGroup,B as EntityNode,F as EntityNodeTemplate,oe as FlowEcsState,k as SystemsModuleNode,h as SystemsModuleNodeTemplate,Qn as ecsNodeTemplates,Kn as ecsNodeTypes};
package/package.json CHANGED
@@ -1,24 +1,25 @@
1
1
  {
2
2
  "name": "@awesome-flow/ecs",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "The ECS package for Awesome Flow. Provides basic components to map Awesome ECS objects.",
5
5
  "type": "module",
6
6
  "scripts": {
7
- "build": "npx tsup",
8
- "build:clean": "npx rimraf ./dist && npm run build",
7
+ "build:dev": "npx tsc -p ./tsconfig.build.json",
8
+ "build:clean": "npx rimraf ./dist && npm run build:dev",
9
+ "build:prod": "npx rimraf ./dist && npx tsup --env.NODE_ENV production && npx copyfiles -u 1 ./src/styles.css ./dist",
9
10
  "typecheck": "npx attw $(npm pack) --ignore-rules no-resolution",
10
11
  "ts": "npx tsc --noEmit --incremental",
11
12
  "ts:watch": "npx tsc --noEmit --incremental --watch"
12
13
  },
13
14
  "dependencies": {
14
- "@awesome-flow/core": "^0.6.0"
15
+ "@awesome-flow/core": "^0.7.1"
15
16
  },
16
17
  "peerDependencies": {
17
18
  "@awesome-ecs/abstract": "*",
18
19
  "@awesome-ecs/core": "*",
19
20
  "@dagrejs/dagre": "*",
20
- "@mantine/core": "*",
21
- "@mantine/hooks": "*",
21
+ "@mantine/core": "7.11.1",
22
+ "@mantine/hooks": "7.11.1",
22
23
  "@tabler/icons-react": "*",
23
24
  "@xyflow/react": "*",
24
25
  "@xyflow/system": "*",
@@ -69,5 +70,5 @@
69
70
  "url": "https://github.com/privatebytes/awesome-flow/issues"
70
71
  },
71
72
  "homepage": "https://github.com/privatebytes/awesome-flow#readme",
72
- "gitHead": "e1a900205037bca5d03d02892051ff525db9a1c5"
73
+ "gitHead": "9ceb33f6845a44dcfca6662349942ed074e21b6e"
73
74
  }