@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.
Files changed (137) hide show
  1. package/package.json +6 -3
  2. package/src/ArrayUtils.ts +63 -65
  3. package/src/AsyncTask.ts +67 -71
  4. package/src/Category.ts +69 -86
  5. package/src/Color.ts +3 -111
  6. package/src/Engine.ts +12 -24
  7. package/src/Executor.ts +109 -0
  8. package/src/Generate.ts +23 -40
  9. package/src/InputSystem.ts +106 -108
  10. package/src/Listener.ts +58 -59
  11. package/src/ObjectPool.ts +83 -84
  12. package/src/ObjectUtils.ts +97 -49
  13. package/src/Scriptable.ts +82 -0
  14. package/src/Serialization.ts +4 -6
  15. package/src/Traverser.ts +41 -39
  16. package/src/actor/Actor.ts +23 -27
  17. package/src/actor/AnimationUnitActor.ts +22 -36
  18. package/src/actor/DivActor.ts +21 -41
  19. package/src/actor/FragmentActor.ts +1 -5
  20. package/src/actor/HTMLActor.ts +81 -0
  21. package/src/actor/HTMLServiceActor.ts +49 -0
  22. package/src/actor/{HTMTransformControllerActor.ts → HTMLTransformControllerActor.ts} +178 -71
  23. package/src/actor/InputActor.ts +50 -0
  24. package/src/actor/TextActor.ts +51 -0
  25. package/src/actor/index.ts +6 -5
  26. package/src/asset/Asset.ts +23 -68
  27. package/src/asset/AssetGraph.ts +21 -28
  28. package/src/descriptor/AnimationUnit.ts +81 -0
  29. package/src/descriptor/Camera.ts +12 -0
  30. package/src/descriptor/Controller.ts +6 -0
  31. package/src/descriptor/Descriptor.ts +133 -113
  32. package/src/descriptor/Div.ts +29 -0
  33. package/src/descriptor/HTML.ts +22 -0
  34. package/src/descriptor/HTMLService.ts +42 -0
  35. package/src/descriptor/HTMLTransformController.ts +67 -0
  36. package/src/descriptor/Input.ts +29 -0
  37. package/src/descriptor/Interaction.ts +80 -0
  38. package/src/descriptor/Node.ts +98 -0
  39. package/src/descriptor/Scene.ts +110 -0
  40. package/src/descriptor/Service.ts +11 -0
  41. package/src/descriptor/Store.ts +136 -0
  42. package/src/descriptor/Text.ts +36 -0
  43. package/src/descriptor/index.ts +14 -15
  44. package/src/graphics/Collection.ts +1 -5
  45. package/src/graphics/Compilation.ts +15 -19
  46. package/src/graphics/Graphics.ts +41 -54
  47. package/src/graphics/Observer.ts +6 -14
  48. package/src/graphics/Unit.ts +3 -9
  49. package/src/graphics/VariableProxy.ts +11 -15
  50. package/src/index.ts +5 -5
  51. package/src/interpreter/AnimationUnitInterpreter.ts +7 -9
  52. package/src/interpreter/DivInterpreter.ts +10 -13
  53. package/src/interpreter/FragmentInterpreter.ts +2 -6
  54. package/src/interpreter/HTMLServiceInterpreter.ts +25 -15
  55. package/src/interpreter/HTMLTransformControllerInterpreter.ts +9 -12
  56. package/src/interpreter/InputInterpreter.ts +41 -0
  57. package/src/interpreter/Interpreter.ts +3 -4
  58. package/src/interpreter/SceneInterpreter.ts +93 -0
  59. package/src/interpreter/ServiceInterpreter.ts +8 -15
  60. package/src/interpreter/StoreInterpreter.ts +7 -0
  61. package/src/interpreter/TextInterpreter.ts +41 -0
  62. package/src/interpreter/index.ts +5 -7
  63. package/src/locale/Language.ts +1 -5
  64. package/src/locale/LanguageProvider.ts +164 -21
  65. package/src/math/Euler.ts +2 -5
  66. package/src/math/Matrix4.ts +2 -4
  67. package/src/math/Quaternion.ts +2 -4
  68. package/src/math/Vector2.ts +4 -4
  69. package/src/math/Vector3.ts +2 -4
  70. package/src/math/utils.ts +1 -5
  71. package/src/schema/AnimationUnit.ts +68 -0
  72. package/src/schema/Asset.ts +13 -0
  73. package/src/schema/Descriptor.ts +41 -0
  74. package/src/schema/HTML.ts +261 -0
  75. package/src/schema/Interaction.ts +50 -0
  76. package/src/schema/Scene.ts +138 -0
  77. package/src/schema/Store.ts +8 -0
  78. package/src/schema/index.ts +7 -0
  79. package/src/scripts/ConditionScriptable.ts +196 -0
  80. package/src/scripts/FetchScriptable.ts +51 -0
  81. package/src/scripts/FindScriptable.ts +23 -0
  82. package/src/scripts/InvokeScriptable.ts +13 -0
  83. package/src/scripts/SwitchSceneScriptable.ts +18 -0
  84. package/src/scripts/UpdateScriptable.ts +60 -0
  85. package/src/scripts/index.ts +6 -0
  86. package/src/utils/AssetProvider.ts +4 -77
  87. package/src/utils/DOM.ts +37 -0
  88. package/src/utils/HTML.ts +5 -0
  89. package/src/utils/Service.ts +40 -0
  90. package/src/utils/constants.ts +1 -5
  91. package/src/utils/http.ts +2 -21
  92. package/src/utils/index.ts +3 -1
  93. package/src/actor/HTMActor.ts +0 -169
  94. package/src/actor/HTMServiceActor.ts +0 -57
  95. package/src/actor/StyleActor.ts +0 -96
  96. package/src/descriptor/AnimationUnitDescriptor.ts +0 -65
  97. package/src/descriptor/CameraDescriptor.ts +0 -12
  98. package/src/descriptor/ControllerDescriptor.ts +0 -16
  99. package/src/descriptor/DatasetDescriptor.ts +0 -90
  100. package/src/descriptor/DivDescriptor.ts +0 -18
  101. package/src/descriptor/DynamicDescriptor.ts +0 -27
  102. package/src/descriptor/HTMLDescriptor.ts +0 -87
  103. package/src/descriptor/HTMLServiceDescriptor.ts +0 -19
  104. package/src/descriptor/HTMLTransformControllerDescriptor.ts +0 -34
  105. package/src/descriptor/NodeDescriptor.ts +0 -32
  106. package/src/descriptor/PrefabDescriptor.ts +0 -53
  107. package/src/descriptor/PrefabInstanceDescriptor.ts +0 -32
  108. package/src/descriptor/ServiceDescriptor.ts +0 -32
  109. package/src/descriptor/ServiceSchedulerDescriptor.ts +0 -32
  110. package/src/descriptor/StyleDescriptor.ts +0 -213
  111. package/src/interaction/InteractionDescriptor.ts +0 -96
  112. package/src/interaction/InteractionExecutor.ts +0 -84
  113. package/src/interaction/Scriptable.ts +0 -44
  114. package/src/interaction/index.ts +0 -3
  115. package/src/interpreter/DatasetInterpreter.ts +0 -11
  116. package/src/interpreter/DynamicInterpreter.ts +0 -207
  117. package/src/interpreter/PrefaInterpreter.ts +0 -11
  118. package/src/interpreter/PrefabInstanceInterpreter.ts +0 -12
  119. package/src/interpreter/ServiceSchedulerInterpreter.ts +0 -42
  120. package/src/interpreter/StyleInterpreter.ts +0 -66
  121. package/src/preset/execute/dataset/index.ts +0 -1
  122. package/src/preset/execute/dataset/update.ts +0 -51
  123. package/src/preset/execute/graphics/index.ts +0 -1
  124. package/src/preset/execute/graphics/invoke.ts +0 -48
  125. package/src/preset/execute/index.ts +0 -4
  126. package/src/preset/execute/net/http.ts +0 -52
  127. package/src/preset/execute/net/index.ts +0 -1
  128. package/src/preset/execute/scheduler/index.ts +0 -1
  129. package/src/preset/execute/scheduler/switch.ts +0 -46
  130. package/src/preset/index.ts +0 -7
  131. package/src/preset/interaction/graphics/index.ts +0 -1
  132. package/src/preset/interaction/graphics/invoke.ts +0 -27
  133. package/src/preset/interaction/index.ts +0 -2
  134. package/src/preset/interaction/scheduler/index.ts +0 -1
  135. package/src/preset/interaction/scheduler/switch.ts +0 -27
  136. package/src/setup/index.ts +0 -17
  137. package/src/utils/compile.ts +0 -50
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@vyr/engine",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "@vyr/locale": "0.0.33",
10
- "tinycolor2": "1.6.0"
9
+ "@vyr/locale": "0.0.34",
10
+ "decamelize-keys": "^2.0.1",
11
+ "camelcase-keys": "^10.0.1",
12
+ "tinycolor2": "1.6.0",
13
+ "zod": "^4.3.6"
11
14
  },
