@woosh/meep-engine 2.46.29 → 2.46.31

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.
Files changed (169) hide show
  1. package/editor/Editor.js +793 -0
  2. package/editor/SelectionVisualizer.js +148 -0
  3. package/editor/actions/concrete/ActionUpdateTexture.js +21 -0
  4. package/editor/actions/concrete/ArrayCopyAction.js +39 -0
  5. package/editor/actions/concrete/ComponentAddAction.js +47 -0
  6. package/editor/actions/concrete/ComponentRemoveAction.js +38 -0
  7. package/editor/actions/concrete/EntityCreateAction.js +47 -0
  8. package/editor/actions/concrete/EntityRemoveAction.js +51 -0
  9. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +118 -0
  10. package/editor/actions/concrete/ModifyPatchSampler2DAction.spec.js +30 -0
  11. package/editor/actions/concrete/ModifyPatchTextureArray2DAction.js +182 -0
  12. package/editor/actions/concrete/PaintTerrainOverlayAction.js +45 -0
  13. package/editor/actions/concrete/PatchTerrainHeightAction.js +67 -0
  14. package/editor/actions/concrete/PatchTerrainTextureAction.js +152 -0
  15. package/editor/actions/concrete/SelectionAddAction.js +36 -0
  16. package/editor/actions/concrete/SelectionClearAction.js +22 -0
  17. package/editor/actions/concrete/SelectionRemoveAction.js +30 -0
  18. package/editor/actions/concrete/TransformModifyAction.js +46 -0
  19. package/editor/actions/concrete/WriteGridValueAction.js +46 -0
  20. package/editor/ecs/EditorEntity.js +12 -0
  21. package/editor/ecs/EditorEntitySystem.js +14 -0
  22. package/editor/ecs/component/FieldDescriptor.js +34 -0
  23. package/editor/ecs/component/FieldValueAdapter.js +20 -0
  24. package/editor/ecs/component/TypeEditor.js +33 -0
  25. package/editor/ecs/component/TypeSchema.d.ts +38 -0
  26. package/editor/ecs/component/createFieldEditor.js +92 -0
  27. package/editor/ecs/component/createObjectEditor.js +361 -0
  28. package/editor/ecs/component/editors/ColorEditor.js +39 -0
  29. package/editor/ecs/component/editors/HTMLElementEditor.js +17 -0
  30. package/editor/ecs/component/editors/ImagePathEditor.js +82 -0
  31. package/editor/ecs/component/editors/LargeStrongEditor.js +107 -0
  32. package/editor/ecs/component/editors/NumericIntervalEditor.js +86 -0
  33. package/editor/ecs/component/editors/ObservedBooleanEditor.js +13 -0
  34. package/editor/ecs/component/editors/ObservedEnumEditor.js +32 -0
  35. package/editor/ecs/component/editors/ObservedIntegerEditor.js +43 -0
  36. package/editor/ecs/component/editors/ObservedStringEditor.js +51 -0
  37. package/editor/ecs/component/editors/Sampler2DEditor.js +221 -0
  38. package/editor/ecs/component/editors/collection/ListEditor.js +83 -0
  39. package/editor/ecs/component/editors/common/BitFlagsEditor.js +80 -0
  40. package/editor/ecs/component/editors/common/EnumEditor.js +41 -0
  41. package/editor/ecs/component/editors/common/makeV3_editor.js +85 -0
  42. package/editor/ecs/component/editors/common/noEditor.js +9 -0
  43. package/editor/ecs/component/editors/ecs/GridObstacleEditor.js +17 -0
  44. package/editor/ecs/component/editors/ecs/MinimapMarkerEditor.js +16 -0
  45. package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.js +225 -0
  46. package/editor/ecs/component/editors/ecs/ParameterTrackEditor.js +17 -0
  47. package/editor/ecs/component/editors/ecs/ParameterTrackSetEditor.js +18 -0
  48. package/editor/ecs/component/editors/ecs/ParticleEmitterEditor.js +58 -0
  49. package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.js +58 -0
  50. package/editor/ecs/component/editors/ecs/SimulationStepDefinitionEditor.js +21 -0
  51. package/editor/ecs/component/editors/ecs/Trail2DEditor.js +33 -0
  52. package/editor/ecs/component/editors/ecs/TransformEditor.js +23 -0
  53. package/editor/ecs/component/editors/ecs/terrain/SplatMappingEditor.js +21 -0
  54. package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +95 -0
  55. package/editor/ecs/component/editors/ecs/terrain/TerrainLayerEditor.js +18 -0
  56. package/editor/ecs/component/editors/ecs/terrain/TerrainLayersEditor.js +22 -0
  57. package/editor/ecs/component/editors/ecs/terrain/TerrainOverlayEditor.js +20 -0
  58. package/editor/ecs/component/editors/geom/QuaternionEditor.js +63 -0
  59. package/editor/ecs/component/editors/geom/Vector1Editor.js +57 -0
  60. package/editor/ecs/component/editors/geom/Vector2Editor.js +11 -0
  61. package/editor/ecs/component/editors/geom/Vector3Editor.js +13 -0
  62. package/editor/ecs/component/editors/geom/Vector4Editor.js +12 -0
  63. package/editor/ecs/component/editors/primitive/ArrayEditor.js +46 -0
  64. package/editor/ecs/component/editors/primitive/BooleanEditor.js +27 -0
  65. package/editor/ecs/component/editors/primitive/FunctionEditor.js +29 -0
  66. package/editor/ecs/component/editors/primitive/NumberEditor.js +60 -0
  67. package/editor/ecs/component/editors/primitive/ObjectEditor.js +12 -0
  68. package/editor/ecs/component/editors/primitive/StringEditor.js +31 -0
  69. package/editor/ecs/component/editors/three/BufferGeometryEditor.js +28 -0
  70. package/editor/ecs/component/editors/three/MaterialEditor.js +27 -0
  71. package/editor/ecs/component/editors/three/MeshEditor.js +35 -0
  72. package/editor/ecs/component/editors/three/TextureEditor.js +112 -0
  73. package/editor/ecs/component/findNearestRegisteredType.js +59 -0
  74. package/editor/ecs/component/prototypeObjectEditor.js +379 -0
  75. package/editor/enableEditor.js +85 -0
  76. package/editor/library/MeshLibrary.js +33 -0
  77. package/editor/process/DisableGameUIProcess.js +43 -0
  78. package/editor/process/EditorProcess.js +35 -0
  79. package/editor/process/ObstacleGridDisplayProcess.js +120 -0
  80. package/editor/process/ProcessEngine.js +123 -0
  81. package/editor/process/SymbolicDisplayProcess.js +132 -0
  82. package/editor/process/symbolic/ComponentSymbolicDisplay.js +34 -0
  83. package/editor/process/symbolic/SymbolicDisplayInternalAPI.js +159 -0
  84. package/editor/process/symbolic/buildThreeJSHelperEntity.js +36 -0
  85. package/editor/process/symbolic/make3DSymbolicDisplay.js +91 -0
  86. package/editor/process/symbolic/makeCameraSymbolicDisplay.js +32 -0
  87. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +176 -0
  88. package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
  89. package/editor/process/symbolic/makeHelperSphereGeometry.js +73 -0
  90. package/editor/process/symbolic/makeLightSymbolicDisplay.js +77 -0
  91. package/editor/process/symbolic/makeParticleEmitterSymbolicDisplay.js +146 -0
  92. package/editor/process/symbolic/makePathSymbolicDisplay.js +105 -0
  93. package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +74 -0
  94. package/editor/process/symbolic/makeSocketsSymbolicDisplay.js +153 -0
  95. package/editor/process/symbolic/makeSolidArrowGeometry.js +391 -0
  96. package/editor/process/symbolic/makeSoundEmitterSymbolicDisplay.js +89 -0
  97. package/editor/process/symbolic/makeStoryTriggerSetAreaDisplay.js +114 -0
  98. package/editor/process/symbolic/synchronizeTransform.js +50 -0
  99. package/editor/tools/FoliagePaintTool.js +168 -0
  100. package/editor/tools/GridPaintTool.js +247 -0
  101. package/editor/tools/SelectionTool.js +407 -0
  102. package/editor/tools/TopDownCameraControlTool.js +59 -0
  103. package/editor/tools/TransformTool.js +370 -0
  104. package/editor/tools/engine/Tool.js +121 -0
  105. package/editor/tools/engine/ToolEngine.js +193 -0
  106. package/editor/tools/engine/ToolState.js +9 -0
  107. package/editor/tools/engine/ToolStateMachine.js +53 -0
  108. package/editor/tools/paint/TerrainHeightPaintTool.js +297 -0
  109. package/editor/tools/paint/TerrainPaintTool.js +211 -0
  110. package/editor/tools/paint/TerrainTexturePaintTool.js +193 -0
  111. package/editor/tools/paint/prototypeTerrainEditor.js +135 -0
  112. package/editor/tools/v2/BlenderCameraOrientationGizmo.d.ts +50 -0
  113. package/editor/tools/v2/BlenderCameraOrientationGizmo.js +500 -0
  114. package/editor/tools/v2/TransformControls.d.ts +20 -0
  115. package/editor/tools/v2/TransformControls.js +1782 -0
  116. package/editor/tools/v2/prototypeTransformControls.js +92 -0
  117. package/editor/view/EditorView.js +462 -0
  118. package/editor/view/GridPickCoordinateView.js +88 -0
  119. package/editor/view/ecs/ComponentControlFactory.js +48 -0
  120. package/editor/view/ecs/ComponentControlView.js +214 -0
  121. package/editor/view/ecs/EntityEditor.js +258 -0
  122. package/editor/view/ecs/EntityList.js +258 -0
  123. package/editor/view/ecs/components/BlackboardController.js +50 -0
  124. package/editor/view/ecs/components/DatGuiController.js +216 -0
  125. package/editor/view/ecs/components/FogOfWarController.js +78 -0
  126. package/editor/view/ecs/components/FogOfWarRevealerController.js +44 -0
  127. package/editor/view/ecs/components/GeneratedArmyController.js +42 -0
  128. package/editor/view/ecs/components/GridObstacleController.js +72 -0
  129. package/editor/view/ecs/components/GridPositionController.js +40 -0
  130. package/editor/view/ecs/components/HeadsUpDisplayController.js +30 -0
  131. package/editor/view/ecs/components/HighlightController.js +47 -0
  132. package/editor/view/ecs/components/MeshController.js +125 -0
  133. package/editor/view/ecs/components/PathFollowerController.js +87 -0
  134. package/editor/view/ecs/components/TagController.js +80 -0
  135. package/editor/view/ecs/components/TerrainController.js +225 -0
  136. package/editor/view/ecs/components/TransformController.js +103 -0
  137. package/editor/view/ecs/components/UnitShopController.js +112 -0
  138. package/editor/view/ecs/components/army/ArmyController.js +130 -0
  139. package/editor/view/ecs/components/color/GaugeView.js +107 -0
  140. package/editor/view/ecs/components/common/AutoCanvasView.js +53 -0
  141. package/editor/view/ecs/components/common/LineView.js +17 -0
  142. package/editor/view/ecs/components/common/NumberController.js +112 -0
  143. package/editor/view/ecs/components/common/NumericIntervalController.js +64 -0
  144. package/editor/view/ecs/components/gui/GUIElementController.js +117 -0
  145. package/editor/view/ecs/components/items/ItemContainerController.js +132 -0
  146. package/editor/view/ecs/components/items/ItemContainerController.stories.js +50 -0
  147. package/editor/view/ecs/components/items/ItemController.js +52 -0
  148. package/editor/view/ecs/components/particles/ColorParameterLUTController.js +444 -0
  149. package/editor/view/ecs/components/particles/ParameterTrackController.js +51 -0
  150. package/editor/view/ecs/components/particles/ParticleEmitterController.js +213 -0
  151. package/editor/view/ecs/components/particles/ParticleLayerController.js +213 -0
  152. package/editor/view/ecs/components/particles/ScalarParameterLUTController.js +401 -0
  153. package/editor/view/ecs/components/sockets/AttachmentSocketsController.js +51 -0
  154. package/editor/view/ecs/components/sound/SoundEmitterController.js +137 -0
  155. package/editor/view/ecs/components/story/StoryTriggerSetController.js +214 -0
  156. package/editor/view/ecs/components/unit/AuraController.js +45 -0
  157. package/editor/view/library/MeshLibraryView.js +164 -0
  158. package/editor/view/node-graph/NodeGraphEditorView.js +170 -0
  159. package/editor/view/node-graph/NodeGraphView.js +453 -0
  160. package/editor/view/node-graph/NodeView.js +135 -0
  161. package/editor/view/node-graph/PortView.js +69 -0
  162. package/editor/view/process/ProcessView.js +63 -0
  163. package/editor/view/tools/ToolSettingsView.js +143 -0
  164. package/editor/view/tools/ToolView.js +58 -0
  165. package/package.json +2 -1
  166. package/src/engine/intelligence/behavior/composite/CompositeBehavior.js +18 -2
  167. package/src/engine/intelligence/behavior/composite/ParallelBehavior.js +21 -9
  168. package/src/engine/intelligence/behavior/composite/SequenceBehavior.js +5 -1
  169. package/src/engine/intelligence/behavior/util/DelayBehavior.js +8 -3
