@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,53 @@
|
|
|
1
|
+
import { DomSizeObserver } from "../../../../../src/view/util/DomSizeObserver.js";
|
|
2
|
+
import { CanvasView } from "../../../../../src/view/elements/CanvasView.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Automatically tracks size on the screen, including that computed from CSS and - re-renders content when size changes
|
|
6
|
+
* @extends View
|
|
7
|
+
*/
|
|
8
|
+
export class AutoCanvasView extends CanvasView {
|
|
9
|
+
constructor({ classList = [] } = {}) {
|
|
10
|
+
super();
|
|
11
|
+
|
|
12
|
+
this.addClasses(classList);
|
|
13
|
+
|
|
14
|
+
const sizeObserver = new DomSizeObserver();
|
|
15
|
+
this.__sizeObserver = sizeObserver;
|
|
16
|
+
|
|
17
|
+
const size = sizeObserver.dimensions.size;
|
|
18
|
+
|
|
19
|
+
// subscribe to visual dimension changes
|
|
20
|
+
size.onChanged.add(this.render, this);
|
|
21
|
+
|
|
22
|
+
sizeObserver.watchView(this);
|
|
23
|
+
this.on.linked.add(this.render,this);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
render() {
|
|
27
|
+
const dimensions = this.__sizeObserver.dimensions;
|
|
28
|
+
const size = dimensions.size;
|
|
29
|
+
|
|
30
|
+
const width = size.x;
|
|
31
|
+
const height = size.y;
|
|
32
|
+
|
|
33
|
+
if (width <= 0 || height <= 0) {
|
|
34
|
+
//canvas too small
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// resize canvas as necessary
|
|
39
|
+
this.size.set(width, height);
|
|
40
|
+
|
|
41
|
+
this.draw(this.context2d, width, height);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
47
|
+
* @param {number} width
|
|
48
|
+
* @param {number} height
|
|
49
|
+
*/
|
|
50
|
+
draw(ctx, width, height) {
|
|
51
|
+
//override this method
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import View from "../../../../../src/view/View.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @extends {View}
|
|
5
|
+
*/
|
|
6
|
+
export class LineView extends View {
|
|
7
|
+
constructor({ elements = [], classList = [] }) {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.el = document.createElement('div');
|
|
11
|
+
this.addClass('ui-line-view');
|
|
12
|
+
|
|
13
|
+
classList.forEach(c => this.addClass(c));
|
|
14
|
+
|
|
15
|
+
elements.forEach(e => this.addChild(e));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import View from "../../../../../src/view/View.js";
|
|
2
|
+
import Vector1 from "../../../../../src/core/geom/Vector1.js";
|
|
3
|
+
|
|
4
|
+
const DEFAULT_VALUE = 0;
|
|
5
|
+
|
|
6
|
+
export class NumberController extends View {
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {string[]} [classList]
|
|
10
|
+
* @param {number} [value]
|
|
11
|
+
* @param figures
|
|
12
|
+
*/
|
|
13
|
+
constructor({ classList = [], value = 0, figures = 6 } = {}) {
|
|
14
|
+
super();
|
|
15
|
+
|
|
16
|
+
const _value = new Vector1(value);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @type {Vector1}
|
|
21
|
+
*/
|
|
22
|
+
this.value = _value;
|
|
23
|
+
|
|
24
|
+
const el = document.createElement('input');
|
|
25
|
+
this.el = el;
|
|
26
|
+
|
|
27
|
+
this.addClasses(classList);
|
|
28
|
+
|
|
29
|
+
el.setAttribute('type', 'text');
|
|
30
|
+
el.setAttribute('spellcheck', false);
|
|
31
|
+
el.setAttribute('size', 2);
|
|
32
|
+
|
|
33
|
+
el.classList.add('ui-number-controller');
|
|
34
|
+
|
|
35
|
+
let lockForward = false;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {number} num_value
|
|
41
|
+
* @return {string}
|
|
42
|
+
*/
|
|
43
|
+
function format_value_string(num_value) {
|
|
44
|
+
|
|
45
|
+
let str = String(num_value);
|
|
46
|
+
|
|
47
|
+
if (Math.abs(num_value) > 0 && Math.abs(num_value % 1).toString().length > (figures + 2)) {
|
|
48
|
+
const long_form = num_value.toFixed(figures);
|
|
49
|
+
|
|
50
|
+
const separator_index = long_form.indexOf('.');
|
|
51
|
+
|
|
52
|
+
if (separator_index !== -1) {
|
|
53
|
+
// has a decimal fraction, remove trailing zeroes
|
|
54
|
+
let i = long_form.length - 1;
|
|
55
|
+
|
|
56
|
+
while (i > 0 && long_form.charAt(i) === "0") {
|
|
57
|
+
i--;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (long_form.charAt(i) === '.') {
|
|
61
|
+
i--;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
str = long_form.slice(0, i + 1);
|
|
65
|
+
} else {
|
|
66
|
+
str = long_form;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return str;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function data2view() {
|
|
74
|
+
|
|
75
|
+
if (lockForward) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const num_value = _value.getValue();
|
|
80
|
+
|
|
81
|
+
el.value = format_value_string(num_value);
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function view2data() {
|
|
86
|
+
lockForward = true;
|
|
87
|
+
|
|
88
|
+
const value = parseFloat(el.value);
|
|
89
|
+
|
|
90
|
+
if (Number.isNaN(value)) {
|
|
91
|
+
_value.set(DEFAULT_VALUE);
|
|
92
|
+
} else {
|
|
93
|
+
_value.set(value);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
lockForward = false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Input field stops being edited
|
|
101
|
+
*/
|
|
102
|
+
function handle_blur() {
|
|
103
|
+
// reformat contents of the input field
|
|
104
|
+
el.value = format_value_string(_value.getValue());
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
_value.process(data2view);
|
|
108
|
+
|
|
109
|
+
el.addEventListener('input', view2data);
|
|
110
|
+
el.addEventListener('blur', handle_blur);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { max2 } from "../../../../../src/core/math/max2.js";
|
|
2
|
+
import { min2 } from "../../../../../src/core/math/min2.js";
|
|
3
|
+
import View from "../../../../../src/view/View.js";
|
|
4
|
+
import LabelView from "../../../../../src/view/common/LabelView.js";
|
|
5
|
+
import { NumberController } from "./NumberController.js";
|
|
6
|
+
|
|
7
|
+
export class NumericIntervalController extends View {
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {NumericInterval} interval
|
|
11
|
+
* @param {string} tag
|
|
12
|
+
*/
|
|
13
|
+
constructor({ interval, tag = 'div' }) {
|
|
14
|
+
super();
|
|
15
|
+
|
|
16
|
+
this.el = document.createElement(tag);
|
|
17
|
+
this.addClass('ui-numeric-interval-controller');
|
|
18
|
+
|
|
19
|
+
const vMin = new NumberController({ classList: ['min'] });
|
|
20
|
+
const vMax = new NumberController({ classList: ['max'] });
|
|
21
|
+
|
|
22
|
+
this.addChild(vMin);
|
|
23
|
+
|
|
24
|
+
this.addChild(new LabelView('-', { classList: ['separator'], tag: 'span' }));
|
|
25
|
+
|
|
26
|
+
this.addChild(vMax);
|
|
27
|
+
|
|
28
|
+
let lockForward = false;
|
|
29
|
+
|
|
30
|
+
function syncForward() {
|
|
31
|
+
|
|
32
|
+
lockForward = true;
|
|
33
|
+
|
|
34
|
+
vMin.value.set(interval.min);
|
|
35
|
+
vMax.value.set(interval.max);
|
|
36
|
+
|
|
37
|
+
lockForward = false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.on.linked.add(syncForward);
|
|
41
|
+
|
|
42
|
+
this.bindSignal(interval.onChanged, syncForward);
|
|
43
|
+
|
|
44
|
+
this.bindSignal(vMin.value.onChanged, (v) => {
|
|
45
|
+
if (lockForward) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const max = max2(v, vMax.value.getValue());
|
|
50
|
+
|
|
51
|
+
interval.set(v, max)
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
this.bindSignal(vMax.value.onChanged, (v) => {
|
|
55
|
+
if (lockForward) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const min = min2(v, vMin.value.getValue());
|
|
60
|
+
|
|
61
|
+
interval.set(min, v)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import View from "../../../../../src/view/View.js";
|
|
2
|
+
import ObservedValue from "../../../../../src/core/model/ObservedValue.js";
|
|
3
|
+
import DatGuiController from "../DatGuiController.js";
|
|
4
|
+
import { GUIElementFlag } from "../../../../../src/engine/ecs/gui/GUIElement.js";
|
|
5
|
+
|
|
6
|
+
export class GUIElementController extends View {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.el = document.createElement('div');
|
|
11
|
+
|
|
12
|
+
this.addClass('gui-element-controller');
|
|
13
|
+
|
|
14
|
+
this.model = new ObservedValue(null);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param {GUIElement} el
|
|
19
|
+
*/
|
|
20
|
+
const update = (el) => {
|
|
21
|
+
this.removeAllChildren();
|
|
22
|
+
|
|
23
|
+
const dat = new DatGuiController();
|
|
24
|
+
|
|
25
|
+
this.addChild(dat);
|
|
26
|
+
|
|
27
|
+
const proxy = {
|
|
28
|
+
klass: "",
|
|
29
|
+
group: "",
|
|
30
|
+
managed: el.getFlag(GUIElementFlag.Managed),
|
|
31
|
+
visible: el.visible.getValue()
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (typeof el.klass === "string") {
|
|
35
|
+
proxy.klass = el.klass;
|
|
36
|
+
}
|
|
37
|
+
if (typeof el.group === "string") {
|
|
38
|
+
proxy.group = el.group;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
dat.addControl(proxy, 'klass').onChange(v => {
|
|
42
|
+
if (typeof v === "string" && v.trim() !== "") {
|
|
43
|
+
el.klass = v;
|
|
44
|
+
} else {
|
|
45
|
+
el.klass = null;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
dat.addControl(proxy, 'group').onChange(v => {
|
|
50
|
+
if (typeof v === "string" && v.trim() !== "") {
|
|
51
|
+
el.group = v;
|
|
52
|
+
} else {
|
|
53
|
+
el.group = null;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
dat.addControl(proxy, 'managed').onChange(v => {
|
|
58
|
+
el.writeFlag(GUIElementFlag.Managed, v);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
dat.addControl(proxy, 'visible').onChange(v => {
|
|
62
|
+
el.visible.set(v);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const params = dat.addFolder('parameter');
|
|
66
|
+
|
|
67
|
+
function makeParam(paramName) {
|
|
68
|
+
|
|
69
|
+
params.add(el.parameters, paramName);
|
|
70
|
+
params.add({
|
|
71
|
+
remove() {
|
|
72
|
+
delete el.parameters[paramName];
|
|
73
|
+
update(el);
|
|
74
|
+
}
|
|
75
|
+
}, 'remove');
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const pc = {
|
|
80
|
+
name: "",
|
|
81
|
+
type: "boolean",
|
|
82
|
+
create() {
|
|
83
|
+
if (pc.name.trim() === "") {
|
|
84
|
+
console.error("Parameter name is empty");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let v;
|
|
89
|
+
|
|
90
|
+
if (pc.type === "boolean") {
|
|
91
|
+
v = false;
|
|
92
|
+
} else if (pc.type === "number") {
|
|
93
|
+
v = 0;
|
|
94
|
+
} else if (pc.type === "string") {
|
|
95
|
+
v = "";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
el.parameters[pc.name] = v;
|
|
99
|
+
|
|
100
|
+
makeParam(pc.name);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
params.add(pc, 'name');
|
|
105
|
+
params.add(pc, 'type', ["boolean", "number", "string"]);
|
|
106
|
+
params.add(pc, 'create');
|
|
107
|
+
|
|
108
|
+
for (let paramName in el.parameters) {
|
|
109
|
+
if (el.parameters.hasOwnProperty(paramName)) {
|
|
110
|
+
makeParam(paramName);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
this.model.onChanged.add(update);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { ItemController } from "./ItemController.js";
|
|
2
|
+
import View from "../../../../../src/view/View.js";
|
|
3
|
+
import ObservedValue from "../../../../../src/core/model/ObservedValue.js";
|
|
4
|
+
import { NumericIntervalController } from "../common/NumericIntervalController.js";
|
|
5
|
+
import LabelView from "../../../../../src/view/common/LabelView.js";
|
|
6
|
+
import { LineView } from "../common/LineView.js";
|
|
7
|
+
import ListView from "../../../../../src/view/common/ListView.js";
|
|
8
|
+
import ButtonView from "../../../../../src/view/elements/button/ButtonView.js";
|
|
9
|
+
import EmptyView from "../../../../../src/view/elements/EmptyView.js";
|
|
10
|
+
import Item from "../../../../../../model/game/ecs/component/Item.js";
|
|
11
|
+
import { NumberController } from "../common/NumberController.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param {ItemContainer} itemContainer
|
|
16
|
+
* @param {ItemDescriptionDatabase} items
|
|
17
|
+
* @returns {View}
|
|
18
|
+
*/
|
|
19
|
+
function makeItemAdder(itemContainer, items) {
|
|
20
|
+
|
|
21
|
+
const vInput = new EmptyView({ classList: ['id'], tag: 'input' });
|
|
22
|
+
|
|
23
|
+
//item adder
|
|
24
|
+
return new LineView({
|
|
25
|
+
classList: [
|
|
26
|
+
'item-adder'
|
|
27
|
+
],
|
|
28
|
+
elements: [
|
|
29
|
+
vInput,
|
|
30
|
+
new ButtonView({
|
|
31
|
+
action() {
|
|
32
|
+
const id = vInput.el.value;
|
|
33
|
+
const itemDescription = items.get(id);
|
|
34
|
+
|
|
35
|
+
if (itemDescription === null) {
|
|
36
|
+
|
|
37
|
+
console.error(`item '${id}' not found`);
|
|
38
|
+
|
|
39
|
+
return;
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const item = new Item();
|
|
44
|
+
item.description = itemDescription;
|
|
45
|
+
|
|
46
|
+
itemContainer.addItem(item);
|
|
47
|
+
},
|
|
48
|
+
name: 'Add',
|
|
49
|
+
classList: ['add']
|
|
50
|
+
})
|
|
51
|
+
]
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class ItemContainerController extends View {
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @param {Localization} localization
|
|
59
|
+
* @param {ItemDescriptionDatabase} itemDatabase
|
|
60
|
+
*/
|
|
61
|
+
constructor({ localization, itemDatabase }) {
|
|
62
|
+
super();
|
|
63
|
+
|
|
64
|
+
this.el = document.createElement('div');
|
|
65
|
+
this.addClass('ui-item-container-controller');
|
|
66
|
+
|
|
67
|
+
this.itemDatabase = itemDatabase;
|
|
68
|
+
|
|
69
|
+
this.model = new ObservedValue(null);
|
|
70
|
+
|
|
71
|
+
const self = this;
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
* @param {ItemContainer} model
|
|
77
|
+
*/
|
|
78
|
+
function setModel(model) {
|
|
79
|
+
self.removeAllChildren();
|
|
80
|
+
|
|
81
|
+
if (model !== null) {
|
|
82
|
+
self.addChild(new LineView({
|
|
83
|
+
elements: [
|
|
84
|
+
new LabelView('random', { tag: 'span' }),
|
|
85
|
+
new NumericIntervalController({ interval: model.random, tag: 'span' })
|
|
86
|
+
],
|
|
87
|
+
classList: ['random']
|
|
88
|
+
}));
|
|
89
|
+
const moneyController = new NumberController();
|
|
90
|
+
|
|
91
|
+
self.addChild(new LineView({
|
|
92
|
+
elements: [
|
|
93
|
+
new LabelView('money', { tag: 'span' }),
|
|
94
|
+
moneyController
|
|
95
|
+
],
|
|
96
|
+
classList: ['money']
|
|
97
|
+
}));
|
|
98
|
+
|
|
99
|
+
moneyController.value.onChanged.add((v) => model.money.set(v));
|
|
100
|
+
moneyController.bindSignal(model.money.onChanged, (v) => {
|
|
101
|
+
moneyController.value.set(v);
|
|
102
|
+
});
|
|
103
|
+
moneyController.value.set(model.money.getValue());
|
|
104
|
+
|
|
105
|
+
self.addChild(new LabelView('Items:'));
|
|
106
|
+
const items = model.items;
|
|
107
|
+
|
|
108
|
+
const vList = new ListView(items, {
|
|
109
|
+
classList: ['items'],
|
|
110
|
+
elementFactory(item) {
|
|
111
|
+
|
|
112
|
+
const itemController = new ItemController({
|
|
113
|
+
item,
|
|
114
|
+
localization,
|
|
115
|
+
requestRemoval() {
|
|
116
|
+
items.removeOneOf(item);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return itemController;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
self.addChild(vList);
|
|
125
|
+
|
|
126
|
+
self.addChild(makeItemAdder(model, self.itemDatabase));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.model.onChanged.add(setModel);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { storiesOf } from "@storybook/html/dist/client/preview";
|
|
2
|
+
import { Localization } from "../../../../../src/core/localization/Localization.js";
|
|
3
|
+
import { ItemContainerController } from "./ItemContainerController.js";
|
|
4
|
+
import ItemContainer from "../../../../../../model/game/ecs/component/item_container/ItemContainer.js";
|
|
5
|
+
import Item from "../../../../../../model/game/ecs/component/Item.js";
|
|
6
|
+
import { EngineHarness } from "../../../../../src/engine/EngineHarness.js";
|
|
7
|
+
import { assert } from "../../../../../src/core/assert.js";
|
|
8
|
+
|
|
9
|
+
const enginePromise = EngineHarness.getSingleton()
|
|
10
|
+
.initialize();
|
|
11
|
+
|
|
12
|
+
enginePromise.then(engine => {
|
|
13
|
+
|
|
14
|
+
engine.gameView.el.style.visibility = 'hidden';
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
storiesOf("ItemContainerController", module)
|
|
18
|
+
.add('Basic', () => {
|
|
19
|
+
const localization = new Localization();
|
|
20
|
+
|
|
21
|
+
const icv = new ItemContainerController({ localization });
|
|
22
|
+
|
|
23
|
+
icv.link();
|
|
24
|
+
|
|
25
|
+
enginePromise.then(engine => {
|
|
26
|
+
icv.itemDatabase = engine.staticKnowledge.items;
|
|
27
|
+
|
|
28
|
+
const itemContainer = new ItemContainer();
|
|
29
|
+
|
|
30
|
+
itemContainer.random.set(1, 2);
|
|
31
|
+
|
|
32
|
+
const id = 'potion_of_major_knowledge';
|
|
33
|
+
const itemDescription = engine.staticKnowledge.items.get(id);
|
|
34
|
+
|
|
35
|
+
assert.notEqual(itemDescription, null, `item '${id}' not found`);
|
|
36
|
+
|
|
37
|
+
const item = new Item();
|
|
38
|
+
|
|
39
|
+
item.description = itemDescription;
|
|
40
|
+
item.count.set(3);
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
itemContainer.items.add(item);
|
|
44
|
+
|
|
45
|
+
icv.model.set(itemContainer);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
return icv.el;
|
|
50
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import ImageView from "../../../../../src/view/elements/image/ImageView.js";
|
|
2
|
+
import { LocalizedLabelView } from "../../../../../src/view/common/LocalizedLabelView.js";
|
|
3
|
+
import ButtonView from "../../../../../src/view/elements/button/ButtonView.js";
|
|
4
|
+
import View from "../../../../../src/view/View.js";
|
|
5
|
+
import { NumberController } from "../common/NumberController.js";
|
|
6
|
+
|
|
7
|
+
export class ItemController extends View {
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {Item} item
|
|
11
|
+
* @param {Localization} localization
|
|
12
|
+
* @param {function} requestRemoval
|
|
13
|
+
*/
|
|
14
|
+
constructor({ item, localization, requestRemoval }) {
|
|
15
|
+
super();
|
|
16
|
+
|
|
17
|
+
this.model = item;
|
|
18
|
+
|
|
19
|
+
this.el = document.createElement('div');
|
|
20
|
+
this.addClass('ui-item-controller');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @type {ItemDescription}
|
|
25
|
+
*/
|
|
26
|
+
const itemDescription = item.description;
|
|
27
|
+
|
|
28
|
+
const iconView = new ImageView(itemDescription.icon);
|
|
29
|
+
iconView.addClass('icon');
|
|
30
|
+
|
|
31
|
+
this.addChild(iconView);
|
|
32
|
+
|
|
33
|
+
const vCount = new NumberController({ classList: ['count'] });
|
|
34
|
+
|
|
35
|
+
this.addChild(vCount);
|
|
36
|
+
|
|
37
|
+
this.addChild(new ButtonView({ action: requestRemoval, name: '', classList: ['remove'] }));
|
|
38
|
+
|
|
39
|
+
vCount.value.set(item.count.getValue());
|
|
40
|
+
this.bindSignal(item.count.onChanged, v => vCount.value.set(v));
|
|
41
|
+
this.bindSignal(vCount.value.onChanged, v => item.count.set(v));
|
|
42
|
+
|
|
43
|
+
const lName = new LocalizedLabelView({
|
|
44
|
+
id: itemDescription.getLocalizationKeyName(),
|
|
45
|
+
localization,
|
|
46
|
+
classList: ["name"]
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
this.addChild(lName);
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
}
|