@safe-engine/pixi 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/components/GUIComponent.d.ts +3 -3
- package/dist/components/GUIComponent.d.ts.map +1 -1
- package/dist/components/NodeComp.d.ts +1 -1
- package/dist/components/NodeComp.d.ts.map +1 -1
- package/dist/components/NodeComp.js +1 -1
- package/dist/helper/utils.d.ts +1 -7
- package/dist/helper/utils.d.ts.map +1 -1
- package/dist/helper/utils.js +5 -25
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/systems/GUISystem.d.ts +1 -2
- package/dist/systems/GUISystem.d.ts.map +1 -1
- package/dist/systems/GUISystem.js +52 -73
- package/dist/systems/RenderSystem.d.ts +1 -2
- package/dist/systems/RenderSystem.d.ts.map +1 -1
- package/dist/systems/RenderSystem.js +47 -70
- package/package.json +2 -3
- package/.github/workflows/npm-publish.yml +0 -35
- package/dist/core/Vec2.d.ts +0 -20
- package/dist/core/Vec2.d.ts.map +0 -1
- package/dist/core/Vec2.js +0 -70
- package/src/app.ts +0 -51
- package/src/components/EnhancedComponent.ts +0 -57
- package/src/components/GUIComponent.ts +0 -147
- package/src/components/NodeComp.ts +0 -409
- package/src/components/RenderComponent.ts +0 -65
- package/src/core/Color.ts +0 -3
- package/src/core/LoadingBar.ts +0 -33
- package/src/core/Scene.ts +0 -17
- package/src/core/Size.ts +0 -21
- package/src/core/Vec2.ts +0 -52
- package/src/core/decorator.ts +0 -18
- package/src/gworld.ts +0 -17
- package/src/helper/html-text-parser.ts +0 -364
- package/src/helper/utils.ts +0 -64
- package/src/index.ts +0 -10
- package/src/systems/GUISystem.ts +0 -95
- package/src/systems/RenderSystem.ts +0 -100
- package/tsconfig.json +0 -24
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
import { Constructor,Entity } from 'entityx-ts'
|
|
2
|
-
import remove from 'lodash/remove'
|
|
3
|
-
import { Color, ColorSource, Container, Point, Sprite } from 'pixi.js'
|
|
4
|
-
import { Action, actionManager, Animation } from 'pixi-action-ease'
|
|
5
|
-
|
|
6
|
-
import { Size } from '../helper/utils'
|
|
7
|
-
import { ComponentType, EnhancedComponent } from './EnhancedComponent'
|
|
8
|
-
import { ProgressBarComp } from './GUIComponent'
|
|
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 {
|
|
18
|
-
entity: Entity
|
|
19
|
-
instance: Container
|
|
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: Container, 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 x() {
|
|
86
|
-
return this.instance.x
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
set x(val: number) {
|
|
90
|
-
this.instance.x = val
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
get y() {
|
|
94
|
-
return this.instance.y
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
set y(val: number) {
|
|
98
|
-
this.instance.y = val
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// get scale() {
|
|
102
|
-
// return this.instance.scale
|
|
103
|
-
// }
|
|
104
|
-
|
|
105
|
-
set scale(val: number) {
|
|
106
|
-
this.instance.scale = new Point(val, val)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
get scaleX() {
|
|
110
|
-
return this.instance.scale.x
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
set scaleX(val: number) {
|
|
114
|
-
this.instance.scale.x = val
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
get scaleY() {
|
|
118
|
-
return this.instance.y
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
set scaleY(val: number) {
|
|
122
|
-
this.instance.y = val
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
get anchorX() {
|
|
126
|
-
return (this.instance as Sprite).anchor.x
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
set anchorX(val: number) {
|
|
130
|
-
if (this.instance instanceof Sprite) this.instance.anchor.x = val
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
get anchorY() {
|
|
134
|
-
return (this.instance as Sprite).anchor.y
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
set anchorY(val: number) {
|
|
138
|
-
if (this.instance instanceof Sprite) this.instance.anchor.y = val
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** rotation is in radians */
|
|
142
|
-
get rotation() {
|
|
143
|
-
return this.instance.rotation
|
|
144
|
-
}
|
|
145
|
-
/** rotation is in radians */
|
|
146
|
-
set rotation(val: number) {
|
|
147
|
-
this.instance.rotation = val
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** angle is in degrees. */
|
|
151
|
-
get angle() {
|
|
152
|
-
return this.instance.angle
|
|
153
|
-
}
|
|
154
|
-
/** angle is in degrees. */
|
|
155
|
-
set angle(val: number) {
|
|
156
|
-
this.instance.angle = val
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
get color() {
|
|
160
|
-
return (this.instance as Sprite).tint
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
set color(val: ColorSource) {
|
|
164
|
-
if (this.instance instanceof Sprite) this.instance.tint = val
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
get opacity() {
|
|
168
|
-
return this.instance.alpha
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
set opacity(val: number) {
|
|
172
|
-
this.instance.alpha = val
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
get active() {
|
|
176
|
-
return this.instance.visible && !this.instance.destroyed
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
set active(val: boolean) {
|
|
180
|
-
this.instance.visible = val
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
get group() {
|
|
184
|
-
return this._group
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
set group(val: number) {
|
|
188
|
-
this._group = val
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
get width() {
|
|
192
|
-
return this.instance.width
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
set width(val) {
|
|
196
|
-
this.instance.width = val
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
get height() {
|
|
200
|
-
return this.instance.height
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
set height(val) {
|
|
204
|
-
this.instance.height = val
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
get zIndex() {
|
|
208
|
-
return this.instance.zIndex
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
set zIndex(val) {
|
|
212
|
-
this.instance.zIndex = val
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
get childrenCount() {
|
|
216
|
-
return this.children.length
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
addComponent<T extends ComponentType>(instance): T {
|
|
220
|
-
return this.entity.assign(instance)
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
getComponent<T extends ComponentType>(component: Constructor<T>): T {
|
|
224
|
-
return this.entity.getComponent(component)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
getComponentsInChildren<T extends ComponentType>(component: Constructor<T>): T[] {
|
|
228
|
-
if (!this.children.length) {
|
|
229
|
-
return []
|
|
230
|
-
}
|
|
231
|
-
const listHave = this.children.filter((child) => {
|
|
232
|
-
return child.getComponent(component)
|
|
233
|
-
})
|
|
234
|
-
return listHave.map((node) => node.getComponent(component))
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
getComponentInChildren<T extends ComponentType>(component: Constructor<T>): T {
|
|
238
|
-
return this.getComponentsInChildren(component)[0]
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
convertToNodeSpace(point: Point) {
|
|
242
|
-
return this.instance.toLocal(point)
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
convertToNodeSpaceAR(point: Point) {
|
|
246
|
-
return this.instance.toLocal(point)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
convertToWorldSpaceAR(point: Point) {
|
|
250
|
-
return this.instance.toGlobal(point)
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
getPosition(): Point {
|
|
254
|
-
return this.instance.position
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
setPosition(x: number | Point, y?: number) {
|
|
258
|
-
if (typeof x !== 'number') {
|
|
259
|
-
this.x = x.x
|
|
260
|
-
this.y = x.y
|
|
261
|
-
} else {
|
|
262
|
-
this.x = x
|
|
263
|
-
this.y = y
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
setRotation(deg: number) {
|
|
268
|
-
this.instance.rotation = deg
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
getRotation() {
|
|
272
|
-
return this.instance.rotation
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// setAnchorPoint(point: number | cc.Point, y?: number) {
|
|
276
|
-
// this.instance.setAnchorPoint(point, y)
|
|
277
|
-
// }
|
|
278
|
-
|
|
279
|
-
// getAnchorPoint() {
|
|
280
|
-
// return this.instance.getAnchorPoint()
|
|
281
|
-
// }
|
|
282
|
-
|
|
283
|
-
// getBoundingBox() {
|
|
284
|
-
// const box = this.instance.getBoundingBox()
|
|
285
|
-
// box.contains = function (point) {
|
|
286
|
-
// return this.x <= point.x && this.x + this.width >= point.x && this.y <= point.y && this.y + this.height >= point.y
|
|
287
|
-
// }
|
|
288
|
-
// return box
|
|
289
|
-
// }
|
|
290
|
-
|
|
291
|
-
getContentSize(): Size {
|
|
292
|
-
return this.instance
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// setContentSize(size: cc.Size | number, height?: number) {
|
|
296
|
-
// this.instance.setContentSize(size, height)
|
|
297
|
-
// if (this.instance instanceof cc.ClippingNode) {
|
|
298
|
-
// const hw = ((size as any).width || size) * 0.5
|
|
299
|
-
// const hh = ((size as any).height || height) * 0.5
|
|
300
|
-
// const stencil = new cc.DrawNode()
|
|
301
|
-
// const rectangle = [cc.p(-hw, -hh), cc.p(hw, -hh), cc.p(hw, hh), cc.p(-hw, hh)]
|
|
302
|
-
// stencil.drawPoly(rectangle, cc.Color.WHITE, 0, cc.Color.WHITE)
|
|
303
|
-
// // stencil.drawDot(cc.p(-height * 0.5, -height * 0.5), height, cc.Color.WHITE);
|
|
304
|
-
// this.instance.stencil = stencil
|
|
305
|
-
// }
|
|
306
|
-
// }
|
|
307
|
-
|
|
308
|
-
setColor(color: Color) {
|
|
309
|
-
(this.instance as Sprite).tint = color
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
setScale(scaleX: number, scaleY?: number) {
|
|
313
|
-
this.instance.scale.x = scaleX
|
|
314
|
-
this.instance.scale.x = scaleY || scaleX
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
runAction(act: Action) {
|
|
318
|
-
const animation = actionManager.runAction(this.instance as any, act)
|
|
319
|
-
this.actionsList.push(animation)
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
stopAllActions() {
|
|
323
|
-
this.actionsList.forEach((act) => {
|
|
324
|
-
actionManager.cancelAction(act)
|
|
325
|
-
})
|
|
326
|
-
this.actionsList = []
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
pauseAllActions() {
|
|
330
|
-
this.actionsList.forEach((anim: Animation) => {
|
|
331
|
-
anim.isPause = true
|
|
332
|
-
})
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
resumeAllActions() {
|
|
336
|
-
this.actionsList.forEach((anim: Animation) => {
|
|
337
|
-
anim.isPause = false
|
|
338
|
-
})
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
destroy() {
|
|
342
|
-
if (this.parent) {
|
|
343
|
-
remove(this.parent.children, ({ entity }) => entity.id === this.entity.id)
|
|
344
|
-
}
|
|
345
|
-
this.children.forEach((child) => {
|
|
346
|
-
child.destroy()
|
|
347
|
-
})
|
|
348
|
-
this.parent = null
|
|
349
|
-
this.entity.destroy()
|
|
350
|
-
this.stopAllActions()
|
|
351
|
-
this.instance.destroy()
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
removeFromParent() {
|
|
355
|
-
this.active = false
|
|
356
|
-
this.stopAllActions()
|
|
357
|
-
this.instance.removeFromParent()
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
addChild(child: NodeComp, zOrder?: number) {
|
|
361
|
-
child.parent = this
|
|
362
|
-
child.active = true
|
|
363
|
-
this.children.push(child)
|
|
364
|
-
this.instance.addChild(child.instance)
|
|
365
|
-
if (zOrder) child.zIndex = zOrder
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
destroyAllChildren() {
|
|
369
|
-
this.children.forEach((child) => {
|
|
370
|
-
child.destroy()
|
|
371
|
-
})
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
on(name: string, callback: EventCallbackType, target?: any) {
|
|
375
|
-
const bound = target ? callback.bind(target) : callback
|
|
376
|
-
if (this.events[name]) {
|
|
377
|
-
this.events[name].push(bound)
|
|
378
|
-
} else {
|
|
379
|
-
this.events[name] = [bound]
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
off(name: string) {
|
|
384
|
-
this.events[name] = undefined
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
emit(name: string, ...params: any) {
|
|
388
|
-
if (this.events[name]) {
|
|
389
|
-
this.events[name].forEach((fc) => fc(...params))
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
resolveComponent(component: EnhancedComponent) {
|
|
394
|
-
if ((component.constructor as any).hasRender) {
|
|
395
|
-
this.addChild(component.node)
|
|
396
|
-
} else {
|
|
397
|
-
this.addComponent(component)
|
|
398
|
-
if (component instanceof ProgressBarComp) {
|
|
399
|
-
this.addChild(component.node)
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
getData<T>(key: string): T {
|
|
404
|
-
return this.data[key]
|
|
405
|
-
}
|
|
406
|
-
setData<T>(key: string, val: T) {
|
|
407
|
-
this.data[key] = val
|
|
408
|
-
}
|
|
409
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { ColorSource, Point, Sprite, Texture, TextureSource } from 'pixi.js'
|
|
2
|
-
|
|
3
|
-
import { ComponentX } from '../core/decorator'
|
|
4
|
-
import { LoadingBar, LoadingBarMode } from '../core/LoadingBar'
|
|
5
|
-
import { SpriteTypes } from '../systems/RenderSystem'
|
|
6
|
-
|
|
7
|
-
export class NodeRender extends ComponentX {
|
|
8
|
-
nodeName?: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class SpriteRender extends ComponentX {
|
|
12
|
-
public spriteFrame: TextureSource
|
|
13
|
-
public type: SpriteTypes
|
|
14
|
-
public fillType: LoadingBarMode = LoadingBarMode.BAR
|
|
15
|
-
public fillRange = 1
|
|
16
|
-
public fillCenter: Point
|
|
17
|
-
loadingBar: LoadingBar
|
|
18
|
-
|
|
19
|
-
// set fillStart(val: number) {
|
|
20
|
-
// if (this.node.instance instanceof cc.ProgressTimer) {
|
|
21
|
-
// this.node.instance.setMidpoint(cc.v2(val, val));
|
|
22
|
-
// }
|
|
23
|
-
// }
|
|
24
|
-
|
|
25
|
-
setFillRange(val: number) {
|
|
26
|
-
if (this.loadingBar) {
|
|
27
|
-
this.loadingBar.progress = val
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getSpriteFrame() {
|
|
32
|
-
return this.spriteFrame
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
setSpriteFrame(frame) {
|
|
36
|
-
this.spriteFrame = frame
|
|
37
|
-
const sprite = this.node.instance as Sprite
|
|
38
|
-
// if (this.node.instance instanceof cc.Sprite) {
|
|
39
|
-
sprite.texture = Texture.from(frame)
|
|
40
|
-
// sprite.texture.rotate = 8
|
|
41
|
-
// } else if (this.node.instance instanceof ccui.ImageView) {
|
|
42
|
-
// if (this.texType) {
|
|
43
|
-
// this.node.instance.loadTexture(frame, this.texType);
|
|
44
|
-
// } else {
|
|
45
|
-
// this.node.instance.loadTexture(frame);
|
|
46
|
-
// }
|
|
47
|
-
// const sprite = new cc.Sprite(frame);
|
|
48
|
-
// this.node.setContentSize(sprite.getContentSize());
|
|
49
|
-
// } else if (this.node.instance instanceof ccui.Button) {
|
|
50
|
-
// this.node.instance.loadTextureNormal(frame);
|
|
51
|
-
// }
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export class GraphicsRender extends ComponentX {
|
|
56
|
-
lineWidth = 2
|
|
57
|
-
strokeColor: ColorSource
|
|
58
|
-
fillColor: ColorSource
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export class MaskRender extends ComponentX {
|
|
62
|
-
type: number
|
|
63
|
-
segments: number
|
|
64
|
-
inverted: boolean
|
|
65
|
-
}
|
package/src/core/Color.ts
DELETED
package/src/core/LoadingBar.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Graphics, Point, Sprite } from 'pixi.js'
|
|
2
|
-
|
|
3
|
-
export enum LoadingBarMode {
|
|
4
|
-
BAR,
|
|
5
|
-
RADIAL,
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class LoadingBar extends Graphics {
|
|
9
|
-
spriteComp: Sprite
|
|
10
|
-
mode: LoadingBarMode
|
|
11
|
-
fillCenter = new Point(0.5, 0.5)
|
|
12
|
-
constructor(mode: LoadingBarMode, spriteComp: Sprite) {
|
|
13
|
-
super()
|
|
14
|
-
this.spriteComp = spriteComp
|
|
15
|
-
this.mode = mode || LoadingBarMode.BAR
|
|
16
|
-
this.beginFill(0xffffff)
|
|
17
|
-
this.drawRect(0, 0, spriteComp.width, spriteComp.height)
|
|
18
|
-
spriteComp.mask = this
|
|
19
|
-
spriteComp.addChild(this)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
set progress(val: number) {
|
|
23
|
-
this.clear()
|
|
24
|
-
this.beginFill(0xffffff)
|
|
25
|
-
if (this.mode === LoadingBarMode.BAR) {
|
|
26
|
-
const spriteComp = this.spriteComp
|
|
27
|
-
this.drawRect(0, 0, spriteComp.width * val, spriteComp.height)
|
|
28
|
-
// console.log('new length', spriteComp.width)
|
|
29
|
-
this.x = -spriteComp.width * 0.5
|
|
30
|
-
this.y = -spriteComp.height * 0.5
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
package/src/core/Scene.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { app } from '../app'
|
|
2
|
-
import { EnhancedComponent } from '../components/EnhancedComponent'
|
|
3
|
-
import { NodeComp } from '../components/NodeComp'
|
|
4
|
-
import { GameWorld } from '../gworld'
|
|
5
|
-
|
|
6
|
-
export class SceneComponent extends EnhancedComponent {
|
|
7
|
-
static boot: () => void
|
|
8
|
-
static create() {
|
|
9
|
-
const world = GameWorld.Instance
|
|
10
|
-
world.entities.reset()
|
|
11
|
-
const root = world.entities.create()
|
|
12
|
-
const node = root.assign(new NodeComp(app.stage, root))
|
|
13
|
-
const sceneComponent = root.assign(new SceneComponent())
|
|
14
|
-
sceneComponent.node = node
|
|
15
|
-
return sceneComponent
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/core/Size.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
class _Size {
|
|
2
|
-
width: number
|
|
3
|
-
height: number
|
|
4
|
-
static ZERO
|
|
5
|
-
constructor(width = 0, height = 0) {
|
|
6
|
-
if (!(this instanceof _Size)) {
|
|
7
|
-
return new _Size(width, height)
|
|
8
|
-
}
|
|
9
|
-
if (height === undefined) {
|
|
10
|
-
this.width = (width as any).width
|
|
11
|
-
this.height = (width as any).height
|
|
12
|
-
}
|
|
13
|
-
this.width = width
|
|
14
|
-
this.height = height
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type Size = _Size
|
|
19
|
-
export function Size(x?: number, y?: number): Size {
|
|
20
|
-
return new _Size(x, y)
|
|
21
|
-
}
|
package/src/core/Vec2.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import clamp from 'lodash/clamp';
|
|
2
|
-
import { Point } from 'pixi.js'
|
|
3
|
-
|
|
4
|
-
class _Vec2 extends Point {
|
|
5
|
-
x: number
|
|
6
|
-
y: number
|
|
7
|
-
static ZERO
|
|
8
|
-
|
|
9
|
-
equals(other: Point) {
|
|
10
|
-
return this.x === other.x && this.y === other.y
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
addSelf(value: Point): Point {
|
|
14
|
-
const nor = value.add(new Point(this.x, this.y))
|
|
15
|
-
this.x = nor.x
|
|
16
|
-
this.y = nor.y
|
|
17
|
-
return nor
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public cross(other: Vec2) {
|
|
21
|
-
return this.x * other.y - this.y * other.x
|
|
22
|
-
}
|
|
23
|
-
public signAngle(other: Vec2) {
|
|
24
|
-
const angle = this.angle(other)
|
|
25
|
-
return this.cross(other) < 0 ? -angle : angle
|
|
26
|
-
}
|
|
27
|
-
public lengthSqr() {
|
|
28
|
-
return this.x * this.x + this.y * this.y
|
|
29
|
-
}
|
|
30
|
-
public dot(other: Vec2) {
|
|
31
|
-
return this.x * other.x + this.y * other.y
|
|
32
|
-
}
|
|
33
|
-
public angle(other: Vec2) {
|
|
34
|
-
const magSqr1 = this.lengthSqr()
|
|
35
|
-
const magSqr2 = other.lengthSqr()
|
|
36
|
-
|
|
37
|
-
if (magSqr1 === 0 || magSqr2 === 0) {
|
|
38
|
-
console.warn('Cant get angle between zero vector')
|
|
39
|
-
return 0.0
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const dot = this.dot(other)
|
|
43
|
-
let theta = dot / Math.sqrt(magSqr1 * magSqr2)
|
|
44
|
-
theta = clamp(theta, -1.0, 1.0)
|
|
45
|
-
return Math.acos(theta)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
export type Vec2 = _Vec2
|
|
49
|
-
export function Vec2(x = 0, y = 0): Vec2 {
|
|
50
|
-
return new _Vec2(x, y)
|
|
51
|
-
}
|
|
52
|
-
Vec2.ZERO = Object.freeze(Vec2(0, 0))
|
package/src/core/decorator.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { EnhancedComponent } from '../components/EnhancedComponent'
|
|
2
|
-
import { GameWorld } from '../gworld'
|
|
3
|
-
|
|
4
|
-
export class NoRenderComponentX extends EnhancedComponent {
|
|
5
|
-
static hasRender = false
|
|
6
|
-
static create(data?: any) {
|
|
7
|
-
return new this(data)
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class ComponentX extends EnhancedComponent {
|
|
12
|
-
static create(data?: any) {
|
|
13
|
-
const world = GameWorld.Instance
|
|
14
|
-
const root = world.entities.create()
|
|
15
|
-
const comp = root.assign(new this(data))
|
|
16
|
-
return comp
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/gworld.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Constructor, System, World } from 'entityx-ts'
|
|
2
|
-
|
|
3
|
-
export class GameWorld extends World {
|
|
4
|
-
listUpdate: (System | Constructor<System>)[] = []
|
|
5
|
-
update(dt: number) {
|
|
6
|
-
this.listUpdate.forEach((system: any) => {
|
|
7
|
-
this.systems.update(system, dt)
|
|
8
|
-
})
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
private static _instance: GameWorld
|
|
12
|
-
|
|
13
|
-
public static get Instance() {
|
|
14
|
-
// Do you need arguments? Make it a regular static method instead.
|
|
15
|
-
return this._instance || (this._instance = new this())
|
|
16
|
-
}
|
|
17
|
-
}
|