CabinGame/Program/src/index.ts

75 lines
2.7 KiB
TypeScript
Raw Normal View History

2020-02-17 11:56:41 +00:00
import { Application, Ticker, settings, SCALE_MODES } from "pixi.js"
import { setup } from "./setup"
import { loadResources } from "./Resources"
2020-02-17 11:56:41 +00:00
import { DoorSystem } from "./Systems/DoorSystem"
2020-02-19 22:12:18 +00:00
import { SpriteSystem } from "./Systems/rendering/SpriteSystem"
import { RenderSystem } from "./Systems/rendering/RenderSystem"
import { TestSystem } from "./Systems/TestSystem"
2020-02-17 11:56:41 +00:00
import { AdventureReturnSystem } from "./Systems/AdventureReturnSystem"
import { VisibleHumanSystem } from "./Systems/VisibleHumanSystem"
2020-02-19 22:12:18 +00:00
import { DebugRenderSystem } from "./Systems/rendering/DebugRenderSystem"
import { PixiCleanupSystem } from "./Systems/rendering/PixiCleanupSystem"
import { ZOrderSystem } from "./Systems/rendering/ZOrderSystem"
import { PathWalkerSystem } from "./Systems/PathWalkerSystem"
import { RandomWalkSystem } from "./Systems/RandomWalkSystem"
import { World } from "ecsy"
import globals from "./globals"
import { canvasWidth, canvasHeight } from "./constants"
import { ClickableSystem } from "./Systems/ClickableSystem"
// Initialize pixi
globals.app = new Application({
width: canvasWidth,
height: canvasHeight,
2020-02-17 11:56:41 +00:00
backgroundColor: 0x000000,
resolution: 1,
antialias: false,
})
document.body.appendChild(globals.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)
globals.app.view.style.width = canvasWidth * multiplier + "px"
globals.app.view.style.height = canvasHeight * multiplier + "px"
}
// Create world and register the systems on it
2020-02-17 11:56:41 +00:00
//we could also register components here but they should get automatically registered once used for the first time
globals.world = new World()
globals.world
2020-02-17 11:56:41 +00:00
.registerSystem(TestSystem) //prio -100
.registerSystem(AdventureReturnSystem) //prio -100
.registerSystem(DoorSystem) //prio 0
.registerSystem(RandomWalkSystem) //prio 0
.registerSystem(PathWalkerSystem) //prio 50
2020-02-17 11:56:41 +00:00
.registerSystem(VisibleHumanSystem) //prio 50
.registerSystem(SpriteSystem) //prio 70
.registerSystem(ClickableSystem) //prio 80
2020-02-17 11:56:41 +00:00
.registerSystem(DebugRenderSystem) //prio 90
.registerSystem(ZOrderSystem) //prio 98
.registerSystem(PixiCleanupSystem) //prio 99
.registerSystem(RenderSystem) //prio 100
loadResources(init)
function init(){
2020-02-17 11:56:41 +00:00
setup()
// Run!
Ticker.shared.add((delta : number) => {
let time = performance.now()
// Run all the systems
globals.world.execute(delta/100, time)
});
}