@woosh/meep-engine 2.46.29 → 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
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import Tool from "./engine/Tool.js";
|
|
2
|
+
import Vector1 from "../../src/core/geom/Vector1.js";
|
|
3
|
+
import ObservedValue from "../../src/core/model/ObservedValue.js";
|
|
4
|
+
import Vector4 from "../../src/core/geom/Vector4.js";
|
|
5
|
+
import loadSampler2D from "../../src/engine/graphics/texture/sampler/loadSampler2D.js";
|
|
6
|
+
import convertSampler2D2Canvas from "../../src/engine/graphics/texture/sampler/Sampler2D2Canvas.js";
|
|
7
|
+
import { InstancedMeshComponent } from "../../src/engine/ecs/foliage/ecs/InstancedMeshComponent.js";
|
|
8
|
+
import { parseHex } from "../../src/core/color/parseHex.js";
|
|
9
|
+
import { obtainTerrain } from "../../src/engine/ecs/terrain/util/obtainTerrain.js";
|
|
10
|
+
|
|
11
|
+
class FoliagePaintTool extends Tool {
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
this.name = "foliage_paint";
|
|
15
|
+
|
|
16
|
+
this.settings.layer = new Vector1(0);
|
|
17
|
+
this.settings.value = new Vector1(1);
|
|
18
|
+
this.settings.alphaMultiplier = new Vector1(1);
|
|
19
|
+
this.settings.color = new ObservedValue("#FFFFFF");
|
|
20
|
+
|
|
21
|
+
this.settings.baseColor = new ObservedValue("#000000");
|
|
22
|
+
this.settings.baseColorAlpha = new Vector1(0.6);
|
|
23
|
+
|
|
24
|
+
const self = this;
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
updateSelection() {
|
|
29
|
+
self.paint();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
buildColor() {
|
|
33
|
+
|
|
34
|
+
const color = new Vector4();
|
|
35
|
+
const baseColor = parseHex(this.settings.color.get());
|
|
36
|
+
color.set(baseColor.r, baseColor.g, baseColor.b, 0);
|
|
37
|
+
color.multiplyScalar(1 / 255);
|
|
38
|
+
|
|
39
|
+
return color;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
buildBaseColor() {
|
|
43
|
+
|
|
44
|
+
const color = new Vector4();
|
|
45
|
+
const baseColor = parseHex(this.settings.baseColor.get());
|
|
46
|
+
color.set(baseColor.r, baseColor.g, baseColor.b, 0);
|
|
47
|
+
color.multiplyScalar(1 / 255);
|
|
48
|
+
|
|
49
|
+
color.w = this.settings.baseColorAlpha.getValue();
|
|
50
|
+
|
|
51
|
+
return color;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
initialize() {
|
|
55
|
+
super.initialize();
|
|
56
|
+
|
|
57
|
+
const engine = this.engine;
|
|
58
|
+
const editor = this.editor;
|
|
59
|
+
|
|
60
|
+
this.terrain = obtainTerrain(engine.entityManager.dataset, function (t, entity) {
|
|
61
|
+
self.terrainEntity = entity;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
this.terrain.overlay.push();
|
|
65
|
+
|
|
66
|
+
this.terrain.overlay.borderWidth.set(0);
|
|
67
|
+
|
|
68
|
+
this.paint();
|
|
69
|
+
|
|
70
|
+
editor.selection.on.added.add(this.updateSelection);
|
|
71
|
+
editor.selection.on.removed.add(this.updateSelection);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
shutdown() {
|
|
75
|
+
this.terrain.overlay.pop();
|
|
76
|
+
|
|
77
|
+
this.editor.selection.on.added.remove(this.updateSelection);
|
|
78
|
+
this.editor.selection.on.removed.remove(this.updateSelection);
|
|
79
|
+
|
|
80
|
+
this.settings.value.onChanged.remove(this.updateSelection);
|
|
81
|
+
this.settings.alphaMultiplier.onChanged.remove(this.updateSelection);
|
|
82
|
+
this.settings.color.onChanged.remove(this.updateSelection);
|
|
83
|
+
|
|
84
|
+
super.shutdown();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
paint() {
|
|
88
|
+
|
|
89
|
+
const alphaMultiplier = this.settings.alphaMultiplier.getValue();
|
|
90
|
+
const overlay = this.terrain.overlay;
|
|
91
|
+
overlay.clear();
|
|
92
|
+
|
|
93
|
+
const layer = this.settings.layer.getValue();
|
|
94
|
+
|
|
95
|
+
const color = this.buildColor();
|
|
96
|
+
|
|
97
|
+
const baseColor = this.buildBaseColor();
|
|
98
|
+
|
|
99
|
+
const engine = this.engine;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
* @param {InstancedMeshComponent} foliage
|
|
104
|
+
* @param {Number} entity
|
|
105
|
+
*/
|
|
106
|
+
function visit(foliage, entity) {
|
|
107
|
+
const foliageLayer = foliage.layers.get(layer);
|
|
108
|
+
loadSampler2D(foliageLayer.densityMap.get(), engine.assetManager).then(function (sampler) {
|
|
109
|
+
|
|
110
|
+
overlay.size.set(sampler.width, sampler.height);
|
|
111
|
+
overlay.clear();
|
|
112
|
+
|
|
113
|
+
const v4c = new Vector4(0, 0, 0, 0);
|
|
114
|
+
|
|
115
|
+
function mappingFunction(index, array, x, y) {
|
|
116
|
+
const address = index;
|
|
117
|
+
const alpha = sampler.data[address / 4] * alphaMultiplier;
|
|
118
|
+
color.w = alpha;
|
|
119
|
+
|
|
120
|
+
Vector4.lerp(color, baseColor, (1 - alpha), v4c);
|
|
121
|
+
|
|
122
|
+
//scale to unsigned byte value
|
|
123
|
+
v4c.multiplyScalar(255);
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
array[address] = v4c.x;
|
|
127
|
+
array[address + 1] = v4c.y;
|
|
128
|
+
array[address + 2] = v4c.z;
|
|
129
|
+
//alpha
|
|
130
|
+
array[address + 3] = v4c.w;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
convertSampler2D2Canvas(sampler, 1, 0, overlay.canvas, mappingFunction);
|
|
134
|
+
|
|
135
|
+
overlay.update();
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//initialize overlay
|
|
140
|
+
this.traverse(visit);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
traverse(callback) {
|
|
144
|
+
/**
|
|
145
|
+
* @type {EntityManager}
|
|
146
|
+
*/
|
|
147
|
+
const entityManger = this.engine.entityManager;
|
|
148
|
+
this.editor.selection.forEach(function (entity) {
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
*
|
|
152
|
+
* @type {InstancedMeshComponent}
|
|
153
|
+
*/
|
|
154
|
+
const foliage = entityManger.getComponent(entity, InstancedMeshComponent);
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
if (foliage === null) {
|
|
158
|
+
//do nothing
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
callback(foliage, entity);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
export default FoliagePaintTool;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import Tool from "./engine/Tool.js";
|
|
2
|
+
import GridPosition from "../../src/engine/grid/components/GridPosition.js";
|
|
3
|
+
import GridObstacle from "../../src/engine/grid/components/GridObstacle.js";
|
|
4
|
+
import Vector4 from "../../src/core/geom/Vector4.js";
|
|
5
|
+
import ObservedValue from "../../src/core/model/ObservedValue.js";
|
|
6
|
+
import Vector1 from "../../src/core/geom/Vector1.js";
|
|
7
|
+
import WriteGridValueAction from "../actions/concrete/WriteGridValueAction.js";
|
|
8
|
+
import PaintTerrainOverlayAction from "../actions/concrete/PaintTerrainOverlayAction.js";
|
|
9
|
+
import { decodeMouseEventButtons, PointerDevice } from "../../src/engine/input/devices/PointerDevice.js";
|
|
10
|
+
import Vector2 from "../../src/core/geom/Vector2.js";
|
|
11
|
+
import TopDownCameraControllerSystem
|
|
12
|
+
from "../../src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
|
|
13
|
+
import { parseHex } from "../../src/core/color/parseHex.js";
|
|
14
|
+
import { obtainTerrain } from "../../src/engine/ecs/terrain/util/obtainTerrain.js";
|
|
15
|
+
import { pick } from "../../src/ecs/grid/pick.js";
|
|
16
|
+
|
|
17
|
+
class GridPaintTool extends Tool {
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
this.name = "grid_paint";
|
|
21
|
+
|
|
22
|
+
this.settings.value = new Vector1(1);
|
|
23
|
+
this.settings.alphaMultiplier = new Vector1(0.15);
|
|
24
|
+
this.settings.color = new ObservedValue("#00FF00");
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
initialize() {
|
|
30
|
+
super.initialize();
|
|
31
|
+
|
|
32
|
+
const engine = this.engine;
|
|
33
|
+
const editor = this.editor;
|
|
34
|
+
|
|
35
|
+
this.terrain = obtainTerrain(engine.entityManager.dataset, function (t, entity) {
|
|
36
|
+
self.terrainEntity = entity;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
this.terrain.overlay.push();
|
|
40
|
+
|
|
41
|
+
this.paint();
|
|
42
|
+
|
|
43
|
+
editor.selection.on.added.add(this.paint, this);
|
|
44
|
+
editor.selection.on.removed.add(this.paint, this);
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
this.settings.value.onChanged.add(this.paint, this);
|
|
48
|
+
this.settings.alphaMultiplier.onChanged.add(this.paint, this);
|
|
49
|
+
this.settings.color.onChanged.add(this.paint, this);
|
|
50
|
+
|
|
51
|
+
this.cameraController = buildCameraController(engine, engine.entityManager);
|
|
52
|
+
this.cameraController.start();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
buildColor() {
|
|
56
|
+
|
|
57
|
+
const color = new Vector4();
|
|
58
|
+
const baseColor = parseHex(this.settings.color.get());
|
|
59
|
+
color.set(baseColor.r, baseColor.g, baseColor.b, 0);
|
|
60
|
+
color.multiplyScalar(1 / 255);
|
|
61
|
+
|
|
62
|
+
return color;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
paint() {
|
|
66
|
+
|
|
67
|
+
const alphaMultiplier = this.settings.alphaMultiplier.getValue();
|
|
68
|
+
const overlay = this.terrain.overlay;
|
|
69
|
+
overlay.clear();
|
|
70
|
+
|
|
71
|
+
const color = this.buildColor();
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @param {GridPosition} gridPosition
|
|
76
|
+
* @param {GridObstacle} obstacle
|
|
77
|
+
* @param {Number} entity
|
|
78
|
+
*/
|
|
79
|
+
function visit(gridPosition, obstacle, entity) {
|
|
80
|
+
obstacle.traverseMask(gridPosition.x, gridPosition.y, function (x, y, value) {
|
|
81
|
+
color.w = value * alphaMultiplier;
|
|
82
|
+
|
|
83
|
+
overlay.clearPoint(x, y);
|
|
84
|
+
overlay.paintPoint(x, y, color);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//initialize overlay
|
|
89
|
+
this.traverse(visit);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
traverse(callback) {
|
|
93
|
+
/**
|
|
94
|
+
* @type {EntityManager}
|
|
95
|
+
*/
|
|
96
|
+
const entityManger = this.engine.entityManager;
|
|
97
|
+
this.editor.selection.forEach(function (entity) {
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
*
|
|
101
|
+
* @type {GridPosition}
|
|
102
|
+
*/
|
|
103
|
+
const gp = entityManger.getComponent(entity, GridPosition);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @type {GridObstacle}
|
|
108
|
+
*/
|
|
109
|
+
const obstacle = entityManger.getComponent(entity, GridObstacle);
|
|
110
|
+
|
|
111
|
+
if (gp === null || obstacle === null) {
|
|
112
|
+
//do nothing
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
callback(gp, obstacle, entity);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
shutdown() {
|
|
120
|
+
this.terrain.overlay.pop();
|
|
121
|
+
|
|
122
|
+
this.editor.selection.on.added.remove(this.paint, this);
|
|
123
|
+
this.editor.selection.on.removed.remove(this.paint, this);
|
|
124
|
+
|
|
125
|
+
this.settings.value.onChanged.remove(this.paint, this);
|
|
126
|
+
this.settings.alphaMultiplier.onChanged.remove(this.paint, this);
|
|
127
|
+
this.settings.color.onChanged.remove(this.paint, this);
|
|
128
|
+
|
|
129
|
+
this.cameraController.stop();
|
|
130
|
+
|
|
131
|
+
super.shutdown();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
affectTile(_x, _y) {
|
|
135
|
+
const x = _x | 0;
|
|
136
|
+
const y = _y | 0;
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
const self = this;
|
|
140
|
+
const alphaMultiplier = this.settings.alphaMultiplier.getValue();
|
|
141
|
+
const paintValue = this.settings.value.getValue();
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
*
|
|
145
|
+
* @param gp
|
|
146
|
+
* @param {GridObstacle} obstacle
|
|
147
|
+
* @param entity
|
|
148
|
+
*/
|
|
149
|
+
function visit(gp, obstacle, entity) {
|
|
150
|
+
|
|
151
|
+
const localX = x - gp.x;
|
|
152
|
+
const localY = y - gp.y;
|
|
153
|
+
|
|
154
|
+
if (!obstacle.isPointWithin(localX, localY)) {
|
|
155
|
+
//painting outside
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const actions = self.editor.actions;
|
|
160
|
+
|
|
161
|
+
const aModifyGrid = new WriteGridValueAction(entity, localX, localY, paintValue);
|
|
162
|
+
|
|
163
|
+
const color = self.buildColor();
|
|
164
|
+
color.w = paintValue * alphaMultiplier;
|
|
165
|
+
|
|
166
|
+
const aPaintGrid = new PaintTerrainOverlayAction(self.terrainEntity, x, y, color);
|
|
167
|
+
|
|
168
|
+
actions.do(aModifyGrid);
|
|
169
|
+
actions.do(aPaintGrid);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
this.traverse(visit);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
affectTileByMousePosition(position) {
|
|
176
|
+
const engine = this.engine;
|
|
177
|
+
|
|
178
|
+
const self = this;
|
|
179
|
+
|
|
180
|
+
pick(position.x, position.y, engine.graphics, this.terrain, function (gridPosition) {
|
|
181
|
+
self.affectTile(gridPosition.x, gridPosition.y);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
start() {
|
|
186
|
+
this.editor.actions.mark('Paining Tiles');
|
|
187
|
+
this.update();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
update() {
|
|
191
|
+
if (this.isRunning()) {
|
|
192
|
+
const p = new Vector2(0, 0);
|
|
193
|
+
this.engine.gameView.positionGlobalToLocal(this.engine.devices.pointer.position, p);
|
|
194
|
+
this.affectTileByMousePosition(p);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
*
|
|
201
|
+
* @param {Engine} engine
|
|
202
|
+
* @param {EntityManager} em
|
|
203
|
+
* @returns {{start: function, stop: function}}
|
|
204
|
+
*/
|
|
205
|
+
function buildCameraController(engine, em) {
|
|
206
|
+
const TopDownCameraController = em.getComponentClassByName("TopDownCameraController");
|
|
207
|
+
const system = em.getSystem(TopDownCameraControllerSystem);
|
|
208
|
+
system.enabled.set(true);
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
let cameraController = null;
|
|
212
|
+
em.traverseEntities([TopDownCameraController], function (c) {
|
|
213
|
+
cameraController = c;
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const pointerDevice = new PointerDevice(window);
|
|
217
|
+
pointerDevice.on.drag.add(function (position, origin, previousPosition, mouseEvent) {
|
|
218
|
+
const buttons = mouseEvent.buttons;
|
|
219
|
+
const pressedButtons = decodeMouseEventButtons(buttons);
|
|
220
|
+
if (pressedButtons[2]) {
|
|
221
|
+
const camera = engine.graphics.camera;
|
|
222
|
+
TopDownCameraController.pan(previousPosition.clone().sub(position), camera, engine.graphics.domElement, cameraController.distance, camera.fov, cameraController.target);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
pointerDevice.on.wheel.add(function (delta) {
|
|
227
|
+
cameraController.distance += delta.y / 70;
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
function start() {
|
|
231
|
+
system.enabled.set(true);
|
|
232
|
+
pointerDevice.start();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function stop() {
|
|
236
|
+
system.enabled.set(false);
|
|
237
|
+
pointerDevice.stop();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
start,
|
|
242
|
+
stop
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
export default GridPaintTool;
|