@woosh/meep-engine 2.37.18 → 2.37.19
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/core/assert.js +1 -1
- package/core/collection/array/typed/isTypedArray.js +20 -0
- package/core/collection/array/typedArrayToDataType.js +1 -0
- package/core/collection/table/RowFirstTable.js +34 -0
- package/core/collection/table/RowFirstTable.spec.js +59 -1
- package/core/color/Color.js +14 -0
- package/core/color/rgb2hex.js +1 -1
- package/core/events/signal/Signal.spec.js +16 -0
- package/core/geom/Quaternion.d.ts +5 -0
- package/core/geom/Quaternion.js +152 -137
- package/core/geom/Quaternion.spec.js +47 -2
- package/core/geom/Vector3.schema.json +16 -0
- package/core/json/JsonUtils.js +2 -20
- package/core/model/ObservedEnum.js +8 -0
- package/editor/Editor.js +97 -1
- package/editor/actions/concrete/PatchTerrainHeightAction.js +1 -1
- 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 +90 -0
- package/editor/ecs/component/createObjectEditor.js +242 -60
- 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 +50 -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 +60 -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 +44 -0
- package/editor/ecs/component/editors/ecs/ParameterTrackEditor.js +17 -0
- package/editor/ecs/component/editors/ecs/ParticleEmitterEditor.js +58 -0
- package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.js +54 -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 +42 -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 +56 -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 +25 -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 +32 -0
- package/editor/ecs/component/findNearestRegisteredType.js +59 -0
- package/editor/ecs/component/prototypeObjectEditor.js +379 -0
- package/editor/view/EditorView.js +1 -1
- package/editor/view/ecs/ComponentControlView.js +2 -30
- package/editor/view/ecs/EntityEditor.js +61 -139
- package/editor/view/ecs/components/GridObstacleController.js +4 -4
- package/editor/view/ecs/components/TerrainController.js +1 -1
- package/editor/view/ecs/components/common/NumberController.js +19 -7
- package/engine/animation/keyed2/AnimationTrack.js +1 -1
- package/engine/ecs/components/TagEditor.js +15 -0
- package/engine/ecs/terrain/ecs/Terrain.js +23 -42
- package/engine/ecs/terrain/ecs/TerrainSystem.js +2 -2
- package/engine/ecs/terrain/ecs/layers/TerrainLayer.js +1 -1
- package/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +1 -1
- package/engine/ecs/transform/Transform.editor.schema.json +16 -0
- package/engine/graphics/ecs/highlight/HighlightEditor.js +17 -0
- package/engine/graphics/ecs/mesh/MeshEditor.js +28 -0
- package/engine/graphics/ecs/mesh-v2/aggregate/prototypeSGMesh.js +3 -3
- package/engine/graphics/micron/render/instanced/shader/shader_rewrite_standard.js +15 -15
- package/engine/graphics/particles/particular/engine/ParticularEngine.js +5 -0
- package/engine/graphics/texture/sampler/Sampler2D.js +16 -0
- package/engine/graphics/util/ScaleObject3ToBox.js +14 -1
- package/engine/graphics/util/makeMeshPreviewScene.js +2 -1
- package/engine/grid/components/GridObstacle.js +0 -44
- package/engine/grid/components/GridObstacleSerializationAdapter.js +46 -0
- package/engine/navigation/ecs/components/Path.d.ts +2 -0
- package/engine/navigation/ecs/components/Path.js +6 -1
- package/generation/example/SampleGenerator0.js +33 -29
- package/generation/example/generators/interactive/mir_generator_place_buff_objects.js +7 -6
- package/generation/example/generators/mir_generator_place_bases.js +7 -3
- package/generation/example/generators/mir_generator_place_road_decorators.js +3 -3
- package/generation/example/generators/mir_generator_place_starting_point.js +3 -2
- package/generation/markers/GridCellActionPlaceMarker.js +9 -3
- package/generation/markers/transform/MarkerNodeTransformerOffsetPosition.js +1 -1
- package/generation/placement/GridCellPlacementRule.js +22 -23
- package/generation/theme/ThemeEngine.js +1 -1
- package/package.json +1 -1
- package/samples/terrain/main.js +1 -1
- package/view/View.js +23 -1
- package/view/common/LabelView.js +1 -1
- package/view/compose3x3transform.js +32 -8
- package/view/controller/dat/DatGuiUtils.js +1 -1
- package/view/elements/DropDownSelectionView.js +11 -3
- package/view/elements/image/ImageView.js +3 -1
- package/core/model/ObservedReal.js +0 -55
- package/editor/ecs/component/ObjectEditor.js +0 -0
|
@@ -1,52 +1,30 @@
|
|
|
1
1
|
import EmptyView from "../../../view/elements/EmptyView.js";
|
|
2
|
+
import { FieldDescriptor } from "./FieldDescriptor.js";
|
|
3
|
+
import { FieldValueAdapter } from "./FieldValueAdapter.js";
|
|
4
|
+
import { createFieldEditor } from "./createFieldEditor.js";
|
|
5
|
+
import { findNearestRegisteredType } from "./findNearestRegisteredType.js";
|
|
2
6
|
import LabelView from "../../../view/common/LabelView.js";
|
|
3
7
|
|
|
4
|
-
class FieldValueAdapter {
|
|
5
|
-
read(object, field_name) {
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
write(object, field_name, value) {
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
8
|
/**
|
|
15
9
|
* @template T
|
|
10
|
+
* @param {T|undefined} value
|
|
16
11
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* @type {string}
|
|
22
|
-
*/
|
|
23
|
-
this.name = "";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* typeof field
|
|
27
|
-
* @type {Class<T>}
|
|
28
|
-
*/
|
|
29
|
-
this.type = null;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @type {FieldValueAdapter|null}
|
|
34
|
-
*/
|
|
35
|
-
this.adapter = null;
|
|
36
|
-
|
|
12
|
+
function objectToClass(value) {
|
|
13
|
+
if (value === null || value === undefined) {
|
|
14
|
+
return;
|
|
37
15
|
}
|
|
38
|
-
}
|
|
39
16
|
|
|
40
|
-
/**
|
|
41
|
-
* @template T
|
|
42
|
-
* @param {T} value
|
|
43
|
-
*/
|
|
44
|
-
function objectToClass(value) {
|
|
45
17
|
const type = typeof value;
|
|
46
18
|
|
|
47
19
|
switch (type) {
|
|
48
20
|
case "object":
|
|
49
|
-
|
|
21
|
+
const proto = Object.getPrototypeOf(value);
|
|
22
|
+
|
|
23
|
+
if (proto === null) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return proto.constructor;
|
|
50
28
|
case "boolean":
|
|
51
29
|
return Boolean;
|
|
52
30
|
case "function":
|
|
@@ -78,10 +56,24 @@ function isPublicField(object, field_name) {
|
|
|
78
56
|
/**
|
|
79
57
|
*
|
|
80
58
|
* @param {Object} object
|
|
81
|
-
* @
|
|
59
|
+
* @param {string} field_name
|
|
60
|
+
* @returns {boolean}
|
|
82
61
|
*/
|
|
83
|
-
function
|
|
84
|
-
|
|
62
|
+
function isReservedField(object, field_name) {
|
|
63
|
+
if (field_name.startsWith('@')) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
* @param {Object} object
|
|
73
|
+
* @param {FieldDescriptor[]} result
|
|
74
|
+
* @param {*} object_proto
|
|
75
|
+
*/
|
|
76
|
+
function extract_object_fields_reflection(object, result, object_proto) {
|
|
85
77
|
const keys = Object.keys(object);
|
|
86
78
|
|
|
87
79
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -91,6 +83,10 @@ function extractObjectFields(object) {
|
|
|
91
83
|
continue;
|
|
92
84
|
}
|
|
93
85
|
|
|
86
|
+
if (isReservedField(object, key)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
|
|
94
90
|
const field_type = objectToClass(object[key]);
|
|
95
91
|
|
|
96
92
|
if (field_type === undefined) {
|
|
@@ -100,56 +96,242 @@ function extractObjectFields(object) {
|
|
|
100
96
|
const descriptor = new FieldDescriptor();
|
|
101
97
|
descriptor.name = key;
|
|
102
98
|
descriptor.type = field_type;
|
|
99
|
+
descriptor.adapter = new FieldValueAdapter();
|
|
103
100
|
|
|
104
101
|
result.push(descriptor);
|
|
105
102
|
}
|
|
106
103
|
|
|
107
|
-
|
|
104
|
+
const descriptors = Object.getOwnPropertyDescriptors(object_proto);
|
|
105
|
+
|
|
106
|
+
for (let d_name in descriptors) {
|
|
107
|
+
const d = descriptors[d_name];
|
|
108
|
+
|
|
109
|
+
const adapter = new FieldValueAdapter();
|
|
110
|
+
|
|
111
|
+
if (d.get === undefined) {
|
|
112
|
+
adapter.readable = false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (d.set === undefined) {
|
|
116
|
+
adapter.writable = false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!adapter.readable) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
let field_value;
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
field_value = adapter.read(object, d_name);
|
|
128
|
+
} catch (e) {
|
|
129
|
+
console.warn(e);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const field_type = objectToClass(field_value);
|
|
134
|
+
|
|
135
|
+
if (field_type === undefined) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const descriptor = new FieldDescriptor();
|
|
140
|
+
|
|
141
|
+
descriptor.name = d_name;
|
|
142
|
+
descriptor.type = field_type;
|
|
143
|
+
descriptor.adapter = adapter;
|
|
144
|
+
|
|
145
|
+
result.push(descriptor);
|
|
146
|
+
}
|
|
108
147
|
}
|
|
109
148
|
|
|
110
149
|
/**
|
|
111
150
|
*
|
|
112
151
|
* @param {Object} object
|
|
113
|
-
* @param {
|
|
114
|
-
* @
|
|
152
|
+
* @param {Map<*, TypeEditor>} registry
|
|
153
|
+
* @returns {FieldDescriptor[]}
|
|
115
154
|
*/
|
|
116
|
-
|
|
117
|
-
const
|
|
155
|
+
function extractObjectFields(object, registry) {
|
|
156
|
+
const result = [];
|
|
118
157
|
|
|
119
|
-
|
|
158
|
+
const object_proto = Object.getPrototypeOf(object);
|
|
159
|
+
const Klass = object_proto.constructor;
|
|
120
160
|
|
|
121
|
-
|
|
161
|
+
const editor = registry.get(Klass);
|
|
122
162
|
|
|
123
|
-
|
|
163
|
+
if (!(editor?.schema?.additionalProperties === false)) {
|
|
164
|
+
|
|
165
|
+
extract_object_fields_reflection(object, result, object_proto);
|
|
124
166
|
|
|
125
|
-
if (factory !== undefined) {
|
|
126
|
-
vValue = factory(object, field);
|
|
127
|
-
} else {
|
|
128
|
-
vValue = createObjectEditor(object, registry);
|
|
129
167
|
}
|
|
130
168
|
|
|
131
|
-
vResult.addChild(vValue);
|
|
132
169
|
|
|
133
|
-
|
|
170
|
+
if (editor !== undefined) {
|
|
171
|
+
|
|
172
|
+
const schema = editor.schema;
|
|
173
|
+
|
|
174
|
+
if (schema !== undefined) {
|
|
175
|
+
// has schema, apply
|
|
176
|
+
const prop_keys = Object.keys(schema.properties);
|
|
177
|
+
|
|
178
|
+
for (let i = 0; i < prop_keys.length; i++) {
|
|
179
|
+
const key = prop_keys[i];
|
|
180
|
+
|
|
181
|
+
const property = schema.properties[key];
|
|
182
|
+
|
|
183
|
+
const field_index = result.findIndex(a => a.name === key);
|
|
184
|
+
|
|
185
|
+
let field;
|
|
186
|
+
|
|
187
|
+
if (field_index === -1) {
|
|
188
|
+
// not in schema yet, build
|
|
189
|
+
field = new FieldDescriptor();
|
|
190
|
+
field.name = key;
|
|
191
|
+
field.adapter = new FieldValueAdapter();
|
|
192
|
+
|
|
193
|
+
result.push(field);
|
|
194
|
+
} else {
|
|
195
|
+
field = result[field_index];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
let actual_type = field.type;
|
|
199
|
+
|
|
200
|
+
if (actual_type === undefined || actual_type === null) {
|
|
201
|
+
let actual_value;
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
actual_value = field.adapter.read(object, key);
|
|
205
|
+
} catch (e) {
|
|
206
|
+
// silent failure
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (actual_value !== undefined && actual_value !== null) {
|
|
210
|
+
actual_type = objectToClass(actual_value);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (property.type) {
|
|
215
|
+
// validate type
|
|
216
|
+
if (actual_type !== undefined && actual_type !== null) {
|
|
217
|
+
if (actual_type !== property.type) {
|
|
218
|
+
console.error(`Schema violation at field '${key}', schema type is different from actual type`, schema, actual_type);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
field.type = property.type;
|
|
223
|
+
} else if (actual_type !== undefined && field.type !== actual_type) {
|
|
224
|
+
field.type = actual_type;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
field.schema = property;
|
|
229
|
+
|
|
230
|
+
if (property.transient === true) {
|
|
231
|
+
// no point in editing transient
|
|
232
|
+
result.splice(field_index, 1);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return result;
|
|
134
239
|
}
|
|
135
240
|
|
|
241
|
+
const build_path = [];
|
|
242
|
+
let build_path_offset = 0;
|
|
243
|
+
|
|
244
|
+
|
|
136
245
|
/**
|
|
137
|
-
*
|
|
138
246
|
* @param {Object} object
|
|
139
|
-
* @param {Map<*,
|
|
247
|
+
* @param {Map<*, TypeEditor>} registry
|
|
248
|
+
* @param {FieldDescriptor} [field_descriptor]
|
|
249
|
+
*/
|
|
250
|
+
export function buildObjectEditorFromRegistry(object, registry, field_descriptor) {
|
|
251
|
+
|
|
252
|
+
const editor = findNearestRegisteredType(registry, object);
|
|
253
|
+
|
|
254
|
+
let fd;
|
|
255
|
+
|
|
256
|
+
if (field_descriptor === undefined) {
|
|
257
|
+
|
|
258
|
+
fd = new FieldDescriptor();
|
|
259
|
+
fd.adapter = new FieldValueAdapter();
|
|
260
|
+
|
|
261
|
+
fd.adapter.read = () => object;
|
|
262
|
+
fd.adapter.writable = false;
|
|
263
|
+
|
|
264
|
+
if (editor.schema) {
|
|
265
|
+
fd.schema = editor.schema;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
} else {
|
|
269
|
+
fd = field_descriptor;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return editor.build(null, fd, registry);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const MAX_DEPTH = 7;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @param {Object} object
|
|
279
|
+
* @param {Map<*, TypeEditor>} registry
|
|
140
280
|
*/
|
|
141
281
|
export function createObjectEditor(object, registry) {
|
|
142
|
-
const fields = extractObjectFields(object);
|
|
143
282
|
|
|
144
|
-
|
|
283
|
+
if (build_path_offset > MAX_DEPTH) {
|
|
284
|
+
// too deep
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const seen_index = build_path.indexOf(object);
|
|
289
|
+
if (seen_index >= 0 && seen_index < build_path_offset) {
|
|
290
|
+
// recursion
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
build_path[build_path_offset++] = object;
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
const vResult = new EmptyView({
|
|
299
|
+
classList: ['auto-object-editor'],
|
|
300
|
+
css: {}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
const fields = extractObjectFields(object, registry);
|
|
305
|
+
|
|
306
|
+
const field_views = [];
|
|
145
307
|
|
|
146
308
|
for (let i = 0; i < fields.length; i++) {
|
|
147
309
|
const field = fields[i];
|
|
148
310
|
|
|
149
|
-
|
|
311
|
+
let vField;
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
vField = createFieldEditor(object, field, registry);
|
|
315
|
+
} catch (e) {
|
|
316
|
+
vField = new LabelView('ERROR');
|
|
317
|
+
console.warn(e);
|
|
318
|
+
}
|
|
150
319
|
|
|
151
|
-
|
|
320
|
+
if (vField === null) {
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
field_views.push(vField);
|
|
152
325
|
}
|
|
153
326
|
|
|
327
|
+
build_path_offset--;
|
|
328
|
+
|
|
329
|
+
if (field_views.length === 0) {
|
|
330
|
+
// skip containers with no data
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
vResult.addChildren(field_views);
|
|
335
|
+
|
|
154
336
|
return vResult;
|
|
155
337
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TypeEditor } from "../TypeEditor.js";
|
|
2
|
+
import EmptyView from "../../../../view/elements/EmptyView.js";
|
|
3
|
+
import { rgb2hex } from "../../../../core/color/rgb2hex.js";
|
|
4
|
+
|
|
5
|
+
export class ColorEditor extends TypeEditor {
|
|
6
|
+
build(parent, field) {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @type {Color}
|
|
10
|
+
*/
|
|
11
|
+
const color = field.adapter.read(parent, field.name);
|
|
12
|
+
|
|
13
|
+
const view = new EmptyView({
|
|
14
|
+
tag: 'input'
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
view.attr({
|
|
18
|
+
type: "color"
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
function sync_up() {
|
|
22
|
+
view.attr({
|
|
23
|
+
value: `#${rgb2hex(color.r * 255, color.g * 255, color.b * 255)}`
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function sync_down(e) {
|
|
28
|
+
const color_value = e.target.value;
|
|
29
|
+
|
|
30
|
+
color.parse(color_value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
view.on.linked.add(sync_up);
|
|
34
|
+
view.el.addEventListener('input', sync_down, false);
|
|
35
|
+
view.el.addEventListener('change', sync_down, false);
|
|
36
|
+
|
|
37
|
+
return view;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TypeEditor } from "../TypeEditor.js";
|
|
2
|
+
import View from "../../../../view/View.js";
|
|
3
|
+
|
|
4
|
+
export class HTMLElementEditor extends TypeEditor {
|
|
5
|
+
build(parent, field, registry) {
|
|
6
|
+
const el = field.adapter?.read(parent, field.name);
|
|
7
|
+
|
|
8
|
+
const view = new View();
|
|
9
|
+
|
|
10
|
+
view.el = el;
|
|
11
|
+
|
|
12
|
+
// make the size small
|
|
13
|
+
view.size.setScalar(32);
|
|
14
|
+
|
|
15
|
+
return view;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TypeEditor } from "../TypeEditor.js";
|
|
2
|
+
import { StringEditor } from "./primitive/StringEditor.js";
|
|
3
|
+
import EmptyView from "../../../../view/elements/EmptyView.js";
|
|
4
|
+
import ImageView from "../../../../view/elements/image/ImageView.js";
|
|
5
|
+
import ObservedString from "../../../../core/model/ObservedString.js";
|
|
6
|
+
import { ObservedStringEditor } from "./ObservedStringEditor.js";
|
|
7
|
+
|
|
8
|
+
export class ImagePathEditor extends TypeEditor {
|
|
9
|
+
inline = true;
|
|
10
|
+
|
|
11
|
+
build(parent, field, registry) {
|
|
12
|
+
let url_editor;
|
|
13
|
+
|
|
14
|
+
if (field.type === String) {
|
|
15
|
+
|
|
16
|
+
url_editor = new StringEditor();
|
|
17
|
+
|
|
18
|
+
} else if (field.type === ObservedString) {
|
|
19
|
+
|
|
20
|
+
url_editor = new ObservedStringEditor();
|
|
21
|
+
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error(`Unsupported type`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const vEditor = url_editor.build(parent, field, registry);
|
|
27
|
+
|
|
28
|
+
const r = new EmptyView({
|
|
29
|
+
css: {
|
|
30
|
+
display: "flex",
|
|
31
|
+
flexDirection: "row"
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const vPreview = new ImageView(field.adapter.read(parent, field.name));
|
|
36
|
+
|
|
37
|
+
vPreview.size.set(32, 32);
|
|
38
|
+
|
|
39
|
+
function update() {
|
|
40
|
+
vPreview.__setSource(vEditor.el.value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
r.addChild(vPreview);
|
|
44
|
+
r.addChild(vEditor);
|
|
45
|
+
|
|
46
|
+
vEditor.el.addEventListener('input', update);
|
|
47
|
+
|
|
48
|
+
return r;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { TypeEditor } from "../TypeEditor.js";
|
|
2
|
+
import EmptyView from "../../../../view/elements/EmptyView.js";
|
|
3
|
+
import { NumberController } from "../../../view/ecs/components/common/NumberController.js";
|
|
4
|
+
import LabelView from "../../../../view/common/LabelView.js";
|
|
5
|
+
|
|
6
|
+
export class NumericIntervalEditor extends TypeEditor {
|
|
7
|
+
build(parent, field, registry) {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @type {NumericInterval}
|
|
11
|
+
*/
|
|
12
|
+
const interval = field.adapter?.read(parent, field.name);
|
|
13
|
+
|
|
14
|
+
const r = new EmptyView({
|
|
15
|
+
classList: ["inline-field-row-editor"]
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const c_0 = new NumberController({ value: interval.min });
|
|
19
|
+
const c_1 = new NumberController({ value: interval.max });
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
r.addChild(new LabelView("min"))
|
|
23
|
+
r.addChild(c_0);
|
|
24
|
+
r.addChild(new LabelView("max"))
|
|
25
|
+
r.addChild(c_1);
|
|
26
|
+
|
|
27
|
+
let lock = false;
|
|
28
|
+
|
|
29
|
+
const sync_up = () => {
|
|
30
|
+
if (lock) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
lock = true;
|
|
35
|
+
|
|
36
|
+
c_0.value.set(interval.min);
|
|
37
|
+
c_1.value.set(interval.max);
|
|
38
|
+
|
|
39
|
+
lock = false;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const sync_down = () => {
|
|
43
|
+
|
|
44
|
+
if (lock) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
lock = true;
|
|
49
|
+
|
|
50
|
+
const v0 = c_0.value.getValue();
|
|
51
|
+
const v1 = c_1.value.getValue();
|
|
52
|
+
|
|
53
|
+
if (v0 <= v1) {
|
|
54
|
+
|
|
55
|
+
interval.set(
|
|
56
|
+
v0,
|
|
57
|
+
v1,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
lock = false;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
r.on.linked.add(sync_up);
|
|
65
|
+
|
|
66
|
+
r.bindSignal(interval.onChanged, sync_up);
|
|
67
|
+
|
|
68
|
+
r.bindSignal(c_0.value.onChanged, sync_down);
|
|
69
|
+
r.bindSignal(c_1.value.onChanged, sync_down);
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
const validate = () => {
|
|
73
|
+
// validation
|
|
74
|
+
|
|
75
|
+
if (c_0.value.getValue() > c_1.value.getValue()) {
|
|
76
|
+
// restore
|
|
77
|
+
sync_up();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
c_0.el.addEventListener('blur', validate);
|
|
82
|
+
c_1.el.addEventListener('blur', validate);
|
|
83
|
+
|
|
84
|
+
return r;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TypeEditor } from "../TypeEditor.js";
|
|
2
|
+
import { CheckboxView } from "../../../../view/elements/CheckboxView.js";
|
|
3
|
+
|
|
4
|
+
export class ObservedBooleanEditor extends TypeEditor {
|
|
5
|
+
build(parent, field, registry) {
|
|
6
|
+
|
|
7
|
+
const ctrl = new CheckboxView({
|
|
8
|
+
value: field.adapter.read(parent, field.name)
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
return ctrl;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TypeEditor } from "../TypeEditor.js";
|
|
2
|
+
import DropDownSelectionView from "../../../../view/elements/DropDownSelectionView.js";
|
|
3
|
+
import List from "../../../../core/collection/list/List.js";
|
|
4
|
+
import { objectKeyByValue } from "../../../../core/model/object/objectKeyByValue.js";
|
|
5
|
+
|
|
6
|
+
export class ObservedEnumEditor extends TypeEditor {
|
|
7
|
+
build(parent, field, registry) {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @type {ObservedEnum}
|
|
11
|
+
*/
|
|
12
|
+
const value = field.adapter.read(parent, field.name);
|
|
13
|
+
|
|
14
|
+
const valueSet = value.getValidValueSet();
|
|
15
|
+
|
|
16
|
+
const ctrl = new DropDownSelectionView(
|
|
17
|
+
new List(Object.keys(valueSet)), {
|
|
18
|
+
changeListener(key) {
|
|
19
|
+
const v = valueSet[key];
|
|
20
|
+
|
|
21
|
+
value.set(v);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
ctrl.on.linked.add(() => {
|
|
27
|
+
ctrl.setSelectedValue(objectKeyByValue(valueSet, value.getValue()));
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
return ctrl;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TypeEditor } from "../TypeEditor.js";
|
|
2
|
+
import { NumberController } from "../../../view/ecs/components/common/NumberController.js";
|
|
3
|
+
|
|
4
|
+
export class ObservedIntegerEditor extends TypeEditor {
|
|
5
|
+
build(parent, field, registry) {
|
|
6
|
+
const instance = field.adapter.read(parent, field.name);
|
|
7
|
+
const ctrl = new NumberController();
|
|
8
|
+
|
|
9
|
+
let lock = false;
|
|
10
|
+
|
|
11
|
+
function sync_down() {
|
|
12
|
+
|
|
13
|
+
if (lock) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
lock = true;
|
|
18
|
+
|
|
19
|
+
instance.set(ctrl.value.getValue());
|
|
20
|
+
|
|
21
|
+
lock = false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function sync_up() {
|
|
25
|
+
if (lock) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
lock = true;
|
|
30
|
+
|
|
31
|
+
ctrl.value.set(instance.getValue());
|
|
32
|
+
|
|
33
|
+
lock = false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
ctrl.on.linked.add(sync_up);
|
|
37
|
+
|
|
38
|
+
ctrl.value.onChanged.add(sync_down);
|
|
39
|
+
ctrl.bindSignal(instance.onChanged, sync_up);
|
|
40
|
+
|
|
41
|
+
return ctrl;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { TypeEditor } from "../TypeEditor.js";
|
|
2
|
+
import EmptyView from "../../../../view/elements/EmptyView.js";
|
|
3
|
+
|
|
4
|
+
export class ObservedStringEditor extends TypeEditor {
|
|
5
|
+
build(parent, field, registry) {
|
|
6
|
+
|
|
7
|
+
const ctrl = new EmptyView({
|
|
8
|
+
tag: 'input'
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
ctrl.attr({
|
|
12
|
+
type: 'text'
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const value = field.adapter.read(parent, field.name);
|
|
16
|
+
|
|
17
|
+
let lock = false;
|
|
18
|
+
|
|
19
|
+
function sync_up() {
|
|
20
|
+
if (lock) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
lock = true;
|
|
25
|
+
|
|
26
|
+
ctrl.el.value = value.getValue();
|
|
27
|
+
|
|
28
|
+
lock = false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function sync_down() {
|
|
32
|
+
if (lock) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
lock = true;
|
|
37
|
+
const str = ctrl.el.value;
|
|
38
|
+
|
|
39
|
+
value.set(str);
|
|
40
|
+
|
|
41
|
+
lock = false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
ctrl.on.linked.add(sync_up);
|
|
45
|
+
ctrl.bindSignal(value.onChanged, sync_up);
|
|
46
|
+
ctrl.el.addEventListener('input', sync_down);
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
return ctrl;
|
|
50
|
+
}
|
|
51
|
+
}
|