Skip to content

Commit

Permalink
fixed typing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonepatr committed Jan 3, 2022
1 parent a9c3d66 commit 3d15245
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
14 changes: 5 additions & 9 deletions src/migrations/2021_12_29_05_08_25_active-effects-for-traits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ async function applyActiveEffects(p, actor) {
await p;
return Promise.all(actor.items.filter(item => item.type === "trait").map(async item => {
if (!item.data.data.effectId) {
//@ts-ignore
const effects = await actor.createEmbeddedDocuments("ActiveEffect", [{
origin: item.uuid,
icon: "systems/twodsix/assets/icons/science.svg"
Expand All @@ -14,12 +13,9 @@ async function applyActiveEffects(p, actor) {
}

export async function migrate(): Promise<void> {
const tokenActor = game.scenes
//@ts-ignore
.reduce((memo, scene) => memo.concat(scene.tokens.contents), [])
.filter(s => s.actor.type === "traveller" && !s.data.actorLink)
.map(token => token._actor);
//@ts-ignore
await game.actors.filter(actor => actor.type === "traveller").reduce(applyActiveEffects, Promise.resolve());
await tokenActor.reduce(applyActiveEffects, Promise.resolve());
const tokenActor = game.scenes?.reduce((memo: TokenDocument[], scene: Scene) => memo.concat(scene.tokens.contents), [])
.filter((token: TokenDocument) => token.actor?.type === "traveller" && !token.data.actorLink)
.map((token: TokenDocument) => token.actor);
await game.actors?.filter(actor => actor.type === "traveller").reduce(applyActiveEffects, Promise.resolve());
await tokenActor?.reduce(applyActiveEffects, Promise.resolve());
}
9 changes: 5 additions & 4 deletions src/module/entities/TwodsixActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Weapon = dataTwodsix.Weapon;
import Gear = dataTwodsix.Gear;
import Traveller = dataTwodsix.Traveller;
import Skills = dataTwodsix.Skills;
import Trait = dataTwodsix.Trait;
import Characteristic = dataTwodsix.Characteristic;

export default class TwodsixActor extends Actor {
Expand Down Expand Up @@ -52,17 +53,17 @@ export default class TwodsixActor extends Actor {
}
}

_onUpdateEmbeddedDocuments(embeddedName, documents, result, options, userId) {
_onUpdateEmbeddedDocuments(embeddedName:string, documents): void {
if (embeddedName === "ActiveEffect") {
documents.forEach(element => {
const item = element.parent.items.find(itm => itm.data.data.effectId === element.id);
(<ActiveEffect[]>documents).forEach((element:ActiveEffect) => {
const item = <TwodsixItem>(<TwodsixActor>element?.parent)?.items.find((itm:TwodsixItem) => (<Trait>itm.data.data).effectId === element.id);
item.update({"data.changes": element.data.changes});
});
}
this.render();
}

protected async _onCreate(data, options, user) {
protected async _onCreate(): Promise<void> {
switch (this.data.type) {
case "traveller":
await this.createUntrainedSkill();
Expand Down
6 changes: 3 additions & 3 deletions src/module/sheets/TwodsixItemSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class TwodsixItemSheet extends AbstractTwodsixItemSheet {
}
}

private _onCreateChange(event:Event): void {
private _onCreateChange(): void {
const changes = (<Trait>this.item.data.data).changes ?? [];
this.item.update({"data.changes": changes.concat({key: "", value: "", mode: 0})});
}
Expand All @@ -135,11 +135,11 @@ export class TwodsixItemSheet extends AbstractTwodsixItemSheet {
}
}

private _onEditConsumable(event): void {
private _onEditConsumable(event:Event): void {
this.getConsumable(event)?.sheet?.render(true);
}

private async _onDeleteConsumable(event): Promise<void> {
private async _onDeleteConsumable(event:Event): Promise<void> {
const consumable = this.getConsumable(event);
if (!consumable) {
(<TwodsixItem>this.item).removeConsumable(""); //TODO Should have await?
Expand Down
1 change: 1 addition & 0 deletions src/types/template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ declare namespace dataTwodsix {
reference: string;
key: string;
changes: TraitChange[];
effectId: string;
}

export interface Weapon extends GearTemplate {
Expand Down

0 comments on commit 3d15245

Please sign in to comment.