2024-03-01 22:04:57 -07:00
|
|
|
import { IMAGES, SPRITE_SPECS, SpriteSpec, Sprites } from "../config";
|
|
|
|
import { Entity, EntityNames } from ".";
|
2024-03-02 01:07:55 -07:00
|
|
|
import {
|
|
|
|
BoundingBox,
|
|
|
|
ComponentNames,
|
|
|
|
Grid,
|
|
|
|
Interactable,
|
|
|
|
Sprite,
|
|
|
|
} from "../components";
|
2024-03-01 22:04:57 -07:00
|
|
|
import { Coord2D } from "../interfaces";
|
2024-03-02 01:34:19 -07:00
|
|
|
import { openModal, closeModal } from "../utils";
|
2024-03-01 22:04:57 -07:00
|
|
|
|
|
|
|
export class FunctionBox extends Entity {
|
|
|
|
private static spriteSpec: SpriteSpec = SPRITE_SPECS.get(
|
|
|
|
Sprites.FUNCTION_BOX,
|
|
|
|
) as SpriteSpec;
|
|
|
|
|
2024-03-02 01:07:55 -07:00
|
|
|
private code: string;
|
|
|
|
|
|
|
|
constructor(gridPosition: Coord2D, code: string) {
|
2024-03-01 22:04:57 -07:00
|
|
|
super(EntityNames.FunctionBox);
|
|
|
|
|
2024-03-02 01:07:55 -07:00
|
|
|
this.code = code;
|
|
|
|
|
2024-03-01 22:04:57 -07:00
|
|
|
this.addComponent(
|
|
|
|
new BoundingBox(
|
|
|
|
{
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
width: FunctionBox.spriteSpec.width,
|
|
|
|
height: FunctionBox.spriteSpec.height,
|
|
|
|
},
|
|
|
|
0,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
this.addComponent(new Grid(true, gridPosition));
|
|
|
|
|
|
|
|
this.addComponent(
|
|
|
|
new Sprite(
|
|
|
|
IMAGES.get(FunctionBox.spriteSpec.sheet)!,
|
|
|
|
{ x: 0, y: 0 },
|
|
|
|
{
|
|
|
|
width: FunctionBox.spriteSpec.width,
|
|
|
|
height: FunctionBox.spriteSpec.height,
|
|
|
|
},
|
|
|
|
FunctionBox.spriteSpec.msPerFrame,
|
|
|
|
FunctionBox.spriteSpec.frames,
|
|
|
|
),
|
|
|
|
);
|
2024-03-02 01:07:55 -07:00
|
|
|
|
|
|
|
this.hooks.set(ComponentNames.Highlight, {
|
|
|
|
add: () => {
|
2024-03-02 01:34:19 -07:00
|
|
|
let modalOpen = false;
|
|
|
|
const interaction = () => {
|
|
|
|
if (modalOpen) {
|
|
|
|
modalOpen = false;
|
|
|
|
closeModal();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
modalOpen = true;
|
|
|
|
openModal(this.code);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.addComponent(new Interactable(interaction));
|
2024-03-02 01:07:55 -07:00
|
|
|
},
|
|
|
|
remove: () => {
|
2024-03-02 01:34:19 -07:00
|
|
|
closeModal();
|
2024-03-02 01:07:55 -07:00
|
|
|
this.removeComponent(ComponentNames.Interactable);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2024-03-01 22:04:57 -07:00
|
|
|
}
|