import { EntityView } from '../view/entity'; import { Renderer } from '../view/renderer/renderer'; import { Collidable } from '../math/collision'; import { CollidableGroup, mkCollision } from './collision'; import { vec2 } from 'gl-matrix'; export class EntityContext implements CollidableGroup { public static async load(renderer: Renderer, name: string): Promise { return new EntityContext( renderer, name, await EntityView.load(renderer, name), ); } public readonly pos: vec2 = vec2.create(); private readonly collision: Collidable[]; private constructor( private readonly renderer: Renderer, private readonly name: string, private readonly view: EntityView, ) { this.collision = mkCollision(view.data.collision); } public render(time: number) { this.renderer.setTranslation(this.pos); this.view.renderByTime(time); } public getTranslation(): vec2 { return this.pos; } public getCollidables(): Collidable[] { return this.collision; } public interact() { alert(`You've interacted with ${this.name}!`); } }