Run Prettier
This commit is contained in:
		| @@ -1,6 +1,12 @@ | ||||
| import { DrawPile } from "./drawpile.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"; | ||||
|  | ||||
| export function addButton( | ||||
| @@ -10,8 +16,8 @@ export function addButton( | ||||
|   enabled: boolean, | ||||
|   cbClick: () => void, | ||||
|   options?: { | ||||
|     endorse?: boolean | ||||
|   } | ||||
|     endorse?: boolean; | ||||
|   }, | ||||
| ) { | ||||
|   let padding = 2; | ||||
|   let topLeft = rect.top; | ||||
|   | ||||
| @@ -118,20 +118,27 @@ export class CheckModal { | ||||
|         resultMessage = hasSkill ? option.success : option.failure; | ||||
|         accomplished = hasSkill; | ||||
|       } | ||||
|       addButton(this.#drawpile, optionLabel, rect, true, () => { | ||||
|         this.#success = resultMessage; | ||||
|       addButton( | ||||
|         this.#drawpile, | ||||
|         optionLabel, | ||||
|         rect, | ||||
|         true, | ||||
|         () => { | ||||
|           this.#success = resultMessage; | ||||
|  | ||||
|         if (accomplished) { | ||||
|           let cb = this.#callback; | ||||
|           if (cb) { | ||||
|             cb(); | ||||
|           if (accomplished) { | ||||
|             let cb = this.#callback; | ||||
|             if (cb) { | ||||
|               cb(); | ||||
|             } | ||||
|           } | ||||
|         } | ||||
|  | ||||
|         if (resultMessage == null) { | ||||
|           this.show(null, null); | ||||
|         } | ||||
|       }, {endorse}); | ||||
|           if (resultMessage == null) { | ||||
|             this.show(null, null); | ||||
|           } | ||||
|         }, | ||||
|         { endorse }, | ||||
|       ); | ||||
|     }; | ||||
|  | ||||
|     if (options.length == 0) { | ||||
|   | ||||
| @@ -3,9 +3,9 @@ import { DrawPile } from "./drawpile.ts"; | ||||
| import { withCamera } from "./layout.ts"; | ||||
| import { getSkillsModal } from "./skillsmodal.ts"; | ||||
| import { addButton } from "./button.ts"; | ||||
| import {getPlayerProgress} from "./playerprogress.ts"; | ||||
| import {getStateManager} from "./statemanager.ts"; | ||||
| import {getCheckModal} from "./checkmodal.ts"; | ||||
| import { getPlayerProgress } from "./playerprogress.ts"; | ||||
| import { getStateManager } from "./statemanager.ts"; | ||||
| import { getCheckModal } from "./checkmodal.ts"; | ||||
|  | ||||
| type Button = { | ||||
|   label: string; | ||||
| @@ -47,7 +47,9 @@ export class Hotbar { | ||||
|      */ | ||||
|     buttons.push({ | ||||
|       label: "Sleep", | ||||
|       cbClick: () => { this.#offerSleep(); }, | ||||
|       cbClick: () => { | ||||
|         this.#offerSleep(); | ||||
|       }, | ||||
|       enabled: true, | ||||
|       endorse: getPlayerProgress().getBlood() < 100, | ||||
|     }); | ||||
| @@ -58,9 +60,10 @@ export class Hotbar { | ||||
|     let bloodAmount = getPlayerProgress().getBlood(); | ||||
|     let sleepText = "You're exhausted."; | ||||
|     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) { | ||||
|         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( | ||||
| @@ -79,12 +82,12 @@ export class Hotbar { | ||||
|             unlockable: "Refrain", | ||||
|             success: null, | ||||
|           }, | ||||
|         ] | ||||
|         ], | ||||
|       }, | ||||
|       () => { | ||||
|         getStateManager().advance(); | ||||
|       } | ||||
|     ) | ||||
|       }, | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   update() { | ||||
| @@ -106,7 +109,7 @@ export class Hotbar { | ||||
|         new Rect(new Point(x, 0), cellSize), | ||||
|         b.enabled, | ||||
|         b.cbClick, | ||||
|         {endorse: b.endorse} | ||||
|         { endorse: b.endorse }, | ||||
|       ); | ||||
|       x += cellSize.w; | ||||
|     } | ||||
|   | ||||
							
								
								
									
										28
									
								
								src/hud.ts
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								src/hud.ts
									
									
									
									
									
								
							| @@ -1,27 +1,35 @@ | ||||
| import { D } from "./engine/public.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 { getPlayerProgress } from "./playerprogress.ts"; | ||||
| import { getHuntMode } from "./huntmode.ts"; | ||||
| import { getStateManager } from "./statemanager.ts"; | ||||
| import {withCamera} from "./layout.ts"; | ||||
| import { withCamera } from "./layout.ts"; | ||||
|  | ||||
| export class Hud { | ||||
|   get size(): Size { | ||||
|     return new Size(96, 176); | ||||
|   } | ||||
|  | ||||
|  | ||||
|   update() { | ||||
|     withCamera("HUD", () => { this.#update() }); | ||||
|     withCamera("HUD", () => { | ||||
|       this.#update(); | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   draw() { | ||||
|     withCamera("HUD", () => { this.#draw() }); | ||||
|     withCamera("HUD", () => { | ||||
|       this.#draw(); | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|  | ||||
|   #update() {} | ||||
|  | ||||
|   #draw() { | ||||
| @@ -59,8 +67,12 @@ export class Hud { | ||||
|     D.drawText("BLD", new Point(0, 160), FG_BOLD); | ||||
|     let bloodAmount = prog.getBlood(); | ||||
|     let bloodColor = FG_TEXT; | ||||
|     if (bloodAmount > 2000) { bloodColor = FG_TEXT_ENDORSED; } | ||||
|     if (bloodAmount < 100) { bloodColor = FG_TOO_EXPENSIVE; } | ||||
|     if (bloodAmount > 2000) { | ||||
|       bloodColor = FG_TEXT_ENDORSED; | ||||
|     } | ||||
|     if (bloodAmount < 100) { | ||||
|       bloodColor = FG_TOO_EXPENSIVE; | ||||
|     } | ||||
|     D.drawText(`${prog.getBlood()}cc`, new Point(32, 160), bloodColor); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| import {Point, Size} from "./engine/datatypes.ts"; | ||||
| import {DrawPile} from "./drawpile.ts"; | ||||
| import {D} from "./engine/public.ts"; | ||||
| import {sprThrallLore} from "./sprites.ts"; | ||||
| import { Point, Size } from "./engine/datatypes.ts"; | ||||
| import { DrawPile } from "./drawpile.ts"; | ||||
| import { D } from "./engine/public.ts"; | ||||
| import { sprThrallLore } from "./sprites.ts"; | ||||
| import { | ||||
|   BG_INSET, | ||||
|   BG_WALL_OR_UNREVEALED, | ||||
| @@ -11,12 +11,12 @@ import { | ||||
|   FG_TEXT_ENDORSED, | ||||
|   FG_TOO_EXPENSIVE, | ||||
| } from "./colors.ts"; | ||||
| import {getPlayerProgress} from "./playerprogress.ts"; | ||||
| import {Architecture, LoadedNewMap} from "./newmap.ts"; | ||||
| import {FLOOR_CELL_SIZE, GridArt} from "./gridart.ts"; | ||||
| import {shadowcast} from "./shadowcast.ts"; | ||||
| import {getCheckModal} from "./checkmodal.ts"; | ||||
| import {withCamera} from "./layout.ts"; | ||||
| import { getPlayerProgress } from "./playerprogress.ts"; | ||||
| import { Architecture, LoadedNewMap } from "./newmap.ts"; | ||||
| import { FLOOR_CELL_SIZE, GridArt } from "./gridart.ts"; | ||||
| import { shadowcast } from "./shadowcast.ts"; | ||||
| import { getCheckModal } from "./checkmodal.ts"; | ||||
| import { withCamera } from "./layout.ts"; | ||||
|  | ||||
| export class HuntMode { | ||||
|   map: LoadedNewMap; | ||||
| @@ -95,10 +95,14 @@ export class HuntMode { | ||||
|  | ||||
|   // draw | ||||
|   update() { | ||||
|     withCamera("Gameplay", () => { this.#update() }); | ||||
|     withCamera("Gameplay", () => { | ||||
|       this.#update(); | ||||
|     }); | ||||
|   } | ||||
|   draw() { | ||||
|     withCamera("Gameplay", () => { this.#draw() }); | ||||
|     withCamera("Gameplay", () => { | ||||
|       this.#draw(); | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   #update() { | ||||
| @@ -156,7 +160,6 @@ export class HuntMode { | ||||
|     let dx = x - this.player.x; | ||||
|     let dy = y - this.player.y; | ||||
|     return dx * dx + dy * dy < 13; | ||||
|  | ||||
|   } | ||||
|  | ||||
|   #draw() { | ||||
| @@ -192,7 +195,7 @@ export class HuntMode { | ||||
|  | ||||
|     // draw inset zone | ||||
|     let cost = this.#computeCostToClick(mapPosition); | ||||
|     let tooExpensive = cost != null && (cost > getPlayerProgress().getBlood()); | ||||
|     let tooExpensive = cost != null && cost > getPlayerProgress().getBlood(); | ||||
|     this.drawpile.addClickable( | ||||
|       OFFSET_FLOOR, | ||||
|       (hover: boolean) => { | ||||
| @@ -218,7 +221,9 @@ export class HuntMode { | ||||
|       gridArt.floorRect, | ||||
|       true, | ||||
|       () => { | ||||
|         if (cost == null || tooExpensive) { return; } | ||||
|         if (cost == null || tooExpensive) { | ||||
|           return; | ||||
|         } | ||||
|         if (pickup?.onClick(cellData)) { | ||||
|           return; | ||||
|         } | ||||
| @@ -315,24 +320,30 @@ export class HuntMode { | ||||
|   } | ||||
|  | ||||
|   #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 | ||||
|     let badgePosition = cell.offset(new Size(-0.25, -0.25)); | ||||
|     badgePosition = badgePosition.offset(new Point( | ||||
|       Math.cos(cell.x * 2 + this.frame / 720 * 2 * Math.PI) * 0.05, | ||||
|       Math.sin(cell.y + this.frame / 480 * 2 * Math.PI) * 0.10 | ||||
|     )); | ||||
|     badgePosition = badgePosition.offset( | ||||
|       new Point( | ||||
|         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( | ||||
|       badgePosition.x * FLOOR_CELL_SIZE.w, | ||||
|       badgePosition.y * FLOOR_CELL_SIZE.h | ||||
|       badgePosition.y * FLOOR_CELL_SIZE.h, | ||||
|     ).offset(globalOffset.negate()); | ||||
|  | ||||
|     let center = new Point(192, 192); | ||||
|     cellOffset = cellOffset.offset(center.negate()); | ||||
|  | ||||
|     let dist = Math.sqrt(cellOffset.x * cellOffset.x + cellOffset.y * cellOffset.y); | ||||
|     let ang = Math.atan2(cellOffset.y, cellOffset.x) | ||||
|     let dist = Math.sqrt( | ||||
|       cellOffset.x * cellOffset.x + cellOffset.y * cellOffset.y, | ||||
|     ); | ||||
|     let ang = Math.atan2(cellOffset.y, cellOffset.x); | ||||
|     // console.log(dist, ang); | ||||
|     dist = Math.min(dist, 128); | ||||
|     cellOffset = new Point(Math.cos(ang) * dist, Math.sin(ang) * dist); | ||||
| @@ -340,7 +351,11 @@ export class HuntMode { | ||||
|  | ||||
|     this.drawpile.add(1024, () => { | ||||
|       // 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, | ||||
|       ); | ||||
|     }); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -62,7 +62,6 @@ export type UIPart = | ||||
|   | "Gameplay" | ||||
|   | "Thralls"; | ||||
|  | ||||
|  | ||||
| export function getPartLocation(part: UIPart) { | ||||
|   switch (part) { | ||||
|     case "BottomModal": | ||||
|   | ||||
| @@ -32,7 +32,7 @@ export class LoadedNewMap { | ||||
|   #entrance: Point | null; | ||||
|   #architecture: Grid<Architecture>; | ||||
|   #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>; | ||||
|   #zoneLabels: Grid<string | null>; | ||||
|  | ||||
|   | ||||
| @@ -1,16 +1,21 @@ | ||||
| import {getThralls, ItemStage, LifeStage, Thrall} from "./thralls.ts"; | ||||
| import {CellView, CheckData} from "./newmap.ts"; | ||||
| import {getPlayerProgress} from "./playerprogress.ts"; | ||||
| import {getHuntMode, HuntMode, initHuntMode} from "./huntmode.ts"; | ||||
| import {generateMap} from "./mapgen.ts"; | ||||
| import {ALL_STATS, Stat} from "./datatypes.ts"; | ||||
| import {D} from "./engine/public.ts"; | ||||
| import {sprLadder, sprLock, sprResourcePickup, sprStatPickup,} 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"; | ||||
| import { getThralls, ItemStage, LifeStage, Thrall } from "./thralls.ts"; | ||||
| import { CellView, CheckData } from "./newmap.ts"; | ||||
| import { getPlayerProgress } from "./playerprogress.ts"; | ||||
| import { getHuntMode, HuntMode, initHuntMode } from "./huntmode.ts"; | ||||
| import { generateMap } from "./mapgen.ts"; | ||||
| import { ALL_STATS, Stat } from "./datatypes.ts"; | ||||
| import { D } from "./engine/public.ts"; | ||||
| import { | ||||
|   sprLadder, | ||||
|   sprLock, | ||||
|   sprResourcePickup, | ||||
|   sprStatPickup, | ||||
| } 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 = | ||||
|   | LockPickup | ||||
| @@ -370,7 +375,11 @@ export class ThrallCollectionPlatePickup { | ||||
|       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 | ||||
|       return true; | ||||
|     } | ||||
|   | ||||
| @@ -279,7 +279,9 @@ export class PlayerProgress { | ||||
|     let skills = this.getAvailableSkills(); | ||||
|     for (let skill of skills.values()) { | ||||
|       if (getSkills().isAtMinimum(skill)) { | ||||
|         if (getPlayerProgress().getExperience() > getSkills().computeCost(skill)) { | ||||
|         if ( | ||||
|           getPlayerProgress().getExperience() > getSkills().computeCost(skill) | ||||
|         ) { | ||||
|           return true; | ||||
|         } | ||||
|       } | ||||
|   | ||||
| @@ -70,7 +70,7 @@ class SkillsTable { | ||||
|   } | ||||
|  | ||||
|   isAtMinimum(skill: Skill) { | ||||
|     let minimumCost = this.get(skill).governing.cost | ||||
|     let minimumCost = this.get(skill).governing.cost; | ||||
|     let currentCost = this.computeCost(skill); | ||||
|     return currentCost <= minimumCost; | ||||
|   } | ||||
|   | ||||
| @@ -2,7 +2,12 @@ import { getPartLocation, withCamera } from "./layout.ts"; | ||||
| import { AlignX, Point, Rect, Size } from "./engine/datatypes.ts"; | ||||
| import { DrawPile } from "./drawpile.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 { getSkills } from "./skills.ts"; | ||||
| import { getPlayerProgress } from "./playerprogress.ts"; | ||||
| @@ -68,7 +73,9 @@ export class SkillsModal { | ||||
|           // two column layout | ||||
|           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); | ||||
|           if (overpriced) { | ||||
|             fg = FG_TEXT_DISABLED; | ||||
| @@ -127,21 +134,34 @@ export class SkillsModal { | ||||
|         endorse = false; | ||||
|       } | ||||
|  | ||||
|       addButton(this.#drawpile, caption, drawButtonRect, canAfford, () => { | ||||
|         getPlayerProgress().spendExperience(cost); | ||||
|         getPlayerProgress().learnSkill(selection); | ||||
|       }, { | ||||
|         endorse | ||||
|       }); | ||||
|       addButton( | ||||
|         this.#drawpile, | ||||
|         caption, | ||||
|         drawButtonRect, | ||||
|         canAfford, | ||||
|         () => { | ||||
|           getPlayerProgress().spendExperience(cost); | ||||
|           getPlayerProgress().learnSkill(selection); | ||||
|         }, | ||||
|         { | ||||
|           endorse, | ||||
|         }, | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     // add close button | ||||
|     let endorseBack = availableSkills.length == 0; | ||||
|     let closeRect = new Rect(new Point(0, 96), new Size(160, 32)); | ||||
|     addButton(this.#drawpile, "Back", closeRect, true, () => { | ||||
|       this.setShown(false); | ||||
|     }, {endorse: endorseBack}); | ||||
|     addButton( | ||||
|       this.#drawpile, | ||||
|       "Back", | ||||
|       closeRect, | ||||
|       true, | ||||
|       () => { | ||||
|         this.setShown(false); | ||||
|       }, | ||||
|       { endorse: endorseBack }, | ||||
|     ); | ||||
|     this.#drawpile.executeOnClick(); | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -33,10 +33,10 @@ import { | ||||
| export type VaultTemplate = { | ||||
|   stats: { primary: Stat; secondary: Stat }; | ||||
|   roomLabels: { | ||||
|     hall: string, | ||||
|     backroom: string, | ||||
|     closet: string, | ||||
|   } | ||||
|     hall: string; | ||||
|     backroom: string; | ||||
|     closet: string; | ||||
|   }; | ||||
|   thrall: () => Thrall; | ||||
|   thrallItem: () => Thrall; | ||||
|   checks: [CheckData, CheckData]; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user