Run Prettier

This commit is contained in:
Pyrex 2025-02-22 13:32:07 -08:00
parent 9e7ca67f55
commit bfc1e53f3e
12 changed files with 163 additions and 90 deletions

View File

@ -1,6 +1,12 @@
import { DrawPile } from "./drawpile.ts"; import { DrawPile } from "./drawpile.ts";
import { AlignX, AlignY, Point, Rect, Size } from "./engine/datatypes.ts"; import { AlignX, AlignY, Point, Rect, Size } from "./engine/datatypes.ts";
import {BG_INSET, FG_BOLD, FG_TEXT, FG_TEXT_DISABLED, FG_TEXT_ENDORSED} from "./colors.ts"; import {
BG_INSET,
FG_BOLD,
FG_TEXT,
FG_TEXT_DISABLED,
FG_TEXT_ENDORSED,
} from "./colors.ts";
import { D } from "./engine/public.ts"; import { D } from "./engine/public.ts";
export function addButton( export function addButton(
@ -10,8 +16,8 @@ export function addButton(
enabled: boolean, enabled: boolean,
cbClick: () => void, cbClick: () => void,
options?: { options?: {
endorse?: boolean endorse?: boolean;
} },
) { ) {
let padding = 2; let padding = 2;
let topLeft = rect.top; let topLeft = rect.top;

View File

@ -118,20 +118,27 @@ export class CheckModal {
resultMessage = hasSkill ? option.success : option.failure; resultMessage = hasSkill ? option.success : option.failure;
accomplished = hasSkill; accomplished = hasSkill;
} }
addButton(this.#drawpile, optionLabel, rect, true, () => { addButton(
this.#success = resultMessage; this.#drawpile,
optionLabel,
rect,
true,
() => {
this.#success = resultMessage;
if (accomplished) { if (accomplished) {
let cb = this.#callback; let cb = this.#callback;
if (cb) { if (cb) {
cb(); cb();
}
} }
}
if (resultMessage == null) { if (resultMessage == null) {
this.show(null, null); this.show(null, null);
} }
}, {endorse}); },
{ endorse },
);
}; };
if (options.length == 0) { if (options.length == 0) {

View File

@ -3,9 +3,9 @@ import { DrawPile } from "./drawpile.ts";
import { withCamera } from "./layout.ts"; import { withCamera } from "./layout.ts";
import { getSkillsModal } from "./skillsmodal.ts"; import { getSkillsModal } from "./skillsmodal.ts";
import { addButton } from "./button.ts"; import { addButton } from "./button.ts";
import {getPlayerProgress} from "./playerprogress.ts"; import { getPlayerProgress } from "./playerprogress.ts";
import {getStateManager} from "./statemanager.ts"; import { getStateManager } from "./statemanager.ts";
import {getCheckModal} from "./checkmodal.ts"; import { getCheckModal } from "./checkmodal.ts";
type Button = { type Button = {
label: string; label: string;
@ -47,7 +47,9 @@ export class Hotbar {
*/ */
buttons.push({ buttons.push({
label: "Sleep", label: "Sleep",
cbClick: () => { this.#offerSleep(); }, cbClick: () => {
this.#offerSleep();
},
enabled: true, enabled: true,
endorse: getPlayerProgress().getBlood() < 100, endorse: getPlayerProgress().getBlood() < 100,
}); });
@ -58,9 +60,10 @@ export class Hotbar {
let bloodAmount = getPlayerProgress().getBlood(); let bloodAmount = getPlayerProgress().getBlood();
let sleepText = "You're exhausted."; let sleepText = "You're exhausted.";
if (bloodAmount > 100) { if (bloodAmount > 100) {
sleepText = "You've got some energy left -- are you sure you want to sleep?"; sleepText =
"You've got some energy left -- are you sure you want to sleep?";
} else if (bloodAmount > 2000) { } else if (bloodAmount > 2000) {
sleepText = "Are you sure you want to sleep? You have so much energy."; sleepText = "Are you sure you want to sleep? You have so much energy.";
} }
getCheckModal().show( getCheckModal().show(
@ -79,12 +82,12 @@ export class Hotbar {
unlockable: "Refrain", unlockable: "Refrain",
success: null, success: null,
}, },
] ],
}, },
() => { () => {
getStateManager().advance(); getStateManager().advance();
} },
) );
} }
update() { update() {
@ -106,7 +109,7 @@ export class Hotbar {
new Rect(new Point(x, 0), cellSize), new Rect(new Point(x, 0), cellSize),
b.enabled, b.enabled,
b.cbClick, b.cbClick,
{endorse: b.endorse} { endorse: b.endorse },
); );
x += cellSize.w; x += cellSize.w;
} }

