67 lines
1.5 KiB
TypeScript
Raw Normal View History

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";
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: () => {
this.addComponent(new Interactable(() => this.viewInsides()));
},
remove: () => {
this.removeComponent(ComponentNames.Interactable);
},
});
}
public viewInsides() {
console.log("I am a function box!");
2024-03-01 22:04:57 -07:00
}
}