@vyr/engine 0.0.1 → 0.0.3

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.
Files changed (59) hide show
  1. package/package.json +1 -19
  2. package/src/Category.ts +7 -7
  3. package/src/Engine.ts +29 -15
  4. package/src/actor/AnimationUnitActor.ts +3 -3
  5. package/src/actor/DivActor.ts +6 -6
  6. package/src/actor/FragmentActor.ts +3 -3
  7. package/src/actor/HTMActor.ts +19 -16
  8. package/src/actor/HTMServiceActor.ts +4 -4
  9. package/src/actor/HTMTransformControllerActor.ts +15 -10
  10. package/src/asset/Asset.ts +25 -27
  11. package/src/asset/AssetGraph.ts +4 -4
  12. package/src/descriptor/DatasetDescriptor.ts +20 -22
  13. package/src/descriptor/Descriptor.ts +1 -28
  14. package/src/descriptor/HTMLTransformControllerDescriptor.ts +2 -2
  15. package/src/descriptor/index.ts +0 -1
  16. package/src/graphics/Compilation.ts +37 -45
  17. package/src/graphics/Graphics.ts +80 -68
  18. package/src/graphics/VariableProxy.ts +8 -8
  19. package/src/index.ts +2 -1
  20. package/src/interaction/InteractionDescriptor.ts +96 -0
  21. package/src/interaction/InteractionExecutor.ts +84 -0
  22. package/src/interaction/Scriptable.ts +40 -0
  23. package/src/interaction/index.ts +3 -0
  24. package/src/interpreter/AnimationUnitInterpreter.ts +5 -5
  25. package/src/interpreter/DivInterpreter.ts +15 -15
  26. package/src/interpreter/DynamicInterpreter.ts +9 -9
  27. package/src/interpreter/FragmentInterpreter.ts +10 -10
  28. package/src/interpreter/HTMLServiceInterpreter.ts +15 -15
  29. package/src/interpreter/HTMLTransformControllerInterpreter.ts +15 -15
  30. package/src/interpreter/Interpreter.ts +9 -9
  31. package/src/interpreter/ServiceInterpreter.ts +6 -6
  32. package/src/interpreter/ServiceSchedulerInterpreter.ts +6 -6
  33. package/src/interpreter/StyleInterpreter.ts +7 -7
  34. package/src/interpreter/index.ts +0 -1
  35. package/src/locale/LanguageProvider.ts +4 -2
  36. package/src/preset/execute/dataset/compile.ts +99 -0
  37. package/src/preset/execute/dataset/index.ts +2 -1
  38. package/src/preset/execute/dataset/update.ts +7 -8
  39. package/src/preset/execute/graphics/invoke.ts +5 -6
  40. package/src/preset/execute/net/{request.ts → http.ts} +9 -17
  41. package/src/preset/execute/net/index.ts +1 -1
  42. package/src/preset/execute/scheduler/switch.ts +8 -8
  43. package/src/preset/index.ts +2 -2
  44. package/src/preset/interaction/dataset/compile.ts +27 -0
  45. package/src/preset/interaction/dataset/index.ts +1 -0
  46. package/src/preset/interaction/graphics/invoke.ts +27 -0
  47. package/src/preset/interaction/index.ts +3 -0
  48. package/src/preset/interaction/scheduler/switch.ts +27 -0
  49. package/src/utils/AssetProvider.ts +7 -6
  50. package/src/utils/constants.ts +10 -0
  51. package/src/utils/index.ts +1 -0
  52. package/src/Scriptable.ts +0 -27
  53. package/src/descriptor/RoutineDescriptor.ts +0 -54
  54. package/src/interpreter/RoutineInterpreter.ts +0 -88
  55. package/src/preset/routine/graphics/invoke.ts +0 -27
  56. package/src/preset/routine/index.ts +0 -2
  57. package/src/preset/routine/scheduler/switch.ts +0 -27
  58. /package/src/preset/{routine → interaction}/graphics/index.ts +0 -0
  59. /package/src/preset/{routine → interaction}/scheduler/index.ts +0 -0
