diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-02 02:22:46 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-02 02:24:18 -0700 |
commit | 06bb4177202b432d5f42141975ec82b5a8837f0e (patch) | |
tree | 7a9cb1e4177684848a3fcca91eed2ec703c787fb /src/engine/entities/FunctionBox.ts | |
parent | cd6a3a56b0a9f27dd7250c7641776fe1bd184888 (diff) | |
download | the-abstraction-engine-06bb4177202b432d5f42141975ec82b5a8837f0e.tar.gz the-abstraction-engine-06bb4177202b432d5f42141975ec82b5a8837f0e.zip |
slight refactor in collision behavior
Diffstat (limited to 'src/engine/entities/FunctionBox.ts')
-rw-r--r-- | src/engine/entities/FunctionBox.ts | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/src/engine/entities/FunctionBox.ts b/src/engine/entities/FunctionBox.ts index 57eeedb..e5d031a 100644 --- a/src/engine/entities/FunctionBox.ts +++ b/src/engine/entities/FunctionBox.ts @@ -4,7 +4,9 @@ import { BoundingBox, ComponentNames, Grid, + Highlight, Interactable, + Pushable, Sprite, } from "../components"; import { Coord2D } from "../interfaces"; @@ -36,7 +38,9 @@ export class FunctionBox extends Entity { ), ); - this.addComponent(new Grid(true, gridPosition)); + this.addComponent(new Pushable()); + + this.addComponent(new Grid(gridPosition)); this.addComponent( new Sprite( @@ -51,25 +55,31 @@ export class FunctionBox extends Entity { ), ); - this.hooks.set(ComponentNames.Highlight, { - add: () => { - let modalOpen = false; - const interaction = () => { - if (modalOpen) { - modalOpen = false; - closeModal(); - return; - } - modalOpen = true; - openModal(this.code); - }; + this.addComponent( + new Highlight( + () => this.onHighlight(), + () => this.onUnhighlight(), + ), + ); + } + + private onUnhighlight() { + closeModal(); + this.removeComponent(ComponentNames.Interactable); + } - this.addComponent(new Interactable(interaction)); - }, - remove: () => { + private onHighlight() { + let modalOpen = false; + const interaction = () => { + if (modalOpen) { + modalOpen = false; closeModal(); - this.removeComponent(ComponentNames.Interactable); - }, - }); + return; + } + modalOpen = true; + openModal(this.code); + }; + + this.addComponent(new Interactable(interaction)); } } |