Updated to 1.3.3, started removing evidence of statships

This commit is contained in:
Jacob Lucas 2021-06-13 04:25:56 +01:00
parent 64bae2140c
commit 104e49615d
5 changed files with 49 additions and 31 deletions

View file

@ -257,7 +257,7 @@ export default class ActorSheet5eVehicle extends ActorSheet5e {
/** @override */ /** @override */
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
if (!this.options.editable) return; if (!this.isEditable) return;
html.find('.item-toggle').click(this._onToggleItem.bind(this)); html.find('.item-toggle').click(this._onToggleItem.bind(this));
html.find('.item-hp input') html.find('.item-hp input')

View file

@ -6,7 +6,7 @@ export const migrateWorld = async function() {
ui.notifications.info(`Applying SW5e System Migration for version ${game.system.data.version}. Please be patient and do not close your game or shut down your server.`, {permanent: true}); ui.notifications.info(`Applying SW5e System 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 // Migrate World Actors
for await ( let a of game.actors.entities ) { for await ( let a of game.actors.contents ) {
try { try {
console.log(`Checking Actor entity ${a.name} for migration needs`); console.log(`Checking Actor entity ${a.name} for migration needs`);
const updateData = await migrateActorData(a.data); const updateData = await migrateActorData(a.data);
@ -21,9 +21,9 @@ export const migrateWorld = async function() {
} }
// Migrate World Items // Migrate World Items
for ( let i of game.items.entities ) { for ( let i of game.items.contents ) {
try { try {
const updateData = migrateItemData(i.data); const updateData = migrateItemData(i.toObject());
if ( !foundry.utils.isObjectEmpty(updateData) ) { if ( !foundry.utils.isObjectEmpty(updateData) ) {
console.log(`Migrating Item entity ${i.name}`); console.log(`Migrating Item entity ${i.name}`);
await i.update(updateData, {enforceTypes: false}); await i.update(updateData, {enforceTypes: false});
@ -35,12 +35,15 @@ export const migrateWorld = async function() {
} }
// Migrate Actor Override Tokens // Migrate Actor Override Tokens
for ( let s of game.scenes.entities ) { for ( let s of game.scenes.contents ) {
try { try {
const updateData = await migrateSceneData(s.data); const updateData = await migrateSceneData(s.data);
if ( !foundry.utils.isObjectEmpty(updateData) ) { if ( !foundry.utils.isObjectEmpty(updateData) ) {
console.log(`Migrating Scene entity ${s.name}`); console.log(`Migrating Scene entity ${s.name}`);
await s.update(updateData, {enforceTypes: false}); await s.update(updateData, {enforceTypes: false});
// If we do not do this, then synthetic token actors remain in cache
// with the un-updated actorData.
s.tokens.contents.forEach(t => t._actor = null);
} }
} catch(err) { } catch(err) {
err.message = `Failed sw5e system migration for Scene ${s.name}: ${err.message}`; err.message = `Failed sw5e system migration for Scene ${s.name}: ${err.message}`;
@ -88,7 +91,7 @@ export const migrateCompendium = async function(pack) {
updateData = await migrateActorData(doc.data); updateData = await migrateActorData(doc.data);
break; break;
case "Item": case "Item":
updateData = migrateItemData(doc.data); updateData = migrateItemData(doc.toObject());
break; break;
case "Scene": case "Scene":
updateData = await migrateSceneData(doc.data); updateData = await migrateSceneData(doc.data);
@ -127,9 +130,11 @@ export const migrateActorData = async function(actor) {
const updateData = {}; const updateData = {};
// Actor Data Updates // Actor Data Updates
_migrateActorMovement(actor, updateData); if(actor.data) {
_migrateActorSenses(actor, updateData); _migrateActorMovement(actor, updateData);
_migrateActorType(actor, updateData); _migrateActorSenses(actor, updateData);
_migrateActorType(actor, updateData);
}
// Migrate Owned Items // Migrate Owned Items
if ( !!actor.items ) { if ( !!actor.items ) {
@ -137,20 +142,21 @@ export const migrateActorData = async function(actor) {
const results = await memo; const results = await memo;
// Migrate the Owned Item // Migrate the Owned Item
let itemUpdate = await migrateActorItemData(i.data, actor); const itemData = i instanceof CONFIG.Item.documentClass ? i.toObject() : i
let itemUpdate = await migrateActorItemData(itemData, actor);
// Prepared, Equipped, and Proficient for NPC actors // Prepared, Equipped, and Proficient for NPC actors
if ( actor.type === "npc" ) { if ( actor.type === "npc" ) {
if (getProperty(i.data, "preparation.prepared") === false) itemUpdate["data.preparation.prepared"] = true; if (getProperty(itemData.data, "preparation.prepared") === false) itemUpdate["data.preparation.prepared"] = true;
if (getProperty(i.data, "equipped") === false) itemUpdate["data.equipped"] = true; if (getProperty(itemData.data, "equipped") === false) itemUpdate["data.equipped"] = true;
if (getProperty(i.data, "proficient") === false) itemUpdate["data.proficient"] = true; if (getProperty(itemData.data, "proficient") === false) itemUpdate["data.proficient"] = true;
} }
// Update the Owned Item // Update the Owned Item
if ( !isObjectEmpty(itemUpdate) ) { if ( !isObjectEmpty(itemUpdate) ) {
itemUpdate._id = i.id; itemUpdate._id = itemData.id;
console.log(`Migrating Actor ${actor.name}'s ${i.name}`); console.log(`Migrating Actor ${actor.name}'s ${i.name}`);
results.push(itemUpdate) results.push(expandObject(itemUpdate));
} }
return results; return results;
@ -237,14 +243,27 @@ export const migrateActorItemData = async function(item, actor) {
export const migrateSceneData = async function(scene) { export const migrateSceneData = async function(scene) {
const tokens = await Promise.all(scene.tokens.map(async token => { const tokens = await Promise.all(scene.tokens.map(async token => {
const t = token.toJSON(); const t = token.toJSON();
if (!t.actorId || t.actorLink || !t.actorData.data) { if (!t.actorId || t.actorLink) {
t.actorData = {}; t.actorData = {};
} }
else if (!game.actors.has(t.actorId)) { else if (!game.actors.has(t.actorId)) {
t.actorId = null; t.actorId = null;
t.actorData = {}; t.actorData = {};
} else if ( !t.actorLink ) { } else if ( !t.actorLink ) {
t.actorData = mergeObject(token.data.actorData, await migrateActorData(t.actorData)); const actorData = duplicate(t.actorData);
actorData.type = token.actor?.type;
const update = migrateActorData(actorData);
['items', 'effects'].forEach(embeddedName => {
if (!update[embeddedName]?.length) return;
const updates = new Map(update[embeddedName].map(u => [u._id, u]));
t.actorData[embeddedName].forEach(original => {
const update = updates.get(original._id);
if (update) mergeObject(original, update);
});
delete update[embeddedName];
});
mergeObject(t.actorData, update);
} }
return t; return t;
})); }));
@ -417,6 +436,7 @@ function _migrateActorSenses(actor, updateData) {
const ad = actor.data; const ad = actor.data;
if ( ad?.traits?.senses === undefined ) return; if ( ad?.traits?.senses === undefined ) return;
const original = ad.traits.senses || ""; const original = ad.traits.senses || "";
if ( typeof original !== "string" ) return;
// Try to match old senses with the format like "Darkvision 60 ft, Blindsight 30 ft" // Try to match old senses with the format like "Darkvision 60 ft, Blindsight 30 ft"
const pattern = /([A-z]+)\s?([0-9]+)\s?([A-z]+)?/; const pattern = /([A-z]+)\s?([0-9]+)\s?([A-z]+)?/;
@ -451,7 +471,7 @@ function _migrateActorSenses(actor, updateData) {
function _migrateActorType(actor, updateData) { function _migrateActorType(actor, updateData) {
const ad = actor.data; const ad = actor.data;
const original = ad.details?.type; const original = ad.details?.type;
if ( (original === undefined) || (foundry.utils.getType(original) === "Object") ) return; if ( typeof original !== "string" ) return;
// New default data structure // New default data structure
let data = { let data = {
@ -518,7 +538,6 @@ function _migrateActorType(actor, updateData) {
// Update the actor data // Update the actor data
updateData["data.details.type"] = data; updateData["data.details.type"] = data;
console.log(data);
return updateData; return updateData;
} }
@ -624,7 +643,7 @@ async function _migrateItemPower(item, actor, updateData) {
* @private * @private
*/ */
function _migrateItemAttunement(item, updateData) { function _migrateItemAttunement(item, updateData) {
if ( item.data.attuned === undefined ) return updateData; if ( item.data.data.attuned === undefined ) return updateData;
updateData["data.attunement"] = CONFIG.SW5E.attunementTypes.NONE; updateData["data.attunement"] = CONFIG.SW5E.attunementTypes.NONE;
updateData["data.-=attuned"] = null; updateData["data.-=attuned"] = null;
return updateData; return updateData;

View file

@ -8,7 +8,7 @@ export const registerSystemSettings = function() {
scope: "world", scope: "world",
config: false, config: false,
type: String, type: String,
default: "" default: game.system.data.version
}); });
/** /**

17
sw5e.js
View file

@ -140,11 +140,11 @@ Hooks.once("init", function() {
makeDefault: false, makeDefault: false,
label: "SW5E.SheetClassNPCOld" label: "SW5E.SheetClassNPCOld"
}); });
Actors.registerSheet("sw5e", ActorSheet5eStarship, { // Actors.registerSheet("sw5e", ActorSheet5eStarship, {
types: ["starship"], // types: ["starship"],
makeDefault: true, // makeDefault: true,
label: "SW5E.SheetClassStarship" // label: "SW5E.SheetClassStarship"
}); // });
Actors.registerSheet('sw5e', ActorSheet5eVehicle, { Actors.registerSheet('sw5e', ActorSheet5eVehicle, {
types: ['vehicle'], types: ['vehicle'],
makeDefault: true, makeDefault: true,
@ -207,7 +207,6 @@ Hooks.once("setup", function() {
}); });
/* -------------------------------------------- */ /* -------------------------------------------- */
//TODO: Setup Migration
/** /**
* Once the entire VTT framework is initialized, check to see if we should perform a data migration * Once the entire VTT framework is initialized, check to see if we should perform a data migration
*/ */
@ -219,12 +218,12 @@ Hooks.once("ready", function() {
// Determine whether a system migration is required and feasible // Determine whether a system migration is required and feasible
if ( !game.user.isGM ) return; if ( !game.user.isGM ) return;
const currentVersion = game.settings.get("sw5e", "systemMigrationVersion"); const currentVersion = game.settings.get("sw5e", "systemMigrationVersion");
const NEEDS_MIGRATION_VERSION = "1.3.2.R1-A5"; const NEEDS_MIGRATION_VERSION = "1.3.0.R1-A6";
// Check for R1 SW5E versions // Check for R1 SW5E versions
const SW5E_NEEDS_MIGRATION_VERSION = "R1-A5"; const SW5E_NEEDS_MIGRATION_VERSION = "R1-A6";
const COMPATIBLE_MIGRATION_VERSION = 0.80; const COMPATIBLE_MIGRATION_VERSION = 0.80;
const needsMigration = currentVersion && (isNewerVersion(SW5E_NEEDS_MIGRATION_VERSION, currentVersion) || isNewerVersion(NEEDS_MIGRATION_VERSION, currentVersion)); const needsMigration = currentVersion && (isNewerVersion(SW5E_NEEDS_MIGRATION_VERSION, currentVersion) || isNewerVersion(NEEDS_MIGRATION_VERSION, currentVersion));
if ( !needsMigration ) return; if (!needsMigration && needsMigration !== "") return;
// Perform the migration // Perform the migration
if ( currentVersion && isNewerVersion(COMPATIBLE_MIGRATION_VERSION, currentVersion) ) { if ( currentVersion && isNewerVersion(COMPATIBLE_MIGRATION_VERSION, currentVersion) ) {

View file

@ -2,7 +2,7 @@
"name": "sw5e", "name": "sw5e",
"title": "SW 5th Edition", "title": "SW 5th Edition",
"description": "A comprehensive game system for running games of SW 5th Edition in the Foundry VTT environment.", "description": "A comprehensive game system for running games of SW 5th Edition in the Foundry VTT environment.",
"version": "1.3.2.R1-A6", "version": "1.3.3.R1-A6",
"author": "Dev Team", "author": "Dev Team",
"scripts": [], "scripts": [],
"esmodules": ["sw5e.js"], "esmodules": ["sw5e.js"],