@vyr/engine 0.0.1 → 0.0.2
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 +1 -19
- package/src/Category.ts +7 -7
- package/src/Engine.ts +12 -12
- package/src/actor/AnimationUnitActor.ts +3 -3
- package/src/actor/DivActor.ts +6 -6
- package/src/actor/FragmentActor.ts +3 -3
- package/src/actor/HTMActor.ts +19 -16
- package/src/actor/HTMServiceActor.ts +4 -4
- package/src/actor/HTMTransformControllerActor.ts +15 -10
- package/src/asset/Asset.ts +9 -26
- package/src/asset/AssetGraph.ts +4 -4
- package/src/descriptor/DatasetDescriptor.ts +20 -22
- package/src/descriptor/Descriptor.ts +1 -28
- package/src/descriptor/HTMLTransformControllerDescriptor.ts +2 -2
- package/src/descriptor/index.ts +0 -1
- package/src/graphics/Compilation.ts +19 -30
- package/src/graphics/Graphics.ts +79 -66
- package/src/graphics/VariableProxy.ts +8 -8
- package/src/index.ts +2 -1
- package/src/interaction/InteractionDescriptor.ts +96 -0
- package/src/interaction/InteractionExecutor.ts +84 -0
- package/src/interaction/Scriptable.ts +40 -0
- package/src/interaction/index.ts +3 -0
- package/src/interpreter/AnimationUnitInterpreter.ts +5 -5
- package/src/interpreter/DivInterpreter.ts +15 -15
- package/src/interpreter/DynamicInterpreter.ts +9 -9
- package/src/interpreter/FragmentInterpreter.ts +10 -10
- package/src/interpreter/HTMLServiceInterpreter.ts +15 -15
- package/src/interpreter/HTMLTransformControllerInterpreter.ts +15 -15
- package/src/interpreter/Interpreter.ts +9 -9
- package/src/interpreter/ServiceInterpreter.ts +6 -6
- package/src/interpreter/ServiceSchedulerInterpreter.ts +6 -6
- package/src/interpreter/StyleInterpreter.ts +7 -7
- package/src/interpreter/index.ts +0 -1
- package/src/locale/LanguageProvider.ts +4 -2
- package/src/preset/execute/dataset/compile.ts +43 -0
- package/src/preset/execute/dataset/index.ts +2 -1
- package/src/preset/execute/dataset/update.ts +7 -8
- package/src/preset/execute/graphics/invoke.ts +5 -6
- package/src/preset/execute/net/{request.ts → http.ts} +7 -16
- package/src/preset/execute/net/index.ts +1 -1
- package/src/preset/execute/scheduler/switch.ts +7 -8
- package/src/preset/index.ts +2 -2
- package/src/preset/interaction/graphics/invoke.ts +27 -0
- package/src/preset/interaction/scheduler/switch.ts +27 -0
- package/src/utils/AssetProvider.ts +7 -6
- package/src/utils/constants.ts +10 -0
- package/src/utils/index.ts +1 -0
- package/src/Scriptable.ts +0 -27
- package/src/descriptor/RoutineDescriptor.ts +0 -54
- package/src/interpreter/RoutineInterpreter.ts +0 -88
- package/src/preset/routine/graphics/invoke.ts +0 -27
- package/src/preset/routine/scheduler/switch.ts +0 -27
- /package/src/preset/{routine → interaction}/graphics/index.ts +0 -0
- /package/src/preset/{routine → interaction}/index.ts +0 -0
- /package/src/preset/{routine → interaction}/scheduler/index.ts +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Engine } from "../Engine";
|
|
2
|
-
import { Graphics } from "./Graphics";
|
|
2
|
+
import { Graphics, TickArgs } from "./Graphics";
|
|
3
3
|
import { Asset } from "../asset";
|
|
4
|
-
import { AnimationUnitDescriptor, ServiceSchedulerDescriptor
|
|
4
|
+
import { AnimationUnitDescriptor, ServiceSchedulerDescriptor } from "../descriptor";
|
|
5
5
|
|
|
6
6
|
class Compilation {
|
|
7
7
|
private collection = new Map<string, Graphics>()
|
|
@@ -18,7 +18,7 @@ class Compilation {
|
|
|
18
18
|
graphics = new Graphics(url, scheduler, engine)
|
|
19
19
|
this.collection.set(scheduler.uuid, graphics)
|
|
20
20
|
}
|
|
21
|
-
graphics.listen(
|
|
21
|
+
graphics.listen()
|
|
22
22
|
|
|
23
23
|
return graphics
|
|
24
24
|
}
|
|
@@ -27,46 +27,35 @@ class Compilation {
|
|
|
27
27
|
unlisten(scheduler: ServiceSchedulerDescriptor, engine: Engine) {
|
|
28
28
|
const graphics = this.collection.get(scheduler.uuid)
|
|
29
29
|
if (graphics === undefined) return
|
|
30
|
-
graphics.unlisten(
|
|
30
|
+
graphics.unlisten()
|
|
31
31
|
this.collection.delete(scheduler.uuid)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
Asset.free()
|
|
36
|
-
|
|
34
|
+
foreach(executor: (graphics: Graphics) => void) {
|
|
37
35
|
const collection = this.collection.values()
|
|
38
36
|
|
|
39
37
|
for (const graphics of collection) {
|
|
38
|
+
executor(graphics)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
graphics.clear(args)
|
|
44
|
-
|
|
45
|
-
engine.trigger(AnimationUnitDescriptor.type, args)
|
|
42
|
+
process(engine: Engine, args: TickArgs) {
|
|
43
|
+
Asset.free()
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
this.foreach((graphics) => {
|
|
46
|
+
graphics.process()
|
|
47
|
+
graphics.clear()
|
|
48
|
+
})
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
engine.trigger(AnimationUnitDescriptor.type, args)
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
engine.trigger('afterRender', args)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
52
|
+
this.foreach((graphics) => graphics.beforeRender())
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
const collection = this.collection.values()
|
|
59
|
-
for (const graphics of collection) graphics.beforeRender(args)
|
|
60
|
-
}
|
|
54
|
+
engine.trigger('beforeRender', args)
|
|
61
55
|
|
|
62
|
-
|
|
63
|
-
const collection = this.collection.values()
|
|
64
|
-
for (const graphics of collection) graphics.render(args)
|
|
65
|
-
}
|
|
56
|
+
this.foreach((graphics) => graphics.render())
|
|
66
57
|
|
|
67
|
-
|
|
68
|
-
const collection = this.collection.values()
|
|
69
|
-
for (const graphics of collection) graphics.afterRender(args)
|
|
58
|
+
engine.trigger('afterRender', args)
|
|
70
59
|
}
|
|
71
60
|
|
|
72
61
|
clear(engine: Engine) {
|
package/src/graphics/Graphics.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { language } from '../locale'
|
|
2
2
|
import { ArrayUtils } from "../ArrayUtils";
|
|
3
3
|
import { Asset, Dependencide } from "../asset";
|
|
4
|
-
import { Descriptor, HTMLDescriptor, HTMLServiceDescriptor,
|
|
4
|
+
import { DatasetDescriptor, Descriptor, HTMLDescriptor, HTMLServiceDescriptor, ServiceDescriptor, ServiceSchedulerDescriptor } from "../descriptor";
|
|
5
5
|
import { privateState } from "../interpreter/Interpreter";
|
|
6
|
-
import { Interpreter,
|
|
6
|
+
import { Interpreter, ServiceInterpreter, ServiceSchedulerInterpreter } from "../interpreter";
|
|
7
7
|
import { observer, UpdateDepsWatcherArgs, UpdateWatcherArgs, WatcherArgs } from "./Observer";
|
|
8
8
|
import { Operation, Queue, Unit } from "./Unit";
|
|
9
9
|
import { Actor } from '../actor/Actor';
|
|
10
10
|
import { UnitCollection } from "./Collection";
|
|
11
11
|
import { VariableProxy } from "./VariableProxy";
|
|
12
12
|
import { Engine } from '../Engine';
|
|
13
|
+
import { InteractionDescriptor } from '../interaction';
|
|
14
|
+
|
|
15
|
+
interface TickArgs {
|
|
16
|
+
delta: number
|
|
17
|
+
}
|
|
13
18
|
|
|
14
19
|
interface PickupObject {
|
|
15
20
|
[k: string]: any
|
|
@@ -17,7 +22,7 @@ interface PickupObject {
|
|
|
17
22
|
generatedBy: string
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
type OverrideUpdate = (descriptor: Descriptor, interpreter: Interpreter
|
|
25
|
+
type OverrideUpdate = (descriptor: Descriptor, interpreter: Interpreter) => void
|
|
21
26
|
|
|
22
27
|
class Graphics {
|
|
23
28
|
static createInterpreter<T extends Interpreter = Interpreter>(descriptor: Descriptor, graphics: Graphics) {
|
|
@@ -41,6 +46,13 @@ class Graphics {
|
|
|
41
46
|
private readonly _services: ServiceDescriptor[] = []
|
|
42
47
|
private readonly _freeQueue: Unit[] = []
|
|
43
48
|
private _currentCamera = ''
|
|
49
|
+
private _currentArgs: TickArgs = { delta: 0 }
|
|
50
|
+
get args() {
|
|
51
|
+
return this._currentArgs
|
|
52
|
+
}
|
|
53
|
+
set args(args: TickArgs) {
|
|
54
|
+
this._currentArgs = args
|
|
55
|
+
}
|
|
44
56
|
readonly unitCollection = new UnitCollection()
|
|
45
57
|
readonly variableProxy = new VariableProxy()
|
|
46
58
|
readonly scheduler: ServiceSchedulerDescriptor
|
|
@@ -53,7 +65,7 @@ class Graphics {
|
|
|
53
65
|
this.url = url
|
|
54
66
|
}
|
|
55
67
|
|
|
56
|
-
listen(
|
|
68
|
+
listen() {
|
|
57
69
|
observer.listen('add', this.addWatcher)
|
|
58
70
|
observer.listen('remove', this.removeWatcher)
|
|
59
71
|
observer.listen('update', this.updateWatcher)
|
|
@@ -64,22 +76,22 @@ class Graphics {
|
|
|
64
76
|
if (root instanceof Descriptor) this.addRoot(this.url, root)
|
|
65
77
|
|
|
66
78
|
Asset.graph.getDependencide(this.url, this._dependencide)
|
|
67
|
-
this._dependencide.
|
|
79
|
+
this._dependencide.forEachForGraphics(asset => {
|
|
68
80
|
const root = Asset.get<Descriptor>(asset)
|
|
69
81
|
if (root instanceof Descriptor) {
|
|
70
82
|
this._assetCollection.set(asset, this.addRoot(asset, root))
|
|
71
83
|
}
|
|
72
84
|
})
|
|
73
85
|
|
|
74
|
-
const descriptor = this.variableProxy.get<ServiceSchedulerDescriptor>(this.scheduler.uuid, this
|
|
86
|
+
const descriptor = this.variableProxy.get<ServiceSchedulerDescriptor>(this.scheduler.uuid, this)
|
|
75
87
|
const interpreter = this.getInterpreter<ServiceSchedulerInterpreter>(descriptor)
|
|
76
|
-
interpreter.install(descriptor
|
|
88
|
+
interpreter.install(descriptor)
|
|
77
89
|
}
|
|
78
90
|
|
|
79
|
-
unlisten(
|
|
80
|
-
const descriptor = this.variableProxy.get<ServiceSchedulerDescriptor>(this.scheduler.uuid, this
|
|
91
|
+
unlisten() {
|
|
92
|
+
const descriptor = this.variableProxy.get<ServiceSchedulerDescriptor>(this.scheduler.uuid, this)
|
|
81
93
|
const interpreter = this.getInterpreter<ServiceSchedulerInterpreter>(descriptor)
|
|
82
|
-
interpreter.uninstall(descriptor
|
|
94
|
+
interpreter.uninstall(descriptor)
|
|
83
95
|
|
|
84
96
|
const master = this.unitCollection.get(this.scheduler.uuid) as Unit
|
|
85
97
|
const assets = [...this._assetCollection.values(), master]
|
|
@@ -87,12 +99,12 @@ class Graphics {
|
|
|
87
99
|
for (const asset of assets) {
|
|
88
100
|
const unit = this.removeRoot(asset.queue.url)
|
|
89
101
|
if (unit === null) continue
|
|
90
|
-
unit.queue.iterator(operation => this.do(operation
|
|
102
|
+
unit.queue.iterator(operation => this.do(operation))
|
|
91
103
|
this._assetCollection.delete(asset.queue.url)
|
|
92
104
|
}
|
|
93
105
|
|
|
94
106
|
const _freeQueue = this._freeCollection.values()
|
|
95
|
-
for (const unit of _freeQueue) this.doFree(unit
|
|
107
|
+
for (const unit of _freeQueue) this.doFree(unit)
|
|
96
108
|
|
|
97
109
|
observer.unlisten('add', this.addWatcher)
|
|
98
110
|
observer.unlisten('remove', this.removeWatcher)
|
|
@@ -103,11 +115,11 @@ class Graphics {
|
|
|
103
115
|
this._dependencide.clear()
|
|
104
116
|
}
|
|
105
117
|
|
|
106
|
-
process(
|
|
107
|
-
for (const unit of this._freeQueue) this.doFree(unit
|
|
118
|
+
process() {
|
|
119
|
+
for (const unit of this._freeQueue) this.doFree(unit)
|
|
108
120
|
this._freeQueue.length = 0
|
|
109
121
|
|
|
110
|
-
this.updateStaticAsset(
|
|
122
|
+
this.updateStaticAsset()
|
|
111
123
|
|
|
112
124
|
this._dependencide.clear()
|
|
113
125
|
Asset.graph.getDependencide(this.url, this._dependencide)
|
|
@@ -116,7 +128,7 @@ class Graphics {
|
|
|
116
128
|
|
|
117
129
|
for (const removeAsset of patch.removeQueue) {
|
|
118
130
|
const unit = this.removeRoot(removeAsset)
|
|
119
|
-
if (unit !== null) unit.queue.iterator(operation => this.do(operation
|
|
131
|
+
if (unit !== null) unit.queue.iterator(operation => this.do(operation))
|
|
120
132
|
this._assetCollection.delete(removeAsset)
|
|
121
133
|
}
|
|
122
134
|
for (const addAsset of patch.addQueue) {
|
|
@@ -127,7 +139,7 @@ class Graphics {
|
|
|
127
139
|
}
|
|
128
140
|
|
|
129
141
|
const assets: Unit[] = []
|
|
130
|
-
this._dependencide.
|
|
142
|
+
this._dependencide.forEachForGraphics(asset => {
|
|
131
143
|
const descriptor = Asset.get<Descriptor>(asset)
|
|
132
144
|
const unit = this.unitCollection.get(descriptor.uuid)
|
|
133
145
|
if (unit === undefined) return console.warn(asset, descriptor)
|
|
@@ -136,18 +148,18 @@ class Graphics {
|
|
|
136
148
|
assets.push(...this._staticAssetQueue)
|
|
137
149
|
|
|
138
150
|
for (const asset of assets) {
|
|
139
|
-
asset.queue.iterator(operation => this.do(operation
|
|
151
|
+
asset.queue.iterator(operation => this.do(operation))
|
|
140
152
|
}
|
|
141
153
|
|
|
142
154
|
const master = this.unitCollection.get(this.scheduler.uuid) as Unit
|
|
143
155
|
|
|
144
|
-
master.queue.iterator(operation => this.do(operation
|
|
156
|
+
master.queue.iterator(operation => this.do(operation))
|
|
145
157
|
|
|
146
158
|
for (const asset of assets) {
|
|
147
|
-
asset.queue.iterator(unit => this.doUpdate(unit
|
|
159
|
+
asset.queue.iterator(unit => this.doUpdate(unit), Queue.Update)
|
|
148
160
|
}
|
|
149
161
|
|
|
150
|
-
const invokeQueue = master.queue.iterator(unit => this.doUpdate(unit
|
|
162
|
+
const invokeQueue = master.queue.iterator(unit => this.doUpdate(unit), Queue.Update)
|
|
151
163
|
for (const unit of invokeQueue) {
|
|
152
164
|
const descriptor = Descriptor.get<Descriptor>(unit.uuid)
|
|
153
165
|
this.invoke('mount', descriptor)
|
|
@@ -157,35 +169,35 @@ class Graphics {
|
|
|
157
169
|
this._freeCollection.clear()
|
|
158
170
|
}
|
|
159
171
|
|
|
160
|
-
clear(
|
|
172
|
+
clear() {
|
|
161
173
|
for (const service of this._services) {
|
|
162
|
-
const descriptor = this.variableProxy.get<ServiceDescriptor>(service.uuid, this
|
|
174
|
+
const descriptor = this.variableProxy.get<ServiceDescriptor>(service.uuid, this)
|
|
163
175
|
const interpreter = this.getInterpreter<ServiceInterpreter>(descriptor)
|
|
164
|
-
interpreter.clear(descriptor
|
|
176
|
+
interpreter.clear(descriptor)
|
|
165
177
|
}
|
|
166
178
|
}
|
|
167
179
|
|
|
168
|
-
beforeRender(
|
|
180
|
+
beforeRender() {
|
|
169
181
|
for (const service of this._services) {
|
|
170
|
-
const descriptor = this.variableProxy.get<ServiceDescriptor>(service.uuid, this
|
|
182
|
+
const descriptor = this.variableProxy.get<ServiceDescriptor>(service.uuid, this)
|
|
171
183
|
const interpreter = this.getInterpreter<ServiceInterpreter>(descriptor)
|
|
172
|
-
interpreter.beforeRender(descriptor
|
|
184
|
+
interpreter.beforeRender(descriptor)
|
|
173
185
|
}
|
|
174
186
|
}
|
|
175
187
|
|
|
176
|
-
render(
|
|
188
|
+
render() {
|
|
177
189
|
for (const service of this._services) {
|
|
178
|
-
const descriptor = this.variableProxy.get<ServiceDescriptor>(service.uuid, this
|
|
190
|
+
const descriptor = this.variableProxy.get<ServiceDescriptor>(service.uuid, this)
|
|
179
191
|
const interpreter = this.getInterpreter<ServiceInterpreter>(descriptor)
|
|
180
|
-
interpreter.render(descriptor
|
|
192
|
+
interpreter.render(descriptor)
|
|
181
193
|
}
|
|
182
194
|
}
|
|
183
195
|
|
|
184
|
-
afterRender(
|
|
196
|
+
afterRender() {
|
|
185
197
|
for (const service of this._services) {
|
|
186
|
-
const descriptor = this.variableProxy.get<ServiceDescriptor>(service.uuid, this
|
|
198
|
+
const descriptor = this.variableProxy.get<ServiceDescriptor>(service.uuid, this)
|
|
187
199
|
const interpreter = this.getInterpreter<ServiceInterpreter>(descriptor)
|
|
188
|
-
interpreter.afterRender(descriptor
|
|
200
|
+
interpreter.afterRender(descriptor)
|
|
189
201
|
}
|
|
190
202
|
}
|
|
191
203
|
|
|
@@ -194,6 +206,8 @@ class Graphics {
|
|
|
194
206
|
this.unitCollection.set(unit)
|
|
195
207
|
this._freeCollection.delete(unit.uuid)
|
|
196
208
|
|
|
209
|
+
if (root instanceof DatasetDescriptor) this.invoke('compile', root)
|
|
210
|
+
|
|
197
211
|
unit.trigger(Queue.Update)
|
|
198
212
|
for (const sub of root.children) {
|
|
199
213
|
observer.trigger('add', { self: sub.uuid, puid: root.uuid })
|
|
@@ -281,7 +295,7 @@ class Graphics {
|
|
|
281
295
|
})
|
|
282
296
|
}
|
|
283
297
|
|
|
284
|
-
private updateStaticAsset(
|
|
298
|
+
private updateStaticAsset() {
|
|
285
299
|
if (this.scheduler.camera !== this._currentCamera) {
|
|
286
300
|
const descriptor = Descriptor.get<Descriptor>(this.scheduler.camera)
|
|
287
301
|
if (descriptor === null) return
|
|
@@ -302,7 +316,7 @@ class Graphics {
|
|
|
302
316
|
const temp = new Map(this._assetCollection)
|
|
303
317
|
const addQueue: string[] = [], removeQueue: string[] = []
|
|
304
318
|
|
|
305
|
-
this._dependencide.
|
|
319
|
+
this._dependencide.forEachForGraphics(asset => {
|
|
306
320
|
temp.has(asset) ? temp.delete(asset) : addQueue.push(asset)
|
|
307
321
|
})
|
|
308
322
|
removeQueue.push(...temp.keys())
|
|
@@ -310,41 +324,41 @@ class Graphics {
|
|
|
310
324
|
return { addQueue, removeQueue }
|
|
311
325
|
}
|
|
312
326
|
|
|
313
|
-
private onMount(unit: Unit
|
|
314
|
-
const parentDescriptor = this.variableProxy.get<Descriptor>(unit.parent, this
|
|
327
|
+
private onMount(unit: Unit) {
|
|
328
|
+
const parentDescriptor = this.variableProxy.get<Descriptor>(unit.parent, this)
|
|
315
329
|
const parentInterpreter = this.getInterpreter(parentDescriptor)
|
|
316
330
|
|
|
317
|
-
const descriptor = this.variableProxy.get<Descriptor>(unit.uuid, this
|
|
331
|
+
const descriptor = this.variableProxy.get<Descriptor>(unit.uuid, this)
|
|
318
332
|
const interpreter = this.getInterpreter(descriptor)
|
|
319
333
|
|
|
320
334
|
if (descriptor instanceof ServiceDescriptor) ArrayUtils.insert(this._services, descriptor)
|
|
321
335
|
|
|
322
|
-
interpreter.mount(descriptor,
|
|
336
|
+
interpreter.mount(descriptor, parentInterpreter, parentDescriptor)
|
|
323
337
|
}
|
|
324
338
|
|
|
325
|
-
private onUnmount(unit: Unit
|
|
326
|
-
const parentDescriptor = this.variableProxy.get<Descriptor>(unit.parent, this
|
|
339
|
+
private onUnmount(unit: Unit) {
|
|
340
|
+
const parentDescriptor = this.variableProxy.get<Descriptor>(unit.parent, this)
|
|
327
341
|
const parentInterpreter = this.getInterpreter(parentDescriptor)
|
|
328
342
|
|
|
329
|
-
const descriptor = this.variableProxy.get<Descriptor>(unit.uuid, this
|
|
343
|
+
const descriptor = this.variableProxy.get<Descriptor>(unit.uuid, this)
|
|
330
344
|
const interpreter = this.getInterpreter(descriptor)
|
|
331
345
|
|
|
332
346
|
if (descriptor instanceof ServiceDescriptor) ArrayUtils.remove(this._services, descriptor)
|
|
333
347
|
|
|
334
|
-
interpreter.unmount(descriptor,
|
|
348
|
+
interpreter.unmount(descriptor, parentInterpreter, parentDescriptor)
|
|
335
349
|
}
|
|
336
350
|
|
|
337
351
|
getUnit<T extends Unit | null = Unit>(uuid: string) {
|
|
338
352
|
return (this.unitCollection.get(uuid) ?? null) as T
|
|
339
353
|
}
|
|
340
354
|
|
|
341
|
-
do(operation: Operation
|
|
355
|
+
do(operation: Operation) {
|
|
342
356
|
switch (operation.type) {
|
|
343
357
|
case Queue.Add:
|
|
344
|
-
this.onMount(operation.unit
|
|
358
|
+
this.onMount(operation.unit)
|
|
345
359
|
break;
|
|
346
360
|
case Queue.Remove:
|
|
347
|
-
this.onUnmount(operation.unit
|
|
361
|
+
this.onUnmount(operation.unit)
|
|
348
362
|
break;
|
|
349
363
|
default:
|
|
350
364
|
console.log('do', operation.type)
|
|
@@ -352,18 +366,18 @@ class Graphics {
|
|
|
352
366
|
}
|
|
353
367
|
}
|
|
354
368
|
|
|
355
|
-
doUpdate(unit: Unit
|
|
356
|
-
const descriptor = this.variableProxy.get<Descriptor>(unit.uuid, this
|
|
369
|
+
doUpdate(unit: Unit) {
|
|
370
|
+
const descriptor = this.variableProxy.get<Descriptor>(unit.uuid, this)
|
|
357
371
|
const interpreter = this.getInterpreter(descriptor)
|
|
358
372
|
const override = this._overwriteUpdate.get(descriptor.uuid)
|
|
359
|
-
override === undefined ? interpreter.update(descriptor
|
|
373
|
+
override === undefined ? interpreter.update(descriptor) : override(descriptor, interpreter)
|
|
360
374
|
}
|
|
361
375
|
|
|
362
|
-
doFree(unit: Unit
|
|
376
|
+
doFree(unit: Unit) {
|
|
363
377
|
const interpreter = this._interpreterCollection.get(unit.uuid)
|
|
364
378
|
if (interpreter === undefined) return
|
|
365
|
-
const descriptor = this.variableProxy.get<Descriptor>(unit.uuid, this
|
|
366
|
-
interpreter.free(descriptor
|
|
379
|
+
const descriptor = this.variableProxy.get<Descriptor>(unit.uuid, this)
|
|
380
|
+
interpreter.free(descriptor)
|
|
367
381
|
this._interpreterCollection.delete(unit.uuid)
|
|
368
382
|
}
|
|
369
383
|
|
|
@@ -382,18 +396,18 @@ class Graphics {
|
|
|
382
396
|
return Descriptor.get<T>(unit.parent)
|
|
383
397
|
}
|
|
384
398
|
|
|
385
|
-
getActor<T extends Actor = Actor>(descriptor: Descriptor
|
|
399
|
+
getActor<T extends Actor = Actor>(descriptor: Descriptor) {
|
|
386
400
|
const interpreter = this.getInterpreter(descriptor)
|
|
387
|
-
return interpreter.getActor<T>(descriptor
|
|
401
|
+
return interpreter.getActor<T>(descriptor)
|
|
388
402
|
}
|
|
389
403
|
|
|
390
|
-
private _pickupItem(target: Descriptor,
|
|
404
|
+
private _pickupItem(target: Descriptor, result: PickupObject[]) {
|
|
391
405
|
if (target.selectable === false) return
|
|
392
406
|
const interpreter = this._interpreterCollection.get(target.uuid)
|
|
393
407
|
if (interpreter === undefined) return
|
|
394
|
-
interpreter.pickup(target,
|
|
408
|
+
interpreter.pickup(target, result)
|
|
395
409
|
}
|
|
396
|
-
private _pickupScene(
|
|
410
|
+
private _pickupScene(result: PickupObject[]) {
|
|
397
411
|
const master = this.unitCollection.get(this.scheduler.uuid)
|
|
398
412
|
if (master === undefined) return result
|
|
399
413
|
|
|
@@ -401,7 +415,7 @@ class Graphics {
|
|
|
401
415
|
for (const unit of units) {
|
|
402
416
|
const descriptor = Descriptor.get<Descriptor>(unit.uuid)
|
|
403
417
|
if (descriptor instanceof HTMLDescriptor) continue
|
|
404
|
-
this._pickupItem(descriptor,
|
|
418
|
+
this._pickupItem(descriptor, result)
|
|
405
419
|
}
|
|
406
420
|
}
|
|
407
421
|
|
|
@@ -434,15 +448,15 @@ class Graphics {
|
|
|
434
448
|
const args = { delta: 0 }
|
|
435
449
|
if (target instanceof ServiceDescriptor) {
|
|
436
450
|
if (target instanceof HTMLServiceDescriptor) {
|
|
437
|
-
this._pickupItem(target,
|
|
451
|
+
this._pickupItem(target, result)
|
|
438
452
|
} else {
|
|
439
453
|
const interpreter = this.getInterpreter<ServiceInterpreter>(target)
|
|
440
|
-
interpreter.beforePickup(mouse, rect
|
|
441
|
-
this._pickupScene(
|
|
454
|
+
interpreter.beforePickup(mouse, rect)
|
|
455
|
+
this._pickupScene(result)
|
|
442
456
|
interpreter.orderBy(result)
|
|
443
457
|
}
|
|
444
458
|
} else {
|
|
445
|
-
this._pickupItem(target,
|
|
459
|
+
this._pickupItem(target, result)
|
|
446
460
|
}
|
|
447
461
|
|
|
448
462
|
return result
|
|
@@ -450,12 +464,10 @@ class Graphics {
|
|
|
450
464
|
|
|
451
465
|
invoke(interaction: string, descriptor: Descriptor) {
|
|
452
466
|
if (descriptor.interactions.length === 0) return
|
|
453
|
-
const eventArgs = { delta: 0, trigger: descriptor }
|
|
454
467
|
for (const inter of descriptor.interactions) {
|
|
455
468
|
if (inter.type === interaction) {
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
interpreter.do(inter.inputs, routine, eventArgs)
|
|
469
|
+
const current = Asset.get<InteractionDescriptor>(inter.url)
|
|
470
|
+
if (current !== null) current.execute(inter.inputs, this, descriptor)
|
|
459
471
|
break
|
|
460
472
|
}
|
|
461
473
|
}
|
|
@@ -471,5 +483,6 @@ class Graphics {
|
|
|
471
483
|
|
|
472
484
|
export {
|
|
473
485
|
PickupObject,
|
|
486
|
+
TickArgs,
|
|
474
487
|
Graphics,
|
|
475
488
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ObjectUtils } from "../ObjectUtils";
|
|
2
2
|
import { Asset } from "../asset";
|
|
3
|
-
import { Scriptable } from "../Scriptable";
|
|
4
|
-
import { Data, DatasetDescriptor, Descriptor,
|
|
3
|
+
import { Scriptable, ScriptableArgs } from "../interaction/Scriptable";
|
|
4
|
+
import { Data, DatasetDescriptor, Descriptor, VariabConfig } from "../descriptor";
|
|
5
5
|
import { Graphics } from "./Graphics";
|
|
6
6
|
|
|
7
7
|
interface ActorCollection { [k: string]: any }
|
|
@@ -34,18 +34,18 @@ class VariableProxy {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
private getVariableValue = (descriptor: Descriptor, data: Data, key: string, config: VariabConfig, graphics: Graphics
|
|
37
|
+
private getVariableValue = (descriptor: Descriptor, data: Data, key: string, config: VariabConfig, graphics: Graphics) => {
|
|
38
38
|
if (config.type === 'key') {
|
|
39
39
|
return ObjectUtils.getValueByKey(data, config.value)
|
|
40
40
|
} else if (config.type === 'custom') {
|
|
41
|
-
const scriptable = Asset.get<Scriptable
|
|
41
|
+
const scriptable = Asset.get<Scriptable<ScriptableArgs<undefined, undefined, undefined>>>(config.value)
|
|
42
42
|
if (scriptable === null) return
|
|
43
|
-
const currentArgs = {
|
|
44
|
-
return scriptable.execute(
|
|
43
|
+
const currentArgs = { key, config, data, input: undefined, result: undefined, trigger: descriptor }
|
|
44
|
+
return scriptable.execute(graphics, currentArgs)
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
get<T extends Descriptor | null = Descriptor | null>(uuid: string, graphics: Graphics
|
|
48
|
+
get<T extends Descriptor | null = Descriptor | null>(uuid: string, graphics: Graphics) {
|
|
49
49
|
const descriptor = Descriptor.get<Descriptor>(uuid)
|
|
50
50
|
if (descriptor === null) return null as unknown as T
|
|
51
51
|
|
|
@@ -63,7 +63,7 @@ class VariableProxy {
|
|
|
63
63
|
for (const key of keys) {
|
|
64
64
|
const variable = descriptor.variables[key]
|
|
65
65
|
if (variable.enabled === false) continue
|
|
66
|
-
const value = this.getVariableValue(descriptor, data, key, variable, graphics
|
|
66
|
+
const value = this.getVariableValue(descriptor, data, key, variable, graphics)
|
|
67
67
|
if (value === undefined) continue
|
|
68
68
|
variables[key] = value
|
|
69
69
|
}
|
package/src/index.ts
CHANGED
|
@@ -15,7 +15,8 @@ export { Listener } from './Listener'
|
|
|
15
15
|
export { InputSystem } from './InputSystem'
|
|
16
16
|
export { destroyInstance } from './ObjectPool'
|
|
17
17
|
export * from './AsyncTask'
|
|
18
|
-
export * from './Scriptable'
|
|
18
|
+
export * from './interaction/Scriptable'
|
|
19
|
+
export * from './interaction'
|
|
19
20
|
export * from './descriptor'
|
|
20
21
|
export * from './interpreter'
|
|
21
22
|
export * from './utils'
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { DeserializationObject, Serialization } from "../Serialization";
|
|
2
|
+
import { Descriptor } from "../descriptor";
|
|
3
|
+
import { AssetProperty, AssetPropertyCollection } from "../asset";
|
|
4
|
+
import { Graphics } from "../graphics";
|
|
5
|
+
import { InteractionExecutor } from "./InteractionExecutor";
|
|
6
|
+
|
|
7
|
+
interface InteractionInput {
|
|
8
|
+
[param: string]: {
|
|
9
|
+
type?: 'data' | string
|
|
10
|
+
value: any
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface InteractionInputCollection {
|
|
15
|
+
[id: string]: InteractionInput
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface InteractionProperty extends AssetProperty {
|
|
19
|
+
uuid: string
|
|
20
|
+
type: string
|
|
21
|
+
inputs: InteractionInputCollection
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface InteractionPropertyCollection extends AssetPropertyCollection<InteractionProperty> { }
|
|
25
|
+
|
|
26
|
+
interface InteractionNode {
|
|
27
|
+
id: string
|
|
28
|
+
label: string
|
|
29
|
+
position: { x: number; y: number }
|
|
30
|
+
interaction: string
|
|
31
|
+
url: string
|
|
32
|
+
input: InteractionInput
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface InteractionMapper {
|
|
36
|
+
source: string
|
|
37
|
+
target: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const privateState = {
|
|
41
|
+
executorPool: new WeakMap<Descriptor, InteractionExecutor>()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class InteractionDescriptor extends Descriptor {
|
|
45
|
+
static type = 'Interaction'
|
|
46
|
+
roots: string[]
|
|
47
|
+
nodes: InteractionNode[]
|
|
48
|
+
mappers: InteractionMapper[]
|
|
49
|
+
|
|
50
|
+
constructor(descriptor: Partial<DeserializationObject<InteractionDescriptor>> = {}) {
|
|
51
|
+
super(descriptor)
|
|
52
|
+
this.roots = descriptor.roots ? Serialization.deepClone(descriptor.roots) : []
|
|
53
|
+
this.nodes = descriptor.nodes ? Serialization.deepClone(descriptor.nodes) : []
|
|
54
|
+
this.mappers = descriptor.mappers ? Serialization.deepClone(descriptor.mappers) : []
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
addNode(nodes: InteractionNode[]) {
|
|
58
|
+
const count = nodes.length
|
|
59
|
+
const max = count - 1
|
|
60
|
+
for (let i = 0; i < count; i++) {
|
|
61
|
+
const node = nodes[i]
|
|
62
|
+
this.nodes.push(node)
|
|
63
|
+
if (i < max) {
|
|
64
|
+
this.mappers.push({ source: node.id, target: nodes[i + 1].id })
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async execute(customInputs: InteractionInputCollection, graphics: Graphics, trigger: Descriptor, otherArgs?: { [k: string]: any }) {
|
|
70
|
+
let executor = privateState.executorPool.get(this)
|
|
71
|
+
if (executor === undefined) {
|
|
72
|
+
executor = new InteractionExecutor()
|
|
73
|
+
executor.update(this)
|
|
74
|
+
privateState.executorPool.set(this, executor)
|
|
75
|
+
}
|
|
76
|
+
await executor.execute(customInputs, this, graphics, trigger,otherArgs)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setNeedsUpdate() {
|
|
80
|
+
const executor = privateState.executorPool.get(this)
|
|
81
|
+
if (executor === undefined) return
|
|
82
|
+
executor.update(this)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
Descriptor.register(InteractionDescriptor)
|
|
87
|
+
|
|
88
|
+
export {
|
|
89
|
+
InteractionInput,
|
|
90
|
+
InteractionInputCollection,
|
|
91
|
+
InteractionProperty,
|
|
92
|
+
InteractionPropertyCollection,
|
|
93
|
+
InteractionNode,
|
|
94
|
+
InteractionMapper,
|
|
95
|
+
InteractionDescriptor,
|
|
96
|
+
}
|