CabinGame/Program/src/index.ts
2020-02-17 12:56:41 +01:00

68 lines
2.3 KiB
TypeScript

import { Application, Ticker, settings, SCALE_MODES } from "pixi.js"
import { World } from "ecsy"
import { setup } from "./setup"
import { loadResources } from "./Resources"
import { DoorSystem } from "./Systems/DoorSystem"
import { SpriteSystem } from "./Systems/SpriteSystem"
import { RenderSystem } from "./Systems/RenderSystem"
import { TestSystem } from "./Systems/TestSystem"
import { AdventureReturnSystem } from "./Systems/AdventureReturnSystem"
import { VisibleHumanSystem } from "./Systems/VisibleHumanSystem"
import { DebugRenderSystem } from "./Systems/DebugRenderSystem"
import { PixiCleanupSystem } from "./Systems/PixiCleanupSystem"
import { ZOrderSystem } from "./Systems/ZOrderSystem"
// Initialize pixi
export let canvasWidth = 81
export let canvasHeight = 144
export const app = new Application({
width: canvasWidth,
height: canvasHeight,
backgroundColor: 0x000000,
resolution: 1,
antialias: false,
})
document.body.appendChild(app.view)
settings.SCALE_MODE = SCALE_MODES.NEAREST
settings.ROUND_PIXELS = true
recalculateSize()
window.addEventListener( 'resize', recalculateSize, false )
function recalculateSize(){
let multiplier = Math.min((window.innerWidth/canvasWidth)|0, (window.innerHeight/canvasHeight)|0)
app.view.style.width = canvasWidth * multiplier + "px"
app.view.style.height = canvasHeight * multiplier + "px"
}
// Create world and register the systems on it
//we could also register components here but they should get automatically registered once used for the first time
export let world = new World()
world
.registerSystem(TestSystem) //prio -100
.registerSystem(AdventureReturnSystem) //prio -100
.registerSystem(DoorSystem) //prio 0
.registerSystem(VisibleHumanSystem) //prio 50
.registerSystem(SpriteSystem) //prio 90
.registerSystem(DebugRenderSystem) //prio 90
.registerSystem(ZOrderSystem) //prio 98
.registerSystem(PixiCleanupSystem) //prio 99
.registerSystem(RenderSystem) //prio 100
loadResources(init)
function init(){
setup()
// Run!
Ticker.shared.add((delta : number) => {
let time = performance.now()
// Run all the systems
world.execute(delta, time)
});
}