More WIP
This commit is contained in:
parent
650cbe7310
commit
76f42fe280
3 changed files with 29 additions and 18 deletions
|
@ -5,10 +5,10 @@
|
||||||
import logger from "../logger";
|
import logger from "../logger";
|
||||||
|
|
||||||
export async function migrate(): Promise<void> {
|
export async function migrate(): Promise<void> {
|
||||||
for (const a of game.actors ?? []) {
|
for (const a of game.actors?.contents ?? []) {
|
||||||
const updateData = getActorUpdateData();
|
const updateData = getActorUpdateData();
|
||||||
logger.info(`Migrating actor ${a.name}`);
|
logger.info(`Migrating actor ${a.name}`);
|
||||||
await a.update(updateData, { enforceTypes: false });
|
await a.update(updateData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,9 @@ export async function migrate(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function migrateItems() {
|
async function migrateItems() {
|
||||||
for (const item of game.items?.entities ?? []) {
|
for (const item of game.items?.contents ?? []) {
|
||||||
try {
|
try {
|
||||||
const updateData = getItemUpdateData(item._data);
|
const updateData = getItemUpdateData(item.toObject());
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
logger.info(`Migrating Item entity ${item.name} (${item.id})`);
|
logger.info(`Migrating Item entity ${item.name} (${item.id})`);
|
||||||
await item.update(updateData), { enforceTypes: false };
|
await item.update(updateData), { enforceTypes: false };
|
||||||
|
@ -26,18 +26,18 @@ async function migrateItems() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getItemUpdateData(itemData: DeepPartial<Item.Data>) {
|
function getItemUpdateData(itemData: foundry.data.ItemData["_source"]) {
|
||||||
if (!["equipment", "trinket"].includes(itemData.type ?? "")) return undefined;
|
if (!["equipment", "trinket"].includes(itemData.type ?? "")) return undefined;
|
||||||
return { type: itemData.type === "equipment" ? "loot" : "equipment" };
|
return { type: itemData.type === "equipment" ? ("loot" as const) : ("equipment" as const) };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function migrateActors() {
|
async function migrateActors() {
|
||||||
for (const actor of game.actors?.entities ?? []) {
|
for (const actor of game.actors?.contents ?? []) {
|
||||||
try {
|
try {
|
||||||
const updateData = getActorUpdateData(actor._data);
|
const updateData = getActorUpdateData(actor.toObject());
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
logger.info(`Migrating Actor entity ${actor.name} (${actor.id})`);
|
logger.info(`Migrating Actor entity ${actor.name} (${actor.id})`);
|
||||||
await actor.update(updateData, { enforceTypes: false });
|
await actor.update(updateData);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.message = `Error during migration of Actor entity ${actor.name} (${actor.id}), continuing anyways.`;
|
err.message = `Error during migration of Actor entity ${actor.name} (${actor.id}), continuing anyways.`;
|
||||||
|
@ -46,9 +46,9 @@ async function migrateActors() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getActorUpdateData(actorData: DeepPartial<Actor.Data>) {
|
function getActorUpdateData(actorData: foundry.data.ActorData["_source"]) {
|
||||||
let hasItemUpdates = false;
|
let hasItemUpdates = false;
|
||||||
const items = actorData.items?.map((itemData) => {
|
const items = actorData.items.map((itemData: foundry.data.ItemData["_source"]) => {
|
||||||
const update = itemData ? getItemUpdateData(itemData) : undefined;
|
const update = itemData ? getItemUpdateData(itemData) : undefined;
|
||||||
if (update) {
|
if (update) {
|
||||||
hasItemUpdates = true;
|
hasItemUpdates = true;
|
||||||
|
@ -61,23 +61,34 @@ function getActorUpdateData(actorData: DeepPartial<Actor.Data>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function migrateScenes() {
|
async function migrateScenes() {
|
||||||
for (const scene of game.scenes?.entities ?? []) {
|
for (const scene of game.scenes?.contents ?? []) {
|
||||||
try {
|
try {
|
||||||
const updateData = getSceneUpdateData(scene._data);
|
const updateData = getSceneUpdateData(scene.toObject());
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
logger.info(`Migrating Scene entity ${scene.name} (${scene.id})`);
|
logger.info(`Migrating Scene entity ${scene.name} (${scene.id})`);
|
||||||
await scene.update(updateData, { enforceTypes: false });
|
await scene.update(updateData);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.message = `Error during migration of Scene entity ${scene.name} (${scene.id}), continuing anyways.`;
|
err.message = `Error during migration of Scene document ${scene.name} (${scene.id}), continuing anyways.`;
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSceneUpdateData(sceneData: Scene.Data) {
|
function getSceneUpdateData(scene: Scene) {
|
||||||
let hasTokenUpdates = false;
|
let hasTokenUpdates = false;
|
||||||
const tokens = sceneData.tokens.map((tokenData) => {
|
// TODO: Continue from here
|
||||||
|
const tokens = scene.tokens.map((tokenData: foundry.data.TokenData["_source"]) => {
|
||||||
|
if (!tokenData.actorId || tokenData.actorLink) {
|
||||||
|
tokenData.actorData = {};
|
||||||
|
} else if (!game.actors?.has(tokenData.actorId)) {
|
||||||
|
tokenData.actorId = null;
|
||||||
|
tokenData.actorData = {};
|
||||||
|
} else if (!tokenData.actorLink) {
|
||||||
|
const actorData = duplicate(tokenData.actorData);
|
||||||
|
actorData.type = token.actor?.type;
|
||||||
|
}
|
||||||
|
|
||||||
if (!tokenData.actorId || tokenData.actorLink || tokenData.actorData.data) {
|
if (!tokenData.actorId || tokenData.actorLink || tokenData.actorData.data) {
|
||||||
tokenData.actorData = {};
|
tokenData.actorData = {};
|
||||||
hasTokenUpdates = true;
|
hasTokenUpdates = true;
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { DS4Check } from "./check";
|
||||||
|
|
||||||
export default function registerSlayingDiceModifier(): void {
|
export default function registerSlayingDiceModifier(): void {
|
||||||
PoolTerm.MODIFIERS.x = slay;
|
PoolTerm.MODIFIERS.x = slay;
|
||||||
PoolTerm.POOL_REGEX = /^{([^}]+)}([A-z]([A-z0-9<=>]+)?)?$/;
|
// PoolTerm.POOL_REGEX = /^{([^}]+)}([A-z]([A-z0-9<=>]+)?)?$/; // TODO: Maybe we don't need this anymore?
|
||||||
}
|
}
|
||||||
|
|
||||||
function slay(this: PoolTerm, modifier: string): void {
|
function slay(this: PoolTerm, modifier: string): void {
|
||||||
|
|
Loading…
Reference in a new issue