summaryrefslogtreecommitdiff
path: root/src/engine/entities/LambdaFactory.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-02 04:02:20 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-02 04:02:20 -0700
commit4b9349b3f8bee21eb086cfd6e7668532a50e6048 (patch)
treefa3ae95f516d8ec10fb0de57886ff88410b6d11d /src/engine/entities/LambdaFactory.ts
parent06bb4177202b432d5f42141975ec82b5a8837f0e (diff)
downloadthe-abstraction-engine-4b9349b3f8bee21eb086cfd6e7668532a50e6048.tar.gz
the-abstraction-engine-4b9349b3f8bee21eb086cfd6e7668532a50e6048.zip
add text on lambda factory
Diffstat (limited to 'src/engine/entities/LambdaFactory.ts')
-rw-r--r--src/engine/entities/LambdaFactory.ts109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/engine/entities/LambdaFactory.ts b/src/engine/entities/LambdaFactory.ts
new file mode 100644
index 0000000..1483b9d
--- /dev/null
+++ b/src/engine/entities/LambdaFactory.ts
@@ -0,0 +1,109 @@
+import { IMAGES, SPRITE_SPECS, SpriteSpec, Sprites } from "../config";
+import { Entity, EntityNames } from ".";
+import {
+ BoundingBox,
+ Colliding,
+ ComponentNames,
+ Grid,
+ Highlight,
+ Interactable,
+ LambdaSpawn,
+ Sprite,
+ Text,
+} from "../components";
+import { Coord2D, Direction } from "../interfaces";
+import { openModal, closeModal } from "../utils";
+
+export class LambdaFactory extends Entity {
+ private static spriteSpec: SpriteSpec = SPRITE_SPECS.get(
+ Sprites.LAMBDA_FACTORY,
+ ) as SpriteSpec;
+
+ private code: string;
+ private spawns: number;
+
+ constructor(gridPosition: Coord2D, code: string, spawns: number) {
+ super(EntityNames.LambdaFactory);
+
+ this.code = code;
+ this.spawns = spawns;
+
+ this.addComponent(
+ new BoundingBox(
+ {
+ x: 0,
+ y: 0,
+ },
+ {
+ width: LambdaFactory.spriteSpec.width,
+ height: LambdaFactory.spriteSpec.height,
+ },
+ 0,
+ ),
+ );
+
+ this.addComponent(new Text(spawns.toString()));
+
+ this.addComponent(new Colliding());
+
+ this.addComponent(new LambdaSpawn(this.spawns, this.code));
+
+ this.addComponent(new Grid(gridPosition));
+
+ this.addComponent(
+ new Sprite(
+ IMAGES.get(LambdaFactory.spriteSpec.sheet)!,
+ { x: 0, y: 0 },
+ {
+ width: LambdaFactory.spriteSpec.width,
+ height: LambdaFactory.spriteSpec.height,
+ },
+ LambdaFactory.spriteSpec.msPerFrame,
+ LambdaFactory.spriteSpec.frames,
+ ),
+ );
+
+ this.addComponent(
+ new Highlight(
+ (direction) => this.onHighlight(direction),
+ () => this.onUnhighlight(),
+ ),
+ );
+ }
+
+ private onUnhighlight() {
+ closeModal();
+ this.removeComponent(ComponentNames.Interactable);
+ }
+
+ private onHighlight(direction: Direction) {
+ if (direction === Direction.LEFT || direction === Direction.RIGHT) {
+ const interaction = () => {
+ const spawner = this.getComponent<LambdaSpawn>(
+ ComponentNames.LambdaSpawn,
+ );
+ spawner.spawn(direction);
+
+ const text = this.getComponent<Text>(ComponentNames.Text);
+ text.text = spawner.spawnsLeft.toString();
+ this.addComponent(text);
+ };
+
+ this.addComponent(new Interactable(interaction));
+ return;
+ }
+
+ let modalOpen = false;
+ const interaction = () => {
+ if (modalOpen) {
+ modalOpen = false;
+ closeModal();
+ return;
+ }
+ modalOpen = true;
+ openModal(this.code);
+ };
+
+ this.addComponent(new Interactable(interaction));
+ }
+}