@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
package/editor/Editor.js
ADDED
|
@@ -0,0 +1,793 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Alex on 14/01/2017.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import List from '../src/core/collection/list/List.js';
|
|
7
|
+
import ToolEngine from './tools/engine/ToolEngine.js';
|
|
8
|
+
import EditorView from './view/EditorView.js';
|
|
9
|
+
import { ActionProcessor } from '../src/core/process/undo/ActionProcessor.js';
|
|
10
|
+
import { KeyCodes } from "../src/engine/input/devices/KeyCodes.js";
|
|
11
|
+
import EntityCreateAction from "./actions/concrete/EntityCreateAction.js";
|
|
12
|
+
import ComponentAddAction from "./actions/concrete/ComponentAddAction.js";
|
|
13
|
+
import SelectionClearAction from "./actions/concrete/SelectionClearAction.js";
|
|
14
|
+
import SelectionAddAction from "./actions/concrete/SelectionAddAction.js";
|
|
15
|
+
import EntityRemoveAction from "./actions/concrete/EntityRemoveAction.js";
|
|
16
|
+
import { SelectionVisualizer } from "./SelectionVisualizer.js";
|
|
17
|
+
import { ProcessEngine } from "./process/ProcessEngine.js";
|
|
18
|
+
import { MeshLibrary } from "./library/MeshLibrary.js";
|
|
19
|
+
import { TransformerMode } from "./tools/TransformTool.js";
|
|
20
|
+
import EntityBuilder from "../src/engine/ecs/EntityBuilder.js";
|
|
21
|
+
import { Camera } from "../src/engine/graphics/ecs/camera/Camera.js";
|
|
22
|
+
import EditorEntitySystem from "./ecs/EditorEntitySystem.js";
|
|
23
|
+
import EditorEntity from "./ecs/EditorEntity.js";
|
|
24
|
+
import TopDownCameraController from "../src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js";
|
|
25
|
+
import { Transform } from "../src/engine/ecs/transform/Transform.js";
|
|
26
|
+
import TopDownCameraControllerSystem, {
|
|
27
|
+
setCameraControllerFromTransform
|
|
28
|
+
} from "../src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
|
|
29
|
+
import { downloadAsFile } from "../src/core/binary/ByteArrayTools.js";
|
|
30
|
+
import BinaryBufferSerializer from "../src/engine/ecs/storage/BinaryBufferSerializer.js";
|
|
31
|
+
import { EncodingBinaryBuffer } from "../src/core/binary/EncodingBinaryBuffer.js";
|
|
32
|
+
import { EntityComponentDataset } from "../src/engine/ecs/EntityComponentDataset.js";
|
|
33
|
+
import InputControllerSystem from "../src/engine/input/ecs/systems/InputControllerSystem.js";
|
|
34
|
+
import { assert } from "../src/core/assert.js";
|
|
35
|
+
import { resetSoundEmitterTracks } from "../../model/game/options/resetSoundEmitterTracks.js";
|
|
36
|
+
import { NumberEditor } from "./ecs/component/editors/primitive/NumberEditor.js";
|
|
37
|
+
import { BooleanEditor } from "./ecs/component/editors/primitive/BooleanEditor.js";
|
|
38
|
+
import { StringEditor } from "./ecs/component/editors/primitive/StringEditor.js";
|
|
39
|
+
import { FunctionEditor } from "./ecs/component/editors/primitive/FunctionEditor.js";
|
|
40
|
+
import { ArrayEditor } from "./ecs/component/editors/primitive/ArrayEditor.js";
|
|
41
|
+
import { ObjectEditor } from "./ecs/component/editors/primitive/ObjectEditor.js";
|
|
42
|
+
import { NumericInterval } from "../src/core/math/interval/NumericInterval.js";
|
|
43
|
+
import { NumericIntervalEditor } from "./ecs/component/editors/NumericIntervalEditor.js";
|
|
44
|
+
import { ListEditor } from "./ecs/component/editors/collection/ListEditor.js";
|
|
45
|
+
import ObservedBoolean from "../src/core/model/ObservedBoolean.js";
|
|
46
|
+
import { ObservedBooleanEditor } from "./ecs/component/editors/ObservedBooleanEditor.js";
|
|
47
|
+
import ObservedEnum from "../src/core/model/ObservedEnum.js";
|
|
48
|
+
import { ObservedEnumEditor } from "./ecs/component/editors/ObservedEnumEditor.js";
|
|
49
|
+
import { Color } from "../src/core/color/Color.js";
|
|
50
|
+
import { ColorEditor } from "./ecs/component/editors/ColorEditor.js";
|
|
51
|
+
import Vector4 from "../src/core/geom/Vector4.js";
|
|
52
|
+
import { Vector4Editor } from "./ecs/component/editors/geom/Vector4Editor.js";
|
|
53
|
+
import Vector3 from "../src/core/geom/Vector3.js";
|
|
54
|
+
import { Vector3Editor } from "./ecs/component/editors/geom/Vector3Editor.js";
|
|
55
|
+
import Vector2 from "../src/core/geom/Vector2.js";
|
|
56
|
+
import { Vector2Editor } from "./ecs/component/editors/geom/Vector2Editor.js";
|
|
57
|
+
import Vector1 from "../src/core/geom/Vector1.js";
|
|
58
|
+
import { Vector1Editor } from "./ecs/component/editors/geom/Vector1Editor.js";
|
|
59
|
+
import ObservedString from "../src/core/model/ObservedString.js";
|
|
60
|
+
import { ObservedStringEditor } from "./ecs/component/editors/ObservedStringEditor.js";
|
|
61
|
+
import Quaternion from "../src/core/geom/Quaternion.js";
|
|
62
|
+
import { QuaternionEditor } from "./ecs/component/editors/geom/QuaternionEditor.js";
|
|
63
|
+
import { Sampler2D } from "../src/engine/graphics/texture/sampler/Sampler2D.js";
|
|
64
|
+
import { Sampler2DEditor } from "./ecs/component/editors/Sampler2DEditor.js";
|
|
65
|
+
import { HTMLElementEditor } from "./ecs/component/editors/HTMLElementEditor.js";
|
|
66
|
+
import WorkerProxy from "../src/core/process/worker/WorkerProxy.js";
|
|
67
|
+
import { noEditor } from "./ecs/component/editors/common/noEditor.js";
|
|
68
|
+
import Signal from "../src/core/events/signal/Signal.js";
|
|
69
|
+
import ObservedInteger from "../src/core/model/ObservedInteger.js";
|
|
70
|
+
import { ObservedIntegerEditor } from "./ecs/component/editors/ObservedIntegerEditor.js";
|
|
71
|
+
|
|
72
|
+
import '../../../../css/editor/EntityEditorView.scss';
|
|
73
|
+
import '../../../../css/editor/EditorView.scss';
|
|
74
|
+
import { ParameterTrackSet } from "../src/engine/graphics/particles/particular/engine/parameter/ParameterTrackSet.js";
|
|
75
|
+
import { ParameterTrackSetEditor } from "./ecs/component/editors/ecs/ParameterTrackSetEditor.js";
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @template T
|
|
79
|
+
* @param {T} original
|
|
80
|
+
* @param {EntityManager} em
|
|
81
|
+
* @returns {T}
|
|
82
|
+
*/
|
|
83
|
+
function cloneComponent(original, em) {
|
|
84
|
+
function newInstance() {
|
|
85
|
+
return new original.constructor();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const cloneViaMethod = {
|
|
89
|
+
name: 'Clone Method',
|
|
90
|
+
check: function (original) {
|
|
91
|
+
return typeof original.clone === "function";
|
|
92
|
+
},
|
|
93
|
+
execute: function (original) {
|
|
94
|
+
return original.clone();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const cloneViaSerialization = {
|
|
99
|
+
name: 'Serialization',
|
|
100
|
+
check: function (original) {
|
|
101
|
+
return typeof original.toJSON === "function" && typeof original.fromJSON === "function";
|
|
102
|
+
},
|
|
103
|
+
execute: function (original) {
|
|
104
|
+
//use serialization to create a clone
|
|
105
|
+
const json = original.toJSON();
|
|
106
|
+
|
|
107
|
+
const clone = newInstance();
|
|
108
|
+
|
|
109
|
+
const system = em.getOwnerSystemByComponentClass(original.constructor);
|
|
110
|
+
|
|
111
|
+
clone.fromJSON(json, system);
|
|
112
|
+
|
|
113
|
+
return clone;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const cloneViaInstantiate = {
|
|
117
|
+
name: 'New Instance',
|
|
118
|
+
check: function (original) {
|
|
119
|
+
return true;
|
|
120
|
+
},
|
|
121
|
+
execute: function (original) {
|
|
122
|
+
//no clone method, that's a bummer
|
|
123
|
+
const typeName = original.constructor.typeName;
|
|
124
|
+
|
|
125
|
+
console.error(`Component '${typeName}' has no 'clone' method, creating a new instance instead..`);
|
|
126
|
+
|
|
127
|
+
return newInstance();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
const cloners = [cloneViaMethod, cloneViaSerialization, cloneViaInstantiate];
|
|
133
|
+
|
|
134
|
+
for (let i = 0; i < cloners.length; i++) {
|
|
135
|
+
const cloner = cloners[i];
|
|
136
|
+
const applicable = cloner.check(original);
|
|
137
|
+
|
|
138
|
+
if (!applicable) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let clone;
|
|
143
|
+
try {
|
|
144
|
+
clone = cloner.execute(original);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (original.constructor !== clone.constructor) {
|
|
150
|
+
console.error(`Cloner ${cloner.name} produced instance with different constructor`, 'original=', original, 'clone=', clone);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return clone;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
throw new Error(`Failed to clone, no cloners worked`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
*
|
|
162
|
+
* @param {Editor} editor
|
|
163
|
+
*/
|
|
164
|
+
function copySelectedEntities(editor) {
|
|
165
|
+
if (editor.selection.isEmpty()) {
|
|
166
|
+
//clear out copy buffer
|
|
167
|
+
editor.copyBuffer = [];
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
*
|
|
173
|
+
* @type {EntityManager}
|
|
174
|
+
*/
|
|
175
|
+
const em = editor.engine.entityManager;
|
|
176
|
+
|
|
177
|
+
const ecd = em.dataset;
|
|
178
|
+
|
|
179
|
+
editor.copyBuffer = editor.selection.map(function (entity) {
|
|
180
|
+
const components = ecd.getAllComponents(entity);
|
|
181
|
+
|
|
182
|
+
//clone all components to preserve their status
|
|
183
|
+
const clonedComponents = [];
|
|
184
|
+
components.forEach(function (c) {
|
|
185
|
+
if (c === undefined) {
|
|
186
|
+
//skip undefined
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
let clone;
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
clone = cloneComponent(c, em);
|
|
194
|
+
} catch (e) {
|
|
195
|
+
console.error(`Failed to clone component, omitting`, c, e);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
clonedComponents.push(clone);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
return clonedComponents;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
*
|
|
208
|
+
* @param {Editor} editor
|
|
209
|
+
*/
|
|
210
|
+
function pasteEntities(editor) {
|
|
211
|
+
const copyBuffer = editor.copyBuffer;
|
|
212
|
+
if (copyBuffer.length === 0) {
|
|
213
|
+
//copy buffer is empty, nothing to do
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const actions = editor.actions;
|
|
218
|
+
|
|
219
|
+
actions.mark('paste entities');
|
|
220
|
+
|
|
221
|
+
const createdEntities = copyBuffer.map(function (components) {
|
|
222
|
+
const entityCreateAction = new EntityCreateAction();
|
|
223
|
+
|
|
224
|
+
actions.do(entityCreateAction);
|
|
225
|
+
|
|
226
|
+
//clone all components to preserve status of the buffer
|
|
227
|
+
const n = components.length;
|
|
228
|
+
|
|
229
|
+
for (let i = 0; i < n; i++) {
|
|
230
|
+
|
|
231
|
+
const c = components[i];
|
|
232
|
+
|
|
233
|
+
const clone = cloneComponent(c, editor.engine.entityManager);
|
|
234
|
+
|
|
235
|
+
const componentAddAction = new ComponentAddAction(entityCreateAction.entity, clone);
|
|
236
|
+
|
|
237
|
+
try {
|
|
238
|
+
actions.do(componentAddAction);
|
|
239
|
+
} catch (e) {
|
|
240
|
+
console.warn(`Failed to add component.`, e, 'The component might have been added as a result of some EntityObserver');
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return entityCreateAction.entity;
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
//select newly created entities
|
|
248
|
+
actions.do(new SelectionClearAction());
|
|
249
|
+
actions.do(new SelectionAddAction(createdEntities));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function buildEditorCamera() {
|
|
253
|
+
const cameraEntity = new EntityBuilder();
|
|
254
|
+
const camera = new Camera();
|
|
255
|
+
|
|
256
|
+
camera.projectionType.set(Camera.ProjectionType.Perspective);
|
|
257
|
+
|
|
258
|
+
camera.autoClip = true;
|
|
259
|
+
camera.active.set(true);
|
|
260
|
+
|
|
261
|
+
cameraEntity.add(camera);
|
|
262
|
+
|
|
263
|
+
const topDownCameraController = new TopDownCameraController();
|
|
264
|
+
topDownCameraController.distanceMin = -Infinity;
|
|
265
|
+
topDownCameraController.distanceMax = Infinity;
|
|
266
|
+
|
|
267
|
+
cameraEntity.add(topDownCameraController);
|
|
268
|
+
cameraEntity.add(new Transform());
|
|
269
|
+
|
|
270
|
+
cameraEntity.add(new EditorEntity());
|
|
271
|
+
|
|
272
|
+
return cameraEntity;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
*
|
|
277
|
+
* @param {EntityBuilder} cameraEntity
|
|
278
|
+
* @param {EntityComponentDataset} dataset
|
|
279
|
+
* @param {Editor} editor
|
|
280
|
+
*/
|
|
281
|
+
function activateEditorCamera(cameraEntity, dataset, editor) {
|
|
282
|
+
|
|
283
|
+
const camera = cameraEntity.getComponent(Camera);
|
|
284
|
+
|
|
285
|
+
let activeCameraEntity = null;
|
|
286
|
+
|
|
287
|
+
//find currently active camera
|
|
288
|
+
dataset.traverseEntities([Camera], function (c, entity) {
|
|
289
|
+
if (dataset.getComponent(entity, EditorEntity) !== undefined) {
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (c.active.getValue()) {
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
c.active.set(false);
|
|
297
|
+
|
|
298
|
+
editor.cleanupTasks.push(function () {
|
|
299
|
+
//remember to restore active camera
|
|
300
|
+
c.active.set(true);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
activeCameraEntity = entity;
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
if (activeCameraEntity !== null) {
|
|
308
|
+
/**
|
|
309
|
+
*
|
|
310
|
+
* @type {Transform}
|
|
311
|
+
*/
|
|
312
|
+
const acTransform = dataset.getComponent(activeCameraEntity, Transform);
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
*
|
|
316
|
+
* @type {Transform}
|
|
317
|
+
*/
|
|
318
|
+
const cameraTransform = cameraEntity.getComponent(Transform);
|
|
319
|
+
|
|
320
|
+
if (acTransform !== undefined) {
|
|
321
|
+
cameraTransform.copy(acTransform);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
*
|
|
326
|
+
* @type {TopDownCameraController}
|
|
327
|
+
*/
|
|
328
|
+
const cameraController = cameraEntity.getComponent(TopDownCameraController);
|
|
329
|
+
|
|
330
|
+
const active_camera_controller = dataset.getComponent(activeCameraEntity, TopDownCameraController);
|
|
331
|
+
if (active_camera_controller !== undefined) {
|
|
332
|
+
cameraController.target.copy(active_camera_controller.target);
|
|
333
|
+
cameraController.distance = active_camera_controller.distance;
|
|
334
|
+
cameraController.pitch = active_camera_controller.pitch;
|
|
335
|
+
cameraController.yaw = active_camera_controller.yaw;
|
|
336
|
+
cameraController.roll = active_camera_controller.roll;
|
|
337
|
+
} else {
|
|
338
|
+
setCameraControllerFromTransform(cameraTransform, cameraController);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
camera.active.set(true);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
*
|
|
347
|
+
* @param {Map<any, TypeEditor>} registry
|
|
348
|
+
*/
|
|
349
|
+
function initialize_basic_registry(registry) {
|
|
350
|
+
|
|
351
|
+
registry.set(Number, new NumberEditor());
|
|
352
|
+
registry.set(Boolean, new BooleanEditor());
|
|
353
|
+
registry.set(String, new StringEditor());
|
|
354
|
+
registry.set(Function, new FunctionEditor());
|
|
355
|
+
registry.set(Array, new ArrayEditor());
|
|
356
|
+
registry.set(Object, new ObjectEditor());
|
|
357
|
+
|
|
358
|
+
registry.set(ObservedInteger, new ObservedIntegerEditor());
|
|
359
|
+
registry.set(ObservedBoolean, new ObservedBooleanEditor());
|
|
360
|
+
registry.set(ObservedEnum, new ObservedEnumEditor());
|
|
361
|
+
registry.set(ObservedString, new ObservedStringEditor());
|
|
362
|
+
|
|
363
|
+
registry.set(NumericInterval, new NumericIntervalEditor());
|
|
364
|
+
registry.set(List, new ListEditor());
|
|
365
|
+
registry.set(Color, new ColorEditor());
|
|
366
|
+
|
|
367
|
+
registry.set(Vector4, new Vector4Editor());
|
|
368
|
+
registry.set(Vector3, new Vector3Editor());
|
|
369
|
+
registry.set(Vector2, new Vector2Editor());
|
|
370
|
+
registry.set(Vector1, new Vector1Editor());
|
|
371
|
+
registry.set(Quaternion, new QuaternionEditor());
|
|
372
|
+
|
|
373
|
+
registry.set(Sampler2D, new Sampler2DEditor());
|
|
374
|
+
registry.set(ParameterTrackSet, new ParameterTrackSetEditor());
|
|
375
|
+
|
|
376
|
+
registry.set(HTMLElement, new HTMLElementEditor());
|
|
377
|
+
registry.set(HTMLCanvasElement, new HTMLElementEditor());
|
|
378
|
+
|
|
379
|
+
registry.set(WorkerProxy, noEditor());
|
|
380
|
+
registry.set(Signal, noEditor());
|
|
381
|
+
|
|
382
|
+
registry.set(Uint8Array, noEditor());
|
|
383
|
+
registry.set(Uint16Array, noEditor());
|
|
384
|
+
registry.set(Uint32Array, noEditor());
|
|
385
|
+
|
|
386
|
+
registry.set(Int8Array, noEditor());
|
|
387
|
+
registry.set(Int16Array, noEditor());
|
|
388
|
+
registry.set(Int32Array, noEditor());
|
|
389
|
+
|
|
390
|
+
registry.set(Float32Array, noEditor());
|
|
391
|
+
registry.set(Float64Array, noEditor());
|
|
392
|
+
|
|
393
|
+
registry.set(CanvasRenderingContext2D, noEditor());
|
|
394
|
+
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
*
|
|
399
|
+
* @constructor
|
|
400
|
+
* @property {List.<Number>} selection represents list of currently selected entities
|
|
401
|
+
* @property {List.<Object>} history list of applied actions
|
|
402
|
+
*/
|
|
403
|
+
function Editor() {
|
|
404
|
+
this.processEngine = new ProcessEngine();
|
|
405
|
+
this.toolEngine = new ToolEngine();
|
|
406
|
+
this.selection = new List();
|
|
407
|
+
this.actions = new ActionProcessor(this);
|
|
408
|
+
this.selectionVistualizer = new SelectionVisualizer(this);
|
|
409
|
+
this.meshLibrary = new MeshLibrary();
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
*
|
|
413
|
+
* @type {Map<any, TypeEditor>}
|
|
414
|
+
*/
|
|
415
|
+
this.type_editor_registry = new Map();
|
|
416
|
+
|
|
417
|
+
initialize_basic_registry(this.type_editor_registry);
|
|
418
|
+
|
|
419
|
+
this.cameraEntity = buildEditorCamera();
|
|
420
|
+
|
|
421
|
+
this.editorEntitySystem = new EditorEntitySystem();
|
|
422
|
+
|
|
423
|
+
this.view = null;
|
|
424
|
+
|
|
425
|
+
this.copyBuffer = [];
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
const self = this;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
*
|
|
432
|
+
* @param keyCode
|
|
433
|
+
* @param {KeyboardEvent} event
|
|
434
|
+
*/
|
|
435
|
+
function processCtrlCombinations(keyCode, event) {
|
|
436
|
+
if (keyCode === KeyCodes.z) {
|
|
437
|
+
event.preventDefault();
|
|
438
|
+
event.stopPropagation();
|
|
439
|
+
|
|
440
|
+
self.actions.undo();
|
|
441
|
+
} else if (keyCode === KeyCodes.y) {
|
|
442
|
+
event.preventDefault();
|
|
443
|
+
event.stopPropagation();
|
|
444
|
+
|
|
445
|
+
self.actions.redo();
|
|
446
|
+
} else if (keyCode === KeyCodes.c) {
|
|
447
|
+
event.preventDefault();
|
|
448
|
+
event.stopPropagation();
|
|
449
|
+
|
|
450
|
+
//copy
|
|
451
|
+
copySelectedEntities(self);
|
|
452
|
+
} else if (keyCode === KeyCodes.v) {
|
|
453
|
+
event.preventDefault();
|
|
454
|
+
event.stopPropagation();
|
|
455
|
+
|
|
456
|
+
//paste
|
|
457
|
+
pasteEntities(self);
|
|
458
|
+
} else if (keyCode === KeyCodes.s) {
|
|
459
|
+
event.preventDefault();
|
|
460
|
+
event.stopPropagation();
|
|
461
|
+
|
|
462
|
+
const entityManager = self.engine.entityManager;
|
|
463
|
+
const currentDataset = entityManager.dataset;
|
|
464
|
+
|
|
465
|
+
//clone dataset
|
|
466
|
+
const dataset = new EntityComponentDataset();
|
|
467
|
+
dataset.setComponentTypeMap(currentDataset.getComponentTypeMap());
|
|
468
|
+
dataset.maskedCopy(currentDataset, currentDataset.getComponentTypeMap());
|
|
469
|
+
|
|
470
|
+
//remove all Editor entities
|
|
471
|
+
dataset.traverseComponents(EditorEntity, function (c, entity) {
|
|
472
|
+
dataset.removeEntity(entity);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
//clone and re-enable the camera
|
|
476
|
+
dataset.traverseComponents(Camera, function (c, entity) {
|
|
477
|
+
const clone = c.clone();
|
|
478
|
+
clone.active.set(true);
|
|
479
|
+
|
|
480
|
+
dataset.removeComponentFromEntity(entity, Camera);
|
|
481
|
+
dataset.addComponentToEntity(entity, clone);
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
// Set music tracks back to time=0
|
|
485
|
+
resetSoundEmitterTracks(dataset);
|
|
486
|
+
|
|
487
|
+
const serializer = new BinaryBufferSerializer();
|
|
488
|
+
serializer.engine = self.engine;
|
|
489
|
+
serializer.registry = engine.binarySerializationRegistry;
|
|
490
|
+
|
|
491
|
+
const state = new EncodingBinaryBuffer();
|
|
492
|
+
|
|
493
|
+
try {
|
|
494
|
+
serializer.process(state, dataset);
|
|
495
|
+
} catch (e) {
|
|
496
|
+
//failed to serialize game state
|
|
497
|
+
console.error("Failed to serialize game state", e);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
state.trim();
|
|
501
|
+
|
|
502
|
+
downloadAsFile(state.data, "level.bin");
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
*
|
|
508
|
+
* @param keyCode
|
|
509
|
+
* @param {KeyboardEvent} event
|
|
510
|
+
*/
|
|
511
|
+
function processSingleKey(keyCode, event) {
|
|
512
|
+
if (keyCode === KeyCodes.delete || keyCode === KeyCodes.x) {
|
|
513
|
+
event.preventDefault();
|
|
514
|
+
event.stopPropagation();
|
|
515
|
+
|
|
516
|
+
self.actions.mark('delete selected entities');
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
const removeActions = self.selection.map(function (entity) {
|
|
520
|
+
|
|
521
|
+
return new EntityRemoveAction(entity);
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
self.actions.do(new SelectionClearAction());
|
|
525
|
+
|
|
526
|
+
removeActions.forEach(function (a) {
|
|
527
|
+
self.actions.do(a);
|
|
528
|
+
});
|
|
529
|
+
} else if (keyCode === KeyCodes.q) {
|
|
530
|
+
let activeTool = self.toolEngine.active.getValue();
|
|
531
|
+
if (activeTool === null || activeTool.name !== "marquee_selection") {
|
|
532
|
+
//activate selection tool
|
|
533
|
+
self.toolEngine.activate("marquee_selection");
|
|
534
|
+
} else {
|
|
535
|
+
//activate transform tool
|
|
536
|
+
self.toolEngine.activate("spatial_transform");
|
|
537
|
+
}
|
|
538
|
+
} else if (keyCode === KeyCodes.g) {
|
|
539
|
+
//activate camera tool
|
|
540
|
+
self.toolEngine.activate("camera_control");
|
|
541
|
+
} else if (keyCode === KeyCodes.d && event.shiftKey) {
|
|
542
|
+
if (!self.selection.isEmpty()) {
|
|
543
|
+
//copy
|
|
544
|
+
copySelectedEntities(self);
|
|
545
|
+
//paste
|
|
546
|
+
pasteEntities(self);
|
|
547
|
+
}
|
|
548
|
+
} else if (keyCode === KeyCodes.w) {
|
|
549
|
+
self.toolEngine.activate("spatial_transform");
|
|
550
|
+
self.toolEngine.active.getValue().mode.set(TransformerMode.Translation);
|
|
551
|
+
} else if (keyCode === KeyCodes.e) {
|
|
552
|
+
self.toolEngine.activate("spatial_transform");
|
|
553
|
+
self.toolEngine.active.getValue().mode.set(TransformerMode.Rotation);
|
|
554
|
+
} else if (keyCode === KeyCodes.r) {
|
|
555
|
+
self.toolEngine.activate("spatial_transform");
|
|
556
|
+
self.toolEngine.active.getValue().mode.set(TransformerMode.Scale);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function isViewFocused(view) {
|
|
561
|
+
function checkChild(el) {
|
|
562
|
+
if (el === view.el) {
|
|
563
|
+
return true;
|
|
564
|
+
} else {
|
|
565
|
+
const children = el.children;
|
|
566
|
+
const numChildren = children.length;
|
|
567
|
+
for (let i = 0; i < numChildren; i++) {
|
|
568
|
+
const child = children[i];
|
|
569
|
+
if (checkChild(child)) {
|
|
570
|
+
return true;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return checkChild(document.activeElement);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
*
|
|
583
|
+
* @param {KeyboardEvent} event
|
|
584
|
+
*/
|
|
585
|
+
function handleKeyDownEvent(event) {
|
|
586
|
+
//check that game view has focus
|
|
587
|
+
if (!isViewFocused(self.engine.gameView)) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const keyCode = event.keyCode;
|
|
592
|
+
if (event.ctrlKey) {
|
|
593
|
+
processCtrlCombinations(keyCode, event);
|
|
594
|
+
} else {
|
|
595
|
+
processSingleKey(keyCode, event)
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
const activeTool = self.toolEngine.active.getValue();
|
|
599
|
+
|
|
600
|
+
if (activeTool !== null && activeTool !== undefined) {
|
|
601
|
+
//pass event to active tool
|
|
602
|
+
activeTool.handleKeyboardEvent(event);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
this.handlers = {
|
|
607
|
+
keyDown: handleKeyDownEvent
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
Editor.prototype.initialize = function () {
|
|
612
|
+
this.toolEngine.initialize();
|
|
613
|
+
this.processEngine.initialize(this);
|
|
614
|
+
this.view = new EditorView(this);
|
|
615
|
+
|
|
616
|
+
this.copyBuffer = [];
|
|
617
|
+
|
|
618
|
+
this.disabledSystems = [];
|
|
619
|
+
|
|
620
|
+
this.lastTool = "marquee_selection";
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
this.cleanupTasks = [];
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Attempt to focus camera on the entity
|
|
628
|
+
* @param {int} entity
|
|
629
|
+
*/
|
|
630
|
+
Editor.prototype.focusEntity = function (entity) {
|
|
631
|
+
const em = this.engine.entityManager;
|
|
632
|
+
|
|
633
|
+
const ecd = em.dataset;
|
|
634
|
+
|
|
635
|
+
//try focus camera on it
|
|
636
|
+
const transform = ecd.getComponent(entity, ecd.getComponentClassByName("Transform"));
|
|
637
|
+
|
|
638
|
+
if (transform !== null) {
|
|
639
|
+
|
|
640
|
+
const TopDownCameraController = ecd.getComponentClassByName("TopDownCameraController");
|
|
641
|
+
const topDownCameraControllerSystem = em.getSystem(TopDownCameraControllerSystem);
|
|
642
|
+
|
|
643
|
+
ecd.traverseComponents(TopDownCameraController, function (camera) {
|
|
644
|
+
const target = camera.target;
|
|
645
|
+
target.set(transform.position.x, target.y, transform.position.z);
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
let originalValue = topDownCameraControllerSystem.enabled.get();
|
|
649
|
+
|
|
650
|
+
if (!originalValue) {
|
|
651
|
+
topDownCameraControllerSystem.enabled.set(true);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
topDownCameraControllerSystem.update(0);
|
|
655
|
+
topDownCameraControllerSystem.enabled.set(originalValue);
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
*
|
|
661
|
+
* @param {Engine} engine
|
|
662
|
+
*/
|
|
663
|
+
Editor.prototype.attach = async function (engine) {
|
|
664
|
+
assert.defined(engine, 'engine');
|
|
665
|
+
assert.ok(engine.isEngine, 'engine.isEngine');
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
this.engine = engine;
|
|
669
|
+
|
|
670
|
+
//validate selection
|
|
671
|
+
const missingEntities = this.selection.filter(function (entity) {
|
|
672
|
+
return !engine.entityManager.dataset.entityExists(entity);
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
//drop missing entities from selection
|
|
676
|
+
this.selection.removeAll(missingEntities);
|
|
677
|
+
|
|
678
|
+
//find interaction system and disable it
|
|
679
|
+
this.disableSystem(TopDownCameraControllerSystem);
|
|
680
|
+
this.disableSystem(InputControllerSystem);
|
|
681
|
+
|
|
682
|
+
//attach EditorEntity system
|
|
683
|
+
await engine.entityManager.addSystem(this.editorEntitySystem);
|
|
684
|
+
|
|
685
|
+
const dataset = engine.entityManager.dataset;
|
|
686
|
+
|
|
687
|
+
const cameraEntity = this.cameraEntity;
|
|
688
|
+
|
|
689
|
+
activateEditorCamera(this.cameraEntity, dataset, this);
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
cameraEntity.build(dataset);
|
|
693
|
+
|
|
694
|
+
this.toolEngine.startup(engine, this);
|
|
695
|
+
this.toolEngine.activate(this.lastTool);
|
|
696
|
+
|
|
697
|
+
this.processEngine.startup();
|
|
698
|
+
|
|
699
|
+
this.selectionVistualizer.startup();
|
|
700
|
+
|
|
701
|
+
//attach view
|
|
702
|
+
engine.viewStack.push(this.view, "Editor");
|
|
703
|
+
|
|
704
|
+
//map keys
|
|
705
|
+
window.addEventListener('keydown', this.handlers.keyDown);
|
|
706
|
+
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
*
|
|
711
|
+
* @param {Class} systemClass
|
|
712
|
+
*/
|
|
713
|
+
Editor.prototype.disableSystem = function (systemClass) {
|
|
714
|
+
|
|
715
|
+
const entityManager = this.engine.entityManager;
|
|
716
|
+
|
|
717
|
+
const system = entityManager.getSystem(systemClass);
|
|
718
|
+
|
|
719
|
+
if (system === null) {
|
|
720
|
+
console.log('System not found', systemClass);
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
const originalState = system.enabled.get();
|
|
725
|
+
|
|
726
|
+
system.enabled.set(false);
|
|
727
|
+
this.disabledSystems.push({
|
|
728
|
+
name: name,
|
|
729
|
+
originalState: originalState,
|
|
730
|
+
system: system
|
|
731
|
+
});
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
Editor.prototype.restoreDisableSystem = function () {
|
|
735
|
+
this.disabledSystems.forEach(function (disabledSystem) {
|
|
736
|
+
disabledSystem.system.enabled.set(disabledSystem.originalState);
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
this.disabledSystems = [];
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
Editor.prototype.detach = function () {
|
|
743
|
+
this.selectionVistualizer.shutdown();
|
|
744
|
+
|
|
745
|
+
this.lastTool = this.toolEngine.active.get().name;
|
|
746
|
+
|
|
747
|
+
this.toolEngine.shutdown();
|
|
748
|
+
|
|
749
|
+
this.processEngine.shutdown();
|
|
750
|
+
|
|
751
|
+
//pop own view from the engine's view stack restoring the original state
|
|
752
|
+
this.engine.viewStack.pop();
|
|
753
|
+
|
|
754
|
+
//unmap keys
|
|
755
|
+
window.removeEventListener('keydown', this.handlers.keyDown);
|
|
756
|
+
|
|
757
|
+
//enable interactions system if it was disabled
|
|
758
|
+
this.restoreDisableSystem();
|
|
759
|
+
|
|
760
|
+
//remove all editor entities
|
|
761
|
+
const dataset = this.engine.entityManager.dataset;
|
|
762
|
+
dataset.traverseComponents(EditorEntity, function (component, entity) {
|
|
763
|
+
dataset.removeEntity(entity);
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
//remove system
|
|
767
|
+
this.engine.entityManager.removeSystem(this.editorEntitySystem);
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
this.cleanupTasks.forEach(t => t());
|
|
771
|
+
|
|
772
|
+
this.cleanupTasks = [];
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
*
|
|
777
|
+
* @param {int} entity
|
|
778
|
+
* @returns {boolean}
|
|
779
|
+
*/
|
|
780
|
+
Editor.prototype.isEditorEntity = function (entity) {
|
|
781
|
+
return isEditorOwnedEntity(entity, this.engine.entityManager.dataset);
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
*
|
|
786
|
+
* @param {int} entity
|
|
787
|
+
* @param {EntityComponentDataset} dataset
|
|
788
|
+
*/
|
|
789
|
+
function isEditorOwnedEntity(entity, dataset) {
|
|
790
|
+
return dataset.getComponent(entity, EditorEntity) !== undefined;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
export default Editor;
|