@safe-engine/pixi 8.3.7 → 8.4.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/.github/workflows/npm-publish.yml +35 -0
- package/README.md +70 -5
- package/dist/app.d.ts +2 -5
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +44 -27
- package/dist/base/gworld.d.ts +2 -0
- package/dist/base/gworld.d.ts.map +1 -1
- package/dist/box2d-wasm/ContactListener.d.ts +12 -0
- package/dist/box2d-wasm/ContactListener.d.ts.map +1 -0
- package/dist/box2d-wasm/ContactListener.js +64 -0
- package/dist/box2d-wasm/PhysicsComponent.d.ts +50 -0
- package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -0
- package/dist/box2d-wasm/PhysicsComponent.js +17 -0
- package/dist/box2d-wasm/PhysicsSprite.d.ts +11 -0
- package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -0
- package/dist/box2d-wasm/PhysicsSprite.js +30 -0
- package/dist/box2d-wasm/PhysicsSystem.d.ts +17 -0
- package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -0
- package/dist/box2d-wasm/PhysicsSystem.js +145 -0
- package/dist/box2d-wasm/debugDraw.d.ts +67 -0
- package/dist/box2d-wasm/debugDraw.d.ts.map +1 -0
- package/dist/box2d-wasm/debugDraw.js +224 -0
- package/dist/box2d-wasm/index.d.ts +6 -0
- package/dist/box2d-wasm/index.d.ts.map +1 -0
- package/dist/box2d-wasm/index.js +17 -0
- package/dist/collider/CollideComponent.d.ts.map +1 -1
- package/dist/collider/CollideComponent.js +12 -13
- package/dist/collider/CollideSystem.d.ts.map +1 -1
- package/dist/collider/CollideSystem.js +1 -2
- package/dist/collider/helper/utils.d.ts +2 -0
- package/dist/collider/helper/utils.d.ts.map +1 -1
- package/dist/collider/helper/utils.js +22 -0
- package/dist/collider/index.d.ts +1 -0
- package/dist/collider/index.d.ts.map +1 -1
- package/dist/collider/index.js +12 -0
- package/dist/components/NodeComp.d.ts +6 -4
- package/dist/components/NodeComp.d.ts.map +1 -1
- package/dist/components/NodeComp.js +13 -13
- package/dist/components/Scene.d.ts.map +1 -1
- package/dist/components/Scene.js +3 -4
- package/dist/core/director.d.ts.map +1 -1
- package/dist/core/director.js +4 -3
- package/dist/dragonbones/DragonBonesSystem.d.ts +2 -1
- package/dist/dragonbones/DragonBonesSystem.d.ts.map +1 -1
- package/dist/dragonbones/DragonBonesSystem.js +2 -0
- package/dist/dragonbones/index.d.ts +1 -0
- package/dist/dragonbones/index.d.ts.map +1 -1
- package/dist/dragonbones/index.js +7 -0
- package/dist/gui/GUIComponent.d.ts +0 -9
- package/dist/gui/GUIComponent.d.ts.map +1 -1
- package/dist/gui/GUIComponent.js +0 -37
- package/dist/gui/GUISystem.d.ts +1 -0
- package/dist/gui/GUISystem.d.ts.map +1 -1
- package/dist/gui/GUISystem.js +2 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/planck/PhysicsComponent.d.ts +7 -7
- package/dist/planck/PhysicsComponent.js +4 -4
- package/dist/planck/PhysicsSystem.js +12 -12
- package/dist/richtext/RichTextComp.d.ts +17 -0
- package/dist/richtext/RichTextComp.d.ts.map +1 -0
- package/dist/richtext/RichTextComp.js +38 -0
- package/dist/richtext/RichTextSystem.d.ts +7 -0
- package/dist/richtext/RichTextSystem.d.ts.map +1 -0
- package/dist/richtext/RichTextSystem.js +25 -0
- package/dist/richtext/html-text-parser.d.ts +20 -0
- package/dist/richtext/html-text-parser.d.ts.map +1 -0
- package/dist/richtext/html-text-parser.js +64 -0
- package/dist/richtext/index.d.ts +3 -0
- package/dist/richtext/index.d.ts.map +1 -0
- package/dist/richtext/index.js +7 -0
- package/dist/spine/index.d.ts +1 -0
- package/dist/spine/index.d.ts.map +1 -1
- package/dist/spine/index.js +7 -0
- package/package.json +9 -11
- package/src/@types/index.d.ts +2 -0
- package/src/@types/safex.d.ts +15 -0
- package/src/app.ts +85 -0
- package/src/base/EnhancedComponent.ts +37 -0
- package/src/base/gworld.ts +19 -0
- package/src/base/index.ts +3 -0
- package/src/base/utils.ts +23 -0
- package/src/box2d-wasm/ContactListener.ts +66 -0
- package/src/box2d-wasm/PhysicsComponent.ts +83 -0
- package/src/box2d-wasm/PhysicsSprite.ts +42 -0
- package/src/box2d-wasm/PhysicsSystem.ts +145 -0
- package/src/box2d-wasm/debugDraw.ts +257 -0
- package/src/box2d-wasm/index.ts +19 -0
- package/src/collider/CollideComponent.ts +257 -0
- package/src/collider/CollideSystem.ts +166 -0
- package/src/collider/helper/Intersection.ts +139 -0
- package/src/collider/helper/utils.ts +37 -0
- package/src/collider/index.ts +16 -0
- package/src/components/BaseComponent.ts +17 -0
- package/src/components/NodeComp.ts +434 -0
- package/src/components/Scene.ts +17 -0
- package/src/core/Color.ts +7 -0
- package/src/core/LoadingBar.ts +63 -0
- package/src/core/NodePool.ts +28 -0
- package/src/core/Size.ts +21 -0
- package/src/core/director.ts +11 -0
- package/src/core/math.ts +13 -0
- package/src/dragonbones/DragonBonesComponent.ts +32 -0
- package/src/dragonbones/DragonBonesSystem.ts +35 -0
- package/src/dragonbones/index.ts +11 -0
- package/src/gui/GUIComponent.ts +159 -0
- package/src/gui/GUISystem.ts +116 -0
- package/src/helper/utils.ts +50 -0
- package/src/index.ts +23 -0
- package/src/norender/NoRenderComponent.ts +60 -0
- package/src/norender/NoRenderSystem.ts +66 -0
- package/src/planck/PhysicsComponent.ts +83 -0
- package/src/planck/PhysicsSprite.ts +43 -0
- package/src/planck/PhysicsSystem.ts +201 -0
- package/src/planck/index.ts +3 -0
- package/src/render/RenderComponent.ts +138 -0
- package/src/render/RenderSystem.ts +67 -0
- package/src/richtext/RichTextComp.ts +46 -0
- package/src/richtext/RichTextSystem.ts +26 -0
- package/src/richtext/html-text-parser.ts +87 -0
- package/src/richtext/index.ts +8 -0
- package/src/spine/SpineComponent.ts +18 -0
- package/src/spine/SpineSystem.ts +30 -0
- package/src/spine/index.ts +11 -0
- package/src/spine/lib/BatchableSpineSlot.ts +138 -0
- package/src/spine/lib/Spine.ts +910 -0
- package/src/spine/lib/SpineDebugRenderer.ts +615 -0
- package/src/spine/lib/SpinePipe.ts +203 -0
- package/src/spine/lib/SpineTexture.ts +143 -0
- package/src/spine/lib/assets/atlasLoader.ts +158 -0
- package/src/spine/lib/assets/skeletonLoader.ts +81 -0
- package/src/spine/lib/darktint/DarkTintBatchGeometry.ts +92 -0
- package/src/spine/lib/darktint/DarkTintBatcher.ts +186 -0
- package/src/spine/lib/darktint/DarkTintShader.ts +74 -0
- package/src/spine/lib/darktint/darkTintBit.ts +77 -0
- package/src/spine/lib/index.ts +43 -0
- package/src/spine/lib/require-shim.ts +43 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Point } from 'pixi.js'
|
|
2
|
+
import { getDistance, v2 } from '../../helper/utils'
|
|
3
|
+
|
|
4
|
+
export function pointInPolygon(pos: Point, polygon: Point[]) {
|
|
5
|
+
let inside = false
|
|
6
|
+
const x = pos.x
|
|
7
|
+
const y = pos.y
|
|
8
|
+
|
|
9
|
+
// use some raycasting to test hits
|
|
10
|
+
// https://github.com/substack/point-in-polygon/blob/master/index.js
|
|
11
|
+
const length = polygon.length
|
|
12
|
+
|
|
13
|
+
let intersect = false
|
|
14
|
+
for (let i = 0, j = length - 1; i < length; j = i++) {
|
|
15
|
+
const xi = polygon[i].x,
|
|
16
|
+
yi = polygon[i].y,
|
|
17
|
+
xj = polygon[j].x,
|
|
18
|
+
yj = polygon[j].y
|
|
19
|
+
intersect = yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi
|
|
20
|
+
|
|
21
|
+
if (intersect) {
|
|
22
|
+
inside = !inside
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return inside
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function lineLine(a1: Point, a2: Point, b1: Point, b2: Point): boolean {
|
|
30
|
+
// jshint camel case:false
|
|
31
|
+
|
|
32
|
+
const ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x)
|
|
33
|
+
const ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x)
|
|
34
|
+
const u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y)
|
|
35
|
+
|
|
36
|
+
if (u_b !== 0) {
|
|
37
|
+
const ua = ua_t / u_b
|
|
38
|
+
const ub = ub_t / u_b
|
|
39
|
+
|
|
40
|
+
if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) {
|
|
41
|
+
return true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function linePolygon(A: Point, B: Point, polygon: Point[]) {
|
|
49
|
+
const length = polygon.length
|
|
50
|
+
for (let i = 0; i < length; ++i) {
|
|
51
|
+
const C = polygon[i]
|
|
52
|
+
const D = polygon[(i + 1) % length]
|
|
53
|
+
|
|
54
|
+
if (lineLine(A, B, C, D)) {
|
|
55
|
+
return true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function pointLineDistance(point: Point, start: Point, end: Point, isSegment) {
|
|
63
|
+
let dx = end.x - start.x
|
|
64
|
+
let dy = end.y - start.y
|
|
65
|
+
const d = dx * dx + dy * dy
|
|
66
|
+
const t = ((point.x - start.x) * dx + (point.y - start.y) * dy) / d
|
|
67
|
+
let p
|
|
68
|
+
|
|
69
|
+
if (!isSegment) {
|
|
70
|
+
p = v2(start.x + t * dx, start.y + t * dy)
|
|
71
|
+
} else if (d) {
|
|
72
|
+
if (t < 0) {
|
|
73
|
+
p = start
|
|
74
|
+
} else if (t > 1) {
|
|
75
|
+
p = end
|
|
76
|
+
} else {
|
|
77
|
+
p = v2(start.x + t * dx, start.y + t * dy)
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
p = start
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
dx = point.x - p.x
|
|
84
|
+
dy = point.y - p.y
|
|
85
|
+
return Math.sqrt(dx * dx + dy * dy)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function polygonPolygon(pts1: Point[], pts2: Point[]) {
|
|
89
|
+
let i = 0,
|
|
90
|
+
l = 0
|
|
91
|
+
|
|
92
|
+
// check if p1 pts1 intersects pts2
|
|
93
|
+
for (l = pts1.length; i < l; ++i) {
|
|
94
|
+
const a1 = pts1[i]
|
|
95
|
+
const a2 = pts1[(i + 1) % l]
|
|
96
|
+
|
|
97
|
+
if (linePolygon(a1, a2, pts2)) {
|
|
98
|
+
return true
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// check if pts1 contains pts2
|
|
103
|
+
for (i = 0, l = pts2.length; i < l; ++i) {
|
|
104
|
+
if (pointInPolygon(pts2[i], pts1)) {
|
|
105
|
+
return true
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// check if pts2 contains pts1
|
|
110
|
+
for (i = 0, l = pts1.length; i < l; ++i) {
|
|
111
|
+
if (pointInPolygon(pts1[i], pts2)) {
|
|
112
|
+
return true
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return false
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function circleCircle(p1: Point, r1: number, p2: Point, r2: number) {
|
|
120
|
+
const d = getDistance(p1, p2)
|
|
121
|
+
return d < r1 + r2
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function polygonCircle(pts1: Point[], p2: Point, r2: number) {
|
|
125
|
+
if (pointInPolygon(p2, pts1)) {
|
|
126
|
+
return true
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
for (let i = 0, l = pts1.length; i < l; i++) {
|
|
130
|
+
const start = i === 0 ? pts1[l - 1] : pts1[i - 1]
|
|
131
|
+
const end = pts1[i]
|
|
132
|
+
|
|
133
|
+
if (pointLineDistance(p2, start, end, true) < r2) {
|
|
134
|
+
return true
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return false
|
|
139
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { GameWorld } from '../../base'
|
|
2
|
+
import { Collider } from '../CollideComponent'
|
|
3
|
+
import { CollideSystem } from '../CollideSystem'
|
|
4
|
+
|
|
5
|
+
export function shouldCollider(colA: Collider, colB: Collider) {
|
|
6
|
+
const groupA = colA.node.group
|
|
7
|
+
const groupB = colB.node.group
|
|
8
|
+
if (groupA === undefined || groupB === undefined) {
|
|
9
|
+
return true
|
|
10
|
+
}
|
|
11
|
+
const { colliderMatrix } = GameWorld.Instance.systems.get(CollideSystem)
|
|
12
|
+
return colliderMatrix[groupA][groupB]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getMin(arr: number[]): number | null {
|
|
16
|
+
if (arr.length === 0) return null;
|
|
17
|
+
|
|
18
|
+
let min = arr[0];
|
|
19
|
+
for (let i = 1; i < arr.length; i++) {
|
|
20
|
+
if (arr[i] < min) {
|
|
21
|
+
min = arr[i];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return min;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getMax(arr: number[]): number | null {
|
|
28
|
+
if (arr.length === 0) return null;
|
|
29
|
+
|
|
30
|
+
let max = arr[0];
|
|
31
|
+
for (let i = 1; i < arr.length; i++) {
|
|
32
|
+
if (arr[i] > max) {
|
|
33
|
+
max = arr[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return max;
|
|
37
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GameWorld } from '..'
|
|
2
|
+
import { CollideSystem, enabledDebugDraw } from './CollideSystem'
|
|
3
|
+
|
|
4
|
+
export * from './CollideComponent'
|
|
5
|
+
export * from './CollideSystem'
|
|
6
|
+
|
|
7
|
+
export function setupCollider(colliderMatrix?, debug = false) {
|
|
8
|
+
GameWorld.Instance.systems.add(CollideSystem)
|
|
9
|
+
GameWorld.Instance.listUpdate.push(CollideSystem)
|
|
10
|
+
GameWorld.Instance.systems.configureOnce(CollideSystem)
|
|
11
|
+
const collideSystem = GameWorld.Instance.systems.get(CollideSystem)
|
|
12
|
+
if (colliderMatrix) {
|
|
13
|
+
collideSystem.colliderMatrix = colliderMatrix
|
|
14
|
+
}
|
|
15
|
+
enabledDebugDraw(debug)
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Container } from 'pixi.js'
|
|
2
|
+
import { EnhancedComponent, GameWorld } from '../base'
|
|
3
|
+
|
|
4
|
+
import { NodeComp } from './NodeComp'
|
|
5
|
+
|
|
6
|
+
export class NoRenderComponentX<Props = {}, C extends Container = Container> extends EnhancedComponent<Props, NodeComp<C>> {
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class ComponentX<Props = {}, C extends Container = Container> extends EnhancedComponent<Props, NodeComp<C>> {
|
|
10
|
+
static hasRender = true
|
|
11
|
+
render?(): this {
|
|
12
|
+
const world = GameWorld.Instance
|
|
13
|
+
const root = world.entities.create()
|
|
14
|
+
const comp = root.assign(this)
|
|
15
|
+
return comp
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { Constructor, Entity } from 'entityx-ts'
|
|
2
|
+
import { Action, actionManager, Animation } from 'pixi-action-ease'
|
|
3
|
+
import { Color, ColorSource, Container, Point, Sprite, Text } from 'pixi.js'
|
|
4
|
+
import { ComponentType, EnhancedComponent, instantiate } from '../base'
|
|
5
|
+
|
|
6
|
+
import { Size } from '../core/Size'
|
|
7
|
+
import { ProgressBarComp } from '../gui/GUIComponent'
|
|
8
|
+
import { ExtraDataComp } from '../norender/NoRenderComponent'
|
|
9
|
+
|
|
10
|
+
export type EventCallbackType = (...args) => void
|
|
11
|
+
export interface EventMap {
|
|
12
|
+
[key: string]: [EventCallbackType]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type TouchEventCallback = (target: { location: Point }) => void
|
|
16
|
+
|
|
17
|
+
export class NodeComp<C extends Container = Container> {
|
|
18
|
+
entity: Entity
|
|
19
|
+
instance: C
|
|
20
|
+
events: EventMap = {}
|
|
21
|
+
data: { [key: string]: any } = {}
|
|
22
|
+
parent: NodeComp
|
|
23
|
+
children: NodeComp[] = []
|
|
24
|
+
actionsList: Animation[] = []
|
|
25
|
+
// offset: cc.Point = cc.v2(0, 0);
|
|
26
|
+
name: string
|
|
27
|
+
// private lastMove: { x: number; y: number }
|
|
28
|
+
private _group = 0
|
|
29
|
+
|
|
30
|
+
onTouchStart?: TouchEventCallback
|
|
31
|
+
onTouchMove?: TouchEventCallback
|
|
32
|
+
onTouchEnd?: TouchEventCallback
|
|
33
|
+
onTouchCancel?: TouchEventCallback
|
|
34
|
+
|
|
35
|
+
setOnTouchStart(cb: TouchEventCallback) {
|
|
36
|
+
this.onTouchStart = cb
|
|
37
|
+
this.instance.on('touchstart', (event) => {
|
|
38
|
+
const { global } = event
|
|
39
|
+
this.onTouchStart({ location: global })
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setOnTouchMove(cb: TouchEventCallback) {
|
|
44
|
+
this.onTouchMove = cb
|
|
45
|
+
this.instance.on('touchmove', (event) => {
|
|
46
|
+
const { global } = event
|
|
47
|
+
this.onTouchMove({ location: global })
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setOnTouchEnd(cb: TouchEventCallback) {
|
|
52
|
+
this.onTouchEnd = cb
|
|
53
|
+
this.instance.on('touchend', (event) => {
|
|
54
|
+
const { global } = event
|
|
55
|
+
this.onTouchEnd({ location: global })
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setOnTouchCancel(cb: TouchEventCallback) {
|
|
60
|
+
this.onTouchCancel = cb
|
|
61
|
+
this.instance.on('touchcancel', (event) => {
|
|
62
|
+
const { global } = event
|
|
63
|
+
this.onTouchCancel({ location: global })
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
constructor(instance: C, entity: Entity) {
|
|
68
|
+
this.entity = entity
|
|
69
|
+
this.instance = instance
|
|
70
|
+
this.instance.eventMode = 'static'
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get uuid() {
|
|
74
|
+
return this.entity.id
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get position(): Point {
|
|
78
|
+
return this.getPosition()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
set position(val: Point) {
|
|
82
|
+
this.setPosition(val.x, val.y)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get posX() {
|
|
86
|
+
return this.instance.x
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
set posX(val: number) {
|
|
90
|
+
this.instance.x = val
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get posY() {
|
|
94
|
+
return this.instance.y
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
set posY(val: number) {
|
|
98
|
+
this.instance.y = val
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
set xy(val: [number, number]) {
|
|
102
|
+
this.setPosition(val[0], val[1])
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get scale() {
|
|
106
|
+
return this.instance.scale.x
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
set scale(val: number) {
|
|
110
|
+
this.instance.scale = new Point(val, val)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get scaleX() {
|
|
114
|
+
return this.instance.scale.x
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
set scaleX(val: number) {
|
|
118
|
+
this.instance.scale.x = val
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
get scaleY() {
|
|
122
|
+
return this.instance.scale.y
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
set scaleY(val: number) {
|
|
126
|
+
this.instance.scale.y = val
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
get anchorX() {
|
|
130
|
+
if ((this.instance instanceof Sprite) || (this.instance instanceof Text))
|
|
131
|
+
return this.instance.anchor.x
|
|
132
|
+
return 0
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
set anchorX(val: number) {
|
|
136
|
+
if ((this.instance instanceof Sprite) || (this.instance instanceof Text))
|
|
137
|
+
this.instance.anchor.x = val
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
get anchorY() {
|
|
141
|
+
if ((this.instance instanceof Sprite) || (this.instance instanceof Text))
|
|
142
|
+
return this.instance.anchor.y
|
|
143
|
+
return 0
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
set anchorY(val: number) {
|
|
147
|
+
if ((this.instance instanceof Sprite) || (this.instance instanceof Text))
|
|
148
|
+
this.instance.anchor.y = val
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** rotation is in radians */
|
|
152
|
+
get rotation() {
|
|
153
|
+
return this.instance.rotation
|
|
154
|
+
}
|
|
155
|
+
/** rotation is in radians */
|
|
156
|
+
set rotation(val: number) {
|
|
157
|
+
this.instance.rotation = val
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** angle is in degrees. */
|
|
161
|
+
get angle() {
|
|
162
|
+
return this.instance.angle
|
|
163
|
+
}
|
|
164
|
+
/** angle is in degrees. */
|
|
165
|
+
set angle(val: number) {
|
|
166
|
+
this.instance.angle = val
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
get color() {
|
|
170
|
+
if (this.instance instanceof Sprite)
|
|
171
|
+
return this.instance.tint
|
|
172
|
+
if (this.instance instanceof Text)
|
|
173
|
+
return this.instance.style.fill as ColorSource
|
|
174
|
+
return 0xffffff
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
set color(val: ColorSource) {
|
|
178
|
+
if (this.instance instanceof Sprite) this.instance.tint = val
|
|
179
|
+
if (this.instance instanceof Text) this.instance.style.fill = val
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
get opacity() {
|
|
183
|
+
return this.instance.alpha
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
set opacity(val: number) {
|
|
187
|
+
this.instance.alpha = val
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
get active() {
|
|
191
|
+
return this.instance.visible && !this.instance.destroyed
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
set active(val: boolean) {
|
|
195
|
+
this.instance.visible = val
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
get group() {
|
|
199
|
+
return this._group
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
set group(val: number) {
|
|
203
|
+
this._group = val
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
get width() {
|
|
207
|
+
return this.instance.width
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
set width(val) {
|
|
211
|
+
this.instance.width = val
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
get height() {
|
|
215
|
+
return this.instance.height
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
set height(val) {
|
|
219
|
+
this.instance.height = val
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
get zIndex() {
|
|
223
|
+
return this.instance.zIndex
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
set zIndex(val) {
|
|
227
|
+
this.instance.zIndex = val
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
get childrenCount() {
|
|
231
|
+
return this.children.length
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
addComponent<T extends ComponentType>(instance): T {
|
|
235
|
+
return this.entity.assign(instance)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
getComponent<T extends Constructor<ComponentType>>(component: T): InstanceType<T> {
|
|
239
|
+
return this.entity.getComponent(component) as any
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
getComponentsInChildren<T extends ComponentType>(component: Constructor<T>): T[] {
|
|
243
|
+
if (!this.children.length) {
|
|
244
|
+
return []
|
|
245
|
+
}
|
|
246
|
+
const listHave = this.children.filter((child) => {
|
|
247
|
+
return child.getComponent(component)
|
|
248
|
+
})
|
|
249
|
+
return listHave.map((node) => node.getComponent(component))
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
getComponentInChildren<T extends ComponentType>(component: Constructor<T>): T {
|
|
253
|
+
return this.getComponentsInChildren(component)[0]
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
convertToNodeSpace(point: Point) {
|
|
257
|
+
return this.instance.toLocal(point)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
convertToNodeSpaceAR(point: Point) {
|
|
261
|
+
return this.instance.toLocal(point)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
convertToWorldSpaceAR(point: Point) {
|
|
265
|
+
return this.instance.toGlobal(point)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
getPosition(): Point {
|
|
269
|
+
return this.instance.position
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
setPosition(x: number | Point, y?: number) {
|
|
273
|
+
if (typeof x !== 'number') {
|
|
274
|
+
this.instance.position = new Point(x.x, x.y)
|
|
275
|
+
} else {
|
|
276
|
+
this.instance.position = new Point(x, y)
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
setRotation(deg: number) {
|
|
281
|
+
this.instance.rotation = deg
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
getRotation() {
|
|
285
|
+
return this.instance.rotation
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// setAnchorPoint(point: number | cc.Point, y?: number) {
|
|
289
|
+
// this.instance.setAnchorPoint(point, y)
|
|
290
|
+
// }
|
|
291
|
+
|
|
292
|
+
// getAnchorPoint() {
|
|
293
|
+
// return this.instance.getAnchorPoint()
|
|
294
|
+
// }
|
|
295
|
+
|
|
296
|
+
// getBoundingBox() {
|
|
297
|
+
// const box = this.instance.getBoundingBox()
|
|
298
|
+
// box.contains = function (point) {
|
|
299
|
+
// return this.x <= point.x && this.x + this.width >= point.x && this.y <= point.y && this.y + this.height >= point.y
|
|
300
|
+
// }
|
|
301
|
+
// return box
|
|
302
|
+
// }
|
|
303
|
+
|
|
304
|
+
getContentSize(): Size {
|
|
305
|
+
return this.instance.boundsArea
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// setContentSize(size: cc.Size | number, height?: number) {
|
|
309
|
+
// this.instance.setContentSize(size, height)
|
|
310
|
+
// if (this.instance instanceof cc.ClippingNode) {
|
|
311
|
+
// const hw = ((size as any).width || size) * 0.5
|
|
312
|
+
// const hh = ((size as any).height || height) * 0.5
|
|
313
|
+
// const stencil = new cc.DrawNode()
|
|
314
|
+
// const rectangle = [cc.p(-hw, -hh), cc.p(hw, -hh), cc.p(hw, hh), cc.p(-hw, hh)]
|
|
315
|
+
// stencil.drawPoly(rectangle, cc.Color.WHITE, 0, cc.Color.WHITE)
|
|
316
|
+
// // stencil.drawDot(cc.p(-height * 0.5, -height * 0.5), height, cc.Color.WHITE);
|
|
317
|
+
// this.instance.stencil = stencil
|
|
318
|
+
// }
|
|
319
|
+
// }
|
|
320
|
+
|
|
321
|
+
setColor(color: Color) {
|
|
322
|
+
if (this.instance instanceof Sprite)
|
|
323
|
+
(this.instance as Sprite).tint = color
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
setScale(scaleX: number, scaleY?: number) {
|
|
327
|
+
this.instance.scale.x = scaleX
|
|
328
|
+
this.instance.scale.x = scaleY || scaleX
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
runAction(act: Action) {
|
|
332
|
+
const animation = actionManager.runAction(this.instance as any, act)
|
|
333
|
+
this.actionsList.push(animation)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
stopAllActions() {
|
|
337
|
+
this.actionsList.forEach((act) => {
|
|
338
|
+
actionManager.cancelAction(act)
|
|
339
|
+
})
|
|
340
|
+
this.actionsList = []
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
pauseAllActions() {
|
|
344
|
+
this.actionsList.forEach((anim: Animation) => {
|
|
345
|
+
anim.isPause = true
|
|
346
|
+
})
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
resumeAllActions() {
|
|
350
|
+
this.actionsList.forEach((anim: Animation) => {
|
|
351
|
+
anim.isPause = false
|
|
352
|
+
})
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
destroy() {
|
|
356
|
+
if (this.parent) {
|
|
357
|
+
this.parent.children = this.parent.children.filter(({ entity }) => entity.id !== this.entity.id)
|
|
358
|
+
}
|
|
359
|
+
this.children.forEach((child) => {
|
|
360
|
+
child.destroy()
|
|
361
|
+
})
|
|
362
|
+
this.parent = null
|
|
363
|
+
this.entity.destroy()
|
|
364
|
+
this.stopAllActions()
|
|
365
|
+
this.instance.destroy()
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
removeFromParent() {
|
|
369
|
+
this.active = false
|
|
370
|
+
this.stopAllActions()
|
|
371
|
+
this.instance.removeFromParent()
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
addChild(child: NodeComp, zOrder?: number) {
|
|
375
|
+
child.parent = this
|
|
376
|
+
child.active = true
|
|
377
|
+
this.children.push(child)
|
|
378
|
+
this.instance.addChild(child.instance)
|
|
379
|
+
if (zOrder) child.zIndex = zOrder
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
destroyAllChildren() {
|
|
383
|
+
this.children.forEach((child) => {
|
|
384
|
+
child.destroy()
|
|
385
|
+
})
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
on(name: string, callback: EventCallbackType, target?: any) {
|
|
389
|
+
const bound = target ? callback.bind(target) : callback
|
|
390
|
+
if (this.events[name]) {
|
|
391
|
+
this.events[name].push(bound)
|
|
392
|
+
} else {
|
|
393
|
+
this.events[name] = [bound]
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
off(name: string) {
|
|
398
|
+
this.events[name] = undefined
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
emit(name: string, ...params: any) {
|
|
402
|
+
if (this.events[name]) {
|
|
403
|
+
this.events[name].forEach((fc) => fc(...params))
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
resolveComponent(component: EnhancedComponent<{}, NodeComp>) {
|
|
408
|
+
// console.log(component.constructor.name, (component.constructor as any).hasRender)
|
|
409
|
+
if ((component.constructor as any).hasRender) {
|
|
410
|
+
this.addChild(component.node)
|
|
411
|
+
} else {
|
|
412
|
+
this.addComponent(component)
|
|
413
|
+
if (component instanceof ProgressBarComp) {
|
|
414
|
+
this.addChild(component.node)
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
getData<T>(key: string): T {
|
|
420
|
+
const data = this.getComponent(ExtraDataComp)
|
|
421
|
+
if (!data) return console.warn('need add ExtraDataComp to Node') as T
|
|
422
|
+
return data.getData(key)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
setData<T>(key: string, value: T) {
|
|
426
|
+
const data = this.getComponent(ExtraDataComp)
|
|
427
|
+
// console.log('setData', key, value, data)
|
|
428
|
+
if (!data) {
|
|
429
|
+
this.addComponent(instantiate(ExtraDataComp, { key, value }))
|
|
430
|
+
} else {
|
|
431
|
+
data.setData(key, value)
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EnhancedComponent, GameWorld } from '../base'
|
|
2
|
+
|
|
3
|
+
import { NodeComp } from './NodeComp'
|
|
4
|
+
|
|
5
|
+
export class SceneComponent extends EnhancedComponent<{}, NodeComp> {
|
|
6
|
+
render() {
|
|
7
|
+
const world = GameWorld.Instance
|
|
8
|
+
world.entities.reset()
|
|
9
|
+
const root = world.entities.create()
|
|
10
|
+
const node = root.assign(new NodeComp(GameWorld.Instance.app.stage, root))
|
|
11
|
+
GameWorld.Instance.app.stage.eventMode = 'static';
|
|
12
|
+
GameWorld.Instance.app.stage.hitArea = GameWorld.Instance.app.screen;
|
|
13
|
+
const sceneComponent = root.assign(this)
|
|
14
|
+
sceneComponent.node = node
|
|
15
|
+
return sceneComponent
|
|
16
|
+
}
|
|
17
|
+
}
|