161 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			161 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { Grid, Point, Size } from "./engine/datatypes.ts";
 | |
| import { Pickup } from "./pickups.ts";
 | |
| import { Skill } from "./datatypes.ts";
 | |
| 
 | |
| export enum Architecture {
 | |
|   Wall,
 | |
|   Floor,
 | |
| }
 | |
| 
 | |
| export type CheckData = {
 | |
|   label: string;
 | |
|   options: (CheckDataOption | ChoiceOption)[];
 | |
| };
 | |
| 
 | |
| export type ChoiceOption = {
 | |
|   isChoice: true;
 | |
|   countsAsSuccess: boolean;
 | |
|   unlockable: string;
 | |
|   success: string | null;
 | |
| };
 | |
| export type CheckDataOption = {
 | |
|   skill: () => Skill;
 | |
|   locked: string;
 | |
|   failure: string;
 | |
|   unlockable: string;
 | |
|   success: string | null;
 | |
| };
 | |
| 
 | |
| export class LoadedNewMap {
 | |
|   #id: string;
 | |
|   #size: Size;
 | |
|   #entrance: Point | null;
 | |
|   #architecture: Grid<Architecture>;
 | |
|   #pickups: Grid<Pickup | null>;
 | |
|   #provinces: Grid<string | null>; // TODO: Does this just duplicate zoneLabels
 | |
|   #revealed: Grid<boolean>;
 | |
|   #zoneLabels: Grid<string | null>;
 | |
| 
 | |
|   constructor(id: string, size: Size) {
 | |
|     this.#id = id;
 | |
|     this.#size = size;
 | |
|     this.#entrance = null;
 | |
|     this.#architecture = new Grid<Architecture>(size, () => Architecture.Wall);
 | |
|     this.#pickups = new Grid<Pickup | null>(size, () => null);
 | |
|     this.#provinces = new Grid<string | null>(size, () => null);
 | |
|     this.#revealed = new Grid<boolean>(size, () => false);
 | |
|     this.#zoneLabels = new Grid<string | null>(size, () => null);
 | |
|   }
 | |
| 
 | |
|   set entrance(point: Point) {
 | |
|     this.#entrance = point;
 | |
|   }
 | |
| 
 | |
|   get entrance(): Point {
 | |
|     if (this.#entrance == null) {
 | |
|       throw `${this.#id}: this.#entrance was never initialized`;
 | |
|     }
 | |
|     return this.#entrance;
 | |
|   }
 | |
| 
 | |
|   get size(): Size {
 | |
|     return this.#size;
 | |
|   }
 | |
| 
 | |
|   get(point: Point): CellView {
 | |
|     return new CellView(this, point);
 | |
|   }
 | |
| 
 | |
|   setArchitecture(point: Point, value: Architecture) {
 | |
|     this.#architecture.set(point, value);
 | |
|   }
 | |
| 
 | |
|   getArchitecture(point: Point): Architecture {
 | |
|     return this.#architecture.get(point);
 | |
|   }
 | |
| 
 | |
|   setPickup(point: Point, value: Pickup | null) {
 | |
|     this.#pickups.set(point, value);
 | |
|   }
 | |
| 
 | |
|   getPickup(point: Point): Pickup | null {
 | |
|     return this.#pickups.get(point);
 | |
|   }
 | |
| 
 | |
|   setProvince(point: Point, value: string | null) {
 | |
|     this.#provinces.set(point, value);
 | |
|   }
 | |
| 
 | |
|   getProvince(point: Point): string | null {
 | |
|     return this.#provinces.get(point);
 | |
|   }
 | |
| 
 | |
|   setRevealed(point: Point, value: boolean) {
 | |
|     this.#revealed.set(point, value);
 | |
|   }
 | |
| 
 | |
|   getRevealed(point: Point): boolean {
 | |
|     return this.#revealed.get(point);
 | |
|   }
 | |
| 
 | |
|   setZoneLabel(point: Point, value: string | null) {
 | |
|     this.#zoneLabels.set(point, value);
 | |
|   }
 | |
| 
 | |
|   getZoneLabel(point: Point): string | null {
 | |
|     return this.#zoneLabels.get(point);
 | |
|   }
 | |
| }
 | |
| 
 | |
| export class CellView {
 | |
|   #map: LoadedNewMap;
 | |
|   #point: Point;
 | |
| 
 | |
|   constructor(map: LoadedNewMap, point: Point) {
 | |
|     this.#map = map;
 | |
|     this.#point = point;
 | |
|   }
 | |
| 
 | |
|   set architecture(value: Architecture) {
 | |
|     this.#map.setArchitecture(this.#point, value);
 | |
|   }
 | |
|   get architecture(): Architecture {
 | |
|     return this.#map.getArchitecture(this.#point);
 | |
|   }
 | |
| 
 | |
|   set pickup(value: Pickup | null) {
 | |
|     this.#map.setPickup(this.#point, value);
 | |
|   }
 | |
|   get pickup(): Pickup | null {
 | |
|     return this.#map.getPickup(this.#point);
 | |
|   }
 | |
| 
 | |
|   set province(value: string | null) {
 | |
|     this.#map.setProvince(this.#point, value);
 | |
|   }
 | |
|   get province(): string | null {
 | |
|     return this.#map.getProvince(this.#point);
 | |
|   }
 | |
| 
 | |
|   set revealed(value: boolean) {
 | |
|     this.#map.setRevealed(this.#point, value);
 | |
|   }
 | |
|   get revealed(): boolean {
 | |
|     return this.#map.getRevealed(this.#point);
 | |
|   }
 | |
| 
 | |
|   set zoneLabel(value: string | null) {
 | |
|     this.#map.setZoneLabel(this.#point, value);
 | |
|   }
 | |
|   get zoneLabel(): string | null {
 | |
|     return this.#map.getZoneLabel(this.#point);
 | |
|   }
 | |
| 
 | |
|   copyFrom(cell: CellView) {
 | |
|     this.architecture = cell.architecture;
 | |
|     this.pickup = cell.pickup;
 | |
|     this.province = cell.province;
 | |
|     this.revealed = cell.revealed;
 | |
|   }
 | |
| }
 |