import { Entity, System, type Cosmic } from "@cosmic/core"; import { Transform, Renderable } from "@cosmic/kit/components"; export class RenderingSystem extends System { public requiredComponents = new Set([Transform.name, Renderable.name]); private context: CanvasRenderingContext2D; constructor(engine: Cosmic) { super(); this.context = engine.getContext(); } public update(entities: Entity[]): void { this.context.clearRect(0, 0, 9999, 9999); entities.forEach((entity) => { const transform = entity.getComponent(Transform)!; this.context.strokeStyle = "#bf1d70"; if (transform.isCollidingWithEntity) this.context.strokeStyle = "#d6a5b0"; if (transform.isCollidingWithCanvasBoundaries) this.context.strokeStyle = "purple"; this.context.strokeRect(transform.x, transform.y, transform.width, transform.height); }); } }