View File

@ -1,27 +1,35 @@
import { D } from "./engine/public.ts"; import { D } from "./engine/public.ts";
import { Point, Size } from "./engine/datatypes.ts"; import { Point, Size } from "./engine/datatypes.ts";
import {BG_OUTER, FG_BOLD, FG_TEXT, FG_TEXT_ENDORSED, FG_TOO_EXPENSIVE} from "./colors.ts"; import {
BG_OUTER,
FG_BOLD,
FG_TEXT,
FG_TEXT_ENDORSED,
FG_TOO_EXPENSIVE,
} from "./colors.ts";
import { ALL_STATS } from "./datatypes.ts"; import { ALL_STATS } from "./datatypes.ts";
import { getPlayerProgress } from "./playerprogress.ts"; import { getPlayerProgress } from "./playerprogress.ts";
import { getHuntMode } from "./huntmode.ts"; import { getHuntMode } from "./huntmode.ts";
import { getStateManager } from "./statemanager.ts"; import { getStateManager } from "./statemanager.ts";
import {withCamera} from "./layout.ts"; import { withCamera } from "./layout.ts";
export class Hud { export class Hud {
get size(): Size { get size(): Size {
return new Size(96, 176); return new Size(96, 176);
} }
update() { update() {
withCamera("HUD", () => { this.#update() }); withCamera("HUD", () => {
this.#update();
});
} }
draw() { draw() {
withCamera("HUD", () => { this.#draw() }); withCamera("HUD", () => {
this.#draw();
});
} }
#update() {} #update() {}
#draw() { #draw() {
@ -59,8 +67,12 @@ export class Hud {
D.drawText("BLD", new Point(0, 160), FG_BOLD); D.drawText("BLD", new Point(0, 160), FG_BOLD);
let bloodAmount = prog.getBlood(); let bloodAmount = prog.getBlood();
let bloodColor = FG_TEXT; let bloodColor = FG_TEXT;
if (bloodAmount > 2000) { bloodColor = FG_TEXT_ENDORSED; } if (bloodAmount > 2000) {
if (bloodAmount < 100) { bloodColor = FG_TOO_EXPENSIVE; } bloodColor = FG_TEXT_ENDORSED;
}
if (bloodAmount < 100) {
bloodColor = FG_TOO_EXPENSIVE;
}
D.drawText(`${prog.getBlood()}cc`, new Point(32, 160), bloodColor); D.drawText(`${prog.getBlood()}cc`, new Point(32, 160), bloodColor);
} }
} }

View File

