From 4efd8da5c12edfa9096a40e9a8b63c7680f4beba Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Wed, 8 Apr 2020 16:46:30 +0200 Subject: [PATCH 001/117] Add type definitions for Broadcast, Logger, Player and Room classes --- index.d.ts | 4 ++ types/Broadcast.d.ts | 44 +++++++++++++++ types/Logger.d.ts | 25 +++++++++ types/Player.d.ts | 57 +++++++++++++++++++ types/Room.d.ts | 129 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 259 insertions(+) create mode 100644 index.d.ts create mode 100644 types/Broadcast.d.ts create mode 100644 types/Logger.d.ts create mode 100644 types/Player.d.ts create mode 100644 types/Room.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 000000000..99e780437 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,4 @@ +export { Broadcast, Broadcastable } from './types/Broadcast'; +export { Logger } from './types/Logger'; +export { Player } from './types/Player'; +export { Room } from './types/Room'; diff --git a/types/Broadcast.d.ts b/types/Broadcast.d.ts new file mode 100644 index 000000000..803ac4aa8 --- /dev/null +++ b/types/Broadcast.d.ts @@ -0,0 +1,44 @@ +import { Player } from './Player'; + +export declare type Broadcastable = { getBroadcastTargets: Array } + +export declare class Broadcast { + /** + * @param {Broadcastable} source Target to send the broadcast to + * @param {string} message + * @param {number|boolean} wrapWidth=false width to wrap the message to or don't wrap at all + * @param {boolean} useColor Whether to parse color tags in the message + * @param {?function(target, message): string} formatter=null Function to call to format the + * message to each target + */ + static at(source: Broadcastable, message: string, wrapWidth: boolean, useColor: boolean, formatter: Function); + + /** + * Broadcast.at for all except given list of players + * @see {@link Broadcast#at} + * @param {Broadcastable} source + * @param {string} message + * @param {Array} excludes + * @param {number|boolean} wrapWidth + * @param {boolean} useColor + * @param {function} formatter + */ + static atExcept(source: Broadcastable, message: string, excludes: Array, wrapWidth: number|boolean, useColor: boolean, formatter: Function); + + /** + * Helper wrapper around Broadcast.at to be used when you're using a formatter + * @see {@link Broadcast#at} + * @param {Broadcastable} source + * @param {string} message + * @param {function} formatter + * @param {number|boolean} wrapWidth + * @param {boolean} useColor + */ + static atFormatted(source: Broadcastable, message, formatter, wrapWidth, useColor); + + /** + * `Broadcast.at` with a newline + * @see {@link Broadcast#at} + */ + static sayAt(source: Broadcastable, message, wrapWidth, useColor, formatter); +} \ No newline at end of file diff --git a/types/Logger.d.ts b/types/Logger.d.ts new file mode 100644 index 000000000..0a2b16b43 --- /dev/null +++ b/types/Logger.d.ts @@ -0,0 +1,25 @@ +export declare class Logger { + static getLevel(): string; + static setLevel(level): void; + /* + Medium priority logging, default. + */ + static log(...messages): void; + /* + Appends red "ERROR" to the start of logs. + Highest priority logging. + */ + static error(...messages): void; + /* + Less high priority than error, still higher visibility than default. + */ + static warn(...messages): void; + /* + Lower priority logging. + Only logs if the environment variable is set to VERBOSE. + */ + static verbose(...messages): void; + static setFileLogging(path): void; + static deactivateFileLogging(): void; + static enablePrettyErrors(): void; +} diff --git a/types/Player.d.ts b/types/Player.d.ts new file mode 100644 index 000000000..663338455 --- /dev/null +++ b/types/Player.d.ts @@ -0,0 +1,57 @@ +import { Room } from './Room'; + +export declare class Player { + constructor(data); + /** + * @see CommandQueue::enqueue + */ + queueCommand(executable, lag); + /** + * Proxy all events on the player to the quest tracker + * @param {string} event + * @param {...*} args + */ + emit(event, ...args); + /** + * Convert prompt tokens into actual data + * @param {string} promptStr + * @param {object} extraData Any extra data to give the prompt access to + */ + interpolatePrompt(promptStr: string, extraData: object); + /** + * Add a line of text to be displayed immediately after the prompt when the prompt is displayed + * @param {string} id Unique prompt id + * @param {function ()} renderer Function to call to render the prompt string + * @param {?boolean} removeOnRender When true prompt will remove itself once rendered + * otherwise prompt will continue to be rendered until removed. + */ + addPrompt(id: string, renderer: Function, removeOnRender: boolean); + + /** + * @param {string} id + */ + removePrompt(id: string); + + /** + * @param {string} id + * @return {boolean} + */ + hasPrompt(id: string): boolean; + + /** + * Move the player to the given room, emitting events appropriately + * @param {Room} nextRoom + * @param {function} onMoved Function to run after the player is moved to the next room but before enter events are fired + * @fires Room#playerLeave + * @fires Room#playerEnter + * @fires Player#enterRoom + */ + moveTo(nextRoom: Room, onMoved: Function); + + /** + * @param {function} callback + */ + save(callback: Function): void; + hydrate(state: object); + serialize(): object +} diff --git a/types/Room.d.ts b/types/Room.d.ts new file mode 100644 index 000000000..91d832773 --- /dev/null +++ b/types/Room.d.ts @@ -0,0 +1,129 @@ +import { Player } from './Player'; + +export declare class Room { + constructor(area: Area, def); + + /** + * Emits event on self and proxies certain events to other entities in the room. + * @param {string} eventName + * @param {...*} args + * @return {void} + */ + emit(eventName: string, ...args): void; + + /** + * @param {Player} player + */ + addPlayer(player: Player): void; + + /** + * @param {Player} player + */ + removePlayer(player: Player): void; + + /** + * @param {Npc} npc + */ + addNpc(npc: Npc): void; + + /** + * @param {Npc} npc + * @param {boolean} removeSpawn + */ + removeNpc(npc: Npc, removeSpawn: boolean): void; + + /** + * @param {Item} item + */ + addItem(item: Item): void; + + /** + * @param {Item} item + */ + removeItem(item: Item): void; + + /** + * Get exits for a room. Both inferred from coordinates and defined in the + * 'exits' property. + * + * @return {Array<{ id: string, direction: string, inferred: boolean, room: Room= }>} + */ + getExits(): Array<{ id: string, direction: string, inferred: boolean, room: Room }>; + + /** + * Get the exit definition of a room's exit by searching the exit name + * @param {string} exitName exit name search + * @return {false|Object} + */ + findExit(exitName: string): false|Object; + + /** + * Get the exit definition of a room's exit to a given room + * @param {Room} nextRoom + * @return {false|Object} + */ + getExitToRoom(nextRoom: Room): false|Object; + + /** + * Check to see if this room has a door preventing movement from `fromRoom` to here + * @param {Room} fromRoom + * @return {boolean} + */ + hasDoor(fromRoom: Room): boolean; + + /** + * @param {Room} fromRoom + * @return {{lockedBy: EntityReference, locked: boolean, closed: boolean}} + */ + getDoor(fromRoom: Room): Object<{lockedBy: EntityReference, locked: boolean, closed: boolean}> + + /** + * Check to see of the door for `fromRoom` is locked + * @param {Room} fromRoom + * @return {boolean} + */ + isDoorLocked(fromRoom: Room): boolean; + + /** + * @param {Room} fromRoom + */ + openDoor(fromRoom: Room): void; + + /** + * @param {Room} fromRoom + */ + closeDoor(fromRoom: Room): void; + + /** + * @param {Room} fromRoom + */ + unlockDoor(fromRoom: Room): void; + + /** + * @param {Room} fromRoom + */ + lockDoor(fromRoom: Room): void; + + /** + * @param {GameState} state + * @param {string} entityRef + * @return {Item} The newly created item + */ + spawnItem(state: GameState, entityRef: string): Item; + + /** + * @param {GameState} state + * @param {string} entityRef + * @fires Npc#spawn + * @return {Npc} + */ + spawnNpc(state: GameState, entityRef: string): Npc; + + hydrate(state: GameState): void; + + /** + * Used by Broadcaster + * @return {Array} + */ + getBroadcastTargets(): Array +} \ No newline at end of file From dc297dad9535735834f06799c08f6e1fdb14eda9 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Wed, 8 Apr 2020 20:28:51 +0200 Subject: [PATCH 002/117] Export namespace instead to declare class to allow definition of class properties --- types/Broadcast.d.ts | 10 ++++----- types/Logger.d.ts | 20 ++++++++--------- types/Player.d.ts | 28 +++++++++++++----------- types/Room.d.ts | 51 ++++++++++++++++++++++++-------------------- 4 files changed, 59 insertions(+), 50 deletions(-) diff --git a/types/Broadcast.d.ts b/types/Broadcast.d.ts index 803ac4aa8..a0f0dec19 100644 --- a/types/Broadcast.d.ts +++ b/types/Broadcast.d.ts @@ -2,7 +2,7 @@ import { Player } from './Player'; export declare type Broadcastable = { getBroadcastTargets: Array } -export declare class Broadcast { +export namespace Broadcast { /** * @param {Broadcastable} source Target to send the broadcast to * @param {string} message @@ -11,7 +11,7 @@ export declare class Broadcast { * @param {?function(target, message): string} formatter=null Function to call to format the * message to each target */ - static at(source: Broadcastable, message: string, wrapWidth: boolean, useColor: boolean, formatter: Function); + static function at(source: Broadcastable, message: string, wrapWidth: boolean, useColor: boolean, formatter: Function); /** * Broadcast.at for all except given list of players @@ -23,7 +23,7 @@ export declare class Broadcast { * @param {boolean} useColor * @param {function} formatter */ - static atExcept(source: Broadcastable, message: string, excludes: Array, wrapWidth: number|boolean, useColor: boolean, formatter: Function); + static function atExcept(source: Broadcastable, message: string, excludes: Array, wrapWidth: number|boolean, useColor: boolean, formatter: Function); /** * Helper wrapper around Broadcast.at to be used when you're using a formatter @@ -34,11 +34,11 @@ export declare class Broadcast { * @param {number|boolean} wrapWidth * @param {boolean} useColor */ - static atFormatted(source: Broadcastable, message, formatter, wrapWidth, useColor); + static function atFormatted(source: Broadcastable, message, formatter, wrapWidth, useColor); /** * `Broadcast.at` with a newline * @see {@link Broadcast#at} */ - static sayAt(source: Broadcastable, message, wrapWidth, useColor, formatter); + static function sayAt(source: Broadcastable, message, wrapWidth, useColor, formatter); } \ No newline at end of file diff --git a/types/Logger.d.ts b/types/Logger.d.ts index 0a2b16b43..2a16ba277 100644 --- a/types/Logger.d.ts +++ b/types/Logger.d.ts @@ -1,25 +1,25 @@ -export declare class Logger { - static getLevel(): string; - static setLevel(level): void; +export namespace Logger { + static function getLevel(): string; + static function setLevel(level): void; /* Medium priority logging, default. */ - static log(...messages): void; + static function log(...messages): void; /* Appends red "ERROR" to the start of logs. Highest priority logging. */ - static error(...messages): void; + static function error(...messages): void; /* Less high priority than error, still higher visibility than default. */ - static warn(...messages): void; + static function warn(...messages): void; /* Lower priority logging. Only logs if the environment variable is set to VERBOSE. */ - static verbose(...messages): void; - static setFileLogging(path): void; - static deactivateFileLogging(): void; - static enablePrettyErrors(): void; + static function verbose(...messages): void; + static function setFileLogging(path): void; + static function deactivateFileLogging(): void; + static function enablePrettyErrors(): void; } diff --git a/types/Player.d.ts b/types/Player.d.ts index 663338455..a02525e0a 100644 --- a/types/Player.d.ts +++ b/types/Player.d.ts @@ -1,23 +1,27 @@ import { Room } from './Room'; -export declare class Player { - constructor(data); +export namespace Player { + function constructor(data); + /** * @see CommandQueue::enqueue */ - queueCommand(executable, lag); + function queueCommand(executable, lag); + /** * Proxy all events on the player to the quest tracker * @param {string} event * @param {...*} args */ - emit(event, ...args); + function emit(event, ...args); + /** * Convert prompt tokens into actual data * @param {string} promptStr * @param {object} extraData Any extra data to give the prompt access to */ - interpolatePrompt(promptStr: string, extraData: object); + function interpolatePrompt(promptStr: string, extraData: object); + /** * Add a line of text to be displayed immediately after the prompt when the prompt is displayed * @param {string} id Unique prompt id @@ -25,18 +29,18 @@ export declare class Player { * @param {?boolean} removeOnRender When true prompt will remove itself once rendered * otherwise prompt will continue to be rendered until removed. */ - addPrompt(id: string, renderer: Function, removeOnRender: boolean); + function addPrompt(id: string, renderer: Function, removeOnRender: boolean); /** * @param {string} id */ - removePrompt(id: string); + function removePrompt(id: string); /** * @param {string} id * @return {boolean} */ - hasPrompt(id: string): boolean; + function hasPrompt(id: string): boolean; /** * Move the player to the given room, emitting events appropriately @@ -46,12 +50,12 @@ export declare class Player { * @fires Room#playerEnter * @fires Player#enterRoom */ - moveTo(nextRoom: Room, onMoved: Function); + function moveTo(nextRoom: Room, onMoved: Function); /** * @param {function} callback */ - save(callback: Function): void; - hydrate(state: object); - serialize(): object + function save(callback: Function): void; + function hydrate(state: Object); + function serialize(): Object; } diff --git a/types/Room.d.ts b/types/Room.d.ts index 91d832773..e24a414d7 100644 --- a/types/Room.d.ts +++ b/types/Room.d.ts @@ -1,7 +1,12 @@ import { Player } from './Player'; -export declare class Room { - constructor(area: Area, def); +export namespace Room { + /** + * @property Area room is in + */ + let area: Area; + + function constructor(area: Area, def); /** * Emits event on self and proxies certain events to other entities in the room. @@ -9,38 +14,38 @@ export declare class Room { * @param {...*} args * @return {void} */ - emit(eventName: string, ...args): void; + function emit(eventName: string, ...args): void; /** * @param {Player} player */ - addPlayer(player: Player): void; + function addPlayer(player: Player): void; /** * @param {Player} player */ - removePlayer(player: Player): void; + function removePlayer(player: Player): void; /** * @param {Npc} npc */ - addNpc(npc: Npc): void; + function addNpc(npc: Npc): void; /** * @param {Npc} npc * @param {boolean} removeSpawn */ - removeNpc(npc: Npc, removeSpawn: boolean): void; + function removeNpc(npc: Npc, removeSpawn: boolean): void; /** * @param {Item} item */ - addItem(item: Item): void; + function addItem(item: Item): void; /** * @param {Item} item */ - removeItem(item: Item): void; + function removeItem(item: Item): void; /** * Get exits for a room. Both inferred from coordinates and defined in the @@ -48,68 +53,68 @@ export declare class Room { * * @return {Array<{ id: string, direction: string, inferred: boolean, room: Room= }>} */ - getExits(): Array<{ id: string, direction: string, inferred: boolean, room: Room }>; + function getExits(): Array<{ id: string, direction: string, inferred: boolean, room: Room }>; /** * Get the exit definition of a room's exit by searching the exit name * @param {string} exitName exit name search * @return {false|Object} */ - findExit(exitName: string): false|Object; + function findExit(exitName: string): false|Object; /** * Get the exit definition of a room's exit to a given room * @param {Room} nextRoom * @return {false|Object} */ - getExitToRoom(nextRoom: Room): false|Object; + function getExitToRoom(nextRoom: Room): false|Object; /** * Check to see if this room has a door preventing movement from `fromRoom` to here * @param {Room} fromRoom * @return {boolean} */ - hasDoor(fromRoom: Room): boolean; + function hasDoor(fromRoom: Room): boolean; /** * @param {Room} fromRoom * @return {{lockedBy: EntityReference, locked: boolean, closed: boolean}} */ - getDoor(fromRoom: Room): Object<{lockedBy: EntityReference, locked: boolean, closed: boolean}> + function getDoor(fromRoom: Room): Object<{lockedBy: EntityReference, locked: boolean, closed: boolean}> /** * Check to see of the door for `fromRoom` is locked * @param {Room} fromRoom * @return {boolean} */ - isDoorLocked(fromRoom: Room): boolean; + function isDoorLocked(fromRoom: Room): boolean; /** * @param {Room} fromRoom */ - openDoor(fromRoom: Room): void; + function openDoor(fromRoom: Room): void; /** * @param {Room} fromRoom */ - closeDoor(fromRoom: Room): void; + function closeDoor(fromRoom: Room): void; /** * @param {Room} fromRoom */ - unlockDoor(fromRoom: Room): void; + function unlockDoor(fromRoom: Room): void; /** * @param {Room} fromRoom */ - lockDoor(fromRoom: Room): void; + function lockDoor(fromRoom: Room): void; /** * @param {GameState} state * @param {string} entityRef * @return {Item} The newly created item */ - spawnItem(state: GameState, entityRef: string): Item; + function spawnItem(state: GameState, entityRef: string): Item; /** * @param {GameState} state @@ -117,13 +122,13 @@ export declare class Room { * @fires Npc#spawn * @return {Npc} */ - spawnNpc(state: GameState, entityRef: string): Npc; + function spawnNpc(state: GameState, entityRef: string): Npc; - hydrate(state: GameState): void; + function hydrate(state: GameState): void; /** * Used by Broadcaster * @return {Array} */ - getBroadcastTargets(): Array + function getBroadcastTargets(): Array } \ No newline at end of file From 030403eb275adc6d168fe6e61bb3da26b6c24d85 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Wed, 8 Apr 2020 20:53:19 +0200 Subject: [PATCH 003/117] Add missing Broadcast methods and types --- types/Broadcast.d.ts | 78 +++++++++++++++++++++++++++++++++++++++++--- types/Logger.d.ts | 18 +++++----- 2 files changed, 83 insertions(+), 13 deletions(-) diff --git a/types/Broadcast.d.ts b/types/Broadcast.d.ts index a0f0dec19..8445c450b 100644 --- a/types/Broadcast.d.ts +++ b/types/Broadcast.d.ts @@ -11,7 +11,7 @@ export namespace Broadcast { * @param {?function(target, message): string} formatter=null Function to call to format the * message to each target */ - static function at(source: Broadcastable, message: string, wrapWidth: boolean, useColor: boolean, formatter: Function); + function at(source: Broadcastable, message: string, wrapWidth: boolean, useColor: boolean, formatter: Function): void; /** * Broadcast.at for all except given list of players @@ -23,7 +23,7 @@ export namespace Broadcast { * @param {boolean} useColor * @param {function} formatter */ - static function atExcept(source: Broadcastable, message: string, excludes: Array, wrapWidth: number|boolean, useColor: boolean, formatter: Function); + function atExcept(source: Broadcastable, message: string, excludes: Array, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; /** * Helper wrapper around Broadcast.at to be used when you're using a formatter @@ -34,11 +34,81 @@ export namespace Broadcast { * @param {number|boolean} wrapWidth * @param {boolean} useColor */ - static function atFormatted(source: Broadcastable, message, formatter, wrapWidth, useColor); + function atFormatted(source: Broadcastable, message: string, formatter: Function, wrapWidth: number|boolean, useColor: boolean): void; /** * `Broadcast.at` with a newline * @see {@link Broadcast#at} */ - static function sayAt(source: Broadcastable, message, wrapWidth, useColor, formatter); + function sayAt(source: Broadcastable, message: string, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; + + /** + * `Broadcast.atExcept` with a newline + * @see {@link Broadcast#atExcept} + */ + function sayAtExcept(source: Broadcastable, message: string, excludes, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; + + /** + * `Broadcast.atFormatted` with a newline + * @see {@link Broadcast#atFormatted} + */ + function sayAtFormatted(source: Broadcastable, message: string, formatter: Function, wrapWidth: number|boolean, useColor: boolean): void; + + /** + * Render the player's prompt including any extra prompts + * @param {Player} player + * @param {object} extra extra data to avail to the prompt string interpolator + * @param {number} wrapWidth + * @param {boolean} useColor + */ + function prompt(player: Player, extra: Object, wrapWidth: number, useColor: boolean): void; + + /** + * Generate an ASCII art progress bar + * @param {number} width Max width + * @param {number} percent Current percent + * @param {string} color + * @param {string} barChar Character to use for the current progress + * @param {string} fillChar Character to use for the rest + * @param {string} delimiters Characters to wrap the bar in + * @return {string} + */ + function progress(width: number, percent: number, color: string, barChar: string, fillChar: string, delimiters: string): string; + + /** + * Center a string in the middle of a given width + * @param {number} width + * @param {string} message + * @param {string} color + * @param {?string} fillChar Character to pad with, defaults to ' ' + * @return {string} + */ + function center(width: number, message: string, color: string, fillChar: string): string; + + /** + * Render a line of a specific width/color + * @param {number} width + * @param {string} fillChar + * @param {?string} color + * @return {string} + */ + function line(width: number, fillChar: string, color: string): string; + + /** + * Wrap a message to a given width. Note: Evaluates color tags + * @param {string} message + * @param {?number} width Defaults to 80 + * @return {string} + */ + function wrap(message: string, width: number): string; + + /** + * Indent all lines of a given string by a given amount + * @param {string} message + * @param {number} indent + * @return {string} + */ + function indent(message: string, indent: number): string; + + function isBroadcastable(source: Broadcastable): boolean; } \ No newline at end of file diff --git a/types/Logger.d.ts b/types/Logger.d.ts index 2a16ba277..004a239fd 100644 --- a/types/Logger.d.ts +++ b/types/Logger.d.ts @@ -1,25 +1,25 @@ export namespace Logger { - static function getLevel(): string; - static function setLevel(level): void; + function getLevel(): string; + function setLevel(level): void; /* Medium priority logging, default. */ - static function log(...messages): void; + function log(...messages): void; /* Appends red "ERROR" to the start of logs. Highest priority logging. */ - static function error(...messages): void; + function error(...messages): void; /* Less high priority than error, still higher visibility than default. */ - static function warn(...messages): void; + function warn(...messages): void; /* Lower priority logging. Only logs if the environment variable is set to VERBOSE. */ - static function verbose(...messages): void; - static function setFileLogging(path): void; - static function deactivateFileLogging(): void; - static function enablePrettyErrors(): void; + function verbose(...messages): void; + function setFileLogging(path): void; + function deactivateFileLogging(): void; + function enablePrettyErrors(): void; } From 276282a4085a1e67f2f1229e824272448ebef903 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Wed, 8 Apr 2020 22:49:14 +0200 Subject: [PATCH 004/117] Add Account definition --- index.d.ts | 1 + types/Account.d.ts | 72 ++++++++++++++++++++++++++++++++++++++++++++ types/Broadcast.d.ts | 4 +-- types/Player.d.ts | 4 +-- types/Room.d.ts | 4 +-- 5 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 types/Account.d.ts diff --git a/index.d.ts b/index.d.ts index 99e780437..36d8a8c3e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1,4 @@ +export { Account } from './types/Account'; export { Broadcast, Broadcastable } from './types/Broadcast'; export { Logger } from './types/Logger'; export { Player } from './types/Player'; diff --git a/types/Account.d.ts b/types/Account.d.ts new file mode 100644 index 000000000..307ccb11a --- /dev/null +++ b/types/Account.d.ts @@ -0,0 +1,72 @@ +export namespace Account { + let username: string; + let characters: Array; + let password: string; + let banned: boolean; + + /** + * @param {Object} data Account save data + */ + function constructor(data: Object); + + /** + * @return {string} + */ + function getUsername(): string; + + /** + * @param {string} username + */ + function addCharacter(username: string): void; + + /** + * @param {string} name + * @return {boolean} + */ + function hasCharacter(name: string): boolean; + + /** + * @param {string} name Delete one of the chars + */ + function deleteCharacter(name: string): void; + + /** + * @param {string} name Removes the deletion of one of the chars + */ + function undeleteCharacter(name: string): void; + + /** + * @param {string} password Unhashed password. Is hashed inside this function + */ + function setPassword(pass: string): void; + + /** + * @param {string} pass Unhashed password to check against account's password + * @return {boolean} + */ + function checkPassword(pass: string): boolean; + + /** + * @param {function} callback after-save callback + */ + function save(callback: Function): void; + + /** + * Set this account to banned + There is no unban because this can just be done by manually editing the account file + */ + function ban(): void; + + /** + * Set this account to deleted + There is no undelete because this can just be done by manually editing the account file + */ + function deleteAccount() + + /** + * Gather data from account object that will be persisted to disk + * + * @return {Object} + */ + function serialize(): Object; +} \ No newline at end of file diff --git a/types/Broadcast.d.ts b/types/Broadcast.d.ts index 8445c450b..53ad4b280 100644 --- a/types/Broadcast.d.ts +++ b/types/Broadcast.d.ts @@ -1,8 +1,8 @@ -import { Player } from './Player'; - export declare type Broadcastable = { getBroadcastTargets: Array } export namespace Broadcast { + import { Player } from './Player'; + /** * @param {Broadcastable} source Target to send the broadcast to * @param {string} message diff --git a/types/Player.d.ts b/types/Player.d.ts index a02525e0a..399beb416 100644 --- a/types/Player.d.ts +++ b/types/Player.d.ts @@ -1,6 +1,6 @@ -import { Room } from './Room'; - export namespace Player { + import { Room } from './Room'; + function constructor(data); /** diff --git a/types/Room.d.ts b/types/Room.d.ts index e24a414d7..e0b871fc8 100644 --- a/types/Room.d.ts +++ b/types/Room.d.ts @@ -1,6 +1,6 @@ -import { Player } from './Player'; - export namespace Room { + import { Player } from './Player'; + /** * @property Area room is in */ From e851849f5c4f42f8c56cd84b1c8e8e52a17a34e3 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Wed, 8 Apr 2020 23:49:34 +0200 Subject: [PATCH 005/117] Add definitions for AccountManger and EntityLoader --- index.d.ts | 2 ++ types/AccountManager.d.ts | 32 ++++++++++++++++++++++++++++++++ types/EntityLoader.d.ts | 21 +++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 types/AccountManager.d.ts create mode 100644 types/EntityLoader.d.ts diff --git a/index.d.ts b/index.d.ts index 36d8a8c3e..2b81b1ba8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,7 @@ export { Account } from './types/Account'; +export { AccountManager } from './types/AccountManager'; export { Broadcast, Broadcastable } from './types/Broadcast'; +export { EntityLoader } from './types/EntityLoader'; export { Logger } from './types/Logger'; export { Player } from './types/Player'; export { Room } from './types/Room'; diff --git a/types/AccountManager.d.ts b/types/AccountManager.d.ts new file mode 100644 index 000000000..bb5aaa92d --- /dev/null +++ b/types/AccountManager.d.ts @@ -0,0 +1,32 @@ +export namespace AccountManager { + import { Account } from './Account'; + import { EntityLoader } from './EntityLoader'; + + let accounts: Map; + let loader: EntityLoader; + + function constructor(); + + /** + * Set the entity loader from which accounts are loaded + * @param {EntityLoader} + */ + function setLoader(loader: EntityLoader): void; + + /** + * @param {Account} acc + */ + function addAccount(acc: Account): void; + + /** + * @param {string} username + * @return {Account|undefined} + */ + function getAccount(username: string): Account|undefined; + + /** + * @param {string} username + * @param {boolean} force Force reload data from disk + */ + async function loadAccount(username: string, force: boolean): void; +} \ No newline at end of file diff --git a/types/EntityLoader.d.ts b/types/EntityLoader.d.ts new file mode 100644 index 000000000..09e2ac47c --- /dev/null +++ b/types/EntityLoader.d.ts @@ -0,0 +1,21 @@ +export namespace EntityLoader { + import { DataSource } from './DataSource'; + + /** + * @param {DataSource} + * @param {object} config + */ + function constructor(dataSource: DataSource, config: Object); + + function setArea(name: string): void; + + function setBundle(name: string): void; + + function hasData(): boolean; + + function fetchAll(); + + function fetch(id); + + function replace(data); +} \ No newline at end of file From 23325284e17d4552bb58909125d1852b586890a5 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Thu, 9 Apr 2020 00:06:44 +0200 Subject: [PATCH 006/117] Fix some import and add types to package.json --- package.json | 1 + types/AccountManager.d.ts | 10 +++++----- types/Broadcast.d.ts | 4 ++-- types/EntityLoader.d.ts | 4 ++-- types/Player.d.ts | 4 ++-- types/Room.d.ts | 4 ++-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 9279bbf70..db6daab7d 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "coverage": "nyc report --reporter=text-lcov | coveralls" }, "main": "index.js", + "types": "./index.d.ts", "dependencies": { "bcryptjs": "^2.4.0", "js-yaml": "^3.12.0", diff --git a/types/AccountManager.d.ts b/types/AccountManager.d.ts index bb5aaa92d..9c3905cbf 100644 --- a/types/AccountManager.d.ts +++ b/types/AccountManager.d.ts @@ -1,9 +1,9 @@ -export namespace AccountManager { - import { Account } from './Account'; - import { EntityLoader } from './EntityLoader'; +import { Account } from '../src/Account'; +import { EntityLoader} from '../src/EntityLoader'; +export namespace AccountManager { let accounts: Map; - let loader: EntityLoader; + let loader: prova; function constructor(); @@ -28,5 +28,5 @@ export namespace AccountManager { * @param {string} username * @param {boolean} force Force reload data from disk */ - async function loadAccount(username: string, force: boolean): void; + function loadAccount(username: string, force: boolean): void; } \ No newline at end of file diff --git a/types/Broadcast.d.ts b/types/Broadcast.d.ts index 53ad4b280..422bea19c 100644 --- a/types/Broadcast.d.ts +++ b/types/Broadcast.d.ts @@ -1,8 +1,8 @@ +import { Player } from '../src/Player'; + export declare type Broadcastable = { getBroadcastTargets: Array } export namespace Broadcast { - import { Player } from './Player'; - /** * @param {Broadcastable} source Target to send the broadcast to * @param {string} message diff --git a/types/EntityLoader.d.ts b/types/EntityLoader.d.ts index 09e2ac47c..44931673e 100644 --- a/types/EntityLoader.d.ts +++ b/types/EntityLoader.d.ts @@ -1,6 +1,6 @@ -export namespace EntityLoader { - import { DataSource } from './DataSource'; +// import { DataSource } from '../src/DataSource'; FIXME +export namespace EntityLoader { /** * @param {DataSource} * @param {object} config diff --git a/types/Player.d.ts b/types/Player.d.ts index 399beb416..a7e200c2a 100644 --- a/types/Player.d.ts +++ b/types/Player.d.ts @@ -1,6 +1,6 @@ -export namespace Player { - import { Room } from './Room'; +import { Room } from '../src/Room'; +export namespace Player { function constructor(data); /** diff --git a/types/Room.d.ts b/types/Room.d.ts index e0b871fc8..6302038bc 100644 --- a/types/Room.d.ts +++ b/types/Room.d.ts @@ -1,6 +1,6 @@ -export namespace Room { - import { Player } from './Player'; +import { Player } from '../src/Player'; +export namespace Room { /** * @property Area room is in */ From 97cc85ff4463036d8ea17488a38e5ba38f16c076 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Thu, 9 Apr 2020 00:08:18 +0200 Subject: [PATCH 007/117] Drop folder path from types declaration on package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index db6daab7d..5874f35b8 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "coverage": "nyc report --reporter=text-lcov | coveralls" }, "main": "index.js", - "types": "./index.d.ts", + "types": "index.d.ts", "dependencies": { "bcryptjs": "^2.4.0", "js-yaml": "^3.12.0", From 3e536ee6192026ba76435f7f3eaca63628a7f948 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Thu, 9 Apr 2020 00:22:10 +0200 Subject: [PATCH 008/117] Add definition for Area --- index.d.ts | 1 + src/Area.js | 2 +- types/Area.d.ts | 99 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 types/Area.d.ts diff --git a/index.d.ts b/index.d.ts index 2b81b1ba8..271ade741 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,6 @@ export { Account } from './types/Account'; export { AccountManager } from './types/AccountManager'; +export { Area } from './types/Area'; export { Broadcast, Broadcastable } from './types/Broadcast'; export { EntityLoader } from './types/EntityLoader'; export { Logger } from './types/Logger'; diff --git a/src/Area.js b/src/Area.js index c8334653d..3fe68c243 100644 --- a/src/Area.js +++ b/src/Area.js @@ -146,7 +146,7 @@ class Area extends GameEntity { * This method is automatically called every N milliseconds where N is defined in the * `setInterval` call to `GameState.AreaMAnager.tickAll` in the `ranvier` executable. It, in turn, * will fire the `updateTick` event on all its rooms and npcs - * + * * @param {GameState} state * @fires Room#updateTick * @fires Npc#updateTick diff --git a/types/Area.d.ts b/types/Area.d.ts new file mode 100644 index 000000000..ac182c288 --- /dev/null +++ b/types/Area.d.ts @@ -0,0 +1,99 @@ +import { Npc } from '../src/Npc'; +import { Room } from '../src/Room'; + +export namespace Area { + /** Bundle this area comes from */ + let bundle: string; + let name: string + let title: string; + /** A custom script for this item */ + let script: string; + /** a Map object keyed by the floor z-index, each floor is an array with [x][y] indexes for coordinates. */ + let map: Map; + /** Map of room id to Room */ + let rooms: Map; + /** Active NPCs that originate from this area. Note: this is NPCs that */ + let npcs: Set; + /** Area configuration */ + let info: Object + /** milliseconds since last respawn tick. See {@link Area#update} */ + let lastRespawnTick: number; + + function constructor(bundle, name, manifest); + + /** + * Get ranvier-root-relative path to this area + * @return {string} + */ + function areaPath(): string; + + /** + * Get an ordered list of floors in this area's map + * @return {Array} + */ + function floors(): Array; + + /** + * @param {string} id Room id + * @return {Room|undefined} + */ + function getRoomById(id: string): Room|undefined; + + /** + * @param {Room} room + * @fires Area#roomAdded + */ + function addRoom(room: Room): void; + + /** + * @param {Room} room + * @fires Area#roomRemoved + */ + function removeRoom(room: Room): void + + /** + * @param {Room} room + * @throws Error + */ + function addRoomToMap(room: Room): void; + + /** + * find a room at the given coordinates for this area + * @param {number} x + * @param {number} y + * @param {number} z + * @return {Room|boolean} + */ + function getRoomAtCoordinates(x: number, y: number, z: number): Room|boolean; + + /** + * @param {Npc} npc + */ + function addNpc(npc: Npc): void; + + /** + * Removes an NPC from the area. NOTE: This must manually remove the NPC from its room as well + * @param {Npc} npc + */ + function removeNpc(npc: Npc): void; + + /** + * This method is automatically called every N milliseconds where N is defined in the + * `setInterval` call to `GameState.AreaMAnager.tickAll` in the `ranvier` executable. It, in turn, + * will fire the `updateTick` event on all its rooms and npcs + * + * @param {GameState} state + * @fires Room#updateTick + * @fires Npc#updateTick + */ + function update(state: GameState): void; + + function hydrate(state): void; + + /** + * Get all possible broadcast targets within an area. This includes all npcs, + * players, rooms, and the area itself + * @return {Array} + */ + function getBroadcastTargets(): Array; +} \ No newline at end of file From cf38ddadf2c95ac91d2a8cfad4ab0cc37f78e5e1 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Thu, 9 Apr 2020 03:31:11 +0200 Subject: [PATCH 009/117] Refactor definitions to allow extends, add some new definitions --- types/Account.d.ts | 34 +++++++++++----------- types/AccountManager.d.ts | 20 ++++++------- types/Area.d.ts | 53 ++++++++++++++++++---------------- types/Broadcast.d.ts | 32 ++++++++++----------- types/Character.d.ts | 5 ++++ types/DataSource.d.ts | 3 ++ types/EffectableEntity.d.ts | 5 ++++ types/EntityLoader.d.ts | 18 ++++++------ types/EntityReference.d.ts | 3 ++ types/GameEntity.d.ts | 7 +++++ types/GameState.d.ts | 3 ++ types/Item.d.ts | 5 ++++ types/Logger.d.ts | 20 ++++++------- types/Metadatable.d.ts | 21 ++++++++++++++ types/Npc.d.ts | 6 ++++ types/Player.d.ts | 29 ++++++++++--------- types/Room.d.ts | 57 +++++++++++++++++++++---------------- types/Scriptable.d.ts | 21 ++++++++++++++ 18 files changed, 216 insertions(+), 126 deletions(-) create mode 100644 types/Character.d.ts create mode 100644 types/DataSource.d.ts create mode 100644 types/EffectableEntity.d.ts create mode 100644 types/EntityReference.d.ts create mode 100644 types/GameEntity.d.ts create mode 100644 types/GameState.d.ts create mode 100644 types/Item.d.ts create mode 100644 types/Metadatable.d.ts create mode 100644 types/Npc.d.ts create mode 100644 types/Scriptable.d.ts diff --git a/types/Account.d.ts b/types/Account.d.ts index 307ccb11a..435c4c7b8 100644 --- a/types/Account.d.ts +++ b/types/Account.d.ts @@ -1,72 +1,72 @@ -export namespace Account { - let username: string; - let characters: Array; - let password: string; - let banned: boolean; +export declare class Account { + username: string; + characters: Array; + password: string; + banned: boolean; /** * @param {Object} data Account save data */ - function constructor(data: Object); + constructor(data: Object); /** * @return {string} */ - function getUsername(): string; + getUsername(): string; /** * @param {string} username */ - function addCharacter(username: string): void; + addCharacter(username: string): void; /** * @param {string} name * @return {boolean} */ - function hasCharacter(name: string): boolean; + hasCharacter(name: string): boolean; /** * @param {string} name Delete one of the chars */ - function deleteCharacter(name: string): void; + deleteCharacter(name: string): void; /** * @param {string} name Removes the deletion of one of the chars */ - function undeleteCharacter(name: string): void; + undeleteCharacter(name: string): void; /** * @param {string} password Unhashed password. Is hashed inside this function */ - function setPassword(pass: string): void; + setPassword(pass: string): void; /** * @param {string} pass Unhashed password to check against account's password * @return {boolean} */ - function checkPassword(pass: string): boolean; + checkPassword(pass: string): boolean; /** * @param {function} callback after-save callback */ - function save(callback: Function): void; + save(callback: Function): void; /** * Set this account to banned There is no unban because this can just be done by manually editing the account file */ - function ban(): void; + ban(): void; /** * Set this account to deleted There is no undelete because this can just be done by manually editing the account file */ - function deleteAccount() + deleteAccount() /** * Gather data from account object that will be persisted to disk * * @return {Object} */ - function serialize(): Object; + serialize(): Object; } \ No newline at end of file diff --git a/types/AccountManager.d.ts b/types/AccountManager.d.ts index 9c3905cbf..728aa64de 100644 --- a/types/AccountManager.d.ts +++ b/types/AccountManager.d.ts @@ -1,32 +1,32 @@ -import { Account } from '../src/Account'; -import { EntityLoader} from '../src/EntityLoader'; +import { Account } from './Account'; +import { EntityLoader} from './EntityLoader'; -export namespace AccountManager { - let accounts: Map; - let loader: prova; +export declare class AccountManager { + accounts: Map; + loader: EntityLoader; - function constructor(); + constructor(); /** * Set the entity loader from which accounts are loaded * @param {EntityLoader} */ - function setLoader(loader: EntityLoader): void; + setLoader(loader: EntityLoader): void; /** * @param {Account} acc */ - function addAccount(acc: Account): void; + addAccount(acc: Account): void; /** * @param {string} username * @return {Account|undefined} */ - function getAccount(username: string): Account|undefined; + getAccount(username: string): Account|undefined; /** * @param {string} username * @param {boolean} force Force reload data from disk */ - function loadAccount(username: string, force: boolean): void; + loadAccount(username: string, force: boolean): void; } \ No newline at end of file diff --git a/types/Area.d.ts b/types/Area.d.ts index ac182c288..14b88fa73 100644 --- a/types/Area.d.ts +++ b/types/Area.d.ts @@ -1,61 +1,64 @@ -import { Npc } from '../src/Npc'; -import { Room } from '../src/Room'; +import { Broadcastable } from './Broadcast'; +import { GameEntity } from './GameEntity'; +import { GameState } from './GameState'; +import { Npc } from './Npc'; +import { Room } from './Room'; -export namespace Area { +export declare class Area extends GameEntity { /** Bundle this area comes from */ - let bundle: string; - let name: string - let title: string; + bundle: string; + name: string + title: string; /** A custom script for this item */ - let script: string; + script: string; /** a Map object keyed by the floor z-index, each floor is an array with [x][y] indexes for coordinates. */ - let map: Map; + map: Map; /** Map of room id to Room */ - let rooms: Map; + rooms: Map; /** Active NPCs that originate from this area. Note: this is NPCs that */ - let npcs: Set; + npcs: Set; /** Area configuration */ - let info: Object + info: Object /** milliseconds since last respawn tick. See {@link Area#update} */ - let lastRespawnTick: number; + lastRespawnTick: number; - function constructor(bundle, name, manifest); + constructor(bundle, name, manifest); /** * Get ranvier-root-relative path to this area * @return {string} */ - function areaPath(): string; + areaPath(): string; /** * Get an ordered list of floors in this area's map * @return {Array} */ - function floors(): Array; + floors(): Array; /** * @param {string} id Room id * @return {Room|undefined} */ - function getRoomById(id: string): Room|undefined; + getRoomById(id: string): Room|undefined; /** * @param {Room} room * @fires Area#roomAdded */ - function addRoom(room: Room): void; + addRoom(room: Room): void; /** * @param {Room} room * @fires Area#roomRemoved */ - function removeRoom(room: Room): void + removeRoom(room: Room): void /** * @param {Room} room * @throws Error */ - function addRoomToMap(room: Room): void; + addRoomToMap(room: Room): void; /** * find a room at the given coordinates for this area @@ -64,18 +67,18 @@ export namespace Area { * @param {number} z * @return {Room|boolean} */ - function getRoomAtCoordinates(x: number, y: number, z: number): Room|boolean; + getRoomAtCoordinates(x: number, y: number, z: number): Room|boolean; /** * @param {Npc} npc */ - function addNpc(npc: Npc): void; + addNpc(npc: Npc): void; /** * Removes an NPC from the area. NOTE: This must manually remove the NPC from its room as well * @param {Npc} npc */ - function removeNpc(npc: Npc): void; + removeNpc(npc: Npc): void; /** * This method is automatically called every N milliseconds where N is defined in the @@ -86,14 +89,14 @@ export namespace Area { * @fires Room#updateTick * @fires Npc#updateTick */ - function update(state: GameState): void; + update(state: GameState): void; - function hydrate(state): void; + hydrate(state): void; /** * Get all possible broadcast targets within an area. This includes all npcs, * players, rooms, and the area itself * @return {Array} */ - function getBroadcastTargets(): Array; + getBroadcastTargets(): Array; } \ No newline at end of file diff --git a/types/Broadcast.d.ts b/types/Broadcast.d.ts index 422bea19c..5874b926f 100644 --- a/types/Broadcast.d.ts +++ b/types/Broadcast.d.ts @@ -1,8 +1,8 @@ -import { Player } from '../src/Player'; +import { Player } from './Player'; -export declare type Broadcastable = { getBroadcastTargets: Array } +export type Broadcastable = { getBroadcastTargets: Array } -export namespace Broadcast { +export declare class Broadcast { /** * @param {Broadcastable} source Target to send the broadcast to * @param {string} message @@ -11,7 +11,7 @@ export namespace Broadcast { * @param {?function(target, message): string} formatter=null Function to call to format the * message to each target */ - function at(source: Broadcastable, message: string, wrapWidth: boolean, useColor: boolean, formatter: Function): void; + at(source: Broadcastable, message: string, wrapWidth: boolean, useColor: boolean, formatter: Function): void; /** * Broadcast.at for all except given list of players @@ -23,7 +23,7 @@ export namespace Broadcast { * @param {boolean} useColor * @param {function} formatter */ - function atExcept(source: Broadcastable, message: string, excludes: Array, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; + atExcept(source: Broadcastable, message: string, excludes: Array, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; /** * Helper wrapper around Broadcast.at to be used when you're using a formatter @@ -34,25 +34,25 @@ export namespace Broadcast { * @param {number|boolean} wrapWidth * @param {boolean} useColor */ - function atFormatted(source: Broadcastable, message: string, formatter: Function, wrapWidth: number|boolean, useColor: boolean): void; + atFormatted(source: Broadcastable, message: string, formatter: Function, wrapWidth: number|boolean, useColor: boolean): void; /** * `Broadcast.at` with a newline * @see {@link Broadcast#at} */ - function sayAt(source: Broadcastable, message: string, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; + sayAt(source: Broadcastable, message: string, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; /** * `Broadcast.atExcept` with a newline * @see {@link Broadcast#atExcept} */ - function sayAtExcept(source: Broadcastable, message: string, excludes, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; + sayAtExcept(source: Broadcastable, message: string, excludes, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; /** * `Broadcast.atFormatted` with a newline * @see {@link Broadcast#atFormatted} */ - function sayAtFormatted(source: Broadcastable, message: string, formatter: Function, wrapWidth: number|boolean, useColor: boolean): void; + sayAtFormatted(source: Broadcastable, message: string, formatter: Function, wrapWidth: number|boolean, useColor: boolean): void; /** * Render the player's prompt including any extra prompts @@ -61,7 +61,7 @@ export namespace Broadcast { * @param {number} wrapWidth * @param {boolean} useColor */ - function prompt(player: Player, extra: Object, wrapWidth: number, useColor: boolean): void; + prompt(player: Player, extra: Object, wrapWidth: number, useColor: boolean): void; /** * Generate an ASCII art progress bar @@ -73,7 +73,7 @@ export namespace Broadcast { * @param {string} delimiters Characters to wrap the bar in * @return {string} */ - function progress(width: number, percent: number, color: string, barChar: string, fillChar: string, delimiters: string): string; + progress(width: number, percent: number, color: string, barChar: string, fillChar: string, delimiters: string): string; /** * Center a string in the middle of a given width @@ -83,7 +83,7 @@ export namespace Broadcast { * @param {?string} fillChar Character to pad with, defaults to ' ' * @return {string} */ - function center(width: number, message: string, color: string, fillChar: string): string; + center(width: number, message: string, color: string, fillChar: string): string; /** * Render a line of a specific width/color @@ -92,7 +92,7 @@ export namespace Broadcast { * @param {?string} color * @return {string} */ - function line(width: number, fillChar: string, color: string): string; + line(width: number, fillChar: string, color: string): string; /** * Wrap a message to a given width. Note: Evaluates color tags @@ -100,7 +100,7 @@ export namespace Broadcast { * @param {?number} width Defaults to 80 * @return {string} */ - function wrap(message: string, width: number): string; + wrap(message: string, width: number): string; /** * Indent all lines of a given string by a given amount @@ -108,7 +108,7 @@ export namespace Broadcast { * @param {number} indent * @return {string} */ - function indent(message: string, indent: number): string; + indent(message: string, indent: number): string; - function isBroadcastable(source: Broadcastable): boolean; + isBroadcastable(source: Broadcastable): boolean; } \ No newline at end of file diff --git a/types/Character.d.ts b/types/Character.d.ts new file mode 100644 index 000000000..25bed63ba --- /dev/null +++ b/types/Character.d.ts @@ -0,0 +1,5 @@ +import { EffectableEntity } from './EffectableEntity'; +import { Metadatable } from './Metadatable'; + +export declare class Character extends Metadatable(EffectableEntity) { +} \ No newline at end of file diff --git a/types/DataSource.d.ts b/types/DataSource.d.ts new file mode 100644 index 000000000..729c6d30c --- /dev/null +++ b/types/DataSource.d.ts @@ -0,0 +1,3 @@ +export declare class DataSource { + +} \ No newline at end of file diff --git a/types/EffectableEntity.d.ts b/types/EffectableEntity.d.ts new file mode 100644 index 000000000..3066835c8 --- /dev/null +++ b/types/EffectableEntity.d.ts @@ -0,0 +1,5 @@ +import { EventEmitter } from 'events'; + +export declare class EffectableEntity extends EventEmitter { + +} \ No newline at end of file diff --git a/types/EntityLoader.d.ts b/types/EntityLoader.d.ts index 44931673e..3315b0044 100644 --- a/types/EntityLoader.d.ts +++ b/types/EntityLoader.d.ts @@ -1,21 +1,21 @@ -// import { DataSource } from '../src/DataSource'; FIXME +import { DataSource } from './DataSource'; -export namespace EntityLoader { +export declare class EntityLoader { /** * @param {DataSource} * @param {object} config */ - function constructor(dataSource: DataSource, config: Object); + constructor(dataSource: DataSource, config: Object); - function setArea(name: string): void; + setArea(name: string): void; - function setBundle(name: string): void; + setBundle(name: string): void; - function hasData(): boolean; + hasData(): boolean; - function fetchAll(); + fetchAll(); - function fetch(id); + fetch(id); - function replace(data); + replace(data); } \ No newline at end of file diff --git a/types/EntityReference.d.ts b/types/EntityReference.d.ts new file mode 100644 index 000000000..8b697ba94 --- /dev/null +++ b/types/EntityReference.d.ts @@ -0,0 +1,3 @@ +export declare class EntityReference { + +} \ No newline at end of file diff --git a/types/GameEntity.d.ts b/types/GameEntity.d.ts new file mode 100644 index 000000000..3eaf6580d --- /dev/null +++ b/types/GameEntity.d.ts @@ -0,0 +1,7 @@ +import { EffectableEntity } from './EffectableEntity'; +import { Metadatable } from './Metadatable'; +import { Scriptable } from './Scriptable'; + +export declare class GameEntity extends Scriptable(Metadatable(EffectableEntity)) { + +} \ No newline at end of file diff --git a/types/GameState.d.ts b/types/GameState.d.ts new file mode 100644 index 000000000..c528240a5 --- /dev/null +++ b/types/GameState.d.ts @@ -0,0 +1,3 @@ +export declare class GameState { + +} \ No newline at end of file diff --git a/types/Item.d.ts b/types/Item.d.ts new file mode 100644 index 000000000..fbdab52eb --- /dev/null +++ b/types/Item.d.ts @@ -0,0 +1,5 @@ +import { GameEntity } from './GameEntity'; + +export declare class Item extends GameEntity { + +} \ No newline at end of file diff --git a/types/Logger.d.ts b/types/Logger.d.ts index 004a239fd..86dac740c 100644 --- a/types/Logger.d.ts +++ b/types/Logger.d.ts @@ -1,25 +1,25 @@ -export namespace Logger { - function getLevel(): string; - function setLevel(level): void; +export declare class Logger { + getLevel(): string; + setLevel(level): void; /* Medium priority logging, default. */ - function log(...messages): void; + log(...messages): void; /* Appends red "ERROR" to the start of logs. Highest priority logging. */ - function error(...messages): void; + error(...messages): void; /* Less high priority than error, still higher visibility than default. */ - function warn(...messages): void; + warn(...messages): void; /* Lower priority logging. Only logs if the environment variable is set to VERBOSE. */ - function verbose(...messages): void; - function setFileLogging(path): void; - function deactivateFileLogging(): void; - function enablePrettyErrors(): void; + verbose(...messages): void; + setFileLogging(path): void; + deactivateFileLogging(): void; + enablePrettyErrors(): void; } diff --git a/types/Metadatable.d.ts b/types/Metadatable.d.ts new file mode 100644 index 000000000..7f94f91d4 --- /dev/null +++ b/types/Metadatable.d.ts @@ -0,0 +1,21 @@ +export declare function Metadatable(parentClass): any { + /** + * Set a metadata value. + * Warning: Does _not_ autovivify, you will need to create the parent objects if they don't exist + * @param {string} key Key to set. Supports dot notation e.g., `"foo.bar"` + * @param {*} value Value must be JSON.stringify-able + * @throws Error + * @throws RangeError + * @fires Metadatable#metadataUpdate + */ + function setMeta(key: string, value: any): void; + + /** + * Get metadata by dot notation + * Warning: This method is _very_ permissive and will not error on a non-existent key. Rather, it will return false. + * @param {string} key Key to fetch. Supports dot notation e.g., `"foo.bar"` + * @return {*} + * @throws Error + */ + function getMeta(key: string): any; +} \ No newline at end of file diff --git a/types/Npc.d.ts b/types/Npc.d.ts new file mode 100644 index 000000000..67280c1d7 --- /dev/null +++ b/types/Npc.d.ts @@ -0,0 +1,6 @@ +import { Character } from './Character'; +import { Scriptable } from './Scriptable'; + +export declare class Npc extends Scriptable(Character) { + +} \ No newline at end of file diff --git a/types/Player.d.ts b/types/Player.d.ts index a7e200c2a..dec614538 100644 --- a/types/Player.d.ts +++ b/types/Player.d.ts @@ -1,46 +1,47 @@ -import { Room } from '../src/Room'; +import { Character } from './Character'; +import { Room } from './Room'; -export namespace Player { - function constructor(data); +export declare class Player extends Character { + constructor(data); /** * @see CommandQueue::enqueue */ - function queueCommand(executable, lag); + queueCommand(executable, lag); /** * Proxy all events on the player to the quest tracker * @param {string} event * @param {...*} args */ - function emit(event, ...args); + emit(event, ...args); /** * Convert prompt tokens into actual data * @param {string} promptStr * @param {object} extraData Any extra data to give the prompt access to */ - function interpolatePrompt(promptStr: string, extraData: object); + interpolatePrompt(promptStr: string, extraData: object); /** * Add a line of text to be displayed immediately after the prompt when the prompt is displayed * @param {string} id Unique prompt id - * @param {function ()} renderer Function to call to render the prompt string + * @param {()} renderer Function to call to render the prompt string * @param {?boolean} removeOnRender When true prompt will remove itself once rendered * otherwise prompt will continue to be rendered until removed. */ - function addPrompt(id: string, renderer: Function, removeOnRender: boolean); + addPrompt(id: string, renderer: Function, removeOnRender: boolean); /** * @param {string} id */ - function removePrompt(id: string); + removePrompt(id: string); /** * @param {string} id * @return {boolean} */ - function hasPrompt(id: string): boolean; + hasPrompt(id: string): boolean; /** * Move the player to the given room, emitting events appropriately @@ -50,12 +51,12 @@ export namespace Player { * @fires Room#playerEnter * @fires Player#enterRoom */ - function moveTo(nextRoom: Room, onMoved: Function); + moveTo(nextRoom: Room, onMoved: Function); /** * @param {function} callback */ - function save(callback: Function): void; - function hydrate(state: Object); - function serialize(): Object; + save(callback: Function): void; + hydrate(state: Object); + serialize(): Object; } diff --git a/types/Room.d.ts b/types/Room.d.ts index 6302038bc..5ffe837c4 100644 --- a/types/Room.d.ts +++ b/types/Room.d.ts @@ -1,12 +1,19 @@ -import { Player } from '../src/Player'; +import { Area } from './Area'; +import { Character } from './Character'; +import { GameEntity } from './GameEntity'; +import { EntityReference } from './EntityReference'; +import { GameState } from './GameState'; +import { Item } from './Item'; +import { Npc } from './Npc'; +import { Player } from './Player'; -export namespace Room { +export declare class Room extends GameEntity { /** * @property Area room is in */ - let area: Area; + area: Area; - function constructor(area: Area, def); + constructor(area: Area, def); /** * Emits event on self and proxies certain events to other entities in the room. @@ -14,38 +21,38 @@ export namespace Room { * @param {...*} args * @return {void} */ - function emit(eventName: string, ...args): void; + emit(eventName: string, ...args): void; /** * @param {Player} player */ - function addPlayer(player: Player): void; + addPlayer(player: Player): void; /** * @param {Player} player */ - function removePlayer(player: Player): void; + removePlayer(player: Player): void; /** * @param {Npc} npc */ - function addNpc(npc: Npc): void; + addNpc(npc: Npc): void; /** * @param {Npc} npc * @param {boolean} removeSpawn */ - function removeNpc(npc: Npc, removeSpawn: boolean): void; + removeNpc(npc: Npc, removeSpawn: boolean): void; /** * @param {Item} item */ - function addItem(item: Item): void; + addItem(item: Item): void; /** * @param {Item} item */ - function removeItem(item: Item): void; + removeItem(item: Item): void; /** * Get exits for a room. Both inferred from coordinates and defined in the @@ -53,68 +60,68 @@ export namespace Room { * * @return {Array<{ id: string, direction: string, inferred: boolean, room: Room= }>} */ - function getExits(): Array<{ id: string, direction: string, inferred: boolean, room: Room }>; + getExits(): Array<{ id: string, direction: string, inferred: boolean, room: Room }>; /** * Get the exit definition of a room's exit by searching the exit name * @param {string} exitName exit name search * @return {false|Object} */ - function findExit(exitName: string): false|Object; + findExit(exitName: string): false|Object; /** * Get the exit definition of a room's exit to a given room * @param {Room} nextRoom * @return {false|Object} */ - function getExitToRoom(nextRoom: Room): false|Object; + getExitToRoom(nextRoom: Room): false|Object; /** * Check to see if this room has a door preventing movement from `fromRoom` to here * @param {Room} fromRoom * @return {boolean} */ - function hasDoor(fromRoom: Room): boolean; + hasDoor(fromRoom: Room): boolean; /** * @param {Room} fromRoom * @return {{lockedBy: EntityReference, locked: boolean, closed: boolean}} */ - function getDoor(fromRoom: Room): Object<{lockedBy: EntityReference, locked: boolean, closed: boolean}> + getDoor(fromRoom: Room): Object; /** * Check to see of the door for `fromRoom` is locked * @param {Room} fromRoom * @return {boolean} */ - function isDoorLocked(fromRoom: Room): boolean; + isDoorLocked(fromRoom: Room): boolean; /** * @param {Room} fromRoom */ - function openDoor(fromRoom: Room): void; + openDoor(fromRoom: Room): void; /** * @param {Room} fromRoom */ - function closeDoor(fromRoom: Room): void; + closeDoor(fromRoom: Room): void; /** * @param {Room} fromRoom */ - function unlockDoor(fromRoom: Room): void; + unlockDoor(fromRoom: Room): void; /** * @param {Room} fromRoom */ - function lockDoor(fromRoom: Room): void; + lockDoor(fromRoom: Room): void; /** * @param {GameState} state * @param {string} entityRef * @return {Item} The newly created item */ - function spawnItem(state: GameState, entityRef: string): Item; + spawnItem(state: GameState, entityRef: string): Item; /** * @param {GameState} state @@ -122,13 +129,13 @@ export namespace Room { * @fires Npc#spawn * @return {Npc} */ - function spawnNpc(state: GameState, entityRef: string): Npc; + spawnNpc(state: GameState, entityRef: string): Npc; - function hydrate(state: GameState): void; + hydrate(state: GameState): void; /** * Used by Broadcaster * @return {Array} */ - function getBroadcastTargets(): Array + getBroadcastTargets(): Array } \ No newline at end of file diff --git a/types/Scriptable.d.ts b/types/Scriptable.d.ts new file mode 100644 index 000000000..2e8bc88bc --- /dev/null +++ b/types/Scriptable.d.ts @@ -0,0 +1,21 @@ +export function Scriptable(parentClass): any { + function emit(name: string, ...args): void; + + /** + * @param {string} name + * @return {boolean} + */ + function hasBehavior(name: string): boolean; + + /** + * @param {string} name + * @return {*} + */ + function getBehavior(name: string): any; + + /** + * Attach this entity's behaviors from the manager + * @param {BehaviorManager} manager + */ + function setupBehaviors(manager: BehaviorManager): void; +} From c75d1eba9e9aa745996280bcc1548263cab1138b Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Thu, 9 Apr 2020 05:03:41 +0200 Subject: [PATCH 010/117] Mixin (Scriptable and Metadataable) definitions and placeholder for BehaviorManager --- types/BehaviorManager.d.ts | 3 +++ types/Metadatable.d.ts | 10 ++++++---- types/Scriptable.d.ts | 15 ++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 types/BehaviorManager.d.ts diff --git a/types/BehaviorManager.d.ts b/types/BehaviorManager.d.ts new file mode 100644 index 000000000..f4d76903e --- /dev/null +++ b/types/BehaviorManager.d.ts @@ -0,0 +1,3 @@ +export class BehaviorManager { + +} \ No newline at end of file diff --git a/types/Metadatable.d.ts b/types/Metadatable.d.ts index 7f94f91d4..f10dd4e5d 100644 --- a/types/Metadatable.d.ts +++ b/types/Metadatable.d.ts @@ -1,4 +1,4 @@ -export declare function Metadatable(parentClass): any { +export declare class MetadatableClass { /** * Set a metadata value. * Warning: Does _not_ autovivify, you will need to create the parent objects if they don't exist @@ -8,7 +8,7 @@ export declare function Metadatable(parentClass): any { * @throws RangeError * @fires Metadatable#metadataUpdate */ - function setMeta(key: string, value: any): void; + setMeta(key: string, value: any): void; /** * Get metadata by dot notation @@ -17,5 +17,7 @@ export declare function Metadatable(parentClass): any { * @return {*} * @throws Error */ - function getMeta(key: string): any; -} \ No newline at end of file + getMeta(key: string): any; +} + +export declare function Metadatable(parentClass: any): any & MetadatableClass; \ No newline at end of file diff --git a/types/Scriptable.d.ts b/types/Scriptable.d.ts index 2e8bc88bc..cf7816ebd 100644 --- a/types/Scriptable.d.ts +++ b/types/Scriptable.d.ts @@ -1,21 +1,26 @@ -export function Scriptable(parentClass): any { - function emit(name: string, ...args): void; +import { BehaviorManager } from './BehaviorManager'; + +export declare class ScriptableClass { + emit(name: string, ...args: any[]): void; /** * @param {string} name * @return {boolean} */ - function hasBehavior(name: string): boolean; + hasBehavior(name: string): boolean; /** * @param {string} name * @return {*} */ - function getBehavior(name: string): any; + getBehavior(name: string): any; /** * Attach this entity's behaviors from the manager * @param {BehaviorManager} manager */ - function setupBehaviors(manager: BehaviorManager): void; + setupBehaviors(manager: BehaviorManager): void; } + +export declare function Scriptable(parentClass: any): any & ScriptableClass; + From dd435dafcd27cafd73780892d100679ad5a36afc Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Thu, 9 Apr 2020 05:06:56 +0200 Subject: [PATCH 011/117] Export definitions for new entitities --- index.d.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index.d.ts b/index.d.ts index 271ade741..5e16c7b36 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,8 +1,20 @@ export { Account } from './types/Account'; export { AccountManager } from './types/AccountManager'; export { Area } from './types/Area'; +export { BehaviorManager } from './types/BehaviorManager'; export { Broadcast, Broadcastable } from './types/Broadcast'; +export { Character } from './types/Character'; +export { DataSource } from './types/DataSource'; +export { EffectableEntity } from './types/EffectableEntity'; export { EntityLoader } from './types/EntityLoader'; +export { EntityReference } from './types/EntityReference'; +export { GameEntity } from './types/GameEntity'; +export { GameState } from './types/GameState'; +export { Item } from './types/Item'; export { Logger } from './types/Logger'; +export { Metadatable, MetadatableClass } from './types/Metadatable'; +export { Npc } from './types/Npc'; export { Player } from './types/Player'; export { Room } from './types/Room'; +export { Scriptable, ScriptableClass } from './types/Scriptable'; + From 0df92681cde6a8b86e610e105ae739a39781285f Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 11:42:09 +0200 Subject: [PATCH 012/117] Update Account definition --- types/Account.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/Account.d.ts b/types/Account.d.ts index 435c4c7b8..6bdab7318 100644 --- a/types/Account.d.ts +++ b/types/Account.d.ts @@ -1,7 +1,11 @@ export declare class Account { + /** @property {string} username */ username: string; + /** @property {Array} characters List of character names in this account */ characters: Array; + /** @property {string} password Hashed password */ password: string; + /** @property {boolean} banned Whether this account is banned or not */ banned: boolean; /** From 468ba41028bb8fcdc7b8c65871b1a631bd5eacc6 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 11:49:39 +0200 Subject: [PATCH 013/117] Add EventManager definition and update Behavior manager --- index.d.ts | 1 + types/BehaviorManager.d.ts | 24 +++++++++++++++++++++++- types/EventManager.d.ts | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 types/EventManager.d.ts diff --git a/index.d.ts b/index.d.ts index 5e16c7b36..f3c4729e7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -8,6 +8,7 @@ export { DataSource } from './types/DataSource'; export { EffectableEntity } from './types/EffectableEntity'; export { EntityLoader } from './types/EntityLoader'; export { EntityReference } from './types/EntityReference'; +export { EventManager } from './types/EventManager'; export { GameEntity } from './types/GameEntity'; export { GameState } from './types/GameState'; export { Item } from './types/Item'; diff --git a/types/BehaviorManager.d.ts b/types/BehaviorManager.d.ts index f4d76903e..2948adca7 100644 --- a/types/BehaviorManager.d.ts +++ b/types/BehaviorManager.d.ts @@ -1,3 +1,25 @@ -export class BehaviorManager { +import { EventManager } from './EventManager'; +export declare class BehaviorManager { + constructor(); + + /** + * Get EventManager for a given behavior + * @param {string} name + * @return {EventManager} + */ + get(name: string): EventManager; + + /** + * Check to see if a behavior exists + * @param {string} name + * @return {boolean} + */ + has(name: string): boolean; + + /** + * @param {string} behaviorName + * @param {Function} listener + */ + addListener(behaviorName: string, event: string, listener: Function) } \ No newline at end of file diff --git a/types/EventManager.d.ts b/types/EventManager.d.ts new file mode 100644 index 000000000..e7ce14573 --- /dev/null +++ b/types/EventManager.d.ts @@ -0,0 +1,36 @@ +export declare class EventManager { + constructor(); + + /** + * Fetch all listeners for a given event + * @param {string} name + * @return {Set} + */ + get(name: string): Set; + + /** + * @param {string} eventName + * @param {Function} listener + */ + add(eventName: string, listener: Function): void; + + /** + * Attach all currently added events to the given emitter + * @param {EventEmitter} emitter + * @param {Object} config + */ + attach(emitter: EventEmitter, config: Object); + + /** + * Remove all listeners for a given emitter or only those for the given events + * If no events are given it will remove all listeners from all events defined + * in this manager. + * + * Warning: This will remove _all_ listeners for a given event list, this includes + * listeners not in this manager but attached to the same event + * + * @param {EventEmitter} emitter + * @param {?string|iterable} events Optional name or list of event names to remove listeners from + */ + detach(emitter: EventEmitter, events: ?string|iterable): void; +} \ No newline at end of file From dba5b64744f6c5d02b3235986fa1bc0edc91b002 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 11:49:59 +0200 Subject: [PATCH 014/117] Add missing docblock paramter for BundleManager --- src/BehaviorManager.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BehaviorManager.js b/src/BehaviorManager.js index e34d80363..a83575304 100644 --- a/src/BehaviorManager.js +++ b/src/BehaviorManager.js @@ -30,6 +30,7 @@ class BehaviorManager { } /** + * @param {string} behaviorName * @param {string} behaviorName * @param {Function} listener */ From 69832be0de803feffa5810ffea11741aa6bbf33c Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 13:11:18 +0200 Subject: [PATCH 015/117] Export new type definitions --- index.d.ts | 15 ++++ types/Account.d.ts | 2 +- types/AccountManager.d.ts | 2 + types/Area.d.ts | 6 +- types/AreaAudience.d.ts | 11 +++ types/AreaFactory.d.ts | 19 +++++ types/AreaFloor.d.ts | 25 +++++++ types/AreaManager.d.ts | 46 ++++++++++++ types/AreaOfEffectDamage.d.ts | 20 ++++++ types/AreaOfEffectHeal.d.ts | 20 ++++++ types/Attribute.d.ts | 51 +++++++++++++ types/AttributeFactory.d.ts | 39 ++++++++++ types/Attributes.d.ts | 24 +++++++ types/BehaviorManager.d.ts | 1 + types/Broadcast.d.ts | 1 + types/BundleManager.d.ts | 130 ++++++++++++++++++++++++++++++++++ types/ChannelAudience.d.ts | 3 + types/Command.d.ts | 3 + types/Damage.d.ts | 2 + types/EntityFactory.d.ts | 3 + types/Heal.d.ts | 2 + 21 files changed, 422 insertions(+), 3 deletions(-) create mode 100644 types/AreaAudience.d.ts create mode 100644 types/AreaFactory.d.ts create mode 100644 types/AreaFloor.d.ts create mode 100644 types/AreaManager.d.ts create mode 100644 types/AreaOfEffectDamage.d.ts create mode 100644 types/AreaOfEffectHeal.d.ts create mode 100644 types/Attribute.d.ts create mode 100644 types/AttributeFactory.d.ts create mode 100644 types/Attributes.d.ts create mode 100644 types/BundleManager.d.ts create mode 100644 types/ChannelAudience.d.ts create mode 100644 types/Command.d.ts create mode 100644 types/Damage.d.ts create mode 100644 types/EntityFactory.d.ts create mode 100644 types/Heal.d.ts diff --git a/index.d.ts b/index.d.ts index f3c4729e7..403d823ea 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,16 +1,31 @@ export { Account } from './types/Account'; export { AccountManager } from './types/AccountManager'; export { Area } from './types/Area'; +export { AreaAudience } from './types/AreaAudience'; +export { AreaFactory } from './types/AreaFactory'; +export { AreaFloor } from './types/AreaFloor'; +export { AreaManager } from './types/AreaManager'; +export { AreaOfEffectDamage } from './types/AreaOfEffectDamage'; +export { AreaOfEffectHeal } from './types/AreaOfEffectHeal'; +export { Attribute, AttributeFormula } from './types/Attribute'; +export { AttributeFactory } from './types/AttributeFactory'; +export { Attributes } from './types/Attributes'; export { BehaviorManager } from './types/BehaviorManager'; export { Broadcast, Broadcastable } from './types/Broadcast'; +export { BundleManager} from './types/BundleManager'; +export { ChannelAudience } from './types/ChannelAudience'; export { Character } from './types/Character'; +export { Command } from './types/Command'; +export { Damage } from './types/Damage'; export { DataSource } from './types/DataSource'; export { EffectableEntity } from './types/EffectableEntity'; +export { EntityFactory } from './types/EntityFactory'; export { EntityLoader } from './types/EntityLoader'; export { EntityReference } from './types/EntityReference'; export { EventManager } from './types/EventManager'; export { GameEntity } from './types/GameEntity'; export { GameState } from './types/GameState'; +export { Heal } from './types/Heal'; export { Item } from './types/Item'; export { Logger } from './types/Logger'; export { Metadatable, MetadatableClass } from './types/Metadatable'; diff --git a/types/Account.d.ts b/types/Account.d.ts index 6bdab7318..4869d35f6 100644 --- a/types/Account.d.ts +++ b/types/Account.d.ts @@ -65,7 +65,7 @@ export declare class Account { * Set this account to deleted There is no undelete because this can just be done by manually editing the account file */ - deleteAccount() + deleteAccount(): void; /** * Gather data from account object that will be persisted to disk diff --git a/types/AccountManager.d.ts b/types/AccountManager.d.ts index 728aa64de..baa44d6a5 100644 --- a/types/AccountManager.d.ts +++ b/types/AccountManager.d.ts @@ -2,7 +2,9 @@ import { Account } from './Account'; import { EntityLoader} from './EntityLoader'; export declare class AccountManager { + /** @property {Map} accounts */ accounts: Map; + /** @property {EntityLoader} loader */ loader: EntityLoader; constructor(); diff --git a/types/Area.d.ts b/types/Area.d.ts index 14b88fa73..d5c34b665 100644 --- a/types/Area.d.ts +++ b/types/Area.d.ts @@ -7,11 +7,13 @@ import { Room } from './Room'; export declare class Area extends GameEntity { /** Bundle this area comes from */ bundle: string; + /** @property {string} name */ name: string + /** @property {string} title */ title: string; - /** A custom script for this item */ + /** @property {string} script A custom script for this item */ script: string; - /** a Map object keyed by the floor z-index, each floor is an array with [x][y] indexes for coordinates. */ + /** @property {Map} map a Map object keyed by the floor z-index, each floor is an array with [x][y] indexes for coordinates. */ map: Map; /** Map of room id to Room */ rooms: Map; diff --git a/types/AreaAudience.d.ts b/types/AreaAudience.d.ts new file mode 100644 index 000000000..f9e5a6c5f --- /dev/null +++ b/types/AreaAudience.d.ts @@ -0,0 +1,11 @@ +import { Broadcastable } from './Broadcast'; +import { ChannelAudience } from './ChannelAudience'; + +/** + * Audience class representing characters in the same area as the sender + * @memberof ChannelAudience + * @extends ChannelAudience + */ +export declare class AreaAudience extends ChannelAudience { + getBroadcastTargets(): Array; +} \ No newline at end of file diff --git a/types/AreaFactory.d.ts b/types/AreaFactory.d.ts new file mode 100644 index 000000000..f016ba0e1 --- /dev/null +++ b/types/AreaFactory.d.ts @@ -0,0 +1,19 @@ +import { Area } from './Area'; +import { EntityFactory } from './EntityFactory'; + +export declare class AreaFactory extends EntityFactory { + /** + * Create a new instance of an area by name. Resulting area will not have + * any of its contained entities (items, npcs, rooms) hydrated. You will + * need to call `area.hydrate(state)` + * + * @param {string} entityRef Area name + * @return {Area} + */ + create(entityRef: string): Area; + + /** + * @see AreaFactory#create + */ + clone(area: Area): Area; +} \ No newline at end of file diff --git a/types/AreaFloor.d.ts b/types/AreaFloor.d.ts new file mode 100644 index 000000000..9f4241460 --- /dev/null +++ b/types/AreaFloor.d.ts @@ -0,0 +1,25 @@ +import { Room } from './Room'; + +export declare class AreaFloor { + /** @property {number} lowX The lowest x value */ + lowX: number; + /** @property {number} highX The highest x value */ + highX: number; + /** @property {number} lowY The lowest y value */ + lowY: number; + /** @property {number} highY The highest y value */ + highY: number; + /** @property {number} z This floor's z index */ + z: number; + + constructor(z: number); + + addRoom(x: number, y: number, room: Room): void; + + /** + * @return {Room|boolean} + */ + getRoom(x: number, y: number): Room; + + removeRoom(x: number, y: number): void; +} \ No newline at end of file diff --git a/types/AreaManager.d.ts b/types/AreaManager.d.ts new file mode 100644 index 000000000..76e036a65 --- /dev/null +++ b/types/AreaManager.d.ts @@ -0,0 +1,46 @@ +import { Area } from "./Area"; +import { GameState } from "./GameState"; + +export declare class AreaManager { + /** @property {Map} areas */ + areas: Map; + + constructor(); + + /** + * @param {string} name + * @return Area + */ + getArea(name: string): Area; + + /** + * @param {string} entityRef + * @return Area + */ + getAreaByReference(entityRef: string): Area; + + /** + * @param {Area} area + */ + addArea(area: Area): void; + + /** + * @param {Area} area + */ + removeArea(area: Area): void; + + /** + * Apply `updateTick` to all areas in the game + * @param {GameState} state + * @fires Area#updateTick + */ + tickAll(state: GameState): void; + + /** + * Get the placeholder area used to house players who were loaded into + * an invalid room + * + * @return {Area} + */ + getPlaceholderArea(): Area; +} \ No newline at end of file diff --git a/types/AreaOfEffectDamage.d.ts b/types/AreaOfEffectDamage.d.ts new file mode 100644 index 000000000..aeca53f28 --- /dev/null +++ b/types/AreaOfEffectDamage.d.ts @@ -0,0 +1,20 @@ +import { Character } from './Character'; +import { Damage } from './Damage'; +import { Room } from './Room'; + +export declare class AreaOfEffectDamage extends Damage { + /** + * @param {Room|Character} target + * @throws RangeError + * @fires Room#areaDamage + */ + commit(room: Room|Character): void; + + /** + * Override this method to customize valid targets such as + * only targeting hostile npcs, or only targeting players, etc. + * @param {Room} room + * @return {Array} + */ + getValidTargets(room: Room): Array; +} \ No newline at end of file diff --git a/types/AreaOfEffectHeal.d.ts b/types/AreaOfEffectHeal.d.ts new file mode 100644 index 000000000..5c460d7f2 --- /dev/null +++ b/types/AreaOfEffectHeal.d.ts @@ -0,0 +1,20 @@ +import { Character } from './Character'; +import { Heal } from './Heal'; +import { Room } from './Room'; + +export declare class AreaOfEffectHeal extends Heal { + /** + * @param {Room|Character} target + * @throws RangeError + * @fires Room#areaDamage + */ + commit(room: Room|Character): void; + + /** + * Override this method to customize valid targets such as + * only targeting hostile npcs, or only targeting players, etc. + * @param {Room} room + * @return {Array} + */ + getValidTargets(room: Room): Array; +} \ No newline at end of file diff --git a/types/Attribute.d.ts b/types/Attribute.d.ts new file mode 100644 index 000000000..d339d123f --- /dev/null +++ b/types/Attribute.d.ts @@ -0,0 +1,51 @@ +export declare class Attribute { + /** @property {string} name */ + name: string; + /** @property {number} base */ + base: number; + /** @property {number} delta Current difference from the base */ + delta: number; + /** @property {AttributeFormula} formula */ + formula: AttributeFormula; + /** @property {object} metadata any custom info for this attribute */ + metadata: object; + + constructor(name: string, base: number, delta: number, formula: AttributeFormula, metadata: object); + + /** + * Lower current value + * @param {number} amount + */ + lower(amount: number): void; + + /** + * Raise current value + * @param {number} amount + */ + raise(amount: number): void; + + /** + * Change the base value + * @param {number} amount + */ + setBase(amount: number): void; + + /** + * Bypass raise/lower, directly setting the delta + * @param {number} amount + */ + setDelta(amount: number): void; + + serialize(): object; +} + +export declare class AttributeFormula { + /** @property {Array} requires Array of attributes required for this formula to run */ + requires: Array; + /** @property {function (...number) : number} formula */ + formula: Function; + + constructor(requires: Array, fn: Function); + + evaluate(attribute, ...args): any; +} \ No newline at end of file diff --git a/types/AttributeFactory.d.ts b/types/AttributeFactory.d.ts new file mode 100644 index 000000000..79dce0b2a --- /dev/null +++ b/types/AttributeFactory.d.ts @@ -0,0 +1,39 @@ +import { Attribute, AttributeFormula } from './Attribute'; + +export declare class AttributeFactory { + /** @property {Map} attributes */ + attributes: Map; + constructor(); + + /** + * @param {string} name + * @param {number} base + * @param {AttributeFormula} formula + */ + add(name: string, base: number, formula: AttributeFormula, metadata: object): void + + /** + * @see Map#has + */ + has(name: string): boolean; + + /** + * Get a attribute definition. Use `create` if you want an instance of a attribute + * @param {string} name + * @return {object} + */ + get(name: string): object; + + /** + * @param {string} name + * @param {number} delta + * @return {Attribute} + */ + create(name: string, base: number, delta: number): Attribute; + + /** + * Make sure there are no circular dependencies between attributes + * @throws Error + */ + validateAttributes(): Map; +} \ No newline at end of file diff --git a/types/Attributes.d.ts b/types/Attributes.d.ts new file mode 100644 index 000000000..7225023bf --- /dev/null +++ b/types/Attributes.d.ts @@ -0,0 +1,24 @@ +import { Attribute } from "./Attribute"; + +export declare class Attributes extends Map { + /** + * @param {Attribute} attribute + */ + add(attribute: Attribute): void; + + /** + * @return {Iterator} see {@link Map#entries} + */ + getAttributes(): Iterator; + + /** + * Clear all deltas for all attributes in the list + */ + clearDeltas(): void; + + /** + * Gather data that will be persisted + * @return {Object} + */ + serialize(): Object; +} \ No newline at end of file diff --git a/types/BehaviorManager.d.ts b/types/BehaviorManager.d.ts index 2948adca7..a4d102a1d 100644 --- a/types/BehaviorManager.d.ts +++ b/types/BehaviorManager.d.ts @@ -19,6 +19,7 @@ export declare class BehaviorManager { /** * @param {string} behaviorName + * @param {string} event * @param {Function} listener */ addListener(behaviorName: string, event: string, listener: Function) diff --git a/types/Broadcast.d.ts b/types/Broadcast.d.ts index 5874b926f..a30be093a 100644 --- a/types/Broadcast.d.ts +++ b/types/Broadcast.d.ts @@ -1,5 +1,6 @@ import { Player } from './Player'; +/** @typedef {{getBroadcastTargets: function(): Array}} */ export type Broadcastable = { getBroadcastTargets: Array } export declare class Broadcast { diff --git a/types/BundleManager.d.ts b/types/BundleManager.d.ts new file mode 100644 index 000000000..da18f912a --- /dev/null +++ b/types/BundleManager.d.ts @@ -0,0 +1,130 @@ +import { Command } from './Command'; +import { EntityFactory } from './EntityFactory'; +import { GameState } from './GameState'; + +export declare class BundleManager { + /** + * @param {GameState} state + */ + constructor(path: string, state: GameState); + + /** + * Load in all bundles + */ + loadBundles(distribute: boolean): void; + + /** + * @param {string} bundle Bundle name + * @param {string} bundlePath Path to bundle directory + */ + loadBundle(bundle: string, bundlePath: string): void; + + loadQuestGoals(bundle: string, goalsDir: string): void; + + loadQuestRewards(bundle: string, rewardsDir: string): void; + + /** + * Load attribute definitions + * @param {string} bundle + * @param {string} attributesFile + */ + loadAttributes(bundle: string, attributesFile: string): void; + + /** + * Load/initialize player. See the {@link http://ranviermud.com/extending/input_events/|Player Event guide} + * @param {string} bundle + * @param {string} eventsFile event js file to load + */ + loadPlayerEvents(bundle: string, eventsFile: string): void; + + /** + * @param {string} bundle + */ + loadAreas(bundle: string): void; + + /** + * @param {string} bundle + * @param {string} areaName + * @param {string} areaPath + */ + loadArea(bundle: string, areaName: string, manifest: string): void; + + /** + * Load an entity (item/npc/room) from file + * @param {string} bundle + * @param {string} areaName + * @param {string} type + * @param {EntityFactory} factory + * @return {Array} + */ + loadEntities(bundle: string, areaName: string, type: string, factory: EntityFactory): Array; + + /** + * @param {EntityFactory} factory Instance of EntityFactory that the item/npc will be loaded into + * @param {string} entityRef + * @param {string} scriptPath + */ + loadEntityScript(factory: EntityFactory, entityRef: string, scriptPath: string): void; + + /** + * @param {string} bundle + * @param {string} areaName + * @return {Promise>} + */ + loadQuests(bundle: string, areaName: string): Promise> + + /** + * @param {string} bundle + * @param {string} commandsDir + */ + loadCommands(bundle: string, commandsDir: string): void; + + /** + * @param {string} commandPath + * @param {string} commandName + * @param {string} bundle + * @return {Command} + */ + createCommand(commandPath: string, commandName: string, bundle: string): Command; + + /** + * @param {string} bundle + * @param {string} channelsFile + */ + loadChannels(bundle: string, channelsFile: string): void; + + /** + * @param {string} bundle + */ + loadHelp(bundle: string): void; + + /** + * @param {string} bundle + * @param {string} inputEventsDir + */ + loadInputEvents(bundle: string, inputEventsDir: string): void; + + /** + * @param {string} bundle + * @param {string} behaviorsDir + */ + loadBehaviors(bundle: string, behaviorsDir: string): void; + + /** + * @param {string} bundle + * @param {string} effectsDir + */ + loadEffects(bundle: string, effectsDir: string): void; + + /** + * @param {string} bundle + * @param {string} skillsDir + */ + loadSkills(bundle: string, skillsDir: string): void; + + /** + * @param {string} bundle + * @param {string} serverEventsDir + */ + loadServerEvents(bundle: string, serverEventsDir: string): void; +} \ No newline at end of file diff --git a/types/ChannelAudience.d.ts b/types/ChannelAudience.d.ts new file mode 100644 index 000000000..f02ef2a60 --- /dev/null +++ b/types/ChannelAudience.d.ts @@ -0,0 +1,3 @@ +export declare class ChannelAudience { + +} \ No newline at end of file diff --git a/types/Command.d.ts b/types/Command.d.ts new file mode 100644 index 000000000..9920ad97c --- /dev/null +++ b/types/Command.d.ts @@ -0,0 +1,3 @@ +export declare class Command { + +} \ No newline at end of file diff --git a/types/Damage.d.ts b/types/Damage.d.ts new file mode 100644 index 000000000..1a7ffd30d --- /dev/null +++ b/types/Damage.d.ts @@ -0,0 +1,2 @@ +export declare class Damage { +} \ No newline at end of file diff --git a/types/EntityFactory.d.ts b/types/EntityFactory.d.ts new file mode 100644 index 000000000..27530c650 --- /dev/null +++ b/types/EntityFactory.d.ts @@ -0,0 +1,3 @@ +export declare class EntityFactory { + +} \ No newline at end of file diff --git a/types/Heal.d.ts b/types/Heal.d.ts new file mode 100644 index 000000000..c842851d6 --- /dev/null +++ b/types/Heal.d.ts @@ -0,0 +1,2 @@ +export declare class Heal { +} \ No newline at end of file From 66e345db8e458630795994024dbf1dd02b4b199a Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 13:12:07 +0200 Subject: [PATCH 016/117] Fix some docblocks on source classes --- src/Attribute.js | 6 +++--- src/AttributeFactory.js | 1 + src/BehaviorManager.js | 2 +- src/BundleManager.js | 11 ++++++----- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Attribute.js b/src/Attribute.js index 192a72286..78b442017 100644 --- a/src/Attribute.js +++ b/src/Attribute.js @@ -22,8 +22,8 @@ class Attribute { * @param {object} metadata={} */ constructor(name, base, delta = 0, formula = null, metadata = {}) { - if (isNaN(base)) { - throw new TypeError(`Base attribute must be a number, got ${base}.`); + if (isNaN(base)) { + throw new TypeError(`Base attribute must be a number, got ${base}.`); } if (isNaN(delta)) { throw new TypeError(`Attribute delta must be a number, got ${delta}.`); @@ -66,7 +66,7 @@ class Attribute { /** * Bypass raise/lower, directly setting the delta - * @param {amount} + * @param {number} amount */ setDelta(amount) { this.delta = Math.min(amount, 0); diff --git a/src/AttributeFactory.js b/src/AttributeFactory.js index 3ab54f5f3..012790b74 100644 --- a/src/AttributeFactory.js +++ b/src/AttributeFactory.js @@ -46,6 +46,7 @@ class AttributeFactory { /** * @param {string} name + * @param {number} base * @param {number} delta * @return {Attribute} */ diff --git a/src/BehaviorManager.js b/src/BehaviorManager.js index a83575304..667a18804 100644 --- a/src/BehaviorManager.js +++ b/src/BehaviorManager.js @@ -31,7 +31,7 @@ class BehaviorManager { /** * @param {string} behaviorName - * @param {string} behaviorName + * @param {string} event * @param {Function} listener */ addListener(behaviorName, event, listener) { diff --git a/src/BundleManager.js b/src/BundleManager.js index 042520b5e..61d9c94ea 100644 --- a/src/BundleManager.js +++ b/src/BundleManager.js @@ -26,6 +26,7 @@ const srcPath = __dirname + '/'; */ class BundleManager { /** + * @param {string} path * @param {GameState} state */ constructor(path, state) { @@ -41,6 +42,7 @@ class BundleManager { /** * Load in all bundles + * @param {boolean} distribute */ async loadBundles(distribute = true) { Logger.verbose('LOAD: BUNDLES'); @@ -317,7 +319,7 @@ class BundleManager { * @param {string} areaName * @param {string} type * @param {EntityFactory} factory - * @return {Array} + * @return {Array} */ async loadEntities(bundle, areaName, type, factory) { const loader = this.loaderRegistry.get(type); @@ -355,7 +357,7 @@ class BundleManager { /** * @param {EntityFactory} factory Instance of EntityFactory that the item/npc will be loaded into - * @param {EntityReference} entityRef + * @param {string} entityRef * @param {string} scriptPath */ loadEntityScript(factory, entityRef, scriptPath) { @@ -369,9 +371,9 @@ class BundleManager { } /** + * @param {string} bundle * @param {string} areaName - * @param {string} questsFile - * @return {Promise>} + * @return {Promise>} */ async loadQuests(bundle, areaName) { const loader = this.loaderRegistry.get('quests'); @@ -455,7 +457,6 @@ class BundleManager { /** * @param {string} bundle - * @param {string} helpDir */ async loadHelp(bundle) { Logger.verbose(`\tLOAD: Help...`); From b4641b372b04a4037131a28d46070752bec20863 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 21:29:14 +0200 Subject: [PATCH 017/117] Update denfinitions for DataSource and EntityLoaders classes --- types/DataSource.d.ts | 10 +++++++++- types/EntityLoader.d.ts | 10 ++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/types/DataSource.d.ts b/types/DataSource.d.ts index 729c6d30c..0a7b334c6 100644 --- a/types/DataSource.d.ts +++ b/types/DataSource.d.ts @@ -1,3 +1,11 @@ -export declare class DataSource { +export declare interface DataSource { + hasData(config: object): Promise; + fetchAll(config: object): Promise; + + fetch(config: object, id: string|number): any; + + replace(config: object, data: any): void; + + update(config: object, id: string|number, data: any): void; } \ No newline at end of file diff --git a/types/EntityLoader.d.ts b/types/EntityLoader.d.ts index 3315b0044..851dc4ada 100644 --- a/types/EntityLoader.d.ts +++ b/types/EntityLoader.d.ts @@ -11,11 +11,13 @@ export declare class EntityLoader { setBundle(name: string): void; - hasData(): boolean; + hasData(): Promise; - fetchAll(); + fetchAll(): Promise; - fetch(id); + fetch(id: string|number); - replace(data); + replace(data: any): void; + + update(id: string|number, data: any): void; } \ No newline at end of file From 0f5dea85338789aae43446bdd893cc5ce2cffb29 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 21:31:13 +0200 Subject: [PATCH 018/117] Update docblock --- types/EntityLoader.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/EntityLoader.d.ts b/types/EntityLoader.d.ts index 851dc4ada..113ea8eca 100644 --- a/types/EntityLoader.d.ts +++ b/types/EntityLoader.d.ts @@ -2,7 +2,7 @@ import { DataSource } from './DataSource'; export declare class EntityLoader { /** - * @param {DataSource} + * @param {DataSource} dataSource A class that implements DataSource interface * @param {object} config */ constructor(dataSource: DataSource, config: Object); From 4f4006c2ba87fe4c97ad79d4c9cd6d035ffeaf8a Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 22:07:37 +0200 Subject: [PATCH 019/117] Export new definitions --- index.d.ts | 7 +++- types/ChannelAudience.d.ts | 29 +++++++++++++++ types/ChannelManager.d.ts | 31 ++++++++++++++++ types/CommandQueue.d.ts | 72 ++++++++++++++++++++++++++++++++++++++ types/CommandType.d.ts | 6 ++++ types/Config.d.ts | 12 +++++++ types/Damage.d.ts | 25 +++++++++++++ types/Data.d.ts | 65 ++++++++++++++++++++++++++++++++++ types/DataSource.d.ts | 4 +-- types/EntityLoader.d.ts | 4 +-- 10 files changed, 250 insertions(+), 5 deletions(-) create mode 100644 types/ChannelManager.d.ts create mode 100644 types/CommandQueue.d.ts create mode 100644 types/CommandType.d.ts create mode 100644 types/Config.d.ts create mode 100644 types/Data.d.ts diff --git a/index.d.ts b/index.d.ts index 403d823ea..7d30a9aeb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -13,10 +13,15 @@ export { Attributes } from './types/Attributes'; export { BehaviorManager } from './types/BehaviorManager'; export { Broadcast, Broadcastable } from './types/Broadcast'; export { BundleManager} from './types/BundleManager'; -export { ChannelAudience } from './types/ChannelAudience'; +export { ChannelOptions, ChannelAudience } from './types/ChannelAudience'; +export { ChannelManager } from './types/ChannelManager'; export { Character } from './types/Character'; +export { CommandQueue } from './types/CommandQueue'; +export { CommandType } from './types/CommandType'; +export { Config } from './types/Config'; export { Command } from './types/Command'; export { Damage } from './types/Damage'; +export { Data } from './types/Data'; export { DataSource } from './types/DataSource'; export { EffectableEntity } from './types/EffectableEntity'; export { EntityFactory } from './types/EntityFactory'; diff --git a/types/ChannelAudience.d.ts b/types/ChannelAudience.d.ts index f02ef2a60..fb8649a2e 100644 --- a/types/ChannelAudience.d.ts +++ b/types/ChannelAudience.d.ts @@ -1,3 +1,32 @@ +import { GameState } from "./GameState" +import { Player } from "./Player"; + +export declare interface ChannelOptions { + /** @param {GameState} state */ + state: GameState; + /** @param {Player} sender */ + sender: Player; + /** @param {string} message */ + message: string; +} + export declare class ChannelAudience { + /** + * Configure the current state for the audience. Called by {@link Channel#send} + * @param {object} options + */ + configure(options: ChannelOptions): void; + + /** + * Find targets for this audience + * @return {Array} + */ + getBroadcastTargets(): Array; + /** + * Modify the message to be sent + * @param {string} message + * @return {string} + */ + alterMessage(message: string): string; } \ No newline at end of file diff --git a/types/ChannelManager.d.ts b/types/ChannelManager.d.ts new file mode 100644 index 000000000..e99d240ee --- /dev/null +++ b/types/ChannelManager.d.ts @@ -0,0 +1,31 @@ +import { Command } from "./Command"; + +export declare class ChannelManager { + constructor(); + + /** + * Get command by name + * @param {string} + * @return {Command} + */ + get(command: string): Command; + + /** + * Add the command and set up aliases + * @param {Command} + */ + add(command: Command): void; + + /** + * @param {Command} + */ + remove(command: Command): void; + + /** + * Find a command from a partial name + * @param {string} search + * @param {boolean} returnAlias true to also return which alias of the command was used + * @return {Command} + */ + find(search: string, returnAlias: boolean): Command; +} \ No newline at end of file diff --git a/types/CommandQueue.d.ts b/types/CommandQueue.d.ts new file mode 100644 index 000000000..ecec7fbce --- /dev/null +++ b/types/CommandQueue.d.ts @@ -0,0 +1,72 @@ +export declare class CommandQueue { + constructor(); + + /** + * Safely add lag to the current queue. This method will not let you add a + * negative amount as a safety measure. If you want to subtract lag you can + * directly manipulate the `lag` property. + * @param {number} amount milliseconds of lag + */ + addLag(amount: number): void; + + /** + * @param {CommandExecutable} executable Thing to run with an execute and a queue label + * @param {number} lag Amount of lag to apply to the queue after the command is run + * @returns {number} + */ + enqueue(executable: CommandExecutable, lag: number): number; + + hasPending(): boolean; + + /** + * Execute the currently pending command if it's ready + * @return {boolean} whether the command was executed + */ + execute(): boolean; + + /** + * @type {Array} + */ + queue(): Array; + + /** + * Flush all pending commands. Does _not_ reset lastRun/lag. Meaning that if + * the queue is flushed after a command was just run its lag will still have + * to expire before another command can be run. To fully reset the queue use + * the reset() method. + */ + flush(): void; + + /** + * Completely reset the queue and any lag. This is fairly dangerous as if the + * player could reliably reset the queue they could negate any command lag. To + * clear commands without altering lag use flush() + */ + reset(): void; + + /** + * Seconds until the next command can be executed + * @type {number} + */ + lagRemaining(): number; + + /** + * Milliseconds til the next command can be executed + * @type {number} + */ + msTilNextRun(): number; + + /** + * For a given command index find how many seconds until it will run + * @param {number} commandIndex + * @return {number} + */ + getTimeTilRun(commandIndex: number): number; + + /** + * Milliseconds until the command at the given index can be run + * @param {number} commandIndex + * @return {number} + */ + getMsTilRun(commandIndex: number): number; +} \ No newline at end of file diff --git a/types/CommandType.d.ts b/types/CommandType.d.ts new file mode 100644 index 000000000..578d57e4e --- /dev/null +++ b/types/CommandType.d.ts @@ -0,0 +1,6 @@ +export declare class CommandType { + COMMAND: Symbol<'COMMAND'>; + SKILL: Symbol<'SKILL'>; + CHANNEL: Symbol<'CHANNEL'>; + MOVEMENT: Symbol<'MOVEMENT'>; +} \ No newline at end of file diff --git a/types/Config.d.ts b/types/Config.d.ts new file mode 100644 index 000000000..795634d2a --- /dev/null +++ b/types/Config.d.ts @@ -0,0 +1,12 @@ +export declare class Config { + /** + * @param {string} key + * @param {*} fallback fallback value + */ + get(key: string, fallback: any): any; + + /** + * Load `ranvier.json` from disk + */ + load(data: any): void; +} \ No newline at end of file diff --git a/types/Damage.d.ts b/types/Damage.d.ts index 1a7ffd30d..166449611 100644 --- a/types/Damage.d.ts +++ b/types/Damage.d.ts @@ -1,2 +1,27 @@ +import { Character } from "./Character"; + export declare class Damage { + /** + * @param {string} attribute Attribute the damage is going to apply to + * @param {number} amount + * @param {Character} [attacker=null] Character causing the damage + * @param {*} [source=null] Where the damage came from: skill, item, room, etc. + * @property {Object} metadata Extra info about the damage: type, hidden, critical, etc. + */ + constructor(attribute: string, amount: number, attacker: Character, source: any, metadata: object); + + /** + * Evaluate actual damage taking attacker/target's effects into account + * @param {Character} target + * @return {number} Final damage amount + */ + evaluate(target: Character): number; + + /** + * Actually lower the attribute + * @param {Character} target + * @fires Character#hit + * @fires Character#damaged + */ + commit(target: Character): void; } \ No newline at end of file diff --git a/types/Data.d.ts b/types/Data.d.ts new file mode 100644 index 000000000..d4382e9e1 --- /dev/null +++ b/types/Data.d.ts @@ -0,0 +1,65 @@ +export declare class Data { + setDataPath(path: string): void; + + /** + * Read in and parse a file. Current supports yaml and json + * @param {string} filepath + * @return {*} parsed contents of file + */ + parseFile(filepath: string): any; + + /** + * Write data to a file + * @param {string} filepath + * @param {*} data + * @param {function} callback + */ + saveFile(filepath: string, data: any, callback: Function): void; + + /** + * load/parse a data file (player/account) + * @param {string} type + * @param {string} id + * @return {*} + */ + load(type: string, id: string): any; + + /** + * Save data file (player/account) data to disk + * @param {string} type + * @param {string} id + * @param {*} data + * @param {function} callback + */ + save(type: string, id: string, data: any, callback: Function): void; + + /** + * Check if a data file exists + * @param {string} type + * @param {string} id + * @return {boolean} + */ + exists(type: string, id: string): boolean; + + /** + * get the file path for a given data file by type (player/account) + * @param {string} type + * @param {string} id + * @return {string} + */ + getDataFilePath(type: string, id: string): string; + + /** + * Determine whether or not a path leads to a legitimate JS file or not. + * @param {string} path + * @param {string} [file] + * @return {boolean} + */ + isScriptFile(path: string, file: string): booleanM + + /** + * load the MOTD for the intro screen + * @return string + */ + loadMotd(): string; +} \ No newline at end of file diff --git a/types/DataSource.d.ts b/types/DataSource.d.ts index 0a7b334c6..37dc38164 100644 --- a/types/DataSource.d.ts +++ b/types/DataSource.d.ts @@ -1,7 +1,7 @@ export declare interface DataSource { - hasData(config: object): Promise; + hasData(config: object): Promise; - fetchAll(config: object): Promise; + fetchAll(config: object): Promise; fetch(config: object, id: string|number): any; diff --git a/types/EntityLoader.d.ts b/types/EntityLoader.d.ts index 113ea8eca..3e843ad68 100644 --- a/types/EntityLoader.d.ts +++ b/types/EntityLoader.d.ts @@ -11,9 +11,9 @@ export declare class EntityLoader { setBundle(name: string): void; - hasData(): Promise; + hasData(): Promise; - fetchAll(): Promise; + fetchAll(): Promise; fetch(id: string|number); From e8e03d406a561c5776215fe7986663f0eebb426e Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 22:07:59 +0200 Subject: [PATCH 020/117] Fix docblock on CommandQueue class --- src/CommandQueue.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommandQueue.js b/src/CommandQueue.js index 3a8210025..80683002f 100644 --- a/src/CommandQueue.js +++ b/src/CommandQueue.js @@ -26,6 +26,7 @@ class CommandQueue { /** * @param {CommandExecutable} executable Thing to run with an execute and a queue label * @param {number} lag Amount of lag to apply to the queue after the command is run + * @returns {number} */ enqueue(executable, lag) { let newIndex = this.commands.push(Object.assign(executable, { lag })) - 1; @@ -100,7 +101,6 @@ class CommandQueue { /** * For a given command index find how many seconds until it will run * @param {number} commandIndex - * @param {boolean} milliseconds * @return {number} */ getTimeTilRun(commandIndex) { From 5aa61969695b319d1b2bc4dd3ce22c940aefe60b Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 22:11:37 +0200 Subject: [PATCH 021/117] Rename ChannelOptions as AudienceOptions --- index.d.ts | 2 +- types/ChannelAudience.d.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index 7d30a9aeb..784e6ffe2 100644 --- a/index.d.ts +++ b/index.d.ts @@ -13,7 +13,7 @@ export { Attributes } from './types/Attributes'; export { BehaviorManager } from './types/BehaviorManager'; export { Broadcast, Broadcastable } from './types/Broadcast'; export { BundleManager} from './types/BundleManager'; -export { ChannelOptions, ChannelAudience } from './types/ChannelAudience'; +export { AudienceOptions, ChannelAudience } from './types/ChannelAudience'; export { ChannelManager } from './types/ChannelManager'; export { Character } from './types/Character'; export { CommandQueue } from './types/CommandQueue'; diff --git a/types/ChannelAudience.d.ts b/types/ChannelAudience.d.ts index fb8649a2e..4aca667ae 100644 --- a/types/ChannelAudience.d.ts +++ b/types/ChannelAudience.d.ts @@ -1,7 +1,7 @@ import { GameState } from "./GameState" import { Player } from "./Player"; -export declare interface ChannelOptions { +export declare interface AudienceOptions { /** @param {GameState} state */ state: GameState; /** @param {Player} sender */ @@ -13,9 +13,9 @@ export declare interface ChannelOptions { export declare class ChannelAudience { /** * Configure the current state for the audience. Called by {@link Channel#send} - * @param {object} options + * @param {AudienceOptions} options */ - configure(options: ChannelOptions): void; + configure(options: AudienceOptions): void; /** * Find targets for this audience From 2cf452363d17950e4d14b880de1c257e62ff973d Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 22:23:14 +0200 Subject: [PATCH 022/117] Add definition for Channel --- index.d.ts | 1 + types/Channel.d.ts | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 types/Channel.d.ts diff --git a/index.d.ts b/index.d.ts index 784e6ffe2..5d34077c7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -13,6 +13,7 @@ export { Attributes } from './types/Attributes'; export { BehaviorManager } from './types/BehaviorManager'; export { Broadcast, Broadcastable } from './types/Broadcast'; export { BundleManager} from './types/BundleManager'; +export { ChannelConfig, Channel} from './types/Channel'; export { AudienceOptions, ChannelAudience } from './types/ChannelAudience'; export { ChannelManager } from './types/ChannelManager'; export { Character } from './types/Character'; diff --git a/types/Channel.d.ts b/types/Channel.d.ts new file mode 100644 index 000000000..89539505d --- /dev/null +++ b/types/Channel.d.ts @@ -0,0 +1,72 @@ +import { ChannelAudience } from './ChannelAudience'; +import { PlayerRoles } from './PlayerRoles'; +import { GameState } from './GameState'; +import { Player } from './Player'; + +export declare interface ChannelConfig { + /** @property {string} name Name of the channel */ + name: string; + /** @property {ChannelAudience} audience */ + audience: ChannelAudience; + /** @property {string} [description] */ + description: string; + /** @property {PlayerRoles} [minRequiredRole] */ + minRequiredRole: PlayerRoles; + /** @property {string} [color] */ + color: string; + /** @property {{sender: function, target: function}} [formatter] */ + formatter: Function; +} + +export declare class Channel { + /** @property {ChannelAudience} audience People who receive messages from this channel */ + audience: ChannelAudience; + /** @property {string} name Actual name of the channel the user will type */ + name: string; + /** @property {string} color Default color. This is purely a helper if you're using default format methods */ + color: string; + /** @property {PlayerRoles} minRequiredRole If set only players with the given role or greater can use the channel */ + minRequiredRole: PlayerRoles; + /** @property {string} description */ + description: string; + /** @property {{sender: function, target: function}} [formatter] */ + formatter: Function; + + constructor(config: ChannelConfig); + + /** + * @param {GameState} state + * @param {Player} sender + * @param {string} message + * @fires GameEntity#channelReceive + */ + send(state: GameState, sender: Player, message: string): void; + + describeSelf(sender: Player): void; + + getUsage(): string; + + /** + * How to render the message the player just sent to the channel + * E.g., you may want "chat" to say "You chat, 'message here'" + * @param {Player} sender + * @param {Player} target + * @param {string} message + * @param {Function} colorify + * @return {string} + */ + formatToSender(sender: Player, target: Player, message: string, colorify: Function): string; + + /** + * How to render the message to everyone else + * E.g., you may want "chat" to say "Playername chats, 'message here'" + * @param {Player} sender + * @param {Player} target + * @param {string} message + * @param {Function} colorify + * @return {string} + */ + formatToReceipient(sender: Player, target: Player, message: string, colorify: Function): string; + + colorify(message: string): string; +} \ No newline at end of file From 0531cce88e9216f14ebfb690a2cbfa3ecd6c42f7 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 22:23:32 +0200 Subject: [PATCH 023/117] Add missing parameter on Channel docblock --- src/Channel.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Channel.js b/src/Channel.js index b0b7ed8c7..0be0d224a 100644 --- a/src/Channel.js +++ b/src/Channel.js @@ -122,6 +122,7 @@ class Channel { * How to render the message the player just sent to the channel * E.g., you may want "chat" to say "You chat, 'message here'" * @param {Player} sender + * @param {Player} target * @param {string} message * @param {Function} colorify * @return {string} From 031db817d897cd76f3b719a361d1994efdcb7a17 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 22:32:17 +0200 Subject: [PATCH 024/117] Add definition for PlayerRoles and refactor definition for CommandType --- types/CommandType.d.ts | 10 +++++----- types/PlayerRoles.d.ts | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 types/PlayerRoles.d.ts diff --git a/types/CommandType.d.ts b/types/CommandType.d.ts index 578d57e4e..2b820c988 100644 --- a/types/CommandType.d.ts +++ b/types/CommandType.d.ts @@ -1,6 +1,6 @@ -export declare class CommandType { - COMMAND: Symbol<'COMMAND'>; - SKILL: Symbol<'SKILL'>; - CHANNEL: Symbol<'CHANNEL'>; - MOVEMENT: Symbol<'MOVEMENT'>; +export declare enum CommandType { + COMMAND = 'COMMAND', + SKILL = 'SKILL', + CHANNEL = 'CHANNEL', + MOVEMENT = 'MOVEMENT', } \ No newline at end of file diff --git a/types/PlayerRoles.d.ts b/types/PlayerRoles.d.ts new file mode 100644 index 000000000..57a71cafa --- /dev/null +++ b/types/PlayerRoles.d.ts @@ -0,0 +1,5 @@ +export declare enum PlayerRoles { + ADMIN = 2, + BUILDER = 1, + PLAYER = 0, +} \ No newline at end of file From c03e2f54aad8fa667d36e0952b77a48a17ef4d15 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 12 Apr 2020 22:34:45 +0200 Subject: [PATCH 025/117] Add definition for SkillType --- index.d.ts | 2 ++ types/SkillType.d.ts | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 types/SkillType.d.ts diff --git a/index.d.ts b/index.d.ts index 5d34077c7..0445bada6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -37,6 +37,8 @@ export { Logger } from './types/Logger'; export { Metadatable, MetadatableClass } from './types/Metadatable'; export { Npc } from './types/Npc'; export { Player } from './types/Player'; +export { PlayerRoles } from './types/PlayerRoles'; export { Room } from './types/Room'; export { Scriptable, ScriptableClass } from './types/Scriptable'; +export { SkillType } from './types/SkillType'; diff --git a/types/SkillType.d.ts b/types/SkillType.d.ts new file mode 100644 index 000000000..f252e40a0 --- /dev/null +++ b/types/SkillType.d.ts @@ -0,0 +1,4 @@ +export declare enum SkillType { + SKILL = 'SKILL', + SPELL = 'SPELL', +} \ No newline at end of file From d97535aea1300d99ea474f057c2a18ad00264bd4 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 13 Apr 2020 21:12:07 +0200 Subject: [PATCH 026/117] Add new definitions for Effect and SkillErrors, some definition fixes --- index.d.ts | 17 ++++- types/AccountManager.d.ts | 2 +- types/Area.d.ts | 4 +- types/Broadcast.d.ts | 28 +++---- types/BundleManager.d.ts | 14 ++-- types/Channel.d.ts | 6 +- types/Effect.d.ts | 157 ++++++++++++++++++++++++++++++++++++++ types/SkillErrors.d.ts | 24 ++++++ 8 files changed, 224 insertions(+), 28 deletions(-) create mode 100644 types/Effect.d.ts create mode 100644 types/SkillErrors.d.ts diff --git a/index.d.ts b/index.d.ts index 0445bada6..27fba529f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -12,8 +12,14 @@ export { AttributeFactory } from './types/AttributeFactory'; export { Attributes } from './types/Attributes'; export { BehaviorManager } from './types/BehaviorManager'; export { Broadcast, Broadcastable } from './types/Broadcast'; -export { BundleManager} from './types/BundleManager'; -export { ChannelConfig, Channel} from './types/Channel'; +export { BundleManager } from './types/BundleManager'; +export { + ChannelConfig, + Channel, + NoMessageError, + NoPartyError, + NoRecipientError, +} from './types/Channel'; export { AudienceOptions, ChannelAudience } from './types/ChannelAudience'; export { ChannelManager } from './types/ChannelManager'; export { Character } from './types/Character'; @@ -24,6 +30,7 @@ export { Command } from './types/Command'; export { Damage } from './types/Damage'; export { Data } from './types/Data'; export { DataSource } from './types/DataSource'; +export { Effect, EffectConfig, EffectModifiers } from './types/Effect'; export { EffectableEntity } from './types/EffectableEntity'; export { EntityFactory } from './types/EntityFactory'; export { EntityLoader } from './types/EntityLoader'; @@ -40,5 +47,9 @@ export { Player } from './types/Player'; export { PlayerRoles } from './types/PlayerRoles'; export { Room } from './types/Room'; export { Scriptable, ScriptableClass } from './types/Scriptable'; +export { + CooldownError, + NotEnoughResourcesError, + PassiveError, +} from './types/SkillErrors'; export { SkillType } from './types/SkillType'; - diff --git a/types/AccountManager.d.ts b/types/AccountManager.d.ts index baa44d6a5..8b4cd90ae 100644 --- a/types/AccountManager.d.ts +++ b/types/AccountManager.d.ts @@ -30,5 +30,5 @@ export declare class AccountManager { * @param {string} username * @param {boolean} force Force reload data from disk */ - loadAccount(username: string, force: boolean): void; + async loadAccount(username: string, force: boolean): void; } \ No newline at end of file diff --git a/types/Area.d.ts b/types/Area.d.ts index d5c34b665..14e67979c 100644 --- a/types/Area.d.ts +++ b/types/Area.d.ts @@ -30,13 +30,13 @@ export declare class Area extends GameEntity { * Get ranvier-root-relative path to this area * @return {string} */ - areaPath(): string; + get areaPath(): string; /** * Get an ordered list of floors in this area's map * @return {Array} */ - floors(): Array; + get floors(): Array; /** * @param {string} id Room id diff --git a/types/Broadcast.d.ts b/types/Broadcast.d.ts index a30be093a..d0251f822 100644 --- a/types/Broadcast.d.ts +++ b/types/Broadcast.d.ts @@ -1,7 +1,7 @@ import { Player } from './Player'; /** @typedef {{getBroadcastTargets: function(): Array}} */ -export type Broadcastable = { getBroadcastTargets: Array } +export declare type Broadcastable = { getBroadcastTargets: Array } export declare class Broadcast { /** @@ -12,7 +12,7 @@ export declare class Broadcast { * @param {?function(target, message): string} formatter=null Function to call to format the * message to each target */ - at(source: Broadcastable, message: string, wrapWidth: boolean, useColor: boolean, formatter: Function): void; + static at(source: Broadcastable, message: string, wrapWidth: boolean, useColor: boolean, formatter: Function): void; /** * Broadcast.at for all except given list of players @@ -24,7 +24,7 @@ export declare class Broadcast { * @param {boolean} useColor * @param {function} formatter */ - atExcept(source: Broadcastable, message: string, excludes: Array, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; + static atExcept(source: Broadcastable, message: string, excludes: Array, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; /** * Helper wrapper around Broadcast.at to be used when you're using a formatter @@ -35,25 +35,25 @@ export declare class Broadcast { * @param {number|boolean} wrapWidth * @param {boolean} useColor */ - atFormatted(source: Broadcastable, message: string, formatter: Function, wrapWidth: number|boolean, useColor: boolean): void; + static atFormatted(source: Broadcastable, message: string, formatter: Function, wrapWidth: number|boolean, useColor: boolean): void; /** * `Broadcast.at` with a newline * @see {@link Broadcast#at} */ - sayAt(source: Broadcastable, message: string, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; + static sayAt(source: Broadcastable, message: string, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; /** * `Broadcast.atExcept` with a newline * @see {@link Broadcast#atExcept} */ - sayAtExcept(source: Broadcastable, message: string, excludes, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; + static sayAtExcept(source: Broadcastable, message: string, excludes, wrapWidth: number|boolean, useColor: boolean, formatter: Function): void; /** * `Broadcast.atFormatted` with a newline * @see {@link Broadcast#atFormatted} */ - sayAtFormatted(source: Broadcastable, message: string, formatter: Function, wrapWidth: number|boolean, useColor: boolean): void; + static sayAtFormatted(source: Broadcastable, message: string, formatter: Function, wrapWidth: number|boolean, useColor: boolean): void; /** * Render the player's prompt including any extra prompts @@ -62,7 +62,7 @@ export declare class Broadcast { * @param {number} wrapWidth * @param {boolean} useColor */ - prompt(player: Player, extra: Object, wrapWidth: number, useColor: boolean): void; + static prompt(player: Player, extra: Object, wrapWidth: number, useColor: boolean): void; /** * Generate an ASCII art progress bar @@ -74,7 +74,7 @@ export declare class Broadcast { * @param {string} delimiters Characters to wrap the bar in * @return {string} */ - progress(width: number, percent: number, color: string, barChar: string, fillChar: string, delimiters: string): string; + static progress(width: number, percent: number, color: string, barChar: string, fillChar: string, delimiters: string): string; /** * Center a string in the middle of a given width @@ -84,7 +84,7 @@ export declare class Broadcast { * @param {?string} fillChar Character to pad with, defaults to ' ' * @return {string} */ - center(width: number, message: string, color: string, fillChar: string): string; + static center(width: number, message: string, color: string, fillChar: string): string; /** * Render a line of a specific width/color @@ -93,7 +93,7 @@ export declare class Broadcast { * @param {?string} color * @return {string} */ - line(width: number, fillChar: string, color: string): string; + static line(width: number, fillChar: string, color: string): string; /** * Wrap a message to a given width. Note: Evaluates color tags @@ -101,7 +101,7 @@ export declare class Broadcast { * @param {?number} width Defaults to 80 * @return {string} */ - wrap(message: string, width: number): string; + static wrap(message: string, width: number): string; /** * Indent all lines of a given string by a given amount @@ -109,7 +109,7 @@ export declare class Broadcast { * @param {number} indent * @return {string} */ - indent(message: string, indent: number): string; + static indent(message: string, indent: number): string; - isBroadcastable(source: Broadcastable): boolean; + static isBroadcastable(source: Broadcastable): boolean; } \ No newline at end of file diff --git a/types/BundleManager.d.ts b/types/BundleManager.d.ts index da18f912a..8467d675b 100644 --- a/types/BundleManager.d.ts +++ b/types/BundleManager.d.ts @@ -11,13 +11,13 @@ export declare class BundleManager { /** * Load in all bundles */ - loadBundles(distribute: boolean): void; + async loadBundles(distribute: boolean): void; /** * @param {string} bundle Bundle name * @param {string} bundlePath Path to bundle directory */ - loadBundle(bundle: string, bundlePath: string): void; + async loadBundle(bundle: string, bundlePath: string): void; loadQuestGoals(bundle: string, goalsDir: string): void; @@ -40,14 +40,14 @@ export declare class BundleManager { /** * @param {string} bundle */ - loadAreas(bundle: string): void; + async loadAreas(bundle: string): void; /** * @param {string} bundle * @param {string} areaName * @param {string} areaPath */ - loadArea(bundle: string, areaName: string, manifest: string): void; + async loadArea(bundle: string, areaName: string, manifest: string): void; /** * Load an entity (item/npc/room) from file @@ -57,7 +57,7 @@ export declare class BundleManager { * @param {EntityFactory} factory * @return {Array} */ - loadEntities(bundle: string, areaName: string, type: string, factory: EntityFactory): Array; + async loadEntities(bundle: string, areaName: string, type: string, factory: EntityFactory): Array; /** * @param {EntityFactory} factory Instance of EntityFactory that the item/npc will be loaded into @@ -71,7 +71,7 @@ export declare class BundleManager { * @param {string} areaName * @return {Promise>} */ - loadQuests(bundle: string, areaName: string): Promise> + async loadQuests(bundle: string, areaName: string): Promise> /** * @param {string} bundle @@ -96,7 +96,7 @@ export declare class BundleManager { /** * @param {string} bundle */ - loadHelp(bundle: string): void; + async loadHelp(bundle: string): void; /** * @param {string} bundle diff --git a/types/Channel.d.ts b/types/Channel.d.ts index 89539505d..ee92b4735 100644 --- a/types/Channel.d.ts +++ b/types/Channel.d.ts @@ -69,4 +69,8 @@ export declare class Channel { formatToReceipient(sender: Player, target: Player, message: string, colorify: Function): string; colorify(message: string): string; -} \ No newline at end of file +} + +export declare class NoPartyError extends Error {} +export declare class NoRecipientError extends Error {} +export declare class NoMessageError extends Error {} \ No newline at end of file diff --git a/types/Effect.d.ts b/types/Effect.d.ts new file mode 100644 index 000000000..6b20ff87d --- /dev/null +++ b/types/Effect.d.ts @@ -0,0 +1,157 @@ +import { Character } from './Character'; +import { Damage } from './Damage'; +import { GameState } from './GameState'; + +/** @typedef EffectModifiers {{attributes: !Object}} */ +export declare type EffectModifiers = { attributes: !Object }; + +export declare interface EffectConfig { + /** @property {boolean} autoActivate If this effect immediately activates itself when added to the target */ + autoActivate: boolean; + /** @property {boolean} hidden If this effect is shown in the character's effect list */ + hidden: boolean; + /** @property {boolean} refreshes If an effect with the same type is applied it will trigger an effectRefresh event instead of applying the additional effect. */ + refreshes: boolean; + /** @property {boolean} unique If multiple effects with the same `config.type` can be applied at once */ + unique: boolean; + /** @property {number} maxStacks When adding an effect of the same type it adds a stack to the current */ + /** effect up to maxStacks instead of adding the effect. Implies `config.unique` */ + maxStacks: number; + /** @property {boolean} persists If false the effect will not save to the player */ + persists: boolean; + /** @property {string} type The effect category, mainly used when disallowing stacking */ + type: string; + /** @property {boolean|number} tickInterval Number of seconds between calls to the `updateTick` listener */ + tickInterval: boolean | number; +} + +export declare class Effect extends EventEmitter { + /** @property {EffectConfig} config Effect configuration (name/desc/duration/etc.) */ + config: EffectConfig; + /** @property {string} description */ + description: string; + /** @property {number} duration Total duration of effect in _milliseconds_ */ + duration: number; + /** @property {number} elapsed Get elapsed time in _milliseconds_ */ + elapsed: number; + /** @property {string} id filename minus .js */ + id: string; + /** @property {EffectModifiers} modifiers Attribute modifier functions */ + modifier: EffectModifiers; + /** @property {string} name */ + name: string; + /** @property {number} remaining Number of seconds remaining */ + remaining: number; + /** @property {number} startedAt Date.now() time this effect became active */ + startedAt: number; + /** @property {object} state Configuration of this _type_ of effect (magnitude, element, stat, etc.) */ + state: object; + /** @property {Character} target Character this effect is... effecting */ + target: Character; + + constructor(id: string, def: object); + + /** + * @type {string} + */ + get name(): string; + + /** + * @type {string} + */ + get description(): string; + + /** + * @type {number} + */ + get duration(): number; + + set duration(dur: number): void; + + /** + * Elapsed time in milliseconds since event was activated + * @type {number} + */ + get elapsed(): number; + + /** + * Remaining time in seconds + * @type {number} + */ + get remaining(): number; + + isCurrent(): boolean; + + /** + * Set this effect active + * @fires Effect#effectActivated + */ + activate(): void; + + /** + * Set this effect active + * @fires Effect#effectDeactivated + */ + deactivate(): void; + + /** + * Remove this effect from its target + * @fires Effect#remove + */ + remove(): void; + + /** + * Stop this effect from having any effect temporarily + */ + pause(): void; + + /** + * Resume a paused effect + */ + resume(): void; + + /** + * Apply effect attribute modifiers to a given value + * + * @param {string} attrName + * @param {number} currentValue + * @return {number} attribute value modified by effect + */ + modifyAttribute(attrName: string, currentValue: number): number; + + /** + * Apply effect property modifiers to a given value + * + * @param {string} propertyName + * @param {*} currentValue + * @return {*} property value modified by effect + */ + modifyProperty(propertyName: string, currentValue: any): any; + + /** + * @param {Damage} damage + * @param {number} currentAmount + * @return {Damage} + */ + modifyIncomingDamage(damage: Damage, currentAmount: number): Damage; + + /** + * @param {Damage} damage + * @param {number} currentAmount + * @return {Damage} + */ + modifyOutgoingDamage(damage: Damage, currentAmount: number): Damage; + + /** + * Gather data to persist + * @return {Object} + */ + serialize(): Object; + + /** + * Reinitialize from persisted data + * @param {GameState} + * @param {Object} data + */ + hydrate(state: GameState, data: Object): void; +} diff --git a/types/SkillErrors.d.ts b/types/SkillErrors.d.ts new file mode 100644 index 000000000..b50075ff8 --- /dev/null +++ b/types/SkillErrors.d.ts @@ -0,0 +1,24 @@ +import { Effect } from './Effect'; + +/** + * Error used when trying to execute a skill and the player doesn't have enough resources + * @extends Error + */ +export declare class NotEnoughResourcesError extends Error { } + +/** + * Error used when trying to execute a passive skill + * @extends Error + */ +export declare class PassiveError extends Error { } + + +export declare class CooldownError extends Error { + /** @property {Effect} effect */ + effect: Effect; + + /** + * @param {Effect} effect Cooldown effect that triggered this error + */ + constructor(effect: Effect); +} \ No newline at end of file From 3667f3504810d716c0fcc01d9af3188ea95d97d7 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 13 Apr 2020 21:15:16 +0200 Subject: [PATCH 027/117] Drop unnecessary space --- src/Effect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Effect.js b/src/Effect.js index 67cad18c8..c23ba113b 100644 --- a/src/Effect.js +++ b/src/Effect.js @@ -109,7 +109,7 @@ class Effect extends EventEmitter { * Elapsed time in milliseconds since event was activated * @type {number} */ - get elapsed () { + get elapsed() { if (!this.startedAt) { return null; } From 331f8d74d3311cfbedeeac0270a41373f8bba34d Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 20 Apr 2020 23:12:39 +0200 Subject: [PATCH 028/117] Fix map property Map types --- types/Area.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/types/Area.d.ts b/types/Area.d.ts index 14e67979c..6072daa63 100644 --- a/types/Area.d.ts +++ b/types/Area.d.ts @@ -1,3 +1,4 @@ +import { AreaFloor } from './AreaFloor'; import { Broadcastable } from './Broadcast'; import { GameEntity } from './GameEntity'; import { GameState } from './GameState'; @@ -13,8 +14,8 @@ export declare class Area extends GameEntity { title: string; /** @property {string} script A custom script for this item */ script: string; - /** @property {Map} map a Map object keyed by the floor z-index, each floor is an array with [x][y] indexes for coordinates. */ - map: Map; + /** @property {Map} map a Map object keyed by the floor z-index, each floor is an array with [x][y] indexes for coordinates. */ + map: Map; /** Map of room id to Room */ rooms: Map; /** Active NPCs that originate from this area. Note: this is NPCs that */ From c424d9f6e8bd2e4588729901a2dc56186a1885b1 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 20 Apr 2020 23:21:23 +0200 Subject: [PATCH 029/117] Declare and export AccountConfig interface to use as argument for Account constructor --- index.d.ts | 2 +- types/Account.d.ts | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 27fba529f..62ec31c30 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -export { Account } from './types/Account'; +export { Account, AccountConfig } from './types/Account'; export { AccountManager } from './types/AccountManager'; export { Area } from './types/Area'; export { AreaAudience } from './types/AreaAudience'; diff --git a/types/Account.d.ts b/types/Account.d.ts index 4869d35f6..ebf622159 100644 --- a/types/Account.d.ts +++ b/types/Account.d.ts @@ -1,3 +1,14 @@ +export declare interface AccountConfig { + /** @property {string} username */ + username: string; + /** @property {Array} characters List of character names in this account */ + characters: Array; + /** @property {string} password Hashed password */ + password: string; + /** @property {boolean} banned Whether this account is banned or not */ + banned: boolean; +} + export declare class Account { /** @property {string} username */ username: string; @@ -9,9 +20,9 @@ export declare class Account { banned: boolean; /** - * @param {Object} data Account save data + * @param {AccountConfig} data Account save data */ - constructor(data: Object); + constructor(data: AccountConfig); /** * @return {string} From e1a93e3c6b7b228c6daf1df122e9949377fb46ab Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 20 Apr 2020 23:22:10 +0200 Subject: [PATCH 030/117] Prettier fix --- types/Account.d.ts | 130 ++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/types/Account.d.ts b/types/Account.d.ts index ebf622159..d4495eeef 100644 --- a/types/Account.d.ts +++ b/types/Account.d.ts @@ -1,87 +1,87 @@ export declare interface AccountConfig { - /** @property {string} username */ - username: string; - /** @property {Array} characters List of character names in this account */ - characters: Array; - /** @property {string} password Hashed password */ - password: string; - /** @property {boolean} banned Whether this account is banned or not */ - banned: boolean; + /** @property {string} username */ + username: string; + /** @property {Array} characters List of character names in this account */ + characters: Array; + /** @property {string} password Hashed password */ + password: string; + /** @property {boolean} banned Whether this account is banned or not */ + banned: boolean; } export declare class Account { - /** @property {string} username */ - username: string; - /** @property {Array} characters List of character names in this account */ - characters: Array; - /** @property {string} password Hashed password */ - password: string; - /** @property {boolean} banned Whether this account is banned or not */ - banned: boolean; + /** @property {string} username */ + username: string; + /** @property {Array} characters List of character names in this account */ + characters: Array; + /** @property {string} password Hashed password */ + password: string; + /** @property {boolean} banned Whether this account is banned or not */ + banned: boolean; - /** - * @param {AccountConfig} data Account save data - */ - constructor(data: AccountConfig); + /** + * @param {AccountConfig} data Account save data + */ + constructor(data: AccountConfig); - /** - * @return {string} - */ - getUsername(): string; + /** + * @return {string} + */ + getUsername(): string; - /** - * @param {string} username - */ - addCharacter(username: string): void; + /** + * @param {string} username + */ + addCharacter(username: string): void; - /** - * @param {string} name - * @return {boolean} - */ - hasCharacter(name: string): boolean; + /** + * @param {string} name + * @return {boolean} + */ + hasCharacter(name: string): boolean; - /** - * @param {string} name Delete one of the chars - */ - deleteCharacter(name: string): void; + /** + * @param {string} name Delete one of the chars + */ + deleteCharacter(name: string): void; - /** - * @param {string} name Removes the deletion of one of the chars - */ - undeleteCharacter(name: string): void; + /** + * @param {string} name Removes the deletion of one of the chars + */ + undeleteCharacter(name: string): void; - /** - * @param {string} password Unhashed password. Is hashed inside this function - */ - setPassword(pass: string): void; + /** + * @param {string} password Unhashed password. Is hashed inside this function + */ + setPassword(pass: string): void; - /** - * @param {string} pass Unhashed password to check against account's password - * @return {boolean} - */ - checkPassword(pass: string): boolean; + /** + * @param {string} pass Unhashed password to check against account's password + * @return {boolean} + */ + checkPassword(pass: string): boolean; - /** - * @param {function} callback after-save callback - */ - save(callback: Function): void; + /** + * @param {function} callback after-save callback + */ + save(callback: Function): void; - /** + /** * Set this account to banned There is no unban because this can just be done by manually editing the account file */ - ban(): void; + ban(): void; - /** + /** * Set this account to deleted There is no undelete because this can just be done by manually editing the account file */ - deleteAccount(): void; + deleteAccount(): void; - /** - * Gather data from account object that will be persisted to disk - * - * @return {Object} - */ - serialize(): Object; -} \ No newline at end of file + /** + * Gather data from account object that will be persisted to disk + * + * @return {Object} + */ + serialize(): Object; +} From 552c21fd00b9f5975551f7ba6869f1b32ba8c1a1 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 20 Apr 2020 23:25:11 +0200 Subject: [PATCH 031/117] Add missing deleted and metadata property on AccountConfig definition --- types/Account.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/Account.d.ts b/types/Account.d.ts index d4495eeef..7f445efc8 100644 --- a/types/Account.d.ts +++ b/types/Account.d.ts @@ -7,6 +7,11 @@ export declare interface AccountConfig { password: string; /** @property {boolean} banned Whether this account is banned or not */ banned: boolean; + /** @property {boolean} deleted Whether this account is deleted or not */ + deleted: boolean; + // Arbitrary data bundles are free to shove whatever they want in + // WARNING: values must be JSON.stringify-able + metadata: object; } export declare class Account { From e2a9ed69593e46beb17ff00d93013847d2019e8b Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 20 Apr 2020 23:34:41 +0200 Subject: [PATCH 032/117] Add basic properties definition for Character class and export empty class for Inventory and EffectList --- types/Character.d.ts | 15 +++++++++++++++ types/EffectList.d.ts | 3 +++ types/Inventory.d.ts | 4 ++++ 3 files changed, 22 insertions(+) create mode 100644 types/EffectList.d.ts create mode 100644 types/Inventory.d.ts diff --git a/types/Character.d.ts b/types/Character.d.ts index 25bed63ba..00f3cc7e4 100644 --- a/types/Character.d.ts +++ b/types/Character.d.ts @@ -1,5 +1,20 @@ import { EffectableEntity } from './EffectableEntity'; +import { EffectList } from './EffectList'; +import { Inventory } from './Inventory'; import { Metadatable } from './Metadatable'; +import { Room } from './Room'; export declare class Character extends Metadatable(EffectableEntity) { + /** @property {string} name Name shown on look/who/login */ + name: string; + /** @property {Inventory} inventory */ + inventory: Inventory; + /** @property {Set} combatants Enemies this character is currently in combat with */ + combatants: Set; + /** @property {number} level */ + level: number; + /** @property {EffectList} effects List of current effects applied to the character */ + effects: EffectList; + /** @property {Room} room Room the character is currently in */ + room: Room; } \ No newline at end of file diff --git a/types/EffectList.d.ts b/types/EffectList.d.ts new file mode 100644 index 000000000..e993b3599 --- /dev/null +++ b/types/EffectList.d.ts @@ -0,0 +1,3 @@ +export declare class EffectList { + +} \ No newline at end of file diff --git a/types/Inventory.d.ts b/types/Inventory.d.ts new file mode 100644 index 000000000..fce902962 --- /dev/null +++ b/types/Inventory.d.ts @@ -0,0 +1,4 @@ +export declare class InventoryFullError extends Error {} + +export declare class Inventory extends Map { +} \ No newline at end of file From fd621ce00b72f8141ca874b9cd707f9766e7a2e7 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 20 Apr 2020 23:35:05 +0200 Subject: [PATCH 033/117] Lint fix --- types/Character.d.ts | 26 +++++++++++++------------- types/Inventory.d.ts | 3 +-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/types/Character.d.ts b/types/Character.d.ts index 00f3cc7e4..2c1ba14be 100644 --- a/types/Character.d.ts +++ b/types/Character.d.ts @@ -5,16 +5,16 @@ import { Metadatable } from './Metadatable'; import { Room } from './Room'; export declare class Character extends Metadatable(EffectableEntity) { - /** @property {string} name Name shown on look/who/login */ - name: string; - /** @property {Inventory} inventory */ - inventory: Inventory; - /** @property {Set} combatants Enemies this character is currently in combat with */ - combatants: Set; - /** @property {number} level */ - level: number; - /** @property {EffectList} effects List of current effects applied to the character */ - effects: EffectList; - /** @property {Room} room Room the character is currently in */ - room: Room; -} \ No newline at end of file + /** @property {string} name Name shown on look/who/login */ + name: string; + /** @property {Inventory} inventory */ + inventory: Inventory; + /** @property {Set} combatants Enemies this character is currently in combat with */ + combatants: Set; + /** @property {number} level */ + level: number; + /** @property {EffectList} effects List of current effects applied to the character */ + effects: EffectList; + /** @property {Room} room Room the character is currently in */ + room: Room; +} diff --git a/types/Inventory.d.ts b/types/Inventory.d.ts index fce902962..ba020b8c0 100644 --- a/types/Inventory.d.ts +++ b/types/Inventory.d.ts @@ -1,4 +1,3 @@ export declare class InventoryFullError extends Error {} -export declare class Inventory extends Map { -} \ No newline at end of file +export declare class Inventory extends Map {} From 8c85d8d1a3b55d4cf1437cd50e06baa6433e000b Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 20 Apr 2020 23:36:39 +0200 Subject: [PATCH 034/117] Export new definition classes --- index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.d.ts b/index.d.ts index 62ec31c30..37298b568 100644 --- a/index.d.ts +++ b/index.d.ts @@ -32,6 +32,7 @@ export { Data } from './types/Data'; export { DataSource } from './types/DataSource'; export { Effect, EffectConfig, EffectModifiers } from './types/Effect'; export { EffectableEntity } from './types/EffectableEntity'; +export { EffectList } from './types/EffectList'; export { EntityFactory } from './types/EntityFactory'; export { EntityLoader } from './types/EntityLoader'; export { EntityReference } from './types/EntityReference'; @@ -40,6 +41,7 @@ export { GameEntity } from './types/GameEntity'; export { GameState } from './types/GameState'; export { Heal } from './types/Heal'; export { Item } from './types/Item'; +export { Inventory, InventoryFullError } from './types/Inventory'; export { Logger } from './types/Logger'; export { Metadatable, MetadatableClass } from './types/Metadatable'; export { Npc } from './types/Npc'; From b110def0a352d9cab35037fca552faeeb782578f Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Tue, 21 Apr 2020 15:38:26 +0200 Subject: [PATCH 035/117] Complete and export definition for Character and CharacterConfig interface --- index.d.ts | 2 +- types/Character.d.ts | 139 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 37298b568..61ad744b8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -22,7 +22,7 @@ export { } from './types/Channel'; export { AudienceOptions, ChannelAudience } from './types/ChannelAudience'; export { ChannelManager } from './types/ChannelManager'; -export { Character } from './types/Character'; +export { Character, CharacterConfig } from './types/Character'; export { CommandQueue } from './types/CommandQueue'; export { CommandType } from './types/CommandType'; export { Config } from './types/Config'; diff --git a/types/Character.d.ts b/types/Character.d.ts index 2c1ba14be..7a14f2da4 100644 --- a/types/Character.d.ts +++ b/types/Character.d.ts @@ -3,6 +3,20 @@ import { EffectList } from './EffectList'; import { Inventory } from './Inventory'; import { Metadatable } from './Metadatable'; import { Room } from './Room'; +import { EntityReference } from './EntityReference'; + +export declare interface CharacterConfig { + /** @property {string} name Name shown on look/who/login */ + name: string; + /** @property {Inventory} inventory */ + inventory: Inventory; + equipment: Map; + /** @property {number} level */ + level: number; + /** @property {Room} room Room the character is currently in */ + room: Room; + metadata: object; +} export declare class Character extends Metadatable(EffectableEntity) { /** @property {string} name Name shown on look/who/login */ @@ -17,4 +31,129 @@ export declare class Character extends Metadatable(EffectableEntity) { effects: EffectList; /** @property {Room} room Room the character is currently in */ room: Room; + + constructor(data: CharacterConfig); + + /** + * Start combat with a given target. + * @param {Character} target + * @param {?number} lag Optional milliseconds of lag to apply before the first attack + * @fires Character#combatStart + */ + initiateCombat(target: Character, lag: number): void; + + /** + * Check to see if this character is currently in combat or if they are + * currently in combat with a specific character + * @param {?Character} target + * @return boolean + */ + isInCombat(target: Character): boolean; + + /** + * @param {Character} target + * @fires Character#combatantAdded + */ + addCombatant(target: Character): void; + + /** + * @param {Character} target + * @fires Character#combatantRemoved + * @fires Character#combatEnd + */ + removeCombatant(target: Character): void; + + /** + * Fully remove this character from combat + */ + removeFromCombat(): void; + + /** + * @param {Item} item + * @param {string} slot Slot to equip the item in + * + * @throws EquipSlotTakenError + * @throws EquipAlreadyEquippedError + * @fires Character#equip + * @fires Item#equip + */ + equip(item: Item, slot: string): void; + + /** + * Remove equipment in a given slot and move it to the character's inventory + * @param {string} slot + * + * @throws InventoryFullError + * @fires Item#unequip + * @fires Character#unequip + */ + unequip(slot: string): void; + + /** + * Move an item to the character's inventory + * @param {Item} item + */ + addItem(item: Item): void; + + /** + * Remove an item from the character's inventory. Warning: This does not automatically place the + * item in any particular place. You will need to manually add it to the room or another + * character's inventory + * @param {Item} item + */ + removeItem(item: Item): void; + + /** + * Check to see if this character has a particular item by EntityReference + * @param {EntityReference} itemReference + * @return {Item|boolean} + */ + hasItem(itemReference: EntityReference): Item | boolean; + + /** + * @return {boolean} + */ + isInventoryFull(): boolean; + + /** + * Begin following another character. If the character follows itself they stop following. + * @param {Character} target + */ + follow(target: Character): void; + + /** + * Stop following whoever the character was following + * @fires Character#unfollowed + */ + unfollow(): void; + + /** + * @param {Character} follower + * @fires Character#gainedFollower + */ + addFollower(follower: Character): void; + + /** + * @param {Character} follower + * @fires Character#lostFollower + */ + removeFollower(follower: Character): void; + + /** + * @param {Character} target + * @return {boolean} + */ + isFollowing(target: Character): boolean; + + /** + * @param {Character} target + * @return {boolean} + */ + hasFollower(target: Character): boolean; + + /** + * Gather data to be persisted + * @return {Object} + */ + serialize(): Object; } From 851130cf3e851e7b8b2f6ecf8e55718815926d89 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Tue, 21 Apr 2020 15:47:34 +0200 Subject: [PATCH 036/117] Add missing import on Character definition --- types/Character.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/Character.d.ts b/types/Character.d.ts index 7a14f2da4..847f90fb3 100644 --- a/types/Character.d.ts +++ b/types/Character.d.ts @@ -4,6 +4,7 @@ import { Inventory } from './Inventory'; import { Metadatable } from './Metadatable'; import { Room } from './Room'; import { EntityReference } from './EntityReference'; +import { Item } from './Item'; export declare interface CharacterConfig { /** @property {string} name Name shown on look/who/login */ From ed6c3d4c3e7a5e014ffba128a60f00ac6094d4ed Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Tue, 21 Apr 2020 15:48:01 +0200 Subject: [PATCH 037/117] Sort imports --- types/Character.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/Character.d.ts b/types/Character.d.ts index 847f90fb3..0442abc04 100644 --- a/types/Character.d.ts +++ b/types/Character.d.ts @@ -1,10 +1,10 @@ import { EffectableEntity } from './EffectableEntity'; import { EffectList } from './EffectList'; +import { EntityReference } from './EntityReference'; import { Inventory } from './Inventory'; +import { Item } from './Item'; import { Metadatable } from './Metadatable'; import { Room } from './Room'; -import { EntityReference } from './EntityReference'; -import { Item } from './Item'; export declare interface CharacterConfig { /** @property {string} name Name shown on look/who/login */ From ce9f331403f0c2e723dde7b77d5c548ee7b68f19 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 18 Sep 2020 18:18:00 -0400 Subject: [PATCH 038/117] Add placeholder types. --- index.d.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/index.d.ts b/index.d.ts index 61ad744b8..b13370429 100644 --- a/index.d.ts +++ b/index.d.ts @@ -55,3 +55,24 @@ export { PassiveError, } from './types/SkillErrors'; export { SkillType } from './types/SkillType'; + + +// Placeholders for types yet to be defined. +export type CommandManager = any; +export type DataSourceRegistry = any; +export type EffectFactory = any; +export type EntityLoaderRegistry = any; +export type GameServer = any; +export type HelpManager = any; +export type ItemFactory = any; +export type ItemManager = any; +export type MobFactory = any; +export type MobManager = any; +export type PartyManager = any; +export type PlayerManager = any; +export type QuestFactory = any; +export type QuestGoalManager = any; +export type QuestRewardManager = any; +export type RoomFactory = any; +export type RoomManager = any; +export type SkillManager = any; \ No newline at end of file From fb5d8720a19b1f03a728e5df719a97fc7985a964 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 18 Sep 2020 18:18:42 -0400 Subject: [PATCH 039/117] Add types to .npmignore exclusions so they are available in node_modules after npm install --- .npmignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.npmignore b/.npmignore index 93c947c2e..f3fbb83a1 100644 --- a/.npmignore +++ b/.npmignore @@ -4,4 +4,6 @@ !LICENSE.txt !src/* !index.js +!index.d.ts +!types/* !package* From 6f1e9ff98ca24df081d425c5209b324658f7527e Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 18 Sep 2020 18:21:34 -0400 Subject: [PATCH 040/117] Newline eof --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index b13370429..ee50ab9d4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -75,4 +75,4 @@ export type QuestGoalManager = any; export type QuestRewardManager = any; export type RoomFactory = any; export type RoomManager = any; -export type SkillManager = any; \ No newline at end of file +export type SkillManager = any; From fea04a4055d4997e459a51ac95df597b6c2bf4e4 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 18 Sep 2020 18:30:20 -0400 Subject: [PATCH 041/117] Fix some of the typing syntax for EventManager, including typing for EventEmitter. --- types/EventManager.d.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/types/EventManager.d.ts b/types/EventManager.d.ts index e7ce14573..16ee541ff 100644 --- a/types/EventManager.d.ts +++ b/types/EventManager.d.ts @@ -1,3 +1,5 @@ +import EventEmitter from 'events'; + export declare class EventManager { constructor(); @@ -19,7 +21,7 @@ export declare class EventManager { * @param {EventEmitter} emitter * @param {Object} config */ - attach(emitter: EventEmitter, config: Object); + attach(emitter: typeof EventEmitter, config?: Object); /** * Remove all listeners for a given emitter or only those for the given events @@ -32,5 +34,5 @@ export declare class EventManager { * @param {EventEmitter} emitter * @param {?string|iterable} events Optional name or list of event names to remove listeners from */ - detach(emitter: EventEmitter, events: ?string|iterable): void; -} \ No newline at end of file + detach(emitter: typeof EventEmitter, events?: string | string[]): void; +} From 3d52964f860db00113ec3149f25b3368f9b2b6a7 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 18 Sep 2020 18:31:47 -0400 Subject: [PATCH 042/117] Type Set in EventManager --- types/EventManager.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/EventManager.d.ts b/types/EventManager.d.ts index 16ee541ff..45ac9b9b1 100644 --- a/types/EventManager.d.ts +++ b/types/EventManager.d.ts @@ -8,7 +8,7 @@ export declare class EventManager { * @param {string} name * @return {Set} */ - get(name: string): Set; + get(name: string): Set; /** * @param {string} eventName From 411e9a2667fd18273a6313b2acdfd28188d0f790 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 18 Sep 2020 18:38:54 -0400 Subject: [PATCH 043/117] Add some static keywords to defs --- types/Config.d.ts | 4 ++-- types/Data.d.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/types/Config.d.ts b/types/Config.d.ts index 795634d2a..3f40da3bf 100644 --- a/types/Config.d.ts +++ b/types/Config.d.ts @@ -3,10 +3,10 @@ export declare class Config { * @param {string} key * @param {*} fallback fallback value */ - get(key: string, fallback: any): any; + static get(key: string, fallback: any): any; /** * Load `ranvier.json` from disk */ - load(data: any): void; + static load(data: any): void; } \ No newline at end of file diff --git a/types/Data.d.ts b/types/Data.d.ts index d4382e9e1..3a9bed088 100644 --- a/types/Data.d.ts +++ b/types/Data.d.ts @@ -1,5 +1,5 @@ export declare class Data { - setDataPath(path: string): void; + static setDataPath(path: string): void; /** * Read in and parse a file. Current supports yaml and json From eee3239371aac0d79269c3759e8394e336cdf49c Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 18 Sep 2020 18:39:41 -0400 Subject: [PATCH 044/117] Add more to Data --- types/Data.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/types/Data.d.ts b/types/Data.d.ts index 3a9bed088..5780755e1 100644 --- a/types/Data.d.ts +++ b/types/Data.d.ts @@ -6,7 +6,7 @@ export declare class Data { * @param {string} filepath * @return {*} parsed contents of file */ - parseFile(filepath: string): any; + static parseFile(filepath: string): any; /** * Write data to a file @@ -14,7 +14,7 @@ export declare class Data { * @param {*} data * @param {function} callback */ - saveFile(filepath: string, data: any, callback: Function): void; + static saveFile(filepath: string, data: any, callback: Function): void; /** * load/parse a data file (player/account) @@ -22,7 +22,7 @@ export declare class Data { * @param {string} id * @return {*} */ - load(type: string, id: string): any; + static load(type: string, id: string): any; /** * Save data file (player/account) data to disk @@ -31,7 +31,7 @@ export declare class Data { * @param {*} data * @param {function} callback */ - save(type: string, id: string, data: any, callback: Function): void; + static save(type: string, id: string, data: any, callback: Function): void; /** * Check if a data file exists @@ -39,7 +39,7 @@ export declare class Data { * @param {string} id * @return {boolean} */ - exists(type: string, id: string): boolean; + static exists(type: string, id: string): boolean; /** * get the file path for a given data file by type (player/account) @@ -47,7 +47,7 @@ export declare class Data { * @param {string} id * @return {string} */ - getDataFilePath(type: string, id: string): string; + static getDataFilePath(type: string, id: string): string; /** * Determine whether or not a path leads to a legitimate JS file or not. @@ -55,11 +55,11 @@ export declare class Data { * @param {string} [file] * @return {boolean} */ - isScriptFile(path: string, file: string): booleanM + static isScriptFile(path: string, file: string): booleanM /** * load the MOTD for the intro screen * @return string */ - loadMotd(): string; + static loadMotd(): string; } \ No newline at end of file From eb7a0f4dd0b37011d5f40fb0e136ab2e357e3a32 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 18 Sep 2020 18:43:41 -0400 Subject: [PATCH 045/117] Add static keyword to Logger --- types/Logger.d.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/types/Logger.d.ts b/types/Logger.d.ts index 86dac740c..d3b33c20e 100644 --- a/types/Logger.d.ts +++ b/types/Logger.d.ts @@ -1,25 +1,25 @@ export declare class Logger { - getLevel(): string; - setLevel(level): void; + static getLevel(): string; + static setLevel(level): void; /* Medium priority logging, default. */ - log(...messages): void; + static log(...messages): void; /* Appends red "ERROR" to the start of logs. Highest priority logging. */ - error(...messages): void; + static error(...messages): void; /* Less high priority than error, still higher visibility than default. */ - warn(...messages): void; + static warn(...messages): void; /* Lower priority logging. Only logs if the environment variable is set to VERBOSE. */ - verbose(...messages): void; - setFileLogging(path): void; - deactivateFileLogging(): void; - enablePrettyErrors(): void; -} + static verbose(...messages): void; + static setFileLogging(path): void; + static deactivateFileLogging(): void;static + static enablePrettyErrors(): void; +} \ No newline at end of file From ef26a1d01095cccc2bbba02b1a37a0b1a96e6635 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 18 Sep 2020 18:45:04 -0400 Subject: [PATCH 046/117] Fix typo, formatting issues --- types/Config.d.ts | 2 +- types/Data.d.ts | 4 ++-- types/Logger.d.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/types/Config.d.ts b/types/Config.d.ts index 3f40da3bf..5b1018473 100644 --- a/types/Config.d.ts +++ b/types/Config.d.ts @@ -9,4 +9,4 @@ export declare class Config { * Load `ranvier.json` from disk */ static load(data: any): void; -} \ No newline at end of file +} diff --git a/types/Data.d.ts b/types/Data.d.ts index 5780755e1..13658fb70 100644 --- a/types/Data.d.ts +++ b/types/Data.d.ts @@ -55,11 +55,11 @@ export declare class Data { * @param {string} [file] * @return {boolean} */ - static isScriptFile(path: string, file: string): booleanM + static isScriptFile(path: string, file: string): boolean; /** * load the MOTD for the intro screen * @return string */ static loadMotd(): string; -} \ No newline at end of file +} diff --git a/types/Logger.d.ts b/types/Logger.d.ts index d3b33c20e..0a2b16b43 100644 --- a/types/Logger.d.ts +++ b/types/Logger.d.ts @@ -20,6 +20,6 @@ export declare class Logger { */ static verbose(...messages): void; static setFileLogging(path): void; - static deactivateFileLogging(): void;static + static deactivateFileLogging(): void; static enablePrettyErrors(): void; -} \ No newline at end of file +} From 7efe54e70c1e158f39d3d3ff3e674042cf4ee849 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 18 Sep 2020 18:56:14 -0400 Subject: [PATCH 047/117] Fix async keyword use -- not allowed in *.d.ts, have to set return type to Promise. Also change Array to T[] --- types/BundleManager.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/BundleManager.d.ts b/types/BundleManager.d.ts index 8467d675b..d31997517 100644 --- a/types/BundleManager.d.ts +++ b/types/BundleManager.d.ts @@ -11,13 +11,13 @@ export declare class BundleManager { /** * Load in all bundles */ - async loadBundles(distribute: boolean): void; + loadBundles(distribute?: boolean): Promise; /** * @param {string} bundle Bundle name * @param {string} bundlePath Path to bundle directory */ - async loadBundle(bundle: string, bundlePath: string): void; + loadBundle(bundle: string, bundlePath: string): Promise; loadQuestGoals(bundle: string, goalsDir: string): void; @@ -40,14 +40,14 @@ export declare class BundleManager { /** * @param {string} bundle */ - async loadAreas(bundle: string): void; + loadAreas(bundle: string): Promise; /** * @param {string} bundle * @param {string} areaName * @param {string} areaPath */ - async loadArea(bundle: string, areaName: string, manifest: string): void; + loadArea(bundle: string, areaName: string, manifest: string): Promise; /** * Load an entity (item/npc/room) from file @@ -57,7 +57,7 @@ export declare class BundleManager { * @param {EntityFactory} factory * @return {Array} */ - async loadEntities(bundle: string, areaName: string, type: string, factory: EntityFactory): Array; + loadEntities(bundle: string, areaName: string, type: string, factory: EntityFactory): Promise; /** * @param {EntityFactory} factory Instance of EntityFactory that the item/npc will be loaded into @@ -71,7 +71,7 @@ export declare class BundleManager { * @param {string} areaName * @return {Promise>} */ - async loadQuests(bundle: string, areaName: string): Promise> + loadQuests(bundle: string, areaName: string): Promise /** * @param {string} bundle @@ -96,7 +96,7 @@ export declare class BundleManager { /** * @param {string} bundle */ - async loadHelp(bundle: string): void; + loadHelp(bundle: string): Promise; /** * @param {string} bundle From e651b3b2446001da2023880cfa4f72aa8f83f1a0 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 18 Sep 2020 18:59:58 -0400 Subject: [PATCH 048/117] Fallback should be optional --- types/Config.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/Config.d.ts b/types/Config.d.ts index 5b1018473..59db12255 100644 --- a/types/Config.d.ts +++ b/types/Config.d.ts @@ -3,7 +3,7 @@ export declare class Config { * @param {string} key * @param {*} fallback fallback value */ - static get(key: string, fallback: any): any; + static get(key: string, fallback?: any): any; /** * Load `ranvier.json` from disk From f06441e92c018d1878f57524be57b8c3fc9ecbda Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 18 Sep 2020 19:07:33 -0400 Subject: [PATCH 049/117] Having placeholder as type w/ same name as class caused issues --- index.d.ts | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/index.d.ts b/index.d.ts index ee50ab9d4..85a680a03 100644 --- a/index.d.ts +++ b/index.d.ts @@ -58,21 +58,21 @@ export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. -export type CommandManager = any; -export type DataSourceRegistry = any; -export type EffectFactory = any; -export type EntityLoaderRegistry = any; -export type GameServer = any; -export type HelpManager = any; -export type ItemFactory = any; -export type ItemManager = any; -export type MobFactory = any; -export type MobManager = any; -export type PartyManager = any; -export type PlayerManager = any; -export type QuestFactory = any; -export type QuestGoalManager = any; -export type QuestRewardManager = any; -export type RoomFactory = any; -export type RoomManager = any; -export type SkillManager = any; +export declare class CommandManager { [key: string]: any }; +export declare class DataSourceRegistry { [key: string]: any }; +export declare class EffectFactory { [key: string]: any }; +export declare class EntityLoaderRegistry { [key: string]: any }; +export declare class GameServer { [key: string]: any }; +export declare class HelpManager { [key: string]: any }; +export declare class ItemFactory { [key: string]: any }; +export declare class ItemManager { [key: string]: any }; +export declare class MobFactory { [key: string]: any }; +export declare class MobManager { [key: string]: any }; +export declare class PartyManager { [key: string]: any }; +export declare class PlayerManager { [key: string]: any }; +export declare class QuestFactory { [key: string]: any }; +export declare class QuestGoalManager { [key: string]: any }; +export declare class QuestRewardManager { [key: string]: any }; +export declare class RoomFactory { [key: string]: any }; +export declare class RoomManager { [key: string]: any }; +export declare class SkillManager { [key: string]: any }; From 4b1fdd852ba1469a81154d71c84e8efd1ffe6b7c Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 15:16:30 -0400 Subject: [PATCH 050/117] Make EntityReference type a string, make Room types more accurate. --- types/EntityReference.d.ts | 4 +--- types/Room.d.ts | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/types/EntityReference.d.ts b/types/EntityReference.d.ts index 8b697ba94..3f3598559 100644 --- a/types/EntityReference.d.ts +++ b/types/EntityReference.d.ts @@ -1,3 +1 @@ -export declare class EntityReference { - -} \ No newline at end of file +export declare type EntityReference = string; \ No newline at end of file diff --git a/types/Room.d.ts b/types/Room.d.ts index 5ffe837c4..a0d32b339 100644 --- a/types/Room.d.ts +++ b/types/Room.d.ts @@ -7,13 +7,38 @@ import { Item } from './Item'; import { Npc } from './Npc'; import { Player } from './Player'; +export interface IDoor { + lockedBy?: EntityReference; + locked?: boolean; + closed?: boolean; +} + +export interface IExit { + id: string; + direction: string; + inferred?: boolean, + room: Room; +} + +export interface IRoomDef { + title: string; + description: string; + id: string; + defaultItems?: Items[]; + defaultNpcs?: Npcs[]; + script?: string; + behaviors?: Record; + coordinates?: [number, number, number]; + doors?: Record; +} + export declare class Room extends GameEntity { /** * @property Area room is in */ area: Area; - constructor(area: Area, def); + constructor(area: Area, def: IRoomDef); /** * Emits event on self and proxies certain events to other entities in the room. @@ -60,21 +85,21 @@ export declare class Room extends GameEntity { * * @return {Array<{ id: string, direction: string, inferred: boolean, room: Room= }>} */ - getExits(): Array<{ id: string, direction: string, inferred: boolean, room: Room }>; + getExits(): IExit[]; /** * Get the exit definition of a room's exit by searching the exit name * @param {string} exitName exit name search * @return {false|Object} */ - findExit(exitName: string): false|Object; + findExit(exitName: string): false | IExit; /** * Get the exit definition of a room's exit to a given room * @param {Room} nextRoom * @return {false|Object} */ - getExitToRoom(nextRoom: Room): false|Object; + getExitToRoom(nextRoom: Room): false | IExit; /** * Check to see if this room has a door preventing movement from `fromRoom` to here @@ -87,7 +112,7 @@ export declare class Room extends GameEntity { * @param {Room} fromRoom * @return {{lockedBy: EntityReference, locked: boolean, closed: boolean}} */ - getDoor(fromRoom: Room): Object; + getDoor(fromRoom: Room): IDoor; /** * Check to see of the door for `fromRoom` is locked @@ -137,5 +162,5 @@ export declare class Room extends GameEntity { * Used by Broadcaster * @return {Array} */ - getBroadcastTargets(): Array + getBroadcastTargets(): Character[] } \ No newline at end of file From f94a486c6b9bfdcc956ef3763faf425c08569ed4 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 15:21:58 -0400 Subject: [PATCH 051/117] Export interfaces --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 61ad744b8..542f48f84 100644 --- a/index.d.ts +++ b/index.d.ts @@ -47,7 +47,7 @@ export { Metadatable, MetadatableClass } from './types/Metadatable'; export { Npc } from './types/Npc'; export { Player } from './types/Player'; export { PlayerRoles } from './types/PlayerRoles'; -export { Room } from './types/Room'; +export { Room, IDoor, IExit } from './types/Room'; export { Scriptable, ScriptableClass } from './types/Scriptable'; export { CooldownError, From 65ab7c2abf512d9012e70e7b9ab47a237e75713b Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 15:40:29 -0400 Subject: [PATCH 052/117] Resolve conflicts --- index.d.ts | 20 ++++++++++++++++++++ types/CommandManager.d.ts | 22 ++++++++++++++++++++++ types/EventManager.d.ts | 4 ++-- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 types/CommandManager.d.ts diff --git a/index.d.ts b/index.d.ts index 542f48f84..f49e5cfcd 100644 --- a/index.d.ts +++ b/index.d.ts @@ -55,3 +55,23 @@ export { PassiveError, } from './types/SkillErrors'; export { SkillType } from './types/SkillType'; + + +// Placeholders for types yet to be defined. +export declare class DataSourceRegistry { [key: string]: any }; +export declare class EffectFactory { [key: string]: any }; +export declare class EntityLoaderRegistry { [key: string]: any }; +export declare class GameServer { [key: string]: any }; +export declare class HelpManager { [key: string]: any }; +export declare class ItemFactory { [key: string]: any }; +export declare class ItemManager { [key: string]: any }; +export declare class MobFactory { [key: string]: any }; +export declare class MobManager { [key: string]: any }; +export declare class PartyManager { [key: string]: any }; +export declare class PlayerManager { [key: string]: any }; +export declare class QuestFactory { [key: string]: any }; +export declare class QuestGoalManager { [key: string]: any }; +export declare class QuestRewardManager { [key: string]: any }; +export declare class RoomFactory { [key: string]: any }; +export declare class RoomManager { [key: string]: any }; +export declare class SkillManager { [key: string]: any }; diff --git a/types/CommandManager.d.ts b/types/CommandManager.d.ts new file mode 100644 index 000000000..437759d04 --- /dev/null +++ b/types/CommandManager.d.ts @@ -0,0 +1,22 @@ +import { Command } from './Command'; + +export declare class CommandManager { + commands: Map; + + /** + * Get command by name + */ + get(command: string): Command | null; + + /** + * Add the command and set up aliases + */ + add(command: Command): void; + + remove(command: Command): void; + + /** + * Find a command from a partial name + */ + find(search: string, returnAlias?: boolean): Commmand | { command: Command, alias: string } | null; +}; diff --git a/types/EventManager.d.ts b/types/EventManager.d.ts index e7ce14573..06ea0a6f2 100644 --- a/types/EventManager.d.ts +++ b/types/EventManager.d.ts @@ -12,14 +12,14 @@ export declare class EventManager { * @param {string} eventName * @param {Function} listener */ - add(eventName: string, listener: Function): void; + add(eventName: string, listener: function): void; /** * Attach all currently added events to the given emitter * @param {EventEmitter} emitter * @param {Object} config */ - attach(emitter: EventEmitter, config: Object); + attach(emitter: typeof EventEmitter, config?: Record): void; /** * Remove all listeners for a given emitter or only those for the given events From 8dc6195143f790c869a592cad099bcd6bad4c059 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 15:41:07 -0400 Subject: [PATCH 053/117] Remove unused import From 7c60baef03638aeadef41b5525efbdfb30f823cd Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 15:41:34 -0400 Subject: [PATCH 054/117] Define find using an overload --- types/CommandManager.d.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/types/CommandManager.d.ts b/types/CommandManager.d.ts index 437759d04..8c8ef31d0 100644 --- a/types/CommandManager.d.ts +++ b/types/CommandManager.d.ts @@ -18,5 +18,10 @@ export declare class CommandManager { /** * Find a command from a partial name */ - find(search: string, returnAlias?: boolean): Commmand | { command: Command, alias: string } | null; + find(search: string): Commmand | null; + + /** + * Find a command from a partial name + */ + find(search: string, returnAlias: boolean): Commmand | { command: Command, alias: string } | null; }; From 14c7c3d71904b7305d8b0c62b5529285ba59f184 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 15:53:37 -0400 Subject: [PATCH 055/117] Add PlayerManager definitions, better variable name in PlayerManager. --- index.d.ts | 4 +-- src/PlayerManager.js | 8 ++--- types/GameState.d.ts | 2 +- types/PlayerManager.d.ts | 76 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 types/PlayerManager.d.ts diff --git a/index.d.ts b/index.d.ts index f49e5cfcd..fa626feb3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -23,6 +23,7 @@ export { export { AudienceOptions, ChannelAudience } from './types/ChannelAudience'; export { ChannelManager } from './types/ChannelManager'; export { Character, CharacterConfig } from './types/Character'; +export { CommandManager } from './types/CommandManager'; export { CommandQueue } from './types/CommandQueue'; export { CommandType } from './types/CommandType'; export { Config } from './types/Config'; @@ -46,6 +47,7 @@ export { Logger } from './types/Logger'; export { Metadatable, MetadatableClass } from './types/Metadatable'; export { Npc } from './types/Npc'; export { Player } from './types/Player'; +export { PlayerManager } from './types/PlayerManager'; export { PlayerRoles } from './types/PlayerRoles'; export { Room, IDoor, IExit } from './types/Room'; export { Scriptable, ScriptableClass } from './types/Scriptable'; @@ -56,7 +58,6 @@ export { } from './types/SkillErrors'; export { SkillType } from './types/SkillType'; - // Placeholders for types yet to be defined. export declare class DataSourceRegistry { [key: string]: any }; export declare class EffectFactory { [key: string]: any }; @@ -68,7 +69,6 @@ export declare class ItemManager { [key: string]: any }; export declare class MobFactory { [key: string]: any }; export declare class MobManager { [key: string]: any }; export declare class PartyManager { [key: string]: any }; -export declare class PlayerManager { [key: string]: any }; export declare class QuestFactory { [key: string]: any }; export declare class QuestGoalManager { [key: string]: any }; export declare class QuestRewardManager { [key: string]: any }; diff --git a/src/PlayerManager.js b/src/PlayerManager.js index 21a99cdbf..9fc51d555 100644 --- a/src/PlayerManager.js +++ b/src/PlayerManager.js @@ -83,11 +83,11 @@ class PlayerManager extends EventEmitter { } /** - * @param {Function} fn Filter function - * @return {array} + * @param {Function} predicate Filter function + * @return {array}, */ - filter(fn) { - return this.getPlayersAsArray().filter(fn); + filter(predicate) { + return this.getPlayersAsArray().filter(predicate); } /** diff --git a/types/GameState.d.ts b/types/GameState.d.ts index c528240a5..eaa252f32 100644 --- a/types/GameState.d.ts +++ b/types/GameState.d.ts @@ -1,3 +1,3 @@ export declare class GameState { - + [key: string]: any; } \ No newline at end of file diff --git a/types/PlayerManager.d.ts b/types/PlayerManager.d.ts new file mode 100644 index 000000000..663409abc --- /dev/null +++ b/types/PlayerManager.d.ts @@ -0,0 +1,76 @@ +import EventEmitter from 'events'; + +import { Account } from './Account'; +import { EntityLoader } from './EntityLoader'; +import { EventManager } from './EventManager'; +import { GameState } from './GameState'; +import { Player } from './Player'; + +export declare class PlayerManager extends EventEmitter { + players: Map; + events: EventManager; + loader: EntityLoader | null; + + /** + * Set the entity loader from which players are loaded + * @param {EntityLoader} + */ + setLoader(loader: EntityLoader): void; + + getPlayer(name: string): Player; + + addPlayer(player: Player): void; + + /** + * Remove the player from the game. WARNING: You must manually save the player first + * as this will modify serializable properties + */ + removePlayer(player: Player, killSocket?: boolean): void; + + getPlayersAsArray(): Player[]; + + addListener(event: string, listener: function): void; + + filter(fn: (current: Player, index: string | number, array: Player[]) => boolean): Player[]; + + /** + * Load a player for an account + * @param {GameState} state + * @param {Account} account + * @param {string} username + * @param {boolean} force true to force reload from storage + * @return {Player} + */ + loadPlayer(state: GameState, account: Account, username: string, force?: boolean): Promise; + + /** + * Turn player into a key used by this class's map + * @param {Player} player + * @return {string} + */ + keyify(player: Player): string; + + exists(name: string): boolean; + + /** + * Save a player + * @fires Player#save + */ + save(player: Player): Promise; + + /** + * Save all players + * @fires Player#save + */ + saveAll(): Promise; + + /** + * @fires Player#updateTick + */ + tickAll(): void; + + /** + * Used by Broadcaster + */ + getBroadcastTargets(): Player; +} \ No newline at end of file From 6a46fb4db83af1a48834bbf52e71d25dec0e30d9 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 15:58:54 -0400 Subject: [PATCH 056/117] Improve types for Account, add serialized type --- types/Account.d.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/types/Account.d.ts b/types/Account.d.ts index 7f445efc8..1aabdb7fe 100644 --- a/types/Account.d.ts +++ b/types/Account.d.ts @@ -2,23 +2,30 @@ export declare interface AccountConfig { /** @property {string} username */ username: string; /** @property {Array} characters List of character names in this account */ - characters: Array; + characters?: string[]; /** @property {string} password Hashed password */ password: string; /** @property {boolean} banned Whether this account is banned or not */ - banned: boolean; + banned?: boolean; /** @property {boolean} deleted Whether this account is deleted or not */ - deleted: boolean; + deleted?: boolean; // Arbitrary data bundles are free to shove whatever they want in // WARNING: values must be JSON.stringify-able - metadata: object; + metadata?: Record; +} + +export declare interface SerializedAccount { + username: string; + characters: string[]; + password: string; + metadata: Record; } export declare class Account { /** @property {string} username */ username: string; /** @property {Array} characters List of character names in this account */ - characters: Array; + characters: string[]; /** @property {string} password Hashed password */ password: string; /** @property {boolean} banned Whether this account is banned or not */ @@ -69,7 +76,7 @@ export declare class Account { /** * @param {function} callback after-save callback */ - save(callback: Function): void; + save(callback: function): void; /** * Set this account to banned @@ -88,5 +95,5 @@ export declare class Account { * * @return {Object} */ - serialize(): Object; + serialize(): SerializedAccount; } From d5f751330d93d9df0af20d925f50aa5212eddfc8 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 16:18:41 -0400 Subject: [PATCH 057/117] Improve DataSource and EntityLoader defs --- types/DataSource.d.ts | 12 +++++++----- types/EntityLoader.d.ts | 13 ++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/types/DataSource.d.ts b/types/DataSource.d.ts index 37dc38164..ce0361c70 100644 --- a/types/DataSource.d.ts +++ b/types/DataSource.d.ts @@ -1,11 +1,13 @@ +import { EntityLoaderConfig } from './EntityLoader'; + export declare interface DataSource { - hasData(config: object): Promise; + hasData(config: EntityLoaderConfig): Promise; - fetchAll(config: object): Promise; + fetchAll(config: EntityLoaderConfig): Promise; - fetch(config: object, id: string|number): any; + fetch(config: EntityLoaderConfig, id: string|number): any; - replace(config: object, data: any): void; + replace(config: EntityLoaderConfig, data: any): void; - update(config: object, id: string|number, data: any): void; + update(config: EntityLoaderConfig, id: string|number, data: any): void; } \ No newline at end of file diff --git a/types/EntityLoader.d.ts b/types/EntityLoader.d.ts index 3e843ad68..645305bbe 100644 --- a/types/EntityLoader.d.ts +++ b/types/EntityLoader.d.ts @@ -1,11 +1,22 @@ import { DataSource } from './DataSource'; +export declare interface EntityLoaderConfig { + area?: string; + bundle?: string; +} + +/** + * Used to CRUD an entity from a configured DataSource + */ export declare class EntityLoader { + dataSource: DataSource; + config: EntityLoaderConfig; + /** * @param {DataSource} dataSource A class that implements DataSource interface * @param {object} config */ - constructor(dataSource: DataSource, config: Object); + constructor(dataSource: DataSource, config: EntityLoaderConfig); setArea(name: string): void; From 682886acb1427a709442d3060e116e90c6200b9a Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 16:31:12 -0400 Subject: [PATCH 058/117] Add Command definition, and fix definition for Room interfaces --- types/Command.d.ts | 26 ++++++++++++++++++++++++++ types/Room.d.ts | 3 +-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/types/Command.d.ts b/types/Command.d.ts index 9920ad97c..976e9a1e5 100644 --- a/types/Command.d.ts +++ b/types/Command.d.ts @@ -1,3 +1,29 @@ +import { CommandType } from './CommandType'; +import { Player } from './Player'; +import { PlayerRoles } from './PlayerRoles'; + +export interface CommandDef { + name: string; + func: function; + type?: CommandType; + aliases?: string[]; + usage?: string; + requiredRole?: PlayerRoles; + metadata?: Record; +} + export declare class Command { + bundle: string; + type: CommandType; + name: string; + func: function; + aliases?: string[]; + usage: string; + requiredRole: PlayerRoles; + file: string; + metadata: Record; + + constructor(bundle: string, name: string, def: CommandDef, file: string); + execute(args: string, player: Player, arg0: string): any; } \ No newline at end of file diff --git a/types/Room.d.ts b/types/Room.d.ts index a0d32b339..6cda6e919 100644 --- a/types/Room.d.ts +++ b/types/Room.d.ts @@ -14,10 +14,9 @@ export interface IDoor { } export interface IExit { - id: string; + roomId: string; direction: string; inferred?: boolean, - room: Room; } export interface IRoomDef { From 787e21b1673bf9ace4a825ee5e9c588bd5b6e417 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 16:33:58 -0400 Subject: [PATCH 059/117] Arg0 for commands is in fact optional --- types/Command.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/Command.d.ts b/types/Command.d.ts index 976e9a1e5..336cd8828 100644 --- a/types/Command.d.ts +++ b/types/Command.d.ts @@ -25,5 +25,5 @@ export declare class Command { constructor(bundle: string, name: string, def: CommandDef, file: string); - execute(args: string, player: Player, arg0: string): any; + execute(args: string, player: Player, arg0?: string): any; } \ No newline at end of file From 58e2a083b3af8f8c07233cc031192bf5de57aaf1 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 16:43:28 -0400 Subject: [PATCH 060/117] Remove I prefix for consistency --- index.d.ts | 2 +- types/Room.d.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index fa626feb3..3d123abbb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -49,7 +49,7 @@ export { Npc } from './types/Npc'; export { Player } from './types/Player'; export { PlayerManager } from './types/PlayerManager'; export { PlayerRoles } from './types/PlayerRoles'; -export { Room, IDoor, IExit } from './types/Room'; +export { Room, Door, Exit } from './types/Room'; export { Scriptable, ScriptableClass } from './types/Scriptable'; export { CooldownError, diff --git a/types/Room.d.ts b/types/Room.d.ts index 6cda6e919..273614091 100644 --- a/types/Room.d.ts +++ b/types/Room.d.ts @@ -7,19 +7,19 @@ import { Item } from './Item'; import { Npc } from './Npc'; import { Player } from './Player'; -export interface IDoor { +export interface Door { lockedBy?: EntityReference; locked?: boolean; closed?: boolean; } -export interface IExit { +export interface Exit { roomId: string; direction: string; inferred?: boolean, } -export interface IRoomDef { +export interface RoomDef { title: string; description: string; id: string; From 520ebd1d029a92c759950c5cc23c57cdd5ce79a1 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 17:11:21 -0400 Subject: [PATCH 061/117] Typing for Heal, Inventory, improve on others --- types/EntityLoader.d.ts | 2 +- types/Heal.d.ts | 10 +++++++++- types/Inventory.d.ts | 33 +++++++++++++++++++++++++++++++-- types/Item.d.ts | 4 ++++ 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/types/EntityLoader.d.ts b/types/EntityLoader.d.ts index 645305bbe..c27b7cd23 100644 --- a/types/EntityLoader.d.ts +++ b/types/EntityLoader.d.ts @@ -26,7 +26,7 @@ export declare class EntityLoader { fetchAll(): Promise; - fetch(id: string|number); + fetch(id: string|number): any; replace(data: any): void; diff --git a/types/Heal.d.ts b/types/Heal.d.ts index c842851d6..10d72bd3a 100644 --- a/types/Heal.d.ts +++ b/types/Heal.d.ts @@ -1,2 +1,10 @@ -export declare class Heal { +import { Damage } from './Damage'; +export declare class Heal extends Damage { + /** + * Raise a given attribute + * @param {Character} target + * @fires Character#heal + * @fires Character#healed + */ + commit(target: Character): void; } \ No newline at end of file diff --git a/types/Inventory.d.ts b/types/Inventory.d.ts index ba020b8c0..677be47f7 100644 --- a/types/Inventory.d.ts +++ b/types/Inventory.d.ts @@ -1,3 +1,32 @@ -export declare class InventoryFullError extends Error {} +import { Item, ItemDef } from './Item'; -export declare class Inventory extends Map {} +export declare class InventoryFullError extends Error { } + +export declare interface InventoryDef { + items?: [string, ItemDef | Item][]; + max?: number; +} + +export declare interface SerializedInventory { + items?: [string, ItemDef][]; + max?: number; +} + + +export declare class Inventory extends Map { + maxSize: number; + readonly isFull: boolean; + + constructor(init: InventoryDef); + + setMax(size: number): void; + + getMax(): number; + + // Can throw InventoryFullError; + addItem(item: Item): void | never; + + removeItem(item: Item): void; + + serialize(): SerializedInventory; +} diff --git a/types/Item.d.ts b/types/Item.d.ts index fbdab52eb..fdf804114 100644 --- a/types/Item.d.ts +++ b/types/Item.d.ts @@ -1,5 +1,9 @@ import { GameEntity } from './GameEntity'; +export declare interface ItemDef { + +} + export declare class Item extends GameEntity { } \ No newline at end of file From 799e6b472375444bc40df20848fa0a92b08a298f Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 25 Sep 2020 17:35:59 -0400 Subject: [PATCH 062/117] Define Item and ItemType --- src/Item.js | 3 +- types/Item.d.ts | 82 +++++++++++++++++++++++++++++++++++++++++++-- types/ItemType.d.ts | 8 +++++ 3 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 types/ItemType.d.ts diff --git a/src/Item.js b/src/Item.js index 9dcaec246..283a656bb 100644 --- a/src/Item.js +++ b/src/Item.js @@ -5,8 +5,7 @@ const uuid = require('uuid/v4'); const GameEntity = require('./GameEntity'); const ItemType = require('./ItemType'); const Logger = require('./Logger'); -const Metadatable = require('./Metadatable'); -const Player = require('./Player'); + const { Inventory, InventoryFullError } = require('./Inventory'); /** diff --git a/types/Item.d.ts b/types/Item.d.ts index fdf804114..5e60abb45 100644 --- a/types/Item.d.ts +++ b/types/Item.d.ts @@ -1,9 +1,87 @@ +import { Area } from './Area'; + import { GameEntity } from './GameEntity'; +import { GameState } from './GameState'; +import { SerializedInventory } from './Inventory'; +import { ItemType } from './ItemType'; export declare interface ItemDef { - + name: string; + id: string; + + description?: string; + inventory?: any; + metadata?: Record; + behaviors?: Record; + items?: ItemDef[]; + maxItems?: number; + isEquipped?: boolean; + entityReference: string; + room?: string | Room | null; + roomDesc?: string; + script?: string; + type?: ItemType | string; + uuid?: string; + closeable?: boolean; + closed?: boolean; + locked?: boolean; + lockedBy?: string | null; + + keywords: string[]; } export declare class Item extends GameEntity { + name: string; + id: string; + + description: string; + metadata: Record; + behaviors: Map; + defaultItems: Item[] | ItemDef[]; + entityReference: string; + maxItems: number; + isEquipped: boolean; + room: string | Room | null; + roomDesc: string; + script: string | null; + type: ItemType | string; + uuid: string; + closeable: boolean; + closed: boolean; + locked: boolean; + lockedBy: string | null; + + carriedBy: string | null; + equippedBy: string | null; + + keywords: string[]; + + + constructor(area: Area, item: ItemDef); + + initializeInventory(inventory: SerializedInventory): void; + + hasKeyword(keyword: string): boolean; -} \ No newline at end of file + addItem(item: Item): void; + + removeItem(item: Item): void; + + isInventoryFull(): boolean; + + _setupInventory(): void; + + findCarrier(): Character | Item | null; + + open(): void; + + close(): void; + + lock(): void; + + unlock(): void; + + hydrate(state: GameState, serialized?: ItemDef): void; + + serialize(): ItemDef; +} diff --git a/types/ItemType.d.ts b/types/ItemType.d.ts new file mode 100644 index 000000000..fd2273c06 --- /dev/null +++ b/types/ItemType.d.ts @@ -0,0 +1,8 @@ +export declare enum ItemType { + OBJECT = 1, + CONTAINER = 2, + ARMOR = 3, + WEAPON = 4, + POTION = 5, + RESOURCE = 6 +}; From eefe463b8382f561bd5c913c3294d6fa81a03897 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Sat, 26 Sep 2020 01:51:33 -0400 Subject: [PATCH 063/117] Consistently add new line at EOF --- types/Command.d.ts | 2 +- types/DataSource.d.ts | 2 +- types/EntityReference.d.ts | 2 +- types/Heal.d.ts | 2 +- types/PlayerManager.d.ts | 2 +- types/Room.d.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/types/Command.d.ts b/types/Command.d.ts index 336cd8828..0f1b20987 100644 --- a/types/Command.d.ts +++ b/types/Command.d.ts @@ -26,4 +26,4 @@ export declare class Command { constructor(bundle: string, name: string, def: CommandDef, file: string); execute(args: string, player: Player, arg0?: string): any; -} \ No newline at end of file +} diff --git a/types/DataSource.d.ts b/types/DataSource.d.ts index ce0361c70..f2ef30950 100644 --- a/types/DataSource.d.ts +++ b/types/DataSource.d.ts @@ -10,4 +10,4 @@ export declare interface DataSource { replace(config: EntityLoaderConfig, data: any): void; update(config: EntityLoaderConfig, id: string|number, data: any): void; -} \ No newline at end of file +} diff --git a/types/EntityReference.d.ts b/types/EntityReference.d.ts index 3f3598559..3a5ab9685 100644 --- a/types/EntityReference.d.ts +++ b/types/EntityReference.d.ts @@ -1 +1 @@ -export declare type EntityReference = string; \ No newline at end of file +export declare type EntityReference = string; diff --git a/types/Heal.d.ts b/types/Heal.d.ts index 10d72bd3a..92817f4da 100644 --- a/types/Heal.d.ts +++ b/types/Heal.d.ts @@ -7,4 +7,4 @@ export declare class Heal extends Damage { * @fires Character#healed */ commit(target: Character): void; -} \ No newline at end of file +} diff --git a/types/PlayerManager.d.ts b/types/PlayerManager.d.ts index 663409abc..2dc5feea7 100644 --- a/types/PlayerManager.d.ts +++ b/types/PlayerManager.d.ts @@ -73,4 +73,4 @@ export declare class PlayerManager extends EventEmitter { * Used by Broadcaster */ getBroadcastTargets(): Player; -} \ No newline at end of file +} diff --git a/types/Room.d.ts b/types/Room.d.ts index 273614091..a0da38acb 100644 --- a/types/Room.d.ts +++ b/types/Room.d.ts @@ -162,4 +162,4 @@ export declare class Room extends GameEntity { * @return {Array} */ getBroadcastTargets(): Character[] -} \ No newline at end of file +} From 9b2f41ce73c19752881ff01ce37cae9dfda3176b Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Sat, 26 Sep 2020 03:29:29 -0400 Subject: [PATCH 064/117] TSC caught some issues finally --- types/Room.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/types/Room.d.ts b/types/Room.d.ts index a0da38acb..fca85219d 100644 --- a/types/Room.d.ts +++ b/types/Room.d.ts @@ -23,12 +23,12 @@ export interface RoomDef { title: string; description: string; id: string; - defaultItems?: Items[]; - defaultNpcs?: Npcs[]; + defaultItems?: Item[]; + defaultNpcs?: Npc[]; script?: string; behaviors?: Record; coordinates?: [number, number, number]; - doors?: Record; + doors?: Record; } export declare class Room extends GameEntity { @@ -37,7 +37,7 @@ export declare class Room extends GameEntity { */ area: Area; - constructor(area: Area, def: IRoomDef); + constructor(area: Area, def: RoomDef); /** * Emits event on self and proxies certain events to other entities in the room. @@ -84,21 +84,21 @@ export declare class Room extends GameEntity { * * @return {Array<{ id: string, direction: string, inferred: boolean, room: Room= }>} */ - getExits(): IExit[]; + getExits(): Exit[]; /** * Get the exit definition of a room's exit by searching the exit name * @param {string} exitName exit name search * @return {false|Object} */ - findExit(exitName: string): false | IExit; + findExit(exitName: string): false | Exit; /** * Get the exit definition of a room's exit to a given room * @param {Room} nextRoom * @return {false|Object} */ - getExitToRoom(nextRoom: Room): false | IExit; + getExitToRoom(nextRoom: Room): false | Exit; /** * Check to see if this room has a door preventing movement from `fromRoom` to here @@ -111,7 +111,7 @@ export declare class Room extends GameEntity { * @param {Room} fromRoom * @return {{lockedBy: EntityReference, locked: boolean, closed: boolean}} */ - getDoor(fromRoom: Room): IDoor; + getDoor(fromRoom: Room): Door; /** * Check to see of the door for `fromRoom` is locked From daf069ce9d42d6d57b76dd01837dd56d0f2a3791 Mon Sep 17 00:00:00 2001 From: Brian Nelson Date: Fri, 9 Oct 2020 20:50:50 -0700 Subject: [PATCH 065/117] Add optional parameter to Account.save() --- types/Account.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/Account.d.ts b/types/Account.d.ts index 1aabdb7fe..7dcf6fd2c 100644 --- a/types/Account.d.ts +++ b/types/Account.d.ts @@ -74,9 +74,9 @@ export declare class Account { checkPassword(pass: string): boolean; /** - * @param {function} callback after-save callback + * @param {?function} callback after-save callback */ - save(callback: function): void; + save(callback?: () => void): void; /** * Set this account to banned From 57647cd4a7a51ba3df5835ca87dc6f9d8524bdf7 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Sat, 10 Oct 2020 00:07:44 -0400 Subject: [PATCH 066/117] Add members to Damage --- types/Damage.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/types/Damage.d.ts b/types/Damage.d.ts index 166449611..4df621868 100644 --- a/types/Damage.d.ts +++ b/types/Damage.d.ts @@ -1,6 +1,14 @@ +import { Attribute } from "./Attribute"; + import { Character } from "./Character"; export declare class Damage { + attribute: Attribute; + amount: number; + attacker?: Character; + source?: any; + metadata?: object; + /** * @param {string} attribute Attribute the damage is going to apply to * @param {number} amount From e1c06edf6ca3c44f578f01537b3338f4f003fc56 Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Sat, 10 Oct 2020 01:15:26 -0400 Subject: [PATCH 067/117] Formatting --- types/Damage.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/Damage.d.ts b/types/Damage.d.ts index 4df621868..605996b9e 100644 --- a/types/Damage.d.ts +++ b/types/Damage.d.ts @@ -1,5 +1,4 @@ import { Attribute } from "./Attribute"; - import { Character } from "./Character"; export declare class Damage { From 0489bb3e559a2d19ac40d9e26c087ea7a9b9ffec Mon Sep 17 00:00:00 2001 From: Sean O'Donohue Date: Fri, 9 Oct 2020 23:50:20 -0400 Subject: [PATCH 068/117] Fix Damage constructor types --- types/Damage.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/Damage.d.ts b/types/Damage.d.ts index 605996b9e..33d53eec5 100644 --- a/types/Damage.d.ts +++ b/types/Damage.d.ts @@ -15,7 +15,7 @@ export declare class Damage { * @param {*} [source=null] Where the damage came from: skill, item, room, etc. * @property {Object} metadata Extra info about the damage: type, hidden, critical, etc. */ - constructor(attribute: string, amount: number, attacker: Character, source: any, metadata: object); + constructor(attribute: string, amount: number, attacker?: Character, source?: any, metadata?: object); /** * Evaluate actual damage taking attacker/target's effects into account From f5fd2c471e3abfa3ed0c87c8aea5387d5fa14689 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 00:20:56 +0100 Subject: [PATCH 069/117] Minor fix for return type of AreaAudience and AccountManager classes --- types/AccountManager.d.ts | 2 +- types/AreaAudience.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/AccountManager.d.ts b/types/AccountManager.d.ts index 8b4cd90ae..d719ea484 100644 --- a/types/AccountManager.d.ts +++ b/types/AccountManager.d.ts @@ -30,5 +30,5 @@ export declare class AccountManager { * @param {string} username * @param {boolean} force Force reload data from disk */ - async loadAccount(username: string, force: boolean): void; + loadAccount(username: string, force: boolean): Promise; } \ No newline at end of file diff --git a/types/AreaAudience.d.ts b/types/AreaAudience.d.ts index f9e5a6c5f..3454b7237 100644 --- a/types/AreaAudience.d.ts +++ b/types/AreaAudience.d.ts @@ -7,5 +7,5 @@ import { ChannelAudience } from './ChannelAudience'; * @extends ChannelAudience */ export declare class AreaAudience extends ChannelAudience { - getBroadcastTargets(): Array; + getBroadcastTargets(): Array; } \ No newline at end of file From 8510ab705655e8bd7ea8c2a4efb2b59e05dede8d Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 01:32:37 +0100 Subject: [PATCH 070/117] Update Command definition --- types/Command.d.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/types/Command.d.ts b/types/Command.d.ts index 0f1b20987..75fa1dca6 100644 --- a/types/Command.d.ts +++ b/types/Command.d.ts @@ -4,7 +4,7 @@ import { PlayerRoles } from './PlayerRoles'; export interface CommandDef { name: string; - func: function; + func: Function; type?: CommandType; aliases?: string[]; usage?: string; @@ -13,14 +13,23 @@ export interface CommandDef { } export declare class Command { + /** @property {string} bundle Bundle this command came from */ bundle: string; + /** @property {CommandType} type */ type: CommandType; + /** @property {string} name */ name: string; - func: function; + /** @property {Function} func Actual function that gets run when the command is executed */ + func: Function; + /** @property {string[]} aliases */ aliases?: string[]; + /** @property {string} usage */ usage: string; + /** @property {PlayerRoles} requiredRole */ requiredRole: PlayerRoles; + /** @property {string} file File the command comes from */ file: string; + /** @property {Record} metadata General use configuration object */ metadata: Record; constructor(bundle: string, name: string, def: CommandDef, file: string); From c09d4b6c2d137f429b1dbef1711a41617f905906 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 01:42:48 +0100 Subject: [PATCH 071/117] Add definition for DataSourceRegistry --- types/DataSourceRegistry.d.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 types/DataSourceRegistry.d.ts diff --git a/types/DataSourceRegistry.d.ts b/types/DataSourceRegistry.d.ts new file mode 100644 index 000000000..77a1571e0 --- /dev/null +++ b/types/DataSourceRegistry.d.ts @@ -0,0 +1,14 @@ +import { DataSource } from './DataSource'; + +/** + * Holds instances of configured DataSources + * @type {Map} + */ +export declare class DataSourceRegistry extends Map { + /** + * @param {Function} requireFn used to require() the loader + * @param {string} rootPath project root + * @param {object} config configuration to load + */ + load(requireFn: Function, rootPath: string, config: object = {}): void; +} From 828ae318ecc97234893ad8bb50a36d78002f1626 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 01:56:46 +0100 Subject: [PATCH 072/117] Add definition for EffectableEntity --- types/EffectableEntity.d.ts | 131 ++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/types/EffectableEntity.d.ts b/types/EffectableEntity.d.ts index 3066835c8..2f94ebb87 100644 --- a/types/EffectableEntity.d.ts +++ b/types/EffectableEntity.d.ts @@ -1,5 +1,136 @@ import { EventEmitter } from 'events'; +import { Damage } from './Damage'; +import { Effect } from './Effect'; +import { GameState } from './GameState'; export declare class EffectableEntity extends EventEmitter { + constructor(data): EffectableEntity; + /** + * Proxy all events on the entity to effects + * @param {string} event + * @param {...*} args + */ + emit(event: string, ...args: any[]): void; + + /** + * @param {string} attr Attribute name + * @return {boolean} + */ + hasAttribute(attr: string): boolean; + + /** + * Get current maximum value of attribute (as modified by effects.) + * @param {string} attr + * @return {number} + */ + getMaxAttribute(attr: string): number; + + /** + * @see {@link Attributes#add} + */ + addAttribute(attribute): void; + + /** + * Get the current value of an attribute (base modified by delta) + * @param {string} attr + * @return {number} + */ + getAttribute(attr: string): number; + + /** + * Get the effected value of a given property + * @param {string} propertyName + * @return {*} + */ + getProperty(propertyName: string): any; + + /** + * Get the base value for a given attribute + * @param {string} attrName Attribute name + * @return {number} + */ + getBaseAttribute(attrName: string): number; + + /** + * Clears any changes to the attribute, setting it to its base value. + * @param {string} attr + * @fires EffectableEntity#attributeUpdate + */ + setAttributeToMax(attr: string): void; + + /** + * Raise an attribute by name + * @param {string} attr + * @param {number} amount + * @see {@link Attributes#raise} + * @fires EffectableEntity#attributeUpdate + */ + raiseAttribute(attr: string, amount: number): void; + + /** + * Lower an attribute by name + * @param {string} attr + * @param {number} amount + * @see {@link Attributes#lower} + * @fires EffectableEntity#attributeUpdate + */ + lowerAttribute(attr: string, amount: number): void; + + /** + * Update an attribute's base value. + * + * NOTE: You _probably_ don't want to use this the way you think you do. You should not use this + * for any temporary modifications to an attribute, instead you should use an Effect modifier. + * + * This will _permanently_ update the base value for an attribute to be used for things like a + * player purchasing a permanent upgrade or increasing a stat on level up + * + * @param {string} attr Attribute name + * @param {number} newBase New base value + * @fires EffectableEntity#attributeUpdate + */ + setAttributeBase(attr: string, newBase: number): void; + + /** + * @param {string} type + * @return {boolean} + * @see {@link Effect} + */ + hasEffectType(type: string): boolean; + + /** + * @param {Effect} effect + * @see {@link Effect#remove} + */ + removeEffect(effect: Effect): void; + + /** + * @see EffectList.evaluateIncomingDamage + * @param {Damage} damage + * @param {number} currentAmount + * @return {number} + */ + evaluateIncomingDamage(damage: Damage, currentAmount: number): number; + + /** + * @see EffectList.evaluateOutgoingDamage + * @param {Damage} damage + * @param {number} currentAmount + * @return {number} + */ + evaluateOutgoingDamage(damage: Damage, currentAmount: number): number; + + /** + * Initialize the entity from storage + * @param {GameState} state + * @param {object} serialized + */ + hydrate(state: GameState, serialized: object = {}): void; + + /** + * Gather data to be persisted + * @return {EffectableEntity} + */ + serialize(): EffectableEntity; } \ No newline at end of file From d04832f5c5660cab4e6b96a924e2d7c998328b54 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 02:24:05 +0100 Subject: [PATCH 073/117] Fix DataSourceRegistry definition --- types/DataSourceRegistry.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/DataSourceRegistry.d.ts b/types/DataSourceRegistry.d.ts index 77a1571e0..a6397712d 100644 --- a/types/DataSourceRegistry.d.ts +++ b/types/DataSourceRegistry.d.ts @@ -10,5 +10,5 @@ export declare class DataSourceRegistry extends Map { * @param {string} rootPath project root * @param {object} config configuration to load */ - load(requireFn: Function, rootPath: string, config: object = {}): void; + load(requireFn: Function, rootPath: string, config: object): void; } From b7fa58667b9450302ac0b5c40c7e8e09da8d8352 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 02:24:18 +0100 Subject: [PATCH 074/117] Add initial test for account --- test/unit/Account.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/unit/Account.js diff --git a/test/unit/Account.js b/test/unit/Account.js new file mode 100644 index 000000000..5e64844d9 --- /dev/null +++ b/test/unit/Account.js @@ -0,0 +1,35 @@ +const assert = require('assert'); +const Account = require('../../src/Account'); + +describe('Account', function () { + /** @param {AccountDef} account */ + let account = null; + /** @param {AccountConfig} mockedAccountData */ + const mockedAccountData = { + username: 'testusername', + characters: ['testchar'], + password: 'testpass', + banned: false, + } + + const originalDateNow = Date.now; + + beforeEach(function (done) { + account = new Account(mockedAccountData); + done(); + }); + + afterEach(function (done) { + Date.now = originalDateNow; + done(); + }); + + describe('#init', function () { + it('should be an instance of account', function (done) { + assert.equal('Account', account.constructor.name); + done(); + }); + }); + + +}); From 221c1a972f8a26f1af4a7ae846f8ccc72ea3b45e Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 03:08:07 +0100 Subject: [PATCH 075/117] Update tests for Account --- test/unit/Account.js | 146 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 124 insertions(+), 22 deletions(-) diff --git a/test/unit/Account.js b/test/unit/Account.js index 5e64844d9..18e11726b 100644 --- a/test/unit/Account.js +++ b/test/unit/Account.js @@ -1,35 +1,137 @@ const assert = require('assert'); const Account = require('../../src/Account'); -describe('Account', function () { - /** @param {AccountDef} account */ - let account = null; - /** @param {AccountConfig} mockedAccountData */ - const mockedAccountData = { - username: 'testusername', - characters: ['testchar'], - password: 'testpass', - banned: false, - } +describe('Account', function () { + /** @param {AccountDef} account */ + let account = null; + /** @param {AccountConfig} mockedAccountData */ + const mockedAccountData = { + username: 'testusername', + characters: [], + password: null + }; + const testChar = { + deleted: false, + username: 'testchar', + }; + const testPass = 'testpass'; - const originalDateNow = Date.now; + const originalDateNow = Date.now; - beforeEach(function (done) { - account = new Account(mockedAccountData); - done(); + beforeEach(function (done) { + account = new Account(mockedAccountData); + done(); + }); + + afterEach(function (done) { + Date.now = originalDateNow; + done(); + }); + + describe('#base methods', function () { + it('should be an instance of account', function (done) { + assert.equal('Account', account.constructor.name); + done(); + }); + }); + + describe('#properties', function () { + it('should get username', function (done) { + assert.equal(mockedAccountData.username, account.getUsername()); + done(); + }); + + it('should set a password', function (done) { + /** + * setPassword function also try to save file on disk, + * but it don't find it and raise an exception + */ + assert.throws(() => account.setPassword(testPass)); + done(); + }); + + it('should check a password', function (done) { + assert.throws(() => account.setPassword(testPass)); + assert.equal(true, account.checkPassword(testPass)); + done(); }); - afterEach(function (done) { - Date.now = originalDateNow; - done(); + it('should save data', function (done) { + /** + * save function also try to save file on disk, + * but it don't find it and raise an exception + */ + assert.throws(() => account.save(() => {})); + done(); }); - describe('#init', function () { - it('should be an instance of account', function (done) { - assert.equal('Account', account.constructor.name); - done(); - }); + it('should mark account as banned', function (done) { + /** + * ban function also try to save file on disk, + * but it don't find it and raise an exception + */ + assert.throws(() => account.ban(() => {})); + assert.equal(true, account.banned); + done(); }); + it('should delete accont and its characters', function (done) { + /** + * save function also try to save file on disk, + * but it don't find it and raise an exception + */ + assert.throws(() => account.deleteAccount(() => {})); + assert.equal(true, account.deleted); + assert.deepEqual([], account.characters); + done(); + }); + + it('should serialize and return accont data', function (done) { + assert.deepEqual( + { ...mockedAccountData, metadata: {} }, + account.serialize() + ); + done(); + }); + }); + + describe('#characters', function () { + it('should add a character to account', function (done) { + assert.equal(undefined, account.hasCharacter(testChar.username)); + account.addCharacter(testChar.username); + assert.deepEqual(testChar, account.hasCharacter(testChar.username)); + done(); + }); + + it('should delete a character from account', function (done) { + assert.deepEqual(testChar, account.hasCharacter(testChar.username)); + /** + * deleteCaracter function also try to save file on disk, + * but it don't find it and raise an exception + */ + assert.throws(() => account.deleteCharacter(testChar.username)); + assert.deepEqual( + { ...testChar, deleted: true }, + account.hasCharacter(testChar.username) + ); + done(); + }); + it('should undelete a character from account', function (done) { + assert.deepEqual( + { ...testChar, deleted: true }, + account.hasCharacter(testChar.username) + ); + /** + * undeleteCaracter function also try to save file on disk, + * but it don't find it and raise an exception + */ + assert.throws(() => account.undeleteCharacter(testChar.username)); + assert.deepEqual( + { ...testChar, deleted: false }, + account.hasCharacter(testChar.username) + ); + done(); + }); + }); }); From 226f8b90b65cd3c8f314c7a6ac1c495e7ed7ba83 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 03:08:30 +0100 Subject: [PATCH 076/117] Minor fix --- test/unit/Account.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/Account.js b/test/unit/Account.js index 18e11726b..cd096064a 100644 --- a/test/unit/Account.js +++ b/test/unit/Account.js @@ -8,7 +8,7 @@ describe('Account', function () { const mockedAccountData = { username: 'testusername', characters: [], - password: null + password: null, }; const testChar = { deleted: false, From c521b78e912f60c4eca11b6c7990553bed205deb Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 23:00:41 +0100 Subject: [PATCH 077/117] Add definitions for EffectConfig (type used by effect factory) and EffectFactory --- index.d.ts | 2 ++ types/EffectFactory.d.ts | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 types/EffectFactory.d.ts diff --git a/index.d.ts b/index.d.ts index 3d123abbb..c634ed436 100644 --- a/index.d.ts +++ b/index.d.ts @@ -30,9 +30,11 @@ export { Config } from './types/Config'; export { Command } from './types/Command'; export { Damage } from './types/Damage'; export { Data } from './types/Data'; +export { DataSourceRegistry } from './types/DataSourceRegistry'; export { DataSource } from './types/DataSource'; export { Effect, EffectConfig, EffectModifiers } from './types/Effect'; export { EffectableEntity } from './types/EffectableEntity'; +export { EffectConfig as EffectFactoryType, EffectFactory } from './types/EffectFactory'; export { EffectList } from './types/EffectList'; export { EntityFactory } from './types/EntityFactory'; export { EntityLoader } from './types/EntityLoader'; diff --git a/types/EffectFactory.d.ts b/types/EffectFactory.d.ts new file mode 100644 index 000000000..75bad4154 --- /dev/null +++ b/types/EffectFactory.d.ts @@ -0,0 +1,38 @@ +import { Effect } from "./Effect"; +import { GameState } from "./GameState"; + +export declare type EffectConfig = { + config: Object; + listeners: Object; +} + +export declare class EffectFactory { + constructor(): EffectFactory; + + /** + * @param {string} id + * @param {EffectConfig} config + * @param {GameState} state + */ + add(id: string, config: EffectConfig, state: GameState): void; + + /** + * @param {string} id + */ + has(id: string): boolean; + + /** + * Get a effect definition. Use `create` if you want an instance of a effect + * @param {string} id + * @return {object} + */ + get(id: string): Effect; + + /** + * @param {string} id effect id + * @param {?object} config Effect.config override + * @param {?object} state Effect.state override + * @return {Effect} + */ + create(id: string, config?: EffectConfig, state: object): Effect +} From c2865019b02850162daddc4dc08e03e861ed346b Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 23:03:36 +0100 Subject: [PATCH 078/117] Add type definition for EffectFlag enum --- index.d.ts | 1 + types/EffectFlag.d.ts | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 types/EffectFlag.d.ts diff --git a/index.d.ts b/index.d.ts index c634ed436..caeff3dd8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -35,6 +35,7 @@ export { DataSource } from './types/DataSource'; export { Effect, EffectConfig, EffectModifiers } from './types/Effect'; export { EffectableEntity } from './types/EffectableEntity'; export { EffectConfig as EffectFactoryType, EffectFactory } from './types/EffectFactory'; +export { EffectFlag } from './types/EffectFlag'; export { EffectList } from './types/EffectList'; export { EntityFactory } from './types/EntityFactory'; export { EntityLoader } from './types/EntityLoader'; diff --git a/types/EffectFlag.d.ts b/types/EffectFlag.d.ts new file mode 100644 index 000000000..3b5faef2d --- /dev/null +++ b/types/EffectFlag.d.ts @@ -0,0 +1,4 @@ +export declare enum EffectFlag { + BUFF = 'BUFF', + DEBUFF = 'DEBUFF', +} \ No newline at end of file From 6781b753a1510a34275f4d7d5720652a544a84f2 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 23:13:00 +0100 Subject: [PATCH 079/117] Add definition for EffectList --- types/EffectList.d.ts | 105 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/types/EffectList.d.ts b/types/EffectList.d.ts index e993b3599..adb9e1449 100644 --- a/types/EffectList.d.ts +++ b/types/EffectList.d.ts @@ -1,3 +1,108 @@ +import { Attribute } from "./Attribute"; +import { Character } from "./Character"; +import { Damage } from "./Damage"; +import { Effect } from "./Effect"; +import { GameState } from "./GameState"; + export declare class EffectList { + effects: Set; + size: number; + target: Character; + + /** + * @param {Character} target + * @param {Array} effects array of serialized effects (Object) or actual Effect instances + */ + constructor(target: Character, effects: Array): EffectList; + + /** + * @type {number} + */ + get size(): number; + + /** + * Get current list of effects as an array + * @return {Array} + */ + entries(): Array; + + /** + * @param {string} type + * @return {boolean} + */ + hasEffectType(type: string): boolean; + + /** + * @param {string} type + * @return {Effect} + */ + getByType(type: string): Effect; + + /** + * Proxy an event to all effects + * @param {string} event + * @param {...*} args + */ + emit(event: string, ...args: Array): void; + + /** + * @param {Effect} effect + * @fires Effect#effectAdded + * @fires Effect#effectStackAdded + * @fires Effect#effectRefreshed + * @fires Character#effectAdded + */ + add(effect: Effect): void; + + /** + * Deactivate and remove an effect + * @param {Effect} effect + * @throws ReferenceError + * @fires Character#effectRemoved + */ + remove(effect: Effect): void; + + /** + * Remove all effects, bypassing all deactivate and remove events + */ + clear(): void; + + /** + * Ensure effects are still current and if not remove them + */ + validateEffects(): void; + + /** + * Gets the effective "max" value of an attribute (before subtracting delta). + * Does the work of actaully applying attribute modification + * @param {Atrribute} attr + * @return {number} + */ + evaluateAttribute(attr: Attribute): number; + + /** + * Gets the effective value of property doing all effect modifications. + * @param {string} propertyName + * @param {number} propertyValue + * @return {number} + */ + evaluateProperty(propertyName: string, propertyValue: number): number; + + /** + * @param {Damage} damage + * @param {number} currentAmount + * @return {number} + */ + evaluateIncomingDamage(damage: Damage, currentAmount: number): number; + + /** + * @param {Damage} damage + * @param {number} currentAmount + * @return {number} + */ + evaluateOutgoingDamage(damage: Damage, currentAmount: number): number; + + serialize(): Array; + hydrate(state: GameState): void; } \ No newline at end of file From a4ad0735661b9ef1f7677845185be633d2318f6e Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 23:21:33 +0100 Subject: [PATCH 080/117] Drop placeholders for already exported types --- index.d.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index caeff3dd8..e92b98992 100644 --- a/index.d.ts +++ b/index.d.ts @@ -62,8 +62,6 @@ export { export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. -export declare class DataSourceRegistry { [key: string]: any }; -export declare class EffectFactory { [key: string]: any }; export declare class EntityLoaderRegistry { [key: string]: any }; export declare class GameServer { [key: string]: any }; export declare class HelpManager { [key: string]: any }; From e7be9e94c1557966c662ef0282054d7b4a66c8b7 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 23:29:50 +0100 Subject: [PATCH 081/117] Add @types/node definition for TS as dev dependency --- package-lock.json | 17 ++++++++++++++--- package.json | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 52e6729ad..a749b75c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -136,6 +136,12 @@ "to-fast-properties": "^2.0.0" } }, + "@types/node": { + "version": "10.17.48", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.48.tgz", + "integrity": "sha512-Agl6xbYP6FOMDeAsr3QVZ+g7Yzg0uhPHWx0j5g4LFdUBHVtqtU+gH660k/lCEe506jJLOGbEzsnqPDTZGJQLag==", + "dev": true + }, "ajv": { "version": "6.6.2", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.6.2.tgz", @@ -878,6 +884,7 @@ "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", "integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=", "dev": true, + "optional": true, "requires": { "kind-of": "^3.0.2", "longest": "^1.0.1", @@ -1247,7 +1254,8 @@ "version": "1.1.6", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", - "dev": true + "dev": true, + "optional": true }, "is-builtin-module": { "version": "1.0.0", @@ -1343,6 +1351,7 @@ "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", "dev": true, + "optional": true, "requires": { "is-buffer": "^1.1.5" } @@ -1395,7 +1404,8 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=", - "dev": true + "dev": true, + "optional": true }, "lru-cache": { "version": "4.1.3", @@ -1698,7 +1708,8 @@ "version": "1.6.1", "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", - "dev": true + "dev": true, + "optional": true }, "require-directory": { "version": "2.1.1", diff --git a/package.json b/package.json index 5874f35b8..39a0803eb 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "devDependencies": { "coveralls": "^3.0.2", "mocha": "^5.2.0", - "nyc": "^13.1.0" + "nyc": "^13.1.0", + "@types/node": "^10.12" } } From b10e620480d90a84d425cff3e26c3c17c94d1656 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 23:43:30 +0100 Subject: [PATCH 082/117] Fix some definition issue using tsc compiler --- types/AreaAudience.d.ts | 2 +- types/EffectFactory.d.ts | 2 +- types/EffectList.d.ts | 3 +-- types/EffectableEntity.d.ts | 4 ++-- types/EventManager.d.ts | 2 +- types/Heal.d.ts | 1 + types/Item.d.ts | 11 ++++++----- types/ItemType.d.ts | 2 +- types/PlayerManager.d.ts | 4 ++-- 9 files changed, 16 insertions(+), 15 deletions(-) diff --git a/types/AreaAudience.d.ts b/types/AreaAudience.d.ts index 3454b7237..3b29a4e26 100644 --- a/types/AreaAudience.d.ts +++ b/types/AreaAudience.d.ts @@ -1,5 +1,5 @@ -import { Broadcastable } from './Broadcast'; import { ChannelAudience } from './ChannelAudience'; +import { Player } from './Player'; /** * Audience class representing characters in the same area as the sender diff --git a/types/EffectFactory.d.ts b/types/EffectFactory.d.ts index 75bad4154..7c7447c09 100644 --- a/types/EffectFactory.d.ts +++ b/types/EffectFactory.d.ts @@ -34,5 +34,5 @@ export declare class EffectFactory { * @param {?object} state Effect.state override * @return {Effect} */ - create(id: string, config?: EffectConfig, state: object): Effect + create(id: string, config?: EffectConfig, state?: object): Effect } diff --git a/types/EffectList.d.ts b/types/EffectList.d.ts index adb9e1449..412caa622 100644 --- a/types/EffectList.d.ts +++ b/types/EffectList.d.ts @@ -5,8 +5,7 @@ import { Effect } from "./Effect"; import { GameState } from "./GameState"; export declare class EffectList { - effects: Set; - size: number; + effects: Set; target: Character; /** diff --git a/types/EffectableEntity.d.ts b/types/EffectableEntity.d.ts index 2f94ebb87..5681cb1c6 100644 --- a/types/EffectableEntity.d.ts +++ b/types/EffectableEntity.d.ts @@ -4,7 +4,7 @@ import { Effect } from './Effect'; import { GameState } from './GameState'; export declare class EffectableEntity extends EventEmitter { - constructor(data): EffectableEntity; + constructor(data); /** * Proxy all events on the entity to effects @@ -126,7 +126,7 @@ export declare class EffectableEntity extends EventEmitter { * @param {GameState} state * @param {object} serialized */ - hydrate(state: GameState, serialized: object = {}): void; + hydrate(state: GameState, serialized: object): void; /** * Gather data to be persisted diff --git a/types/EventManager.d.ts b/types/EventManager.d.ts index e4b784e23..2fad7cbaf 100644 --- a/types/EventManager.d.ts +++ b/types/EventManager.d.ts @@ -14,7 +14,7 @@ export declare class EventManager { * @param {string} eventName * @param {Function} listener */ - add(eventName: string, listener: function): void; + add(eventName: string, listener: Function): void; /** * Attach all currently added events to the given emitter diff --git a/types/Heal.d.ts b/types/Heal.d.ts index 92817f4da..871f2313e 100644 --- a/types/Heal.d.ts +++ b/types/Heal.d.ts @@ -1,3 +1,4 @@ +import { Character } from './Character'; import { Damage } from './Damage'; export declare class Heal extends Damage { /** diff --git a/types/Item.d.ts b/types/Item.d.ts index 5e60abb45..53174f162 100644 --- a/types/Item.d.ts +++ b/types/Item.d.ts @@ -1,9 +1,10 @@ import { Area } from './Area'; - +import { Character } from './Character'; import { GameEntity } from './GameEntity'; import { GameState } from './GameState'; -import { SerializedInventory } from './Inventory'; import { ItemType } from './ItemType'; +import { Room } from './Room'; +import { SerializedInventory } from './Inventory'; export declare interface ItemDef { name: string; @@ -33,7 +34,7 @@ export declare interface ItemDef { export declare class Item extends GameEntity { name: string; id: string; - + description: string; metadata: Record; behaviors: Map; @@ -50,7 +51,7 @@ export declare class Item extends GameEntity { closed: boolean; locked: boolean; lockedBy: string | null; - + carriedBy: string | null; equippedBy: string | null; @@ -78,7 +79,7 @@ export declare class Item extends GameEntity { close(): void; lock(): void; - + unlock(): void; hydrate(state: GameState, serialized?: ItemDef): void; diff --git a/types/ItemType.d.ts b/types/ItemType.d.ts index fd2273c06..3425ca826 100644 --- a/types/ItemType.d.ts +++ b/types/ItemType.d.ts @@ -5,4 +5,4 @@ export declare enum ItemType { WEAPON = 4, POTION = 5, RESOURCE = 6 -}; +} diff --git a/types/PlayerManager.d.ts b/types/PlayerManager.d.ts index 2dc5feea7..a576c5ca9 100644 --- a/types/PlayerManager.d.ts +++ b/types/PlayerManager.d.ts @@ -1,4 +1,4 @@ -import EventEmitter from 'events'; +import { EventEmitter } from 'events'; import { Account } from './Account'; import { EntityLoader } from './EntityLoader'; @@ -29,7 +29,7 @@ export declare class PlayerManager extends EventEmitter { getPlayersAsArray(): Player[]; - addListener(event: string, listener: function): void; + addListener(event: string, listener: Function): void; filter(fn: (current: Player, index: string | number, array: Player[]) => boolean): Player[]; From e4065dbc91d7e00f633b58baba030264c1b13f1a Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 23:48:46 +0100 Subject: [PATCH 083/117] Add missing type definition for CommandExecutable --- types/CommandQueue.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/types/CommandQueue.d.ts b/types/CommandQueue.d.ts index ecec7fbce..0c2037239 100644 --- a/types/CommandQueue.d.ts +++ b/types/CommandQueue.d.ts @@ -1,3 +1,10 @@ +/** @typedef {{ execute: function (), label: string, lag: number= }} */ +export declare type CommandExecutable = { + execute: Function; + label: string; + lag: number; +} + export declare class CommandQueue { constructor(); From 27511f992bc74900bc9222a91eb4d9ee4955d5d1 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sat, 5 Dec 2020 23:49:12 +0100 Subject: [PATCH 084/117] Export type CommandExecutable definition --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index e92b98992..bce307cc8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -24,7 +24,7 @@ export { AudienceOptions, ChannelAudience } from './types/ChannelAudience'; export { ChannelManager } from './types/ChannelManager'; export { Character, CharacterConfig } from './types/Character'; export { CommandManager } from './types/CommandManager'; -export { CommandQueue } from './types/CommandQueue'; +export { CommandExecutable, CommandQueue } from './types/CommandQueue'; export { CommandType } from './types/CommandType'; export { Config } from './types/Config'; export { Command } from './types/Command'; From b585bd1846bf7f24bd95d92dd6a872886c113c0a Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 00:10:03 +0100 Subject: [PATCH 085/117] Fix some wrong definitions --- index.d.ts | 3 ++- types/CommandManager.d.ts | 2 +- types/Effect.d.ts | 5 ++++- types/EffectFactory.d.ts | 6 +++--- types/EffectList.d.ts | 2 +- types/EffectableEntity.d.ts | 2 +- types/PlayerManager.d.ts | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index bce307cc8..3e9da6c36 100644 --- a/index.d.ts +++ b/index.d.ts @@ -62,7 +62,7 @@ export { export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. -export declare class EntityLoaderRegistry { [key: string]: any }; +/*export declare class EntityLoaderRegistry { [key: string]: any }; export declare class GameServer { [key: string]: any }; export declare class HelpManager { [key: string]: any }; export declare class ItemFactory { [key: string]: any }; @@ -76,3 +76,4 @@ export declare class QuestRewardManager { [key: string]: any }; export declare class RoomFactory { [key: string]: any }; export declare class RoomManager { [key: string]: any }; export declare class SkillManager { [key: string]: any }; +*/ diff --git a/types/CommandManager.d.ts b/types/CommandManager.d.ts index 8c8ef31d0..4db20a071 100644 --- a/types/CommandManager.d.ts +++ b/types/CommandManager.d.ts @@ -1,4 +1,4 @@ -import { Command } from './Command'; +import { Command } from "./Command"; export declare class CommandManager { commands: Map; diff --git a/types/Effect.d.ts b/types/Effect.d.ts index 6b20ff87d..ca0cafbaa 100644 --- a/types/Effect.d.ts +++ b/types/Effect.d.ts @@ -1,9 +1,12 @@ import { Character } from './Character'; import { Damage } from './Damage'; +import { EventEmitter } from 'events'; import { GameState } from './GameState'; /** @typedef EffectModifiers {{attributes: !Object}} */ -export declare type EffectModifiers = { attributes: !Object }; +export declare type EffectModifiers = { + attributes: !Object +}; export declare interface EffectConfig { /** @property {boolean} autoActivate If this effect immediately activates itself when added to the target */ diff --git a/types/EffectFactory.d.ts b/types/EffectFactory.d.ts index 7c7447c09..6b6f6d6b9 100644 --- a/types/EffectFactory.d.ts +++ b/types/EffectFactory.d.ts @@ -2,12 +2,12 @@ import { Effect } from "./Effect"; import { GameState } from "./GameState"; export declare type EffectConfig = { - config: Object; - listeners: Object; + config: { [key: string]: any } + listeners: { [key: string]: Function } } export declare class EffectFactory { - constructor(): EffectFactory; + constructor(); /** * @param {string} id diff --git a/types/EffectList.d.ts b/types/EffectList.d.ts index 412caa622..4ba8be1da 100644 --- a/types/EffectList.d.ts +++ b/types/EffectList.d.ts @@ -12,7 +12,7 @@ export declare class EffectList { * @param {Character} target * @param {Array} effects array of serialized effects (Object) or actual Effect instances */ - constructor(target: Character, effects: Array): EffectList; + constructor(target: Character, effects: Array); /** * @type {number} diff --git a/types/EffectableEntity.d.ts b/types/EffectableEntity.d.ts index 5681cb1c6..8081b7cc6 100644 --- a/types/EffectableEntity.d.ts +++ b/types/EffectableEntity.d.ts @@ -11,7 +11,7 @@ export declare class EffectableEntity extends EventEmitter { * @param {string} event * @param {...*} args */ - emit(event: string, ...args: any[]): void; + emit(event: string | symbol, ...args: any[]): boolean; /** * @param {string} attr Attribute name diff --git a/types/PlayerManager.d.ts b/types/PlayerManager.d.ts index a576c5ca9..43e3ceb54 100644 --- a/types/PlayerManager.d.ts +++ b/types/PlayerManager.d.ts @@ -29,7 +29,7 @@ export declare class PlayerManager extends EventEmitter { getPlayersAsArray(): Player[]; - addListener(event: string, listener: Function): void; + addListener(event: string | symbol, listener: (...args: any[]) => void): this; filter(fn: (current: Player, index: string | number, array: Player[]) => boolean): Player[]; From 98a18e24c15c003ba04e7bdbecd5e9e59f0801f0 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 00:15:05 +0100 Subject: [PATCH 086/117] Fix some definition issue --- types/CommandManager.d.ts | 2 +- types/Effect.d.ts | 21 ++++++--------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/types/CommandManager.d.ts b/types/CommandManager.d.ts index 4db20a071..618861400 100644 --- a/types/CommandManager.d.ts +++ b/types/CommandManager.d.ts @@ -24,4 +24,4 @@ export declare class CommandManager { * Find a command from a partial name */ find(search: string, returnAlias: boolean): Commmand | { command: Command, alias: string } | null; -}; +} diff --git a/types/Effect.d.ts b/types/Effect.d.ts index ca0cafbaa..a300dc922 100644 --- a/types/Effect.d.ts +++ b/types/Effect.d.ts @@ -5,7 +5,7 @@ import { GameState } from './GameState'; /** @typedef EffectModifiers {{attributes: !Object}} */ export declare type EffectModifiers = { - attributes: !Object + attributes: { [key: string]: Function } }; export declare interface EffectConfig { @@ -31,20 +31,10 @@ export declare interface EffectConfig { export declare class Effect extends EventEmitter { /** @property {EffectConfig} config Effect configuration (name/desc/duration/etc.) */ config: EffectConfig; - /** @property {string} description */ - description: string; - /** @property {number} duration Total duration of effect in _milliseconds_ */ - duration: number; - /** @property {number} elapsed Get elapsed time in _milliseconds_ */ - elapsed: number; /** @property {string} id filename minus .js */ id: string; /** @property {EffectModifiers} modifiers Attribute modifier functions */ modifier: EffectModifiers; - /** @property {string} name */ - name: string; - /** @property {number} remaining Number of seconds remaining */ - remaining: number; /** @property {number} startedAt Date.now() time this effect became active */ startedAt: number; /** @property {object} state Configuration of this _type_ of effect (magnitude, element, stat, etc.) */ @@ -65,21 +55,22 @@ export declare class Effect extends EventEmitter { get description(): string; /** - * @type {number} + * Total duration of effect in milliseconds + * @property {number} */ get duration(): number; - set duration(dur: number): void; + set duration(dur: number); /** * Elapsed time in milliseconds since event was activated - * @type {number} + * @property {number} */ get elapsed(): number; /** * Remaining time in seconds - * @type {number} + * @property {number} */ get remaining(): number; From cbda06e1d4306098a26db47aef3dbaba0e48acf2 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 00:19:50 +0100 Subject: [PATCH 087/117] Fix all errors on types definitions --- types/CommandManager.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/CommandManager.d.ts b/types/CommandManager.d.ts index 618861400..3aacd863f 100644 --- a/types/CommandManager.d.ts +++ b/types/CommandManager.d.ts @@ -18,10 +18,10 @@ export declare class CommandManager { /** * Find a command from a partial name */ - find(search: string): Commmand | null; + find(search: string): Command | null; /** * Find a command from a partial name */ - find(search: string, returnAlias: boolean): Commmand | { command: Command, alias: string } | null; + find(search: string, returnAlias: boolean): Command | { command: Command, alias: string } | null; } From ac2c3580a1ab356045c6e6f873b6e6dacfbfd55c Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 00:21:07 +0100 Subject: [PATCH 088/117] Format index.d.ts --- index.d.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 3e9da6c36..b0a7332fd 100644 --- a/index.d.ts +++ b/index.d.ts @@ -34,7 +34,10 @@ export { DataSourceRegistry } from './types/DataSourceRegistry'; export { DataSource } from './types/DataSource'; export { Effect, EffectConfig, EffectModifiers } from './types/Effect'; export { EffectableEntity } from './types/EffectableEntity'; -export { EffectConfig as EffectFactoryType, EffectFactory } from './types/EffectFactory'; +export { + EffectConfig as EffectFactoryType, + EffectFactory, +} from './types/EffectFactory'; export { EffectFlag } from './types/EffectFlag'; export { EffectList } from './types/EffectList'; export { EntityFactory } from './types/EntityFactory'; @@ -62,7 +65,8 @@ export { export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. -/*export declare class EntityLoaderRegistry { [key: string]: any }; +/* +export declare class EntityLoaderRegistry { [key: string]: any }; export declare class GameServer { [key: string]: any }; export declare class HelpManager { [key: string]: any }; export declare class ItemFactory { [key: string]: any }; From 7bb19c52909362f4e9e758988517566b8780cb0d Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 00:46:54 +0100 Subject: [PATCH 089/117] Add definition for EntityFactory --- types/EntityFactory.d.ts | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/types/EntityFactory.d.ts b/types/EntityFactory.d.ts index 27530c650..60f2db813 100644 --- a/types/EntityFactory.d.ts +++ b/types/EntityFactory.d.ts @@ -1,3 +1,59 @@ +import { Area } from "./Area"; +import { Item } from "./Item"; +import { Npc } from "./Npc"; +import { Room } from "./Room"; + export declare class EntityFactory { + constructor(); + + /** + * Create the key used by the entities and scripts maps + * @param {string} area Area name + * @param {number} id + * @return {string} + */ + createEntityRef(area: string, id: number): string; + + /** + * @param {string} entityRef + * @return {Object} + */ + getDefinition(entityRef: string): object; + + /** + * @param {string} entityRef + * @param {Object} def + */ + setDefinition(entityRef: string, def: object): void; + + /** + * Add an event listener from a script to a specific item + * @see BehaviorManager::addListener + * @param {string} entityRef + * @param {string} event + * @param {Function} listener + */ + addScriptListener(entityRef: string, event: string, listener: Function): void; + + /** + * Create a new instance of a given npc definition. Resulting npc will not be held or equipped + * and will _not_ have its default contents. If you want it to also populate its default contents + * you must manually call `npc.hydrate(state)` + * + * @param {Area} area + * @param {string} entityRef + * @param {Item|Npc|Room|Area} Type Type of entity to instantiate + * @return {type} + */ + createByType(area: Area, entityRef: string, Type: Item|Npc|Room|Area): Item|Npc|Room|Area; + + /** Method overloaded on sublasses */ + //create(); + /** + * Clone an existing entity. + * @param {Item|Npc|Room|Area} entity + * @return {Item|Npc|Room|Area} + */ + clone(entity: Item|Npc|Room|Area): Item|Npc|Room|Area;; } \ No newline at end of file From b1d38a4c8b01270b9a84d0990fd49e486eed9951 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:05:01 +0100 Subject: [PATCH 090/117] Add definition for EntityLoaderRegistry --- index.d.ts | 2 +- types/EntityLoaderRegistry.d.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 types/EntityLoaderRegistry.d.ts diff --git a/index.d.ts b/index.d.ts index b0a7332fd..ddc2a70a7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -42,6 +42,7 @@ export { EffectFlag } from './types/EffectFlag'; export { EffectList } from './types/EffectList'; export { EntityFactory } from './types/EntityFactory'; export { EntityLoader } from './types/EntityLoader'; +export { EntityLoaderRegistry } from './types/EntityLoaderRegistry'; export { EntityReference } from './types/EntityReference'; export { EventManager } from './types/EventManager'; export { GameEntity } from './types/GameEntity'; @@ -66,7 +67,6 @@ export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. /* -export declare class EntityLoaderRegistry { [key: string]: any }; export declare class GameServer { [key: string]: any }; export declare class HelpManager { [key: string]: any }; export declare class ItemFactory { [key: string]: any }; diff --git a/types/EntityLoaderRegistry.d.ts b/types/EntityLoaderRegistry.d.ts new file mode 100644 index 000000000..5b8763026 --- /dev/null +++ b/types/EntityLoaderRegistry.d.ts @@ -0,0 +1,12 @@ +import EntityLoader from '../src/EntityLoader'; + +/** + * Holds instances of configured EntityLoaders + * @type {Map} + */ +export declare class EntityLoaderRegistry extends Map { + load( + sourceRegistry: EntityLoader, + config: { name: string; settings: object } + ): void; +} From dccff291b596585813060f7069b15a19cbb2ee8e Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:07:51 +0100 Subject: [PATCH 091/117] Add definitions for EquipErrors --- index.d.ts | 1 + types/EquipErrors.d.ts | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 types/EquipErrors.d.ts diff --git a/index.d.ts b/index.d.ts index ddc2a70a7..819c5e74d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -45,6 +45,7 @@ export { EntityLoader } from './types/EntityLoader'; export { EntityLoaderRegistry } from './types/EntityLoaderRegistry'; export { EntityReference } from './types/EntityReference'; export { EventManager } from './types/EventManager'; +export { EquipAlreadyEquippedError, EquipSlotTakenError } from './types/EquipErrors'; export { GameEntity } from './types/GameEntity'; export { GameState } from './types/GameState'; export { Heal } from './types/Heal'; diff --git a/types/EquipErrors.d.ts b/types/EquipErrors.d.ts new file mode 100644 index 000000000..69ded5b43 --- /dev/null +++ b/types/EquipErrors.d.ts @@ -0,0 +1,2 @@ +export declare class EquipSlotTakenError extends Error {} +export declare class EquipAlreadyEquippedError extends Error {} From dd72770c4abb734c20447b8d216db3ffc9da65f8 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:11:34 +0100 Subject: [PATCH 092/117] Add definition for EventUtil --- index.d.ts | 1 + types/EventUtil.d.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 types/EventUtil.d.ts diff --git a/index.d.ts b/index.d.ts index 819c5e74d..c4cecea31 100644 --- a/index.d.ts +++ b/index.d.ts @@ -45,6 +45,7 @@ export { EntityLoader } from './types/EntityLoader'; export { EntityLoaderRegistry } from './types/EntityLoaderRegistry'; export { EntityReference } from './types/EntityReference'; export { EventManager } from './types/EventManager'; +export { EventUtil } from './types/EventUtil'; export { EquipAlreadyEquippedError, EquipSlotTakenError } from './types/EquipErrors'; export { GameEntity } from './types/GameEntity'; export { GameState } from './types/GameState'; diff --git a/types/EventUtil.d.ts b/types/EventUtil.d.ts new file mode 100644 index 000000000..091b9a9ce --- /dev/null +++ b/types/EventUtil.d.ts @@ -0,0 +1,17 @@ +import { Socket } from "net"; + +export declare class EventUtil { + /** + * Generate a function for writing colored output to a socket + * @param {net.Socket} socket + * @return {function (string)} + */ + static genWrite(socket: Socket): Function; + + /** + * Generate a function for writing colored output to a socket with a newline + * @param {net.Socket} socket + * @return {function (string)} + */ + static genSay(socket: Socket): Function; +} From 61319e65c24f9153d2b6afda468e018b34809b3c Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:16:16 +0100 Subject: [PATCH 093/117] Add definition for GameServer --- index.d.ts | 1 + types/GameServer.d.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 types/GameServer.d.ts diff --git a/index.d.ts b/index.d.ts index c4cecea31..3af527c8a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -48,6 +48,7 @@ export { EventManager } from './types/EventManager'; export { EventUtil } from './types/EventUtil'; export { EquipAlreadyEquippedError, EquipSlotTakenError } from './types/EquipErrors'; export { GameEntity } from './types/GameEntity'; +export { GameServer } from './types/GameServer'; export { GameState } from './types/GameState'; export { Heal } from './types/Heal'; export { Item } from './types/Item'; diff --git a/types/GameServer.d.ts b/types/GameServer.d.ts new file mode 100644 index 000000000..30e889b2b --- /dev/null +++ b/types/GameServer.d.ts @@ -0,0 +1,14 @@ +import { EventEmitter } from 'events'; + +export declare class GameServer extends EventEmitter { + /** + * @param {commander} commander + * @fires GameServer#startup + */ + startup(commander: object): void; + + /** + * @fires GameServer#shutdown + */ + shutdown(): void; +} From 79e96e05dcde1dad0f14a9af718deee468a31856 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:21:49 +0100 Subject: [PATCH 094/117] Add definitions for Helpfile and HelpfileOptions --- index.d.ts | 2 +- types/Helpfile.d.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 types/Helpfile.d.ts diff --git a/index.d.ts b/index.d.ts index 3af527c8a..a6b516fe6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -51,6 +51,7 @@ export { GameEntity } from './types/GameEntity'; export { GameServer } from './types/GameServer'; export { GameState } from './types/GameState'; export { Heal } from './types/Heal'; +export { Helpfile, HelpfileOptions } from './types/Helpfile'; export { Item } from './types/Item'; export { Inventory, InventoryFullError } from './types/Inventory'; export { Logger } from './types/Logger'; @@ -70,7 +71,6 @@ export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. /* -export declare class GameServer { [key: string]: any }; export declare class HelpManager { [key: string]: any }; export declare class ItemFactory { [key: string]: any }; export declare class ItemManager { [key: string]: any }; diff --git a/types/Helpfile.d.ts b/types/Helpfile.d.ts new file mode 100644 index 000000000..a9f3d2db7 --- /dev/null +++ b/types/Helpfile.d.ts @@ -0,0 +1,16 @@ +export declare interface HelpfileOptions { + keywords: string[]; + command: string; + channel: string; + related: string[]; + body: string; +} + +export declare class Helpfile { + /** + * @param {string} bundle Bundle the helpfile comes from + * @param {string} name + * @param {HelpfileOptions} options + */ + constructor(bundle: string, name: string, options: HelpfileOptions); +} From 9030d2d803540b34ea32b117ab7a8425c113382d Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:26:57 +0100 Subject: [PATCH 095/117] Add definition for HelpManager --- index.d.ts | 1 + types/HelpManager.d.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 types/HelpManager.d.ts diff --git a/index.d.ts b/index.d.ts index a6b516fe6..1581e3582 100644 --- a/index.d.ts +++ b/index.d.ts @@ -52,6 +52,7 @@ export { GameServer } from './types/GameServer'; export { GameState } from './types/GameState'; export { Heal } from './types/Heal'; export { Helpfile, HelpfileOptions } from './types/Helpfile'; +export { HelpManager } from './types/HelpManager'; export { Item } from './types/Item'; export { Inventory, InventoryFullError } from './types/Inventory'; export { Logger } from './types/Logger'; diff --git a/types/HelpManager.d.ts b/types/HelpManager.d.ts new file mode 100644 index 000000000..35de3e2f2 --- /dev/null +++ b/types/HelpManager.d.ts @@ -0,0 +1,28 @@ +import { Helpfile } from "./Helpfile"; + +export declare class HelpManager { + constructor(); + + /** + * @param {string} help Helpfile name + */ + get(help: string): Helpfile | undefined; + + /** + * @param {Helpfile} help + */ + add(help: Helpfile): void; + + /** + * @param {string} search + * @return {Help} + */ + find(search: string): Helpfile; + + /** + * Returns first help matching keywords + * @param {string} search + * @return {?string} + */ + getFirst(help: string): Helpfile | null; +} \ No newline at end of file From ed00ff99921d67476bd6df5c7d059f32d812719d Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:30:06 +0100 Subject: [PATCH 096/117] Add definition for ItemFactory --- index.d.ts | 3 +-- types/ItemFactory.d.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 types/ItemFactory.d.ts diff --git a/index.d.ts b/index.d.ts index 1581e3582..4d026e407 100644 --- a/index.d.ts +++ b/index.d.ts @@ -55,6 +55,7 @@ export { Helpfile, HelpfileOptions } from './types/Helpfile'; export { HelpManager } from './types/HelpManager'; export { Item } from './types/Item'; export { Inventory, InventoryFullError } from './types/Inventory'; +export { ItemFactory } from './types/ItemFactory'; export { Logger } from './types/Logger'; export { Metadatable, MetadatableClass } from './types/Metadatable'; export { Npc } from './types/Npc'; @@ -72,8 +73,6 @@ export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. /* -export declare class HelpManager { [key: string]: any }; -export declare class ItemFactory { [key: string]: any }; export declare class ItemManager { [key: string]: any }; export declare class MobFactory { [key: string]: any }; export declare class MobManager { [key: string]: any }; diff --git a/types/ItemFactory.d.ts b/types/ItemFactory.d.ts new file mode 100644 index 000000000..497e82434 --- /dev/null +++ b/types/ItemFactory.d.ts @@ -0,0 +1,17 @@ +import { Area } from './Area'; +import { EntityFactory } from './EntityFactory'; +import { Item } from './Item'; + +export declare class ItemFactory extends EntityFactory { + /** + * Create a new instance of an item by EntityReference. Resulting item will + * not be held or equipped and will _not_ have its default contents. If you + * want it to also populate its default contents you must manually call + * `item.hydrate(state)` + * + * @param {Area} area + * @param {string} entityRef + * @return {Item} + */ + create(area: Area, entityRef: string): Item; +} From 4cbed66e2560869805d03bdcefdd9adbc9ae73b3 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:35:01 +0100 Subject: [PATCH 097/117] Add definition for ItemManager --- index.d.ts | 1 + types/ItemManager.d.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 types/ItemManager.d.ts diff --git a/index.d.ts b/index.d.ts index 4d026e407..8ea51e42b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -54,6 +54,7 @@ export { Heal } from './types/Heal'; export { Helpfile, HelpfileOptions } from './types/Helpfile'; export { HelpManager } from './types/HelpManager'; export { Item } from './types/Item'; +export { ItemManager } from './types/ItemManager'; export { Inventory, InventoryFullError } from './types/Inventory'; export { ItemFactory } from './types/ItemFactory'; export { Logger } from './types/Logger'; diff --git a/types/ItemManager.d.ts b/types/ItemManager.d.ts new file mode 100644 index 000000000..db2bf5307 --- /dev/null +++ b/types/ItemManager.d.ts @@ -0,0 +1,14 @@ +import { Item } from './Item'; + +export declare class ItemManager { + constructor(); + + add(item: Item): void; + + remove(item: Item): void; + + /** + * @fires Item#updateTick + */ + tickAll(): void; +} From 27ee8c36022b62b1a15d8a2a8870481bd2773220 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:37:10 +0100 Subject: [PATCH 098/117] Add definition for MobFactory --- index.d.ts | 3 +-- types/MobFactory.d.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 types/MobFactory.d.ts diff --git a/index.d.ts b/index.d.ts index 8ea51e42b..2f9219b53 100644 --- a/index.d.ts +++ b/index.d.ts @@ -59,6 +59,7 @@ export { Inventory, InventoryFullError } from './types/Inventory'; export { ItemFactory } from './types/ItemFactory'; export { Logger } from './types/Logger'; export { Metadatable, MetadatableClass } from './types/Metadatable'; +export { MobFactory } from './types/MobFactory'; export { Npc } from './types/Npc'; export { Player } from './types/Player'; export { PlayerManager } from './types/PlayerManager'; @@ -74,8 +75,6 @@ export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. /* -export declare class ItemManager { [key: string]: any }; -export declare class MobFactory { [key: string]: any }; export declare class MobManager { [key: string]: any }; export declare class PartyManager { [key: string]: any }; export declare class QuestFactory { [key: string]: any }; diff --git a/types/MobFactory.d.ts b/types/MobFactory.d.ts new file mode 100644 index 000000000..2fa52fd72 --- /dev/null +++ b/types/MobFactory.d.ts @@ -0,0 +1,16 @@ +import { Area } from './Area'; +import { EntityFactory } from './EntityFactory'; +import { Npc } from './Npc'; + +export declare class MobFactory extends EntityFactory { + /** + * Create a new instance of a given npc definition. Resulting npc will not + * have its default inventory. If you want to also populate its default + * contents you must manually call `npc.hydrate(state)` + * + * @param {Area} area + * @param {string} entityRef + * @return {Npc} + */ + create(area: Area, entityRef: string): Npc; +} From ba1cf885d6b71d6c5a74c3208c9a179bc39c81af Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:39:27 +0100 Subject: [PATCH 099/117] Add definition for MobManager --- index.d.ts | 2 +- types/MobManager.d.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 types/MobManager.d.ts diff --git a/index.d.ts b/index.d.ts index 2f9219b53..58a7cb435 100644 --- a/index.d.ts +++ b/index.d.ts @@ -60,6 +60,7 @@ export { ItemFactory } from './types/ItemFactory'; export { Logger } from './types/Logger'; export { Metadatable, MetadatableClass } from './types/Metadatable'; export { MobFactory } from './types/MobFactory'; +export { MobManager } from './types/MobManager'; export { Npc } from './types/Npc'; export { Player } from './types/Player'; export { PlayerManager } from './types/PlayerManager'; @@ -75,7 +76,6 @@ export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. /* -export declare class MobManager { [key: string]: any }; export declare class PartyManager { [key: string]: any }; export declare class QuestFactory { [key: string]: any }; export declare class QuestGoalManager { [key: string]: any }; diff --git a/types/MobManager.d.ts b/types/MobManager.d.ts new file mode 100644 index 000000000..9485eaaa0 --- /dev/null +++ b/types/MobManager.d.ts @@ -0,0 +1,16 @@ +import { Npc } from './Npc'; + +export declare class MobManager { + constructor(); + + /** + * @param {Npc} mob + */ + addMob(mob: Npc): void; + + /** + * Completely obliterate a mob from the game, nuclear option + * @param {Npc} mob + */ + removeMob(mob: Npc): void; +} From 33f0f822075626f6af2bf416573702dc9b955f41 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:44:26 +0100 Subject: [PATCH 100/117] Complete definition for Npc --- types/Npc.d.ts | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/types/Npc.d.ts b/types/Npc.d.ts index 67280c1d7..6a4da53b7 100644 --- a/types/Npc.d.ts +++ b/types/Npc.d.ts @@ -1,6 +1,30 @@ -import { Character } from './Character'; +import { Area } from './Area'; +import { Character, CharacterConfig } from './Character'; +import { GameState } from './GameState'; +import { Room } from './Room'; import { Scriptable } from './Scriptable'; +/** + * @property {number} id Area-relative id (vnum) + * @property {Area} area Area npc belongs to (not necessarily the area they're currently in) + * @property {Map} behaviors + * @extends Character + * @mixes Scriptable + */ export declare class Npc extends Scriptable(Character) { + constructor(area: Area, data: CharacterConfig); -} \ No newline at end of file + /** + * Move the npc to the given room, emitting events appropriately + * @param {Room} nextRoom + * @param {function} onMoved Function to run after the npc is moved to the next room but before enter events are fired + * @fires Room#npcLeave + * @fires Room#npcEnter + * @fires Npc#enterRoom + */ + moveTo(nextRoom: Room, onMoved: Function): void; + + hydrate(state: GameState): void; + + get isNpc(): boolean; +} From 4af3e1e0da0a252fc21cee1d78639418682135ab Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:47:12 +0100 Subject: [PATCH 101/117] Add definition for PartyAudience --- index.d.ts | 1 + types/PartyAudience.d.ts | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 types/PartyAudience.d.ts diff --git a/index.d.ts b/index.d.ts index 58a7cb435..dc7b9167d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -62,6 +62,7 @@ export { Metadatable, MetadatableClass } from './types/Metadatable'; export { MobFactory } from './types/MobFactory'; export { MobManager } from './types/MobManager'; export { Npc } from './types/Npc'; +export { PartyAudience } from './types/PartyAudience'; export { Player } from './types/Player'; export { PlayerManager } from './types/PlayerManager'; export { PlayerRoles } from './types/PlayerRoles'; diff --git a/types/PartyAudience.d.ts b/types/PartyAudience.d.ts new file mode 100644 index 000000000..7048f978d --- /dev/null +++ b/types/PartyAudience.d.ts @@ -0,0 +1,6 @@ +import { ChannelAudience } from './ChannelAudience'; +import { Player } from './Player'; + +export declare class PartyAudience extends ChannelAudience { + getBroadcastTargets(): Array; +} \ No newline at end of file From b868c728145bb9e7f7e32fc9552fed3dc3f8ed22 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 01:56:46 +0100 Subject: [PATCH 102/117] Add definitions for Party and PartyManager --- index.d.ts | 2 ++ types/Party.d.ts | 19 +++++++++++++++++++ types/PartyManager.d.ts | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 types/Party.d.ts create mode 100644 types/PartyManager.d.ts diff --git a/index.d.ts b/index.d.ts index dc7b9167d..bc05ed17b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -62,6 +62,8 @@ export { Metadatable, MetadatableClass } from './types/Metadatable'; export { MobFactory } from './types/MobFactory'; export { MobManager } from './types/MobManager'; export { Npc } from './types/Npc'; +export { Party } from './types/Party'; +export { PartyManager } from './types/PartyManager'; export { PartyAudience } from './types/PartyAudience'; export { Player } from './types/Player'; export { PlayerManager } from './types/PlayerManager'; diff --git a/types/Party.d.ts b/types/Party.d.ts new file mode 100644 index 000000000..c3f7e117b --- /dev/null +++ b/types/Party.d.ts @@ -0,0 +1,19 @@ +import { Player } from "./Player"; + +export declare class Party extends Set { + constructor(leader: Player); + + delete(member: Player): boolean; + + add(member: Player): this; + + disband(): void; + + invite(target: Player): void; + + isInvited(target: Player): boolean; + + removeInvite(target: Player): void; + + getBroadcastTargets(): Array; +} \ No newline at end of file diff --git a/types/PartyManager.d.ts b/types/PartyManager.d.ts new file mode 100644 index 000000000..54ed3351b --- /dev/null +++ b/types/PartyManager.d.ts @@ -0,0 +1,19 @@ +import { Party } from './Party'; +import { Player } from './Player'; + +/** + * Keeps track of active in game parties and is used to create new parties + * @extends Set + */ +export declare class PartyManager extends Set { + /** + * Create a new party from with a given leader + * @param {Player} leader + */ + create(leader: Player): void; + + /** + * @param {Party} party + */ + disband(party: Party): void; +} From bc4ce42708444789a3cbb7ef0f86ae9dd11e7b2c Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 20:55:04 +0100 Subject: [PATCH 103/117] Update PlayerManager definition --- types/PlayerManager.d.ts | 44 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/types/PlayerManager.d.ts b/types/PlayerManager.d.ts index 43e3ceb54..155954542 100644 --- a/types/PlayerManager.d.ts +++ b/types/PlayerManager.d.ts @@ -6,19 +6,37 @@ import { EventManager } from './EventManager'; import { GameState } from './GameState'; import { Player } from './Player'; +/** + * Keeps track of all active players in game + * @extends EventEmitter + * @property {Map} players + * @property {EventManager} events Player events + * @property {EntityLoader} loader + * @listens PlayerManager#save + * @listens PlayerManager#updateTick + */ export declare class PlayerManager extends EventEmitter { players: Map; events: EventManager; loader: EntityLoader | null; + constructor(); + /** * Set the entity loader from which players are loaded * @param {EntityLoader} */ setLoader(loader: EntityLoader): void; + /** + * @param {string} name + * @return {Player} + */ getPlayer(name: string): Player; + /** + * @param {Player} player + */ addPlayer(player: Player): void; /** @@ -27,11 +45,24 @@ export declare class PlayerManager extends EventEmitter { */ removePlayer(player: Player, killSocket?: boolean): void; + /** + * @return {array} + */ getPlayersAsArray(): Player[]; + /** + * @param {string} behaviorName + * @param {Function} listener + */ addListener(event: string | symbol, listener: (...args: any[]) => void): this; - filter(fn: (current: Player, index: string | number, array: Player[]) => boolean): Player[]; + /** + * @param {Function} predicate Filter function + * @return {Player[]}, + */ + filter( + fn: (current: Player, index: string | number, array: Player[]) => boolean + ): Player[]; /** * Load a player for an account @@ -41,7 +72,12 @@ export declare class PlayerManager extends EventEmitter { * @param {boolean} force true to force reload from storage * @return {Player} */ - loadPlayer(state: GameState, account: Account, username: string, force?: boolean): Promise; + loadPlayer( + state: GameState, + account: Account, + username: string, + force?: boolean + ): Promise; /** * Turn player into a key used by this class's map @@ -50,6 +86,10 @@ export declare class PlayerManager extends EventEmitter { */ keyify(player: Player): string; + /** + * @param {string} name + * @return {boolean} + */ exists(name: string): boolean; /** From 1c33abeb15eb87b0a1d918086da9be8aab2f0ba6 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 20:57:56 +0100 Subject: [PATCH 104/117] Add definition for PrivateAudience --- index.d.ts | 2 +- types/PrivateAudience.d.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 types/PrivateAudience.d.ts diff --git a/index.d.ts b/index.d.ts index bc05ed17b..f5e412595 100644 --- a/index.d.ts +++ b/index.d.ts @@ -68,6 +68,7 @@ export { PartyAudience } from './types/PartyAudience'; export { Player } from './types/Player'; export { PlayerManager } from './types/PlayerManager'; export { PlayerRoles } from './types/PlayerRoles'; +export { PrivateAudience } from './types/PrivateAudience'; export { Room, Door, Exit } from './types/Room'; export { Scriptable, ScriptableClass } from './types/Scriptable'; export { @@ -79,7 +80,6 @@ export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. /* -export declare class PartyManager { [key: string]: any }; export declare class QuestFactory { [key: string]: any }; export declare class QuestGoalManager { [key: string]: any }; export declare class QuestRewardManager { [key: string]: any }; diff --git a/types/PrivateAudience.d.ts b/types/PrivateAudience.d.ts new file mode 100644 index 000000000..2b19434f8 --- /dev/null +++ b/types/PrivateAudience.d.ts @@ -0,0 +1,14 @@ +import { ChannelAudience } from './ChannelAudience'; +import { Player } from './Player'; + +/** + * Audience class representing a specific targeted player. + * Example: `tell` command or `whisper` command. + * @memberof ChannelAudience + * @extends ChannelAudience + */ +export declare class PrivateAudience extends ChannelAudience { + getBroadcastTargets(): Player[]; + + alterMessage(message: string): string; +} \ No newline at end of file From c767a8f2fdc06d487e638ebc02a091a71afda71c Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 21:22:17 +0100 Subject: [PATCH 105/117] Add definitions for Quest, QuestGoals, QuestRewards and its subtypes --- index.d.ts | 15 ++++++++-- types/Quest.d.ts | 61 +++++++++++++++++++++++++++++++++++++++++ types/QuestFactory.d.ts | 3 ++ types/QuestGoal.d.ts | 36 ++++++++++++++++++++++++ types/QuestReward.d.ts | 37 +++++++++++++++++++++++++ 5 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 types/Quest.d.ts create mode 100644 types/QuestFactory.d.ts create mode 100644 types/QuestGoal.d.ts create mode 100644 types/QuestReward.d.ts diff --git a/index.d.ts b/index.d.ts index f5e412595..09242d0ce 100644 --- a/index.d.ts +++ b/index.d.ts @@ -46,7 +46,10 @@ export { EntityLoaderRegistry } from './types/EntityLoaderRegistry'; export { EntityReference } from './types/EntityReference'; export { EventManager } from './types/EventManager'; export { EventUtil } from './types/EventUtil'; -export { EquipAlreadyEquippedError, EquipSlotTakenError } from './types/EquipErrors'; +export { + EquipAlreadyEquippedError, + EquipSlotTakenError, +} from './types/EquipErrors'; export { GameEntity } from './types/GameEntity'; export { GameServer } from './types/GameServer'; export { GameState } from './types/GameState'; @@ -69,6 +72,15 @@ export { Player } from './types/Player'; export { PlayerManager } from './types/PlayerManager'; export { PlayerRoles } from './types/PlayerRoles'; export { PrivateAudience } from './types/PrivateAudience'; +export { Quest, QuestConfig } from './types/Quest'; +export { QuestFactory } from './types/QuestFactory'; +export { + QuestGoal, + QuestGoalConfig, + QuestGoalProgress, + QuestGoalSerialized, +} from './types/QuestGoal'; +export { QuestReward, QuestRewardConfig } from './types/QuestReward'; export { Room, Door, Exit } from './types/Room'; export { Scriptable, ScriptableClass } from './types/Scriptable'; export { @@ -80,7 +92,6 @@ export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. /* -export declare class QuestFactory { [key: string]: any }; export declare class QuestGoalManager { [key: string]: any }; export declare class QuestRewardManager { [key: string]: any }; export declare class RoomFactory { [key: string]: any }; diff --git a/types/Quest.d.ts b/types/Quest.d.ts new file mode 100644 index 000000000..1a83c205f --- /dev/null +++ b/types/Quest.d.ts @@ -0,0 +1,61 @@ +import { EventEmitter } from 'events'; +import { GameState } from './GameState'; +import { Player } from './Player'; +import { QuestGoal } from './QuestGoal'; +import { QuestReward } from './QuestReward'; + +export declare type QuestConfig = { + title: string; + description: string, + completionMessage: string | null, + requires: string[], + level: number, + autoComplete: boolean, + repeatable: boolean, + rewards: QuestReward[], + goals: QuestGoal[] + +} + +/** + * @property {object} config Default config for this quest, see individual quest types for details + * @property {Player} player + * @property {object} state Current completion state + * @extends EventEmitter + */ +export declare class Quest extends EventEmitter { + constructor(GameState: GameState, id: string, config: QuestConfig, player: Player); + + /** + * Proxy all events to all the goals + * @param {string} event + * @param {...*} args + */ + emit(event, ...args); + + addGoal(goal); + + /** + * @fires Quest#turn-in-ready + * @fires Quest#progress + */ + onProgressUpdated(); + + /** + * @return {{ percent: number, display: string }} + */ + getProgress(); + + /** + * Save the current state of the quest on player save + * @return {object} + */ + serialize(); + + hydrate(); + + /** + * @fires Quest#complete + */ + complete(); +} diff --git a/types/QuestFactory.d.ts b/types/QuestFactory.d.ts new file mode 100644 index 000000000..07719abd9 --- /dev/null +++ b/types/QuestFactory.d.ts @@ -0,0 +1,3 @@ +export declare class QuestFactory { + +} \ No newline at end of file diff --git a/types/QuestGoal.d.ts b/types/QuestGoal.d.ts new file mode 100644 index 000000000..96d5fb835 --- /dev/null +++ b/types/QuestGoal.d.ts @@ -0,0 +1,36 @@ +import { EventEmitter } from 'events'; +import { GameState } from './GameState'; +import { Player } from './Player'; +import { Quest } from './Quest'; + +export declare type QuestGoalConfig = {}; +export declare type QuestGoalProgress = { + percent: number; + display: string; +}; +export declare type QuestGoalSerialized = { + state: GameState; + progress: QuestGoalProgress; + config: QuestGoalConfig; +}; + +export declare class QuestGoal extends EventEmitter { + /** + * @param {Quest} quest Quest this goal is for + * @param {object} config + * @param {Player} player + */ + constructor(quest: Quest, config: QuestGoalConfig, player: Player); + + /** + * @return {{ percent: number, display: string}} + */ + getProgress(): QuestGoalProgress; + + /** + * Put any cleanup activities after the quest is finished here + */ + complete(): void; + + serialize(): QuestGoalSerialized; +} diff --git a/types/QuestReward.d.ts b/types/QuestReward.d.ts new file mode 100644 index 000000000..e4fcb32d0 --- /dev/null +++ b/types/QuestReward.d.ts @@ -0,0 +1,37 @@ +import { GameState } from './GameState'; +import { Player } from './Player'; +import { Quest } from './Quest'; + +export declare type QuestRewardConfig = {}; + +/** + * Representation of a quest reward + * The {@link http://ranviermud.com/extending/areas/quests/|Quest guide} has instructions on to + * create new reward type for quests + */ +export declare class QuestReward { + /** + * Assign the reward to the player + * @param {GameState} GameState + * @param {Quest} quest quest this reward is being given from + * @param {object} config + * @param {Player} player + */ + static reward( + GameState: GameState, + quest: Quest, + config: QuestRewardConfig, + player: Player + ): void; + + /** + * Render the reward + * @return string + */ + static display( + GameState: GameState, + quest: Quest, + config: QuestRewardConfig, + player: Player + ): string; +} From ed5b9f8762ba65b793ad76e981c0359588133d64 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 21:27:14 +0100 Subject: [PATCH 106/117] Add definition for QuestFactory --- types/QuestFactory.d.ts | 46 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/types/QuestFactory.d.ts b/types/QuestFactory.d.ts index 07719abd9..f2d422278 100644 --- a/types/QuestFactory.d.ts +++ b/types/QuestFactory.d.ts @@ -1,3 +1,47 @@ +import { GameState } from './GameState'; +import { Player } from './Player'; +import { Quest, QuestConfig } from './Quest'; + export declare class QuestFactory { + constructor(); + + add(areaName: string, id: string, config: QuestConfig); + + set(qid: string, val: QuestConfig); + + /** + * Get a quest definition. Use `create` if you want an instance of a quest + * @param {string} qid + * @return {object} + */ + get(qid: string): Quest; + + /** + * Check to see if a player can start a given quest based on the quest's + * prerequisite quests + * @param {entityReference} questRef + * @return {boolean} + */ + canStart(player: Player, questRef: string); + + /** + * @param {GameState} GameState + * @param {entityReference} qid + * @param {Player} player + * @param {Array} state current quest state + * @return {Quest} + */ + create( + GameState: GameState, + qid: string, + player: Player, + state: any[] + ): Quest; -} \ No newline at end of file + /** + * @param {string} areaName + * @param {number} id + * @return {string} + */ + makeQuestKey(area: string, id: number): string; +} From 36a2f0feb4a6592970734a70a1a2d4060e7cce42 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 21:33:19 +0100 Subject: [PATCH 107/117] Add definition for QuestTracker --- index.d.ts | 1 + types/QuestTracker.d.ts | 58 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 types/QuestTracker.d.ts diff --git a/index.d.ts b/index.d.ts index 09242d0ce..245db4e21 100644 --- a/index.d.ts +++ b/index.d.ts @@ -81,6 +81,7 @@ export { QuestGoalSerialized, } from './types/QuestGoal'; export { QuestReward, QuestRewardConfig } from './types/QuestReward'; +export { QuestTracker, SerializedQuestTracker } from './types/QuestTracker'; export { Room, Door, Exit } from './types/Room'; export { Scriptable, ScriptableClass } from './types/Scriptable'; export { diff --git a/types/QuestTracker.d.ts b/types/QuestTracker.d.ts new file mode 100644 index 000000000..dbc679d27 --- /dev/null +++ b/types/QuestTracker.d.ts @@ -0,0 +1,58 @@ +import { GameState } from './GameState'; +import { Player } from './Player'; +import { Quest } from './Quest'; + +export declare type SerializedQuestTracker = { + completed: Quest[]; + active: Quest[]; +}; + +export declare class QuestTracker { + /** + * @param {Player} player + * @param {Array} active + * @param {Array} completed + */ + constructor(player: Player, active: Quest[], completed: Quest[]); + + /** + * Proxy events to all active quests + * @param {string} event + * @param {...*} args + */ + emit(event: string, ...args: any[]): void; + + /** + * @param {EntityReference} qid + * @return {boolean} + */ + isActive(qid: string): boolean; + + /** + * @param {EntityReference} qid + * @return {boolean} + */ + isComplete(qid: string): boolean; + + get(qid: string): Quest; + + /** + * @param {EntityReference} qid + */ + complete(qid: string); + + /** + * @param {Quest} quest + */ + start(quest: Quest): void; + + /** + * @param {GameState} state + */ + hydrate(state: GameState): void; + + /** + * @return {object} + */ + serialize(): SerializedQuestTracker; +} From d4a46f5223fc55ce65c1d091552828fd64daa2cf Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 21:38:05 +0100 Subject: [PATCH 108/117] Add definition for QuestGoalManager --- index.d.ts | 2 +- types/QuestGoalManager.d.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 types/QuestGoalManager.d.ts diff --git a/index.d.ts b/index.d.ts index 245db4e21..884cf6f65 100644 --- a/index.d.ts +++ b/index.d.ts @@ -80,6 +80,7 @@ export { QuestGoalProgress, QuestGoalSerialized, } from './types/QuestGoal'; +export { QuestGoalManager } from './types/QuestGoalManager'; export { QuestReward, QuestRewardConfig } from './types/QuestReward'; export { QuestTracker, SerializedQuestTracker } from './types/QuestTracker'; export { Room, Door, Exit } from './types/Room'; @@ -93,7 +94,6 @@ export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. /* -export declare class QuestGoalManager { [key: string]: any }; export declare class QuestRewardManager { [key: string]: any }; export declare class RoomFactory { [key: string]: any }; export declare class RoomManager { [key: string]: any }; diff --git a/types/QuestGoalManager.d.ts b/types/QuestGoalManager.d.ts new file mode 100644 index 000000000..e790a2065 --- /dev/null +++ b/types/QuestGoalManager.d.ts @@ -0,0 +1,4 @@ +/** + * Simple map of quest goal name => class definition + */ +export declare class QuestGoalManager extends Map {} From d6fd885f7b5a7f1f534d44db004040aa3527015f Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 21:39:13 +0100 Subject: [PATCH 109/117] Add definition for QuestRewardManager --- index.d.ts | 1 + types/QuestRewardManager.d.ts | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 types/QuestRewardManager.d.ts diff --git a/index.d.ts b/index.d.ts index 884cf6f65..a9ea74834 100644 --- a/index.d.ts +++ b/index.d.ts @@ -82,6 +82,7 @@ export { } from './types/QuestGoal'; export { QuestGoalManager } from './types/QuestGoalManager'; export { QuestReward, QuestRewardConfig } from './types/QuestReward'; +export { QuestRewardManager } from './types/QuestRewardManager'; export { QuestTracker, SerializedQuestTracker } from './types/QuestTracker'; export { Room, Door, Exit } from './types/Room'; export { Scriptable, ScriptableClass } from './types/Scriptable'; diff --git a/types/QuestRewardManager.d.ts b/types/QuestRewardManager.d.ts new file mode 100644 index 000000000..73833b171 --- /dev/null +++ b/types/QuestRewardManager.d.ts @@ -0,0 +1,4 @@ +/** + * Simple map of quest reward name => class instance + */ +export declare class QuestRewardManager extends Map {} From c4f68beb09d56e32227811de96be88194528b48e Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 21:41:53 +0100 Subject: [PATCH 110/117] Add definition for RoleAudience --- index.d.ts | 1 + types/RoleAudience.d.ts | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 types/RoleAudience.d.ts diff --git a/index.d.ts b/index.d.ts index a9ea74834..c3704d807 100644 --- a/index.d.ts +++ b/index.d.ts @@ -84,6 +84,7 @@ export { QuestGoalManager } from './types/QuestGoalManager'; export { QuestReward, QuestRewardConfig } from './types/QuestReward'; export { QuestRewardManager } from './types/QuestRewardManager'; export { QuestTracker, SerializedQuestTracker } from './types/QuestTracker'; +export { RoleAudience} from './types/RoleAudience'; export { Room, Door, Exit } from './types/Room'; export { Scriptable, ScriptableClass } from './types/Scriptable'; export { diff --git a/types/RoleAudience.d.ts b/types/RoleAudience.d.ts new file mode 100644 index 000000000..5d2fd9e3f --- /dev/null +++ b/types/RoleAudience.d.ts @@ -0,0 +1,8 @@ +import { AudienceOptions, ChannelAudience } from "./ChannelAudience"; +import { Player } from "./Player"; + +export declare class RoleAudience extends ChannelAudience { + constructor(options: AudienceOptions); + + getBroadcastTargets(): Player[]; +} \ No newline at end of file From 379bb0f6e4158a6281c7e1665e91eaf9accd237a Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 21:44:17 +0100 Subject: [PATCH 111/117] Add definition for RoomAudience --- index.d.ts | 2 +- types/RoomAudience.d.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 types/RoomAudience.d.ts diff --git a/index.d.ts b/index.d.ts index c3704d807..8d9da547c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -86,6 +86,7 @@ export { QuestRewardManager } from './types/QuestRewardManager'; export { QuestTracker, SerializedQuestTracker } from './types/QuestTracker'; export { RoleAudience} from './types/RoleAudience'; export { Room, Door, Exit } from './types/Room'; +export { RoomAudience } from './types/RoomAudience'; export { Scriptable, ScriptableClass } from './types/Scriptable'; export { CooldownError, @@ -96,7 +97,6 @@ export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. /* -export declare class QuestRewardManager { [key: string]: any }; export declare class RoomFactory { [key: string]: any }; export declare class RoomManager { [key: string]: any }; export declare class SkillManager { [key: string]: any }; diff --git a/types/RoomAudience.d.ts b/types/RoomAudience.d.ts new file mode 100644 index 000000000..0fe2c8829 --- /dev/null +++ b/types/RoomAudience.d.ts @@ -0,0 +1,6 @@ +import { ChannelAudience } from "./ChannelAudience"; +import { Player } from "./Player"; + +export declare class RoomAudience extends ChannelAudience { + getBroadcastTargets(): Player[]; +} \ No newline at end of file From 09ebc9b03c6a481cb41990b50213e9cbfeb03464 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 21:46:43 +0100 Subject: [PATCH 112/117] Add definition for RoomFactory --- index.d.ts | 2 +- types/RoomFactory.d.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 types/RoomFactory.d.ts diff --git a/index.d.ts b/index.d.ts index 8d9da547c..c0ece456b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -87,6 +87,7 @@ export { QuestTracker, SerializedQuestTracker } from './types/QuestTracker'; export { RoleAudience} from './types/RoleAudience'; export { Room, Door, Exit } from './types/Room'; export { RoomAudience } from './types/RoomAudience'; +export { RoomFactory } from './types/RoomFactory'; export { Scriptable, ScriptableClass } from './types/Scriptable'; export { CooldownError, @@ -97,7 +98,6 @@ export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. /* -export declare class RoomFactory { [key: string]: any }; export declare class RoomManager { [key: string]: any }; export declare class SkillManager { [key: string]: any }; */ diff --git a/types/RoomFactory.d.ts b/types/RoomFactory.d.ts new file mode 100644 index 000000000..9ca1a8c8f --- /dev/null +++ b/types/RoomFactory.d.ts @@ -0,0 +1,18 @@ +import { Area } from './Area'; +import { EntityFactory } from './EntityFactory'; +import { Room } from './Room'; + +/** + * Stores definitions of rooms to allow for easy creation/cloning + * @extends EntityFactory + */ +export declare class RoomFactory extends EntityFactory { + /** + * Create a new instance of a given room. Room will not be hydrated + * + * @param {Area} area + * @param {string} entityRef + * @return {Room} + */ + create(area: Area, entityRef: string): Room; +} From 00d03381c1636228da53875518709738f967507d Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Sun, 6 Dec 2020 21:48:54 +0100 Subject: [PATCH 113/117] Add definition for RoomManager --- index.d.ts | 1 + types/RoomManager.d.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 types/RoomManager.d.ts diff --git a/index.d.ts b/index.d.ts index c0ece456b..1cc5153a1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -88,6 +88,7 @@ export { RoleAudience} from './types/RoleAudience'; export { Room, Door, Exit } from './types/Room'; export { RoomAudience } from './types/RoomAudience'; export { RoomFactory } from './types/RoomFactory'; +export { RoomManager } from './types/RoomManager'; export { Scriptable, ScriptableClass } from './types/Scriptable'; export { CooldownError, diff --git a/types/RoomManager.d.ts b/types/RoomManager.d.ts new file mode 100644 index 000000000..aaddf63de --- /dev/null +++ b/types/RoomManager.d.ts @@ -0,0 +1,24 @@ +import { Room } from "./Room"; + +/** + * Keeps track of all the individual rooms in the game + */ +export declare class RoomManager { + constructor(); + + /** + * @param {string} entityRef + * @return {Room} + */ + getRoom(entityRef: string): Room; + + /** + * @param {Room} room + */ + addRoom(room: Room): void; + + /** + * @param {Room} room + */ + removeRoom(room: Room): void; +} From 71b55eda29c18d4af474d63381980dc57892d754 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 7 Dec 2020 00:09:07 +0100 Subject: [PATCH 114/117] Add definitio for Skill, SkillFlag and SkillManager --- index.d.ts | 4 +- types/Skill.d.ts | 123 ++++++++++++++++++++++++++++++++++++++++ types/SkillFlag.d.ts | 4 ++ types/SkillManager.d.ts | 29 ++++++++++ 4 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 types/Skill.d.ts create mode 100644 types/SkillFlag.d.ts create mode 100644 types/SkillManager.d.ts diff --git a/index.d.ts b/index.d.ts index 1cc5153a1..634fa7546 100644 --- a/index.d.ts +++ b/index.d.ts @@ -90,15 +90,17 @@ export { RoomAudience } from './types/RoomAudience'; export { RoomFactory } from './types/RoomFactory'; export { RoomManager } from './types/RoomManager'; export { Scriptable, ScriptableClass } from './types/Scriptable'; +export { Skill } from './types/Skill'; export { CooldownError, NotEnoughResourcesError, PassiveError, } from './types/SkillErrors'; +export { SkillFlag } from './types/SkillFlag'; +export { SkillManager } from './types/SkillManager'; export { SkillType } from './types/SkillType'; // Placeholders for types yet to be defined. /* export declare class RoomManager { [key: string]: any }; -export declare class SkillManager { [key: string]: any }; */ diff --git a/types/Skill.d.ts b/types/Skill.d.ts new file mode 100644 index 000000000..8d334aeb9 --- /dev/null +++ b/types/Skill.d.ts @@ -0,0 +1,123 @@ +import { Attribute } from './Attribute'; +import { Character } from './Character'; +import { Effect } from './Effect'; +import { GameState } from './GameState'; +import { Player } from './Player'; +import { SkillType } from './SkillType'; + +export declare type SkillResource = { + attribute: string; + cost: number; +}; + +export declare type SkillConfig = { + configureEffect: Function; + cooldown: + | number + | { + group: string; + length: number; + }; + effect: Effect; + flags: string[]; + info: Function; + initiatesCombat?: boolean; + name: string; + requiresTarget?: boolean; + resource: null | SkillResource; + run: Function; + targetSelf?: boolean; + type: SkillType; + options?: object; +}; + +export declare type CooldownConfig = { + config: { + name: string; + description: string; + unique: boolean; + type: string; + }; + state: { + cooldownId: null | string; + }; + listeners: { + effectDeactivated: Function; + }; +}; + +/** + * @property {function (Effect)} configureEffect modify the skill's effect before adding to player + * @property {null|number} cooldownLength When a number > 0 apply a cooldown effect to disallow usage + * until the cooldown has ended + * @property {string} effect Id of the passive effect for this skill + * @property {Array} flags + * @property {function ()} info Function to run to display extra info about this skill + * @property {function ()} run Function to run when skill is executed/activated + * @property {GameState} state + * @property {SkillType} type + */ +export declare class Skill { + /** + * @param {string} id + * @param {object} config + * @param {GameState} state + */ + constructor(id: string, config: SkillConfig, state: GameState); + + /** + * perform an active skill + * @param {string} args + * @param {Player} player + * @param {Character} target + */ + execute(args: string, player: Player, target: Character): boolean; + + /** + * @param {Player} player + * @return {boolean} If the player has paid the resource cost(s). + */ + payResourceCosts(player: Player): boolean; + + // Helper to pay a single resource cost. + payResourceCost(player: Player, resource: SkillResource): Boolean; + + activate(player: Player): void; + + /** + * @param {Character} character + * @return {boolean|Effect} If on cooldown returns the cooldown effect + */ + onCooldown(character: Character): boolean | Effect; + + /** + * Put this skill on cooldown + * @param {Character} character + */ + cooldown(character: Character): void; + + getCooldownId(): string; + + /** + * Create an instance of the cooldown effect for use by cooldown() + * + * @private + * @return {Effect} + */ + createCooldownEffect(): Effect; + + getDefaultCooldownConfig(): CooldownConfig; + + /** + * @param {Character} character + * @return {boolean} + */ + hasEnoughResources(character: Character): boolean; + + /** + * @param {Character} character + * @param {{ attribute: string, cost: number}} resource + * @return {boolean} + */ + hasEnoughResource(character: Character, resource: SkillResource): boolean; +} diff --git a/types/SkillFlag.d.ts b/types/SkillFlag.d.ts new file mode 100644 index 000000000..41b69d375 --- /dev/null +++ b/types/SkillFlag.d.ts @@ -0,0 +1,4 @@ +export declare enum SkillFlag { + PASSIVE = 'PASSIVE', + ACTIVE = 'ACTIVE' +} \ No newline at end of file diff --git a/types/SkillManager.d.ts b/types/SkillManager.d.ts new file mode 100644 index 000000000..ad72bc53a --- /dev/null +++ b/types/SkillManager.d.ts @@ -0,0 +1,29 @@ +import { Skill } from './Skill'; + +export declare class SkillManager { + constructor(); + + /** + * @param {string} skill Skill name + * @return {Skill|undefined} + */ + get(skill: Skill): Skill | undefined; + + /** + * @param {Skill} skill + */ + add(skill: Skill): void; + + /** + * @param {Skill} skill + */ + remove(skill: Skill): void; + + /** + * Find executable skills + * @param {string} search + * @param {boolean} includePassive + * @return {Skill} + */ + find(search: string, includePassive?: boolean): Skill | undefined; +} From c4af796f7507ef6608ae54aff478dbcbf44f48d8 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 7 Dec 2020 00:28:30 +0100 Subject: [PATCH 115/117] Add definition for TransportStream and WorldAudience --- index.d.ts | 7 ++----- types/TransportStream.d.ts | 37 +++++++++++++++++++++++++++++++++++++ types/WorldAudience.d.ts | 11 +++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 types/TransportStream.d.ts create mode 100644 types/WorldAudience.d.ts diff --git a/index.d.ts b/index.d.ts index 634fa7546..33557999e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -99,8 +99,5 @@ export { export { SkillFlag } from './types/SkillFlag'; export { SkillManager } from './types/SkillManager'; export { SkillType } from './types/SkillType'; - -// Placeholders for types yet to be defined. -/* -export declare class RoomManager { [key: string]: any }; -*/ +export { TransportStream } from './types/TransportStream'; +export { WorldAudience } from './types/WorldAudience'; diff --git a/types/TransportStream.d.ts b/types/TransportStream.d.ts new file mode 100644 index 000000000..b88abd763 --- /dev/null +++ b/types/TransportStream.d.ts @@ -0,0 +1,37 @@ +import { EventEmitter } from 'events'; +import { Socket } from 'net'; + +export declare class TransportStream extends EventEmitter { + get readable(): boolean; + + get writable(): boolean; + + write(): void; + + /** + * A subtype-safe way to execute commands on a specific type of stream that invalid types will ignore. For given input + * for command (example, `"someCommand"` ill look for a method called `executeSomeCommand` on the `TransportStream` + * @param {string} command + * @param {...*} args + * @return {*} + */ + command(command: string, ...args: any[]); + + address(): undefined; + + end(): void; + + setEncoding(): void; + + pause(): void; + + resume(): void; + + destroy(): void; + + /** + * Attach a socket to this stream + * @param {*} socket + */ + attach(socket: Socket): void; +} diff --git a/types/WorldAudience.d.ts b/types/WorldAudience.d.ts new file mode 100644 index 000000000..83509ea4c --- /dev/null +++ b/types/WorldAudience.d.ts @@ -0,0 +1,11 @@ +import { ChannelAudience } from './ChannelAudience'; +import { Player } from './Player'; + +/** + * Audience class representing everyone in the game, except sender. + * @memberof ChannelAudience + * @extends ChannelAudience + */ +export declare class WorldAudience extends ChannelAudience { + getBroadcastTargets(): Player[]; +} From 00b9a285c03744251b3a4f65e31be1d5e4cd1288 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 7 Dec 2020 00:32:41 +0100 Subject: [PATCH 116/117] Add definition for Util --- index.d.ts | 1 + types/Util.d.ts | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 types/Util.d.ts diff --git a/index.d.ts b/index.d.ts index 33557999e..7add8e635 100644 --- a/index.d.ts +++ b/index.d.ts @@ -100,4 +100,5 @@ export { SkillFlag } from './types/SkillFlag'; export { SkillManager } from './types/SkillManager'; export { SkillType } from './types/SkillType'; export { TransportStream } from './types/TransportStream'; +export { Util } from './types/Util'; export { WorldAudience } from './types/WorldAudience'; diff --git a/types/Util.d.ts b/types/Util.d.ts new file mode 100644 index 000000000..51505c13d --- /dev/null +++ b/types/Util.d.ts @@ -0,0 +1,8 @@ +export declare type Util = { + /** + * Check to see if a given object is iterable + * @param {Object} obj + * @return {boolean} + */ + isIterable(obj: object): boolean; +}; From 7a779af7b54187263f0d453f92e2bddc25a1d502 Mon Sep 17 00:00:00 2001 From: Claudio Giordano Date: Mon, 7 Dec 2020 00:39:48 +0100 Subject: [PATCH 117/117] Add typescript as dev dependency --- package-lock.json | 6 ++++++ package.json | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index a749b75c6..3140ff81c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2392,6 +2392,12 @@ "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", "dev": true }, + "typescript": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.2.tgz", + "integrity": "sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ==", + "dev": true + }, "uri-js": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", diff --git a/package.json b/package.json index 39a0803eb..26d31e7ed 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "coveralls": "^3.0.2", "mocha": "^5.2.0", "nyc": "^13.1.0", - "@types/node": "^10.12" + "@types/node": "^10.12", + "typescript": "4.1.2" } }