@awesome-flow/ecs 0.3.0 → 0.5.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.cjs +214 -237
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -21
- package/dist/index.d.ts +22 -21
- package/dist/index.js +192 -216
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -35,80 +35,22 @@ var EcsFlowRepository = class {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
// src/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
import { useReactFlow } from "@xyflow/react";
|
|
45
|
-
import { useCallback, useContext, useEffect, useMemo } from "react";
|
|
46
|
-
import { Fragment, jsx } from "react/jsx-runtime";
|
|
47
|
-
function FlowEcsAutoLayout(props) {
|
|
48
|
-
const { getNodes, getEdges } = useReactFlow();
|
|
49
|
-
const context = useContext(FlowContext);
|
|
50
|
-
const setNodes = context.useFlowStore((state) => state.setNodes);
|
|
51
|
-
const graph = useMemo(() => new Dagre.graphlib.Graph().setDefaultEdgeLabel(() => ({})), []);
|
|
52
|
-
const getLayoutElements = useCallback(
|
|
53
|
-
(nodes, edges, options) => {
|
|
54
|
-
graph.setGraph(options);
|
|
55
|
-
edges.forEach((edge) => graph.setEdge(edge.source, edge.target));
|
|
56
|
-
nodes.forEach((node) => {
|
|
57
|
-
if (node.measured) {
|
|
58
|
-
graph.setNode(node.id, {
|
|
59
|
-
width: node.measured.width,
|
|
60
|
-
height: node.measured.height
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
Dagre.layout(graph);
|
|
65
|
-
return {
|
|
66
|
-
nodes: nodes.map((node) => {
|
|
67
|
-
const graphNode = graph.node(node.id);
|
|
68
|
-
if (graphNode) {
|
|
69
|
-
return { ...node, position: { x: graphNode.x, y: graphNode.y } };
|
|
70
|
-
}
|
|
71
|
-
return node;
|
|
72
|
-
}),
|
|
73
|
-
edges
|
|
74
|
-
};
|
|
75
|
-
},
|
|
76
|
-
[graph]
|
|
77
|
-
);
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
if (props.needsLayout) {
|
|
80
|
-
const storeNodes = getNodes();
|
|
81
|
-
if (storeNodes?.length) {
|
|
82
|
-
const edges = getEdges();
|
|
83
|
-
const layout = getLayoutElements(storeNodes, edges, {
|
|
84
|
-
rankdir: "LR"
|
|
85
|
-
});
|
|
86
|
-
setNodes(layout.nodes);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}, [props.needsLayout]);
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
if (props.needsLayout) {
|
|
92
|
-
props.setNeedsLayout(false);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
return /* @__PURE__ */ jsx(Fragment, {});
|
|
96
|
-
}
|
|
97
|
-
var flow_ecs_auto_layout_default = FlowEcsAutoLayout;
|
|
98
|
-
|
|
99
|
-
// src/flow/flow-ecs-entities.tsx
|
|
100
|
-
import { FlowContext as FlowContext4 } from "@awesome-flow/core/abstract";
|
|
101
|
-
import { useContext as useContext8, useEffect as useEffect5, useState as useState2 } from "react";
|
|
38
|
+
// src/abstract/handle-types.ts
|
|
39
|
+
var EcsHandleDataType = /* @__PURE__ */ ((EcsHandleDataType2) => {
|
|
40
|
+
EcsHandleDataType2["proxy"] = "proxy";
|
|
41
|
+
EcsHandleDataType2["module"] = "module";
|
|
42
|
+
return EcsHandleDataType2;
|
|
43
|
+
})(EcsHandleDataType || {});
|
|
102
44
|
|
|
103
45
|
// src/nodes/node-systems-module.tsx
|
|
104
46
|
import { NodeContainer } from "@awesome-flow/core/layout";
|
|
105
|
-
import { useContext
|
|
47
|
+
import { useContext } from "react";
|
|
106
48
|
import { Badge as Badge3 } from "@mantine/core";
|
|
107
49
|
|
|
108
50
|
// src/layout/systems-module-layout.tsx
|
|
109
51
|
import { SystemType } from "@awesome-ecs/abstract/systems";
|
|
110
52
|
import { Accordion as Accordion2, Text } from "@mantine/core";
|
|
111
|
-
import { useMemo as
|
|
53
|
+
import { useMemo as useMemo2 } from "react";
|
|
112
54
|
|
|
113
55
|
// src/components/pipeline-middleware-list.tsx
|
|
114
56
|
import { Accordion, Badge as Badge2, Stack } from "@mantine/core";
|
|
@@ -118,9 +60,9 @@ import { Badge } from "@mantine/core";
|
|
|
118
60
|
import { memo as memo2 } from "react";
|
|
119
61
|
|
|
120
62
|
// src/components/formatter-camel-case.tsx
|
|
121
|
-
import { memo, useMemo
|
|
63
|
+
import { memo, useMemo } from "react";
|
|
122
64
|
function CamelCaseFormatter(props) {
|
|
123
|
-
const value =
|
|
65
|
+
const value = useMemo(
|
|
124
66
|
() => props.value?.toString().replace(/([a-z])([A-Z])/g, "$1 $2"),
|
|
125
67
|
[props.value]
|
|
126
68
|
);
|
|
@@ -129,16 +71,16 @@ function CamelCaseFormatter(props) {
|
|
|
129
71
|
var formatter_camel_case_default = memo(CamelCaseFormatter);
|
|
130
72
|
|
|
131
73
|
// src/components/badge-list.tsx
|
|
132
|
-
import { jsx
|
|
74
|
+
import { jsx } from "react/jsx-runtime";
|
|
133
75
|
function BadgeList(props) {
|
|
134
76
|
return props.items.map((value, i) => {
|
|
135
|
-
return /* @__PURE__ */
|
|
77
|
+
return /* @__PURE__ */ jsx(Badge, { ...props.badge || [], children: /* @__PURE__ */ jsx(formatter_camel_case_default, { value }) }, i);
|
|
136
78
|
});
|
|
137
79
|
}
|
|
138
80
|
var badge_list_default = memo2(BadgeList);
|
|
139
81
|
|
|
140
82
|
// src/components/pipeline-middleware-list.tsx
|
|
141
|
-
import { jsx as
|
|
83
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
142
84
|
function PipelineMiddlewareList(props) {
|
|
143
85
|
let middleware = [];
|
|
144
86
|
if (props.pipeline) {
|
|
@@ -148,54 +90,54 @@ function PipelineMiddlewareList(props) {
|
|
|
148
90
|
return m.name || m.constructor.name;
|
|
149
91
|
});
|
|
150
92
|
return /* @__PURE__ */ jsxs(Accordion.Item, { value: props.label, children: [
|
|
151
|
-
/* @__PURE__ */
|
|
152
|
-
/* @__PURE__ */
|
|
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" } }) }) })
|
|
153
95
|
] }, props.label);
|
|
154
96
|
}
|
|
155
97
|
var pipeline_middleware_list_default = PipelineMiddlewareList;
|
|
156
98
|
|
|
157
99
|
// src/layout/systems-module-layout.tsx
|
|
158
|
-
import { Fragment
|
|
100
|
+
import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
159
101
|
function SystemsModuleLayout(props) {
|
|
160
102
|
const { module } = props;
|
|
161
103
|
const runtimeContext = module["runtimeContext"];
|
|
162
104
|
const { systemContext } = runtimeContext;
|
|
163
|
-
const { status } =
|
|
105
|
+
const { status } = useMemo2(() => {
|
|
164
106
|
return systemContext.runtime;
|
|
165
107
|
}, [systemContext.runtime.status]);
|
|
166
108
|
const init = runtimeContext.systemPipelines.get(SystemType.initialize);
|
|
167
109
|
const update = runtimeContext.systemPipelines.get(SystemType.update);
|
|
168
110
|
const render = runtimeContext.systemPipelines.get(SystemType.render);
|
|
169
111
|
const sync = runtimeContext.systemPipelines.get(SystemType.sync);
|
|
170
|
-
return /* @__PURE__ */ jsxs2(
|
|
112
|
+
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
171
113
|
/* @__PURE__ */ jsxs2(Text, { children: [
|
|
172
114
|
"Status: ",
|
|
173
115
|
status
|
|
174
116
|
] }),
|
|
175
117
|
/* @__PURE__ */ jsxs2(Accordion2, { children: [
|
|
176
|
-
init && /* @__PURE__ */
|
|
177
|
-
update && /* @__PURE__ */
|
|
178
|
-
render && /* @__PURE__ */
|
|
179
|
-
sync && /* @__PURE__ */
|
|
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" })
|
|
180
122
|
] })
|
|
181
123
|
] });
|
|
182
124
|
}
|
|
183
125
|
var systems_module_layout_default = SystemsModuleLayout;
|
|
184
126
|
|
|
185
127
|
// src/nodes/node-systems-module.tsx
|
|
186
|
-
import { jsx as
|
|
128
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
187
129
|
function SystemsModuleNode({ id, data, selected, type }) {
|
|
188
|
-
const { systemsModuleRepository } =
|
|
130
|
+
const { systemsModuleRepository } = useContext(EcsFlowContext);
|
|
189
131
|
const module = systemsModuleRepository.get(data.entityType);
|
|
190
|
-
return /* @__PURE__ */
|
|
132
|
+
return /* @__PURE__ */ jsx4(
|
|
191
133
|
NodeContainer,
|
|
192
134
|
{
|
|
193
135
|
id,
|
|
194
136
|
selected,
|
|
195
137
|
data,
|
|
196
|
-
title: /* @__PURE__ */
|
|
138
|
+
title: /* @__PURE__ */ jsx4(Badge3, { fullWidth: true, color: "indigo", variant: "transparent", children: /* @__PURE__ */ jsx4(formatter_camel_case_default, { value: data.entityType }) }),
|
|
197
139
|
type,
|
|
198
|
-
children: /* @__PURE__ */
|
|
140
|
+
children: /* @__PURE__ */ jsx4(systems_module_layout_default, { type: data.entityType, module })
|
|
199
141
|
}
|
|
200
142
|
);
|
|
201
143
|
}
|
|
@@ -204,7 +146,7 @@ var node_systems_module_default = SystemsModuleNode;
|
|
|
204
146
|
// src/nodes/node-entity.tsx
|
|
205
147
|
import { NodeContainer as NodeContainer2 } from "@awesome-flow/core/layout";
|
|
206
148
|
import { Badge as Badge9 } from "@mantine/core";
|
|
207
|
-
import { useContext as
|
|
149
|
+
import { useContext as useContext4, useMemo as useMemo5 } from "react";
|
|
208
150
|
|
|
209
151
|
// src/layout/entity-layout.tsx
|
|
210
152
|
import { Accordion as Accordion6, Badge as Badge8, Divider, Group } from "@mantine/core";
|
|
@@ -215,43 +157,43 @@ import { memo as memo5 } from "react";
|
|
|
215
157
|
|
|
216
158
|
// src/components/entity-component-inspector.tsx
|
|
217
159
|
import { Box, Button, Collapse } from "@mantine/core";
|
|
218
|
-
import { memo as memo4, useMemo as
|
|
160
|
+
import { memo as memo4, useMemo as useMemo4 } from "react";
|
|
219
161
|
import { useDisclosure } from "@mantine/hooks";
|
|
220
162
|
|
|
221
163
|
// src/components/object-inspector.tsx
|
|
222
164
|
import { useComputedColorScheme } from "@mantine/core";
|
|
223
|
-
import { memo as memo3, useMemo as
|
|
165
|
+
import { memo as memo3, useMemo as useMemo3 } from "react";
|
|
224
166
|
import { Inspector } from "react-inspector";
|
|
225
|
-
import { jsx as
|
|
167
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
226
168
|
function ObjectInspector(props) {
|
|
227
169
|
const colorScheme = useComputedColorScheme();
|
|
228
|
-
const theme =
|
|
170
|
+
const theme = useMemo3(
|
|
229
171
|
() => colorScheme === "dark" ? "chromeDark" : "chromeLight",
|
|
230
172
|
[colorScheme]
|
|
231
173
|
);
|
|
232
|
-
return /* @__PURE__ */
|
|
174
|
+
return /* @__PURE__ */ jsx5(Inspector, { table: false, theme, data: props.data });
|
|
233
175
|
}
|
|
234
176
|
var object_inspector_default = memo3(ObjectInspector);
|
|
235
177
|
|
|
236
178
|
// src/components/entity-component-inspector.tsx
|
|
237
|
-
import { jsx as
|
|
179
|
+
import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
238
180
|
function EntityComponentInspector(props) {
|
|
239
181
|
const [opened, { toggle }] = useDisclosure(false);
|
|
240
|
-
const buttonColor =
|
|
182
|
+
const buttonColor = useMemo4(() => opened ? "light" : "indigo", [opened]);
|
|
241
183
|
return /* @__PURE__ */ jsxs3(Box, { children: [
|
|
242
|
-
/* @__PURE__ */
|
|
243
|
-
/* @__PURE__ */
|
|
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 }) })
|
|
244
186
|
] });
|
|
245
187
|
}
|
|
246
188
|
var entity_component_inspector_default = memo4(EntityComponentInspector);
|
|
247
189
|
|
|
248
190
|
// src/components/entity-component-list.tsx
|
|
249
|
-
import { jsx as
|
|
191
|
+
import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
250
192
|
function EntityComponentList(props) {
|
|
251
193
|
const components = Array.from(props.entity.components.values());
|
|
252
194
|
return /* @__PURE__ */ jsxs4(Accordion3.Item, { value: "components", children: [
|
|
253
|
-
/* @__PURE__ */
|
|
254
|
-
/* @__PURE__ */
|
|
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)) }) })
|
|
255
197
|
] }, "components");
|
|
256
198
|
}
|
|
257
199
|
var entity_component_list_default = memo5(EntityComponentList);
|
|
@@ -259,41 +201,41 @@ var entity_component_list_default = memo5(EntityComponentList);
|
|
|
259
201
|
// src/components/entity-proxy-list.tsx
|
|
260
202
|
import { Accordion as Accordion4, Badge as Badge5, Stack as Stack3 } from "@mantine/core";
|
|
261
203
|
import { memo as memo6 } from "react";
|
|
262
|
-
import { jsx as
|
|
204
|
+
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
263
205
|
function EntityProxyList(props) {
|
|
264
206
|
const proxies = Array.from(props.entity.proxies.values()).map((c) => c.values());
|
|
265
207
|
const items = proxies.map((p) => Array.from(p).map((k) => EcsIdGenerator.entityProxy(k))).flat();
|
|
266
208
|
return /* @__PURE__ */ jsxs5(Accordion4.Item, { value: "proxies", children: [
|
|
267
|
-
/* @__PURE__ */
|
|
268
|
-
/* @__PURE__ */
|
|
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" } }) }) })
|
|
269
211
|
] }, "proxies");
|
|
270
212
|
}
|
|
271
213
|
var entity_proxy_list_default = memo6(EntityProxyList);
|
|
272
214
|
|
|
273
215
|
// src/components/entity-subscription-list.tsx
|
|
274
216
|
import { Accordion as Accordion5, Badge as Badge6, Stack as Stack4 } from "@mantine/core";
|
|
275
|
-
import { memo as memo7, useContext as
|
|
276
|
-
import { jsx as
|
|
217
|
+
import { memo as memo7, useContext as useContext2 } from "react";
|
|
218
|
+
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
277
219
|
function EntitySubscriptionList(props) {
|
|
278
|
-
const { entityEventsManager } =
|
|
220
|
+
const { entityEventsManager } = useContext2(EcsFlowContext);
|
|
279
221
|
const subscriptions = entityEventsManager.getSubscriptionsForEntity(props.entity.myProxy);
|
|
280
222
|
return /* @__PURE__ */ jsxs6(Accordion5.Item, { value: "subscriptions", children: [
|
|
281
|
-
/* @__PURE__ */
|
|
282
|
-
/* @__PURE__ */
|
|
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" } }) }) })
|
|
283
225
|
] }, "subscriptions");
|
|
284
226
|
}
|
|
285
227
|
var entity_subscription_list_default = memo7(EntitySubscriptionList);
|
|
286
228
|
|
|
287
229
|
// src/components/entity-update-counter.tsx
|
|
288
230
|
import { Badge as Badge7 } from "@mantine/core";
|
|
289
|
-
import { memo as memo8, useContext as
|
|
290
|
-
import { Fragment as
|
|
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";
|
|
291
233
|
function EntityUpdateCounter(props) {
|
|
292
234
|
const [, setRefresh] = useState(0);
|
|
293
|
-
const { entityUpdateCounter } =
|
|
235
|
+
const { entityUpdateCounter } = useContext3(EcsFlowContext);
|
|
294
236
|
const updates = entityUpdateCounter.getUpdateCount(props.entityUid) || 0;
|
|
295
237
|
const removes = entityUpdateCounter.getRemoveCount(props.entityUid) || 0;
|
|
296
|
-
|
|
238
|
+
useEffect(() => {
|
|
297
239
|
const interval = setInterval(() => {
|
|
298
240
|
setRefresh((refresh) => refresh + 1);
|
|
299
241
|
}, 1e3);
|
|
@@ -302,129 +244,104 @@ function EntityUpdateCounter(props) {
|
|
|
302
244
|
clearInterval(interval);
|
|
303
245
|
};
|
|
304
246
|
}, []);
|
|
305
|
-
return /* @__PURE__ */ jsxs7(
|
|
306
|
-
/* @__PURE__ */
|
|
307
|
-
/* @__PURE__ */
|
|
247
|
+
return /* @__PURE__ */ jsxs7(Fragment2, { children: [
|
|
248
|
+
/* @__PURE__ */ jsx10(Badge7, { variant: "light", children: updates }),
|
|
249
|
+
/* @__PURE__ */ jsx10(Badge7, { variant: "light", color: "orange", children: removes })
|
|
308
250
|
] });
|
|
309
251
|
}
|
|
310
252
|
var entity_update_counter_default = memo8(EntityUpdateCounter);
|
|
311
253
|
|
|
312
254
|
// src/layout/entity-layout.tsx
|
|
313
|
-
import { Fragment as
|
|
255
|
+
import { Fragment as Fragment3, jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
314
256
|
function EntityLayout({ entity }) {
|
|
315
|
-
return /* @__PURE__ */ jsxs8(
|
|
257
|
+
return /* @__PURE__ */ jsxs8(Fragment3, { children: [
|
|
316
258
|
/* @__PURE__ */ jsxs8(Group, { children: [
|
|
317
|
-
/* @__PURE__ */
|
|
318
|
-
/* @__PURE__ */
|
|
259
|
+
/* @__PURE__ */ jsx11(Badge8, { variant: "outline", color: "orange", children: entity.myProxy.entityUid }),
|
|
260
|
+
/* @__PURE__ */ jsx11(entity_update_counter_default, { entityUid: entity.myProxy.entityUid })
|
|
319
261
|
] }),
|
|
320
|
-
/* @__PURE__ */
|
|
262
|
+
/* @__PURE__ */ jsx11(Divider, { my: 5 }),
|
|
321
263
|
/* @__PURE__ */ jsxs8(Accordion6, { children: [
|
|
322
|
-
/* @__PURE__ */
|
|
323
|
-
/* @__PURE__ */
|
|
324
|
-
/* @__PURE__ */
|
|
264
|
+
/* @__PURE__ */ jsx11(entity_component_list_default, { entity }),
|
|
265
|
+
/* @__PURE__ */ jsx11(entity_proxy_list_default, { entity }),
|
|
266
|
+
/* @__PURE__ */ jsx11(entity_subscription_list_default, { entity })
|
|
325
267
|
] })
|
|
326
268
|
] });
|
|
327
269
|
}
|
|
328
270
|
var entity_layout_default = EntityLayout;
|
|
329
271
|
|
|
330
272
|
// src/nodes/node-entity.tsx
|
|
331
|
-
import { jsx as
|
|
273
|
+
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
332
274
|
function EntityNode({ id, data, selected, type }) {
|
|
333
|
-
const { entityRepository } =
|
|
334
|
-
const entity =
|
|
335
|
-
return /* @__PURE__ */
|
|
275
|
+
const { entityRepository } = useContext4(EcsFlowContext);
|
|
276
|
+
const entity = useMemo5(() => entityRepository.get(data.entity), [data.entity]);
|
|
277
|
+
return /* @__PURE__ */ jsx12(
|
|
336
278
|
NodeContainer2,
|
|
337
279
|
{
|
|
338
280
|
id,
|
|
339
281
|
selected,
|
|
340
282
|
data,
|
|
341
|
-
title: /* @__PURE__ */
|
|
283
|
+
title: /* @__PURE__ */ jsx12(Badge9, { fullWidth: true, variant: "transparent", children: /* @__PURE__ */ jsx12(formatter_camel_case_default, { value: entity.myProxy.entityType }) }),
|
|
342
284
|
type,
|
|
343
|
-
children: /* @__PURE__ */
|
|
285
|
+
children: /* @__PURE__ */ jsx12(entity_layout_default, { entity })
|
|
344
286
|
}
|
|
345
287
|
);
|
|
346
288
|
}
|
|
347
289
|
var node_entity_default = EntityNode;
|
|
348
290
|
|
|
349
291
|
// src/templates/template-entity-node.ts
|
|
350
|
-
import { IDGenerator } from "@awesome-flow/core/utils";
|
|
351
292
|
import { Position } from "@xyflow/react";
|
|
352
293
|
|
|
353
|
-
// src/abstract/
|
|
354
|
-
var
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
})(EcsHandleDataType || {});
|
|
294
|
+
// src/abstract/templates.ts
|
|
295
|
+
var EcsTemplateGroup = /* @__PURE__ */ ((EcsTemplateGroup2) => {
|
|
296
|
+
EcsTemplateGroup2["ecs"] = "ECS";
|
|
297
|
+
return EcsTemplateGroup2;
|
|
298
|
+
})(EcsTemplateGroup || {});
|
|
359
299
|
|
|
360
300
|
// src/templates/template-entity-node.ts
|
|
361
301
|
var EntityNodeTemplate = class {
|
|
362
|
-
|
|
363
|
-
|
|
302
|
+
template = {
|
|
303
|
+
type: "entity-node" /* entity */,
|
|
304
|
+
group: "ECS" /* ecs */,
|
|
305
|
+
data: {
|
|
364
306
|
title: "Entity",
|
|
365
307
|
entity: null
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
connection: "source",
|
|
383
|
-
disabled: true
|
|
384
|
-
}
|
|
385
|
-
]
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
isHandleAllowed() {
|
|
389
|
-
return false;
|
|
390
|
-
}
|
|
391
|
-
getHandleAllowedDataType() {
|
|
392
|
-
return 1 /* proxy */;
|
|
393
|
-
}
|
|
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
|
+
};
|
|
394
324
|
};
|
|
395
325
|
|
|
396
326
|
// src/templates/template-systems-module.ts
|
|
397
|
-
import { IDGenerator as IDGenerator2 } from "@awesome-flow/core/utils";
|
|
398
327
|
import { Position as Position2 } from "@xyflow/react";
|
|
399
328
|
var SystemsModuleNodeTemplate = class {
|
|
400
|
-
|
|
401
|
-
|
|
329
|
+
template = {
|
|
330
|
+
type: "systems-module-node" /* systemsModule */,
|
|
331
|
+
group: "ECS" /* ecs */,
|
|
332
|
+
data: {
|
|
402
333
|
title: "Systems Module",
|
|
403
|
-
entityType: null
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
-
}
|
|
334
|
+
entityType: null
|
|
335
|
+
},
|
|
336
|
+
handles: [
|
|
337
|
+
{
|
|
338
|
+
dataType: "module" /* module */,
|
|
339
|
+
position: Position2.Left,
|
|
340
|
+
connection: "target",
|
|
341
|
+
disabled: true
|
|
342
|
+
}
|
|
343
|
+
]
|
|
344
|
+
};
|
|
428
345
|
};
|
|
429
346
|
|
|
430
347
|
// src/abstract/node-types.ts
|
|
@@ -442,14 +359,79 @@ var ecsNodeTemplates = {
|
|
|
442
359
|
["systems-module-node" /* systemsModule */]: new SystemsModuleNodeTemplate()
|
|
443
360
|
};
|
|
444
361
|
|
|
362
|
+
// src/flow/flow-ecs-state.tsx
|
|
363
|
+
import { useEffect as useEffect7, useState as useState4, memo as memo9 } from "react";
|
|
364
|
+
|
|
365
|
+
// src/flow/flow-ecs-auto-layout.tsx
|
|
366
|
+
import { useFlowStore } from "@awesome-flow/core/hooks";
|
|
367
|
+
import Dagre from "@dagrejs/dagre";
|
|
368
|
+
import { useReactFlow } from "@xyflow/react";
|
|
369
|
+
import { useCallback, useContext as useContext5, useEffect as useEffect2, useMemo as useMemo6, useState as useState2 } from "react";
|
|
370
|
+
import { Fragment as Fragment4, jsx as jsx13 } from "react/jsx-runtime";
|
|
371
|
+
function FlowEcsAutoLayout() {
|
|
372
|
+
const [needsLayout, setNeedsLayout] = useState2(false);
|
|
373
|
+
const { ecsFlowRepository } = useContext5(EcsFlowContext);
|
|
374
|
+
useEffect2(() => {
|
|
375
|
+
setNeedsLayout(true);
|
|
376
|
+
}, [ecsFlowRepository.sizeNodes]);
|
|
377
|
+
const { getNodes, getEdges } = useReactFlow();
|
|
378
|
+
const setNodes = useFlowStore((state) => state.setNodes);
|
|
379
|
+
const graph = useMemo6(() => new Dagre.graphlib.Graph().setDefaultEdgeLabel(() => ({})), []);
|
|
380
|
+
const getLayoutElements = useCallback(
|
|
381
|
+
(nodes, edges, options) => {
|
|
382
|
+
graph.setGraph(options);
|
|
383
|
+
edges.forEach((edge) => graph.setEdge(edge.source, edge.target));
|
|
384
|
+
nodes.forEach((node) => {
|
|
385
|
+
if (node.measured) {
|
|
386
|
+
graph.setNode(node.id, {
|
|
387
|
+
width: node.measured.width,
|
|
388
|
+
height: node.measured.height
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
Dagre.layout(graph);
|
|
393
|
+
return {
|
|
394
|
+
nodes: nodes.map((node) => {
|
|
395
|
+
const graphNode = graph.node(node.id);
|
|
396
|
+
if (graphNode) {
|
|
397
|
+
return { ...node, position: { x: graphNode.x, y: graphNode.y } };
|
|
398
|
+
}
|
|
399
|
+
return node;
|
|
400
|
+
}),
|
|
401
|
+
edges
|
|
402
|
+
};
|
|
403
|
+
},
|
|
404
|
+
[graph]
|
|
405
|
+
);
|
|
406
|
+
useEffect2(() => {
|
|
407
|
+
if (needsLayout) {
|
|
408
|
+
const storeNodes = getNodes();
|
|
409
|
+
if (storeNodes?.length && !storeNodes.some((n) => !n.measured?.width || !n.measured?.height)) {
|
|
410
|
+
const edges = getEdges();
|
|
411
|
+
const layout = getLayoutElements(storeNodes, edges, {
|
|
412
|
+
rankdir: "LR"
|
|
413
|
+
});
|
|
414
|
+
setNodes(layout.nodes);
|
|
415
|
+
setNeedsLayout(false);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
return /* @__PURE__ */ jsx13(Fragment4, {});
|
|
420
|
+
}
|
|
421
|
+
var flow_ecs_auto_layout_default = FlowEcsAutoLayout;
|
|
422
|
+
|
|
423
|
+
// src/flow/flow-ecs-entities.tsx
|
|
424
|
+
import { FlowContext } from "@awesome-flow/core/abstract";
|
|
425
|
+
import { useContext as useContext8, useEffect as useEffect5, useState as useState3 } from "react";
|
|
426
|
+
import { useFlowStore as useFlowStore4 } from "@awesome-flow/core/hooks";
|
|
427
|
+
|
|
445
428
|
// src/flow/flow-ecs-edge-proxies.tsx
|
|
446
429
|
import { useContext as useContext6, useEffect as useEffect3 } from "react";
|
|
447
|
-
import {
|
|
430
|
+
import { useFlowStore as useFlowStore2 } from "@awesome-flow/core/hooks";
|
|
448
431
|
import { Fragment as Fragment5, jsx as jsx14 } from "react/jsx-runtime";
|
|
449
432
|
function FlowEcsEdgeProxies(props) {
|
|
450
433
|
const { nodesToConnect } = props;
|
|
451
|
-
const
|
|
452
|
-
const onConnect = context.useFlowStore((state) => state.onConnect);
|
|
434
|
+
const onConnect = useFlowStore2((state) => state.onConnect);
|
|
453
435
|
const { ecsFlowRepository, entityRepository } = useContext6(EcsFlowContext);
|
|
454
436
|
useEffect3(() => {
|
|
455
437
|
for (const node of nodesToConnect) {
|
|
@@ -477,12 +459,11 @@ var flow_ecs_edge_proxies_default = FlowEcsEdgeProxies;
|
|
|
477
459
|
|
|
478
460
|
// src/flow/flow-ecs-edge-modules.tsx
|
|
479
461
|
import { useContext as useContext7, useEffect as useEffect4 } from "react";
|
|
480
|
-
import {
|
|
462
|
+
import { useFlowStore as useFlowStore3 } from "@awesome-flow/core/hooks";
|
|
481
463
|
import { Fragment as Fragment6, jsx as jsx15 } from "react/jsx-runtime";
|
|
482
464
|
function FlowEcsEdgeModules(props) {
|
|
483
465
|
const { nodesToConnect } = props;
|
|
484
|
-
const
|
|
485
|
-
const onConnect = context.useFlowStore((state) => state.onConnect);
|
|
466
|
+
const onConnect = useFlowStore3((state) => state.onConnect);
|
|
486
467
|
const { ecsFlowRepository, entityRepository } = useContext7(EcsFlowContext);
|
|
487
468
|
useEffect4(() => {
|
|
488
469
|
for (const node of nodesToConnect) {
|
|
@@ -507,10 +488,10 @@ var flow_ecs_edge_modules_default = FlowEcsEdgeModules;
|
|
|
507
488
|
// src/flow/flow-ecs-entities.tsx
|
|
508
489
|
import { Fragment as Fragment7, jsx as jsx16, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
509
490
|
function FlowEcsEntities() {
|
|
510
|
-
const
|
|
511
|
-
const addNodes =
|
|
491
|
+
const { nodeFactory } = useContext8(FlowContext);
|
|
492
|
+
const addNodes = useFlowStore4((state) => state.addNodes);
|
|
512
493
|
const { ecsFlowRepository, entityRepository } = useContext8(EcsFlowContext);
|
|
513
|
-
const [entityNodes, setEntityNodes] =
|
|
494
|
+
const [entityNodes, setEntityNodes] = useState3([]);
|
|
514
495
|
useEffect5(() => {
|
|
515
496
|
const entities = entityRepository.listAll();
|
|
516
497
|
const nodes = [];
|
|
@@ -518,7 +499,7 @@ function FlowEcsEntities() {
|
|
|
518
499
|
if (ecsFlowRepository.getEntityNode(entity.myProxy)) {
|
|
519
500
|
continue;
|
|
520
501
|
}
|
|
521
|
-
const node =
|
|
502
|
+
const node = nodeFactory.createNodeFromType("entity-node" /* entity */);
|
|
522
503
|
node.data.entity = entity.myProxy;
|
|
523
504
|
node.position = { x: 0, y: 0 };
|
|
524
505
|
ecsFlowRepository.addEntityNode(node);
|
|
@@ -536,11 +517,12 @@ var flow_ecs_entities_default = FlowEcsEntities;
|
|
|
536
517
|
|
|
537
518
|
// src/flow/flow-ecs-modules.tsx
|
|
538
519
|
import { useEffect as useEffect6, useContext as useContext9 } from "react";
|
|
539
|
-
import { FlowContext as
|
|
520
|
+
import { FlowContext as FlowContext2 } from "@awesome-flow/core/abstract";
|
|
521
|
+
import { useFlowStore as useFlowStore5 } from "@awesome-flow/core/hooks";
|
|
540
522
|
import { Fragment as Fragment8, jsx as jsx17 } from "react/jsx-runtime";
|
|
541
523
|
function FlowEcsModules() {
|
|
542
|
-
const
|
|
543
|
-
const addNodes =
|
|
524
|
+
const { nodeFactory } = useContext9(FlowContext2);
|
|
525
|
+
const addNodes = useFlowStore5((state) => state.addNodes);
|
|
544
526
|
const { ecsFlowRepository, systemsModuleRepository } = useContext9(EcsFlowContext);
|
|
545
527
|
useEffect6(() => {
|
|
546
528
|
const modules = Array.from(systemsModuleRepository.list()).filter((m) => !!m);
|
|
@@ -550,9 +532,7 @@ function FlowEcsModules() {
|
|
|
550
532
|
if (ecsFlowRepository.getSystemModuleNode(element)) {
|
|
551
533
|
continue;
|
|
552
534
|
}
|
|
553
|
-
const node =
|
|
554
|
-
"systems-module-node" /* systemsModule */
|
|
555
|
-
);
|
|
535
|
+
const node = nodeFactory.createNodeFromType("systems-module-node" /* systemsModule */);
|
|
556
536
|
node.data.entityType = element;
|
|
557
537
|
node.position = { x: 0, y: 0 };
|
|
558
538
|
ecsFlowRepository.addSystemModuleNode(node);
|
|
@@ -569,12 +549,7 @@ var flow_ecs_modules_default = FlowEcsModules;
|
|
|
569
549
|
// src/flow/flow-ecs-state.tsx
|
|
570
550
|
import { Fragment as Fragment9, jsx as jsx18, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
571
551
|
function FlowEcsState(props) {
|
|
572
|
-
const [, setUpdates] =
|
|
573
|
-
const [needsLayout, setNeedsLayout] = useState3(false);
|
|
574
|
-
const { ecsFlowRepository } = useContext10(EcsFlowContext);
|
|
575
|
-
useEffect7(() => {
|
|
576
|
-
setNeedsLayout(true);
|
|
577
|
-
}, [ecsFlowRepository.sizeNodes]);
|
|
552
|
+
const [, setUpdates] = useState4(0);
|
|
578
553
|
useEffect7(() => {
|
|
579
554
|
setInterval(() => {
|
|
580
555
|
setUpdates((updates) => updates + 1);
|
|
@@ -583,15 +558,16 @@ function FlowEcsState(props) {
|
|
|
583
558
|
return /* @__PURE__ */ jsxs10(Fragment9, { children: [
|
|
584
559
|
props.showSystemModules && /* @__PURE__ */ jsx18(flow_ecs_modules_default, {}),
|
|
585
560
|
props.showEntities && /* @__PURE__ */ jsx18(flow_ecs_entities_default, {}),
|
|
586
|
-
props.autoLayout && /* @__PURE__ */ jsx18(flow_ecs_auto_layout_default, {
|
|
561
|
+
props.autoLayout && /* @__PURE__ */ jsx18(flow_ecs_auto_layout_default, {})
|
|
587
562
|
] });
|
|
588
563
|
}
|
|
589
|
-
var flow_ecs_state_default = FlowEcsState;
|
|
564
|
+
var flow_ecs_state_default = memo9(FlowEcsState);
|
|
590
565
|
export {
|
|
591
566
|
EcsFlowContext,
|
|
592
567
|
EcsFlowRepository,
|
|
593
568
|
EcsHandleDataType,
|
|
594
569
|
EcsNodeType,
|
|
570
|
+
EcsTemplateGroup,
|
|
595
571
|
node_entity_default as EntityNode,
|
|
596
572
|
EntityNodeTemplate,
|
|
597
573
|
flow_ecs_state_default as FlowEcsState,
|