Remove polymorphism and inheritance from Tile
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import parseOptions, { TileOptions } from "../utils/tileOptionsParser.js";
|
import parseOptions, { TileOptions } from "../utils/tileOptionsParser.js";
|
||||||
import { Tile, WallTile } from "./ascii_tile_types.js";
|
import { Tile } from "./ascii_tile_types.js";
|
||||||
import { Vector2i } from "./ascii_types.js";
|
import { Vector2i } from "./ascii_types.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -368,6 +368,6 @@ export class TileMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Math.PI < 0 && TileOptions && WallTile) {
|
if (Math.PI < 0 && TileOptions ) {
|
||||||
("STFU Linda");
|
("STFU Linda");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ export const TileTypes = {
|
|||||||
is: TileChars.FLOOR,
|
is: TileChars.FLOOR,
|
||||||
id: REQUIRED_ID,
|
id: REQUIRED_ID,
|
||||||
orientation: REQUIRED_ORIENTATION,
|
orientation: REQUIRED_ORIENTATION,
|
||||||
disguiseAs: TileChars.FLOOR,
|
|
||||||
revealedMinimapChar: "𝑥",
|
revealedMinimapChar: "𝑥",
|
||||||
revealedMinimapColor: "#EE82EE", // purple
|
revealedMinimapColor: "#EE82EE", // purple
|
||||||
},
|
},
|
||||||
@@ -128,13 +127,17 @@ export class Tile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If this tile is disguised, copy its attributes, but
|
// If this tile imitates another tile type, copy those tile
|
||||||
// do not overwrite own attributes.
|
// types without overwrite own properties.
|
||||||
|
//
|
||||||
|
// Example: SECRET_PORTALs are disguised as walls, and will
|
||||||
|
// look like walls until they are revealed/uncovered via
|
||||||
|
// bump event, spell, or other method for discovering secrets
|
||||||
//
|
//
|
||||||
if (this.disguiseAs !== undefined) {
|
if (this.disguiseAs !== undefined) {
|
||||||
this.revealed = false;
|
this.revealed = false;
|
||||||
|
|
||||||
const other = shallowCopy(TileTypes[this.is]);
|
const other = shallowCopy(TileTypes[this.disguiseAs]);
|
||||||
for (const [pKey, pVal] of Object.entries(other)) {
|
for (const [pKey, pVal] of Object.entries(other)) {
|
||||||
if (this.key !== undefined) {
|
if (this.key !== undefined) {
|
||||||
this[pKey] = pVal;
|
this[pKey] = pVal;
|
||||||
@@ -146,6 +149,14 @@ export class Tile {
|
|||||||
// If this tile "inherits" properties from another tile type,
|
// If this tile "inherits" properties from another tile type,
|
||||||
// copy those properties, but do not overwrite own attributes.
|
// copy those properties, but do not overwrite own attributes.
|
||||||
//
|
//
|
||||||
|
// Example: PLAYER_START_POINT is just a floor tile, since its only job
|
||||||
|
// is to server as a place to spawn the player when they enter this floor,
|
||||||
|
// as well as add an icon to the minimap
|
||||||
|
//
|
||||||
|
// Example: ENCOUNTER_START_POINT is just a floor type. It does
|
||||||
|
// carry data on which kind if encounter that spawns here, and some
|
||||||
|
// other encounter properties. This tile is not even shown on the minmap.
|
||||||
|
//
|
||||||
if (this.is !== undefined) {
|
if (this.is !== undefined) {
|
||||||
//
|
//
|
||||||
const other = shallowCopy(TileTypes[this.is]);
|
const other = shallowCopy(TileTypes[this.is]);
|
||||||
@@ -157,7 +168,7 @@ export class Tile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Normalize Orientation
|
// Normalize Orientation.
|
||||||
//
|
//
|
||||||
if (this.orientation !== undefined && typeof this.orientation === "string") {
|
if (this.orientation !== undefined && typeof this.orientation === "string") {
|
||||||
const valueMap = {
|
const valueMap = {
|
||||||
@@ -169,22 +180,34 @@ export class Tile {
|
|||||||
this.orientation = mustBeString(valueMap[this.orientation.toLowerCase()]);
|
this.orientation = mustBeString(valueMap[this.orientation.toLowerCase()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Tiles are not necessarily required to have an ID, but if they have one, it must be string or number
|
||||||
if (this.id !== undefined) {
|
if (this.id !== undefined) {
|
||||||
mustBe(this.id, "number", "string");
|
mustBe(this.id, "number", "string");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// If a tile has a texture, the texture id must be string or number
|
||||||
if (this.textureId !== undefined) {
|
if (this.textureId !== undefined) {
|
||||||
mustBe(this.textureId, "number", "string");
|
mustBe(this.textureId, "number", "string");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// If a tile is a portal with a portal target, that target id must be a number or string.
|
||||||
if (this.portalTargetId !== undefined) {
|
if (this.portalTargetId !== undefined) {
|
||||||
mustBe(this.portalTargetId, "number", "string");
|
mustBe(this.portalTargetId, "number", "string");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CreateWalLTile() {
|
||||||
|
return this.fromChar();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} char
|
* @param {string} char
|
||||||
* @param {TileOptions} options Options
|
* @param {TileOptions} options Options
|
||||||
* @param {number} x
|
*
|
||||||
* @param {number} y
|
* @returns {Tile}
|
||||||
*/
|
*/
|
||||||
static fromChar(char, options) {
|
static fromChar(char, options) {
|
||||||
//
|
//
|
||||||
@@ -206,6 +229,8 @@ export class Tile {
|
|||||||
|
|
||||||
creationArgs[key] = fetchFromOption ? getOption(key) : shallowCopy(val);
|
creationArgs[key] = fetchFromOption ? getOption(key) : shallowCopy(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Tile(creationArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
clone() {
|
clone() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { CharType, TileMap } from "./ascii_tile_map";
|
import { CharType, TileMap } from "./ascii_tile_map";
|
||||||
import { EncounterTile, FloorTile, PlayerStartTile, TrapTile, LootTile, WallTile } from "./ascii_tile_types";
|
import { Tile } from "./ascii_tile_types";
|
||||||
import { Orientation } from "./ascii_types";
|
import { Orientation } from "./ascii_types";
|
||||||
|
|
||||||
class DungeonGenerator {
|
class DungeonGenerator {
|
||||||
|
|||||||
Reference in New Issue
Block a user