@woosh/meep-engine 2.46.28 → 2.46.30
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/editor/Editor.js +793 -0
- package/editor/SelectionVisualizer.js +148 -0
- package/editor/actions/concrete/ActionUpdateTexture.js +21 -0
- package/editor/actions/concrete/ArrayCopyAction.js +39 -0
- package/editor/actions/concrete/ComponentAddAction.js +47 -0
- package/editor/actions/concrete/ComponentRemoveAction.js +38 -0
- package/editor/actions/concrete/EntityCreateAction.js +47 -0
- package/editor/actions/concrete/EntityRemoveAction.js +51 -0
- package/editor/actions/concrete/ModifyPatchSampler2DAction.js +118 -0
- package/editor/actions/concrete/ModifyPatchSampler2DAction.spec.js +30 -0
- package/editor/actions/concrete/ModifyPatchTextureArray2DAction.js +182 -0
- package/editor/actions/concrete/PaintTerrainOverlayAction.js +45 -0
- package/editor/actions/concrete/PatchTerrainHeightAction.js +67 -0
- package/editor/actions/concrete/PatchTerrainTextureAction.js +152 -0
- package/editor/actions/concrete/SelectionAddAction.js +36 -0
- package/editor/actions/concrete/SelectionClearAction.js +22 -0
- package/editor/actions/concrete/SelectionRemoveAction.js +30 -0
- package/editor/actions/concrete/TransformModifyAction.js +46 -0
- package/editor/actions/concrete/WriteGridValueAction.js +46 -0
- package/editor/ecs/EditorEntity.js +12 -0
- package/editor/ecs/EditorEntitySystem.js +14 -0
- package/editor/ecs/component/FieldDescriptor.js +34 -0
- package/editor/ecs/component/FieldValueAdapter.js +20 -0
- package/editor/ecs/component/TypeEditor.js +33 -0
- package/editor/ecs/component/TypeSchema.d.ts +38 -0
- package/editor/ecs/component/createFieldEditor.js +92 -0
- package/editor/ecs/component/createObjectEditor.js +361 -0
- package/editor/ecs/component/editors/ColorEditor.js +39 -0
- package/editor/ecs/component/editors/HTMLElementEditor.js +17 -0
- package/editor/ecs/component/editors/ImagePathEditor.js +82 -0
- package/editor/ecs/component/editors/LargeStrongEditor.js +107 -0
- package/editor/ecs/component/editors/NumericIntervalEditor.js +86 -0
- package/editor/ecs/component/editors/ObservedBooleanEditor.js +13 -0
- package/editor/ecs/component/editors/ObservedEnumEditor.js +32 -0
- package/editor/ecs/component/editors/ObservedIntegerEditor.js +43 -0
- package/editor/ecs/component/editors/ObservedStringEditor.js +51 -0
- package/editor/ecs/component/editors/Sampler2DEditor.js +221 -0
- package/editor/ecs/component/editors/collection/ListEditor.js +83 -0
- package/editor/ecs/component/editors/common/BitFlagsEditor.js +80 -0
- package/editor/ecs/component/editors/common/EnumEditor.js +41 -0
- package/editor/ecs/component/editors/common/makeV3_editor.js +85 -0
- package/editor/ecs/component/editors/common/noEditor.js +9 -0
- package/editor/ecs/component/editors/ecs/GridObstacleEditor.js +17 -0
- package/editor/ecs/component/editors/ecs/MinimapMarkerEditor.js +16 -0
- package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.js +225 -0
- package/editor/ecs/component/editors/ecs/ParameterTrackEditor.js +17 -0
- package/editor/ecs/component/editors/ecs/ParameterTrackSetEditor.js +18 -0
- package/editor/ecs/component/editors/ecs/ParticleEmitterEditor.js +58 -0
- package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.js +58 -0
- package/editor/ecs/component/editors/ecs/SimulationStepDefinitionEditor.js +21 -0
- package/editor/ecs/component/editors/ecs/Trail2DEditor.js +33 -0
- package/editor/ecs/component/editors/ecs/TransformEditor.js +23 -0
- package/editor/ecs/component/editors/ecs/terrain/SplatMappingEditor.js +21 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +95 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainLayerEditor.js +18 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainLayersEditor.js +22 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainOverlayEditor.js +20 -0
- package/editor/ecs/component/editors/geom/QuaternionEditor.js +63 -0
- package/editor/ecs/component/editors/geom/Vector1Editor.js +57 -0
- package/editor/ecs/component/editors/geom/Vector2Editor.js +11 -0
- package/editor/ecs/component/editors/geom/Vector3Editor.js +13 -0
- package/editor/ecs/component/editors/geom/Vector4Editor.js +12 -0
- package/editor/ecs/component/editors/primitive/ArrayEditor.js +46 -0
- package/editor/ecs/component/editors/primitive/BooleanEditor.js +27 -0
- package/editor/ecs/component/editors/primitive/FunctionEditor.js +29 -0
- package/editor/ecs/component/editors/primitive/NumberEditor.js +60 -0
- package/editor/ecs/component/editors/primitive/ObjectEditor.js +12 -0
- package/editor/ecs/component/editors/primitive/StringEditor.js +31 -0
- package/editor/ecs/component/editors/three/BufferGeometryEditor.js +28 -0
- package/editor/ecs/component/editors/three/MaterialEditor.js +27 -0
- package/editor/ecs/component/editors/three/MeshEditor.js +35 -0
- package/editor/ecs/component/editors/three/TextureEditor.js +112 -0
- package/editor/ecs/component/findNearestRegisteredType.js +59 -0
- package/editor/ecs/component/prototypeObjectEditor.js +379 -0
- package/editor/enableEditor.js +85 -0
- package/editor/library/MeshLibrary.js +33 -0
- package/editor/process/DisableGameUIProcess.js +43 -0
- package/editor/process/EditorProcess.js +35 -0
- package/editor/process/ObstacleGridDisplayProcess.js +120 -0
- package/editor/process/ProcessEngine.js +123 -0
- package/editor/process/SymbolicDisplayProcess.js +132 -0
- package/editor/process/symbolic/ComponentSymbolicDisplay.js +34 -0
- package/editor/process/symbolic/SymbolicDisplayInternalAPI.js +159 -0
- package/editor/process/symbolic/buildThreeJSHelperEntity.js +36 -0
- package/editor/process/symbolic/make3DSymbolicDisplay.js +91 -0
- package/editor/process/symbolic/makeCameraSymbolicDisplay.js +32 -0
- package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +176 -0
- package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
- package/editor/process/symbolic/makeHelperSphereGeometry.js +73 -0
- package/editor/process/symbolic/makeLightSymbolicDisplay.js +77 -0
- package/editor/process/symbolic/makeParticleEmitterSymbolicDisplay.js +146 -0
- package/editor/process/symbolic/makePathSymbolicDisplay.js +105 -0
- package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +74 -0
- package/editor/process/symbolic/makeSocketsSymbolicDisplay.js +153 -0
- package/editor/process/symbolic/makeSolidArrowGeometry.js +391 -0
- package/editor/process/symbolic/makeSoundEmitterSymbolicDisplay.js +89 -0
- package/editor/process/symbolic/makeStoryTriggerSetAreaDisplay.js +114 -0
- package/editor/process/symbolic/synchronizeTransform.js +50 -0
- package/editor/tools/FoliagePaintTool.js +168 -0
- package/editor/tools/GridPaintTool.js +247 -0
- package/editor/tools/SelectionTool.js +407 -0
- package/editor/tools/TopDownCameraControlTool.js +59 -0
- package/editor/tools/TransformTool.js +370 -0
- package/editor/tools/engine/Tool.js +121 -0
- package/editor/tools/engine/ToolEngine.js +193 -0
- package/editor/tools/engine/ToolState.js +9 -0
- package/editor/tools/engine/ToolStateMachine.js +53 -0
- package/editor/tools/paint/TerrainHeightPaintTool.js +297 -0
- package/editor/tools/paint/TerrainPaintTool.js +211 -0
- package/editor/tools/paint/TerrainTexturePaintTool.js +193 -0
- package/editor/tools/paint/prototypeTerrainEditor.js +135 -0
- package/editor/tools/v2/BlenderCameraOrientationGizmo.d.ts +50 -0
- package/editor/tools/v2/BlenderCameraOrientationGizmo.js +500 -0
- package/editor/tools/v2/TransformControls.d.ts +20 -0
- package/editor/tools/v2/TransformControls.js +1782 -0
- package/editor/tools/v2/prototypeTransformControls.js +92 -0
- package/editor/view/EditorView.js +462 -0
- package/editor/view/GridPickCoordinateView.js +88 -0
- package/editor/view/ecs/ComponentControlFactory.js +48 -0
- package/editor/view/ecs/ComponentControlView.js +214 -0
- package/editor/view/ecs/EntityEditor.js +258 -0
- package/editor/view/ecs/EntityList.js +258 -0
- package/editor/view/ecs/components/BlackboardController.js +50 -0
- package/editor/view/ecs/components/DatGuiController.js +216 -0
- package/editor/view/ecs/components/FogOfWarController.js +78 -0
- package/editor/view/ecs/components/FogOfWarRevealerController.js +44 -0
- package/editor/view/ecs/components/GeneratedArmyController.js +42 -0
- package/editor/view/ecs/components/GridObstacleController.js +72 -0
- package/editor/view/ecs/components/GridPositionController.js +40 -0
- package/editor/view/ecs/components/HeadsUpDisplayController.js +30 -0
- package/editor/view/ecs/components/HighlightController.js +47 -0
- package/editor/view/ecs/components/MeshController.js +125 -0
- package/editor/view/ecs/components/PathFollowerController.js +87 -0
- package/editor/view/ecs/components/TagController.js +80 -0
- package/editor/view/ecs/components/TerrainController.js +225 -0
- package/editor/view/ecs/components/TransformController.js +103 -0
- package/editor/view/ecs/components/UnitShopController.js +112 -0
- package/editor/view/ecs/components/army/ArmyController.js +130 -0
- package/editor/view/ecs/components/color/GaugeView.js +107 -0
- package/editor/view/ecs/components/common/AutoCanvasView.js +53 -0
- package/editor/view/ecs/components/common/LineView.js +17 -0
- package/editor/view/ecs/components/common/NumberController.js +112 -0
- package/editor/view/ecs/components/common/NumericIntervalController.js +64 -0
- package/editor/view/ecs/components/gui/GUIElementController.js +117 -0
- package/editor/view/ecs/components/items/ItemContainerController.js +132 -0
- package/editor/view/ecs/components/items/ItemContainerController.stories.js +50 -0
- package/editor/view/ecs/components/items/ItemController.js +52 -0
- package/editor/view/ecs/components/particles/ColorParameterLUTController.js +444 -0
- package/editor/view/ecs/components/particles/ParameterTrackController.js +51 -0
- package/editor/view/ecs/components/particles/ParticleEmitterController.js +213 -0
- package/editor/view/ecs/components/particles/ParticleLayerController.js +213 -0
- package/editor/view/ecs/components/particles/ScalarParameterLUTController.js +401 -0
- package/editor/view/ecs/components/sockets/AttachmentSocketsController.js +51 -0
- package/editor/view/ecs/components/sound/SoundEmitterController.js +137 -0
- package/editor/view/ecs/components/story/StoryTriggerSetController.js +214 -0
- package/editor/view/ecs/components/unit/AuraController.js +45 -0
- package/editor/view/library/MeshLibraryView.js +164 -0
- package/editor/view/node-graph/NodeGraphEditorView.js +170 -0
- package/editor/view/node-graph/NodeGraphView.js +453 -0
- package/editor/view/node-graph/NodeView.js +135 -0
- package/editor/view/node-graph/PortView.js +69 -0
- package/editor/view/process/ProcessView.js +63 -0
- package/editor/view/tools/ToolSettingsView.js +143 -0
- package/editor/view/tools/ToolView.js +58 -0
- package/package.json +2 -1
- package/src/core/bvh2/bvh3/EBBVHLeafProxy.js +6 -1
- package/src/core/geom/3d/aabb/aabb3_matrix4_project.js +1 -1
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.d.ts +9 -0
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +148 -9
- package/src/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +21 -1
- package/src/engine/graphics/render/forward_plus/LightManager.js +0 -60
- package/src/engine/graphics/render/forward_plus/LightRenderMetadata.js +1 -3
- package/src/engine/graphics/render/forward_plus/model/Decal.js +1 -1
- package/src/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.d.ts +0 -3
- package/src/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +0 -11
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import View from "../../../src/view/View.js";
|
|
2
|
+
import Signal from "../../../src/core/events/signal/Signal.js";
|
|
3
|
+
import dom from "../../../src/view/DOM.js";
|
|
4
|
+
import ObservedBoolean from "../../../src/core/model/ObservedBoolean.js";
|
|
5
|
+
import LabelView from "../../../src/view/common/LabelView.js";
|
|
6
|
+
import ButtonView from "../../../src/view/elements/button/ButtonView.js";
|
|
7
|
+
import EmptyView from "../../../src/view/elements/EmptyView.js";
|
|
8
|
+
import { downloadAsFile } from "../../../src/core/binary/ByteArrayTools.js";
|
|
9
|
+
|
|
10
|
+
export async function obtainClipBoard() {
|
|
11
|
+
if (navigator.clipboard === undefined) {
|
|
12
|
+
const queries = [{
|
|
13
|
+
name: "clipboard-read"
|
|
14
|
+
}, {
|
|
15
|
+
name: "clipboard-write"
|
|
16
|
+
}];
|
|
17
|
+
|
|
18
|
+
const permission_queries = queries.map(q => navigator.permissions.query(q));
|
|
19
|
+
|
|
20
|
+
const statuses = await Promise.all(permission_queries);
|
|
21
|
+
|
|
22
|
+
for (let i = 0; i < statuses.length; i++) {
|
|
23
|
+
const permissionStatus = statuses[i];
|
|
24
|
+
|
|
25
|
+
if (permissionStatus.state !== "granted") {
|
|
26
|
+
throw new Error(`Permission for query not granted (actual state = ${permissionStatus.state}). Query:${JSON.stringify(queries[i])}`)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return navigator.clipboard;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param {string} text
|
|
37
|
+
* @param {string} [data_name]
|
|
38
|
+
* @returns {Promise<void>}
|
|
39
|
+
*/
|
|
40
|
+
export async function safeClipboardWriteText(text, data_name = "data") {
|
|
41
|
+
|
|
42
|
+
return obtainClipBoard().then(
|
|
43
|
+
() => {
|
|
44
|
+
return navigator.clipboard.writeText(text);
|
|
45
|
+
},
|
|
46
|
+
() => {
|
|
47
|
+
// no clipboard available
|
|
48
|
+
console.log(`No clipboard available, downloading instead`);
|
|
49
|
+
downloadAsFile(text, `${data_name}.json`);
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function safeClipboardReadText() {
|
|
55
|
+
|
|
56
|
+
return obtainClipBoard().then(() => {
|
|
57
|
+
|
|
58
|
+
return navigator.clipboard.readText();
|
|
59
|
+
}, () => {
|
|
60
|
+
// clipboard not available
|
|
61
|
+
console.log(`No clipboard available, using a prompt instead`);
|
|
62
|
+
|
|
63
|
+
function clickElem(elem) {
|
|
64
|
+
// Thx user1601638 on Stack Overflow (6/6/2018 - https://stackoverflow.com/questions/13405129/javascript-create-and-save-file )
|
|
65
|
+
var eventMouse = document.createEvent("MouseEvents")
|
|
66
|
+
eventMouse.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
|
|
67
|
+
elem.dispatchEvent(eventMouse)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function openFile(func) {
|
|
71
|
+
const fileInput = document.createElement("input");
|
|
72
|
+
|
|
73
|
+
const readFile = function (e) {
|
|
74
|
+
var file = e.target.files[0];
|
|
75
|
+
if (!file) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
var reader = new FileReader();
|
|
79
|
+
reader.onload = function (e) {
|
|
80
|
+
var contents = e.target.result;
|
|
81
|
+
fileInput.func(contents)
|
|
82
|
+
document.body.removeChild(fileInput)
|
|
83
|
+
}
|
|
84
|
+
reader.readAsText(file)
|
|
85
|
+
}
|
|
86
|
+
fileInput.type = 'file'
|
|
87
|
+
fileInput.style.display = 'none'
|
|
88
|
+
fileInput.onchange = readFile
|
|
89
|
+
fileInput.func = func
|
|
90
|
+
document.body.appendChild(fileInput)
|
|
91
|
+
clickElem(fileInput)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
openFile(resolve);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @template T
|
|
105
|
+
*/
|
|
106
|
+
export class ComponentControlView extends View {
|
|
107
|
+
/**
|
|
108
|
+
* @template T
|
|
109
|
+
* @param {number} entity
|
|
110
|
+
* @param {T} component
|
|
111
|
+
* @param {EntityManager} entityManager
|
|
112
|
+
* @param {View} vController
|
|
113
|
+
* @param engine
|
|
114
|
+
* @constructor
|
|
115
|
+
*/
|
|
116
|
+
constructor(entity, component, entityManager, vController, engine) {
|
|
117
|
+
super();
|
|
118
|
+
|
|
119
|
+
this.signal = {
|
|
120
|
+
remove: new Signal()
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const dRoot = dom('div');
|
|
124
|
+
|
|
125
|
+
dRoot.addClass('entity-editor-component-control-view');
|
|
126
|
+
|
|
127
|
+
this.el = dRoot.el;
|
|
128
|
+
|
|
129
|
+
const folded = this.folded = new ObservedBoolean(false);
|
|
130
|
+
|
|
131
|
+
const componentType = component.constructor;
|
|
132
|
+
const typeName = componentType.typeName;
|
|
133
|
+
|
|
134
|
+
const vComponentName = new LabelView(typeName);
|
|
135
|
+
|
|
136
|
+
const bFold = new ButtonView({
|
|
137
|
+
classList: ['fold-toggle'],
|
|
138
|
+
action() {
|
|
139
|
+
folded.invert();
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const bRemove = new ButtonView({
|
|
144
|
+
classList: ['remove'],
|
|
145
|
+
action() {
|
|
146
|
+
self.signal.remove.dispatch();
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const bCopy = new ButtonView({
|
|
151
|
+
classList: ['copy'],
|
|
152
|
+
async action() {
|
|
153
|
+
const json = component.toJSON();
|
|
154
|
+
|
|
155
|
+
const data = JSON.stringify({
|
|
156
|
+
type: typeName,
|
|
157
|
+
data: json
|
|
158
|
+
}, 3, 3);
|
|
159
|
+
|
|
160
|
+
safeClipboardWriteText(data, typeName).then(() => {
|
|
161
|
+
console.log(`${entity}:${typeName} dumped`);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
bCopy.setClass('disabled', component.hasOwnProperty('toJSON') && typeof component.toJSON !== "function");
|
|
167
|
+
|
|
168
|
+
const bPaste = new ButtonView({
|
|
169
|
+
classList: ['paste'],
|
|
170
|
+
async action() {
|
|
171
|
+
|
|
172
|
+
safeClipboardReadText().then(text => {
|
|
173
|
+
const json = JSON.parse(text);
|
|
174
|
+
|
|
175
|
+
if (json.type !== typeName) {
|
|
176
|
+
throw new Error(`Component type(=${json.type}) in clipboard does not match current component type(=${typeName})`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
//get system
|
|
180
|
+
component.fromJSON(json.data, engine);
|
|
181
|
+
|
|
182
|
+
console.log(`${entity}:${typeName} pasted from clip`);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
bPaste.setClass('disabled', component.hasOwnProperty('fromJSON') && typeof component.fromJSON !== "function");
|
|
189
|
+
|
|
190
|
+
const vTitleBar = new EmptyView();
|
|
191
|
+
dom(vTitleBar.el).addClass('title-bar');
|
|
192
|
+
|
|
193
|
+
vTitleBar.addChild(vComponentName);
|
|
194
|
+
vTitleBar.addChild(bCopy);
|
|
195
|
+
vTitleBar.addChild(bPaste);
|
|
196
|
+
vTitleBar.addChild(bFold);
|
|
197
|
+
vTitleBar.addChild(bRemove);
|
|
198
|
+
|
|
199
|
+
this.addChild(vTitleBar);
|
|
200
|
+
|
|
201
|
+
const self = this;
|
|
202
|
+
|
|
203
|
+
folded.process(function (v) {
|
|
204
|
+
|
|
205
|
+
dRoot.setClass('folded', v);
|
|
206
|
+
|
|
207
|
+
if (v) {
|
|
208
|
+
self.removeChild(vController);
|
|
209
|
+
} else {
|
|
210
|
+
self.addChild(vController);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Alex on 15/01/2017.
|
|
3
|
+
*/
|
|
4
|
+
import View from "../../../src/view/View.js";
|
|
5
|
+
import dom from "../../../src/view/DOM.js";
|
|
6
|
+
|
|
7
|
+
import List from '../../../src/core/collection/list/List.js';
|
|
8
|
+
import ObservedValue from '../../../src/core/model/ObservedValue.js';
|
|
9
|
+
import LabelView from '../../../src/view/common/LabelView.js';
|
|
10
|
+
import ButtonView from '../../../src/view/elements/button/ButtonView.js';
|
|
11
|
+
import DropDownSelectionView from '../../../src/view/elements/DropDownSelectionView.js';
|
|
12
|
+
import EmptyView from "../../../src/view/elements/EmptyView.js";
|
|
13
|
+
import { EntityManager, EventType } from "../../../src/engine/ecs/EntityManager.js";
|
|
14
|
+
import ComponentRemoveAction from "../../actions/concrete/ComponentRemoveAction.js";
|
|
15
|
+
import ComponentAddAction from "../../actions/concrete/ComponentAddAction.js";
|
|
16
|
+
import { LineView } from "./components/common/LineView.js";
|
|
17
|
+
import { ComponentControlView } from "./ComponentControlView.js";
|
|
18
|
+
import { buildObjectEditorFromRegistry } from "../../ecs/component/createObjectEditor.js";
|
|
19
|
+
import { isDefined } from "../../../src/core/process/matcher/Matchers.js";
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class EntityEditor extends View {
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param {ComponentControlFactory} componentControlFactory
|
|
26
|
+
* @param {Editor} editor
|
|
27
|
+
* @constructor
|
|
28
|
+
*/
|
|
29
|
+
constructor(componentControlFactory, editor) {
|
|
30
|
+
|
|
31
|
+
super();
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
const dRoot = dom('div');
|
|
35
|
+
|
|
36
|
+
dRoot.addClass('entity-editor-view');
|
|
37
|
+
|
|
38
|
+
this.el = dRoot.el;
|
|
39
|
+
const self = this;
|
|
40
|
+
|
|
41
|
+
this.model = new ObservedValue(null);
|
|
42
|
+
/**
|
|
43
|
+
* @type {ObservedValue<EntityManager>}
|
|
44
|
+
*/
|
|
45
|
+
this.entityManager = new ObservedValue(null);
|
|
46
|
+
this.components = new List();
|
|
47
|
+
|
|
48
|
+
const vComponentList = new EmptyView({ classList: ['component-list'] });
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @type {Map<any, TypeEditor>}
|
|
53
|
+
*/
|
|
54
|
+
const registry = editor.type_editor_registry;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @type {Map<Object, ComponentControlView>}
|
|
59
|
+
*/
|
|
60
|
+
this.componentControllers = new Map();
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @returns {EntityComponentDataset}
|
|
65
|
+
*/
|
|
66
|
+
function get_dataset() {
|
|
67
|
+
return self.entityManager.get().dataset;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function addComponent(event) {
|
|
71
|
+
if (event.instance === undefined) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
self.components.add(event.instance);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function removeComponent(event) {
|
|
79
|
+
// console.log('removeComponent.Event',event, self.components);
|
|
80
|
+
|
|
81
|
+
if (event.instance === undefined) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
self.components.removeOneOf(event.instance);
|
|
87
|
+
} catch (e) {
|
|
88
|
+
console.error(e);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function watchEntity(entity) {
|
|
93
|
+
|
|
94
|
+
const dataset = get_dataset();
|
|
95
|
+
|
|
96
|
+
if (!dataset.entityExists(entity)) {
|
|
97
|
+
//doesn't exist, nothing to do
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
dataset.addEntityEventListener(entity, EventType.ComponentAdded, addComponent);
|
|
102
|
+
dataset.addEntityEventListener(entity, EventType.ComponentRemoved, removeComponent);
|
|
103
|
+
dataset.addEntityEventListener(entity, EventType.EntityRemoved, unwatchEntity);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function unwatchEntity(entity) {
|
|
107
|
+
|
|
108
|
+
const dataset = get_dataset();
|
|
109
|
+
|
|
110
|
+
if (!dataset.entityExists(entity)) {
|
|
111
|
+
//doesn't exist, nothing to do
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
dataset.removeEntityEventListener(entity, EventType.ComponentAdded, addComponent);
|
|
116
|
+
dataset.removeEntityEventListener(entity, EventType.ComponentRemoved, removeComponent);
|
|
117
|
+
dataset.removeEntityEventListener(entity, EventType.EntityRemoved, unwatchEntity);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
this.model.onChanged.add(function (entity, oldEntity) {
|
|
121
|
+
if (oldEntity !== undefined && oldEntity !== null) {
|
|
122
|
+
unwatchEntity(oldEntity);
|
|
123
|
+
}
|
|
124
|
+
watchEntity(entity);
|
|
125
|
+
|
|
126
|
+
self.components.reset();
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
*
|
|
131
|
+
* @type {EntityComponentDataset}
|
|
132
|
+
*/
|
|
133
|
+
const dataset = get_dataset();
|
|
134
|
+
|
|
135
|
+
unattachedTypes.reset();
|
|
136
|
+
unattachedTypes.addAll(dataset.getComponentTypeMap().map(a => a.typeName).filter(isDefined));
|
|
137
|
+
|
|
138
|
+
const components = dataset.getAllComponents(entity);
|
|
139
|
+
components.forEach(function (c) {
|
|
140
|
+
self.components.add(c);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
this.vLabelEntity = new LabelView(this.model, {
|
|
145
|
+
classList: ['id', 'label']
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
this.addChild(vComponentList);
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
const unattachedTypes = new List();
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @template T
|
|
155
|
+
* @param {T} component
|
|
156
|
+
*/
|
|
157
|
+
function handleComponentAdded(component) {
|
|
158
|
+
let view;
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
view = buildObjectEditorFromRegistry(component, registry);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
view = new LabelView(`ERROR: ${e.message}\n${e.stack}`);
|
|
164
|
+
|
|
165
|
+
console.warn('Failed to build editor', e);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (!view) {
|
|
169
|
+
view = new LabelView('EMPTY');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
*
|
|
174
|
+
* @type {EntityManager}
|
|
175
|
+
*/
|
|
176
|
+
const entityManager = self.entityManager.getValue();
|
|
177
|
+
|
|
178
|
+
const entityId = self.model.getValue();
|
|
179
|
+
|
|
180
|
+
const vBody = new EmptyView({
|
|
181
|
+
classList: ['body']
|
|
182
|
+
});
|
|
183
|
+
vBody.addChild(view);
|
|
184
|
+
|
|
185
|
+
const controlView = new ComponentControlView(entityId, component, entityManager, vBody, editor.engine);
|
|
186
|
+
|
|
187
|
+
const Klass = component.constructor;
|
|
188
|
+
|
|
189
|
+
controlView.signal.remove.add(function () {
|
|
190
|
+
|
|
191
|
+
editor.actions.mark('Remove Component');
|
|
192
|
+
editor.actions.do(new ComponentRemoveAction(entityId, Klass));
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
vComponentList.addChild(controlView);
|
|
197
|
+
self.componentControllers.set(component, controlView);
|
|
198
|
+
|
|
199
|
+
unattachedTypes.removeOneOf(Klass.typeName);
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function handleComponentRemoved(c) {
|
|
204
|
+
// console.log("handleComponentRemoved",c);
|
|
205
|
+
if (self.componentControllers.has(c)) {
|
|
206
|
+
const controlView = self.componentControllers.get(c);
|
|
207
|
+
self.componentControllers.delete(c);
|
|
208
|
+
vComponentList.removeChild(controlView);
|
|
209
|
+
|
|
210
|
+
const Klass = c.constructor;
|
|
211
|
+
|
|
212
|
+
unattachedTypes.add(Klass.typeName);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
this.components.on.added.add(handleComponentAdded);
|
|
217
|
+
this.components.on.removed.add(handleComponentRemoved);
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
const typeSelection = new DropDownSelectionView(unattachedTypes);
|
|
221
|
+
|
|
222
|
+
const buttonView = new ButtonView({
|
|
223
|
+
classList: ['add-component'],
|
|
224
|
+
name: "Add",
|
|
225
|
+
action: function () {
|
|
226
|
+
const selectedValue = typeSelection.getSelectedValue();
|
|
227
|
+
const em = self.entityManager.get();
|
|
228
|
+
const ComponentClass = em.getComponentClassByName(selectedValue);
|
|
229
|
+
const component = new ComponentClass();
|
|
230
|
+
|
|
231
|
+
const entityIndex = self.model.get();
|
|
232
|
+
|
|
233
|
+
editor.actions.mark('Add Component');
|
|
234
|
+
editor.actions.do(new ComponentAddAction(entityIndex, component));
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
this.addChild(new LineView({
|
|
239
|
+
elements: [this.vLabelEntity, buttonView, typeSelection],
|
|
240
|
+
classList: ['component-adder']
|
|
241
|
+
}));
|
|
242
|
+
|
|
243
|
+
this.handlers = {};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
link() {
|
|
247
|
+
super.link()
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
unlink() {
|
|
253
|
+
super.unlink();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
export default EntityEditor;
|