@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,63 @@
|
|
|
1
|
+
import { Container, Graphics, Point, Sprite, Texture } 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.fill(0xffffff)
|
|
17
|
+
this.rect(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.fill(0xffffff)
|
|
25
|
+
if (this.mode === LoadingBarMode.BAR) {
|
|
26
|
+
const spriteComp = this.spriteComp
|
|
27
|
+
this.rect(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
|
+
}
|
|
34
|
+
|
|
35
|
+
export class ProgressTimer extends Container {
|
|
36
|
+
graphics: Graphics
|
|
37
|
+
spriteComp: Sprite
|
|
38
|
+
mode: LoadingBarMode
|
|
39
|
+
fillCenter = new Point(0.5, 0.5)
|
|
40
|
+
constructor(mode: LoadingBarMode, spriteFrame: string) {
|
|
41
|
+
super()
|
|
42
|
+
const texture = Texture.from(spriteFrame)
|
|
43
|
+
this.spriteComp = Sprite.from(texture)
|
|
44
|
+
this.graphics = new Graphics()
|
|
45
|
+
this.mode = mode || LoadingBarMode.BAR
|
|
46
|
+
this.graphics.fill(0xffffff)
|
|
47
|
+
this.graphics.rect(0, 0, this.spriteComp.width, this.spriteComp.height)
|
|
48
|
+
this.spriteComp.mask = this.graphics
|
|
49
|
+
this.addChild(this.graphics)
|
|
50
|
+
this.addChild(this.spriteComp)
|
|
51
|
+
// this.graphics.x = -this.spriteComp.width * this.fillCenter.x
|
|
52
|
+
// this.graphics.y = -this.spriteComp.height * this.fillCenter.y
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
set progress(val: number) {
|
|
56
|
+
this.graphics.clear()
|
|
57
|
+
if (this.mode === LoadingBarMode.BAR) {
|
|
58
|
+
this.graphics.rect(0, 0, this.spriteComp.width * val, this.spriteComp.height)
|
|
59
|
+
// console.log('new length', this.width)
|
|
60
|
+
this.graphics.fill(0xffffff)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { NodeComp } from "../components/NodeComp"
|
|
2
|
+
|
|
3
|
+
export class NodePool {
|
|
4
|
+
items: NodeComp[] = []
|
|
5
|
+
|
|
6
|
+
put(node: NodeComp) {
|
|
7
|
+
if (node) {
|
|
8
|
+
node.active = false
|
|
9
|
+
node.removeFromParent()
|
|
10
|
+
this.items.push(node)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get(): NodeComp {
|
|
15
|
+
const node = this.items.pop()
|
|
16
|
+
node.active = true
|
|
17
|
+
return node
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
size() {
|
|
21
|
+
return this.items.length
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
clear() {
|
|
25
|
+
this.items.forEach((node) => node.destroy())
|
|
26
|
+
this.items.length = 0
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/core/Size.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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/math.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DEG_TO_RAD, RAD_TO_DEG } from 'pixi.js'
|
|
2
|
+
|
|
3
|
+
export function randomRangeInt(minInclude: Integer, maxExclude: Integer) {
|
|
4
|
+
return Math.round(Math.random() * (maxExclude - minInclude - 1)) + minInclude
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function degreesToRadians(deg: Float) {
|
|
8
|
+
return DEG_TO_RAD * deg
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function radiansToDegrees(rad: Float) {
|
|
12
|
+
return RAD_TO_DEG * rad
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ComponentX } from "../components/BaseComponent"
|
|
2
|
+
interface DragonBonesData {
|
|
3
|
+
atlas: string
|
|
4
|
+
skeleton: string
|
|
5
|
+
texture: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface DragonBonesProps {
|
|
9
|
+
data: DragonBonesData
|
|
10
|
+
skin?: string
|
|
11
|
+
animation?: string
|
|
12
|
+
playTimes?: number
|
|
13
|
+
timeScale?: number
|
|
14
|
+
onAnimationStart?: (event: { name: string }) => void
|
|
15
|
+
onAnimationEnd?: (event: { name: string }) => void
|
|
16
|
+
onAnimationComplete?: (event: { name: string }) => void
|
|
17
|
+
}
|
|
18
|
+
export class DragonBones extends ComponentX<DragonBonesProps> {
|
|
19
|
+
|
|
20
|
+
setAnimation(name: string, playTimes = 0) {
|
|
21
|
+
const skel: any = this.node.instance
|
|
22
|
+
if (skel.animation) {
|
|
23
|
+
skel.animation.play(name, playTimes)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
setSkeletonData(data: string) {
|
|
28
|
+
const skel: any = this.node.instance
|
|
29
|
+
const atlas = data.replace('.json', '.atlas')
|
|
30
|
+
skel.initWithArgs(data, atlas, this.node.scale)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PixiFactory } from 'dragonbones-pixijs';
|
|
2
|
+
import { EntityManager, EventManager, EventTypes, System } from 'entityx-ts';
|
|
3
|
+
|
|
4
|
+
import { Assets } from 'pixi.js';
|
|
5
|
+
import { GameWorld } from '../base';
|
|
6
|
+
import { NodeComp } from '../components/NodeComp';
|
|
7
|
+
import { DragonBones } from './DragonBonesComponent';
|
|
8
|
+
|
|
9
|
+
export class DragonBonesSystem implements System {
|
|
10
|
+
configure(event_manager: EventManager<GameWorld>) {
|
|
11
|
+
event_manager.subscribe(EventTypes.ComponentAdded, DragonBones, ({ entity, component }) => {
|
|
12
|
+
const { data, animation, playTimes = 0 } = component.props
|
|
13
|
+
const { skeleton, atlas, texture } = data
|
|
14
|
+
const skeletonAsset = Assets.get(skeleton)
|
|
15
|
+
const atlasAsset = Assets.get(atlas)
|
|
16
|
+
const textureAsset = Assets.get(texture)
|
|
17
|
+
const armatureName = skeletonAsset.armature[0].name
|
|
18
|
+
// console.log(skeletonAsset, textureAsset, atlasAsset)
|
|
19
|
+
const factory = PixiFactory.factory;
|
|
20
|
+
factory.parseDragonBonesData(skeletonAsset);
|
|
21
|
+
factory.parseTextureAtlasData(atlasAsset, textureAsset)
|
|
22
|
+
const armatureDisplay = factory.buildArmatureDisplay(armatureName)!;
|
|
23
|
+
armatureDisplay.debugDraw = false;
|
|
24
|
+
const node = armatureDisplay;
|
|
25
|
+
if (animation) {
|
|
26
|
+
armatureDisplay.animation.play(animation, playTimes);
|
|
27
|
+
}
|
|
28
|
+
component.node = entity.assign(new NodeComp(node, entity))
|
|
29
|
+
})
|
|
30
|
+
// event_manager.subscribe(EventTypes.ComponentRemoved, DragonBones, ({ }) => { })
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
update(entities: EntityManager, events: EventManager<GameWorld>, dt: number) {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GameWorld } from '..'
|
|
2
|
+
import { DragonBonesSystem } from './DragonBonesSystem'
|
|
3
|
+
|
|
4
|
+
export * from './DragonBonesComponent'
|
|
5
|
+
export * from './DragonBonesSystem'
|
|
6
|
+
|
|
7
|
+
export function setupDragonBones() {
|
|
8
|
+
GameWorld.Instance.systems.add(DragonBonesSystem)
|
|
9
|
+
GameWorld.Instance.listUpdate.push(DragonBonesSystem)
|
|
10
|
+
GameWorld.Instance.systems.configureOnce(DragonBonesSystem)
|
|
11
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { CheckBox, CheckBoxOptions, Input, List, ProgressBar, RadioGroup, Slider, SliderOptions } from '@pixi/ui'
|
|
2
|
+
import { Assets, Container, FillInput, Point, Text } from 'pixi.js'
|
|
3
|
+
|
|
4
|
+
import { ComponentX, NoRenderComponentX } from '../components/BaseComponent'
|
|
5
|
+
import { Color4B } from '../core/Color'
|
|
6
|
+
import { LoadingBarMode, ProgressTimer } from '../core/LoadingBar'
|
|
7
|
+
|
|
8
|
+
export const FillType = {
|
|
9
|
+
HORIZONTAL: 0,
|
|
10
|
+
VERTICAL: 1,
|
|
11
|
+
RADIAL: 2,
|
|
12
|
+
}
|
|
13
|
+
type Keys = keyof typeof FillType
|
|
14
|
+
type Values = (typeof FillType)[Keys]
|
|
15
|
+
|
|
16
|
+
interface ButtonCompProps {
|
|
17
|
+
normalImage?: string
|
|
18
|
+
selectedImage?: string
|
|
19
|
+
disableImage?: string
|
|
20
|
+
zoomScale?: number
|
|
21
|
+
onPress: (target: ButtonComp) => void
|
|
22
|
+
}
|
|
23
|
+
export class ButtonComp extends NoRenderComponentX<ButtonCompProps> {
|
|
24
|
+
// setOnPress(cb: (target: ButtonComp) => void) {
|
|
25
|
+
// this.onPress = cb
|
|
26
|
+
// }
|
|
27
|
+
|
|
28
|
+
set enabled(val) {
|
|
29
|
+
this.node.instance.interactive = val
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class ProgressBarComp extends ComponentX<{}, ProgressBar> {
|
|
34
|
+
mode = LoadingBarMode.BAR
|
|
35
|
+
isReverse: boolean
|
|
36
|
+
bg: string
|
|
37
|
+
fill: string
|
|
38
|
+
|
|
39
|
+
get progress() {
|
|
40
|
+
return this.node.instance.progress
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set progress(val: number) {
|
|
44
|
+
this.node.instance.progress = val
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
interface LabelCompProps {
|
|
48
|
+
font?: string
|
|
49
|
+
string?: string
|
|
50
|
+
size?: number
|
|
51
|
+
}
|
|
52
|
+
export class LabelComp extends ComponentX<LabelCompProps, Text> {
|
|
53
|
+
|
|
54
|
+
get string() {
|
|
55
|
+
return this.props.string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
set string(val: string) {
|
|
59
|
+
this.props.string = val
|
|
60
|
+
if (!this.node) return
|
|
61
|
+
if (this.node.instance instanceof Text) {
|
|
62
|
+
this.node.instance.text = val
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get size() {
|
|
67
|
+
return this.props.size
|
|
68
|
+
}
|
|
69
|
+
set size(val) {
|
|
70
|
+
this.props.size = val
|
|
71
|
+
if (!this.node) return
|
|
72
|
+
if (this.node.instance instanceof Text) {
|
|
73
|
+
this.node.instance.style.fontSize = val
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get font() {
|
|
78
|
+
return this.props.font
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
set font(val: string) {
|
|
82
|
+
this.props.font = val
|
|
83
|
+
if (!this.node) return
|
|
84
|
+
// console.log('set font', val, Assets.get(val))
|
|
85
|
+
if (this.node.instance instanceof Text) {
|
|
86
|
+
if (Assets.get(val)) this.node.instance.style.fontFamily = Assets.get(val).family
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface ScrollViewProps {
|
|
92
|
+
width: number
|
|
93
|
+
height: number
|
|
94
|
+
}
|
|
95
|
+
export class ScrollView extends NoRenderComponentX<ScrollViewProps> {
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export class BlockInputEventsComp extends NoRenderComponentX { }
|
|
100
|
+
|
|
101
|
+
interface ProgressTimerProps {
|
|
102
|
+
spriteFrame: string
|
|
103
|
+
fillType?: number
|
|
104
|
+
fillRange?: number
|
|
105
|
+
fillCenter?: Point
|
|
106
|
+
isReverse?: boolean
|
|
107
|
+
}
|
|
108
|
+
export class ProgressTimerComp extends ComponentX<ProgressTimerProps & { $ref?: ProgressTimerComp }, ProgressTimer> {
|
|
109
|
+
|
|
110
|
+
getFillRange() {
|
|
111
|
+
return this.node.instance.progress
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setFillStart(val: number) {
|
|
115
|
+
this.node.instance.fillCenter.x = val
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
setFillRange(val: number) {
|
|
119
|
+
// console.log('setFillRange', this.node.instance);
|
|
120
|
+
this.node.instance.progress = val
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
interface LabelOutlineCompProps {
|
|
125
|
+
color: Color4B
|
|
126
|
+
width: number
|
|
127
|
+
}
|
|
128
|
+
export class LabelOutlineComp extends NoRenderComponentX<LabelOutlineCompProps> {
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface LabelShadowCompProps {
|
|
133
|
+
color: Color4B
|
|
134
|
+
blur: number
|
|
135
|
+
offset?: Point
|
|
136
|
+
}
|
|
137
|
+
export class LabelShadowComp extends NoRenderComponentX<LabelShadowCompProps> {
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export class InputComp extends ComponentX<{}, Input> {
|
|
142
|
+
bg: string
|
|
143
|
+
fill: FillInput
|
|
144
|
+
font: string
|
|
145
|
+
string: string
|
|
146
|
+
size = 64
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export class ListComp extends ComponentX<{}, List> {
|
|
150
|
+
}
|
|
151
|
+
export class SliderComp extends ComponentX<{}, Slider> {
|
|
152
|
+
bg: string
|
|
153
|
+
fill: SliderOptions['fill']
|
|
154
|
+
slider: Container
|
|
155
|
+
}
|
|
156
|
+
export class RadioGroupComp extends ComponentX<{}, RadioGroup> {
|
|
157
|
+
}
|
|
158
|
+
export class CheckBoxComp extends ComponentX<{ style: CheckBoxOptions['style'] }, CheckBox> {
|
|
159
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Button, CheckBox, List, RadioGroup, ScrollBox } from '@pixi/ui'
|
|
2
|
+
import {
|
|
3
|
+
EventManager,
|
|
4
|
+
EventTypes,
|
|
5
|
+
System
|
|
6
|
+
} from 'entityx-ts'
|
|
7
|
+
import { callFunc, easeBackIn, scaleTo, sequence } from 'pixi-action-ease'
|
|
8
|
+
import { Text } from 'pixi.js'
|
|
9
|
+
|
|
10
|
+
import { NodeComp } from '..'
|
|
11
|
+
import { GameWorld } from '../base'
|
|
12
|
+
import { LoadingBarMode, ProgressTimer } from '../core/LoadingBar'
|
|
13
|
+
import { ButtonComp, CheckBoxComp, LabelComp, LabelOutlineComp, LabelShadowComp, ListComp, ProgressTimerComp, RadioGroupComp, ScrollView } from './GUIComponent'
|
|
14
|
+
|
|
15
|
+
export class GUISystem implements System {
|
|
16
|
+
defaultFont: string
|
|
17
|
+
configure(event_manager: EventManager<GameWorld>) {
|
|
18
|
+
event_manager.subscribe(EventTypes.ComponentAdded, ButtonComp, ({ entity, component }) => {
|
|
19
|
+
const nodeComp = entity.getComponent(NodeComp)
|
|
20
|
+
// const { normalImage, selectedImage, disableImage, texType, zoomScale } = button
|
|
21
|
+
// console.log('onPress.ButtonComp', component)
|
|
22
|
+
const button = new Button(nodeComp.instance)
|
|
23
|
+
// node.setZoomScale(zoomScale - 1)
|
|
24
|
+
component.node = nodeComp
|
|
25
|
+
// component.node = entity.assign(new NodeComp(node, entity))
|
|
26
|
+
button.onPress.connect(() => {
|
|
27
|
+
// console.log('onPress.connect')
|
|
28
|
+
const scale = scaleTo(0.5, 1.2)
|
|
29
|
+
const scaleDown = scaleTo(0.5, 1)
|
|
30
|
+
const seq = sequence(
|
|
31
|
+
scale,
|
|
32
|
+
callFunc(() => {
|
|
33
|
+
if (Object.prototype.hasOwnProperty.call(component.props, 'onPress')) {
|
|
34
|
+
component.props.onPress(component)
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
scaleDown,
|
|
38
|
+
)
|
|
39
|
+
const ease = easeBackIn(seq)
|
|
40
|
+
component.node.runAction(ease)
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
// event_manager.subscribe(EventTypes.ComponentAdded, ProgressBarComp, ({ entity, component }) => {
|
|
44
|
+
// const { progress = 1, bg, fill } = component.props
|
|
45
|
+
// const node = new ProgressBar({ bg, fill, progress })
|
|
46
|
+
// component.node = entity.assign(new NodeComp(node, entity))
|
|
47
|
+
// })
|
|
48
|
+
event_manager.subscribe(EventTypes.ComponentAdded, ProgressTimerComp, ({ entity, component }) => {
|
|
49
|
+
// console.log(component, '.progress')
|
|
50
|
+
const { spriteFrame, fillCenter } = component.props
|
|
51
|
+
const node = new ProgressTimer(LoadingBarMode.BAR, spriteFrame)
|
|
52
|
+
if (fillCenter) {
|
|
53
|
+
node.fillCenter = fillCenter
|
|
54
|
+
}
|
|
55
|
+
component.node = entity.assign(new NodeComp(node, entity))
|
|
56
|
+
})
|
|
57
|
+
event_manager.subscribe(EventTypes.ComponentAdded, ScrollView, ({ entity, component }) => {
|
|
58
|
+
const { width, height } = component.props
|
|
59
|
+
const view = new ScrollBox({ width, height })
|
|
60
|
+
component.node = entity.assign(new NodeComp(view, entity))
|
|
61
|
+
})
|
|
62
|
+
event_manager.subscribe(EventTypes.ComponentAdded, ListComp, ({ entity, component }) => {
|
|
63
|
+
const view = new List()
|
|
64
|
+
component.node = entity.assign(new NodeComp(view, entity))
|
|
65
|
+
})
|
|
66
|
+
// event_manager.subscribe(EventTypes.ComponentAdded, SliderComp, ({ entity, component }) => {
|
|
67
|
+
// const { bg, slider, fill } = component.props
|
|
68
|
+
// const view = new Slider({ bg, fill, slider })
|
|
69
|
+
// component.node = entity.assign(new NodeComp(view, entity))
|
|
70
|
+
// })
|
|
71
|
+
event_manager.subscribe(EventTypes.ComponentAdded, RadioGroupComp, ({ entity, component }) => {
|
|
72
|
+
const view = new RadioGroup()
|
|
73
|
+
component.node = entity.assign(new NodeComp(view, entity))
|
|
74
|
+
})
|
|
75
|
+
event_manager.subscribe(EventTypes.ComponentAdded, CheckBoxComp, ({ entity, component }) => {
|
|
76
|
+
const { style } = component.props
|
|
77
|
+
const view = new CheckBox({ style })
|
|
78
|
+
component.node = entity.assign(new NodeComp(view, entity))
|
|
79
|
+
})
|
|
80
|
+
// event_manager.subscribe(EventTypes.ComponentAdded, InputComp, ({ entity, component }) => {
|
|
81
|
+
// const { bg, size = 48, fill } = component.props
|
|
82
|
+
// const view = new Input({ bg, textStyle: { fontSize: size, fill } })
|
|
83
|
+
// component.node = entity.assign(new NodeComp(view, entity))
|
|
84
|
+
// })
|
|
85
|
+
event_manager.subscribe(EventTypes.ComponentAdded, LabelComp, ({ entity, component }) => {
|
|
86
|
+
// console.log('ComponentAddedEvent LabelComp', component)
|
|
87
|
+
const node = new Text()
|
|
88
|
+
// node.texture.rotate = 8
|
|
89
|
+
node.style.fill = '#fff'
|
|
90
|
+
component.node = entity.assign(new NodeComp(node, entity))
|
|
91
|
+
const { string = '', font = this.defaultFont, size = 64 } = component.props
|
|
92
|
+
if (font) component.font = (font)
|
|
93
|
+
component.size = (size)
|
|
94
|
+
component.string = (string)
|
|
95
|
+
})
|
|
96
|
+
event_manager.subscribe(EventTypes.ComponentAdded, LabelOutlineComp, ({ entity, component }) => {
|
|
97
|
+
const { color, width } = component.props
|
|
98
|
+
const node = entity.getComponent(NodeComp)
|
|
99
|
+
if (node.instance instanceof Text) {
|
|
100
|
+
node.instance.style.stroke = { color, width }
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
event_manager.subscribe(EventTypes.ComponentAdded, LabelShadowComp, ({ entity, component }) => {
|
|
104
|
+
const { color, blur, offset } = component.props
|
|
105
|
+
const node = entity.getComponent(NodeComp)
|
|
106
|
+
if (node.instance instanceof Text) {
|
|
107
|
+
node.instance.style.dropShadow = { color, blur, alpha: 1, angle: 0, distance: 0 }
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
// event_manager.subscribe(EventTypes.ComponentAdded, BlockInputEventsComp), this);
|
|
112
|
+
}
|
|
113
|
+
// update() {
|
|
114
|
+
// throw new Error('Method not implemented.');
|
|
115
|
+
// }
|
|
116
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Constructor, EntityManager, EventManager, EventReceive, EventTypes, System } from 'entityx-ts';
|
|
2
|
+
import { Point } from 'pixi.js';
|
|
3
|
+
import { EnhancedComponent, GameWorld } from '../base';
|
|
4
|
+
|
|
5
|
+
import { NodeComp } from '../components/NodeComp';
|
|
6
|
+
|
|
7
|
+
export function v2(x: number | { x: number, y: number } = 0, y = 0) {
|
|
8
|
+
if (typeof x === 'object' && 'x' in x && 'y' in x) {
|
|
9
|
+
return new Point(x.x, x.y)
|
|
10
|
+
}
|
|
11
|
+
return new Point(x, y)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getDistance(point1: Point, point2: Point) {
|
|
15
|
+
const dx = point2.x - point1.x;
|
|
16
|
+
const dy = point2.y - point1.y;
|
|
17
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function registerSystem<T extends EnhancedComponent<any>>(component: Constructor<T>) {
|
|
21
|
+
if (GameWorld.Instance.systems.isRegistered(`${component.name}System`)) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
class NewSystem implements System {
|
|
25
|
+
configure(event_manager: EventManager<GameWorld>) {
|
|
26
|
+
console.log('configure registerSystem core', component.name)
|
|
27
|
+
event_manager.subscribe(EventTypes.ComponentAdded, component, (event: EventReceive<T>) => {
|
|
28
|
+
// console.log('receiveComponentAddedEvent', event)
|
|
29
|
+
const ett = event.entity
|
|
30
|
+
const newComp = ett.getComponent<T>(component)
|
|
31
|
+
newComp.node = ett.getComponent(NodeComp)
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
update(entities: EntityManager, events: EventManager<GameWorld>, dt: number) {
|
|
36
|
+
for (const entt of entities.entities_with_components(component)) {
|
|
37
|
+
const comp = entt.getComponent(component)
|
|
38
|
+
// console.log('comp', comp.constructor.name, typeof comp['update'] === 'function')
|
|
39
|
+
if (comp.node.active && typeof comp['update'] === 'function') {
|
|
40
|
+
comp['update'](dt)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
Object.defineProperty(NewSystem, 'name', { value: `${component.name}System` })
|
|
46
|
+
GameWorld.Instance.systems.add(NewSystem)
|
|
47
|
+
GameWorld.Instance.systems.configureOnce(NewSystem)
|
|
48
|
+
GameWorld.Instance.listUpdate.push(NewSystem)
|
|
49
|
+
return NewSystem
|
|
50
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from 'pixi-action-ease'
|
|
2
|
+
export * from 'pixi.js'
|
|
3
|
+
export { Vec2 } from 'planck'
|
|
4
|
+
export * from './app'
|
|
5
|
+
export * from './base'
|
|
6
|
+
export * from './collider'
|
|
7
|
+
export * from './collider/helper/Intersection'
|
|
8
|
+
export * from './components/BaseComponent'
|
|
9
|
+
export * from './components/NodeComp'
|
|
10
|
+
export * from './components/Scene'
|
|
11
|
+
export * from './core/Color'
|
|
12
|
+
export * from './core/director'
|
|
13
|
+
export * from './core/math'
|
|
14
|
+
export * from './core/NodePool'
|
|
15
|
+
export * from './dragonbones'
|
|
16
|
+
export * from './gui/GUIComponent'
|
|
17
|
+
export * from './gui/GUISystem'
|
|
18
|
+
export * from './helper/utils'
|
|
19
|
+
export * from './norender/NoRenderComponent'
|
|
20
|
+
export * from './render/RenderComponent'
|
|
21
|
+
export * from './render/RenderSystem'
|
|
22
|
+
export * from './richtext'
|
|
23
|
+
export * from './spine'
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { FederatedPointerEvent } from 'pixi.js'
|
|
2
|
+
import { NoRenderComponentX } from '../components/BaseComponent'
|
|
3
|
+
import { EventCallbackType, EventMap, NodeComp } from '../components/NodeComp'
|
|
4
|
+
|
|
5
|
+
// export class Touch extends FederatedPointerEvent {
|
|
6
|
+
// declare getLocation: () => Vec2
|
|
7
|
+
// declare getDelta: () => Vec2
|
|
8
|
+
// }
|
|
9
|
+
|
|
10
|
+
export type TouchEventCallback = (touch?: FederatedPointerEvent, node?: NodeComp) => void
|
|
11
|
+
|
|
12
|
+
export class EventRegister extends NoRenderComponentX {
|
|
13
|
+
events: EventMap = {}
|
|
14
|
+
|
|
15
|
+
on(name: string, callback: EventCallbackType, target?: any) {
|
|
16
|
+
const bound = target ? callback.bind(target) : callback
|
|
17
|
+
if (this.events[name]) {
|
|
18
|
+
this.events[name].push(bound)
|
|
19
|
+
} else {
|
|
20
|
+
this.events[name] = [bound]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
off(name: string, callback?: EventCallbackType, target?: any)
|
|
25
|
+
off(name: string) {
|
|
26
|
+
this.events[name] = undefined
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
emit(name: string, ...params: any) {
|
|
30
|
+
if (this.events[name]) {
|
|
31
|
+
this.events[name].forEach((fc) => fc(...params))
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface TouchEventProps {
|
|
37
|
+
onTouchStart?: TouchEventCallback
|
|
38
|
+
onTouchMove?: TouchEventCallback
|
|
39
|
+
onTouchEnd?: TouchEventCallback
|
|
40
|
+
onTouchCancel?: TouchEventCallback
|
|
41
|
+
}
|
|
42
|
+
export class TouchEventRegister extends NoRenderComponentX<TouchEventProps> {
|
|
43
|
+
listener: EventListener
|
|
44
|
+
touch: Touch
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface ExtraDataProps {
|
|
48
|
+
key: string
|
|
49
|
+
value: any
|
|
50
|
+
}
|
|
51
|
+
export class ExtraDataComp extends NoRenderComponentX<ExtraDataProps> {
|
|
52
|
+
data: { [key: string]: any } = {}
|
|
53
|
+
|
|
54
|
+
getData<T>(key: string): T {
|
|
55
|
+
return this.data[key]
|
|
56
|
+
}
|
|
57
|
+
setData<T>(key: string, val: T) {
|
|
58
|
+
this.data[key] = val
|
|
59
|
+
}
|
|
60
|
+
}
|