From 4b9349b3f8bee21eb086cfd6e7668532a50e6048 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sat, 2 Mar 2024 04:02:20 -0700 Subject: add text on lambda factory --- src/engine/systems/LambdaFactory.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/engine/systems/LambdaFactory.ts (limited to 'src/engine/systems/LambdaFactory.ts') diff --git a/src/engine/systems/LambdaFactory.ts b/src/engine/systems/LambdaFactory.ts new file mode 100644 index 0000000..1263eae --- /dev/null +++ b/src/engine/systems/LambdaFactory.ts @@ -0,0 +1,34 @@ +import { System, SystemNames } from "."; +import { Game } from ".."; +import { ComponentNames, Grid, LambdaSpawn } from "../components"; +import { FunctionBox } from "../entities"; + +export class LambdaFactory extends System { + constructor() { + super(SystemNames.LambdaFactory); + } + + public update(_dt: number, game: Game) { + game.forEachEntityWithComponent(ComponentNames.LambdaSpawn, (entity) => { + const lambdaSpawn = entity.getComponent( + ComponentNames.LambdaSpawn, + )!; + const hasGrid = entity.hasComponent(SystemNames.Grid); + + if (!lambdaSpawn.direction || !hasGrid) { + return; + } + + const grid = entity.getComponent(SystemNames.Grid)!; + + const lambda = new FunctionBox(grid.gridPosition, lambdaSpawn.code); + const lambdaGrid = lambda.getComponent(SystemNames.Grid)!; + lambdaGrid.movingDirection = lambdaSpawn.direction; + lambda.addComponent(lambdaGrid); + game.addEntity(lambda); + + lambdaSpawn.direction = null; + entity.addComponent(lambdaSpawn); + }); + } +} -- cgit v1.2.3-70-g09d2