@@ -1,4 +1,4 @@
1
- import { Descriptor, StyleDescriptor, UpdateArgs } from "../descriptor";
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, args: UpdateArgs) {
30
+ protected createActor(descriptor: StyleDescriptor) {
31
31
  return new StyleActor()
32
32
  }
33
33
 
34
- update(descriptor: StyleDescriptor, args: UpdateArgs) {
35
- super.update(descriptor, args)
34
+ update(descriptor: StyleDescriptor) {
35
+ super.update(descriptor)
36
36
 
37
- const actor = this.getActor<StyleActor>(descriptor, args)
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, args: UpdateArgs) {
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, args)
59
+ super.free(descriptor)
60
60
  }
61
61
  }
62
62
  Interpreter.register(StyleInterpreter)
@@ -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/request.ts': string
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/request.ts': '网络请求',
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,99 @@
1
+ import { language } from "../../../locale";
2
+ import { Asset } from "../../../asset";
3
+ import { InteractionNode, Scriptable, ScriptableArgs } from "../../../interaction";
4
+ import { DatasetDescriptor, Descriptor, HttpDataConfig } from "../../../descriptor";
5
+ import { Graphics } from "../../../graphics";
6
+ import { ExecuteScriptable as HttpScriptable } from "../net/http";
7
+
8
+ const scriptable = Asset.createVirtualUrl('preset/dataset/compile.ts')
9
+ class ExecuteScriptable extends Scriptable {
10
+
11
+ async getData(config: HttpDataConfig, http: HttpScriptable, trigger: Descriptor, graphics: Graphics) {
12
+ const args: ScriptableArgs = {
13
+ input: {
14
+ previous: '',
15
+ user: {
16
+ type: { value: config.type },
17
+ url: { value: config.url },
18
+ data: { value: '' },
19
+ },
20
+ default: {}
21
+ },
22
+ result: new Map(),
23
+ trigger: trigger
24
+ }
25
+
26
+ const data = await http.execute(graphics, args)
27
+
28
+ return this.transformData(data, config)
29
+ }
30
+
31
+ transformData(data: any, config: HttpDataConfig) {
32
+ return data
33
+ }
34
+
35
+ async execute(graphics: Graphics, args: ScriptableArgs) {
36
+ const { trigger } = args
37
+
38
+ if (trigger instanceof DatasetDescriptor && trigger.dataConfigs.length > 0) {
39
+ const dataConfigs = trigger.dataConfigs as HttpDataConfig[]
40
+ const http = new HttpScriptable(Asset.createVirtualUrl('preset/dataset/compile/http.ts'))
41
+
42
+ let mergeData: any[] | any
43
+ if (dataConfigs.length === 1) {
44
+ const config = dataConfigs[0]
45
+ const finalData = await this.getData(config, http, trigger, graphics)
46
+ mergeData = config.key ? { [config.key]: finalData } : finalData
47
+ } else {
48
+ const keys = new Set<string>()
49
+ const queue: Promise<any>[] = []
50
+ for (const config of dataConfigs) {
51
+ keys.add(config.key)
52
+
53
+ const task = this.getData(config, http, trigger, graphics).then(finalData => {
54
+ const first = keys.values().next().value
55
+ if (keys.size === 1 && (first === '' || first === undefined)) {
56
+ if (!mergeData) mergeData = []
57
+ mergeData.push(finalData)
58
+ } else {
59
+ if (!mergeData) mergeData = {}
60
+ mergeData[config.key] ? Object.assign(mergeData[config.key], finalData) : mergeData[config.key] = finalData
61
+ }
62
+ })
63
+ queue.push(task)
64
+ }
65
+ await Promise.all(queue)
66
+ }
67
+
68
+ trigger.setData(mergeData)
69
+ }
70
+ }
71
+ }
72
+ Asset.provider(scriptable, async () => ({ default: ExecuteScriptable }))
73
+
74
+ const createExecuteInput = (args: any = {}) => {
75
+ const input = {
76
+ }
77
+
78
+ return input
79
+ }
80
+
81
+ const createExecuteNode = (options: { id: string; position?: any; input?: any }) => {
82
+ const executeNode: InteractionNode = {
83
+ id: options.id,
84
+ label: language.get(scriptable as any),
85
+ position: { x: options?.position?.x ?? 20, y: options?.position?.y ?? 20 },
86
+ interaction: 'Execute',
87
+ url: scriptable,
88
+ input: createExecuteInput(options.input)
89
+ }
90
+ return executeNode
91
+ }
92
+
93
+ export {
94
+ scriptable,
95
+ createExecuteInput,
96
+ createExecuteNode,
97
+ }
98
+
99
+
@@ -1 +1,2 @@
1
- export * as update from './update'
1
+ export * as update from './update'
2
+ export * as compile from './compile'
@@ -1,16 +1,15 @@
1
1
  import { language } from "../../../locale";
