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.ts43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/engine/entities/LambdaFactory.ts b/src/engine/entities/LambdaFactory.ts
index 1483b9d..4861c6b 100644
--- a/src/engine/entities/LambdaFactory.ts
+++ b/src/engine/entities/LambdaFactory.ts
@@ -1,4 +1,10 @@
-import { IMAGES, SPRITE_SPECS, SpriteSpec, Sprites } from "../config";
+import {
+ IMAGES,
+ Miscellaneous,
+ SPRITE_SPECS,
+ SpriteSpec,
+ Sprites,
+} from "../config";
import { Entity, EntityNames } from ".";
import {
BoundingBox,
@@ -94,16 +100,45 @@ export class LambdaFactory extends Entity {
}
let modalOpen = false;
+ const close = () => {
+ modalOpen = false;
+ closeModal();
+
+ const spawner = this.getComponent<LambdaSpawn>(
+ ComponentNames.LambdaSpawn,
+ );
+ spawner.code = (
+ document.getElementById("code") as HTMLTextAreaElement
+ ).value;
+ this.addComponent(spawner);
+
+ document.getElementById(Miscellaneous.CANVAS_ID)!.focus();
+ return;
+ };
+
const interaction = () => {
if (modalOpen) {
- modalOpen = false;
- closeModal();
+ close();
return;
}
+
modalOpen = true;
- openModal(this.code);
+ openModal(this.codeEditor(this.code));
+
+ document.getElementById("close-modal")!.addEventListener("click", close);
};
this.addComponent(new Interactable(interaction));
}
+
+ private codeEditor(code: string) {
+ return `
+ <div>
+ <textarea id="code" autofocus="autofocus" rows="10" cols="50">
+ ${code}
+ </textarea>
+ <button id="close-modal">Close</button>
+ </div>
+ `;
+ }
}