From 7fed2516b659cd66b9906e3f8f61bdd0d1909eb0 Mon Sep 17 00:00:00 2001 From: kts of kettek Date: Sat, 29 Jan 2022 02:23:39 -0800 Subject: [PATCH] Add decor parsing --- Engine/src/data/decor.ts | 67 +++++++++++++++++++++++++++++++++++++ Engine/src/engine.ts | 1 + Engine/src/shared/decors.ts | 10 ++++++ 3 files changed, 78 insertions(+) create mode 100644 Engine/src/data/decor.ts create mode 100644 Engine/src/shared/decors.ts diff --git a/Engine/src/data/decor.ts b/Engine/src/data/decor.ts new file mode 100644 index 0000000..851bd54 --- /dev/null +++ b/Engine/src/data/decor.ts @@ -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) { + +} \ No newline at end of file diff --git a/Engine/src/engine.ts b/Engine/src/engine.ts index b7bb165..8a6f7d8 100644 --- a/Engine/src/engine.ts +++ b/Engine/src/engine.ts @@ -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 diff --git a/Engine/src/shared/decors.ts b/Engine/src/shared/decors.ts new file mode 100644 index 0000000..bd7ccaa --- /dev/null +++ b/Engine/src/shared/decors.ts @@ -0,0 +1,10 @@ +import assets from '../../../Assets/Decors/**/*.yaml' +import { Decor } from '../data/decor' + +const decors: Record = {} + +for (let [key, value] of Object.entries(assets)) { + decors[key] = new Decor(value) +} + +export default decors \ No newline at end of file