2
2
  import { Asset } from "../../../asset";
3
- import { DatasetDescriptor, Descriptor, RoutineNode, UpdateArgs } from "../../../descriptor";
3
+ import { DatasetDescriptor } from "../../../descriptor";
4
+ import { InteractionNode, Scriptable, ScriptableArgs } from "../../../interaction";
4
5
  import { Graphics } from "../../../graphics";
5
- import { Scriptable } from "../../../Scriptable";
6
6
  import { Category } from "../../../Category";
7
7
 
8
8
  const scriptable = Asset.createVirtualUrl('preset/dataset/update.ts')
9
9
  class ExecuteScriptable extends Scriptable {
10
- async execute(descriptor: Descriptor, graphics: Graphics, args: UpdateArgs) {
11
- //@ts-ignore
10
+ async execute(graphics: Graphics, args: ScriptableArgs) {
12
11
  const { input, result } = args
13
- const dataset = input?.user?.url.value ?? input.default.url.value
12
+ const dataset = input?.user?.dataset.value ?? input.default.dataset.value
14
13
 
15
14
  const previous = result.get(input.previous)
16
15
  const datasetDescriptor = Asset.get<DatasetDescriptor>(dataset)
@@ -25,18 +24,18 @@ Asset.provider(scriptable, async () => ({ default: ExecuteScriptable }))
25
24
 
26
25
  const createExecuteInput = (args: any = {}) => {
27
26
  const input = {
28
- url: { value: args.url ?? '', type: Category.dataset }
27
+ dataset: { value: args.dataset ?? '', type: Category.dataset }
29
28
  }
30
29
 
31
30
  return input
32
31
  }
33
32
 
34
33
  const createExecuteNode = (options: { id: string; position?: any; input?: any }) => {
35
- const executeNode: RoutineNode = {
34
+ const executeNode: InteractionNode = {
36
35
  id: options.id,
37
36
  label: language.get(scriptable as any),
38
37
  position: { x: options?.position?.x ?? 20, y: options?.position?.y ?? 20 },
39
- routine: 'Execute',
38
+ interaction: 'Execute',
40
39
  url: scriptable,
41
40
  input: createExecuteInput(options.input)
42
41
  }
@@ -1,13 +1,12 @@
1
1
  import { language } from "../../../locale";
2
2
  import { Asset } from "../../../asset";
3
- import { Descriptor, RoutineNode, UpdateArgs } from "../../../descriptor";
3
+ import { Descriptor } from "../../../descriptor";
4
+ import { InteractionNode, Scriptable, ScriptableArgs } from "../../../interaction";
4
5
  import { Graphics } from "../../../graphics";
5
- import { Scriptable } from "../../../Scriptable";
6
6
 
7
7
  const scriptable = Asset.createVirtualUrl('preset/graphics/invoke.ts')
8
8
  class ExecuteScriptable extends Scriptable {
9
- async execute(descriptor: Descriptor, graphics: Graphics, args: UpdateArgs) {
10
- //@ts-ignore
9
+ async execute(graphics: Graphics, args: ScriptableArgs) {
11
10
  const { input } = args
12
11
  const interaction = input?.user?.interaction.value ?? input.default.interaction.value
13
12
  const target = input?.user?.target.value ?? input.default.target.value
@@ -29,11 +28,11 @@ const createExecuteInput = (args: any = {}) => {
29
28
  }
30
29
 
31
30
  const createExecuteNode = (options: { id: string; position?: any; input?: any }) => {
32
- const executeNode: RoutineNode = {
31
+ const executeNode: InteractionNode = {
33
32
  id: options.id,
34
33
  label: language.get(scriptable as any),
35
34
  position: { x: options?.position?.x ?? 20, y: options?.position?.y ?? 20 },
36
- routine: 'Execute',
35
+ interaction: 'Execute',
37
36
  url: scriptable,
38
37
  input: createExecuteInput(options.input)
39
38
  }
@@ -1,21 +1,14 @@
1
1
  import { language } from "../../../locale";
2
2
  import { Asset } from "../../../asset";
3
- import { Descriptor, RoutineNode, UpdateArgs } from "../../../descriptor";
3
+ import { HttpType } from "../../../utils";
4
4
  import { Graphics } from "../../../graphics";
5
- import { Scriptable } from "../../../Scriptable";
5
+ import { Scriptable, InteractionNode, ScriptableArgs } from "../../../interaction";
6
6
 
7
- enum RequestType {
8
- GET = 'GET',
9
- POST = 'POST',
10
- PUT = 'PUT',
11
- DELETE = 'DELETE',
12
- }
13
-
14
- const scriptable = Asset.createVirtualUrl('preset/net/request.ts')
7
+ const scriptable = Asset.createVirtualUrl('preset/net/http.ts')
15
8
  class ExecuteScriptable extends Scriptable {
16
9
 
17
10
  joinUrl(url: string, requestData: any) {
18
- const urlObj = new URL(url);
11
+ const urlObj = new URL(Asset.joinUrl(url));
19
12
 
20
13
  // 直接将requestData添加到urlObj的searchParams中
21
14
  Object.entries(requestData).forEach(([key, value]) => {
@@ -27,8 +20,7 @@ class ExecuteScriptable extends Scriptable {
27
20
  return urlObj.toString()
28
21
  }
29
22
 
30
- async execute(descriptor: Descriptor, graphics: Graphics, args: UpdateArgs) {
31
- //@ts-ignore
23
+ async execute(graphics: Graphics, args: ScriptableArgs) {
32
24
  const { input, result } = args
33
25
  let url = input?.user?.url.value ?? input.default.url.value
34
26
  const type: string = input?.user?.type.value ?? input.default.type.value
@@ -58,7 +50,7 @@ class ExecuteScriptable extends Scriptable {
58
50
  },
59
51
  }
60
52
  let res
61
- if (type === RequestType.GET) {
53
+ if (type === HttpType.GET) {
62
54
  res = await fetch(this.joinUrl(url, requestData), config)
63
55
  } else {
64
56
  res = await fetch(url, { ...config, body: JSON.stringify(requestData) })
@@ -82,11 +74,11 @@ const createExecuteInput = (args: any = {}) => {
82
74
  }
83
75
 
84
76
  const createExecuteNode = (options: { id: string; position?: any; input?: any }) => {
85
- const executeNode: RoutineNode = {
77
+ const executeNode: InteractionNode = {
86
78
  id: options.id,
87
79
  label: language.get(scriptable as any),
88
80
  position: { x: options?.position?.x ?? 20, y: options?.position?.y ?? 20 },
89
- routine: 'Execute',
81
+ interaction: 'Execute',
90
82
  url: scriptable,
91
83
  input: createExecuteInput(options.input)
92
84
  }
@@ -95,7 +87,7 @@ const createExecuteNode = (options: { id: string; position?: any; input?: any })
95
87
 
96
88
  export {
97
89
  scriptable,
98
- RequestType,
90
+ ExecuteScriptable,
99
91
  createExecuteInput,
100
92
  createExecuteNode,
101
93
  }
@@ -1 +1 @@
1
- export * as request from './request'
1
+ export * as http from './http'
@@ -1,16 +1,16 @@
1
1
  import { language } from "../../../locale";
2
2
  import { Asset } from "../../../asset";
3
- import { Descriptor, RoutineNode, ServiceSchedulerDescriptor, UpdateArgs } from "../../../descriptor";
3
+ import { ServiceSchedulerDescriptor } from "../../../descriptor";
4
+ import { InteractionNode, Scriptable, ScriptableArgs } from "../../../interaction";
4
5
  import { Graphics } from "../../../graphics";
5
- import { Scriptable } from "../../../Scriptable";
6
6
 
7
7
  const scriptable = Asset.createVirtualUrl('preset/scheduler/switch.ts')
8
8
  class ExecuteScriptable extends Scriptable {
9
- async execute(descriptor: Descriptor, graphics: Graphics, args: UpdateArgs) {
10
- //@ts-ignore
11
- const scene = args.input?.user?.url.value
9
+ async execute(graphics: Graphics, args: ScriptableArgs) {
10
+ const scene = args.input?.user?.scene.value
12
11
  if (!scene) return
13
12
  await Asset.loadAll(scene)
13
+ await Asset.compileDataset(scene, graphics.engine)
14
14
  const scheduler = Asset.get<ServiceSchedulerDescriptor>(scene)
15
15
  graphics.engine.switch(scheduler)
16
16
  }
@@ -19,18 +19,18 @@ Asset.provider(scriptable, async () => ({ default: ExecuteScriptable }))
19
19
 
20
20
  const createExecuteInput = (args: any = {}) => {
21
21
  const input = {
22
- url: { value: args.url ?? '' },
22
+ scene: { value: args.scene ?? '' },
23
23
  }
24
24
 
25
25
  return input
26
26
  }
27
27
 
28
28
  const createExecuteNode = (options: { id: string; position?: any; input?: any }) => {
29
- const executeNode: RoutineNode = {
29
+ const executeNode: InteractionNode = {
30
30
  id: options.id,
31
31
  label: language.get(scriptable as any),
32
32
  position: { x: options?.position?.x ?? 20, y: options?.position?.y ?? 20 },
33
- routine: 'Execute',
33
+ interaction: 'Execute',
34
34
  url: scriptable,
35
35
  input: createExecuteInput(options.input)
36
36
  }
@@ -1,7 +1,7 @@
1
1
  import * as executePreset from './execute'
2
- import * as routinePreset from './routine'
2
+ import * as interactionPreset from './interaction'
3
3
 
4
4
  export {
5
5
  executePreset,
6
- routinePreset
6
+ interactionPreset
7
7
  }
@@ -0,0 +1,27 @@
1
+ import { Asset } from "../../../asset";
2
+ import { InteractionDescriptor } from "../../../interaction";
3
+ import { dataset } from "../../execute"
4
+
5
+ const url = Asset.createVirtualUrl('preset/dataset/compile.interaction.json')
6
+ const nodes = {
7
+ compile: 'compile'
8
+ }
9
+ let _currentInteraction: InteractionDescriptor | null = null
10
+ const interactionProvider = async () => {
11
+ if (_currentInteraction === null) {
12
+ _currentInteraction = new InteractionDescriptor()
13
+ const compileNode = dataset.compile.createExecuteNode({ id: nodes.compile })
14
+ _currentInteraction.addNode([compileNode])
15
+ _currentInteraction.roots.push(compileNode.id)
16
+ }
17
+ return _currentInteraction
18
+ }
19
+
20
+ Asset.provider(url, interactionProvider)
21
+
22
+ export {
23
+ url,
24
+ nodes,
25
+ }
26
+
27
+
@@ -0,0 +1 @@
1
+ export * as compile from "./compile"
@@ -0,0 +1,27 @@
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.provider(url, interactionProvider)
21
+
22
+ export {
23
+ url,
24
+ nodes,
25
+ }
26
+
27
+
@@ -0,0 +1,3 @@
1
+ export * as dataset from './dataset'
2
+ export * as scheduler from './scheduler'
3
+ export * as graphics from './graphics'
@@ -0,0 +1,27 @@
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.provider(url, interactionProvider)
21
+
22
+ export {
23
+ url,
24
+ nodes,
25
+ }
26
+
27
+
@@ -1,4 +1,5 @@
1
- import { Descriptor, DynamicDescriptor, PrefabInstanceDescriptor, RoutineDescriptor, HTMLDescriptor, StyleDescriptor, InteractionProperty, RoutineNode } from "../descriptor"
1
+ import { InteractionDescriptor, InteractionNode, InteractionProperty } from "../interaction"
2
+ import { Descriptor, DynamicDescriptor, PrefabInstanceDescriptor, HTMLDescriptor, StyleDescriptor } from "../descriptor"
2
3
  import { AssetGraph, Port } from "../asset"
3
4
  import { Category } from "../Category"
4
5
 
@@ -14,7 +15,7 @@ const interactionExecutor = (interaction: InteractionProperty, path: string, por
14
15
  }
15
16
  }
16
17
  }
17
- const routineNodeExecutor = (node: RoutineNode, path: string, port: Port) => {
18
+ const interactionNodeExecutor = (node: InteractionNode, path: string, port: Port) => {
18
19
  const params = Object.keys(node.input)
19
20
  for (const param of params) {
20
21
  const value = node.input[param]
@@ -29,7 +30,7 @@ const DescriptorProvider = (descriptor: Descriptor, port: Port) => {
29
30
  const interaction = descriptor.interactions[i]
30
31
  if (interaction.url) {
31
32
  interactionExecutor(interaction, `interactions[${i}]`, port)
32
- port.edges.push({ key: `interactions[${i}].url`, category: Category.routine, asset: interaction.url })
33
+ port.edges.push({ key: `interactions[${i}].url`, category: Category.interaction, asset: interaction.url })
33
34
  }
34
35
  }
35
36
  }
@@ -40,12 +41,12 @@ const StyleDescriptorProvider = (descriptor: StyleDescriptor, port: Port) => {
40
41
  if (descriptor.inherit) port.edges.push({ key: 'inherit', category: Category.style, asset: descriptor.inherit })
41
42
  }
42
43
 
43
- const RoutineDescriptorProvider = (descriptor: RoutineDescriptor, port: Port) => {
44
+ const InteractionDescriptorProvider = (descriptor: InteractionDescriptor, port: Port) => {
44
45
  if (descriptor.nodes.length > 0) {
45
46
  for (let i = 0; i < descriptor.nodes.length; i++) {
46
47
  const node = descriptor.nodes[i]
47
48
  if (node.url) {
48
- routineNodeExecutor(node, `nodes[${i}]`, port)
49
+ interactionNodeExecutor(node, `nodes[${i}]`, port)
49
50
  port.edges.push({ key: `nodes[${i}].url`, category: Category.ts, asset: node.url })
50
51
  }
51
52
  }
@@ -66,7 +67,7 @@ const PrefabInstanceDescriptorProvider = (descriptor: PrefabInstanceDescriptor,
66
67
 
67
68
  AssetGraph.register(Descriptor.type, DescriptorProvider)
68
69
  AssetGraph.register(StyleDescriptor.type, StyleDescriptorProvider)
69
- AssetGraph.register(RoutineDescriptor.type, RoutineDescriptorProvider)
70
+ AssetGraph.register(InteractionDescriptor.type, InteractionDescriptorProvider)
70
71
  AssetGraph.register(HTMLDescriptor.type, HTMLDescriptorProvider)
71
72
  AssetGraph.register(DynamicDescriptor.type, DynamicDescriptorProvider)
72
73
  AssetGraph.register(PrefabInstanceDescriptor.type, PrefabInstanceDescriptorProvider)
@@ -0,0 +1,10 @@
1
+ enum HttpType {
2
+ GET = 'GET',
3
+ POST = 'POST',
4
+ PUT = 'PUT',
5
+ DELETE = 'DELETE',
6
+ }
7
+
8
+ export {
9
+ HttpType
10
+ }
@@ -1 +1,2 @@
1
+ export * from './constants'
1
2
  export * from './AssetProvider'
package/src/Scriptable.ts DELETED
@@ -1,27 +0,0 @@
1
- import { Descriptor, UpdateArgs } from "./descriptor"
2
- import { Graphics } from "./graphics/Graphics"
3
-
4
- /**
5
- * 可编程脚本(脚本不会在服务端实例化)
6
- */
7
- class Scriptable {
8
- readonly uuid
9
- /**脚本文件的url路径 */
10
- get url() {
11
- return this.uuid
12
- }
13
-
14
- constructor(url: string) {
15
- this.uuid = url
16
- }
17
-
18
- /**脚本的准备事件,该方法在脚本被实例化后立即执行
19
- *
20
- * 一般在该事件中进行脚本的准备工作,如从服务端获取资源或数据
21
- */
22
- async ready() { }
23
-
24
- execute(descriptor: Descriptor, graphics: Graphics, args: UpdateArgs): any { }
25
- }
26
-
27
- export { Scriptable }
@@ -1,54 +0,0 @@
1
- import { DeserializationObject } from "../Serialization";
2
- import { Descriptor, InteractionInput, UpdateArgs } from ".";
3
-
4
- interface RoutineNode {
5
- id: string
6
- label: string
7
- position: { x: number; y: number }
8
- routine: string
9
- url: string
10
- input: InteractionInput
11
- }
12
-
13
- interface RoutineMapper {
14
- source: string
15
- target: string
16
- }
17
-
18
- interface RoutineUpdateArgs<T = InteractionInput> extends UpdateArgs {
19
- input: {
20
- previous: string
21
- default: T
22
- user: T
23
- }
24
- }
25
-
26
- class RoutineDescriptor extends Descriptor {
27
- static type = 'Routine'
28
- roots: string[]
29
- nodes: RoutineNode[]
30
- mappers: RoutineMapper[]
31
-
32
- constructor(descriptor: Partial<DeserializationObject<RoutineDescriptor>> = {}) {
33
- super(descriptor)
34
- this.roots = descriptor.roots ? Descriptor.deepClone(descriptor.roots) : []
35
- this.nodes = descriptor.nodes ? Descriptor.deepClone(descriptor.nodes) : []
36
- this.mappers = descriptor.mappers ? Descriptor.deepClone(descriptor.mappers) : []
37
- }
38
-
39
- addNode(nodes: RoutineNode[]) {
40
- const count = nodes.length
41
- const max = count - 1
42
- for (let i = 0; i < count; i++) {
43
- const node = nodes[i]
44
- this.nodes.push(node)
45
- if (i < max) {
46
- this.mappers.push({ source: node.id, target: nodes[i + 1].id })
47
- }
48
- }
49
- }
50
- }
51
- Descriptor.register(RoutineDescriptor)
52
-
53
-
54
- export { RoutineNode, RoutineMapper, RoutineUpdateArgs, RoutineDescriptor }