Skip to content

Commit

Permalink
Basic Foundry v10 compatibility
Browse files Browse the repository at this point in the history
There will be bugs.
  • Loading branch information
Esrin committed Aug 19, 2022
1 parent 315782d commit 276368f
Show file tree
Hide file tree
Showing 36 changed files with 175 additions and 173 deletions.
2 changes: 1 addition & 1 deletion modules/actors/actor-ffg-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class ActorOptions {
if (!this.options[optionName]) {
this.options[optionName] = { ...options };
}
if (typeof this.data.object.data.flags?.starwarsffg?.config == "undefined") {
if (typeof this.data.object.flags?.starwarsffg?.config == "undefined") {
await this.data.object.setFlag("starwarsffg", "config", {});
}

Expand Down
75 changes: 37 additions & 38 deletions modules/actors/actor-ffg.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export class ActorFFG extends Actor {
* Augment the basic actor data with additional dynamic data.
*/
prepareDerivedData() {
CONFIG.logger.debug(`Preparing Actor Data ${this.data.type}`);
const actorData = this.data;
const data = actorData.data;
const flags = actorData.flags;
CONFIG.logger.debug(`Preparing Actor Data ${this.type}`);
const actor = this;
const data = actor.system;
const flags = actor.flags;

// Make separate methods for each Actor type (character, minion, etc.) to keep
// things organized.
Expand All @@ -40,13 +40,13 @@ export class ActorFFG extends Actor {
});
}
this._prepareSharedData.bind(this);
this._prepareSharedData(actorData);
if (actorData.type === "minion") this._prepareMinionData(actorData);
if (actorData.type === "character") this._prepareCharacterData(actorData);
this._prepareSharedData(actor);
if (actor.type === "minion") this._prepareMinionData(actor);
if (actor.type === "character") this._prepareCharacterData(actor);
}

_prepareSharedData(actorData) {
const data = actorData.data;
const data = actorData.system;
//data.biography = PopoutEditor.replaceRollTags(data.biography, actorData);
data.biography = PopoutEditor.renderDiceImages(data.biography, actorData);

Expand Down Expand Up @@ -90,7 +90,7 @@ export class ActorFFG extends Actor {
* Prepare Minion type specific data
*/
_prepareMinionData(actorData) {
const data = actorData.data;
const data = actorData.system;

// Set Wounds threshold to unit_wounds * quantity to account for minion group health.
data.stats.wounds.max = Math.floor(data.unit_wounds.value * data.quantity.max);
Expand Down Expand Up @@ -183,7 +183,7 @@ export class ActorFFG extends Actor {
* Prepare Character type specific data
*/
_prepareCharacterData(actorData) {
const data = actorData.data;
const data = actorData;

// Build complete talent list.

Expand All @@ -195,14 +195,14 @@ export class ActorFFG extends Actor {
specializations.forEach((element) => {
//go through each list of talent where learned = true

const learnedTalents = Object.keys(element.data.data.talents).filter((key) => element.data.data.talents[key].islearned === true);
const learnedTalents = Object.keys(element.system.talents).filter((key) => element.system.talents[key].islearned === true);

learnedTalents.forEach((talent) => {
const item = JSON.parse(JSON.stringify(element.data.data.talents[talent]));
const item = JSON.parse(JSON.stringify(element.system.talents[talent]));
item.firstSpecialization = element.id;
item.source = [{ type: "specialization", typeLabel: "SWFFG.Specialization", name: element.name, id: element.id }];
if (item.isRanked) {
item.rank = element.data.data.talents[talent]?.rank ? element.data.data.talents[talent].rank : 1;
item.rank = element.system.talents[talent]?.rank ? element.system.talents[talent].rank : 1;
} else {
item.rank = "N/A";
}
Expand All @@ -214,7 +214,7 @@ export class ActorFFG extends Actor {
globalTalentList.push(item);
} else {
globalTalentList[index].source.push({ type: "specialization", typeLabel: "SWFFG.Specialization", name: element.name, id: element.id });
globalTalentList[index].rank += element.data.data.talents[talent]?.rank ? element.data.data.talents[talent].rank : 1;
globalTalentList[index].rank += element.system.talents[talent]?.rank ? element.system.talents[talent].rank : 1;
}
});
});
Expand All @@ -227,21 +227,21 @@ export class ActorFFG extends Actor {
const item = {
name: element.name,
itemId: element.id,
description: element.data?.data?.description,
activation: element.data?.data?.activation?.value,
activationLabel: element.data?.data?.activation?.label,
isRanked: element.data?.data?.ranks?.ranked,
description: element.system?.description,
activation: element.system?.activation?.value,
activationLabel: element.system?.activation?.label,
isRanked: element.system?.ranks?.ranked,
source: [{ type: "talent", typeLabel: "SWFFG.Talent", name: element.name, id: element.id }],
};

if (item.isRanked) {
item.rank = element.data.data.ranks.current;
item.rank = element.system.ranks.current;
} else {
item.rank = "N/A";
}

if (CONFIG.FFG.theme !== "starwars") {
item.tier = parseInt(element.data?.data?.tier, 10);
item.tier = parseInt(element.system?.tier, 10);
}

let index = globalTalentList.findIndex((obj) => {
Expand All @@ -252,9 +252,9 @@ export class ActorFFG extends Actor {
globalTalentList.push(item);
} else {
globalTalentList[index].source.push({ type: "talent", typeLabel: "SWFFG.Talent", name: element.name, id: element.id });
globalTalentList[index].rank += element.data.data.ranks.current;
globalTalentList[index].rank += element.system.ranks.current;
if (CONFIG.FFG.theme !== "starwars") {
globalTalentList[index].tier = Math.abs(parseInt(globalTalentList[index].rank) + (parseInt(element.data?.data?.tier, 10) - 1));
globalTalentList[index].tier = Math.abs(parseInt(globalTalentList[index].rank) + (parseInt(element.system?.tier, 10) - 1));
}
}
});
Expand Down Expand Up @@ -313,30 +313,30 @@ export class ActorFFG extends Actor {
}

_calculateDerivedValues(actorData) {
const data = actorData.data;
const items = actorData.items.map((item) => item.data);
const data = actorData.system;
const items = actorData.items;
var encum = 0;

// Loop through all items
for (let [key, item] of Object.entries(items)) {
try {
// Calculate encumbrance, only if encumbrance value exists
if (item.data?.encumbrance?.adjusted !== undefined || item.data?.encumbrance?.value !== undefined) {
if (item.type === "armour" && item?.data?.equippable?.equipped) {
if (item.system?.encumbrance?.adjusted !== undefined || item.system?.encumbrance?.value !== undefined) {
if (item.type === "armour" && item?.system?.equippable?.equipped) {
const equippedEncumbrance = +item.data.encumbrance.adjusted - 3;
encum += equippedEncumbrance > 0 ? equippedEncumbrance : 0;
} else if (item.type === "armour" || item.type === "weapon" || item.type === "shipweapon") {
let count = 0;
if (item.data?.quantity?.value) {
count = item.data.quantity.value;
if (item.system?.quantity?.value) {
count = item.system.quantity.value;
}
encum += ((item.data?.encumbrance?.adjusted !== undefined) ? item.data?.encumbrance?.adjusted : item.data?.encumbrance?.value) * count;
encum += ((item.system?.encumbrance?.adjusted !== undefined) ? item.system?.encumbrance?.adjusted : item.system?.encumbrance?.value) * count;
} else {
let count = 0;
if (item.data?.quantity?.value) {
count = item.data.quantity.value;
if (item.system?.quantity?.value) {
count = item.system.quantity.value;
}
encum += item.data?.encumbrance?.value * count;
encum += item.system?.encumbrance?.value * count;
}
}
} catch (err) {
Expand Down Expand Up @@ -407,8 +407,7 @@ export class ActorFFG extends Actor {
* @param {string} modifierType
*/
_setModifiers(actorData, properties, name, modifierType) {
const actor = this;
const data = actorData.data;
const data = actorData.system;
const attributes = Object.keys(data.attributes)
.filter((key) =>
Object.keys(properties)
Expand Down Expand Up @@ -505,12 +504,12 @@ export class ActorFFG extends Actor {
* @param {object} actorData
*/
_applyModifiers(actorData) {
const data = actorData.data;
const data = actorData.system;
const isPC = this.hasPlayerOwner;
if (!actorData.modifiers) {
actorData.modifiers = {};
}
const items = actorData.items.map((item) => item.data);
const items = actorData.items;

this._setModifiers.bind(this);

Expand Down Expand Up @@ -634,13 +633,13 @@ export class ActorFFG extends Actor {
}

_applyVehicleModifiers(actorData) {
const data = actorData.data;
const data = actorData.system;
const isPC = this.hasPlayerOwner;
if (!actorData.modifiers) {
actorData.modifiers = {};
}

const items = actorData.items.map((item) => item.data);
const items = actorData.items;

this._setModifiers(actorData, CONFIG.FFG.vehicle_stats, "stats", "Stat");
Object.keys(CONFIG.FFG.vehicle_stats).forEach((k) => {
Expand Down
Loading

0 comments on commit 276368f

Please sign in to comment.