@vyr/engine 0.0.1
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 +19 -0
- package/src/ArrayUtils.ts +65 -0
- package/src/AsyncTask.ts +72 -0
- package/src/Category.ts +119 -0
- package/src/Color.ts +111 -0
- package/src/Engine.ts +101 -0
- package/src/Generate.ts +40 -0
- package/src/InputSystem.ts +108 -0
- package/src/Listener.ts +59 -0
- package/src/ObjectPool.ts +84 -0
- package/src/ObjectUtils.ts +49 -0
- package/src/Scriptable.ts +27 -0
- package/src/Serialization.ts +49 -0
- package/src/Traverser.ts +39 -0
- package/src/actor/Actor.ts +28 -0
- package/src/actor/AnimationUnitActor.ts +289 -0
- package/src/actor/DivActor.ts +70 -0
- package/src/actor/FragmentActor.ts +56 -0
- package/src/actor/HTMActor.ts +166 -0
- package/src/actor/HTMServiceActor.ts +57 -0
- package/src/actor/HTMTransformControllerActor.ts +404 -0
- package/src/actor/StyleActor.ts +96 -0
- package/src/actor/index.ts +8 -0
- package/src/asset/Asset.ts +271 -0
- package/src/asset/AssetGraph.ts +246 -0
- package/src/asset/index.ts +2 -0
- package/src/descriptor/AnimationUnitDescriptor.ts +65 -0
- package/src/descriptor/CameraDescriptor.ts +12 -0
- package/src/descriptor/ControllerDescriptor.ts +16 -0
- package/src/descriptor/DatasetDescriptor.ts +92 -0
- package/src/descriptor/Descriptor.ts +415 -0
- package/src/descriptor/DivDescriptor.ts +18 -0
- package/src/descriptor/DynamicDescriptor.ts +27 -0
- package/src/descriptor/HTMLDescriptor.ts +87 -0
- package/src/descriptor/HTMLServiceDescriptor.ts +19 -0
- package/src/descriptor/HTMLTransformControllerDescriptor.ts +34 -0
- package/src/descriptor/NodeDescriptor.ts +32 -0
- package/src/descriptor/PrefabDescriptor.ts +53 -0
- package/src/descriptor/PrefabInstanceDescriptor.ts +32 -0
- package/src/descriptor/RoutineDescriptor.ts +54 -0
- package/src/descriptor/ServiceDescriptor.ts +32 -0
- package/src/descriptor/ServiceSchedulerDescriptor.ts +32 -0
- package/src/descriptor/StyleDescriptor.ts +213 -0
- package/src/descriptor/index.ts +17 -0
- package/src/graphics/Collection.ts +25 -0
- package/src/graphics/Compilation.ts +82 -0
- package/src/graphics/Graphics.ts +475 -0
- package/src/graphics/Observer.ts +36 -0
- package/src/graphics/Unit.ts +83 -0
- package/src/graphics/VariableProxy.ts +92 -0
- package/src/graphics/index.ts +5 -0
- package/src/index.ts +26 -0
- package/src/interpreter/AnimationUnitInterpreter.ts +53 -0
- package/src/interpreter/DatasetInterpreter.ts +11 -0
- package/src/interpreter/DivInterpreter.ts +44 -0
- package/src/interpreter/DynamicInterpreter.ts +207 -0
- package/src/interpreter/FragmentInterpreter.ts +34 -0
- package/src/interpreter/HTMLServiceInterpreter.ts +47 -0
- package/src/interpreter/HTMLTransformControllerInterpreter.ts +40 -0
- package/src/interpreter/Interpreter.ts +69 -0
- package/src/interpreter/PrefaInterpreter.ts +11 -0
- package/src/interpreter/PrefabInstanceInterpreter.ts +12 -0
- package/src/interpreter/RoutineInterpreter.ts +88 -0
- package/src/interpreter/ServiceInterpreter.ts +24 -0
- package/src/interpreter/ServiceSchedulerInterpreter.ts +42 -0
- package/src/interpreter/StyleInterpreter.ts +66 -0
- package/src/interpreter/index.ts +14 -0
- package/src/locale/Language.ts +10 -0
- package/src/locale/LanguageProvider.ts +48 -0
- package/src/locale/index.ts +2 -0
- package/src/math/Euler.ts +303 -0
- package/src/math/Matrix4.ts +1123 -0
- package/src/math/Quaternion.ts +737 -0
- package/src/math/Vector2.ts +680 -0
- package/src/math/Vector3.ts +1062 -0
- package/src/math/index.ts +5 -0
- package/src/math/utils.ts +17 -0
- package/src/preset/execute/dataset/index.ts +1 -0
- package/src/preset/execute/dataset/update.ts +52 -0
- package/src/preset/execute/graphics/index.ts +1 -0
- package/src/preset/execute/graphics/invoke.ts +49 -0
- package/src/preset/execute/index.ts +4 -0
- package/src/preset/execute/net/index.ts +1 -0
- package/src/preset/execute/net/request.ts +103 -0
- package/src/preset/execute/scheduler/index.ts +1 -0
- package/src/preset/execute/scheduler/switch.ts +46 -0
- package/src/preset/index.ts +7 -0
- package/src/preset/routine/graphics/index.ts +1 -0
- package/src/preset/routine/graphics/invoke.ts +27 -0
- package/src/preset/routine/index.ts +2 -0
- package/src/preset/routine/scheduler/index.ts +1 -0
- package/src/preset/routine/scheduler/switch.ts +27 -0
- package/src/setup/index.ts +17 -0
- package/src/utils/AssetProvider.ts +72 -0
- package/src/utils/index.ts +1 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DeserializationObject } from "../Serialization"
|
|
2
|
+
import { ControllerDescriptor } from "./ControllerDescriptor"
|
|
3
|
+
import { UpdateArgs } from "./Descriptor"
|
|
4
|
+
|
|
5
|
+
interface HTMLTransformControllerChangeArgs extends UpdateArgs {
|
|
6
|
+
event: {
|
|
7
|
+
type: string
|
|
8
|
+
target: string
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class HTMLTransformControllerDescriptor extends ControllerDescriptor {
|
|
13
|
+
static type = 'HTMLTransformController'
|
|
14
|
+
|
|
15
|
+
/**控制器的摄像机 */
|
|
16
|
+
camera: string
|
|
17
|
+
/**控制器的模式 */
|
|
18
|
+
mode: string
|
|
19
|
+
/**控制器的目标 */
|
|
20
|
+
target: string
|
|
21
|
+
/**控制器触发事件时执行的脚本依赖 */
|
|
22
|
+
event: string
|
|
23
|
+
|
|
24
|
+
constructor(descriptor: Partial<DeserializationObject<HTMLTransformControllerDescriptor>> = {}) {
|
|
25
|
+
super(descriptor)
|
|
26
|
+
this.camera = descriptor.camera ?? ''
|
|
27
|
+
this.mode = descriptor.mode ?? ''
|
|
28
|
+
this.target = descriptor.target ?? ''
|
|
29
|
+
this.event = descriptor.event ?? ''
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
ControllerDescriptor.register(HTMLTransformControllerDescriptor)
|
|
33
|
+
|
|
34
|
+
export { HTMLTransformControllerChangeArgs, HTMLTransformControllerDescriptor }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Euler, Vector3 } from "../math"
|
|
2
|
+
import { DeserializationObject } from "../Serialization"
|
|
3
|
+
import { Descriptor } from "./Descriptor"
|
|
4
|
+
|
|
5
|
+
class NodeDescriptor extends Descriptor {
|
|
6
|
+
static type = 'Node'
|
|
7
|
+
readonly scale: Vector3
|
|
8
|
+
readonly position: Vector3
|
|
9
|
+
readonly rotation: Euler
|
|
10
|
+
layer = 0
|
|
11
|
+
visible = true
|
|
12
|
+
renderOrder = 0
|
|
13
|
+
castShadow = false
|
|
14
|
+
receiveShadow = false
|
|
15
|
+
|
|
16
|
+
constructor(descriptor: Partial<DeserializationObject<NodeDescriptor>> = {}) {
|
|
17
|
+
super(descriptor)
|
|
18
|
+
this.scale = descriptor.scale ? Vector3.create(descriptor.scale) : Vector3.create(1, 1, 1)
|
|
19
|
+
this.position = Vector3.create(descriptor.position)
|
|
20
|
+
this.rotation = Euler.create(descriptor.rotation)
|
|
21
|
+
this.layer = descriptor.layer ?? 0
|
|
22
|
+
this.visible = descriptor.visible ?? true
|
|
23
|
+
this.renderOrder = descriptor.renderOrder ?? 0
|
|
24
|
+
this.castShadow = descriptor.castShadow ?? false
|
|
25
|
+
this.receiveShadow = descriptor.receiveShadow ?? false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
Descriptor.register(NodeDescriptor)
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
NodeDescriptor
|
|
32
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DeserializationObject } from "../Serialization"
|
|
2
|
+
import { Descriptor } from "./Descriptor"
|
|
3
|
+
|
|
4
|
+
class PrefabeDescriptor extends Descriptor {
|
|
5
|
+
static type = 'Prefab'
|
|
6
|
+
|
|
7
|
+
static add(parent: Descriptor, sub: Descriptor) {
|
|
8
|
+
parent.add(sub)
|
|
9
|
+
|
|
10
|
+
const instanceCollection = this.getInstanceCollection(parent.uuid)
|
|
11
|
+
if (instanceCollection === null) return
|
|
12
|
+
for (const instance of instanceCollection) {
|
|
13
|
+
const instanceDescriptor = this.get<Descriptor>(instance)
|
|
14
|
+
instanceDescriptor.add(sub.clone(true))
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static remove(parent: Descriptor, sub: Descriptor) {
|
|
19
|
+
parent.remove(sub)
|
|
20
|
+
|
|
21
|
+
const instanceCollection = this.getInstanceCollection(sub.uuid)
|
|
22
|
+
if (instanceCollection === null) return
|
|
23
|
+
for (const instance of instanceCollection) {
|
|
24
|
+
const instanceDescriptor = this.get<Descriptor>(instance)
|
|
25
|
+
const ancestor = instanceDescriptor.traceAncestor(false)
|
|
26
|
+
if (ancestor.parent === null) continue
|
|
27
|
+
ancestor.parent.remove(instanceDescriptor)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static update(descriptor: Descriptor) {
|
|
32
|
+
descriptor.setNeedsUpdate()
|
|
33
|
+
|
|
34
|
+
const instanceCollection = this.getInstanceCollection(descriptor.uuid)
|
|
35
|
+
if (instanceCollection === null) return
|
|
36
|
+
for (const instance of instanceCollection) {
|
|
37
|
+
const instanceDescriptor = this.get<Descriptor>(instance)
|
|
38
|
+
instanceDescriptor.syncWith(descriptor)
|
|
39
|
+
instanceDescriptor.setNeedsUpdate()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
category: 'html' | 'scene'
|
|
44
|
+
|
|
45
|
+
constructor(descriptor: Partial<DeserializationObject<PrefabeDescriptor>> = {}) {
|
|
46
|
+
super(descriptor)
|
|
47
|
+
this.category = descriptor.category ?? 'html'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
Descriptor.register(PrefabeDescriptor)
|
|
52
|
+
|
|
53
|
+
export { PrefabeDescriptor }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DeserializationObject } from "../Serialization"
|
|
2
|
+
import { Descriptor } from "./Descriptor"
|
|
3
|
+
import { PrefabeDescriptor } from "./PrefabDescriptor"
|
|
4
|
+
|
|
5
|
+
class PrefabInstanceDescriptor extends Descriptor {
|
|
6
|
+
static type = 'PrefabInstance'
|
|
7
|
+
|
|
8
|
+
static fromPrefab(url: string, descriptor: PrefabeDescriptor) {
|
|
9
|
+
const clone = Descriptor.cloneAndFixReferences(descriptor)
|
|
10
|
+
|
|
11
|
+
const prefabInstance = new PrefabInstanceDescriptor({
|
|
12
|
+
name: clone.name ? `${clone.name}-prefab` : 'prefab',
|
|
13
|
+
interactions: clone.interactions,
|
|
14
|
+
prefab: clone.prefab,
|
|
15
|
+
url,
|
|
16
|
+
})
|
|
17
|
+
prefabInstance.add(...clone.children)
|
|
18
|
+
|
|
19
|
+
return prefabInstance
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
readonly url: string
|
|
23
|
+
|
|
24
|
+
constructor(descriptor: Partial<DeserializationObject<PrefabInstanceDescriptor>> = {}) {
|
|
25
|
+
super(descriptor)
|
|
26
|
+
this.url = descriptor.url ?? ''
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Descriptor.register(PrefabInstanceDescriptor)
|
|
31
|
+
|
|
32
|
+
export { PrefabInstanceDescriptor }
|
|
@@ -0,0 +1,54 @@
|
|
|
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 }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DeserializationObject } from "../Serialization"
|
|
2
|
+
import { DefaultStyleColor, StyleColor } from "../Color"
|
|
3
|
+
import { Descriptor } from "./Descriptor"
|
|
4
|
+
import { HTMLDescriptor } from "./HTMLDescriptor"
|
|
5
|
+
|
|
6
|
+
abstract class ServiceDescriptor extends HTMLDescriptor {
|
|
7
|
+
static type = 'Service'
|
|
8
|
+
|
|
9
|
+
backgroundColor: StyleColor
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 获取当前描述器节点的父服务节点
|
|
13
|
+
*
|
|
14
|
+
* 注意:若你需要在渲染流程中获取父服务节点,你应该调用`Graphics`的同名方法,因为一些动态节点可能并未直接被插入到节点树中。
|
|
15
|
+
*/
|
|
16
|
+
static traceService(descriptor: Descriptor | null): ServiceDescriptor | null {
|
|
17
|
+
if (descriptor === null) return null
|
|
18
|
+
if (descriptor instanceof ServiceDescriptor) {
|
|
19
|
+
return descriptor instanceof ServiceDescriptor ? descriptor : null
|
|
20
|
+
} else {
|
|
21
|
+
const ancestor = descriptor.traceAncestor(false)
|
|
22
|
+
return this.traceService(ancestor.parent)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
constructor(descriptor: Partial<DeserializationObject<ServiceDescriptor>> = {}) {
|
|
27
|
+
super(descriptor)
|
|
28
|
+
this.backgroundColor = descriptor.backgroundColor ? DefaultStyleColor.create(descriptor.backgroundColor) : new DefaultStyleColor({ opacity: 0 })
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { ServiceDescriptor }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Vector2, Vector3 } from "../math";
|
|
2
|
+
import { DeserializationObject } from "../Serialization"
|
|
3
|
+
import { Descriptor } from "./Descriptor"
|
|
4
|
+
import { ServiceDescriptor } from "./ServiceDescriptor";
|
|
5
|
+
|
|
6
|
+
interface RayIntersection {
|
|
7
|
+
object: Descriptor
|
|
8
|
+
distance: number
|
|
9
|
+
point: Vector3
|
|
10
|
+
normal: Vector2 | null
|
|
11
|
+
uv: Vector2 | null
|
|
12
|
+
uv1: Vector2 | null
|
|
13
|
+
faceIndex: number | null
|
|
14
|
+
instanceId: number | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class ServiceSchedulerDescriptor extends Descriptor {
|
|
18
|
+
static type = 'ServiceScheduler'
|
|
19
|
+
/**调度器的默认调度脚本 */
|
|
20
|
+
declare children: ServiceDescriptor[]
|
|
21
|
+
/**调度器渲染场景时使用的相机 */
|
|
22
|
+
camera: string
|
|
23
|
+
|
|
24
|
+
constructor(descriptor: Partial<DeserializationObject> = {}) {
|
|
25
|
+
super(descriptor)
|
|
26
|
+
this.camera = descriptor.camera ?? ''
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Descriptor.register(ServiceSchedulerDescriptor)
|
|
31
|
+
|
|
32
|
+
export { RayIntersection, ServiceSchedulerDescriptor }
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { DeserializationObject } from "../Serialization"
|
|
2
|
+
import { BasicStyleColor, DefaultStyleColor, StyleColor } from "../Color"
|
|
3
|
+
import { Descriptor } from "./Descriptor"
|
|
4
|
+
|
|
5
|
+
class StyleShadow {
|
|
6
|
+
/**阴影类型
|
|
7
|
+
* - 0 box-shadow
|
|
8
|
+
* - 1 text-shadow
|
|
9
|
+
*/
|
|
10
|
+
type: number
|
|
11
|
+
/** 阴影颜色 */
|
|
12
|
+
color: DefaultStyleColor
|
|
13
|
+
/** 阴影是否内嵌 */
|
|
14
|
+
inset: boolean
|
|
15
|
+
/** 阴影水平偏移 */
|
|
16
|
+
offsetX: number
|
|
17
|
+
/** 阴影垂直偏移 */
|
|
18
|
+
offsetY: number
|
|
19
|
+
/** 阴影模糊半径 */
|
|
20
|
+
blur: number
|
|
21
|
+
/** 阴影扩展半径 */
|
|
22
|
+
spread: number
|
|
23
|
+
|
|
24
|
+
constructor(shadow: Partial<DeserializationObject<StyleShadow>> = {}) {
|
|
25
|
+
this.type = shadow.type ?? 0
|
|
26
|
+
this.color = new DefaultStyleColor(shadow.color)
|
|
27
|
+
this.inset = shadow.inset ?? false
|
|
28
|
+
this.offsetX = shadow.offsetX ?? 0
|
|
29
|
+
this.offsetY = shadow.offsetY ?? 0
|
|
30
|
+
this.blur = shadow.blur ?? 0
|
|
31
|
+
this.spread = shadow.spread ?? 0
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getStyleValue(unit = 'px') {
|
|
35
|
+
if (this.type === 0) {
|
|
36
|
+
const inset = this.inset ? 'inset' : ''
|
|
37
|
+
return `${inset} ${this.offsetX}${unit} ${this.offsetY}${unit} ${this.blur}${unit} ${this.spread}${unit} ${this.color.getColor()}`
|
|
38
|
+
} else {
|
|
39
|
+
return ` ${this.offsetX}${unit} ${this.offsetY}${unit} ${this.spread}${unit} ${this.color.getColor()}`
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class StyleSpacing {
|
|
45
|
+
left: number
|
|
46
|
+
top: number
|
|
47
|
+
right: number
|
|
48
|
+
bottom: number
|
|
49
|
+
|
|
50
|
+
constructor(border: Partial<DeserializationObject<StyleSpacing>> = {}) {
|
|
51
|
+
this.left = border.left ?? 0
|
|
52
|
+
this.top = border.top ?? 0
|
|
53
|
+
this.right = border.right ?? 0
|
|
54
|
+
this.bottom = border.bottom ?? 0
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getStyleValue(unit = 'px') {
|
|
58
|
+
return `${this.top}${unit} ${this.right}${unit} ${this.bottom}${unit} ${this.left}${unit}`
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type StyleRuleType = StyleColor | StyleShadow | StyleSpacing | number | string
|
|
63
|
+
|
|
64
|
+
class StyleRule<T extends StyleRuleType = StyleRuleType> {
|
|
65
|
+
static clone(rule: DeserializationObject<StyleRule>) {
|
|
66
|
+
let value: StyleRuleType
|
|
67
|
+
if (['box-shadow', 'text-shadow'].includes(rule.name)) {
|
|
68
|
+
//@ts-ignore
|
|
69
|
+
value = new StyleShadow(rule.value)
|
|
70
|
+
} else if (['background', 'border-color', 'color'].includes(rule.name)) {
|
|
71
|
+
//@ts-ignore
|
|
72
|
+
value = BasicStyleColor.create(rule.value)
|
|
73
|
+
} else if (['border-width', 'padding', 'margin'].includes(rule.name)) {
|
|
74
|
+
//@ts-ignore
|
|
75
|
+
value = new StyleSpacing(rule.value)
|
|
76
|
+
} else {
|
|
77
|
+
value = rule.value
|
|
78
|
+
}
|
|
79
|
+
return new StyleRule(rule.name, value, rule.inherit, rule.unit)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
name: string
|
|
83
|
+
value: T
|
|
84
|
+
inherit: boolean
|
|
85
|
+
unit: string
|
|
86
|
+
|
|
87
|
+
constructor(name: string, value: T, inherit: boolean = false, unit = '') {
|
|
88
|
+
this.name = name
|
|
89
|
+
this.value = value
|
|
90
|
+
this.inherit = inherit
|
|
91
|
+
this.unit = unit
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getValue() {
|
|
95
|
+
if (this.value instanceof BasicStyleColor) {
|
|
96
|
+
return this.value.getColor()
|
|
97
|
+
} else if (this.value instanceof StyleShadow) {
|
|
98
|
+
return this.value.getStyleValue(this.unit)
|
|
99
|
+
} else if (this.value instanceof StyleSpacing) {
|
|
100
|
+
return this.value.getStyleValue(this.unit)
|
|
101
|
+
} else if (this.name === 'transition') {
|
|
102
|
+
return `all ${this.value}s`
|
|
103
|
+
} else {
|
|
104
|
+
return this.value + this.unit
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let _basicStyle: StyleDescriptor | null = null
|
|
110
|
+
class StyleDescriptor extends Descriptor {
|
|
111
|
+
static type = 'Style'
|
|
112
|
+
static basicName = 'vyr_basic_style'
|
|
113
|
+
static activeName = 'vyr_active_style'
|
|
114
|
+
static get basicStyle() {
|
|
115
|
+
if (_basicStyle === null) {
|
|
116
|
+
_basicStyle = new StyleDescriptor({ name: 'basic', rules: [] })
|
|
117
|
+
const rules = StyleDescriptor.generateRule(false)
|
|
118
|
+
for (const rule of rules) _basicStyle.addRule(rule)
|
|
119
|
+
}
|
|
120
|
+
return _basicStyle
|
|
121
|
+
}
|
|
122
|
+
static generateRule = (inherit = true) => {
|
|
123
|
+
const rules: StyleRule[] = []
|
|
124
|
+
rules.push(new StyleRule('cursor', 'default', inherit))
|
|
125
|
+
rules.push(new StyleRule('padding', new StyleSpacing(), inherit, 'px'))
|
|
126
|
+
rules.push(new StyleRule('box-sizing', 'border-box', inherit))
|
|
127
|
+
rules.push(new StyleRule('overflow-x', 'visible', inherit))
|
|
128
|
+
rules.push(new StyleRule('overflow-y', 'visible', inherit))
|
|
129
|
+
rules.push(new StyleRule('vertical-align', 'baseline', inherit))
|
|
130
|
+
|
|
131
|
+
rules.push(new StyleRule('transition', 0.5, inherit))
|
|
132
|
+
|
|
133
|
+
rules.push(new StyleRule('background', new DefaultStyleColor({ opacity: 0 }), inherit))
|
|
134
|
+
rules.push(new StyleRule('background-blend-mode', 'normal', inherit))
|
|
135
|
+
rules.push(new StyleRule('background-clip', 'border-box', inherit))
|
|
136
|
+
|
|
137
|
+
rules.push(new StyleRule('box-shadow', new StyleShadow({ type: 0 }), inherit, 'px'))
|
|
138
|
+
rules.push(new StyleRule('text-shadow', new StyleShadow({ type: 1 }), inherit, 'px'))
|
|
139
|
+
|
|
140
|
+
rules.push(new StyleRule('border-style', 'solid', inherit))
|
|
141
|
+
rules.push(new StyleRule('border-color', new DefaultStyleColor(), inherit))
|
|
142
|
+
rules.push(new StyleRule('border-width', new StyleSpacing(), inherit, 'px'))
|
|
143
|
+
|
|
144
|
+
rules.push(new StyleRule('color', new DefaultStyleColor({ value: '#000000' }), inherit))
|
|
145
|
+
rules.push(new StyleRule('font-size', 16, inherit, 'px'))
|
|
146
|
+
rules.push(new StyleRule('text-align', 'left', inherit))
|
|
147
|
+
rules.push(new StyleRule('font-weight', 'normal', inherit))
|
|
148
|
+
rules.push(new StyleRule('line-height', 1.2, inherit))
|
|
149
|
+
rules.push(new StyleRule('font-style', 'normal', inherit))
|
|
150
|
+
rules.push(new StyleRule('text-decoration', 'none', inherit))
|
|
151
|
+
rules.push(new StyleRule('letter-spacing', 0, inherit, 'px'))
|
|
152
|
+
rules.push(new StyleRule('white-space', 'normal', inherit))
|
|
153
|
+
rules.push(new StyleRule('font-family', 'unset', inherit))
|
|
154
|
+
|
|
155
|
+
return rules
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**样式继承 */
|
|
159
|
+
inherit: string
|
|
160
|
+
/**样式规则 */
|
|
161
|
+
readonly rules: StyleRule[]
|
|
162
|
+
readonly hoverRules: StyleRule[]
|
|
163
|
+
readonly activeRules: StyleRule[]
|
|
164
|
+
|
|
165
|
+
constructor(descriptor: Partial<DeserializationObject<StyleDescriptor>> = {}) {
|
|
166
|
+
super(descriptor)
|
|
167
|
+
this.inherit = descriptor.inherit ?? ''
|
|
168
|
+
|
|
169
|
+
if (Array.isArray(descriptor.rules)) {
|
|
170
|
+
this.rules = []
|
|
171
|
+
for (const rule of descriptor.rules) this.addRule(StyleRule.clone(rule), this.rules)
|
|
172
|
+
} else {
|
|
173
|
+
this.rules = StyleDescriptor.generateRule(true)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (Array.isArray(descriptor.hoverRules)) {
|
|
177
|
+
this.hoverRules = []
|
|
178
|
+
for (const rule of descriptor.hoverRules) this.addRule(StyleRule.clone(rule), this.hoverRules)
|
|
179
|
+
} else {
|
|
180
|
+
this.hoverRules = StyleDescriptor.generateRule(true)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (Array.isArray(descriptor.activeRules)) {
|
|
184
|
+
this.activeRules = []
|
|
185
|
+
for (const rule of descriptor.activeRules) this.addRule(StyleRule.clone(rule), this.activeRules)
|
|
186
|
+
} else {
|
|
187
|
+
this.activeRules = StyleDescriptor.generateRule(true)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
addRule(rule: StyleRule, rules = this.rules) {
|
|
192
|
+
for (const item of rules) {
|
|
193
|
+
if (rule.name === item.name) return
|
|
194
|
+
}
|
|
195
|
+
rules.push(rule)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
removeRule(rule: StyleRule, rules = this.rules) {
|
|
199
|
+
for (let i = 0; i < rules.length; i++) {
|
|
200
|
+
const item = this.rules[i]
|
|
201
|
+
if (rule.name !== item.name) continue
|
|
202
|
+
rules.splice(i, 1)
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
clearRule(rules = this.rules) {
|
|
208
|
+
rules.length = 0
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
Descriptor.register(StyleDescriptor)
|
|
212
|
+
|
|
213
|
+
export { StyleShadow, StyleSpacing, StyleRuleType, StyleRule, StyleDescriptor }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './Descriptor'
|
|
2
|
+
export * from './DatasetDescriptor'
|
|
3
|
+
export * from './StyleDescriptor'
|
|
4
|
+
export * from './PrefabDescriptor'
|
|
5
|
+
export * from './RoutineDescriptor'
|
|
6
|
+
export * from './PrefabInstanceDescriptor'
|
|
7
|
+
export * from './DynamicDescriptor'
|
|
8
|
+
export * from './HTMLDescriptor'
|
|
9
|
+
export * from './DivDescriptor'
|
|
10
|
+
export * from './NodeDescriptor'
|
|
11
|
+
export * from './CameraDescriptor'
|
|
12
|
+
export * from './AnimationUnitDescriptor'
|
|
13
|
+
export * from './ControllerDescriptor'
|
|
14
|
+
export * from './HTMLTransformControllerDescriptor'
|
|
15
|
+
export * from './ServiceDescriptor'
|
|
16
|
+
export * from './HTMLServiceDescriptor'
|
|
17
|
+
export * from './ServiceSchedulerDescriptor'
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Unit } from "./Unit"
|
|
2
|
+
|
|
3
|
+
class UnitCollection {
|
|
4
|
+
private readonly instanceCollection = new Map<string, Unit>()
|
|
5
|
+
|
|
6
|
+
set(unit: Unit) {
|
|
7
|
+
this.instanceCollection.set(unit.uuid, unit)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
delete(uuid: string) {
|
|
11
|
+
this.instanceCollection.delete(uuid)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get(uuid: string) {
|
|
15
|
+
return this.instanceCollection.get(uuid)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
values() {
|
|
19
|
+
return [...this.instanceCollection.values()]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
UnitCollection
|
|
25
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Engine } from "../Engine";
|
|
2
|
+
import { Graphics } from "./Graphics";
|
|
3
|
+
import { Asset } from "../asset";
|
|
4
|
+
import { AnimationUnitDescriptor, ServiceSchedulerDescriptor, UpdateArgs } from "../descriptor";
|
|
5
|
+
|
|
6
|
+
class Compilation {
|
|
7
|
+
private collection = new Map<string, Graphics>()
|
|
8
|
+
|
|
9
|
+
get(scheduler: ServiceSchedulerDescriptor) {
|
|
10
|
+
return (this.collection.get(scheduler.uuid) ?? null) as Graphics
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
listen(scheduler: ServiceSchedulerDescriptor, engine: Engine) {
|
|
14
|
+
const url = Asset.getUrlByUuid(scheduler.uuid)
|
|
15
|
+
if (url) {
|
|
16
|
+
let graphics = this.collection.get(scheduler.uuid)
|
|
17
|
+
if (graphics === undefined) {
|
|
18
|
+
graphics = new Graphics(url, scheduler, engine)
|
|
19
|
+
this.collection.set(scheduler.uuid, graphics)
|
|
20
|
+
}
|
|
21
|
+
graphics.listen({ delta: 0 })
|
|
22
|
+
|
|
23
|
+
return graphics
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
unlisten(scheduler: ServiceSchedulerDescriptor, engine: Engine) {
|
|
28
|
+
const graphics = this.collection.get(scheduler.uuid)
|
|
29
|
+
if (graphics === undefined) return
|
|
30
|
+
graphics.unlisten({ delta: 0 })
|
|
31
|
+
this.collection.delete(scheduler.uuid)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
process(engine: Engine, args: UpdateArgs) {
|
|
35
|
+
Asset.free()
|
|
36
|
+
|
|
37
|
+
const collection = this.collection.values()
|
|
38
|
+
|
|
39
|
+
for (const graphics of collection) {
|
|
40
|
+
|
|
41
|
+
graphics.process(args)
|
|
42
|
+
|
|
43
|
+
graphics.clear(args)
|
|
44
|
+
|
|
45
|
+
engine.trigger(AnimationUnitDescriptor.type, args)
|
|
46
|
+
|
|
47
|
+
this.beforeRender(args)
|
|
48
|
+
engine.trigger('beforeRender', args)
|
|
49
|
+
|
|
50
|
+
this.render(args)
|
|
51
|
+
|
|
52
|
+
this.afterRender(args)
|
|
53
|
+
engine.trigger('afterRender', args)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
beforeRender(args: UpdateArgs) {
|
|
58
|
+
const collection = this.collection.values()
|
|
59
|
+
for (const graphics of collection) graphics.beforeRender(args)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
render(args: UpdateArgs) {
|
|
63
|
+
const collection = this.collection.values()
|
|
64
|
+
for (const graphics of collection) graphics.render(args)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
afterRender(args: UpdateArgs) {
|
|
68
|
+
const collection = this.collection.values()
|
|
69
|
+
for (const graphics of collection) graphics.afterRender(args)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
clear(engine: Engine) {
|
|
73
|
+
const collection = this.collection.values()
|
|
74
|
+
for (const graphics of collection) {
|
|
75
|
+
this.unlisten(graphics.scheduler, engine)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export {
|
|
81
|
+
Compilation
|
|
82
|
+
}
|