@ -1,7 +1,7 @@
import {Point, Size} from "./engine/datatypes.ts"; import { Point, Size } from "./engine/datatypes.ts";
import {DrawPile} from "./drawpile.ts"; import { DrawPile } from "./drawpile.ts";
import {D} from "./engine/public.ts"; import { D } from "./engine/public.ts";
import {sprThrallLore} from "./sprites.ts"; import { sprThrallLore } from "./sprites.ts";
import { import {
BG_INSET, BG_INSET,
BG_WALL_OR_UNREVEALED, BG_WALL_OR_UNREVEALED,
@ -11,12 +11,12 @@ import {
FG_TEXT_ENDORSED, FG_TEXT_ENDORSED,
FG_TOO_EXPENSIVE, FG_TOO_EXPENSIVE,
} from "./colors.ts"; } from "./colors.ts";
import {getPlayerProgress} from "./playerprogress.ts"; import { getPlayerProgress } from "./playerprogress.ts";
import {Architecture, LoadedNewMap} from "./newmap.ts"; import { Architecture, LoadedNewMap } from "./newmap.ts";
import {FLOOR_CELL_SIZE, GridArt} from "./gridart.ts"; import { FLOOR_CELL_SIZE, GridArt } from "./gridart.ts";
import {shadowcast} from "./shadowcast.ts"; import { shadowcast } from "./shadowcast.ts";
import {getCheckModal} from "./checkmodal.ts"; import { getCheckModal } from "./checkmodal.ts";
import {withCamera} from "./layout.ts"; import { withCamera } from "./layout.ts";
export class HuntMode { export class HuntMode {
map: LoadedNewMap; map: LoadedNewMap;
@ -95,10 +95,14 @@ export class HuntMode {
// draw // draw
update() { update() {
withCamera("Gameplay", () => { this.#update() }); withCamera("Gameplay", () => {
this.#update();
});
} }
draw() { draw() {
withCamera("Gameplay", () => { this.#draw() }); withCamera("Gameplay", () => {
this.#draw();
});
} }
#update() { #update() {
@ -156,7 +160,6 @@ export class HuntMode {
let dx = x - this.player.x; let dx = x - this.player.x;
let dy = y - this.player.y; let dy = y - this.player.y;
return dx * dx + dy * dy < 13; return dx * dx + dy * dy < 13;
} }
#draw() { #draw() {
@ -192,7 +195,7 @@ export class HuntMode {
// draw inset zone // draw inset zone
let cost = this.#computeCostToClick(mapPosition); let cost = this.#computeCostToClick(mapPosition);
let tooExpensive = cost != null && (cost > getPlayerProgress().getBlood()); let tooExpensive = cost != null && cost > getPlayerProgress().getBlood();
this.drawpile.addClickable( this.drawpile.addClickable(
OFFSET_FLOOR, OFFSET_FLOOR,
(hover: boolean) => { (hover: boolean) => {
@ -218,7 +221,9 @@ export class HuntMode {
gridArt.floorRect, gridArt.floorRect,
true, true,
() => { () => {
if (cost == null || tooExpensive) { return; } if (cost == null || tooExpensive) {
return;
}
if (pickup?.onClick(cellData)) { if (pickup?.onClick(cellData)) {
return; return;
} }
@ -315,24 +320,30 @@ export class HuntMode {
} }
#drawBadge(globalOffset: Point, cell: Point) { #drawBadge(globalOffset: Point, cell: Point) {
if (!this.map.get(cell).pickup?.advertisesBadge()) { return; } if (!this.map.get(cell).pickup?.advertisesBadge()) {
return;
}
// NOTE: This doesn't think of visibility at all // NOTE: This doesn't think of visibility at all
let badgePosition = cell.offset(new Size(-0.25, -0.25)); let badgePosition = cell.offset(new Size(-0.25, -0.25));
badgePosition = badgePosition.offset(new Point( badgePosition = badgePosition.offset(
Math.cos(cell.x * 2 + this.frame / 720 * 2 * Math.PI) * 0.05, new Point(
Math.sin(cell.y + this.frame / 480 * 2 * Math.PI) * 0.10 Math.cos(cell.x * 2 + (this.frame / 720) * 2 * Math.PI) * 0.05,
)); Math.sin(cell.y + (this.frame / 480) * 2 * Math.PI) * 0.1,
),
);
let cellOffset = new Point( let cellOffset = new Point(
badgePosition.x * FLOOR_CELL_SIZE.w, badgePosition.x * FLOOR_CELL_SIZE.w,
badgePosition.y * FLOOR_CELL_SIZE.h badgePosition.y * FLOOR_CELL_SIZE.h,
).offset(globalOffset.negate()); ).offset(globalOffset.negate());
let center = new Point(192, 192); let center = new Point(192, 192);
cellOffset = cellOffset.offset(center.negate()); cellOffset = cellOffset.offset(center.negate());
let dist = Math.sqrt(cellOffset.x * cellOffset.x + cellOffset.y * cellOffset.y); let dist = Math.sqrt(
let ang = Math.atan2(cellOffset.y, cellOffset.x) cellOffset.x * cellOffset.x + cellOffset.y * cellOffset.y,
);
let ang = Math.atan2(cellOffset.y, cellOffset.x);
// console.log(dist, ang); // console.log(dist, ang);
dist = Math.min(dist, 128); dist = Math.min(dist, 128);
cellOffset = new Point(Math.cos(ang) * dist, Math.sin(ang) * dist); cellOffset = new Point(Math.cos(ang) * dist, Math.sin(ang) * dist);
@ -340,7 +351,11 @@ export class HuntMode {
this.drawpile.add(1024, () => { this.drawpile.add(1024, () => {
// draw badge // draw badge
D.fillRect(cellOffset.offset(new Point(-4, -4)), new Size(8, 8), FG_TEXT_ENDORSED) D.fillRect(
cellOffset.offset(new Point(-4, -4)),
new Size(8, 8),
FG_TEXT_ENDORSED,
);
}); });
} }
} }

View File

@ -62,7 +62,6 @@ export type UIPart =
| "Gameplay" | "Gameplay"
| "Thralls"; | "Thralls";
export function getPartLocation(part: UIPart) { export function getPartLocation(part: UIPart) {
switch (part) { switch (part) {
case "BottomModal": case "BottomModal":

View File

@ -32,7 +32,7 @@ export class LoadedNewMap {
#entrance: Point | null; #entrance: Point | null;
#architecture: Grid<Architecture>; #architecture: Grid<Architecture>;
#pickups: Grid<Pickup | null>; #pickups: Grid<Pickup | null>;
#provinces: Grid<string | null>; // TODO: Does this just duplicate zoneLabels #provinces: Grid<string | null>; // TODO: Does this just duplicate zoneLabels
#revealed: Grid<boolean>; #revealed: Grid<boolean>;
#zoneLabels: Grid<string | null>; #zoneLabels: Grid<string | null>;

View File

@ -1,16 +1,21 @@
import {getThralls, ItemStage, LifeStage, Thrall} from "./thralls.ts"; import { getThralls, ItemStage, LifeStage, Thrall } from "./thralls.ts";
import {CellView, CheckData} from "./newmap.ts"; import { CellView, CheckData } from "./newmap.ts";
import {getPlayerProgress} from "./playerprogress.ts"; import { getPlayerProgress } from "./playerprogress.ts";
import {getHuntMode, HuntMode, initHuntMode} from "./huntmode.ts"; import { getHuntMode, HuntMode, initHuntMode } from "./huntmode.ts";
import {generateMap} from "./mapgen.ts"; import { generateMap } from "./mapgen.ts";
import {ALL_STATS, Stat} from "./datatypes.ts"; import { ALL_STATS, Stat } from "./datatypes.ts";
import {D} from "./engine/public.ts"; import { D } from "./engine/public.ts";
import {sprLadder, sprLock, sprResourcePickup, sprStatPickup,} from "./sprites.ts"; import {
import {GridArt} from "./gridart.ts"; sprLadder,
import {getCheckModal} from "./checkmodal.ts"; sprLock,
import {Point, Size} from "./engine/datatypes.ts"; sprResourcePickup,
import {choose} from "./utils.ts"; sprStatPickup,
import {FG_TEXT} from "./colors.ts"; } from "./sprites.ts";
import { GridArt } from "./gridart.ts";
import { getCheckModal } from "./checkmodal.ts";
import { Point, Size } from "./engine/datatypes.ts";
import { choose } from "./utils.ts";
import { FG_TEXT } from "./colors.ts";
export type Pickup = export type Pickup =
| LockPickup | LockPickup
@ -370,7 +375,11 @@ export class ThrallCollectionPlatePickup {
return true; return true;
} }
if (itemStage == ItemStage.Delivered && lifeStage != LifeStage.Dead && !this.rewarded) { if (
itemStage == ItemStage.Delivered &&
lifeStage != LifeStage.Dead &&
!this.rewarded
) {
// the player should collect it! make sure they see a badge informing them of that // the player should collect it! make sure they see a badge informing them of that
return true; return true;
} }

View File

@ -279,7 +279,9 @@ export class PlayerProgress {
let skills = this.getAvailableSkills(); let skills = this.getAvailableSkills();
for (let skill of skills.values()) { for (let skill of skills.values()) {
if (getSkills().isAtMinimum(skill)) { if (getSkills().isAtMinimum(skill)) {
if (getPlayerProgress().getExperience() > getSkills().computeCost(skill)) { if (
getPlayerProgress().getExperience() > getSkills().computeCost(skill)
) {
return true; return true;
} }
} }

View File

@ -70,7 +70,7 @@ class SkillsTable {
} }
isAtMinimum(skill: Skill) { isAtMinimum(skill: Skill) {
let minimumCost = this.get(skill).governing.cost let minimumCost = this.get(skill).governing.cost;
let currentCost = this.computeCost(skill); let currentCost = this.computeCost(skill);
return currentCost <= minimumCost; return currentCost <= minimumCost;
} }

View File

@ -2,7 +2,12 @@ import { getPartLocation, withCamera } from "./layout.ts";
import { AlignX, Point, Rect, Size } from "./engine/datatypes.ts"; import { AlignX, Point, Rect, Size } from "./engine/datatypes.ts";
import { DrawPile } from "./drawpile.ts"; import { DrawPile } from "./drawpile.ts";
import { D } from "./engine/public.ts"; import { D } from "./engine/public.ts";
import {BG_INSET, FG_BOLD, FG_TEXT_DISABLED, FG_TEXT_ENDORSED} from "./colors.ts"; import {
BG_INSET,
FG_BOLD,
FG_TEXT_DISABLED,
FG_TEXT_ENDORSED,
} from "./colors.ts";
import { addButton } from "./button.ts"; import { addButton } from "./button.ts";
import { getSkills } from "./skills.ts"; import { getSkills } from "./skills.ts";
import { getPlayerProgress } from "./playerprogress.ts"; import { getPlayerProgress } from "./playerprogress.ts";
@ -68,7 +73,9 @@ export class SkillsModal {
// two column layout // two column layout
let [bg, fg] = [BG_INSET, FG_BOLD]; let [bg, fg] = [BG_INSET, FG_BOLD];
let overpriced = getSkills().computeCost(skill) > getPlayerProgress().getExperience(); let overpriced =
getSkills().computeCost(skill) >
getPlayerProgress().getExperience();
let atMinimum = getSkills().isAtMinimum(skill); let atMinimum = getSkills().isAtMinimum(skill);
if (overpriced) { if (overpriced) {
fg = FG_TEXT_DISABLED; fg = FG_TEXT_DISABLED;
@ -127,21 +134,34 @@ export class SkillsModal {
endorse = false; endorse = false;
} }
addButton(this.#drawpile, caption, drawButtonRect, canAfford, () => { addButton(
getPlayerProgress().spendExperience(cost); this.#drawpile,
getPlayerProgress().learnSkill(selection); caption,
}, { drawButtonRect,
endorse canAfford,
}); () => {
getPlayerProgress().spendExperience(cost);
getPlayerProgress().learnSkill(selection);
},
{
endorse,
},
);
} }
// add close button // add close button
let endorseBack = availableSkills.length == 0; let endorseBack = availableSkills.length == 0;
let closeRect = new Rect(new Point(0, 96), new Size(160, 32)); let closeRect = new Rect(new Point(0, 96), new Size(160, 32));
addButton(this.#drawpile, "Back", closeRect, true, () => { addButton(
this.setShown(false); this.#drawpile,
}, {endorse: endorseBack}); "Back",
closeRect,
true,
() => {
this.setShown(false);
},
{ endorse: endorseBack },
);
this.#drawpile.executeOnClick(); this.#drawpile.executeOnClick();
} }

View File

@ -33,10 +33,10 @@ import {
export type VaultTemplate = { export type VaultTemplate = {
stats: { primary: Stat; secondary: Stat }; stats: { primary: Stat; secondary: Stat };
roomLabels: { roomLabels: {
hall: string, hall: string;
backroom: string, backroom: string;
closet: string, closet: string;
} };
thrall: () => Thrall; thrall: () => Thrall;
thrallItem: () => Thrall; thrallItem: () => Thrall;
checks: [CheckData, CheckData]; checks: [CheckData, CheckData];