From dec7b614d895a1b507137e4a96a8999ff63aa179 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Wed, 23 Aug 2023 19:44:59 -0600 Subject: holy fuck we actually got somewhere --- engine/entities/Entity.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'engine/entities/Entity.ts') diff --git a/engine/entities/Entity.ts b/engine/entities/Entity.ts index 4e9df78..88982cb 100644 --- a/engine/entities/Entity.ts +++ b/engine/entities/Entity.ts @@ -1,10 +1,13 @@ +import { EntityNames, Player } from "."; import type { Component } from "../components"; export abstract class Entity { - public readonly id: string; - public readonly components: Map; + public id: string; + public components: Map; + public name: string; - constructor(id: string = crypto.randomUUID()) { + constructor(name: string, id: string = crypto.randomUUID()) { + this.name = name; this.id = id; this.components = new Map(); } @@ -27,4 +30,13 @@ export abstract class Entity { public hasComponent(name: string): boolean { return this.components.has(name); } + + static from(entityName: string, args: any): Entity { + switch (entityName) { + case EntityNames.Player: + return new Player(args.playerId); + default: + throw new Error(".from() Entity type not implemented: " + entityName); + } + } } -- cgit v1.2.3-70-g09d2