Add decor parsing
This commit is contained in:
parent
89eea0e5a7
commit
7fed2516b6
67
Engine/src/data/decor.ts
Normal file
67
Engine/src/data/decor.ts
Normal file
|
@ -0,0 +1,67 @@
|
|||
import * as PIXI from 'pixi.js'
|
||||
|
||||
export class Decor {
|
||||
texture: PIXI.Texture
|
||||
decorations: Decoration[] = []
|
||||
|
||||
constructor(o: any) {
|
||||
this.texture = PIXI.Texture.from('./Assets/Decors/'+o.image)
|
||||
// Load decorations.
|
||||
for (let d of o.decorations) {
|
||||
this.decorations.push(new Decoration(this.texture.baseTexture, d))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class Decoration {
|
||||
frames: DecorationFrame[] = []
|
||||
constructor(t: PIXI.BaseTexture, o: any) {
|
||||
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) {
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ import * as PIXI from 'pixi.js'
|
|||
import { ContextI } from './ContextI'
|
||||
import { MenuState } from './states/Menu'
|
||||
import { StateI } from './states/StateI'
|
||||
import decors from './shared/decors'
|
||||
|
||||
export class Engine {
|
||||
ctx: ContextI
|
||||
|
|
10
Engine/src/shared/decors.ts
Normal file
10
Engine/src/shared/decors.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import assets from '../../../Assets/Decors/**/*.yaml'
|
||||
import { Decor } from '../data/decor'
|
||||
|
||||
const decors: Record<string, Decor> = {}
|
||||
|
||||
for (let [key, value] of Object.entries(assets)) {
|
||||
decors[key] = new Decor(value)
|
||||
}
|
||||
|
||||
export default decors
|
Loading…
Reference in New Issue
Block a user