Skip to content

Commit

Permalink
fix: Hopefully this should fix the issue with disappearing item skill…
Browse files Browse the repository at this point in the history
…s and skill modifiers. It also makes it less likely that future migrations mess things up.
  • Loading branch information
xdy committed Sep 19, 2020
1 parent c19ae85 commit 3334e23
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@types/webpack-env": "^1.15.3",
"@typescript-eslint/eslint-plugin": "^4.1.1",
"@typescript-eslint/parser": "^4.1.1",
"compression-webpack-plugin": "^6.0.1",
"compression-webpack-plugin": "^6.0.2",
"copy-webpack-plugin": "^6.1.1",
"css-loader": "^4.2.1",
"eslint": "^7.9.0",
Expand All @@ -42,9 +42,9 @@
"semantic-release": "^17.1.2",
"source-map-loader": "^1.1.0",
"style-loader": "^1.2.1",
"ts-loader": "^8.0.2",
"ts-loader": "^8.0.4",
"ts-node": "^9.0.0",
"typescript": "^4.0.2",
"typescript": "^4.0.3",
"url-loader": "^4.1.0",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12",
Expand Down
19 changes: 13 additions & 6 deletions src/module/hooks/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@ import {Migration} from "../migration";
import compareVersions from "compare-versions";


export function before(worldVersion, MIGRATIONS_IMPLEMENTED:string) {
return compareVersions(worldVersion, MIGRATIONS_IMPLEMENTED) === -1;
}

Hooks.once("ready", async function () {
// Determine whether a system migration is required and feasible

const MIGRATIONS_IMPLEMENTED = "0.6.1";
let currentVersion = null;
const systemVersion = game.system.data.version;
let worldVersion = null;
if (game.settings.settings.has("twodsix.systemMigrationVersion")) {
currentVersion = await game.settings.get("twodsix", "systemMigrationVersion");
if (currentVersion == "null") {
currentVersion = null;
worldVersion = await game.settings.get("twodsix", "systemMigrationVersion");
if (worldVersion == "null" || worldVersion == "") {
worldVersion = null;
}
}
const needMigration = currentVersion === null || currentVersion === "" || compareVersions(currentVersion, game.system.data.version);

const needMigration = worldVersion === null || compareVersions(worldVersion, systemVersion) === -1;

// Perform the migration
if (needMigration && game.user.isGM) {
if (!currentVersion || currentVersion < MIGRATIONS_IMPLEMENTED) {
if (!worldVersion || before(worldVersion, MIGRATIONS_IMPLEMENTED)) {
ui.notifications.error(`Your world data is from a Twodsix system version before migrations were implemented (in 0.6.1). This is most likely not a problem if you have used the system recently, but errors may occur.`, {permanent: true});
}
await Migration.migrateWorld();
Expand Down
19 changes: 16 additions & 3 deletions src/module/migration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {TwodsixItemData} from "./entities/TwodsixItem";
import {before} from "./hooks/ready";

//TODO Move all types to a better place
export type UpdateData = {
Expand All @@ -14,7 +15,7 @@ export class Migration {
const actorData = actor.data;
await this.migrateActorItems(actorData, systemMigrationVersion, actor);

if (systemMigrationVersion < "0.6.20") {
if (before(systemMigrationVersion, "0.6.20")) {
updateData['data.hits.value'] = 0;
updateData['data.hits.min'] = 0;
updateData['data.hits.max'] = 0;
Expand All @@ -41,14 +42,26 @@ export class Migration {
private static async migrateItemData(item:TwodsixItemData, systemMigrationVersion:string):Promise<UpdateData> {
const updateData:UpdateData = <UpdateData>{};

if (systemMigrationVersion < "0.6.9") {
if (before(systemMigrationVersion, "0.6.9")) {
updateData['data.name'] = item.name;
}

if (systemMigrationVersion < "0.6.15") {
if (before(systemMigrationVersion, "0.6.15")) {
updateData['data.skillModifier'] = 0;
}

if (before(systemMigrationVersion, "0.6.22")) {
if (item.type != 'skills') {
if (!item.data.skill) {
updateData['data.skill'] = "";
}
if (!item.data.skillModifier) {
updateData['data.skillModifier'] = 0;
}
}
}


return updateData;
}

Expand Down
3 changes: 2 additions & 1 deletion static/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@
"equipped": {
"weight": 0
},
"skillModifier": 0
"skillModifier": 0,
"skill": ""
}
},
"equipment": {
Expand Down

0 comments on commit 3334e23

Please sign in to comment.