diff options
author | Elizabeth Hunt <elizabeth@simponic.xyz> | 2025-03-01 12:36:47 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth@simponic.xyz> | 2025-03-01 12:36:47 -0700 |
commit | 8dacee8f73633131fd68935c1e2493dc4beec837 (patch) | |
tree | fc9adf76fce4761b01208ba2f44e72a6838244aa /src/engine/entities/Sign.ts | |
parent | d903bd9a13e790cf42c84c3dc59bf89ffeae1d80 (diff) | |
download | the-abstraction-engine-8dacee8f73633131fd68935c1e2493dc4beec837.tar.gz the-abstraction-engine-8dacee8f73633131fd68935c1e2493dc4beec837.zip |
updates
Diffstat (limited to 'src/engine/entities/Sign.ts')
-rw-r--r-- | src/engine/entities/Sign.ts | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/src/engine/entities/Sign.ts b/src/engine/entities/Sign.ts index 45f2986..c85ad40 100644 --- a/src/engine/entities/Sign.ts +++ b/src/engine/entities/Sign.ts @@ -1,18 +1,27 @@ -import { Entity, EntityNames, makeLambdaTermHighlightComponent } from "."; -import { BoundingBox, Colliding, Grid, Sprite } from "../components"; +import { Entity, EntityNames } from "."; +import { + BoundingBox, + Colliding, + ComponentNames, + Grid, + Highlight, + Interactable, + Modal, + Sprite, +} from "../components"; import { IMAGES, SPRITE_SPECS, SpriteSpec, Sprites } from "../config"; import { Coord2D } from "../interfaces"; export class Sign extends Entity { private static spriteSpec: SpriteSpec = SPRITE_SPECS.get( - Sprites.SIGN, + Sprites.SIGN ) as SpriteSpec; - private text: string; - - constructor(text: string, gridPosition: Coord2D) { + constructor( + private readonly text: string, + gridPosition: Coord2D + ) { super(EntityNames.Sign); - this.text = text; const dimension = { width: Sign.spriteSpec.width, @@ -25,8 +34,8 @@ export class Sign extends Entity { { x: 0, y: 0 }, dimension, Sign.spriteSpec.msPerFrame, - Sign.spriteSpec.frames, - ), + Sign.spriteSpec.frames + ) ); this.addComponent( @@ -36,14 +45,40 @@ export class Sign extends Entity { y: 0, }, dimension, - 0, - ), + 0 + ) ); this.addComponent(new Grid(gridPosition)); this.addComponent(new Colliding()); - this.addComponent(makeLambdaTermHighlightComponent(this, this.text)); + this.addComponent( + new Highlight(this.onHighlight.bind(this), this.onUnhighlight.bind(this)) + ); + } + + private onHighlight() { + this.addComponent(new Interactable(this.interaction.bind(this))); + } + + private onUnhighlight() { + this.removeComponent(ComponentNames.Modal); + this.removeComponent(ComponentNames.Interactable); + } + + private interaction() { + if (this.hasComponent(ComponentNames.Modal)) { + this.removeComponent(ComponentNames.Modal); + return; + } + this.addComponent( + new Modal({ + type: "CONTENT", + contentInit: { + content: `<p>${this.text}</p>`, + }, + }) + ); } } |