Skip to content

Commit

Permalink
interactables are now researchable
Browse files Browse the repository at this point in the history
  • Loading branch information
SomewhatMay committed Nov 3, 2024
1 parent 8df838c commit 90a33fe
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 15 deletions.
10 changes: 10 additions & 0 deletions src/scenes/game/interactables/interaction-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export class InteractionListener {
const currentAction = this.scene.registry.get("action");

if (target !== "" && currentAction === "") {
// if researching, ensure the interactable is discovered
if (action === "research") {
if (store.getDiscovered(target) !== 100) {
notification.displayNotification(
"You must discover ?????? before you can research it!"
);
return;
}
}

this.scene.registry.set("action", action);

const wasDiscovered = store.getDiscovered(target);
Expand Down
19 changes: 13 additions & 6 deletions src/scenes/ui/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export class Menu extends UIContainer {
this.drawAction("[E] Observe", 0);
this.drawAction("[F] Touch", 1);
this.drawAction("[Q] Smell", 2);
this.drawAction("[R] Research " + (discovered === 100 ? "🔓" : "🔒"), 3);
this.drawAction(
"[R] Research " + (discovered === 100 ? "" : "🔒"),
3,
discovered !== 100
);
}

subscribeToEvents() {
Expand All @@ -69,11 +73,14 @@ export class Menu extends UIContainer {
this.store.changed("interactables", updateVisibility);
}

drawAction(title: string, n: number) {
this.drawText(Menu.WIDTH / 2, this.lineY + 8 + n * 30, title, 22).setOrigin(
0.5,
0
);
drawAction(title: string, n: number, disabled: boolean = false) {
this.drawText(
Menu.WIDTH / 2,
this.lineY + 8 + n * 30,
title,
22,
disabled ? "gray" : "black"
).setOrigin(0.5, 0);
}

update() {
Expand Down
38 changes: 29 additions & 9 deletions src/scenes/ui/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,44 @@ import { screenSize } from "../../constants";
export class Notification extends UIContainer {
static readonly WIDTH = 400;
static readonly HEIGHT = 50;
static readonly PADDING = 16;

private messageIndex = 0;

constructor(scene: MainGame) {
const padding = 16;
super(scene, screenSize.x - Notification.WIDTH - padding, padding);
super(scene, screenSize.x, Notification.PADDING);
}

draw(message: string = "") {
this.clear();

this.drawRoundRect(0, 0, Notification.WIDTH, Notification.HEIGHT);

this.drawText(
Notification.WIDTH / 2,
Notification.HEIGHT / 2,
message
).setOrigin(0.5, 0.5);
const textObj = new Phaser.GameObjects.Text(
this.scene,
this.offsetX - 48,
Notification.HEIGHT / 2 + Notification.PADDING,
message,
{
fontFamily: 'Georgia, "Goudy Bookletter 1911", Times, serif',
fontSize: "20px",
}
)
.setOrigin(1, 0.5)
.setColor("black");
this.children.push(textObj);
this.layer.add(textObj);

this.drawRoundRect(
-textObj.width - 64,
0,
textObj.width + 32,
Notification.HEIGHT
);

// this.drawText(
// Notification.WIDTH / 2,
// Notification.HEIGHT / 2,
// message
// ).setOrigin(0.5, 0.5);
}

displayNotification(message: string) {
Expand Down

0 comments on commit 90a33fe

Please sign in to comment.