@@ -0,0 +1,148 @@
1
+ import { BoxHelper, Group } from 'three';
2
+ import Mesh from "../src/engine/graphics/ecs/mesh/Mesh.js";
3
+ import { SignalBinding } from "../src/core/events/signal/SignalBinding.js";
4
+ import { MeshEvents } from "../src/engine/graphics/ecs/mesh/MeshEvents.js";
5
+
6
+
7
+ /**
8
+ *
9
+ * @param entity
10
+ * @param {EntityManager} entityManager
11
+ * @constructor
12
+ */
13
+ function SelectionContainer(entity, entityManager) {
14
+ this.entity = entity;
15
+ this.entityManager = entityManager;
16
+
17
+ this.isLinked = false;
18
+
19
+ const boxHelper = new BoxHelper();
20
+ boxHelper.material.depthTest = true;
21
+ boxHelper.material.transparent = true;
22
+
23
+ this.boxHelper = boxHelper;
24
+
25
+ const self = this;
26
+
27
+ function updateMesh() {
28
+ const mesh = entityManager.getComponent(entity, Mesh);
29
+
30
+ if (mesh !== null && mesh !== undefined && mesh.hasMesh()) {
31
+ boxHelper.setFromObject(mesh.mesh);
32
+ boxHelper.visible = true;
33
+ } else {
34
+ boxHelper.visible = false;
35
+ }
36
+ }
37
+
38
+ function updateBox() {
39
+ boxHelper.update();
40
+ }
41
+
42
+ function animationLoop() {
43
+ if (!self.isLinked) {
44
+ return;
45
+ }
46
+ updateBox();
47
+ requestAnimationFrame(animationLoop);
48
+ }
49
+
50
+ updateMesh();
51
+
52
+ this.handlers = {
53
+ updateMesh,
54
+ animationLoop
55
+ };
56
+ }
57
+
58
+ SelectionContainer.prototype.link = function () {
59
+ this.isLinked = true;
60
+ this.handlers.animationLoop();
61
+
62
+ this.entityManager.addEntityEventListener(this.entity, MeshEvents.DataSet, this.handlers.updateMesh);
63
+ };
64
+
65
+ SelectionContainer.prototype.unlink = function () {
66
+ this.isLinked = false;
67
+
68
+ this.entityManager.removeEntityEventListener(this.entity, MeshEvents.DataSet, this.handlers.updateMesh);
69
+ };
70
+
71
+ /**
72
+ *
73
+ * @param {Editor} editor
74
+ * @constructor
75
+ */
76
+ function SelectionVisualizer(editor) {
77
+ this.editor = editor;
78
+
79
+ /**
80
+ *
81
+ * @returns {EntityManager}
82
+ */
83
+ function getEM() {
84
+ return editor.engine.entityManager;
85
+ }
86
+
87
+
88
+ const group = this.group = new Group();
89
+
90
+ const containers = [];
91
+
92
+ function addEntity(entity) {
93
+ //try to get a transform
94
+
95
+ const em = getEM();
96
+
97
+ const container = new SelectionContainer(entity, em);
98
+ container.link();
99
+ containers[entity] = container;
100
+
101
+ group.add(container.boxHelper);
102
+ }
103
+
104
+ function removeEntity(entity) {
105
+ const container = containers[entity];
106
+ if (container === undefined) {
107
+ console.error(`Failed to un-select entity ${entity}, it no container was registered.`);
108
+ return;
109
+ }
110
+ container.unlink();
111
+ delete containers[entity];
112
+
113
+ group.remove(container.boxHelper);
114
+ }
115
+
116
+ this.handlers = {
117
+ addEntity,
118
+ removeEntity
119
+ };
120
+
121
+ this.bindings = [
122
+ new SignalBinding(editor.selection.on.added, addEntity),
123
+ new SignalBinding(editor.selection.on.removed, removeEntity)
124
+ ]
125
+ }
126
+
127
+ SelectionVisualizer.prototype.startup = function () {
128
+ this.editor.engine.graphics.scene.add(this.group);
129
+
130
+ this.editor.selection.forEach(this.handlers.addEntity);
131
+
132
+ this.bindings.forEach(function (b) {
133
+ b.link();
134
+ });
135
+ };
136
+
137
+ SelectionVisualizer.prototype.shutdown = function () {
138
+ this.editor.engine.graphics.scene.remove(this.group);
139
+
140
+
141
+ this.editor.selection.forEach(this.handlers.removeEntity);
142
+
143
+ this.bindings.forEach(function (b) {
144
+ b.unlink();
145
+ });
146
+ };
147
+
148
+ export { SelectionVisualizer };
@@ -0,0 +1,21 @@
1
+ import { Action } from "../../../src/core/process/undo/Action.js";
2
+
3
+ export class ActionUpdateTexture extends Action {
4
+ /**
5
+ *
6
+ * @param {THREE.Texture} texture
7
+ */
8
+ constructor(texture) {
9
+ super();
10
+
11
+ this.__texture = texture;
12
+ }
13
+
14
+ async apply(context) {
15
+ this.__texture.needsUpdate = true;
16
+ }
17
+
18
+ async revert(context) {
19
+ this.__texture.needsUpdate = true;
20
+ }
21
+ }
@@ -0,0 +1,39 @@
1
+ import { Action } from "../../../src/core/process/undo/Action.js";
2
+ import { array_copy } from "../../../src/core/collection/array/copyArray.js";
3
+
4
+ export class ArrayCopyAction extends Action {
5
+ /**
6
+ * @template T
7
+ * @param {ArrayLike<T>|T[]|Uint8Array|Float32Array} source
8
+ * @param {ArrayLike<T>|T[]|Uint8Array|Float32Array} destination
9
+ */
10
+ constructor(source, destination) {
11
+ super();
12
+
13
+ this.__source = source;
14
+ this.__destination = destination;
15
+
16
+ /**
17
+ *
18
+ * @type {ArrayLike<T>|null}
19
+ * @private
20
+ */
21
+ this.__restore_value = null;
22
+ }
23
+
24
+ async apply(context) {
25
+
26
+ const CTOR = Object.getPrototypeOf(this.__destination).constructor;
27
+ this.__restore_value = new CTOR(this.__destination.length);
28
+
29
+ // remember old value
30
+ array_copy(this.__destination, 0, this.__restore_value, 0, this.__destination.length);
31
+
32
+ // copy data across
33
+ array_copy(this.__source, 0, this.__destination, 0, this.__source.length);
34
+ }
35
+
36
+ async revert(context) {
37
+ array_copy(this.__restore_value, 0, this.__destination, 0, this.__restore_value.length);
38
+ }
39
+ }
@@ -0,0 +1,47 @@
1
+ import { Action } from "../../../src/core/process/undo/Action.js";
2
+
3
+ class ComponentAddAction extends Action {
4
+ /**
5
+ * Created by Alex on 16/01/2017.
6
+ */
7
+ constructor(entity, component) {
8
+ super();
9
+ this.entity = entity;
10
+ this.component = component;
11
+ /**
12
+ *
13
+ * @type {EntityComponentDataset}
14
+ */
15
+ this.dataset = null;
16
+ }
17
+
18
+ async apply(editor) {
19
+ /**
20
+ * @type {EntityManager}
21
+ */
22
+ const em = editor.engine.entityManager;
23
+
24
+ /**
25
+ *
26
+ * @type {EntityComponentDataset}
27
+ */
28
+ const dataset = em.dataset;
29
+
30
+ this.dataset = dataset;
31
+
32
+ const clazz = this.component.constructor;
33
+
34
+ if (dataset.getComponent(this.entity, clazz)) {
35
+ throw new Error(`entity ${this.entity} already has a '${clazz.typeName}' component`);
36
+ }
37
+
38
+ dataset.addComponentToEntity(this.entity, this.component);
39
+ }
40
+
41
+ async revert(editor) {
42
+ const clazz = this.component.constructor;
43
+ this.dataset.removeComponentFromEntity(this.entity, clazz);
44
+ }
45
+ }
46
+
47
+ export default ComponentAddAction;
@@ -0,0 +1,38 @@
1
+ import { Action } from "../../../src/core/process/undo/Action.js";
2
+
3
+ /**
4
+ * Created by Alex on 16/01/2017.
5
+ * TODO update
6
+ */
7
+ class ComponentRemoveAction extends Action {
8
+ constructor(entity, componentType) {
9
+ super();
10
+
11
+ this.entity = entity;
12
+ this.componentType = componentType;
13
+ this.component = null;
14
+ }
15
+
16
+ async apply(editor) {
17
+ /**
18
+ * @type {Engine}
19
+ */
20
+ const engine = editor.engine;
21
+
22
+ const em = engine.entityManager;
23
+
24
+ /**
25
+ * @type {EntityComponentDataset}
26
+ */
27
+ const ecd = em.dataset;
28
+
29
+ this.component = ecd.removeComponentFromEntity(this.entity, this.componentType);
30
+ }
31
+
32
+ async revert(editor) {
33
+ const em = editor.engine.entityManager;
34
+ em.addComponentToEntity(this.entity, this.component);
35
+ }
36
+ }
37
+
38
+ export default ComponentRemoveAction;
@@ -0,0 +1,47 @@
1
+ import { Action } from "../../../src/core/process/undo/Action.js";
2
+
3
+ class EntityCreateAction extends Action {
4
+ /**
5
+ * Created by Alex on 16/01/2017.
6
+ */
7
+ constructor() {
8
+ super();
9
+ /**
10
+ *
11
+ * @type {number|null}
12
+ */
13
+ this.entity = null;
14
+
15
+ /**
16
+ *
17
+ * @type {EntityComponentDataset}
18
+ */
19
+ this.ecd = null;
20
+ }
21
+
22
+ async apply(editor) {
23
+ if (this.ecd === null) {
24
+ /**
25
+ * @type {EntityManager}
26
+ */
27
+ const em = editor.engine.entityManager;
28
+
29
+ const ecd = em.dataset;
30
+
31
+ this.ecd = ecd;
32
+ }
33
+
34
+
35
+ if (this.entity === null) {
36
+ this.entity = this.ecd.createEntity();
37
+ } else {
38
+ this.ecd.createEntitySpecific(this.entity);
39
+ }
40
+ }
41
+
42
+ async revert(editor) {
43
+ this.ecd.removeEntity(this.entity);
44
+ }
45
+ }
46
+
47
+ export default EntityCreateAction;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Created by Alex on 16/01/2017.
3
+ */
4
+
5
+ import { Action } from "../../../src/core/process/undo/Action.js";
6
+
7
+ /**
8
+ * @extends {Action<Editor>}
9
+ */
10
+ class EntityRemoveAction extends Action {
11
+ constructor(entity) {
12
+ super();
13
+ this.entity = entity;
14
+ this.components = [];
15
+ }
16
+
17
+ /**
18
+ *
19
+ * @param {Editor} editor
20
+ */
21
+ async apply(editor) {
22
+ const em = editor.engine.entityManager;
23
+
24
+ const ecd = em.dataset;
25
+
26
+ this.components = ecd.getAllComponents(this.entity);
27
+
28
+ ecd.removeEntity(this.entity);
29
+ }
30
+
31
+ /**
32
+ *
33
+ * @param {Editor} editor
34
+ */
35
+ async revert(editor) {
36
+ const em = editor.engine.entityManager;
37
+
38
+ const ecd = em.dataset;
39
+
40
+ ecd.createEntitySpecific(this.entity);
41
+
42
+ for (let i = 0; i < this.components.length; i++) {
43
+ const c = this.components[i];
44
+ if (c !== undefined) {
45
+ ecd.addComponentToEntityByIndex(this.entity, i, c);
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ export default EntityRemoveAction;
@@ -0,0 +1,118 @@
1
+ import { Action } from "../../../src/core/process/undo/Action.js";
2
+ import { Sampler2D } from "../../../src/engine/graphics/texture/sampler/Sampler2D.js";
3
+
4
+ export class ModifyPatchSampler2DAction extends Action {
5
+ /**
6
+ *
7
+ * @param {Sampler2D} sampler
8
+ * @param {number[]} bounds
9
+ */
10
+ constructor(sampler, bounds) {
11
+ super();
12
+
13
+ /**
14
+ *
15
+ * @type {Sampler2D}
16
+ * @private
17
+ */
18
+ this.__sampler = sampler;
19
+
20
+ /**
21
+ *
22
+ * @type {number[]}
23
+ * @private
24
+ */
25
+ this.__bounds = bounds;
26
+
27
+ const width = this.__bounds[2] - this.__bounds[0];
28
+ const height = this.__bounds[3] - this.__bounds[1];
29
+
30
+ /**
31
+ *
32
+ * @type {Sampler2D}
33
+ */
34
+ this.__patch_new = Sampler2D.float32(sampler.itemSize, width, height);
35
+
36
+ /**
37
+ *
38
+ * @type {Sampler2D}
39
+ * @private
40
+ */
41
+ this.__patch_old = Sampler2D.float32(sampler.itemSize, width, height);
42
+ }
43
+
44
+ get patch() {
45
+ return this.__patch_new;
46
+ }
47
+
48
+ get x() {
49
+ return this.__bounds[0];
50
+ }
51
+
52
+ get y() {
53
+ return this.__bounds[1];
54
+ }
55
+
56
+ /**
57
+ *
58
+ * @param {number} x coordinate in global space
59
+ * @param {number} y coordinate in global space
60
+ * @param {number} [channel]
61
+ * @returns {number} delta between original value and the new one after the change
62
+ */
63
+ computeDelta(x, y, channel = 0) {
64
+ const _x = x - this.x;
65
+
66
+ if (_x < 0 || _x > this.__patch_new.width - 1) {
67
+ return 0;
68
+ }
69
+
70
+ const _y = y - this.y;
71
+
72
+ if (_y < 0 || _y > this.__patch_new.height - 1) {
73
+ return 0;
74
+ }
75
+
76
+ const value_old = this.__patch_old.sampleChannelBilinear(_x, _y, channel);
77
+ const value_new = this.__patch_new.sampleChannelBilinear(_x, _y, channel);
78
+
79
+ return value_new - value_old;
80
+ }
81
+
82
+ computeByteSize() {
83
+ return this.__patch_new.computeByteSize() + this.__patch_old.computeByteSize() + 280;
84
+ }
85
+
86
+
87
+ async apply(context) {
88
+
89
+ /**
90
+ *
91
+ * @type {Sampler2D}
92
+ */
93
+ const source = this.__sampler;
94
+
95
+ //store old data from the patch
96
+ const patch_old = this.__patch_old;
97
+
98
+ patch_old.copy_sameItemSize(source, this.x, this.y, 0, 0, patch_old.width, patch_old.height);
99
+
100
+ const patch_new = this.__patch_new;
101
+
102
+ //apply the patch
103
+ source.copy_sameItemSize(patch_new, 0, 0, this.x, this.y, patch_new.width, patch_new.height);
104
+ }
105
+
106
+ async revert(context) {
107
+ /**
108
+ *
109
+ * @type {Sampler2D}
110
+ */
111
+ const source = this.__sampler;
112
+
113
+ const patch_old = this.__patch_old;
114
+
115
+ //apply the patch
116
+ source.copy_sameItemSize(patch_old, 0, 0, this.x, this.y, patch_old.width, patch_old.height);
117
+ }
118
+ }
@@ -0,0 +1,30 @@
1
+ import { ModifyPatchSampler2DAction } from "./ModifyPatchSampler2DAction.js";
2
+ import { Sampler2D } from "../../../src/engine/graphics/texture/sampler/Sampler2D.js";
3
+
4
+ test("apply patch size 0", async () => {
5
+ const sampler = Sampler2D.uint8(1, 1, 1);
6
+ sampler.data[0] = 123;
7
+
8
+ const action = new ModifyPatchSampler2DAction(sampler, [0, 0, 0, 0]);
9
+
10
+ await action.apply();
11
+
12
+ expect([...sampler.data]).toEqual([123]);
13
+ });
14
+
15
+ test("apply patch size 1, fill entire", async () => {
16
+ const sampler = Sampler2D.uint8(1, 1, 1);
17
+ sampler.data[0] = 123;
18
+
19
+ const action = new ModifyPatchSampler2DAction(sampler, [0, 0, 1, 1]);
20
+
21
+ action.patch.data[0] = 42;
22
+
23
+ await action.apply();
24
+
25
+ expect([...sampler.data]).toEqual([42]);
26
+
27
+ await action.revert();
28
+
29
+ expect([...sampler.data]).toEqual([123]);
30
+ });