kiwiengine 0.5.4 → 0.5.6
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/examples/auto-battle/objects/character.ts +1 -1
- package/examples/battle-benchmark-matterjs/objects/character.ts +1 -1
- package/examples/battle-benchmark-separation/objects/character.ts +1 -1
- package/examples/battle-benchmark-separation2/objects/character.ts +1 -1
- package/examples/simple-battle/objects/character.ts +1 -1
- package/lib/asset/preload.js +21 -19
- package/lib/asset/preload.js.map +1 -1
- package/lib/dom/dom-animated-sprite.js.map +1 -1
- package/lib/dom/dom-game-object.js.map +1 -1
- package/lib/dom/dom-sprite.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/node/core/game-object.js.map +1 -1
- package/lib/node/core/renderable.js +2 -0
- package/lib/node/core/renderable.js.map +1 -1
- package/lib/node/core/transformable.js +5 -1
- package/lib/node/core/transformable.js.map +1 -1
- package/lib/node/ext/animated-sprite.js +16 -15
- package/lib/node/ext/animated-sprite.js.map +1 -1
- package/lib/node/ext/bitmap-text.js +29 -19
- package/lib/node/ext/bitmap-text.js.map +1 -1
- package/lib/node/ext/spine.js.map +1 -1
- package/lib/node/ext/sprite.js.map +1 -1
- package/lib/node/physics/physics-object.js +8 -1
- package/lib/node/physics/physics-object.js.map +1 -1
- package/lib/node/physics/physics-world.js.map +1 -1
- package/lib/types/asset/preload.d.ts +2 -0
- package/lib/types/asset/preload.d.ts.map +1 -1
- package/lib/types/dom/dom-animated-sprite.d.ts +1 -1
- package/lib/types/dom/dom-animated-sprite.d.ts.map +1 -1
- package/lib/types/dom/dom-game-object.d.ts +1 -1
- package/lib/types/dom/dom-game-object.d.ts.map +1 -1
- package/lib/types/dom/dom-sprite.d.ts +1 -1
- package/lib/types/dom/dom-sprite.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/node/core/game-object.d.ts +1 -1
- package/lib/types/node/core/game-object.d.ts.map +1 -1
- package/lib/types/node/core/renderable.d.ts +2 -0
- package/lib/types/node/core/renderable.d.ts.map +1 -1
- package/lib/types/node/core/transformable.d.ts +3 -0
- package/lib/types/node/core/transformable.d.ts.map +1 -1
- package/lib/types/node/ext/animated-sprite.d.ts +1 -1
- package/lib/types/node/ext/animated-sprite.d.ts.map +1 -1
- package/lib/types/node/ext/bitmap-text.d.ts +4 -2
- package/lib/types/node/ext/bitmap-text.d.ts.map +1 -1
- package/lib/types/node/ext/spine.d.ts +1 -1
- package/lib/types/node/ext/spine.d.ts.map +1 -1
- package/lib/types/node/ext/sprite.d.ts +1 -1
- package/lib/types/node/ext/sprite.d.ts.map +1 -1
- package/lib/types/node/physics/physics-object.d.ts +2 -1
- package/lib/types/node/physics/physics-object.d.ts.map +1 -1
- package/lib/types/node/physics/physics-world.d.ts +1 -1
- package/lib/types/node/physics/physics-world.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/asset/preload.ts +18 -16
- package/src/dom/dom-animated-sprite.ts +1 -1
- package/src/dom/dom-game-object.ts +1 -1
- package/src/dom/dom-sprite.ts +1 -1
- package/src/index.ts +1 -1
- package/src/node/core/game-object.ts +1 -1
- package/src/node/core/renderable.ts +3 -0
- package/src/node/core/transformable.ts +6 -1
- package/src/node/ext/animated-sprite.ts +18 -17
- package/src/node/ext/bitmap-text.ts +37 -21
- package/src/node/ext/spine.ts +1 -1
- package/src/node/ext/sprite.ts +1 -1
- package/src/node/physics/physics-object.ts +9 -2
- package/src/node/physics/physics-world.ts +1 -1
|
@@ -69,4 +69,7 @@ export abstract class RenderableNode<C extends PixiContainer, E extends EventMap
|
|
|
69
69
|
|
|
70
70
|
set tint(t) { this._pixiContainer.tint = t }
|
|
71
71
|
get tint() { return this._pixiContainer.tint }
|
|
72
|
+
|
|
73
|
+
hide() { this._pixiContainer.visible = false }
|
|
74
|
+
show() { this._pixiContainer.visible = true }
|
|
72
75
|
}
|
|
@@ -13,6 +13,7 @@ export type TransformableNodeOptions = {
|
|
|
13
13
|
pivotX?: number
|
|
14
14
|
pivotY?: number
|
|
15
15
|
rotation?: number
|
|
16
|
+
drawOrder?: number
|
|
16
17
|
|
|
17
18
|
alpha?: number
|
|
18
19
|
layer?: string
|
|
@@ -38,6 +39,7 @@ export abstract class TransformableNode<C extends PixiContainer, E extends Event
|
|
|
38
39
|
if (options.pivotY !== undefined) this.pivotY = options.pivotY
|
|
39
40
|
if (options.rotation !== undefined) this.rotation = options.rotation
|
|
40
41
|
if (options.alpha !== undefined) this.alpha = options.alpha
|
|
42
|
+
if (options.drawOrder !== undefined) this.drawOrder = options.drawOrder
|
|
41
43
|
|
|
42
44
|
this.#layer = options.layer
|
|
43
45
|
this.#useYSort = options.useYSort ?? false
|
|
@@ -75,7 +77,7 @@ export abstract class TransformableNode<C extends PixiContainer, E extends Event
|
|
|
75
77
|
} else {
|
|
76
78
|
const lt = this.localTransform
|
|
77
79
|
pc.position.set(lt.x, lt.y)
|
|
78
|
-
if (this.#useYSort)
|
|
80
|
+
if (this.#useYSort) this.drawOrder = lt.y
|
|
79
81
|
pc.pivot.set(lt.pivotX, lt.pivotY)
|
|
80
82
|
pc.scale.set(lt.scaleX, lt.scaleY)
|
|
81
83
|
pc.rotation = lt.rotation
|
|
@@ -108,4 +110,7 @@ export abstract class TransformableNode<C extends PixiContainer, E extends Event
|
|
|
108
110
|
|
|
109
111
|
set rotation(v) { this.localTransform.rotation = v }
|
|
110
112
|
get rotation() { return this.localTransform.rotation }
|
|
113
|
+
|
|
114
|
+
set drawOrder(v) { this._pixiContainer.zIndex = v }
|
|
115
|
+
get drawOrder() { return this._pixiContainer.zIndex }
|
|
111
116
|
}
|
|
@@ -10,7 +10,7 @@ export type AnimatedSpriteNodeOptions = {
|
|
|
10
10
|
animation: string
|
|
11
11
|
} & GameObjectOptions
|
|
12
12
|
|
|
13
|
-
export class AnimatedSpriteNode<E extends EventMap =
|
|
13
|
+
export class AnimatedSpriteNode<E extends EventMap = {}> extends GameObject<E & {
|
|
14
14
|
animationend: (animation: string) => void
|
|
15
15
|
}> {
|
|
16
16
|
#src: string
|
|
@@ -46,25 +46,26 @@ export class AnimatedSpriteNode<E extends EventMap = EventMap> extends GameObjec
|
|
|
46
46
|
this.#sprite?.destroy()
|
|
47
47
|
this.#sprite = undefined
|
|
48
48
|
|
|
49
|
-
if (this.#sheet)
|
|
50
|
-
if (!this.#sheet.animations[this.#animation]) {
|
|
51
|
-
console.error(`Animation not found: ${this.#animation}`)
|
|
52
|
-
return
|
|
53
|
-
}
|
|
49
|
+
if (!this.#sheet) return
|
|
54
50
|
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
if (!this.#sheet.animations[this.#animation]) {
|
|
52
|
+
console.error(`Animation not found: ${this.#animation}`)
|
|
53
|
+
return
|
|
54
|
+
}
|
|
57
55
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
s.animationSpeed = a.fps / 60
|
|
61
|
-
s.play()
|
|
62
|
-
s.onLoop = () => (this as any).emit('animationend', this.#animation)
|
|
63
|
-
s.onComplete = () => (this as any).emit('animationend', this.#animation)
|
|
56
|
+
const a = this.#atlas.animations[this.#animation]
|
|
57
|
+
const s = new PixiAnimatedSprite(this.#sheet.animations[this.#animation])
|
|
64
58
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
s.anchor.set(0.5, 0.5)
|
|
60
|
+
s.zIndex = -999999
|
|
61
|
+
s.loop = a.loop
|
|
62
|
+
s.animationSpeed = a.fps / 60
|
|
63
|
+
s.play()
|
|
64
|
+
s.onLoop = () => (this as any).emit('animationend', this.#animation)
|
|
65
|
+
s.onComplete = () => (this as any).emit('animationend', this.#animation)
|
|
66
|
+
|
|
67
|
+
this._pixiContainer.addChild(s)
|
|
68
|
+
this.#sprite = s
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
set src(src) {
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { EventMap } from '@webtaku/event-emitter'
|
|
2
2
|
import { Rectangle as PixiRectangle, Sprite as PixiSprite, Texture as PixiTexture } from 'pixi.js'
|
|
3
3
|
import { bitmapFontLoader } from '../../asset/loaders/bitmap-font'
|
|
4
|
+
import { BitmapFont } from '../../types/bitmap-font'
|
|
4
5
|
import { GameObject, GameObjectOptions } from '../core/game-object'
|
|
5
6
|
|
|
6
7
|
export type BitmapTextNodeOptions = {
|
|
7
8
|
fnt: string
|
|
8
9
|
src: string
|
|
9
|
-
text
|
|
10
|
+
text?: string
|
|
10
11
|
} & GameObjectOptions
|
|
11
12
|
|
|
12
|
-
export class BitmapTextNode<E extends EventMap =
|
|
13
|
+
export class BitmapTextNode<E extends EventMap = {}> extends GameObject<E> {
|
|
13
14
|
#fnt: string
|
|
14
15
|
#src: string
|
|
15
|
-
#text
|
|
16
|
+
#text?: string
|
|
17
|
+
|
|
18
|
+
#font?: BitmapFont
|
|
16
19
|
#sprites: PixiSprite[] = []
|
|
17
20
|
|
|
18
21
|
constructor(options: BitmapTextNodeOptions) {
|
|
@@ -23,21 +26,14 @@ export class BitmapTextNode<E extends EventMap = EventMap> extends GameObject<E>
|
|
|
23
26
|
this.#load()
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
let font
|
|
28
|
-
if (bitmapFontLoader.checkCached(this.#fnt)) {
|
|
29
|
-
font = bitmapFontLoader.getCached(this.#fnt)
|
|
30
|
-
} else {
|
|
31
|
-
console.info(`Bitmap font not preloaded. Loading now: ${this.#fnt}`)
|
|
32
|
-
font = await bitmapFontLoader.load(this.#fnt, this.#src)
|
|
33
|
-
}
|
|
34
|
-
if (!font) return
|
|
35
|
-
|
|
29
|
+
#updateText() {
|
|
36
30
|
for (const sprite of this.#sprites) {
|
|
37
31
|
sprite.destroy()
|
|
38
32
|
}
|
|
39
33
|
this.#sprites = []
|
|
40
34
|
|
|
35
|
+
if (!this.#font || !this.#text) return
|
|
36
|
+
|
|
41
37
|
let xPos = 0, yPos = 0
|
|
42
38
|
let minX = Infinity, minY = Infinity
|
|
43
39
|
let maxX = -Infinity, maxY = -Infinity
|
|
@@ -47,16 +43,16 @@ export class BitmapTextNode<E extends EventMap = EventMap> extends GameObject<E>
|
|
|
47
43
|
|
|
48
44
|
if (charCode === 10) {
|
|
49
45
|
xPos = 0
|
|
50
|
-
yPos += font.lineHeight
|
|
46
|
+
yPos += this.#font.lineHeight
|
|
51
47
|
continue
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
const c = font.chars[charCode]
|
|
50
|
+
const c = this.#font.chars[charCode]
|
|
55
51
|
if (!c) continue
|
|
56
52
|
|
|
57
53
|
const frame = new PixiRectangle(c.x, c.y, c.width, c.height)
|
|
58
|
-
const texture = new PixiTexture({ source: font.texture.source, frame })
|
|
59
|
-
const sprite = new PixiSprite(texture)
|
|
54
|
+
const texture = new PixiTexture({ source: this.#font.texture.source, frame })
|
|
55
|
+
const sprite = new PixiSprite({ texture, zIndex: -999999 })
|
|
60
56
|
|
|
61
57
|
const x0 = xPos + c.xoffset
|
|
62
58
|
const y0 = yPos + c.yoffset
|
|
@@ -87,16 +83,27 @@ export class BitmapTextNode<E extends EventMap = EventMap> extends GameObject<E>
|
|
|
87
83
|
maxY = 0
|
|
88
84
|
}
|
|
89
85
|
|
|
90
|
-
const
|
|
91
|
-
const
|
|
86
|
+
const cx = (minX + maxX) / 2
|
|
87
|
+
const cy = (minY + maxY) / 2
|
|
92
88
|
|
|
93
89
|
for (const s of this.#sprites) {
|
|
94
|
-
s.x -=
|
|
95
|
-
s.y -=
|
|
90
|
+
s.x -= cx
|
|
91
|
+
s.y -= cy
|
|
96
92
|
this._pixiContainer.addChild(s)
|
|
97
93
|
}
|
|
98
94
|
}
|
|
99
95
|
|
|
96
|
+
async #load() {
|
|
97
|
+
if (bitmapFontLoader.checkCached(this.#fnt)) {
|
|
98
|
+
this.#font = bitmapFontLoader.getCached(this.#fnt)
|
|
99
|
+
} else {
|
|
100
|
+
console.info(`Bitmap font not preloaded. Loading now: ${this.#fnt}`)
|
|
101
|
+
this.#font = await bitmapFontLoader.load(this.#fnt, this.#src)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this.#updateText()
|
|
105
|
+
}
|
|
106
|
+
|
|
100
107
|
changeFont(fnt: string, src: string) {
|
|
101
108
|
if (this.#fnt !== fnt || this.#src !== src) {
|
|
102
109
|
bitmapFontLoader.release(this.#fnt)
|
|
@@ -106,6 +113,15 @@ export class BitmapTextNode<E extends EventMap = EventMap> extends GameObject<E>
|
|
|
106
113
|
}
|
|
107
114
|
}
|
|
108
115
|
|
|
116
|
+
set text(text: string | undefined) {
|
|
117
|
+
this.#text = text
|
|
118
|
+
this.#updateText()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
get text() {
|
|
122
|
+
return this.#text
|
|
123
|
+
}
|
|
124
|
+
|
|
109
125
|
override remove() {
|
|
110
126
|
bitmapFontLoader.release(this.#fnt)
|
|
111
127
|
super.remove()
|
package/src/node/ext/spine.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type SpineNodeOptions = {
|
|
|
19
19
|
loop?: boolean
|
|
20
20
|
} & GameObjectOptions
|
|
21
21
|
|
|
22
|
-
export class SpineNode<E extends EventMap =
|
|
22
|
+
export class SpineNode<E extends EventMap = {}> extends GameObject<E & {
|
|
23
23
|
animationend: (animation: string) => void
|
|
24
24
|
}> {
|
|
25
25
|
#atlas: string
|
package/src/node/ext/sprite.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type SpriteNodeOptions = {
|
|
|
7
7
|
src: string
|
|
8
8
|
} & GameObjectOptions
|
|
9
9
|
|
|
10
|
-
export class SpriteNode<E extends EventMap =
|
|
10
|
+
export class SpriteNode<E extends EventMap = {}> extends GameObject<E> {
|
|
11
11
|
#src: string
|
|
12
12
|
#sprite?: PixiSprite
|
|
13
13
|
|
|
@@ -21,11 +21,12 @@ export type PhysicsObjectOptions = {
|
|
|
21
21
|
useYSort?: boolean
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export class PhysicsObject<E extends EventMap =
|
|
24
|
+
export class PhysicsObject<E extends EventMap = {}> extends RenderableNode<PixiContainer, E> {
|
|
25
25
|
#localTransform = new LocalTransform()
|
|
26
26
|
#matterBody: Matter.Body
|
|
27
27
|
|
|
28
28
|
#useYSort = false
|
|
29
|
+
#collisionsEnabled = true
|
|
29
30
|
|
|
30
31
|
constructor(options: PhysicsObjectOptions) {
|
|
31
32
|
super(new PixiContainer({ sortableChildren: true }))
|
|
@@ -65,7 +66,7 @@ export class PhysicsObject<E extends EventMap = EventMap> extends RenderableNode
|
|
|
65
66
|
: parent.constructor?.name ?? typeof parent
|
|
66
67
|
throw new Error(`PhysicsObject parent must be PhysicsWorld, but got ${actual}`)
|
|
67
68
|
}
|
|
68
|
-
parent.addBody(this.#matterBody)
|
|
69
|
+
if (this.#collisionsEnabled) parent.addBody(this.#matterBody)
|
|
69
70
|
super.parent = parent
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -122,6 +123,12 @@ export class PhysicsObject<E extends EventMap = EventMap> extends RenderableNode
|
|
|
122
123
|
get isStatic() { return this.#matterBody.isStatic }
|
|
123
124
|
|
|
124
125
|
disableCollisions() {
|
|
126
|
+
this.#collisionsEnabled = false
|
|
125
127
|
this.#removeFromWorld()
|
|
126
128
|
}
|
|
129
|
+
|
|
130
|
+
enableCollisions() {
|
|
131
|
+
this.#collisionsEnabled = true;
|
|
132
|
+
(this.parent as PhysicsWorld)?.addBody(this.#matterBody)
|
|
133
|
+
}
|
|
127
134
|
}
|
|
@@ -7,7 +7,7 @@ export type PhysicsWorldOptions = {
|
|
|
7
7
|
gravity?: number
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export class PhysicsWorld<E extends EventMap =
|
|
10
|
+
export class PhysicsWorld<E extends EventMap = {}> extends RenderableNode<PixiContainer, E> {
|
|
11
11
|
#matterEngine = Matter.Engine.create()
|
|
12
12
|
|
|
13
13
|
constructor(options?: PhysicsWorldOptions) {
|