@vyr/engine 0.0.33 → 0.0.34
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/package.json +6 -3
- package/src/ArrayUtils.ts +63 -65
- package/src/AsyncTask.ts +67 -71
- package/src/Category.ts +69 -86
- package/src/Color.ts +3 -111
- package/src/Engine.ts +12 -24
- package/src/Executor.ts +109 -0
- package/src/Generate.ts +23 -40
- package/src/InputSystem.ts +106 -108
- package/src/Listener.ts +58 -59
- package/src/ObjectPool.ts +83 -84
- package/src/ObjectUtils.ts +97 -49
- package/src/Scriptable.ts +82 -0
- package/src/Serialization.ts +4 -6
- package/src/Traverser.ts +41 -39
- package/src/actor/Actor.ts +23 -27
- package/src/actor/AnimationUnitActor.ts +22 -36
- package/src/actor/DivActor.ts +21 -41
- package/src/actor/FragmentActor.ts +1 -5
- package/src/actor/HTMLActor.ts +81 -0
- package/src/actor/HTMLServiceActor.ts +49 -0
- package/src/actor/{HTMTransformControllerActor.ts → HTMLTransformControllerActor.ts} +178 -71
- package/src/actor/InputActor.ts +50 -0
- package/src/actor/TextActor.ts +51 -0
- package/src/actor/index.ts +6 -5
- package/src/asset/Asset.ts +23 -68
- package/src/asset/AssetGraph.ts +21 -28
- package/src/descriptor/AnimationUnit.ts +81 -0
- package/src/descriptor/Camera.ts +12 -0
- package/src/descriptor/Controller.ts +6 -0
- package/src/descriptor/Descriptor.ts +133 -113
- package/src/descriptor/Div.ts +29 -0
- package/src/descriptor/HTML.ts +22 -0
- package/src/descriptor/HTMLService.ts +42 -0
- package/src/descriptor/HTMLTransformController.ts +67 -0
- package/src/descriptor/Input.ts +29 -0
- package/src/descriptor/Interaction.ts +80 -0
- package/src/descriptor/Node.ts +98 -0
- package/src/descriptor/Scene.ts +110 -0
- package/src/descriptor/Service.ts +11 -0
- package/src/descriptor/Store.ts +136 -0
- package/src/descriptor/Text.ts +36 -0
- package/src/descriptor/index.ts +14 -15
- package/src/graphics/Collection.ts +1 -5
- package/src/graphics/Compilation.ts +15 -19
- package/src/graphics/Graphics.ts +41 -54
- package/src/graphics/Observer.ts +6 -14
- package/src/graphics/Unit.ts +3 -9
- package/src/graphics/VariableProxy.ts +11 -15
- package/src/index.ts +5 -5
- package/src/interpreter/AnimationUnitInterpreter.ts +7 -9
- package/src/interpreter/DivInterpreter.ts +10 -13
- package/src/interpreter/FragmentInterpreter.ts +2 -6
- package/src/interpreter/HTMLServiceInterpreter.ts +25 -15
- package/src/interpreter/HTMLTransformControllerInterpreter.ts +9 -12
- package/src/interpreter/InputInterpreter.ts +41 -0
- package/src/interpreter/Interpreter.ts +3 -4
- package/src/interpreter/SceneInterpreter.ts +93 -0
- package/src/interpreter/ServiceInterpreter.ts +8 -15
- package/src/interpreter/StoreInterpreter.ts +7 -0
- package/src/interpreter/TextInterpreter.ts +41 -0
- package/src/interpreter/index.ts +5 -7
- package/src/locale/Language.ts +1 -5
- package/src/locale/LanguageProvider.ts +164 -21
- package/src/math/Euler.ts +2 -5
- package/src/math/Matrix4.ts +2 -4
- package/src/math/Quaternion.ts +2 -4
- package/src/math/Vector2.ts +4 -4
- package/src/math/Vector3.ts +2 -4
- package/src/math/utils.ts +1 -5
- package/src/schema/AnimationUnit.ts +68 -0
- package/src/schema/Asset.ts +13 -0
- package/src/schema/Descriptor.ts +41 -0
- package/src/schema/HTML.ts +261 -0
- package/src/schema/Interaction.ts +50 -0
- package/src/schema/Scene.ts +138 -0
- package/src/schema/Store.ts +8 -0
- package/src/schema/index.ts +7 -0
- package/src/scripts/ConditionScriptable.ts +196 -0
- package/src/scripts/FetchScriptable.ts +51 -0
- package/src/scripts/FindScriptable.ts +23 -0
- package/src/scripts/InvokeScriptable.ts +13 -0
- package/src/scripts/SwitchSceneScriptable.ts +18 -0
- package/src/scripts/UpdateScriptable.ts +60 -0
- package/src/scripts/index.ts +6 -0
- package/src/utils/AssetProvider.ts +4 -77
- package/src/utils/DOM.ts +37 -0
- package/src/utils/HTML.ts +5 -0
- package/src/utils/Service.ts +40 -0
- package/src/utils/constants.ts +1 -5
- package/src/utils/http.ts +2 -21
- package/src/utils/index.ts +3 -1
- package/src/actor/HTMActor.ts +0 -169
- package/src/actor/HTMServiceActor.ts +0 -57
- package/src/actor/StyleActor.ts +0 -96
- package/src/descriptor/AnimationUnitDescriptor.ts +0 -65
- package/src/descriptor/CameraDescriptor.ts +0 -12
- package/src/descriptor/ControllerDescriptor.ts +0 -16
- package/src/descriptor/DatasetDescriptor.ts +0 -90
- package/src/descriptor/DivDescriptor.ts +0 -18
- package/src/descriptor/DynamicDescriptor.ts +0 -27
- package/src/descriptor/HTMLDescriptor.ts +0 -87
- package/src/descriptor/HTMLServiceDescriptor.ts +0 -19
- package/src/descriptor/HTMLTransformControllerDescriptor.ts +0 -34
- package/src/descriptor/NodeDescriptor.ts +0 -32
- package/src/descriptor/PrefabDescriptor.ts +0 -53
- package/src/descriptor/PrefabInstanceDescriptor.ts +0 -32
- package/src/descriptor/ServiceDescriptor.ts +0 -32
- package/src/descriptor/ServiceSchedulerDescriptor.ts +0 -32
- package/src/descriptor/StyleDescriptor.ts +0 -213
- package/src/interaction/InteractionDescriptor.ts +0 -96
- package/src/interaction/InteractionExecutor.ts +0 -84
- package/src/interaction/Scriptable.ts +0 -44
- package/src/interaction/index.ts +0 -3
- package/src/interpreter/DatasetInterpreter.ts +0 -11
- package/src/interpreter/DynamicInterpreter.ts +0 -207
- package/src/interpreter/PrefaInterpreter.ts +0 -11
- package/src/interpreter/PrefabInstanceInterpreter.ts +0 -12
- package/src/interpreter/ServiceSchedulerInterpreter.ts +0 -42
- package/src/interpreter/StyleInterpreter.ts +0 -66
- package/src/preset/execute/dataset/index.ts +0 -1
- package/src/preset/execute/dataset/update.ts +0 -51
- package/src/preset/execute/graphics/index.ts +0 -1
- package/src/preset/execute/graphics/invoke.ts +0 -48
- package/src/preset/execute/index.ts +0 -4
- package/src/preset/execute/net/http.ts +0 -52
- package/src/preset/execute/net/index.ts +0 -1
- package/src/preset/execute/scheduler/index.ts +0 -1
- package/src/preset/execute/scheduler/switch.ts +0 -46
- package/src/preset/index.ts +0 -7
- package/src/preset/interaction/graphics/index.ts +0 -1
- package/src/preset/interaction/graphics/invoke.ts +0 -27
- package/src/preset/interaction/index.ts +0 -2
- package/src/preset/interaction/scheduler/index.ts +0 -1
- package/src/preset/interaction/scheduler/switch.ts +0 -27
- package/src/setup/index.ts +0 -17
- package/src/utils/compile.ts +0 -50
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { ArrayUtils } from "../ArrayUtils"
|
|
2
|
-
import { Asset } from "../asset"
|
|
3
|
-
import { DynamicDescriptor, Descriptor, Data, DatasetDescriptor, PrefabeDescriptor } from "../descriptor"
|
|
4
|
-
import { observer, UpdateWatcherArgs, WatcherArgs } from "../graphics"
|
|
5
|
-
import { Category } from "../Category"
|
|
6
|
-
import { FragmentInterpreter, Interpreter } from "."
|
|
7
|
-
|
|
8
|
-
class DynamicInterpreter extends FragmentInterpreter {
|
|
9
|
-
static type = DynamicDescriptor.type
|
|
10
|
-
|
|
11
|
-
private _currentDepth = 0
|
|
12
|
-
private _datasetCloneCollection = new Map<string, DatasetDescriptor>()
|
|
13
|
-
private _rawToCloneCollection = new Map<string, Descriptor[]>()
|
|
14
|
-
private _cloneCollection = new Map<number, Descriptor>()
|
|
15
|
-
|
|
16
|
-
private _getDataset(descriptor: Descriptor, dataCollection: Data, i: number) {
|
|
17
|
-
const url = Asset.createVirtualUrl(`dynamic/dataset/${descriptor.uuid}-${i}-${this._currentDepth}${Category.datasetSuffix}`)
|
|
18
|
-
if (this._datasetCloneCollection.has(url)) return url
|
|
19
|
-
const data = dataCollection[i]
|
|
20
|
-
const dataset = new DatasetDescriptor()
|
|
21
|
-
dataset.setExtraData({ index: i })
|
|
22
|
-
dataset.setData(data)
|
|
23
|
-
Asset.set(url, dataset)
|
|
24
|
-
this._datasetCloneCollection.set(url, dataset)
|
|
25
|
-
return url
|
|
26
|
-
}
|
|
27
|
-
private _getDataByDataset<T extends Data | null = Data | null>(url: string) {
|
|
28
|
-
const dataset = this._datasetCloneCollection.get(url)
|
|
29
|
-
|
|
30
|
-
return (dataset?.getData() ?? null) as T
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private _setCache(raw: Descriptor, clone: Descriptor) {
|
|
34
|
-
let clones = this._rawToCloneCollection.get(raw.uuid)
|
|
35
|
-
if (clones === undefined) {
|
|
36
|
-
clones = []
|
|
37
|
-
this._rawToCloneCollection.set(raw.uuid, clones)
|
|
38
|
-
}
|
|
39
|
-
clones.push(clone)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private _markSubDynamic(raw: DynamicDescriptor, parent: Descriptor, generatedBy: string, map: Map<string, Descriptor>, childs: Descriptor[]) {
|
|
43
|
-
this._currentDepth += 1
|
|
44
|
-
const template = Asset.get<Descriptor>(raw.url)
|
|
45
|
-
if (raw.dataConfig === 2) {
|
|
46
|
-
const parentData = this._getDataByDataset(parent.dataset)
|
|
47
|
-
if (parentData === null || typeof parentData !== 'object') return
|
|
48
|
-
//TODO 使用路径解析工具,实现更强大属性支持
|
|
49
|
-
const pathData = parentData[raw.dataPath]
|
|
50
|
-
if (Array.isArray(pathData) === false || pathData.length === 0) return
|
|
51
|
-
|
|
52
|
-
for (let i = 0; i < pathData.length; i++) {
|
|
53
|
-
const dataset = this._getDataset(raw, pathData, i)
|
|
54
|
-
const clone = this._markAndClone(template, dataset, generatedBy, map, childs)
|
|
55
|
-
parent.add(clone)
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
const selfData = this._getDataByDataset(raw.dataset)
|
|
59
|
-
if (Array.isArray(selfData) === false || selfData.length === 0) return
|
|
60
|
-
|
|
61
|
-
for (let i = 0; i < selfData.length; i++) {
|
|
62
|
-
const dataset = this._getDataset(raw, selfData, i)
|
|
63
|
-
const clone = this._markAndClone(template, dataset, generatedBy, map, childs)
|
|
64
|
-
parent.add(clone)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private _markAndClone(raw: Descriptor, dataset: string, generatedBy: string, map: Map<string, Descriptor>, childs: Descriptor[]) {
|
|
70
|
-
let clone
|
|
71
|
-
if (raw instanceof DynamicDescriptor) {
|
|
72
|
-
clone = new Descriptor({ dataset })
|
|
73
|
-
if (raw.url) this._markSubDynamic(raw, clone, generatedBy, map, childs)
|
|
74
|
-
} else if (raw instanceof PrefabeDescriptor) {
|
|
75
|
-
clone = new Descriptor({ dataset })
|
|
76
|
-
} else {
|
|
77
|
-
clone = raw.clone(false)
|
|
78
|
-
clone.dataset = dataset
|
|
79
|
-
map.set(raw.uuid, clone)
|
|
80
|
-
if (clone.interactions.length > 0) childs.push(clone)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
clone.generatedBy = generatedBy
|
|
84
|
-
|
|
85
|
-
for (const subRaw of raw.children) {
|
|
86
|
-
const subClone = this._markAndClone(subRaw, dataset, generatedBy, map, childs)
|
|
87
|
-
clone.add(subClone)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
this._setCache(raw, clone)
|
|
91
|
-
|
|
92
|
-
return clone
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private _onAdd = (args: WatcherArgs) => {
|
|
96
|
-
const clones = this._rawToCloneCollection.get(args.puid)
|
|
97
|
-
if (clones === undefined) return
|
|
98
|
-
|
|
99
|
-
const max = clones.length
|
|
100
|
-
const descriptor = Descriptor.get<Descriptor>(args.self)
|
|
101
|
-
for (let i = 0; i < max; i++) {
|
|
102
|
-
const clone = clones[i]
|
|
103
|
-
const map = new Map<string, Descriptor>()
|
|
104
|
-
const childs: Descriptor[] = []
|
|
105
|
-
const subClone = this._markAndClone(descriptor, clone.dataset, clone.generatedBy, map, childs)
|
|
106
|
-
Descriptor.fixReferences(childs, map)
|
|
107
|
-
clone.add(subClone)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private _onRemove = (args: WatcherArgs) => {
|
|
112
|
-
const clones = this._rawToCloneCollection.get(args.self)
|
|
113
|
-
if (clones === undefined) return
|
|
114
|
-
|
|
115
|
-
while (clones.length > 0) {
|
|
116
|
-
const clone = clones.pop()
|
|
117
|
-
if (clone === undefined) continue
|
|
118
|
-
const parent = this.graphics.getParent(clone.uuid)
|
|
119
|
-
if (parent === null) continue
|
|
120
|
-
parent.remove(clone)
|
|
121
|
-
ArrayUtils.remove(clones, clone)
|
|
122
|
-
}
|
|
123
|
-
const descriptor = Descriptor.get<Descriptor>(args.self)
|
|
124
|
-
descriptor.traverse(sub => {
|
|
125
|
-
this._rawToCloneCollection.delete(sub.uuid)
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private _onUpdate = (args: UpdateWatcherArgs) => {
|
|
130
|
-
const clones = this._rawToCloneCollection.get(args.self)
|
|
131
|
-
if (clones === undefined) return
|
|
132
|
-
|
|
133
|
-
const raw = Descriptor.get<Descriptor>(args.self)
|
|
134
|
-
if (raw instanceof DynamicDescriptor) {
|
|
135
|
-
const ancestor = raw.traceAncestor()
|
|
136
|
-
if (ancestor.parent === null) return
|
|
137
|
-
const watcher = { self: args.self, puid: ancestor.parent.uuid }
|
|
138
|
-
this._onRemove(watcher)
|
|
139
|
-
this._onAdd(watcher)
|
|
140
|
-
} else {
|
|
141
|
-
for (const clone of clones) {
|
|
142
|
-
clone.syncWith(raw)
|
|
143
|
-
clone.setNeedsUpdate()
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
private _clearByOnUpdate = (args: WatcherArgs) => {
|
|
149
|
-
if (args.self !== this.unit.uuid) return
|
|
150
|
-
|
|
151
|
-
this._rawToCloneCollection.clear()
|
|
152
|
-
this._datasetCloneCollection.clear()
|
|
153
|
-
|
|
154
|
-
const clones = this._cloneCollection.values()
|
|
155
|
-
for (const clone of clones) {
|
|
156
|
-
observer.trigger('remove', { self: clone.uuid, puid: this.unit.uuid })
|
|
157
|
-
}
|
|
158
|
-
this._cloneCollection.clear()
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
mount(descriptor: Descriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor): void {
|
|
162
|
-
super.mount(descriptor, parentInterpreter, parentDescriptor)
|
|
163
|
-
observer.listen('update', this._clearByOnUpdate)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
unmount(descriptor: Descriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
167
|
-
observer.unlisten('update', this._clearByOnUpdate)
|
|
168
|
-
super.unmount(descriptor, parentInterpreter, parentDescriptor)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
update(descriptor: DynamicDescriptor) {
|
|
172
|
-
super.update(descriptor)
|
|
173
|
-
|
|
174
|
-
observer.unlisten('add', this._onAdd)
|
|
175
|
-
observer.unlisten('remove', this._onRemove)
|
|
176
|
-
observer.unlisten('update', this._onUpdate)
|
|
177
|
-
|
|
178
|
-
if (descriptor.dataset && descriptor.url) {
|
|
179
|
-
const rootData = DatasetDescriptor.getCollection(descriptor.dataset)
|
|
180
|
-
if (rootData.length > 0) {
|
|
181
|
-
const template = Asset.get<Descriptor>(descriptor.url)
|
|
182
|
-
for (let i = 0; i < rootData.length; i++) {
|
|
183
|
-
this._currentDepth = 0
|
|
184
|
-
const dataset = this._getDataset(descriptor, rootData, i)
|
|
185
|
-
const map = new Map<string, Descriptor>()
|
|
186
|
-
const childs: Descriptor[] = []
|
|
187
|
-
const clone = this._markAndClone(template, dataset, descriptor.uuid, map, childs)
|
|
188
|
-
Descriptor.fixReferences(childs, map)
|
|
189
|
-
this._cloneCollection.set(i, clone)
|
|
190
|
-
observer.trigger('add', { self: clone.uuid, puid: descriptor.uuid })
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
observer.listen('add', this._onAdd)
|
|
196
|
-
observer.listen('remove', this._onRemove)
|
|
197
|
-
observer.listen('update', this._onUpdate)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
free(descriptor: Descriptor) {
|
|
201
|
-
observer.unlisten('add', this._onAdd)
|
|
202
|
-
observer.unlisten('remove', this._onRemove)
|
|
203
|
-
observer.unlisten('update', this._onUpdate)
|
|
204
|
-
super.free(descriptor)
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
FragmentInterpreter.register(DynamicInterpreter)
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { PrefabeDescriptor } from "../descriptor";
|
|
2
|
-
import { FragmentInterpreter } from "./FragmentInterpreter";
|
|
3
|
-
|
|
4
|
-
class PrefaInterpreter extends FragmentInterpreter {
|
|
5
|
-
static type = PrefabeDescriptor.type
|
|
6
|
-
}
|
|
7
|
-
FragmentInterpreter.register(PrefaInterpreter)
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
PrefaInterpreter
|
|
11
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { PrefabInstanceDescriptor } from "../descriptor";
|
|
2
|
-
import { FragmentInterpreter } from "./FragmentInterpreter";
|
|
3
|
-
|
|
4
|
-
class PrefabInstanceInterpreter extends FragmentInterpreter {
|
|
5
|
-
static type = PrefabInstanceDescriptor.type
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
FragmentInterpreter.register(PrefabInstanceInterpreter)
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
PrefabInstanceInterpreter
|
|
12
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Descriptor, ServiceSchedulerDescriptor } from "../descriptor"
|
|
2
|
-
import { DivActor } from "../actor"
|
|
3
|
-
import { Interpreter } from "./Interpreter"
|
|
4
|
-
|
|
5
|
-
class ServiceSchedulerInterpreter extends Interpreter {
|
|
6
|
-
static type = ServiceSchedulerDescriptor.type
|
|
7
|
-
|
|
8
|
-
protected createActor(descriptor: Descriptor) {
|
|
9
|
-
const actor = new DivActor(descriptor.uuid)
|
|
10
|
-
return actor
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
private resize = () => { }
|
|
14
|
-
private unresize = () => { }
|
|
15
|
-
|
|
16
|
-
install(descriptor: ServiceSchedulerDescriptor) {
|
|
17
|
-
const actor = this.getActor<DivActor>(descriptor)
|
|
18
|
-
const wrapper = actor.getWrapper()
|
|
19
|
-
|
|
20
|
-
this.graphics.engine.DOM.appendChild(wrapper)
|
|
21
|
-
|
|
22
|
-
this.resize = () => {
|
|
23
|
-
wrapper.style.width = this.graphics.engine.DOM.clientWidth + 'px'
|
|
24
|
-
wrapper.style.height = this.graphics.engine.DOM.clientHeight + 'px'
|
|
25
|
-
actor.DOM.style.width = '100%'
|
|
26
|
-
actor.DOM.style.height = '100%'
|
|
27
|
-
}
|
|
28
|
-
const uuid = this.graphics.engine.inputSystem.listen('resize', this.resize, { target: window })
|
|
29
|
-
this.unresize = () => this.graphics.engine.inputSystem.unlisten(uuid)
|
|
30
|
-
this.resize()
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
uninstall(descriptor: ServiceSchedulerDescriptor) {
|
|
34
|
-
this.unresize()
|
|
35
|
-
const actor = this.getActor<DivActor>(descriptor)
|
|
36
|
-
const wrapper = actor.getWrapper()
|
|
37
|
-
wrapper.remove()
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
Interpreter.register(ServiceSchedulerInterpreter)
|
|
41
|
-
|
|
42
|
-
export { ServiceSchedulerInterpreter }
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Descriptor, StyleDescriptor } from "../descriptor";
|
|
2
|
-
import { StyleActor } from "../actor";
|
|
3
|
-
import { Graphics, Unit } from "../graphics";
|
|
4
|
-
import { Interpreter } from "./Interpreter";
|
|
5
|
-
|
|
6
|
-
let _sheet: CSSStyleSheet | null = null
|
|
7
|
-
|
|
8
|
-
class StyleInterpreter extends Interpreter {
|
|
9
|
-
static type = StyleDescriptor.type
|
|
10
|
-
static get sheet() {
|
|
11
|
-
if (_sheet === null) {
|
|
12
|
-
const style = document.createElement('style')
|
|
13
|
-
style.setAttribute('type', 'text/css')
|
|
14
|
-
document.head.appendChild(style)
|
|
15
|
-
_sheet = style.sheet as CSSStyleSheet
|
|
16
|
-
}
|
|
17
|
-
return _sheet as CSSStyleSheet
|
|
18
|
-
}
|
|
19
|
-
static insertRule(styles: string[]) {
|
|
20
|
-
for (const style of styles) this.sheet.insertRule(style, StyleInterpreter.sheet.cssRules.length)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
readonly className
|
|
24
|
-
|
|
25
|
-
constructor(unit: Unit, graphics: Graphics) {
|
|
26
|
-
super(unit, graphics)
|
|
27
|
-
this.className = `vyr_${unit.uuid}`
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
protected createActor(descriptor: StyleDescriptor) {
|
|
31
|
-
return new StyleActor()
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
update(descriptor: StyleDescriptor) {
|
|
35
|
-
super.update(descriptor)
|
|
36
|
-
|
|
37
|
-
const actor = this.getActor<StyleActor>(descriptor)
|
|
38
|
-
actor.update(descriptor, this.className)
|
|
39
|
-
|
|
40
|
-
if (actor.updateRule(StyleInterpreter.sheet) === true) return
|
|
41
|
-
|
|
42
|
-
const styleValues = actor.getStyleValue()
|
|
43
|
-
StyleInterpreter.insertRule(styleValues)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
free(descriptor: Descriptor) {
|
|
47
|
-
const selectorTexts = [`.${this.className}`, `.${this.className}:hover`]
|
|
48
|
-
for (let i = StyleInterpreter.sheet.cssRules.length - 1; i >= 0; i--) {
|
|
49
|
-
const rule = StyleInterpreter.sheet.cssRules[i]
|
|
50
|
-
if (rule instanceof CSSStyleRule) {
|
|
51
|
-
const i = selectorTexts.indexOf(rule.selectorText)
|
|
52
|
-
if (i > -1) {
|
|
53
|
-
StyleInterpreter.sheet.deleteRule(i)
|
|
54
|
-
selectorTexts.splice(i, 1)
|
|
55
|
-
if (selectorTexts.length === 0) return
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
super.free(descriptor)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
Interpreter.register(StyleInterpreter)
|
|
63
|
-
|
|
64
|
-
export {
|
|
65
|
-
StyleInterpreter
|
|
66
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as update from './update'
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { language } from "../../../locale";
|
|
2
|
-
import { Asset } from "../../../asset";
|
|
3
|
-
import { DatasetDescriptor } from "../../../descriptor";
|
|
4
|
-
import { InteractionNode, Scriptable, ScriptableArgs } from "../../../interaction";
|
|
5
|
-
import { Graphics } from "../../../graphics";
|
|
6
|
-
import { Category } from "../../../Category";
|
|
7
|
-
|
|
8
|
-
const scriptable = Asset.createVirtualUrl('preset/dataset/update.ts')
|
|
9
|
-
class ExecuteScriptable extends Scriptable {
|
|
10
|
-
async execute(graphics: Graphics, args: ScriptableArgs) {
|
|
11
|
-
const { input, result } = args
|
|
12
|
-
const dataset = this.getInputValue('dataset', input)
|
|
13
|
-
|
|
14
|
-
const previous = result.get(input.previous)
|
|
15
|
-
const datasetDescriptor = Asset.get<DatasetDescriptor>(dataset)
|
|
16
|
-
if (datasetDescriptor instanceof DatasetDescriptor) {
|
|
17
|
-
if (previous) datasetDescriptor.setData(previous)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return {}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
Asset.setProvider(scriptable, async () => ({ default: ExecuteScriptable }))
|
|
24
|
-
|
|
25
|
-
const createExecuteInput = (args: any = {}) => {
|
|
26
|
-
const input = {
|
|
27
|
-
dataset: { value: args.dataset ?? '', type: Category.dataset }
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return input
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const createExecuteNode = (options: { id: string; position?: any; input?: any }) => {
|
|
34
|
-
const executeNode: InteractionNode = {
|
|
35
|
-
id: options.id,
|
|
36
|
-
label: language.get(scriptable as any),
|
|
37
|
-
position: { x: options?.position?.x ?? 20, y: options?.position?.y ?? 20 },
|
|
38
|
-
interaction: 'Execute',
|
|
39
|
-
url: scriptable,
|
|
40
|
-
input: createExecuteInput(options.input)
|
|
41
|
-
}
|
|
42
|
-
return executeNode
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export {
|
|
46
|
-
scriptable,
|
|
47
|
-
createExecuteInput,
|
|
48
|
-
createExecuteNode,
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as invoke from './invoke'
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { language } from "../../../locale";
|
|
2
|
-
import { Asset } from "../../../asset";
|
|
3
|
-
import { Descriptor } from "../../../descriptor";
|
|
4
|
-
import { InteractionNode, Scriptable, ScriptableArgs } from "../../../interaction";
|
|
5
|
-
import { Graphics } from "../../../graphics";
|
|
6
|
-
|
|
7
|
-
const scriptable = Asset.createVirtualUrl('preset/graphics/invoke.ts')
|
|
8
|
-
class ExecuteScriptable extends Scriptable {
|
|
9
|
-
async execute(graphics: Graphics, args: ScriptableArgs) {
|
|
10
|
-
const { input } = args
|
|
11
|
-
const interaction = this.getInputValue('interaction', input)
|
|
12
|
-
const target = this.getInputValue('target', input)
|
|
13
|
-
const targetDescriptor = Descriptor.get<Descriptor>(target)
|
|
14
|
-
if (interaction && targetDescriptor) {
|
|
15
|
-
graphics.invoke(interaction, targetDescriptor)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
Asset.setProvider(scriptable, async () => ({ default: ExecuteScriptable }))
|
|
20
|
-
|
|
21
|
-
const createExecuteInput = (args: any = {}) => {
|
|
22
|
-
const input = {
|
|
23
|
-
target: { value: args.target ?? '' },
|
|
24
|
-
interaction: { value: args.interaction ?? '' },
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return input
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const createExecuteNode = (options: { id: string; position?: any; input?: any }) => {
|
|
31
|
-
const executeNode: InteractionNode = {
|
|
32
|
-
id: options.id,
|
|
33
|
-
label: language.get(scriptable as any),
|
|
34
|
-
position: { x: options?.position?.x ?? 20, y: options?.position?.y ?? 20 },
|
|
35
|
-
interaction: 'Execute',
|
|
36
|
-
url: scriptable,
|
|
37
|
-
input: createExecuteInput(options.input)
|
|
38
|
-
}
|
|
39
|
-
return executeNode
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export {
|
|
43
|
-
scriptable,
|
|
44
|
-
createExecuteInput,
|
|
45
|
-
createExecuteNode,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { language } from "../../../locale";
|
|
2
|
-
import { Asset } from "../../../asset";
|
|
3
|
-
import { http } from "../../../utils";
|
|
4
|
-
import { Graphics } from "../../../graphics";
|
|
5
|
-
import { Scriptable, InteractionNode, ScriptableArgs } from "../../../interaction";
|
|
6
|
-
|
|
7
|
-
const scriptable = Asset.createVirtualUrl('preset/net/http.ts')
|
|
8
|
-
class ExecuteScriptable extends Scriptable {
|
|
9
|
-
|
|
10
|
-
async execute(graphics: Graphics, args: ScriptableArgs) {
|
|
11
|
-
const { input, result } = args
|
|
12
|
-
let url = this.getInputValue('url', input)
|
|
13
|
-
const type = this.getInputValue('type', input)
|
|
14
|
-
const data = this.getInputValue('data', input)
|
|
15
|
-
|
|
16
|
-
const json = await http(url, type, data, result)
|
|
17
|
-
|
|
18
|
-
return json
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
Asset.setProvider(scriptable, async () => ({ default: ExecuteScriptable }))
|
|
22
|
-
|
|
23
|
-
const createExecuteInput = (args: any = {}) => {
|
|
24
|
-
const input = {
|
|
25
|
-
url: { value: args.url ?? '' },
|
|
26
|
-
type: { value: args.type ?? '' },
|
|
27
|
-
data: { value: args.data ?? '' },
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return input
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const createExecuteNode = (options: { id: string; position?: any; input?: any }) => {
|
|
34
|
-
const executeNode: InteractionNode = {
|
|
35
|
-
id: options.id,
|
|
36
|
-
label: language.get(scriptable as any),
|
|
37
|
-
position: { x: options?.position?.x ?? 20, y: options?.position?.y ?? 20 },
|
|
38
|
-
interaction: 'Execute',
|
|
39
|
-
url: scriptable,
|
|
40
|
-
input: createExecuteInput(options.input)
|
|
41
|
-
}
|
|
42
|
-
return executeNode
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export {
|
|
46
|
-
scriptable,
|
|
47
|
-
ExecuteScriptable,
|
|
48
|
-
createExecuteInput,
|
|
49
|
-
createExecuteNode,
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as http from './http'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as switch from './switch'
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { language } from "../../../locale";
|
|
2
|
-
import { Asset } from "../../../asset";
|
|
3
|
-
import { ServiceSchedulerDescriptor } from "../../../descriptor";
|
|
4
|
-
import { InteractionNode, Scriptable, ScriptableArgs } from "../../../interaction";
|
|
5
|
-
import { Graphics } from "../../../graphics";
|
|
6
|
-
|
|
7
|
-
const scriptable = Asset.createVirtualUrl('preset/scheduler/switch.ts')
|
|
8
|
-
class ExecuteScriptable extends Scriptable {
|
|
9
|
-
async execute(graphics: Graphics, args: ScriptableArgs) {
|
|
10
|
-
const scene = this.getInputValue('scene', args.input)
|
|
11
|
-
if (!scene) return
|
|
12
|
-
await Asset.loadAll(scene)
|
|
13
|
-
await Asset.compileDataset(scene, graphics.engine)
|
|
14
|
-
const scheduler = Asset.get<ServiceSchedulerDescriptor>(scene)
|
|
15
|
-
graphics.engine.switch(scheduler)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
Asset.setProvider(scriptable, async () => ({ default: ExecuteScriptable }))
|
|
19
|
-
|
|
20
|
-
const createExecuteInput = (args: any = {}) => {
|
|
21
|
-
const input = {
|
|
22
|
-
scene: { value: args.scene ?? '' },
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return input
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const createExecuteNode = (options: { id: string; position?: any; input?: any }) => {
|
|
29
|
-
const executeNode: InteractionNode = {
|
|
30
|
-
id: options.id,
|
|
31
|
-
label: language.get(scriptable as any),
|
|
32
|
-
position: { x: options?.position?.x ?? 20, y: options?.position?.y ?? 20 },
|
|
33
|
-
interaction: 'Execute',
|
|
34
|
-
url: scriptable,
|
|
35
|
-
input: createExecuteInput(options.input)
|
|
36
|
-
}
|
|
37
|
-
return executeNode
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export {
|
|
41
|
-
scriptable,
|
|
42
|
-
createExecuteInput,
|
|
43
|
-
createExecuteNode,
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
package/src/preset/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as invoke from "./invoke"
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Asset } from "../../../asset";
|
|
2
|
-
import { InteractionDescriptor } from "../../../interaction";
|
|
3
|
-
import { graphics } from "../../execute"
|
|
4
|
-
|
|
5
|
-
const url = Asset.createVirtualUrl('preset/graphics/invoke.interaction.json')
|
|
6
|
-
const nodes = {
|
|
7
|
-
invoke: 'invoke'
|
|
8
|
-
}
|
|
9
|
-
let _currentInteraction: InteractionDescriptor | null = null
|
|
10
|
-
const interactionProvider = async () => {
|
|
11
|
-
if (_currentInteraction === null) {
|
|
12
|
-
_currentInteraction = new InteractionDescriptor()
|
|
13
|
-
const invokeNode = graphics.invoke.createExecuteNode({ id: nodes.invoke })
|
|
14
|
-
_currentInteraction.addNode([invokeNode])
|
|
15
|
-
_currentInteraction.roots.push(invokeNode.id)
|
|
16
|
-
}
|
|
17
|
-
return _currentInteraction
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
Asset.setProvider(url, interactionProvider)
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
url,
|
|
24
|
-
nodes,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as switch from "./switch"
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Asset } from "../../../asset";
|
|
2
|
-
import { InteractionDescriptor } from "../../../interaction";
|
|
3
|
-
import { scheduler } from "../../execute"
|
|
4
|
-
|
|
5
|
-
const url = Asset.createVirtualUrl('preset/scheduler/switch.interaction.json')
|
|
6
|
-
const nodes = {
|
|
7
|
-
switch: 'switch',
|
|
8
|
-
}
|
|
9
|
-
let _currentInteraction: InteractionDescriptor | null = null
|
|
10
|
-
const interactionProvider = async () => {
|
|
11
|
-
if (_currentInteraction === null) {
|
|
12
|
-
_currentInteraction = new InteractionDescriptor()
|
|
13
|
-
const switchNode = scheduler.switch.createExecuteNode({ id: nodes.switch })
|
|
14
|
-
_currentInteraction.addNode([switchNode])
|
|
15
|
-
_currentInteraction.roots.push(switchNode.id)
|
|
16
|
-
}
|
|
17
|
-
return _currentInteraction
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
Asset.setProvider(url, interactionProvider)
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
url,
|
|
24
|
-
nodes,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
package/src/setup/index.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { StyleDescriptor } from "../descriptor"
|
|
2
|
-
import { StyleInterpreter } from "../interpreter"
|
|
3
|
-
import { StyleActor } from "../actor"
|
|
4
|
-
|
|
5
|
-
let needSetupStyle = false
|
|
6
|
-
const setupStyle = () => {
|
|
7
|
-
if (needSetupStyle === true) return
|
|
8
|
-
needSetupStyle = true
|
|
9
|
-
const actor = new StyleActor()
|
|
10
|
-
actor.update(StyleDescriptor.basicStyle, StyleDescriptor.basicName)
|
|
11
|
-
const styleValues = actor.getStyleValue()
|
|
12
|
-
StyleInterpreter.insertRule(styleValues)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
setupStyle
|
|
17
|
-
}
|