From 4233aca561b5650924f3cc4232cfd294d706c863 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sat, 2 Mar 2024 06:00:47 -0700 Subject: refocus canvas on lambda factory clsoe --- src/engine/entities/LambdaFactory.ts | 43 ++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'src/engine/entities/LambdaFactory.ts') 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( + 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 ` +
+ + +
+ `; + } } -- cgit v1.2.3-70-g09d2