Skip to content

Commit

Permalink
Merge pull request RanvierMUD#17 from Ranvier-TS/use-record-not-objec…
Browse files Browse the repository at this point in the history
…t-qgoal

Avoid using object type
  • Loading branch information
seanohue authored Jun 9, 2021
2 parents 1268a6a + f63593e commit 8aacd73
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Quest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class Quest extends EventEmitter {
}

hydrate() {
(this.state as ISerializedQuestDef[]).forEach((goalState, i: number) => {
(this.state as ISerializedQuestGoal[]).forEach((goalState, i: number) => {
this.goals[i].hydrate(goalState.state);
});
}
Expand Down
15 changes: 6 additions & 9 deletions src/QuestGoal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface IQuestGoalDef {
}

export interface ISerializedQuestGoal {
state: object;
state: Record<string, unknown>;
progress: {
percent: number;
display: string;
Expand All @@ -27,10 +27,10 @@ export interface IQuestGoalConfig {
* create new quest goals for quests
* @extends EventEmitter
*/
export class QuestGoal extends EventEmitter {
export class QuestGoal<TState = Record<string, unknown>> extends EventEmitter {
config: IQuestGoalConfig;
quest: Quest;
state: object;
state: Partial<TState>;
player: Player;
/**
* @param {Quest} quest Quest this goal is for
Expand All @@ -51,10 +51,7 @@ export class QuestGoal extends EventEmitter {
this.player = player;
}

/**
* @return {{ percent: number, display: string}}
*/
getProgress() {
getProgress(): { percent: number, display: string} {
return {
percent: 0,
display:
Expand All @@ -69,13 +66,13 @@ export class QuestGoal extends EventEmitter {

serialize(): ISerializedQuestGoal {
return {
state: this.state,
state: this.state as Record<string, unknown>,
progress: this.getProgress(),
config: this.config,
};
}

hydrate(state: object) {
hydrate(state: TState) {
this.state = state;
}
}
4 changes: 2 additions & 2 deletions src/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ export class Room extends GameEntity {
*
* @return {Array<{ id: string, direction: string, inferred: boolean, room: Room= }>}
*/
getExits() {
const exits = JSON.parse(JSON.stringify(this.exits)).map((exit: IExit) => {
getExits(): IExit[] {
const exits: IExit[] = JSON.parse(JSON.stringify(this.exits)).map((exit: IExit) => {
exit.inferred = false;
return exit;
});
Expand Down

0 comments on commit 8aacd73

Please sign in to comment.