@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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Asset } from "../asset"
|
|
2
|
+
import { Scriptable } from "./Scriptable"
|
|
3
|
+
import { InteractionDescriptor, InteractionInputCollection, InteractionNode } from "./InteractionDescriptor"
|
|
4
|
+
import { Graphics } from "../graphics/Graphics"
|
|
5
|
+
|
|
6
|
+
type ExecuteResult = { [k: string]: any } | null
|
|
7
|
+
|
|
8
|
+
class InteractionExecutor {
|
|
9
|
+
readonly collection = new Map<string, InteractionNode>()
|
|
10
|
+
readonly linkCollection = new Map<string, string[]>()
|
|
11
|
+
|
|
12
|
+
update(interaction: InteractionDescriptor) {
|
|
13
|
+
this.collection.clear()
|
|
14
|
+
this.linkCollection.clear()
|
|
15
|
+
|
|
16
|
+
for (const node of interaction.nodes) {
|
|
17
|
+
this.collection.set(node.id, node)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
for (const mapper of interaction.mappers) {
|
|
21
|
+
let link = this.linkCollection.get(mapper.source)
|
|
22
|
+
if (link === undefined) {
|
|
23
|
+
link = []
|
|
24
|
+
this.linkCollection.set(mapper.source, link)
|
|
25
|
+
}
|
|
26
|
+
link.push(mapper.target)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async doBranch(branch: string, previous: string, customInputs: InteractionInputCollection, interaction: InteractionDescriptor, graphics: Graphics, result: Map<string, ExecuteResult>, trigger: any, otherArgs?: any) {
|
|
31
|
+
await this.doExecute(branch, previous, customInputs, interaction, graphics, result, trigger, otherArgs)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async doCondition(condition: string, previous: string, customInputs: InteractionInputCollection, interaction: InteractionDescriptor, graphics: Graphics, result: Map<string, ExecuteResult>, trigger: any, otherArgs?: any) {
|
|
35
|
+
const preResult = result.get(previous)
|
|
36
|
+
const conditionResult = result.get(condition)
|
|
37
|
+
if (preResult !== conditionResult?.condition.value) return
|
|
38
|
+
|
|
39
|
+
await this.doExecute(condition, previous, customInputs, interaction, graphics, result, trigger, otherArgs)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async doExecute(execute: string, previous: string, customInputs: InteractionInputCollection, interaction: InteractionDescriptor, graphics: Graphics, result: Map<string, ExecuteResult>, trigger: any, otherArgs?: any) {
|
|
43
|
+
const nexts = this.linkCollection.get(execute)
|
|
44
|
+
if (nexts === undefined) return
|
|
45
|
+
|
|
46
|
+
for (const next of nexts) {
|
|
47
|
+
await this.doNext(next, execute, customInputs, interaction, graphics, result, trigger, otherArgs)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async doNext(current: string, previous: string, customInputs: InteractionInputCollection, interaction: InteractionDescriptor, graphics: Graphics, result: Map<string, ExecuteResult>, trigger: any, otherArgs?: any) {
|
|
52
|
+
const active = this.collection.get(current)
|
|
53
|
+
if (active === undefined) return
|
|
54
|
+
|
|
55
|
+
const currentInput = customInputs[current] ?? {}
|
|
56
|
+
const script = Asset.get<Scriptable>(active.url)
|
|
57
|
+
if (script) {
|
|
58
|
+
const args = { input: { previous, default: active.input, user: currentInput }, result, trigger }
|
|
59
|
+
if (otherArgs) Object.assign(args, otherArgs)
|
|
60
|
+
const executeResult = await script.execute(graphics, args)
|
|
61
|
+
result.set(current, executeResult)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (active.interaction === 'Branch') {
|
|
65
|
+
await this.doBranch(current, previous, customInputs, interaction, graphics, result, trigger, otherArgs)
|
|
66
|
+
} else if (active.interaction === 'Condition') {
|
|
67
|
+
if (result.has(current) === false) result.set(current, active.input)
|
|
68
|
+
await this.doCondition(current, previous, customInputs, interaction, graphics, result, trigger, otherArgs)
|
|
69
|
+
} else {
|
|
70
|
+
await this.doExecute(current, previous, customInputs, interaction, graphics, result, trigger, otherArgs)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async execute(customInputs: InteractionInputCollection, interaction: InteractionDescriptor, graphics: Graphics, trigger: any, otherArgs?: any) {
|
|
75
|
+
for (const root of interaction.roots) {
|
|
76
|
+
const resultCollection = new Map()
|
|
77
|
+
await this.doNext(root, '', customInputs, interaction, graphics, resultCollection, trigger, otherArgs)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
InteractionExecutor
|
|
84
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Descriptor } from "../descriptor"
|
|
2
|
+
import { Graphics } from "../graphics/Graphics"
|
|
3
|
+
import { InteractionInput } from "./InteractionDescriptor";
|
|
4
|
+
|
|
5
|
+
interface ScriptableInput<T = InteractionInput> {
|
|
6
|
+
previous: string;
|
|
7
|
+
default: T,
|
|
8
|
+
user: T
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface ScriptableArgs<T = InteractionInput, R = Map<string, any>, I = ScriptableInput<T>> {
|
|
12
|
+
input: I,
|
|
13
|
+
result: R,
|
|
14
|
+
trigger: Descriptor
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 可编程脚本(脚本不会在服务端实例化)
|
|
19
|
+
*/
|
|
20
|
+
class Scriptable<T extends ScriptableArgs<any, any, any> = ScriptableArgs> {
|
|
21
|
+
readonly uuid
|
|
22
|
+
/**脚本文件的url路径 */
|
|
23
|
+
get url() {
|
|
24
|
+
return this.uuid
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
constructor(url: string) {
|
|
28
|
+
this.uuid = url
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**脚本的准备事件,该方法在脚本被实例化后立即执行
|
|
32
|
+
*
|
|
33
|
+
* 一般在该事件中进行脚本的准备工作,如从服务端获取资源或数据
|
|
34
|
+
*/
|
|
35
|
+
async ready() { }
|
|
36
|
+
|
|
37
|
+
execute(graphics: Graphics, args: T): any { }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { ScriptableArgs, Scriptable }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnimationUnitDescriptor, Descriptor
|
|
1
|
+
import { AnimationUnitDescriptor, Descriptor } from '../descriptor';
|
|
2
2
|
import { ArrayUtils } from '../ArrayUtils';
|
|
3
3
|
import { Interpreter } from './Interpreter'
|
|
4
4
|
import { AnimationUnitActor } from "../actor";
|
|
@@ -29,8 +29,8 @@ class AnimationUnitInterpreter extends Interpreter {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
update(descriptor: AnimationUnitDescriptor
|
|
33
|
-
super.update(descriptor
|
|
32
|
+
update(descriptor: AnimationUnitDescriptor) {
|
|
33
|
+
super.update(descriptor)
|
|
34
34
|
|
|
35
35
|
this.freeUnit()
|
|
36
36
|
|
|
@@ -43,9 +43,9 @@ class AnimationUnitInterpreter extends Interpreter {
|
|
|
43
43
|
this.animationUnit.listen(this.graphics)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
unmount(descriptor: AnimationUnitDescriptor,
|
|
46
|
+
unmount(descriptor: AnimationUnitDescriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
47
47
|
this.freeUnit()
|
|
48
|
-
super.unmount(descriptor,
|
|
48
|
+
super.unmount(descriptor, parentInterpreter, parentDescriptor)
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
Interpreter.register(AnimationUnitInterpreter)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Descriptor, DivDescriptor
|
|
1
|
+
import { Descriptor, DivDescriptor } from "../descriptor"
|
|
2
2
|
import { Interpreter } from "./Interpreter"
|
|
3
3
|
import { DivActor, HTMLActor } from "../actor"
|
|
4
4
|
import { PickupObject } from "../graphics"
|
|
@@ -6,36 +6,36 @@ import { PickupObject } from "../graphics"
|
|
|
6
6
|
class DivInterpreter extends Interpreter {
|
|
7
7
|
static type = DivDescriptor.type
|
|
8
8
|
|
|
9
|
-
protected createActor(descriptor: DivDescriptor
|
|
9
|
+
protected createActor(descriptor: DivDescriptor) {
|
|
10
10
|
return new DivActor(descriptor.uuid)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
update(descriptor: DivDescriptor
|
|
14
|
-
super.update(descriptor
|
|
15
|
-
const actor = this.getActor<DivActor>(descriptor
|
|
16
|
-
actor.update(descriptor
|
|
13
|
+
update(descriptor: DivDescriptor) {
|
|
14
|
+
super.update(descriptor)
|
|
15
|
+
const actor = this.getActor<DivActor>(descriptor)
|
|
16
|
+
actor.update(descriptor)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
mount(descriptor: DivDescriptor,
|
|
20
|
-
super.mount(descriptor,
|
|
21
|
-
const actor = this.getActor<DivActor>(descriptor
|
|
19
|
+
mount(descriptor: DivDescriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
20
|
+
super.mount(descriptor, parentInterpreter, parentDescriptor)
|
|
21
|
+
const actor = this.getActor<DivActor>(descriptor)
|
|
22
22
|
|
|
23
|
-
const parenActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor
|
|
23
|
+
const parenActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor)
|
|
24
24
|
parenActor.add(actor)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
unmount(descriptor: DivDescriptor,
|
|
28
|
-
const actor = this.getActor<DivActor>(descriptor
|
|
27
|
+
unmount(descriptor: DivDescriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
28
|
+
const actor = this.getActor<DivActor>(descriptor)
|
|
29
29
|
actor.clearStyleClass(actor.DOM)
|
|
30
30
|
actor.cleanInteraction()
|
|
31
31
|
|
|
32
|
-
const parenActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor
|
|
32
|
+
const parenActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor)
|
|
33
33
|
parenActor.remove(actor)
|
|
34
34
|
|
|
35
|
-
super.unmount(descriptor,
|
|
35
|
+
super.unmount(descriptor, parentInterpreter, parentDescriptor)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
pickup(descriptor: DivDescriptor,
|
|
38
|
+
pickup(descriptor: DivDescriptor, result: PickupObject[]) {
|
|
39
39
|
result.push({ uuid: descriptor.uuid, generatedBy: descriptor.generatedBy })
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ArrayUtils } from "../ArrayUtils"
|
|
2
2
|
import { Asset } from "../asset"
|
|
3
|
-
import { DynamicDescriptor, Descriptor,
|
|
3
|
+
import { DynamicDescriptor, Descriptor, Data, DatasetDescriptor, PrefabeDescriptor } from "../descriptor"
|
|
4
4
|
import { observer, UpdateWatcherArgs, WatcherArgs } from "../graphics"
|
|
5
5
|
import { Category } from "../Category"
|
|
6
6
|
import { FragmentInterpreter, Interpreter } from "."
|
|
@@ -158,18 +158,18 @@ class DynamicInterpreter extends FragmentInterpreter {
|
|
|
158
158
|
this._cloneCollection.clear()
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
mount(descriptor: Descriptor,
|
|
162
|
-
super.mount(descriptor,
|
|
161
|
+
mount(descriptor: Descriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor): void {
|
|
162
|
+
super.mount(descriptor, parentInterpreter, parentDescriptor)
|
|
163
163
|
observer.listen('update', this._clearByOnUpdate)
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
unmount(descriptor: Descriptor,
|
|
166
|
+
unmount(descriptor: Descriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
167
167
|
observer.unlisten('update', this._clearByOnUpdate)
|
|
168
|
-
super.unmount(descriptor,
|
|
168
|
+
super.unmount(descriptor, parentInterpreter, parentDescriptor)
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
update(descriptor: DynamicDescriptor
|
|
172
|
-
super.update(descriptor
|
|
171
|
+
update(descriptor: DynamicDescriptor) {
|
|
172
|
+
super.update(descriptor)
|
|
173
173
|
|
|
174
174
|
observer.unlisten('add', this._onAdd)
|
|
175
175
|
observer.unlisten('remove', this._onRemove)
|
|
@@ -197,11 +197,11 @@ class DynamicInterpreter extends FragmentInterpreter {
|
|
|
197
197
|
observer.listen('update', this._onUpdate)
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
free(descriptor: Descriptor
|
|
200
|
+
free(descriptor: Descriptor) {
|
|
201
201
|
observer.unlisten('add', this._onAdd)
|
|
202
202
|
observer.unlisten('remove', this._onRemove)
|
|
203
203
|
observer.unlisten('update', this._onUpdate)
|
|
204
|
-
super.free(descriptor
|
|
204
|
+
super.free(descriptor)
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
FragmentInterpreter.register(DynamicInterpreter)
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { FragmentActor } from "../actor";
|
|
2
|
-
import { Descriptor
|
|
2
|
+
import { Descriptor } from "../descriptor";
|
|
3
3
|
import { Interpreter } from "./Interpreter";
|
|
4
4
|
|
|
5
5
|
class FragmentInterpreter extends Interpreter {
|
|
6
6
|
static type = Descriptor.type
|
|
7
7
|
|
|
8
|
-
protected createActor(descriptor: Descriptor
|
|
8
|
+
protected createActor(descriptor: Descriptor) {
|
|
9
9
|
return new FragmentActor()
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**将节点挂载到场景 */
|
|
13
|
-
mount(descriptor: Descriptor,
|
|
14
|
-
super.mount(descriptor,
|
|
15
|
-
const actor = this.getActor<FragmentActor>(descriptor
|
|
13
|
+
mount(descriptor: Descriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
14
|
+
super.mount(descriptor, parentInterpreter, parentDescriptor)
|
|
15
|
+
const actor = this.getActor<FragmentActor>(descriptor)
|
|
16
16
|
actor.bind(parentDescriptor.uuid)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**将节点从场景中卸载 */
|
|
20
|
-
unmount(descriptor: Descriptor,
|
|
21
|
-
super.unmount(descriptor,
|
|
20
|
+
unmount(descriptor: Descriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
21
|
+
super.unmount(descriptor, parentInterpreter, parentDescriptor)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
free(descriptor: Descriptor
|
|
25
|
-
const actor = this.getActor<FragmentActor>(descriptor
|
|
24
|
+
free(descriptor: Descriptor): void {
|
|
25
|
+
const actor = this.getActor<FragmentActor>(descriptor)
|
|
26
26
|
actor.unbind()
|
|
27
|
-
super.free(descriptor
|
|
27
|
+
super.free(descriptor)
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
Interpreter.register(FragmentInterpreter)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Descriptor, HTMLServiceDescriptor
|
|
1
|
+
import { Descriptor, HTMLServiceDescriptor } from "../descriptor"
|
|
2
2
|
import { Interpreter, ServiceInterpreter } from "."
|
|
3
3
|
import { HTMLActor, HTMLServiceActor } from "../actor"
|
|
4
4
|
import { PickupObject } from "../graphics"
|
|
@@ -6,39 +6,39 @@ import { PickupObject } from "../graphics"
|
|
|
6
6
|
class HTMLServiceInterpreter extends ServiceInterpreter {
|
|
7
7
|
static type = HTMLServiceDescriptor.type
|
|
8
8
|
|
|
9
|
-
protected createActor(descriptor: HTMLServiceDescriptor
|
|
9
|
+
protected createActor(descriptor: HTMLServiceDescriptor) {
|
|
10
10
|
const actor = new HTMLServiceActor(descriptor.uuid)
|
|
11
11
|
actor.DOM.addEventListener('pointerdown', e => e.stopPropagation())
|
|
12
12
|
return actor
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
update(descriptor: HTMLServiceDescriptor
|
|
16
|
-
super.update(descriptor
|
|
15
|
+
update(descriptor: HTMLServiceDescriptor) {
|
|
16
|
+
super.update(descriptor)
|
|
17
17
|
|
|
18
|
-
const actor = this.getActor<HTMLServiceActor>(descriptor
|
|
19
|
-
actor.update(descriptor
|
|
18
|
+
const actor = this.getActor<HTMLServiceActor>(descriptor)
|
|
19
|
+
actor.update(descriptor)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
mount(descriptor: HTMLServiceDescriptor,
|
|
23
|
-
super.mount(descriptor,
|
|
24
|
-
const actor = this.getActor<HTMLServiceActor>(descriptor
|
|
22
|
+
mount(descriptor: HTMLServiceDescriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
23
|
+
super.mount(descriptor, parentInterpreter, parentDescriptor)
|
|
24
|
+
const actor = this.getActor<HTMLServiceActor>(descriptor)
|
|
25
25
|
|
|
26
|
-
const parenActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor
|
|
26
|
+
const parenActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor)
|
|
27
27
|
parenActor.add(actor)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
unmount(descriptor: HTMLServiceDescriptor,
|
|
31
|
-
const actor = this.getActor<HTMLServiceActor>(descriptor
|
|
30
|
+
unmount(descriptor: HTMLServiceDescriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
31
|
+
const actor = this.getActor<HTMLServiceActor>(descriptor)
|
|
32
32
|
actor.clearStyleClass(actor.DOM)
|
|
33
33
|
actor.cleanInteraction()
|
|
34
34
|
|
|
35
|
-
const parenActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor
|
|
35
|
+
const parenActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor)
|
|
36
36
|
parenActor.remove(actor)
|
|
37
37
|
|
|
38
|
-
super.unmount(descriptor,
|
|
38
|
+
super.unmount(descriptor, parentInterpreter, parentDescriptor)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
pickup(descriptor: HTMLServiceDescriptor,
|
|
41
|
+
pickup(descriptor: HTMLServiceDescriptor, result: PickupObject[]) {
|
|
42
42
|
result.push({ uuid: descriptor.uuid, generatedBy: descriptor.generatedBy })
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { Descriptor, HTMLTransformControllerDescriptor
|
|
1
|
+
import { Descriptor, HTMLTransformControllerDescriptor } from "../descriptor"
|
|
2
2
|
import { HTMLTransformControllerActor } from "../actor"
|
|
3
3
|
import { Interpreter } from "./Interpreter"
|
|
4
4
|
|
|
5
5
|
class HTMLTransformControllerInterpreter extends Interpreter {
|
|
6
6
|
static type = HTMLTransformControllerDescriptor.type
|
|
7
7
|
|
|
8
|
-
protected createActor(descriptor: HTMLTransformControllerDescriptor
|
|
8
|
+
protected createActor(descriptor: HTMLTransformControllerDescriptor) {
|
|
9
9
|
const actor = new HTMLTransformControllerActor()
|
|
10
10
|
return actor
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
update(descriptor: HTMLTransformControllerDescriptor
|
|
14
|
-
super.update(descriptor
|
|
15
|
-
const actor = this.getActor<HTMLTransformControllerActor>(descriptor
|
|
16
|
-
actor.update(descriptor
|
|
13
|
+
update(descriptor: HTMLTransformControllerDescriptor) {
|
|
14
|
+
super.update(descriptor)
|
|
15
|
+
const actor = this.getActor<HTMLTransformControllerActor>(descriptor)
|
|
16
|
+
actor.update(descriptor)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
mount(descriptor: HTMLTransformControllerDescriptor,
|
|
20
|
-
super.mount(descriptor,
|
|
21
|
-
this.getActor<HTMLTransformControllerActor>(descriptor
|
|
19
|
+
mount(descriptor: HTMLTransformControllerDescriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
20
|
+
super.mount(descriptor, parentInterpreter, parentDescriptor)
|
|
21
|
+
this.getActor<HTMLTransformControllerActor>(descriptor)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
unmount(descriptor: HTMLTransformControllerDescriptor,
|
|
25
|
-
const actor = this.getActor<HTMLTransformControllerActor>(descriptor
|
|
24
|
+
unmount(descriptor: HTMLTransformControllerDescriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
25
|
+
const actor = this.getActor<HTMLTransformControllerActor>(descriptor)
|
|
26
26
|
actor.unlisten()
|
|
27
27
|
|
|
28
|
-
super.unmount(descriptor,
|
|
28
|
+
super.unmount(descriptor, parentInterpreter, parentDescriptor)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
free(descriptor: HTMLTransformControllerDescriptor
|
|
32
|
-
const actor = this.getActor<HTMLTransformControllerActor>(descriptor
|
|
31
|
+
free(descriptor: HTMLTransformControllerDescriptor) {
|
|
32
|
+
const actor = this.getActor<HTMLTransformControllerActor>(descriptor)
|
|
33
33
|
actor.dispose()
|
|
34
|
-
super.free(descriptor
|
|
34
|
+
super.free(descriptor)
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
Interpreter.register(HTMLTransformControllerInterpreter)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { language } from '../locale'
|
|
2
2
|
import { Actor } from '../actor'
|
|
3
3
|
import { Unit, PickupObject, Graphics } from "../graphics"
|
|
4
|
-
import { Descriptor
|
|
4
|
+
import { Descriptor } from "../descriptor"
|
|
5
5
|
|
|
6
6
|
const privateState = {
|
|
7
7
|
factory: false,
|
|
@@ -33,37 +33,37 @@ class Interpreter {
|
|
|
33
33
|
this.graphics = graphics
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
protected createActor(descriptor: Descriptor
|
|
36
|
+
protected createActor(descriptor: Descriptor) {
|
|
37
37
|
return new Actor()
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**使用描述器获取代理对象,若代理对象不存在则会使用描述器创建一个代理对象 */
|
|
41
|
-
getActor<T extends Actor = Actor>(descriptor: Descriptor
|
|
41
|
+
getActor<T extends Actor = Actor>(descriptor: Descriptor): T {
|
|
42
42
|
let actor = privateState.actorCollection.get(this)
|
|
43
43
|
if (actor !== undefined) return actor as T
|
|
44
|
-
actor = this.createActor(descriptor
|
|
44
|
+
actor = this.createActor(descriptor)
|
|
45
45
|
Actor.seGraphics(actor, this.graphics)
|
|
46
46
|
privateState.actorCollection.set(this, actor)
|
|
47
47
|
return actor as T
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**使用描述更新节点 */
|
|
51
|
-
update(descriptor: Descriptor,
|
|
51
|
+
update(descriptor: Descriptor,) { }
|
|
52
52
|
|
|
53
53
|
/**将节点挂载到场景 */
|
|
54
|
-
mount(descriptor: Descriptor,
|
|
54
|
+
mount(descriptor: Descriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) { }
|
|
55
55
|
|
|
56
56
|
/**将节点从场景中卸载 */
|
|
57
|
-
unmount(descriptor: Descriptor,
|
|
57
|
+
unmount(descriptor: Descriptor, parentInterpreter: Interpreter, parentDescriptor: Descriptor) { }
|
|
58
58
|
|
|
59
|
-
free(descriptor: Descriptor
|
|
59
|
+
free(descriptor: Descriptor) {
|
|
60
60
|
const actor = privateState.actorCollection.get(this)
|
|
61
61
|
if (actor === undefined) return
|
|
62
62
|
Actor.seGraphics(actor, this.graphics)
|
|
63
63
|
privateState.actorCollection.delete(this)
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
pickup(descriptor: Descriptor,
|
|
66
|
+
pickup(descriptor: Descriptor, result: PickupObject[]) { }
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export { Interpreter, privateState }
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { ServiceDescriptor
|
|
1
|
+
import { ServiceDescriptor } from "../descriptor";
|
|
2
2
|
import { PickupObject } from "../graphics";
|
|
3
3
|
import { Interpreter } from "./Interpreter";
|
|
4
4
|
|
|
5
5
|
class ServiceInterpreter extends Interpreter {
|
|
6
6
|
static type = ServiceDescriptor.type
|
|
7
7
|
|
|
8
|
-
clear(service: ServiceDescriptor
|
|
8
|
+
clear(service: ServiceDescriptor) { }
|
|
9
9
|
|
|
10
|
-
beforeRender(service: ServiceDescriptor
|
|
10
|
+
beforeRender(service: ServiceDescriptor) { }
|
|
11
11
|
|
|
12
|
-
render(service: ServiceDescriptor
|
|
12
|
+
render(service: ServiceDescriptor) { }
|
|
13
13
|
|
|
14
|
-
afterRender(service: ServiceDescriptor
|
|
14
|
+
afterRender(service: ServiceDescriptor) { }
|
|
15
15
|
|
|
16
|
-
beforePickup(mouse: { x: number; y: number }, rect: DOMRect
|
|
16
|
+
beforePickup(mouse: { x: number; y: number }, rect: DOMRect) { }
|
|
17
17
|
|
|
18
18
|
orderBy(result: PickupObject[]) { }
|
|
19
19
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Descriptor, ServiceSchedulerDescriptor
|
|
1
|
+
import { Descriptor, ServiceSchedulerDescriptor } from "../descriptor"
|
|
2
2
|
import { DivActor } from "../actor"
|
|
3
3
|
import { Interpreter } from "./Interpreter"
|
|
4
4
|
|
|
5
5
|
class ServiceSchedulerInterpreter extends Interpreter {
|
|
6
6
|
static type = ServiceSchedulerDescriptor.type
|
|
7
7
|
|
|
8
|
-
protected createActor(descriptor: Descriptor
|
|
8
|
+
protected createActor(descriptor: Descriptor) {
|
|
9
9
|
const actor = new DivActor(descriptor.uuid)
|
|
10
10
|
return actor
|
|
11
11
|
}
|
|
@@ -13,8 +13,8 @@ class ServiceSchedulerInterpreter extends Interpreter {
|
|
|
13
13
|
private resize = () => { }
|
|
14
14
|
private unresize = () => { }
|
|
15
15
|
|
|
16
|
-
install(descriptor: ServiceSchedulerDescriptor
|
|
17
|
-
const actor = this.getActor<DivActor>(descriptor
|
|
16
|
+
install(descriptor: ServiceSchedulerDescriptor) {
|
|
17
|
+
const actor = this.getActor<DivActor>(descriptor)
|
|
18
18
|
const wrapper = actor.getWrapper()
|
|
19
19
|
|
|
20
20
|
this.graphics.engine.DOM.appendChild(wrapper)
|
|
@@ -30,9 +30,9 @@ class ServiceSchedulerInterpreter extends Interpreter {
|
|
|
30
30
|
this.resize()
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
uninstall(descriptor: ServiceSchedulerDescriptor
|
|
33
|
+
uninstall(descriptor: ServiceSchedulerDescriptor) {
|
|
34
34
|
this.unresize()
|
|
35
|
-
const actor = this.getActor<DivActor>(descriptor
|
|
35
|
+
const actor = this.getActor<DivActor>(descriptor)
|
|
36
36
|
const wrapper = actor.getWrapper()
|
|
37
37
|
wrapper.remove()
|
|
38
38
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Descriptor, StyleDescriptor
|
|
1
|
+
import { Descriptor, StyleDescriptor } from "../descriptor";
|
|
2
2
|
import { StyleActor } from "../actor";
|
|
3
3
|
import { Graphics, Unit } from "../graphics";
|
|
4
4
|
import { Interpreter } from "./Interpreter";
|
|
@@ -27,14 +27,14 @@ class StyleInterpreter extends Interpreter {
|
|
|
27
27
|
this.className = `vyr_${unit.uuid}`
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
protected createActor(descriptor: StyleDescriptor
|
|
30
|
+
protected createActor(descriptor: StyleDescriptor) {
|
|
31
31
|
return new StyleActor()
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
update(descriptor: StyleDescriptor
|
|
35
|
-
super.update(descriptor
|
|
34
|
+
update(descriptor: StyleDescriptor) {
|
|
35
|
+
super.update(descriptor)
|
|
36
36
|
|
|
37
|
-
const actor = this.getActor<StyleActor>(descriptor
|
|
37
|
+
const actor = this.getActor<StyleActor>(descriptor)
|
|
38
38
|
actor.update(descriptor, this.className)
|
|
39
39
|
|
|
40
40
|
if (actor.updateRule(StyleInterpreter.sheet) === true) return
|
|
@@ -43,7 +43,7 @@ class StyleInterpreter extends Interpreter {
|
|
|
43
43
|
StyleInterpreter.insertRule(styleValues)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
free(descriptor: Descriptor
|
|
46
|
+
free(descriptor: Descriptor) {
|
|
47
47
|
const selectorTexts = [`.${this.className}`, `.${this.className}:hover`]
|
|
48
48
|
for (let i = StyleInterpreter.sheet.cssRules.length - 1; i >= 0; i--) {
|
|
49
49
|
const rule = StyleInterpreter.sheet.cssRules[i]
|
|
@@ -56,7 +56,7 @@ class StyleInterpreter extends Interpreter {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
super.free(descriptor
|
|
59
|
+
super.free(descriptor)
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
Interpreter.register(StyleInterpreter)
|
package/src/interpreter/index.ts
CHANGED
|
@@ -4,7 +4,6 @@ export * from './StyleInterpreter'
|
|
|
4
4
|
export * from './AnimationUnitInterpreter'
|
|
5
5
|
export * from './FragmentInterpreter'
|
|
6
6
|
export * from './DynamicInterpreter'
|
|
7
|
-
export * from './RoutineInterpreter'
|
|
8
7
|
export * from './PrefaInterpreter'
|
|
9
8
|
export * from './PrefabInstanceInterpreter'
|
|
10
9
|
export * from "./DivInterpreter";
|
|
@@ -14,8 +14,9 @@ interface ZhCNLanguageProvider extends LanguageProvider {
|
|
|
14
14
|
'graphics.unit.notFound': string
|
|
15
15
|
'engine.run.container.notFound': string
|
|
16
16
|
|
|
17
|
-
'/virtual:/preset/net/
|
|
17
|
+
'/virtual:/preset/net/http.ts': string
|
|
18
18
|
'/virtual:/preset/dataset/update.ts': string
|
|
19
|
+
'/virtual:/preset/dataset/compile.ts': string
|
|
19
20
|
'/virtual:/preset/scheduler/switch.ts': string
|
|
20
21
|
'/virtual:/preset/graphics/invoke.ts': string
|
|
21
22
|
}
|
|
@@ -36,8 +37,9 @@ const zhCnLanguageProvider: ZhCNLanguageProvider = {
|
|
|
36
37
|
'graphics.unit.notFound': '单元不存在:{{uuid}}',
|
|
37
38
|
'engine.run.container.notFound': '挂载节点不存在',
|
|
38
39
|
|
|
39
|
-
'/virtual:/preset/net/
|
|
40
|
+
'/virtual:/preset/net/http.ts': '网络请求',
|
|
40
41
|
'/virtual:/preset/dataset/update.ts': '更新数据集',
|
|
42
|
+
'/virtual:/preset/dataset/compile.ts': '组合数据集',
|
|
41
43
|
'/virtual:/preset/scheduler/switch.ts': '切换场景',
|
|
42
44
|
'/virtual:/preset/graphics/invoke.ts': '调用交互',
|
|
43
45
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { language } from "../../../locale";
|
|
2
|
+
import { Asset } from "../../../asset";
|
|
3
|
+
import { InteractionNode, Scriptable, ScriptableArgs } from "../../../interaction";
|
|
4
|
+
import { Graphics } from "../../../graphics";
|
|
5
|
+
|
|
6
|
+
const scriptable = Asset.createVirtualUrl('preset/dataset/compile.ts')
|
|
7
|
+
class ExecuteScriptable extends Scriptable {
|
|
8
|
+
async execute(graphics: Graphics, args: ScriptableArgs) {
|
|
9
|
+
// const { input, result } = args
|
|
10
|
+
console.log(args)
|
|
11
|
+
|
|
12
|
+
return {}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
Asset.provider(scriptable, async () => ({ default: ExecuteScriptable }))
|
|
16
|
+
|
|
17
|
+
const createExecuteInput = (args: any = {}) => {
|
|
18
|
+
const input = {
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return input
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const createExecuteNode = (options: { id: string; position?: any; input?: any }) => {
|
|
26
|
+
const executeNode: InteractionNode = {
|
|
27
|
+
id: options.id,
|
|
28
|
+
label: language.get(scriptable as any),
|
|
29
|
+
position: { x: options?.position?.x ?? 20, y: options?.position?.y ?? 20 },
|
|
30
|
+
interaction: 'Execute',
|
|
31
|
+
url: scriptable,
|
|
32
|
+
input: createExecuteInput(options.input)
|
|
33
|
+
}
|
|
34
|
+
return executeNode
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
scriptable,
|
|
39
|
+
createExecuteInput,
|
|
40
|
+
createExecuteNode,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|