GH-17 Adds Localization migration

- Closes #17
This commit is contained in:
Megastruktur 2020-08-05 14:00:57 +03:00
parent 1c000f216e
commit ec6539d335
6 changed files with 120 additions and 10 deletions

View File

@ -1,5 +1,6 @@
v0.7.5
v1.0
- Adds localization for text (except Items) (megastruktur)
- Adds Rolls mod and styling (dunderjester)
- Added Localization for text (except Items) + Migrations (megastruktur)
- Added Rolls mod and styling (dunderjester)
- Changed the Versioning for easier tracking

View File

@ -5,6 +5,7 @@
*/
// Import Modules
import { registerSystemSettings } from "./settings.js";
import { preloadHandlebarsTemplates } from "./blades-templates.js";
import { bladesRoll, simpleRollPopup } from "./blades-roll.js";
import { BladesHelpers } from "./blades-helpers.js";
@ -13,6 +14,7 @@ import { BladesItem } from "./blades-item.js";
import { BladesItemSheet } from "./blades-item-sheet.js";
import { BladesActorSheet } from "./blades-actor-sheet.js";
import { BladesCrewSheet } from "./blades-crew-sheet.js";
import * as migrations from "./migration.js";
window.BladesHelpers = BladesHelpers;
@ -33,6 +35,9 @@ Hooks.once("init", async function() {
CONFIG.Item.entityClass = BladesItem;
CONFIG.Actor.entityClass = BladesActor;
// Register System Settings
registerSystemSettings();
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet("blades", BladesActorSheet, { types: ["character"], makeDefault: true });
@ -71,8 +76,6 @@ Hooks.once("init", async function() {
});
// Equals handlebar.
// NotEquals handlebar.
Handlebars.registerHelper('noteq', (a, b, options) => {
return (a !== b) ? options.fn(this) : '';
@ -127,6 +130,23 @@ Hooks.once("init", async function() {
});
/**
* Once the entire VTT framework is initialized, check to see if we should perform a data migration
*/
Hooks.once("ready", function() {
// Determine whether a system migration is required
const currentVersion = game.settings.get("bitd", "systemMigrationVersion");
const NEEDS_MIGRATION_VERSION = 1.0;
let needMigration = (currentVersion < NEEDS_MIGRATION_VERSION) || (currentVersion === null);
// Perform the migration
if ( needMigration && game.user.isGM ) {
migrations.migrateWorld();
}
});
/*
* Hooks
*/

76
module/migration.js Normal file
View File

@ -0,0 +1,76 @@
/**
* Perform a system migration for the entire World, applying migrations for Actors, Items, and Compendium packs
* @return {Promise} A Promise which resolves once the migration is completed
*/
export const migrateWorld = async function() {
ui.notifications.info(`Applying BITD Actors migration for version ${game.system.data.version}. Please be patient and do not close your game or shut down your server.`, {permanent: true});
// Migrate World Actors
for ( let a of game.actors.entities ) {
if (a.data.type === 'character') {
try {
const updateData = _migrateActorSkills(a.data);
if ( !isObjectEmpty(updateData) ) {
console.log(`Migrating Actor entity ${a.name}`);
await a.update(updateData, {enforceTypes: false});
}
} catch(err) {
console.error(err);
}
}
}
// Set the migration as complete
game.settings.set("bitd", "systemMigrationVersion", game.system.data.version);
ui.notifications.info(`BITD System Migration to version ${game.system.data.version} completed!`, {permanent: true});
};
/* -------------------------------------------- */
/* -------------------------------------------- */
/* Entity Type Migration Helpers */
/* -------------------------------------------- */
/**
* Migrate the actor skills
* @param {Actor} actor The actor to Update
* @return {Object} The updateData to apply
*/
function _migrateActorSkills(actor) {
let updateData = {}
const attributes = game.system.model.Actor.character.attributes;
for ( let attribute_name of Object.keys(actor.data.attributes || {}) ) {
// Insert attribute label
if (typeof actor.data.attributes[attribute_name].label === 'undefined') {
updateData[`data.attributes.${attribute_name}.label`] = attributes[attribute_name].label;
}
for ( let skill_name of Object.keys(actor.data.attributes[attribute_name]['skills']) ) {
// Insert skill label
// Copy Skill value
if (typeof actor.data.attributes[attribute_name].skills[skill_name].label === 'undefined') {
// Create Label.
updateData[`data.attributes.${attribute_name}.skills.${skill_name}.label`] = attributes[attribute_name].skills[skill_name].label;
// Migrate from skillname = [0]
let skill_tmp = actor.data.attributes[attribute_name].skills[skill_name];
if (Array.isArray(skill_tmp)) {
updateData[`data.attributes.${attribute_name}.skills.${skill_name}.value`] = [skill_tmp[0]];
}
}
}
}
return updateData;
// for ( let k of Object.keys(actor.data.attributes || {}) ) {
// if ( k in b ) updateData[`data.bonuses.${k}`] = b[k];
// else updateData[`data.bonuses.-=${k}`] = null;
// }
}
/* -------------------------------------------- */

13
module/settings.js Normal file
View File

@ -0,0 +1,13 @@
export const registerSystemSettings = function() {
/**
* Track the system version upon which point a migration was last applied
*/
game.settings.register("bitd", "systemMigrationVersion", {
name: "System Migration Version",
scope: "world",
config: false,
type: Number,
default: 0
});
};

View File

@ -2,7 +2,7 @@
"name": "blades-in-the-dark",
"title": "Blades in the Dark",
"description": "Blades in the dark game system.",
"version": "0.7.4",
"version": "1.0",
"minimumCoreVersion": "0.5.3",
"compatibleCoreVersion": "0.7.0",
"templateVersion": 1,
@ -17,8 +17,8 @@
}
],
"url": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/",
"manifest": "https://raw.githubusercontent.com/megastruktur/foundryvtt-blades-in-the-dark/0.7.4/system.json",
"download": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/archive/0.7.4.zip",
"manifest": "https://raw.githubusercontent.com/megastruktur/foundryvtt-blades-in-the-dark/1.0/system.json",
"download": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/archive/1.0.zip",
"packs": [
{
"name": "class",

View File

@ -5,7 +5,7 @@
<div id="attributes-{{attribute_name}}" class="attribute">
<div id="attributes-{{attribute_name}}-title" class="attributes-exp">
<div class="stripe">
<label class="attribute-label" for="{{attribute_name}}-exp-0">{{#if attribute.label}}{{localize attribute.label}}{{else}}{{attribute_name}}{{/if}}</label>
<label class="attribute-label" for="{{attribute_name}}-exp-0">{{localize attribute.label}}</label>
<a class="roll-die-attribute" data-roll-attribute="{{attribute_name}}" title="Roll"><i class="fas fa-dice"></i></a>
</div>
<div class="stripe-tooth-body">
@ -44,7 +44,7 @@
<label for="attributes-{{skill_name}}-3"></label>
<input type="radio" id="attributes-{{skill_name}}-4" name="data.attributes.{{attribute_name}}.skills.{{skill_name}}.value" value="4">
<label for="attributes-{{skill_name}}-4"></label>
<div class="attribute-skill-label">{{#if skill.label}}{{localize skill.label}}{{else}}{{skill_name}}{{/if}}</div>
<div class="attribute-skill-label">{{localize skill.label}}</div>
{{/multiboxes}}
</div>
<a class="roll-die-attribute" data-roll-attribute="{{skill_name}}" title="Roll"><i class="fas fa-dice"></i></a>