summaryrefslogtreecommitdiff
path: root/src/engine/systems/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/systems/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/systems/LambdaFactory.ts')
-rw-r--r--src/engine/systems/LambdaFactory.ts34
1 files changed, 34 insertions, 0 deletions
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<LambdaSpawn>(
+ ComponentNames.LambdaSpawn,
+ )!;
+ const hasGrid = entity.hasComponent(SystemNames.Grid);
+
+ if (!lambdaSpawn.direction || !hasGrid) {
+ return;
+ }
+
+ const grid = entity.getComponent<Grid>(SystemNames.Grid)!;
+
+ const lambda = new FunctionBox(grid.gridPosition, lambdaSpawn.code);
+ const lambdaGrid = lambda.getComponent<Grid>(SystemNames.Grid)!;
+ lambdaGrid.movingDirection = lambdaSpawn.direction;
+ lambda.addComponent(lambdaGrid);
+ game.addEntity(lambda);
+
+ lambdaSpawn.direction = null;
+ entity.addComponent(lambdaSpawn);
+ });
+ }
+}