summaryrefslogtreecommitdiff
path: root/src/engine/entities/LambdaFactory.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/entities/LambdaFactory.ts')
-rw-r--r--src/engine/entities/LambdaFactory.ts24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/engine/entities/LambdaFactory.ts b/src/engine/entities/LambdaFactory.ts
index 1c897eb..a0f5749 100644
--- a/src/engine/entities/LambdaFactory.ts
+++ b/src/engine/entities/LambdaFactory.ts
@@ -5,15 +5,15 @@ import {
SpriteSpec,
Sprites,
} from "../config";
-import { Entity, EntityNames } from ".";
+import { Entity, EntityNames, FunctionBox } from ".";
import {
BoundingBox,
Colliding,
ComponentNames,
Grid,
+ GridSpawn,
Highlight,
Interactable,
- LambdaSpawn,
Sprite,
Text,
} from "../components";
@@ -75,11 +75,13 @@ export class LambdaFactory extends Entity {
private codeEditorState: CodeEditorState | null;
private spawns: number;
+ private code: string;
constructor(gridPosition: Coord2D, code: string, spawns: number) {
super(EntityNames.LambdaFactory);
this.spawns = spawns;
+ this.code = code;
this.codeEditorState = null;
this.addComponent(
@@ -100,7 +102,12 @@ export class LambdaFactory extends Entity {
this.addComponent(new Colliding());
- this.addComponent(new LambdaSpawn(this.spawns, code));
+ this.addComponent(
+ new GridSpawn(
+ this.spawns,
+ () => new FunctionBox({ x: 0, y: 0 }, this.code),
+ ),
+ );
this.addComponent(new Grid(gridPosition));
@@ -131,8 +138,8 @@ export class LambdaFactory extends Entity {
}
private spawnNewLambda(direction: Direction) {
- const spawner = this.getComponent<LambdaSpawn>(ComponentNames.LambdaSpawn);
- spawner.spawn(direction);
+ const spawner = this.getComponent<GridSpawn>(ComponentNames.GridSpawn);
+ spawner.spawnEntity(direction);
const text = this.getComponent<Text>(ComponentNames.Text);
text.text = spawner.spawnsLeft.toString();
@@ -144,9 +151,8 @@ export class LambdaFactory extends Entity {
"<div class='code'><div id='code'></div><br><p id='syntax-error' class='error'></p><button id='close-modal'>Save</button></div>";
openModal(modalContent);
- const { code } = this.getComponent<LambdaSpawn>(ComponentNames.LambdaSpawn);
const startState = EditorState.create({
- doc: code,
+ doc: this.code,
extensions: [
basicSetup,
keymap.of(defaultKeymap),
@@ -236,9 +242,7 @@ export class LambdaFactory extends Entity {
return;
}
- const spawner = this.getComponent<LambdaSpawn>(ComponentNames.LambdaSpawn);
- spawner.code = text;
- this.addComponent(spawner);
+ this.code = text;
view.destroy();
editorElement.innerHTML = "";