2022-01-29 01:37:01 -08:00
|
|
|
import { ContextI } from "../ContextI"
|
2022-01-29 03:44:34 -08:00
|
|
|
import { segments } from "../shared/segments"
|
2022-01-29 01:37:01 -08:00
|
|
|
import { StateI } from "./StateI"
|
2022-01-29 03:44:34 -08:00
|
|
|
import * as PIXI from 'pixi.js'
|
|
|
|
import { DecorationInstance } from "../shared/decors"
|
2022-01-29 01:37:01 -08:00
|
|
|
|
|
|
|
export function GameState(ctx: ContextI): StateI {
|
|
|
|
|
2022-01-29 03:44:34 -08:00
|
|
|
let rootContainer = new PIXI.Container()
|
|
|
|
let decorations: DecorationInstance[] = []
|
|
|
|
|
2022-01-29 01:37:01 -08:00
|
|
|
let enter = () => {
|
|
|
|
console.log('less goooo')
|
2022-01-29 03:44:34 -08:00
|
|
|
// Load the world segment.
|
|
|
|
let w = segments.world
|
|
|
|
if (!w) return ctx.pop()
|
|
|
|
rootContainer.width = w.width
|
|
|
|
rootContainer.height = w.height
|
|
|
|
rootContainer.scale.set(2, 2)
|
|
|
|
for (let l of w.layers) {
|
|
|
|
let container = new PIXI.Container()
|
|
|
|
container.width = w.width
|
|
|
|
container.height = w.height
|
|
|
|
|
|
|
|
for (let d of l.decorations) {
|
|
|
|
let di = new DecorationInstance(d.decor, d.decoration)
|
|
|
|
di.elapsed = d.timeOffset
|
|
|
|
di.container.x = d.x
|
|
|
|
di.container.y = d.y
|
|
|
|
if (d.flip) {
|
|
|
|
console.log('friggin flip it')
|
|
|
|
di.container.pivot.y = 1
|
|
|
|
di.container.scale.y *= -1
|
|
|
|
di.container.position.y--
|
|
|
|
}
|
|
|
|
if (d.mirror) {
|
|
|
|
di.container.pivot.x = 1
|
|
|
|
di.container.scale.x *= -1
|
|
|
|
di.container.position.x--
|
|
|
|
}
|
|
|
|
|
|
|
|
container.addChild(di.container)
|
|
|
|
decorations.push(di)
|
|
|
|
}
|
|
|
|
|
|
|
|
rootContainer.addChild(container)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.app.stage.addChild(rootContainer)
|
2022-01-29 01:37:01 -08:00
|
|
|
}
|
|
|
|
let leave = () => {
|
2022-01-29 03:44:34 -08:00
|
|
|
ctx.app.stage.removeChild(rootContainer)
|
2022-01-29 01:37:01 -08:00
|
|
|
}
|
|
|
|
let update = (delta: number) => {
|
2022-01-29 03:44:34 -08:00
|
|
|
for (let decoration of decorations) {
|
|
|
|
decoration.update(delta)
|
|
|
|
}
|
2022-01-29 01:37:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
enter,
|
|
|
|
leave,
|
|
|
|
update,
|
|
|
|
}
|
|
|
|
}
|