Skip to content

Commit

Permalink
Merge pull request dmdorman#515 from phBalance/phBalance/skill-charac…
Browse files Browse the repository at this point in the history
…teristics-cant-be-changed

Replace item.system.characteristic with item.system.CHARACTERISTIC
  • Loading branch information
phBalance authored Dec 21, 2023
2 parents ce86247 + fbb0ce4 commit c4ddf0a
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 1,261 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Ignore all markdown files
**/*.md

#
# Ignore all json files
**/*.json
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
- Fix crash with Aid and Telekinesis powers during upload. [#474](https://github.com/dmdorman/hero6e-foundryvtt/issues/474)
- Correct general skill roll calculations to be 11 plus levels. [#456](https://github.com/dmdorman/hero6e-foundryvtt/issues/456)
- Improvements to a number of 5e power cost calculations (MP, EC, Forcefield, Teleport, Stretching, Multiform) during upload.
- Characters with incompletely defined adjustment powers will get a warning during upload with a hint on how to fix them.
- Fix HDC uploads when name is missing from HDC file.
- Fix missing display of BACKGROUND an other character information. [#483](https://github.com/dmdorman/hero6e-foundryvtt/issues/483)
- Configuration setting to toggle custom resource bars. Existing worlds will retain custom resource bars, new worlds will default to core FoundryVTT resource bars. The [Bar Brawl](https://foundryvtt.com/packages/barbrawl) module is superior, although requires some configuration. Bugs related to system custom bars still exist. We are likely to deprecate the custom resource bars in this system. [#502](https://github.com/dmdorman/hero6e-foundryvtt/issues/502) [#368](https://github.com/dmdorman/hero6e-foundryvtt/issues/368) [#274](https://github.com/dmdorman/hero6e-foundryvtt/issues/274) [#174](https://github.com/dmdorman/hero6e-foundryvtt/issues/174)
- Skill characteristics can now be changed in game and will update appropriately. [#511](https://github.com/dmdorman/hero6e-foundryvtt/issues/511)
- Lots of behind the scenes work to help improve readability and consistency of the code.

## Version 3.0.52
Expand All @@ -24,7 +26,7 @@
- Fix for power modifiers being ignored (such as reduce endurance).
- Initial support for BOOSTABLE CHARGES. Associated burnout is not implemented. Does not account for reducing the DC increase for powers with advantages. [#432](https://github.com/dmdorman/hero6e-foundryvtt/issues/432)
- Fix for Combat Skill Levels where edit sheet did not allow for changing values.
- Improved range pentaly tags and associated tooltips.
- Improved range penalty tags and associated tooltips.
- Fixed error for cone placement.
- Fixed range penalty when distance is 2 or fewer hexes. [#437](https://github.com/dmdorman/hero6e-foundryvtt/issues/437)
- Improved ALTERNATE COMBAT VALUE upload. [#439](https://github.com/dmdorman/hero6e-foundryvtt/issues/439)
Expand Down
1 change: 0 additions & 1 deletion module/actor/actor-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,6 @@ export class HeroSystemActorSheet extends ActorSheet {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(contents, "text/xml");
await this.actor.uploadFromXml(xmlDoc);
//applyCharacterSheet.bind(this)(xmlDoc)
ui.notifications.info(`${this.actor.name} upload complete`);
}.bind(this);
reader.readAsText(file);
Expand Down
2 changes: 1 addition & 1 deletion module/actor/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ export class HeroSystem6eActor extends Actor {
system: {
XMLID: "PERCEPTION",
ALIAS: "Perception",
CHARACTERISTIC: "int",
CHARACTERISTIC: "INT",
state: "trained",
levels: "0",
},
Expand Down
4 changes: 2 additions & 2 deletions module/herosystem6e.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ Hooks.once("init", async function () {
});

Handlebars.registerHelper("toLowerCase", function (str) {
return str.toLowerCase();
return str?.toLowerCase();
});

Handlebars.registerHelper("toUpperCase", function (str) {
return str.toUpperCase();
return str?.toUpperCase();
});

Handlebars.registerHelper("is_active_segment", function (actives, index) {
Expand Down
9 changes: 0 additions & 9 deletions module/item/item-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,6 @@ export class HeroSystem6eItemSheet extends ItemSheet {
data.effects = this.document.effects;
}

// skillCharacteristics should be lowercase to match CONFIG.HERO.skillCharacteristics.
// Not needed for new uploads, but previous uploads may incorrectly have upperCase version
// and thus the item-skill-sheet.hbs selectOptions won't match, thus defaulting to general.
// Can probably remove at some point.
if (data.system.characteristic) {
data.system.characteristic =
data.system.characteristic.toLowerCase();
}

// Signed OCV and DCV
if (data.system.ocv != undefined) {
data.system.ocv = ("+" + parseInt(data.system.ocv)).replace(
Expand Down
9 changes: 2 additions & 7 deletions module/item/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -2915,8 +2915,7 @@ export class HeroSystem6eItem extends Item {
}

// No Characteristic = no roll (Skill Enhancers for example) except for FINDWEAKNESS
const characteristicBased =
skillData.CHARACTERISTIC || skillData.characteristic;
const characteristicBased = skillData.CHARACTERISTIC;
if (!characteristicBased) {
if (skillData.XMLID === "FINDWEAKNESS") {
// Provide up to 2 tags to explain how the roll was calculated:
Expand Down Expand Up @@ -2971,11 +2970,7 @@ export class HeroSystem6eItem extends Item {
skillData.roll = "10-";
skillData.tags.push({ value: 10, name: "Proficiency" });
} else if (characteristicBased) {
const characteristic = (
skillData.CHARACTERISTIC || skillData.characteristic
).toLowerCase();

skillData.characteristic = characteristic;
const characteristic = skillData.CHARACTERISTIC.toLowerCase();

const baseRollValue =
skillData.CHARACTERISTIC === "GENERAL" ? 11 : 9;
Expand Down
59 changes: 47 additions & 12 deletions module/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { HeroSystem6eItem } from "./item/item.js";
import { getPowerInfo } from "./utility/util.js";
import { createEffects, updateItemSubTypes } from "./utility/upload_hdc.js";

function getAllActorsInGame() {
return [
...game.actors.contents,
...game.scenes.contents
.map((scene) => scene.tokens)
.map((token) => token.actorLink)
.filter((actorLink) => actorLink),
];
}

export async function migrateWorld() {
const lastMigration = game.settings.get(game.system.id, "lastMigration");

Expand Down Expand Up @@ -295,6 +305,7 @@ export async function migrateWorld() {

// if lastMigration < 3.0.53
// Default bar3 to TRUE for existing worlds
// All item's system.characteristic replaced with system.CHARACTERISTIC
if (foundry.utils.isNewerVersion("3.0.53", lastMigration)) {
console.log("bar3");
if (!game.settings.get(game.system.id, "bar3")) {
Expand All @@ -304,25 +315,30 @@ export async function migrateWorld() {
token.object.refresh();
}
}

const queue = getAllActorsInGame();
let dateNow = new Date();

for (const [index, actor] of queue.entries()) {
if (new Date() - dateNow > 4000) {
ui.notifications.info(
`Migrating actor's items to 3.0.53: (${
queue.length - index
} actors remaining)`,
);
dateNow = new Date();
}

await migrate_actor_items_to_3_0_53(actor);
}
}

// Reparse all items (description, cost, etc) on every migration
{
let d = new Date();
let queue = [];
const queue = getAllActorsInGame();

ui.notifications.info(`Migrating actor data`);
for (const actor of game.actors.contents) {
queue.push(actor);
}

for (const scene of game.scenes.contents) {
for (const token of scene.tokens) {
if (!token.actorLink) {
queue.push(token.actor);
}
}
}

while (queue.length > 0) {
if (new Date() - d > 4000) {
Expand Down Expand Up @@ -379,6 +395,25 @@ async function migrateActorCostDescription(actor) {
}
}

async function migrate_actor_items_to_3_0_53(actor) {
for (const item of actor.items) {
// Get rid of item.system.characteristic and replace with
// item.system.CHARACTERISTIC
if (!item.system.CHARACTERISTIC && item.system.characteristic) {
await item.update({
"system.CHARACTERISTIC":
item.system.characteristic.toUpperCase(),
});
}

if (item.system.characteristic) {
await item.update({
"system.-=characteristic": null,
});
}
}
}

async function migrateActor_3_0_35(actor) {
try {
if (!actor) return;
Expand Down
Loading

0 comments on commit c4ddf0a

Please sign in to comment.