Skip to content

Commit

Permalink
fix: change so that Actor creates untrained skill
Browse files Browse the repository at this point in the history
Previously creating a new TwodsixActor did create an untrained skill,
however creating an Actor does not create an untrained skill. This
fix makes it so that an untrained skill is created in both cases.

Fix xdy#328
  • Loading branch information
jonepatr authored and xdy committed Jan 19, 2021
1 parent f7155b7 commit f69f57f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
10 changes: 1 addition & 9 deletions src/module/entities/TwodsixActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ import {TwodsixDiceRoll} from "../utils/TwodsixDiceRoll";
import TwodsixItem from "./TwodsixItem";

export default class TwodsixActor extends Actor {
public static async create(data:Record<string, unknown>, options?:Record<string, unknown>):Promise<Entity> {
const actor = await super.create(data, options) as TwodsixActor;
if (actor.data.type == "traveller") {
await actor.createUntrainedSkill();
}
return actor;
}

/**
* Augment the basic actor data with additional dynamic data.
*/
Expand Down Expand Up @@ -134,7 +126,7 @@ export default class TwodsixActor extends Actor {
return this.getOwnedItem(this.data.data.untrainedSkill) as TwodsixItem;
}

private async createUntrainedSkill() {
public async createUntrainedSkill(): Promise<void> {
const untrainedSkill = await this.buildUntrainedSkill();
await this.update({"data.untrainedSkill": untrainedSkill._id});
}
Expand Down
7 changes: 7 additions & 0 deletions src/module/hooks/addUntrainedSkill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import TwodsixActor from "../entities/TwodsixActor";

Hooks.on('createActor', async (actor: TwodsixActor) => {
if (actor.data.type == "traveller") {
await actor.createUntrainedSkill();
}
});
8 changes: 0 additions & 8 deletions src/module/hooks/index.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/twodsix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {TwodsixShipSheet} from "./module/sheets/TwodsixShipSheet";
import {TwodsixItemSheet} from "./module/sheets/TwodsixItemSheet";
import registerHandlebarsHelpers from "./module/handlebars";
import {registerSettings} from "./module/settings";
import "./module/hooks/index";
require.context("./module/hooks", false, /\.ts$/).keys().forEach(fileName => {
import("./module/hooks/" + fileName.substring(2));
});
import {rollItemMacro} from "./module/utils/rollItemMacro";

Hooks.once('init', async function () {
Expand Down

0 comments on commit f69f57f

Please sign in to comment.