Skip to content

Commit

Permalink
closes #70
Browse files Browse the repository at this point in the history
  • Loading branch information
Muttley committed May 31, 2024
1 parent a50fc2b commit 482f60f
Show file tree
Hide file tree
Showing 31 changed files with 810 additions and 519 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
- [#75] Error in char sheet talent listing text enrichments used in description

### Chores
- [#67] Merge Portuguese/Brazilian translation updates from Crowdin
- [#72] Merge French and Portuguese/Brazilian translation updates from Crowdin
- [#78] Merge Spanish and Portuguese/Brazilian translation updates from Crowdin
- [#79] Merge Portuguese/Brazilian translation updates from Crowdin
- [#67] Merge new Portuguese/Brazilian translation updates from Crowdin
- [#72] Merge new French and Portuguese/Brazilian translation updates from Crowdin
- [#78] Merge new Spanish and Portuguese/Brazilian translation updates from Crowdin
- [#79] Merge new Portuguese/Brazilian translation updates from Crowdin
- [#87] Unable to alter max momentum setting if you reduce it to zero

*Many thanks to **lozanoje** for contributing code and translations included in this build*

Expand Down
102 changes: 72 additions & 30 deletions system/src/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,36 @@ AC2D20.DAMAGE_EFFECTS = {
vicious: "AC2D20.WEAPONS.damageEffect.vicious",
};

AC2D20.VEHICLE_QUALITIES = {
cargo_x: "AC2D20.VEHICLES.QUALITIES.cargo_x",
cumbersome: "AC2D20.VEHICLES.QUALITIES.cumbersome",
enclosed: "AC2D20.VEHICLES.QUALITIES.enclosed",
exposed: "AC2D20.VEHICLES.QUALITIES.exposed",
high_performance: "AC2D20.VEHICLES.QUALITIES.high_performance",
single_seat: "AC2D20.VEHICLES.QUALITIES.single_seat",
tough_x: "AC2D20.VEHICLES.QUALITIES.tough_x",
};

AC2D20.WEAPON_QUALITIES = {
accurate: "AC2D20.WEAPONS.weaponQuality.accurate",
bane: "AC2D20.WEAPONS.weaponQuality.bane",
close_quarters: "AC2D20.WEAPONS.weaponQuality.close_quarters",
cumbersome: "AC2D20.WEAPONS.weaponQuality.cumbersome",
debilitating: "AC2D20.WEAPONS.weaponQuality.debilitating",
escalation: "AC2D20.WEAPONS.weaponQuality.escalation",
giant_killer: "AC2D20.WEAPONS.weaponQuality.giant_killer",
heavy: "AC2D20.WEAPONS.weaponQuality.heavy",
hidden: "AC2D20.WEAPONS.weaponQuality.hidden",
hunger: "AC2D20.WEAPONS.weaponQuality.hunger",
inaccurate: "AC2D20.WEAPONS.weaponQuality.inaccurate",
indirect: "AC2D20.WEAPONS.weaponQuality.indirect",
munition: "AC2D20.WEAPONS.weaponQuality.munition",
parrying: "AC2D20.WEAPONS.weaponQuality.parrying",
reliable: "AC2D20.WEAPONS.weaponQuality.reliable",
subtle: "AC2D20.WEAPONS.weaponQuality.subtle",
unreliable: "AC2D20.WEAPONS.weaponQuality.unreliable",
};

AC2D20.WEAPONS = {
range: {
reach: "AC2D20.RANGE.reach",
Expand Down Expand Up @@ -77,37 +107,8 @@ AC2D20.spellcastingTypes = {
dabbler: "dabbler",
};

export async function buildSkillTranslations() {
CONFIG.AC2D20.SKILL_NAMES = {};

const skills = await ac2d20.utils.getSkillsCompendium().getDocuments();

for (const skill of skills) {
// Get the localized name of a skill, if there is no
// localization then it is likely a custom skill, in which
// case we will just use it's original name
//
const nameKey = `AC2D20.SKILL.${skill.name.toUpperCase()}`;
let localizedName = game.i18n.localize(nameKey);

if (localizedName === nameKey) localizedName = skill.name;

CONFIG.AC2D20.SKILL_NAMES[nameKey] = localizedName;
}
}

export async function generateEnrichedTooltips() {
// CONFIG.AC2D20.WEAPON_QUALITY_TOOLTIPS = {};
// CONFIG.AC2D20.WEAPON_QUALITY_HAS_RANK = {};
// for (const key in CONFIG.AC2D20.WEAPON_QUALITIES) {
// CONFIG.AC2D20.WEAPON_QUALITY_TOOLTIPS[key] = await TextEditor.enrichHTML(
// game.i18n.localize(
// `AC2D20.TOOLTIPS.WeaponQuality.${key}`
// )
// );
// CONFIG.AC2D20.WEAPON_QUALITY_HAS_RANK[key] = key.endsWith("_x");
// }

// Damage Effects
CONFIG.AC2D20.DAMAGE_EFFECT_HAS_RANK = {};
CONFIG.AC2D20.DAMAGE_EFFECT_TOOLTIPS = [];
for (const key in CONFIG.AC2D20.DAMAGE_EFFECTS) {
Expand All @@ -118,4 +119,45 @@ export async function generateEnrichedTooltips() {
);
CONFIG.AC2D20.DAMAGE_EFFECT_HAS_RANK[key] = key.endsWith("_x");
}

// Vehicle Qualities
CONFIG.AC2D20.VEHICLE_QUALITY_HAS_RANK = {};
CONFIG.AC2D20.VEHICLE_QUALITY_TOOLTIPS = [];
for (const key in CONFIG.AC2D20.VEHICLE_QUALITIES) {
CONFIG.AC2D20.VEHICLE_QUALITY_TOOLTIPS[key] = await TextEditor.enrichHTML(
game.i18n.localize(
`AC2D20.Tooltips.VehicleQuality.${key}`
)
);
CONFIG.AC2D20.VEHICLE_QUALITY_HAS_RANK[key] = key.endsWith("_x");
}

// Weapon Qualities
CONFIG.AC2D20.WEAPON_QUALITY_TOOLTIPS = {};
for (const key in CONFIG.AC2D20.WEAPON_QUALITIES) {
CONFIG.AC2D20.WEAPON_QUALITY_TOOLTIPS[key] = await TextEditor.enrichHTML(
game.i18n.localize(
`AC2D20.Tooltips.WeaponQuality.${key}`
)
);
}
}

export async function prepareSkills() {
const skillPackName = game.settings.get("ac2d20", "compendium-skills");

let packSkills = await game.packs.get(skillPackName).getDocuments();

let _skills = [];

packSkills.forEach(s => {

_skills.push({
focuses: s.system.focuses.map(f => f.title),
key: s.name,
label: game.i18n.localize(`AC2D20.SKILL.${s.name.toUpperCase()}`),
});
});

CONFIG.AC2D20.SKILLS = _skills.sort((a, b) => a.key.localeCompare(b.key));
}
6 changes: 0 additions & 6 deletions system/src/documents/ACItem.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,4 @@ export default class ACItem extends Item {
ChatMessage.create(chatData);
}


async updateFocuses(_focuses) {
let updatedItem = { "_id": this.id, "system.focuses": _focuses };
await this.update(updatedItem);
}

}
39 changes: 39 additions & 0 deletions system/src/handlebars.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,41 @@ export const registerHandlebarsHelpers = function() {
return listString;
});

Handlebars.registerHelper("listWeaponQualities", function(qualities) {
const elements = [];

for (const key in qualities) {
if (!CONFIG.AC2D20.WEAPON_QUALITIES.hasOwnProperty(key)) continue;

const effect = qualities[key];

if (!effect.value) continue;

let qualityName = CONFIG.AC2D20.WEAPON_QUALITIES[key];

const tooltip = CONFIG.AC2D20.WEAPON_QUALITY_TOOLTIPS[key];

const resultHtml = document.createElement("span");
resultHtml.classList.add("quality", "hover");
resultHtml.dataset.key = key;
resultHtml.dataset.tooltip = tooltip;
resultHtml.innerHTML = qualityName;

elements.push(resultHtml.outerHTML);
}

let listString = "";

if (elements.length > 0) {
listString = elements.join(", ");
}
else {
listString = "—";
}

return listString;
});

Handlebars.registerHelper("math", function(lvalue, operator, rvalue, options) {
lvalue = parseFloat(lvalue);
rvalue = parseFloat(rvalue);
Expand All @@ -125,11 +160,15 @@ export const registerHandlebarsHelpers = function() {

Handlebars.registerHelper("getSkillFocusList", function(key) {
if (key === "") return [];

const skill = CONFIG.AC2D20.SKILLS.find(s => s.key === key);

const focuses = {};

for (const focus of skill.focuses) {
focuses[focus] = ac2d20.utils.getLocalizedFocusName(focus);
}

return focuses;
});

Expand Down
48 changes: 1 addition & 47 deletions system/src/hooks/readyHook.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { prepareSkills } from "../config.mjs";
import ACMigrationRunner from "../migrations/ACMigrationRunner.mjs";

export const readyHook = {
Expand All @@ -12,55 +13,8 @@ export const readyHook = {
}

prepareSkills();
prepareTooltips();

ac2d20.utils.showNewReleaseNotes();
});
},
};

async function prepareSkills() {
const skillPackName = game.settings.get("ac2d20", "compendium-skills");

let packSkills = await game.packs.get(skillPackName).getDocuments();

let _skills = [];

packSkills.forEach(s => {

_skills.push({
focuses: s.system.focuses.map(f => f.title),
key: s.name,
label: game.i18n.localize(`AC2D20.SKILL.${s.name.toUpperCase()}`),
});
});

CONFIG.AC2D20.SKILLS = _skills.sort((a, b) => a.key.localeCompare(b.key));
}

async function prepareTooltips() {
const listLocation = await game.settings.get("ac2d20", "hoversJsonLocation");

const jsonFile = await fetch(listLocation);

const content = await jsonFile.json();

CONFIG.AC2D20.WEAPONS.effects = content.effects;
CONFIG.AC2D20.WEAPONS.qualities = content.qualities;
CONFIG.AC2D20.WEAPONS.vehiclesqualities = content.vehiclesqualities;

for await (const key of Object.keys(content.effects)) {
let qEnriched = await TextEditor.enrichHTML(content.effects[key], {async: true});
content.effects[key] = qEnriched.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#039;");
}

for await (const key of Object.keys(content.qualities)) {
let qEnriched = await TextEditor.enrichHTML(content.qualities[key], {async: true});
content.qualities[key] = qEnriched.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#039;");
}

for await (const key of Object.keys(content.vehiclesqualities)) {
let qEnriched = await TextEditor.enrichHTML(content.vehiclesqualities[key], {async: true});
content.vehiclesqualities[key] = qEnriched.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#039;");
}
}
2 changes: 0 additions & 2 deletions system/src/migrations/updates/Update_240526_1.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { ACUpdateBase } from "../ACUpdateBase.mjs";
export default class Update_240526_1 extends ACUpdateBase {
static version = 240526.1;

// Update the actor to the latest schema version.
//
async updateActor(actorData) {
if (actorData.type !== "vehicle") return;

Expand Down
2 changes: 0 additions & 2 deletions system/src/migrations/updates/Update_240526_2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { ACUpdateBase } from "../ACUpdateBase.mjs";
export default class Update_240526_2 extends ACUpdateBase {
static version = 240526.2;

// Update the actor to the latest schema version.
//
async updateActor(actorData) {
// Get rid of ancient legacy data that's no longer needed
const updateData = {
Expand Down
2 changes: 0 additions & 2 deletions system/src/migrations/updates/Update_240527_1.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { ACUpdateBase } from "../ACUpdateBase.mjs";
export default class Update_240527_1 extends ACUpdateBase {
static version = 240527.1;

// Update the actor to the latest schema version.
//
async updateActor(actorData) {
const truthsText = actorData.system.truthsText ?? "";
if (truthsText === "") return;
Expand Down
2 changes: 1 addition & 1 deletion system/src/migrations/updates/Update_240529_1.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class Update_240529_1 extends ACUpdateBase {
const value = itemData.system.effect[key].value;

let rank = itemData.system.effect[key].rank;
rank = rank >= 0 ? rank : 0;
rank = rank && rank >= 0 ? rank : 0;

if (rename_effects.includes(key)) {
updateData[`system.effect.-=${key}`] = null;
Expand Down
31 changes: 31 additions & 0 deletions system/src/migrations/updates/Update_240530_1.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ACUpdateBase } from "../ACUpdateBase.mjs";

export default class Update_240530_1 extends ACUpdateBase {
static version = 240530.1;

async updateItem(itemData, actorData) {
if (itemData.type !== "weapon") return;

const updateData = {};

for (const key in itemData.system.qualities) {
const value = itemData.system.qualities[key].value;

if (key === "closeQuarters") {
updateData[`system.qualities.-=${key}`] = null;
updateData["system.qualities.close_quarters.value"] = value;
}
else if (key === "giant-killer") {
updateData[`system.qualities.-=${key}`] = null;
updateData["system.qualities.giant_killer.value"] = value;
}
else {
updateData[`system.qualities.${key}.-=description`] = null;
updateData[`system.qualities.${key}.-=label`] = null;
}
}

return updateData;
}

}
41 changes: 41 additions & 0 deletions system/src/migrations/updates/Update_240531_1.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { ACUpdateBase } from "../ACUpdateBase.mjs";

export default class Update_240531_1 extends ACUpdateBase {
static version = 240531.1;

async updateActor(actorData) {
if (actorData.type !== "vehicle") return;

const updateData = {};

for (const key in actorData.system.qualities) {
const value = actorData.system.qualities[key].value;

let rank = actorData.system.qualities[key].rank;
rank = rank && rank >= 0 ? rank : 0;

if (key === "cargo") {
updateData[`system.qualities.-=${key}`] = null;
updateData["system.qualities.cargo_x.rank"] = rank;
updateData["system.qualities.cargo_x.value"] = value;
}
else if (key === "highPerformance") {
updateData[`system.qualities.-=${key}`] = null;
updateData["system.qualities.high_performance.rank"] = rank;
updateData["system.qualities.high_performance.value"] = value;
}
else if (key === "singleSeat") {
updateData[`system.qualities.-=${key}`] = null;
updateData["system.qualities.single_seat.rank"] = rank;
updateData["system.qualities.single_seat.value"] = value;
}
else if (key === "tough") {
updateData[`system.qualities.-=${key}`] = null;
updateData["system.qualities.tough_x.rank"] = rank;
updateData["system.qualities.tough_x.value"] = value;
}
}

return updateData;
}
}
2 changes: 2 additions & 0 deletions system/src/migrations/updates/_module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export {default as Update_240526_1} from "./Update_240526_1.mjs";
export {default as Update_240526_2} from "./Update_240526_2.mjs";
export {default as Update_240527_1} from "./Update_240527_1.mjs";
export {default as Update_240529_1} from "./Update_240529_1.mjs";
export {default as Update_240530_1} from "./Update_240530_1.mjs";
export {default as Update_240531_1} from "./Update_240531_1.mjs";
Loading

0 comments on commit 482f60f

Please sign in to comment.