CabinGame/Program/src/Systems/rendering/DebugRenderSystem.ts

44 lines
1.6 KiB
TypeScript
Raw Normal View History

2020-02-17 11:56:41 +00:00
import { System, Entity, Not } from "ecsy"
2020-02-19 22:12:18 +00:00
import { DebugRect } from "../../Components/rendering/debugRect";
import { PixiRepresentation } from "../../Components/rendering/pixiRepresentation";
2020-02-17 11:56:41 +00:00
import { Graphics, DisplayObject } from "pixi.js";
2020-02-19 22:12:18 +00:00
import globals from "../../globals";
2020-02-17 11:56:41 +00:00
// MovableSystem
export class DebugRenderSystem extends System {
priority: 90
// This method will get called on every frame by default
execute(delta : number) {
// Iterate through all the entities on the query
this.queries.newRectangles.results.forEach((entity: Entity) => {
let debugRect = entity.getComponent(DebugRect)
let graphic = new Graphics()
graphic.lineStyle(1, debugRect.color, 0.5)
graphic.drawRect(debugRect.rect.source.x, debugRect.rect.source.y, debugRect.rect.size.x, debugRect.rect.size.y)
globals.app.stage.addChild(graphic)
2020-02-17 11:56:41 +00:00
entity.addComponent(PixiRepresentation, <PixiRepresentation>{value: <DisplayObject>graphic})
})
this.queries.rectangles.changed.forEach((entity: Entity) => {
let debugRect = entity.getComponent(DebugRect)
let graphic = entity.getMutableComponent(PixiRepresentation).value as Graphics
graphic.clear
graphic.lineStyle(1, debugRect.color, 0.5)
graphic.drawRect(debugRect.rect.source.x, debugRect.rect.source.y, debugRect.rect.size.x, debugRect.rect.size.y)
})
}
static queries = {
newRectangles: {
components: [ DebugRect, Not(PixiRepresentation) ]
},
rectangles: {
components: [ DebugRect, PixiRepresentation ],
listen: {
changed: [ DebugRect ]
}
},
}
queries: any;
}