GGJ22/Engine/src/data/decor.ts

80 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-01-29 02:23:39 -08:00
import * as PIXI from 'pixi.js'
export class Decor {
2022-01-29 03:44:34 -08:00
uuid: string
2022-01-29 02:23:39 -08:00
texture: PIXI.Texture
decorations: Decoration[] = []
constructor(o: any) {
2022-01-29 03:44:34 -08:00
this.uuid = o.uuid
2022-01-29 02:23:39 -08:00
this.texture = PIXI.Texture.from('./Assets/Decors/'+o.image)
2022-01-29 03:44:34 -08:00
this.texture.baseTexture.scaleMode = PIXI.SCALE_MODES.NEAREST
2022-01-29 02:23:39 -08:00
// Load decorations.
for (let d of o.decorations) {
this.decorations.push(new Decoration(this.texture.baseTexture, d))
}
}
}
export class Decoration {
2022-01-29 03:44:34 -08:00
uuid: string
2022-01-29 02:23:39 -08:00
frames: DecorationFrame[] = []
2022-01-29 03:44:34 -08:00
width: number = 0
height: number = 0
timeOffset: number = 0
2022-01-29 02:23:39 -08:00
constructor(t: PIXI.BaseTexture, o: any) {
2022-01-29 03:44:34 -08:00
this.width = o.width
this.height = o.height
this.uuid = o.uuid
if (!isNaN(o.timeOffset)) {
this.timeOffset = o.timeOffset
}
2022-01-29 02:23:39 -08:00
for (let frame of o.frames) {
this.frames.push(new DecorationFrame(t, frame))
}
}
}
export class DecorationFrame {
parts: DecorationPart[] = []
time: number = 0
constructor(t: PIXI.BaseTexture, o: any) {
this.time = o.frame_time
for (let p of o.parts) {
this.parts.push(new DecorationPart(t, p))
}
}
}
export class DecorationPart {
texture: PIXI.Texture
clipX: number = 0
clipY: number = 0
clipWidth: number = 0
clipHeight: number = 0
x: number = 0
y: number = 0
alpha: number = 1
rotation: number = 0
mirror: boolean = false
flip: boolean = false
constructor(t: PIXI.BaseTexture, o: any) {
this.clipX = o.clipX
this.clipY = o.clipY
this.clipWidth = o.clipWidth
this.clipHeight = o.clipHeight
this.x = o.x
this.y = o.y
this.alpha = o.alpha
this.rotation = o.rotation
this.mirror = o.mirror
this.flip = o.flip
// Hmm.
this.texture = new PIXI.Texture(t, new PIXI.Rectangle(this.clipX, this.clipY, this.clipWidth, this.clipHeight))
}
}
// This loads a file in an expected Vio Decor format and returns an array of Decor entries.
export function load(obj: any) {
}