Fixes all Tokens to be force actor linked. Adds migration.
This commit is contained in:
parent
683ccd6449
commit
2de449cd7e
4 changed files with 83 additions and 1 deletions
|
@ -1,3 +1,6 @@
|
|||
v2.15
|
||||
- Fixes all Tokens to be force "actor linked"
|
||||
|
||||
v2.14
|
||||
- Fixes Dice-so-Nice integration
|
||||
|
||||
|
|
|
@ -7,6 +7,22 @@ import { BladesHelpers } from "./blades-helpers.js";
|
|||
*/
|
||||
export class BladesActor extends Actor {
|
||||
|
||||
/** @override */
|
||||
static async create(data, options={}) {
|
||||
|
||||
data.token = data.token || {};
|
||||
|
||||
// For Crew and Character set the Token to sync with charsheet.
|
||||
switch (data.type) {
|
||||
case 'character':
|
||||
case 'crew':
|
||||
data.token.actorLink = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return super.create(data, options);
|
||||
}
|
||||
|
||||
/** @override */
|
||||
getRollData() {
|
||||
|
|
|
@ -269,7 +269,7 @@ Hooks.once("ready", function() {
|
|||
|
||||
// Determine whether a system migration is required
|
||||
const currentVersion = game.settings.get("bitd", "systemMigrationVersion");
|
||||
const NEEDS_MIGRATION_VERSION = 2.0;
|
||||
const NEEDS_MIGRATION_VERSION = 2.15;
|
||||
|
||||
let needMigration = (currentVersion < NEEDS_MIGRATION_VERSION) || (currentVersion === null);
|
||||
|
||||
|
|
|
@ -18,6 +18,33 @@ export const migrateWorld = async function() {
|
|||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate Token Link for Character and Crew
|
||||
if (a.data.type === 'character' || a.data.type === 'crew') {
|
||||
try {
|
||||
const updateData = _migrateTokenLink(a.data);
|
||||
if ( !isObjectEmpty(updateData) ) {
|
||||
console.log(`Migrating Token Link for ${a.name}`);
|
||||
await a.update(updateData, {enforceTypes: false});
|
||||
}
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Migrate Actor Link
|
||||
for ( let s of game.scenes.entities ) {
|
||||
try {
|
||||
const updateData = _migrateSceneData(s.data);
|
||||
if ( !isObjectEmpty(updateData) ) {
|
||||
console.log(`Migrating Scene entity ${s.name}`);
|
||||
await s.update(updateData, {enforceTypes: false});
|
||||
}
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the migration as complete
|
||||
|
@ -25,6 +52,26 @@ export const migrateWorld = async function() {
|
|||
ui.notifications.info(`BITD System Migration to version ${game.system.data.version} completed!`, {permanent: true});
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Migrate a single Scene entity to incorporate changes to the data model of it's actor data overrides
|
||||
* Return an Object of updateData to be applied
|
||||
* @param {Object} scene The Scene data to Update
|
||||
* @return {Object} The updateData to apply
|
||||
*/
|
||||
export const _migrateSceneData = function(scene) {
|
||||
const tokens = duplicate(scene.tokens);
|
||||
return {
|
||||
tokens: tokens.map(t => {
|
||||
t.actorLink = true;
|
||||
t.actorData = {};
|
||||
return t;
|
||||
})
|
||||
};
|
||||
};
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
@ -93,4 +140,20 @@ function _migrateActor(actor) {
|
|||
// }
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
|
||||
/**
|
||||
* Make Token be an Actor link.
|
||||
* @param {Actor} actor The actor to Update
|
||||
* @return {Object} The updateData to apply
|
||||
*/
|
||||
function _migrateTokenLink(actor) {
|
||||
|
||||
let updateData = {}
|
||||
updateData['token.actorLink'] = true;
|
||||
|
||||
return updateData;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
Reference in a new issue