Skip to content

Commit

Permalink
Removed code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunomiac committed Oct 29, 2023
1 parent 0d897cf commit fc7e67d
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 325 deletions.
37 changes: 36 additions & 1 deletion module/BladesActor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import U from "./core/utilities.js";
import C, { BladesActorType, Tag, Playbook, BladesItemType, ActionTrait, PrereqType, AdvancementPoint, Randomizers, Factor } from "./core/constants.js";
import { BladesItem } from "./documents/BladesItemProxy.js";
import { BladesRollMod } from "./BladesRoll.js";
import BladesPushAlert from "./BladesPushAlert.js";
import { SelectionCategory } from "./BladesDialog.js";
var BladesActorUniqueTags;
Expand Down Expand Up @@ -735,7 +736,41 @@ class BladesActor extends Actor {
parentActor;
get isSubActor() { return this.parentActor !== undefined; }


get rollModsData() {
return BladesRollMod.ParseDocRollMods(this);
}
get rollFactors() {
const factorData = {
[Factor.tier]: {
name: Factor.tier,
display: "Tier",
value: this.getFactorTotal(Factor.tier),
max: this.getFactorTotal(Factor.tier),
baseVal: this.getFactorTotal(Factor.tier),
isActive: true,
isPrimary: true,
isDominant: false,
highFavorsPC: true
},
[Factor.quality]: {
name: Factor.quality,
display: "Quality",
value: this.getFactorTotal(Factor.quality),
max: this.getFactorTotal(Factor.quality),
baseVal: this.getFactorTotal(Factor.quality),
isActive: false,
isPrimary: false,
isDominant: false,
highFavorsPC: true
}
};
return factorData;
}
get rollPrimaryID() { return this.id; }
get rollPrimaryDoc() { return this; }
get rollPrimaryName() { return this.name; }
get rollPrimaryType() { return this.type; }
get rollPrimaryImg() { return this.img; }
get members() {
if (!BladesActor.IsType(this, BladesActorType.crew)) {
return [];
Expand Down
39 changes: 1 addition & 38 deletions module/documents/actors/BladesCrew.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
|* ▌████░░░░ ░░░░█████▐ *|
\* ****▌███████████████████████████████████████████████████████████████████████████▐**** */

import { BladesItemType, Factor } from "../../core/constants.js";
import { BladesItemType } from "../../core/constants.js";
import BladesActor from "../../BladesActor.js";
import { BladesRollMod } from "../../BladesRoll.js";
class BladesCrew extends BladesActor {

static async create(data, options = {}) {
Expand All @@ -23,42 +22,6 @@ class BladesCrew extends BladesActor {
};
return super.create(data, options);
}
get rollModsData() {
return BladesRollMod.ParseDocRollMods(this);
}
get rollFactors() {
const factorData = {
[Factor.tier]: {
name: Factor.tier,
display: "Tier",
value: this.getFactorTotal(Factor.tier),
max: this.getFactorTotal(Factor.tier),
baseVal: this.getFactorTotal(Factor.tier),
isActive: true,
isPrimary: true,
isDominant: false,
highFavorsPC: true
},
[Factor.quality]: {
name: Factor.quality,
display: "Quality",
value: this.getFactorTotal(Factor.quality),
max: this.getFactorTotal(Factor.quality),
baseVal: this.getFactorTotal(Factor.quality),
isActive: false,
isPrimary: false,
isDominant: false,
highFavorsPC: true
}
};
return factorData;
}

get rollPrimaryID() { return this.id; }
get rollPrimaryDoc() { return this; }
get rollPrimaryName() { return this.name; }
get rollPrimaryType() { return this.type; }
get rollPrimaryImg() { return this.img; }

get rollParticipantID() { return this.id; }
get rollParticipantDoc() { return this; }
Expand Down
28 changes: 0 additions & 28 deletions module/documents/actors/BladesFaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,8 @@
|* ▌████░░░░ ░░░░█████▐ *|
\* ****▌███████████████████████████████████████████████████████████████████████████▐**** */

import { Factor } from "../../core/constants.js";
import BladesActor from "../../BladesActor.js";
class BladesFaction extends BladesActor {
get rollFactors() {
const factorData = {
[Factor.tier]: {
name: Factor.tier,
display: "Tier",
value: this.getFactorTotal(Factor.tier),
max: this.getFactorTotal(Factor.tier),
baseVal: this.getFactorTotal(Factor.tier),
isActive: true,
isPrimary: true,
isDominant: false,
highFavorsPC: true
},
[Factor.quality]: {
name: Factor.quality,
display: "Quality",
value: this.getFactorTotal(Factor.quality),
max: this.getFactorTotal(Factor.quality),
baseVal: this.getFactorTotal(Factor.quality),
isActive: false,
isPrimary: false,
isDominant: false,
highFavorsPC: true
}
};
return factorData;
}

get rollOppID() { return this.id; }
get rollOppDoc() { return this; }
Expand Down
73 changes: 24 additions & 49 deletions module/documents/actors/BladesNPC.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,34 @@
|* ▌████░░░░ ░░░░█████▐ *|
\* ****▌███████████████████████████████████████████████████████████████████████████▐**** */

import { BladesActorType, Factor } from "../../core/constants.js";
import { Factor } from "../../core/constants.js";
import BladesActor from "../../BladesActor.js";
class BladesNPC extends BladesActor {
get rollFactors() {
const factorData = {
[Factor.tier]: {
name: Factor.tier,
display: "Tier",
value: this.getFactorTotal(Factor.tier),
max: this.getFactorTotal(Factor.tier),
baseVal: this.getFactorTotal(Factor.tier),
isActive: true,
isPrimary: true,
isDominant: false,
highFavorsPC: true
},
[Factor.quality]: {
name: Factor.quality,
display: "Quality",
value: this.getFactorTotal(Factor.quality),
max: this.getFactorTotal(Factor.quality),
baseVal: this.getFactorTotal(Factor.quality),
isActive: false,
isPrimary: false,
isDominant: false,
highFavorsPC: true
}
const factorData = super.rollFactors;
factorData[Factor.scale] = {
name: Factor.scale,
display: "Scale",
value: this.getFactorTotal(Factor.scale),
max: this.getFactorTotal(Factor.scale),
baseVal: this.getFactorTotal(Factor.scale),
cssClasses: "factor-grey",
isActive: false,
isPrimary: false,
isDominant: false,
highFavorsPC: true
};
factorData[Factor.magnitude] = {
name: Factor.magnitude,
display: "Magnitude",
value: this.getFactorTotal(Factor.magnitude),
max: this.getFactorTotal(Factor.magnitude),
baseVal: this.getFactorTotal(Factor.magnitude),
isActive: false,
isPrimary: false,
isDominant: false,
highFavorsPC: true
};
if (BladesActor.IsType(this, BladesActorType.npc)) {
factorData[Factor.scale] = {
name: Factor.scale,
display: "Scale",
value: this.getFactorTotal(Factor.scale),
max: this.getFactorTotal(Factor.scale),
baseVal: this.getFactorTotal(Factor.scale),
cssClasses: "factor-grey",
isActive: false,
isPrimary: false,
isDominant: false,
highFavorsPC: true
};
factorData[Factor.magnitude] = {
name: Factor.magnitude,
display: "Magnitude",
value: this.getFactorTotal(Factor.magnitude),
max: this.getFactorTotal(Factor.magnitude),
baseVal: this.getFactorTotal(Factor.magnitude),
isActive: false,
isPrimary: false,
isDominant: false,
highFavorsPC: true
};
}
return factorData;
}

Expand Down
38 changes: 3 additions & 35 deletions module/documents/actors/BladesPC.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
|* ▌████░░░░ ░░░░█████▐ *|
\* ****▌███████████████████████████████████████████████████████████████████████████▐**** */

import C, { AttributeTrait, Harm, BladesActorType, BladesItemType, Tag, RollModSection, Factor, RollModStatus } from "../../core/constants.js";
import C, { AttributeTrait, Harm, BladesActorType, BladesItemType, Tag, RollModSection, RollModStatus } from "../../core/constants.js";
import U from "../../core/utilities.js";
import { BladesActor } from "../BladesActorProxy.js";
import { BladesItem } from "../BladesItemProxy.js";
import { BladesRollMod } from "../../BladesRoll.js";
class BladesPC extends BladesActor {

static IsType(doc) {
Expand Down Expand Up @@ -202,40 +201,9 @@ class BladesPC extends BladesActor {
}
await this.update({ "system.stash.value": Math.min(this.system.stash.value + amount, this.system.stash.max) });
}
get rollFactors() {
const factorData = {
[Factor.tier]: {
name: Factor.tier,
display: "Tier",
value: this.getFactorTotal(Factor.tier),
max: this.getFactorTotal(Factor.tier),
baseVal: this.getFactorTotal(Factor.tier),
isActive: true,
isPrimary: true,
isDominant: false,
highFavorsPC: true
},
[Factor.quality]: {
name: Factor.quality,
display: "Quality",
value: this.getFactorTotal(Factor.quality),
max: this.getFactorTotal(Factor.quality),
baseVal: this.getFactorTotal(Factor.quality),
isActive: false,
isPrimary: false,
isDominant: false,
highFavorsPC: true
}
};
return factorData;
}
get rollPrimaryID() { return this.id; }
get rollPrimaryDoc() { return this; }
get rollPrimaryName() { return this.name; }
get rollPrimaryType() { return this.type; }
get rollPrimaryImg() { return this.img; }

get rollModsData() {
const rollModsData = BladesRollMod.ParseDocRollMods(this);
const rollModsData = super.rollModsData;
[
[/1d/, RollModSection.roll],
[/Less Effect/, RollModSection.effect]
Expand Down
47 changes: 47 additions & 0 deletions ts/BladesActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import C, {BladesActorType, Tag, Playbook, BladesItemType, AttributeTrait, Actio
import {BladesPC, BladesCrew, BladesNPC, BladesFaction} from "./documents/BladesActorProxy";
import {BladesItem} from "./documents/BladesItemProxy";

import {BladesRollMod} from "./BladesRoll";
import BladesPushAlert from "./BladesPushAlert";
import {SelectionCategory} from "./BladesDialog";

Expand Down Expand Up @@ -852,6 +853,52 @@ class BladesActor extends Actor implements BladesDocument<Actor> {

// #endregion

// #region BladesRoll Implementation
get rollModsData(): BladesRoll.RollModData[] {
return BladesRollMod.ParseDocRollMods(this);
}

get rollFactors(): Partial<Record<Factor, BladesRoll.FactorData>> {
const factorData: Partial<Record<Factor, BladesRoll.FactorData>> = {
[Factor.tier]: {
name: Factor.tier,
display: "Tier",
value: this.getFactorTotal(Factor.tier),
max: this.getFactorTotal(Factor.tier),
baseVal: this.getFactorTotal(Factor.tier),
isActive: true,
isPrimary: true,
isDominant: false,
highFavorsPC: true
},
[Factor.quality]: {
name: Factor.quality,
display: "Quality",
value: this.getFactorTotal(Factor.quality),
max: this.getFactorTotal(Factor.quality),
baseVal: this.getFactorTotal(Factor.quality),
isActive: false,
isPrimary: false,
isDominant: false,
highFavorsPC: true
}
};

return factorData;
}

// #region BladesRoll.PrimaryDoc Implementation

get rollPrimaryID() { return this.id; }

get rollPrimaryDoc() { return this; }

get rollPrimaryName() { return this.name; }

get rollPrimaryType() { return this.type; }

get rollPrimaryImg() { return this.img; }

// #region BladesCrew Implementation ~

get members(): BladesPC[] {
Expand Down
Loading

0 comments on commit fc7e67d

Please sign in to comment.