12
15
  "devDependencies": {
13
16
  "@types/tinycolor2": "1.4.6"
package/src/ArrayUtils.ts CHANGED
@@ -1,65 +1,63 @@
1
- import { ObjectUtils } from "./ObjectUtils"
2
-
3
- class ArrayUtils {
4
-
5
- static insert<T extends any = any>(arr: T[], item: T) {
6
- const i = arr.indexOf(item)
7
- if (i === -1) arr.push(item)
8
- }
9
-
10
- static remove<T extends any = any>(arr: T[], item: T) {
11
- const i = arr.indexOf(item)
12
- if (i > -1) arr.splice(i, 1)
13
- }
14
-
15
- static auto<T extends any = any>(arr: T[], item: T) {
16
- const i = arr.indexOf(item)
17
- i === -1 ? arr.push(item) : arr.splice(i, 1)
18
- }
19
-
20
- static insertByKey<T extends any = any>(arr: T[], key: keyof T, item: T) {
21
- const count = arr.length;
22
- for (let i = 0; i < count; i++) {
23
- if (arr[i][key] === item[key]) return
24
- }
25
- arr.push(item)
26
- }
27
-
28
- static removeByKey<T extends any = any, K extends keyof T = keyof T>(arr: T[], key: keyof T, value: T[K]) {
29
- const count = arr.length;
30
- for (let i = 0; i < count; i++) {
31
- const item = arr[i]
32
- if (item[key] === value) {
33
- arr.splice(i, 1)
34
- return
35
- }
36
- }
37
- }
38
-
39
- static equals(left: { [k: string]: any }, right: { [k: string]: any }, ignore: string[] = []) {
40
- if (left.length !== right.length) return false
41
-
42
- for (let i = 0; i < left.length; i++) {
43
- const value = left[i]
44
- const t = typeof value
45
-
46
- if (t === 'string' || t === 'boolean' || t === 'number' || t === 'bigint' || t === 'undefined' || t === 'symbol' || t === null) {
47
- if (value !== right[i]) return false
48
- }
49
-
50
- if (Array.isArray(value)) {
51
- if (ArrayUtils.equals(value, right[i], ignore) == false) return false
52
- continue
53
- }
54
-
55
- if (t === 'object') {
56
- if (ObjectUtils.equals(value, right[i], ignore) === false) return false
57
- continue
58
- }
59
- }
60
-
61
- return true
62
- }
63
- }
64
-
65
- export { ArrayUtils }
1
+ import { ObjectUtils } from "./ObjectUtils"
2
+
3
+ export class ArrayUtils {
4
+
5
+ static insert<T extends any = any>(arr: T[], item: T) {
6
+ const i = arr.indexOf(item)
7
+ if (i === -1) arr.push(item)
8
+ }
9
+
10
+ static remove<T extends any = any>(arr: T[], item: T) {
11
+ const i = arr.indexOf(item)
12
+ if (i > -1) arr.splice(i, 1)
13
+ }
14
+
15
+ static auto<T extends any = any>(arr: T[], item: T) {
16
+ const i = arr.indexOf(item)
17
+ i === -1 ? arr.push(item) : arr.splice(i, 1)
18
+ }
19
+
20
+ static insertByKey<T extends any = any>(arr: T[], key: keyof T, item: T) {
21
+ const count = arr.length;
22
+ for (let i = 0; i < count; i++) {
23
+ if (arr[i][key] === item[key]) return
24
+ }
25
+ arr.push(item)
26
+ }
27
+
28
+ static removeByKey<T extends any = any, K extends keyof T = keyof T>(arr: T[], key: keyof T, value: T[K]) {
29
+ const count = arr.length;
30
+ for (let i = 0; i < count; i++) {
31
+ const item = arr[i]
32
+ if (item[key] === value) {
33
+ arr.splice(i, 1)
34
+ return
35
+ }
36
+ }
37
+ }
38
+
39
+ static equals(left: { [k: string]: any }, right: { [k: string]: any }, ignore: string[] = []) {
40
+ if (left.length !== right.length) return false
41
+
42
+ for (let i = 0; i < left.length; i++) {
43
+ const value = left[i]
44
+ const t = typeof value
45
+
46
+ if (t === 'string' || t === 'boolean' || t === 'number' || t === 'bigint' || t === 'undefined' || t === 'symbol' || t === null) {
47
+ if (value !== right[i]) return false
48
+ }
49
+
50
+ if (Array.isArray(value)) {
51
+ if (ArrayUtils.equals(value, right[i], ignore) == false) return false
52
+ continue
53
+ }
54
+
55
+ if (t === 'object') {
56
+ if (ObjectUtils.equals(value, right[i], ignore) === false) return false
57
+ continue
58
+ }
59
+ }
60
+
61
+ return true
62
+ }
63
+ }
package/src/AsyncTask.ts CHANGED
@@ -1,72 +1,68 @@
1
- import { language } from './locale'
2
-
3
- enum STATUS {
4
- PENDING = 1,
5
- RUNNING = 2,
6
- RESOLVED = 3,
7
- REJECTED = 4,
8
- CANCELLED = 5
9
- }
10
-
11
- type AsyncTaskFn<T> = () => T | Promise<T>
12
-
13
- class AsyncTask<T = any> {
14
- private _task: AsyncTaskFn<T>;
15
- private _status: STATUS;
16
- private _promise: Promise<T>;
17
- private _resolve!: ((value: T | PromiseLike<T>) => void) | null;
18
- private _reject!: ((reason?: any) => void) | null;
19
-
20
- constructor(task?: AsyncTaskFn<T>) {
21
- this._task = task ?? (async () => { }) as AsyncTaskFn<T>;
22
- this._status = STATUS.PENDING;
23
- this._promise = new Promise<T>((resolve, reject) => {
24
- this._resolve = resolve;
25
- this._reject = reject;
26
- })
27
- }
28
-
29
- /**运行任务 */
30
- run(): Promise<T> {
31
- if (this._status !== STATUS.PENDING) return this._promise
32
-
33
- this._status = STATUS.RUNNING;
34
-
35
- Promise.resolve(this._task())
36
- .then(result => {
37
- if (this._status === STATUS.RUNNING) {
38
- this._status = STATUS.RESOLVED;
39
- this._resolve!(result);
40
- }
41
- })
42
- .catch(error => {
43
- if (this._status === STATUS.RUNNING) {
44
- this._status = STATUS.REJECTED;
45
- this._reject!(error);
46
- }
47
- });
48
-
49
- return this._promise;
50
- }
51
-
52
- /**取消运行中的任务 */
53
- cancel(): boolean {
54
- if (this._status === STATUS.PENDING || this._status === STATUS.RUNNING) {
55
- this._status = STATUS.CANCELLED;
56
- if (this._reject) {
57
- this._reject(new Error(language.get('asyncTask.task.was.cancelled')));
58
- }
59
- return true;
60
- }
61
- return false;
62
- }
63
-
64
- /**等待任务完成 */
65
- done(): Promise<T> {
66
- return this._promise;
67
- }
68
- }
69
-
70
- export {
71
- AsyncTask
1
+ import { language } from './locale'
2
+
3
+ enum STATUS {
4
+ PENDING = 1,
5
+ RUNNING = 2,
6
+ RESOLVED = 3,
7
+ REJECTED = 4,
8
+ CANCELLED = 5
9
+ }
10
+
11
+ export type AsyncTaskFn<T> = (...args: any[]) => T | Promise<T>
12
+
13
+ export class AsyncTask<T = any> {
14
+ private _task: AsyncTaskFn<T>;
15
+ private _status: STATUS;
16
+ private _promise: Promise<T>;
17
+ private _resolve!: ((value: T | PromiseLike<T>) => void) | null;
18
+ private _reject!: ((reason?: any) => void) | null;
19
+
20
+ constructor(task?: AsyncTaskFn<T>) {
21
+ this._task = task ?? (async () => { }) as AsyncTaskFn<T>;
22
+ this._status = STATUS.PENDING;
23
+ this._promise = new Promise<T>((resolve, reject) => {
24
+ this._resolve = resolve;
25
+ this._reject = reject;
26
+ })
27
+ }
28
+
29
+ /**运行任务 */
30
+ run(...args: any[]): Promise<T> {
31
+ if (this._status !== STATUS.PENDING) return this._promise
32
+
33
+ this._status = STATUS.RUNNING;
34
+
35
+ Promise.resolve(this._task(...args))
36
+ .then(result => {
37
+ if (this._status === STATUS.RUNNING) {
38
+ this._status = STATUS.RESOLVED;
39
+ this._resolve!(result);
40
+ }
41
+ })
42
+ .catch(error => {
43
+ if (this._status === STATUS.RUNNING) {
44
+ this._status = STATUS.REJECTED;
45
+ this._reject!(error);
46
+ }
47
+ });
48
+
49
+ return this._promise;
50
+ }
51
+
52
+ /**取消运行中的任务 */
53
+ cancel(): boolean {
54
+ if (this._status === STATUS.PENDING || this._status === STATUS.RUNNING) {
55
+ this._status = STATUS.CANCELLED;
56
+ if (this._reject) {
57
+ this._reject(new Error(language.get('asyncTask.task.was.cancelled')));
58
+ }
59
+ return true;
60
+ }
61
+ return false;
62
+ }
63
+
64
+ /**等待任务完成 */
65
+ done(): Promise<T> {
66
+ return this._promise;
67
+ }
72
68
  }
package/src/Category.ts CHANGED
@@ -1,100 +1,78 @@
1
- /**资产的类别 */
2
- class Category {
3
- static ts = 'ts'
4
- static prefab = 'prefab'
5
- static dataset = 'dataset'
6
- static style = 'style'
7
- static font = 'font'
8
- static interaction = 'interaction'
9
- static texture = 'texture'
10
- static material = 'material'
11
- static geometry = 'geometry'
12
- static scene = 'scene'
13
- static json = 'json'
14
- static image = 'image'
15
- static audio = 'audio'
16
- static video = 'video'
17
- static model = 'model'
18
- static other = 'other'
1
+ class CategoryDefine {
2
+ store = 'store'
3
+ interaction = 'interaction'
4
+ texture = 'texture'
5
+ material = 'material'
6
+ geometry = 'geometry'
7
+ scene = 'scene'
8
+ json = 'json'
9
+ image = 'image'
10
+ audio = 'audio'
11
+ video = 'video'
12
+ model = 'model'
13
+ font = 'font'
14
+ other = 'other'
19
15
 
20
- static tsSuffix = `.${this.ts}`
21
- static prefabSuffix = `.${this.prefab}.json`
22
- static datasetSuffix = `.${this.dataset}.json`
23
- static styleSuffix = `.${this.style}.json`
24
- static fontSuffix = `.${this.font}.json`
25
- static interactionSuffix = `.${this.interaction}.json`
26
- static textureSuffix = `.${this.texture}.json`
27
- static materialSuffix = `.${this.material}.json`
28
- static geometrySuffix = `.${this.geometry}.json`
29
- static sceneSuffix = `.${this.scene}.json`
30
- static manifestSuffix = `.manifest.json`
16
+ isDescriptor(category: string) {
17
+ const list = [
18
+ this.store,
19
+ this.interaction,
20
+ this.texture,
21
+ this.material,
22
+ this.geometry,
23
+ this.scene,
24
+ ]
25
+ return list.includes(category)
26
+ }
27
+ }
28
+ export const Category = new CategoryDefine()
31
29
 
32
- static jsonSuffixs = ['.json']
30
+ class SuffixDefine {
33
31
  static imageSuffixs = ['.png', '.jpg', '.jpeg', '.bmp', '.gif']
34
32
  static audioSuffixs = ['.mp3', '.wav', '.wmv']
35
33
  static videoSuffixs = ['.mp4', '.m2v', '.mkv', '.rmvb', '.wmv', '.avi', '.flv', '.mov', '.m4v']
36
34
  static modelSuffixs = ['.glb', '.gltf']
37
35
 
38
- static descriptorSuffixs = [
39
- this.prefabSuffix,
40
- this.datasetSuffix,
41
- this.styleSuffix,
42
- this.interactionSuffix,
43
- this.textureSuffix,
44
- this.materialSuffix,
45
- this.geometrySuffix,
46
- this.sceneSuffix,
47
- ]
48
- static descriptorCategorys = [
49
- this.prefab,
50
- this.dataset,
51
- this.style,
52
- this.interaction,
53
- this.texture,
54
- this.material,
55
- this.geometry,
56
- this.scene,
57
- ]
36
+ storeSuffix = `.${Category.store}.json`
37
+ interactionSuffix = `.${Category.interaction}.json`
38
+ textureSuffix = `.${Category.texture}.json`
39
+ materialSuffix = `.${Category.material}.json`
40
+ geometrySuffix = `.${Category.geometry}.json`
41
+ sceneSuffix = `.${Category.scene}.json`
42
+ fontSuffix = `.${Category.font}.json`
43
+ jsonSuffix = '.json'
58
44
 
59
- /**根据后缀获取资产类型 */
60
- static getCategory(suffix: string) {
61
- if (suffix === this.tsSuffix) {
62
- return this.ts
63
- } else if (suffix === this.prefabSuffix) {
64
- return this.prefab
65
- } else if (suffix === this.datasetSuffix) {
66
- return this.dataset
67
- } else if (suffix === this.styleSuffix) {
68
- return this.style
69
- } else if (suffix === this.fontSuffix) {
70
- return this.font
45
+ getCategory(suffix: string) {
46
+ if (suffix === this.storeSuffix) {
47
+ return Category.store
71
48
  } else if (suffix === this.interactionSuffix) {
72
- return this.interaction
49
+ return Category.interaction
73
50
  } else if (suffix === this.textureSuffix) {
74
- return this.texture
51
+ return Category.texture
75
52
  } else if (suffix === this.materialSuffix) {
76
- return this.material
53
+ return Category.material
77
54
  } else if (suffix === this.geometrySuffix) {
78
- return this.geometry
55
+ return Category.geometry
79
56
  } else if (suffix === this.sceneSuffix) {
80
- return this.scene
81
- } else if (this.jsonSuffixs.includes(suffix)) {
82
- return this.json
83
- } else if (this.imageSuffixs.includes(suffix)) {
84
- return this.image
85
- } else if (this.audioSuffixs.includes(suffix)) {
86
- return this.audio
87
- } else if (this.videoSuffixs.includes(suffix)) {
88
- return this.video
89
- } else if (this.modelSuffixs.includes(suffix)) {
90
- return this.model
57
+ return Category.scene
58
+ } else if (suffix === this.fontSuffix) {
59
+ return Category.font
60
+ } else if (suffix === this.jsonSuffix) {
61
+ return Category.json
62
+ } else if (SuffixDefine.imageSuffixs.includes(suffix)) {
63
+ return Category.image
64
+ } else if (SuffixDefine.audioSuffixs.includes(suffix)) {
65
+ return Category.audio
66
+ } else if (SuffixDefine.videoSuffixs.includes(suffix)) {
67
+ return Category.video
68
+ } else if (SuffixDefine.modelSuffixs.includes(suffix)) {
69
+ return Category.model
91
70
  } else {
92
- return this.other
71
+ return Category.other
93
72
  }
94
73
  }
95
74
 
96
- /**根据名称解析资产信息 */
97
- static parseName(name?: string) {
75
+ parseName(name?: string) {
98
76
  const result = { name: '', suffix: '', category: 'other' }
99
77
  if (name === undefined || name === '') return result
100
78
 
@@ -109,11 +87,16 @@ class Category {
109
87
  return result
110
88
  }
111
89
 
112
- /**根据后缀判断是否为描述器类资产 */
113
- static isDescriptor(suffix: string, type: 'suffix' | 'category' = 'suffix') {
114
- const tests = type === 'suffix' ? Category.descriptorSuffixs : Category.descriptorCategorys
115
- return tests.includes(suffix)
90
+ isDescriptor(suffix: string) {
91
+ const list = [
92
+ this.storeSuffix,
93
+ this.interactionSuffix,
94
+ this.textureSuffix,
95
+ this.materialSuffix,
96
+ this.geometrySuffix,
97
+ this.sceneSuffix,
98
+ ]
99
+ return list.includes(suffix)
116
100
  }
117
101
  }
118
-
119
- export { Category }
102
+ export const Suffix = new SuffixDefine()
package/src/Color.ts CHANGED
@@ -1,111 +1,3 @@
1
- import tinycolor from "tinycolor2"
2
- import { DeserializationObject, Serialization } from "./Serialization"
3
-
4
- class Color extends tinycolor { }
5
-
6
- interface ColorItem {
7
- value: string
8
- opacity: number
9
- ratio: number
10
- }
11
-
12
- class BasicStyleColor {
13
- static type = 'basic'
14
- static create(color: DeserializationObject<BasicStyleColor>) {
15
- switch (color.type) {
16
- case "linear":
17
- return new LinearStyleColor(color as LinearStyleColor)
18
- case "radial":
19
- return new RadialStyleColor(color as RadialStyleColor)
20
- default:
21
- return new DefaultStyleColor(color as DefaultStyleColor)
22
- }
23
- }
24
- static getColor(color: BasicStyleColor) {
25
- return 'rgba(0,0,0,0)'
26
- }
27
- type: string
28
-
29
- constructor() {
30
- this.type = (this.constructor as typeof BasicStyleColor).type
31
- }
32
-
33
- getColor() {
34
- return (this.constructor as typeof BasicStyleColor).getColor(this)
35
- }
36
-
37
- }
38
-
39
- class DefaultStyleColor extends BasicStyleColor {
40
- static type = 'default'
41
- static getColor(color: DefaultStyleColor) {
42
- return new Color(color.value).setAlpha(color.opacity).toRgbString()
43
- }
44
- declare type: 'default'
45
- value: string
46
- opacity: number
47
-
48
- constructor(color: Partial<DeserializationObject<DefaultStyleColor>> = {}) {
49
- super()
50
- this.value = color.value ?? '#ffffff'
51
- this.opacity = color.opacity ?? 1
52
- }
53
- }
54
-
55
- class LinearStyleColor extends BasicStyleColor {
56
- static type = 'linear'
57
- static getColor(color: LinearStyleColor) {
58
- let items = ''
59
- for (const item of color.value) {
60
- items += `, ${new Color(item.value).setAlpha(item.opacity).toRgbString()} ${item.ratio * 100}%`
61
- }
62
-
63
- return `linear-gradient(${color.angle}deg ${items})`
64
- }
65
- declare type: 'linear'
66
- angle: number
67
- value: ColorItem[]
68
- constructor(color: Partial<DeserializationObject<LinearStyleColor>> = {}) {
69
- super()
70
- this.angle = color.angle ?? 0
71
- this.value = color.value ? Serialization.deepClone(color.value) : [{ value: '#ffffff', opacity: 1, ratio: 0 }, { value: '#ffffff', opacity: 1, ratio: 1 }]
72
- }
73
-
74
- }
75
-
76
- class RadialStyleColor extends BasicStyleColor {
77
- static type = 'radial'
78
- static getColor(color: RadialStyleColor) {
79
- let radis = ''
80
- if (color.radius < 0) {
81
- radis = 'farthest-corner'
82
- } else {
83
- radis = `${color.radius}px`
84
- }
85
-
86
- let center = ''
87
- center = `${color.center.x * 100}% ${color.center.y * 100}%`
88
-
89
- let items = ''
90
- for (const item of color.value) {
91
- items += `, ${new Color(item.value).setAlpha(item.opacity).toRgbString()} ${item.ratio * 100}%`
92
- }
93
-
94
- return `radial-gradient(circle ${radis} at ${center} ${items})`
95
- }
96
- declare type: 'radial'
97
- center: { x: number; y: number }
98
- radius: number
99
- value: ColorItem[]
100
-
101
- constructor(color: Partial<DeserializationObject<RadialStyleColor>> = {}) {
102
- super()
103
- this.center = color.center ? Serialization.deepClone(color.center) : { x: 0.5, y: 0.5 }
104
- this.radius = color.radius ?? -1
105
- this.value = color.value ? Serialization.deepClone(color.value) : [{ value: '#ffffff', opacity: 1, ratio: 0 }, { value: '#ffffff', opacity: 1, ratio: 1 }]
106
- }
107
- }
108
-
109
- type StyleColor = DefaultStyleColor | LinearStyleColor | RadialStyleColor
110
-
111
- export { ColorItem, BasicStyleColor, DefaultStyleColor, LinearStyleColor, RadialStyleColor, StyleColor, Color }
1
+ import tinycolor from "tinycolor2"
2
+
3
+ export class Color extends tinycolor { }
package/src/Engine.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { language } from './locale'
2
2
  import { Asset } from './asset'
3
- import { ServiceSchedulerDescriptor, StyleDescriptor } from './descriptor'
3
+ import { Scene } from './descriptor'
4
4
  import { Generate } from './Generate'
5
5
  import { InputSystem } from './InputSystem'
6
6
  import { Listener } from './Listener'
7
7
  import { Compilation, TickArgs } from './graphics'
8
- import { setupStyle } from './setup';
8
+ import { createEngineDOM } from './utils'
9
9
 
10
10
  interface EngineData { }
11
11
 
@@ -14,27 +14,18 @@ interface EngineListener {
14
14
  afterRender: (args: TickArgs) => void
15
15
  }
16
16
 
17
- class Engine extends Listener<EngineListener> {
17
+ export class Engine extends Listener<EngineListener> {
18
18
  private compilation = new Compilation()
19
19
  private active = ''
20
20
  private prevTimestamp = 0
21
21
  private frame = 0
22
22
 
23
23
  readonly uuid = Generate.uuid()
24
- readonly DOM = document.createElement('div')
24
+ readonly DOM = createEngineDOM()
25
25
  readonly inputSystem = new InputSystem(this.DOM)
26
26
 
27
27
  constructor(data: Partial<EngineData> = {}) {
28
28
  super()
29
- this.DOM.style.width = '100%'
30
- this.DOM.style.height = '100%'
31
- this.DOM.style.position = 'relative'
32
- this.DOM.style.top = '0'
33
- this.DOM.style.left = '0'
34
- this.DOM.style.overflow = 'hidden'
35
- this.DOM.classList.add('vyr-engine', StyleDescriptor.basicName)
36
- this.DOM.setAttribute('data-vyr', `vyr-engine`)
37
- this.DOM.addEventListener('contextmenu', (e) => e.preventDefault())
38
29
  }
39
30
 
40
31
  private getDelta(timestamp: number) {
@@ -64,7 +55,6 @@ class Engine extends Listener<EngineListener> {
64
55
  el = ele
65
56
  }
66
57
  el.appendChild(this.DOM)
67
- setupStyle()
68
58
 
69
59
  this.prevTimestamp = performance.now()
70
60
  this.tick(this.prevTimestamp)
@@ -77,15 +67,15 @@ class Engine extends Listener<EngineListener> {
77
67
  this.frame = 0
78
68
  }
79
69
 
80
- switch(scheduler: ServiceSchedulerDescriptor) {
81
- const current = Asset.get<ServiceSchedulerDescriptor>(this.active)
70
+ switch(scene: Scene) {
71
+ const current = Asset.get<Scene>(this.active)
82
72
  if (current) this.compilation.unlisten(current)
83
73
 
84
- const url = Asset.getUrlByUuid(scheduler.uuid)
74
+ const url = Asset.getUrlByUuid(scene.uuid)
85
75
 
86
76
  if (!url) return console.warn(language.get('engine.switch.url.notFound'))
87
77
 
88
- const graphics = this.compilation.ensureExists(url, scheduler, this)
78
+ const graphics = this.compilation.ensureExists(url, scene, this)
89
79
 
90
80
  this.compilation.listen(graphics)
91
81
  this.active = url
@@ -103,13 +93,11 @@ class Engine extends Listener<EngineListener> {
103
93
  this.compilation.clear()
104
94
  }
105
95
 
106
- getGraphics(scheduler: ServiceSchedulerDescriptor) {
107
- return this.compilation.get(scheduler)
96
+ getGraphics(scene: Scene) {
97
+ return this.compilation.get(scene)
108
98
  }
109
99
 
110
- ensureGraphics(url: string, scheduler: ServiceSchedulerDescriptor) {
111
- return this.compilation.ensureExists(url, scheduler, this)
100
+ ensureGraphics(url: string, scene: Scene) {
101
+ return this.compilation.ensureExists(url, scene, this)
112
102
  }
113
103
  }
114
-
115
- export { Engine }