Merge branch '085-fix-problem-with-negative-ctn' into 'master'
Fix problem with check target numbers <= 0 Closes #85 See merge request dungeonslayers/ds4!114
This commit is contained in:
commit
3f6682c9b2
15 changed files with 225 additions and 77 deletions
|
@ -48,30 +48,134 @@ describe("evaluateCheck with a single die", () => {
|
||||||
{ result: 20, checkTargetNumber: 4, active: false, discarded: true, failure: true },
|
{ result: 20, checkTargetNumber: 4, active: false, discarded: true, failure: true },
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should roll a die even when the checkTargetNumber is 0 and coup on 1", () => {
|
||||||
|
expect(evaluateCheck([1], 0)).toEqual([
|
||||||
|
{ result: 1, checkTargetNumber: 0, active: true, discarded: false, success: true, count: 0 },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should roll a die even when the checkTargetNumber is 0 and fail on values > 1 and < 20", () => {
|
||||||
|
for (let i = 2; i < 20; i++) {
|
||||||
|
expect(evaluateCheck([i], 0)).toEqual([
|
||||||
|
{ result: i, checkTargetNumber: 0, active: false, discarded: true },
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should roll a die even when the checkTargetNumber is 0 and fumble on 20", () => {
|
||||||
|
expect(evaluateCheck([20], 0)).toEqual([
|
||||||
|
{ result: 20, checkTargetNumber: 0, active: false, discarded: true, failure: true },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should roll a die even when the checkTargetNumber is < 0 and coup on 1", () => {
|
||||||
|
expect(evaluateCheck([1], -1)).toEqual([
|
||||||
|
{ result: 1, checkTargetNumber: -1, active: true, discarded: false, success: true, count: -1 },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should roll a die even when the checkTargetNumber is < 0 and fail on values > 1 and < 20", () => {
|
||||||
|
for (let i = 2; i < 20; i++) {
|
||||||
|
expect(evaluateCheck([i], -1)).toEqual([
|
||||||
|
{ result: i, checkTargetNumber: -1, active: false, discarded: true },
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should roll a die even when the checkTargetNumber is < 0 and fumble on 20", () => {
|
||||||
|
expect(evaluateCheck([20], -1)).toEqual([
|
||||||
|
{ result: 20, checkTargetNumber: -1, active: false, discarded: true, failure: true },
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("evaluateCheck with a single die and coup / fumble modification", () => {
|
describe("evaluateCheck with a single die and coup / fumble modification", () => {
|
||||||
|
const maximumCoupResult = 2;
|
||||||
|
const minimumFumbleResult = 19;
|
||||||
|
|
||||||
it("should assign the checkTargetNumber to the single die and coup on 'maximumCoupResult'", () => {
|
it("should assign the checkTargetNumber to the single die and coup on 'maximumCoupResult'", () => {
|
||||||
expect(evaluateCheck([2], 4, { maximumCoupResult: 2 })).toEqual([
|
expect(evaluateCheck([maximumCoupResult], 4, { maximumCoupResult })).toEqual([
|
||||||
{ result: 2, checkTargetNumber: 4, active: true, discarded: false, success: true, count: 4 },
|
{
|
||||||
|
result: maximumCoupResult,
|
||||||
|
checkTargetNumber: 4,
|
||||||
|
active: true,
|
||||||
|
discarded: false,
|
||||||
|
success: true,
|
||||||
|
count: 4,
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should assign the checkTargetNumber to the single die and not coup on lower edge case '3'", () => {
|
it("should assign the checkTargetNumber to the single die and not coup on lower edge case 'maximumCoupResult + 1'", () => {
|
||||||
expect(evaluateCheck([3], 4, { maximumCoupResult: 2 })).toEqual([
|
expect(evaluateCheck([maximumCoupResult + 1], 4, { maximumCoupResult })).toEqual([
|
||||||
{ result: 3, checkTargetNumber: 4, active: true, discarded: false },
|
{ result: maximumCoupResult + 1, checkTargetNumber: 4, active: true, discarded: false },
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should assign the checkTargetNumber to the single die and fumble on 'minimumFUmbleResultResult'", () => {
|
it("should assign the checkTargetNumber to the single die and fumble on 'minimumFumbleResultResult'", () => {
|
||||||
expect(evaluateCheck([19], 20, { minimumFumbleResult: 19 })).toEqual([
|
expect(evaluateCheck([minimumFumbleResult], 20, { minimumFumbleResult })).toEqual([
|
||||||
{ result: 19, checkTargetNumber: 20, active: true, discarded: false, failure: true },
|
{ result: minimumFumbleResult, checkTargetNumber: 20, active: true, discarded: false, failure: true },
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should assign the checkTargetNumber to the single die and not fumble on upper edge case '18'", () => {
|
it("should assign the checkTargetNumber to the single die and not fumble on upper edge case 'minimumFumbleResult - 1'", () => {
|
||||||
expect(evaluateCheck([18], 20, { minimumFumbleResult: 19 })).toEqual([
|
expect(evaluateCheck([minimumFumbleResult - 1], 20, { minimumFumbleResult })).toEqual([
|
||||||
{ result: 18, checkTargetNumber: 20, active: true, discarded: false },
|
{ result: minimumFumbleResult - 1, checkTargetNumber: 20, active: true, discarded: false },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should roll a die even when the checkTargetNumber is 0 and coup on 'maximumCoupResult'", () => {
|
||||||
|
expect(evaluateCheck([maximumCoupResult], 0, { maximumCoupResult })).toEqual([
|
||||||
|
{
|
||||||
|
result: maximumCoupResult,
|
||||||
|
checkTargetNumber: 0,
|
||||||
|
active: true,
|
||||||
|
discarded: false,
|
||||||
|
success: true,
|
||||||
|
count: 0,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should roll a die even when the checkTargetNumber is 0 and fail on '> maximumCoupResult and < minimumFumbleResult", () => {
|
||||||
|
for (let i = maximumCoupResult + 1; i < minimumFumbleResult; i++) {
|
||||||
|
expect(evaluateCheck([i], 0, { maximumCoupResult, minimumFumbleResult })).toEqual([
|
||||||
|
{ result: i, checkTargetNumber: 0, active: false, discarded: true },
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should roll a die even when the checkTargetNumber is 0 and fumble on 'minimumFumbleResult'", () => {
|
||||||
|
expect(evaluateCheck([minimumFumbleResult], 0, { minimumFumbleResult })).toEqual([
|
||||||
|
{ result: minimumFumbleResult, checkTargetNumber: 0, active: false, discarded: true, failure: true },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should roll a die even when the checkTargetNumber is < 0 and coup on 'maximumCoupResult'", () => {
|
||||||
|
expect(evaluateCheck([maximumCoupResult], -1, { maximumCoupResult })).toEqual([
|
||||||
|
{
|
||||||
|
result: maximumCoupResult,
|
||||||
|
checkTargetNumber: -1,
|
||||||
|
active: true,
|
||||||
|
discarded: false,
|
||||||
|
success: true,
|
||||||
|
count: -1,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should roll a die even when the checkTargetNumber is < 0 and fail on '> maximumCoupResult and < minimumFumbleResult", () => {
|
||||||
|
for (let i = maximumCoupResult + 1; i < minimumFumbleResult; i++) {
|
||||||
|
expect(evaluateCheck([i], -1, { maximumCoupResult, minimumFumbleResult })).toEqual([
|
||||||
|
{ result: i, checkTargetNumber: -1, active: false, discarded: true },
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should roll a die even when the checkTargetNumber is < 0 and fumble on 'minimumFumbleResult'", () => {
|
||||||
|
expect(evaluateCheck([minimumFumbleResult], -1, { minimumFumbleResult })).toEqual([
|
||||||
|
{ result: minimumFumbleResult, checkTargetNumber: -1, active: false, discarded: true, failure: true },
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -235,7 +235,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Data<DS4Actor>> {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const id = $(event.currentTarget).parents(".item").data("itemId");
|
const id = $(event.currentTarget).parents(".item").data("itemId");
|
||||||
const item = this.actor.getOwnedItem(id);
|
const item = this.actor.getOwnedItem(id);
|
||||||
item.roll();
|
item.roll().catch((e) => notifications.error(e, { log: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -245,7 +245,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Data<DS4Actor>> {
|
||||||
protected _onRollCheck(event: JQuery.ClickEvent): void {
|
protected _onRollCheck(event: JQuery.ClickEvent): void {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const check = event.currentTarget.dataset["check"];
|
const check = event.currentTarget.dataset["check"];
|
||||||
this.actor.rollCheck(check);
|
this.actor.rollCheck(check).catch((e) => notifications.error(e, { log: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
|
|
|
@ -6,6 +6,7 @@ import registerHandlebarsHelpers from "../handlebars/handlebars-helpers";
|
||||||
import registerHandlebarsPartials from "../handlebars/handlebars-partials";
|
import registerHandlebarsPartials from "../handlebars/handlebars-partials";
|
||||||
import { DS4Item } from "../item/item";
|
import { DS4Item } from "../item/item";
|
||||||
import { DS4ItemSheet } from "../item/item-sheet";
|
import { DS4ItemSheet } from "../item/item-sheet";
|
||||||
|
import logger from "../logger";
|
||||||
import { macros } from "../macros/macros";
|
import { macros } from "../macros/macros";
|
||||||
import { migration } from "../migrations";
|
import { migration } from "../migrations";
|
||||||
import { DS4Check } from "../rolls/check";
|
import { DS4Check } from "../rolls/check";
|
||||||
|
@ -19,7 +20,7 @@ export default function registerForInitHook(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
console.log(`DS4 | Initializing the DS4 Game System\n${DS4.ASCII}`);
|
logger.info(`Initializing the DS4 Game System\n${DS4.ASCII}`);
|
||||||
|
|
||||||
game.ds4 = {
|
game.ds4 = {
|
||||||
DS4Actor,
|
DS4Actor,
|
||||||
|
|
27
src/module/logger.ts
Normal file
27
src/module/logger.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
const loggingContext = "DS4";
|
||||||
|
const loggingSeparator = "|";
|
||||||
|
|
||||||
|
type LogLevel = "debug" | "info" | "warning" | "error";
|
||||||
|
type LoggingFunction = (...data: unknown[]) => void;
|
||||||
|
|
||||||
|
class Logger {
|
||||||
|
readonly debug: LoggingFunction;
|
||||||
|
readonly info: LoggingFunction;
|
||||||
|
readonly warn: LoggingFunction;
|
||||||
|
readonly error: LoggingFunction;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.debug = this.getLoggingFunction("debug");
|
||||||
|
this.info = this.getLoggingFunction("info");
|
||||||
|
this.warn = this.getLoggingFunction("warning");
|
||||||
|
this.error = this.getLoggingFunction("error");
|
||||||
|
}
|
||||||
|
|
||||||
|
getLoggingFunction(type: LogLevel = "info") {
|
||||||
|
const log = { debug: console.debug, info: console.info, warning: console.warn, error: console.error }[type];
|
||||||
|
return (...data: unknown[]) => log(loggingContext, loggingSeparator, ...data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const logger = new Logger();
|
||||||
|
export default logger;
|
|
@ -45,5 +45,5 @@ export async function rollCheck(check: Check): Promise<void> {
|
||||||
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
|
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return actor.rollCheck(check);
|
return actor.rollCheck(check).catch((e) => notifications.error(e, { log: true }));
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,5 @@ export async function rollGenericCheck(): Promise<void> {
|
||||||
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
|
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return actor.rollGenericCheck();
|
return actor.rollGenericCheck().catch((e) => notifications.error(e, { log: true }));
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,5 +53,5 @@ export async function rollItem(itemId: string): Promise<void> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return item.roll();
|
return item.roll().catch((e) => notifications.error(e, { log: true }));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logger from "./logger";
|
||||||
import { migrate as migrate001 } from "./migrations/001";
|
import { migrate as migrate001 } from "./migrations/001";
|
||||||
import { migrate as migrate002 } from "./migrations/002";
|
import { migrate as migrate002 } from "./migrations/002";
|
||||||
import { migrate as migrate003 } from "./migrations/003";
|
import { migrate as migrate003 } from "./migrations/003";
|
||||||
|
@ -40,7 +41,7 @@ async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion
|
||||||
|
|
||||||
for (const [i, migration] of migrationsToExecute.entries()) {
|
for (const [i, migration] of migrationsToExecute.entries()) {
|
||||||
const currentMigrationVersion = oldMigrationVersion + i + 1;
|
const currentMigrationVersion = oldMigrationVersion + i + 1;
|
||||||
console.log("executing migration script ", currentMigrationVersion);
|
logger.info("executing migration script ", currentMigrationVersion);
|
||||||
try {
|
try {
|
||||||
await migration();
|
await migration();
|
||||||
game.settings.set("ds4", "systemMigrationVersion", currentMigrationVersion);
|
game.settings.set("ds4", "systemMigrationVersion", currentMigrationVersion);
|
||||||
|
@ -54,7 +55,7 @@ async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion
|
||||||
{ permanent: true },
|
{ permanent: true },
|
||||||
);
|
);
|
||||||
err.message = `Failed ds4 system migration: ${err.message}`;
|
err.message = `Failed ds4 system migration: ${err.message}`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
import logger from "../logger";
|
||||||
|
|
||||||
export async function migrate(): Promise<void> {
|
export async function migrate(): Promise<void> {
|
||||||
for (const a of game.actors?.entities ?? []) {
|
for (const a of game.actors?.entities ?? []) {
|
||||||
const updateData = getActorUpdateData();
|
const updateData = getActorUpdateData();
|
||||||
console.log(`Migrating actor ${a.name}`);
|
logger.info(`Migrating actor ${a.name}`);
|
||||||
await a.update(updateData, { enforceTypes: false });
|
await a.update(updateData, { enforceTypes: false });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import logger from "../logger";
|
||||||
|
|
||||||
export async function migrate(): Promise<void> {
|
export async function migrate(): Promise<void> {
|
||||||
await migrateItems();
|
await migrateItems();
|
||||||
await migrateActors();
|
await migrateActors();
|
||||||
|
@ -10,12 +12,12 @@ async function migrateItems() {
|
||||||
try {
|
try {
|
||||||
const updateData = getItemUpdateData(item._data);
|
const updateData = getItemUpdateData(item._data);
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
console.log(`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 };
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.message = `Error during migration of Item entity ${item.name} (${item.id}), continuing anyways.`;
|
err.message = `Error during migration of Item entity ${item.name} (${item.id}), continuing anyways.`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,12 +32,12 @@ async function migrateActors() {
|
||||||
try {
|
try {
|
||||||
const updateData = getActorUpdateData(actor._data);
|
const updateData = getActorUpdateData(actor._data);
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
console.log(`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, { enforceTypes: false });
|
||||||
}
|
}
|
||||||
} 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.`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,12 +61,12 @@ async function migrateScenes() {
|
||||||
try {
|
try {
|
||||||
const updateData = getSceneUpdateData(scene._data);
|
const updateData = getSceneUpdateData(scene._data);
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
console.log(`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, { enforceTypes: false });
|
||||||
}
|
}
|
||||||
} 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 entity ${scene.name} (${scene.id}), continuing anyways.`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,12 +125,12 @@ async function migrateCompendium(compendium: Compendium) {
|
||||||
};
|
};
|
||||||
const updateData = getUpdateData(entity);
|
const updateData = getUpdateData(entity);
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
console.log(`Migrating entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}`);
|
logger.info(`Migrating entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}`);
|
||||||
await compendium.updateEntity({ ...updateData, _id: entity._id });
|
await compendium.updateEntity({ ...updateData, _id: entity._id });
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.message = `Error during migration of entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
err.message = `Error during migration of entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import logger from "../logger";
|
||||||
|
|
||||||
export async function migrate(): Promise<void> {
|
export async function migrate(): Promise<void> {
|
||||||
await migrateItems();
|
await migrateItems();
|
||||||
await migrateActors();
|
await migrateActors();
|
||||||
|
@ -10,12 +12,12 @@ async function migrateItems() {
|
||||||
try {
|
try {
|
||||||
const updateData = getItemUpdateData(item._data);
|
const updateData = getItemUpdateData(item._data);
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
console.log(`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 };
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.message = `Error during migration of Item entity ${item.name} (${item.id}), continuing anyways.`;
|
err.message = `Error during migration of Item entity ${item.name} (${item.id}), continuing anyways.`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,12 +36,12 @@ async function migrateActors() {
|
||||||
try {
|
try {
|
||||||
const updateData = getActorUpdateData(actor._data);
|
const updateData = getActorUpdateData(actor._data);
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
console.log(`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, { enforceTypes: false });
|
||||||
}
|
}
|
||||||
} 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.`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,12 +65,12 @@ async function migrateScenes() {
|
||||||
try {
|
try {
|
||||||
const updateData = getSceneUpdateData(scene._data);
|
const updateData = getSceneUpdateData(scene._data);
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
console.log(`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, { enforceTypes: false });
|
||||||
}
|
}
|
||||||
} 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 entity ${scene.name} (${scene.id}), continuing anyways.`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,12 +129,12 @@ async function migrateCompendium(compendium: Compendium) {
|
||||||
};
|
};
|
||||||
const updateData = getUpdateData(entity);
|
const updateData = getUpdateData(entity);
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
console.log(`Migrating entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}`);
|
logger.info(`Migrating entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}`);
|
||||||
await compendium.updateEntity({ ...updateData, _id: entity._id });
|
await compendium.updateEntity({ ...updateData, _id: entity._id });
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.message = `Error during migration of entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
err.message = `Error during migration of entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { DS4SpellDataData } from "../item/item-data";
|
import { DS4SpellDataData } from "../item/item-data";
|
||||||
|
import logger from "../logger";
|
||||||
|
|
||||||
export async function migrate(): Promise<void> {
|
export async function migrate(): Promise<void> {
|
||||||
await migrateItems();
|
await migrateItems();
|
||||||
|
@ -12,12 +13,12 @@ async function migrateItems() {
|
||||||
try {
|
try {
|
||||||
const updateData = getItemUpdateData(item._data);
|
const updateData = getItemUpdateData(item._data);
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
console.log(`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 };
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.message = `Error during migration of Item entity ${item.name} (${item.id}), continuing anyways.`;
|
err.message = `Error during migration of Item entity ${item.name} (${item.id}), continuing anyways.`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,12 +40,12 @@ async function migrateActors() {
|
||||||
try {
|
try {
|
||||||
const updateData = getActorUpdateData(actor._data);
|
const updateData = getActorUpdateData(actor._data);
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
console.log(`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, { enforceTypes: false });
|
||||||
}
|
}
|
||||||
} 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.`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,12 +76,12 @@ async function migrateScenes() {
|
||||||
try {
|
try {
|
||||||
const updateData = getSceneUpdateData(scene._data);
|
const updateData = getSceneUpdateData(scene._data);
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
console.log(`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, { enforceTypes: false });
|
||||||
}
|
}
|
||||||
} 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 entity ${scene.name} (${scene.id}), continuing anyways.`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,12 +141,12 @@ async function migrateCompendium(compendium: Compendium) {
|
||||||
};
|
};
|
||||||
const updateData = getUpdateData(entity);
|
const updateData = getUpdateData(entity);
|
||||||
if (updateData) {
|
if (updateData) {
|
||||||
console.log(`Migrating entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}`);
|
logger.info(`Migrating entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}`);
|
||||||
await compendium.updateEntity({ ...updateData, _id: entity._id });
|
await compendium.updateEntity({ ...updateData, _id: entity._id });
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.message = `Error during migration of entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
err.message = `Error during migration of entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
||||||
console.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,5 +113,5 @@ function evaluateDiceWithSubChecks(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRequiredNumberOfDice(checkTargetNumber: number): number {
|
export function getRequiredNumberOfDice(checkTargetNumber: number): number {
|
||||||
return Math.ceil(checkTargetNumber / 20);
|
return Math.max(Math.ceil(checkTargetNumber / 20), 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,9 @@ class CheckFactory {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
createCheckTargetNumberModifier(): string | null {
|
createCheckTargetNumberModifier(): string {
|
||||||
return "v" + (this.checkTargetNumber + this.gmModifier);
|
const totalCheckTargetNumber = Math.max(this.checkTargetNumber + this.gmModifier, 0);
|
||||||
|
return `v${totalCheckTargetNumber}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
createCoupFumbleModifier(): string | null {
|
createCoupFumbleModifier(): string | null {
|
||||||
|
@ -55,7 +56,7 @@ class CheckFactory {
|
||||||
const isMaximumCoupResultRequired = this.options.maximumCoupResult !== defaultCheckOptions.maximumCoupResult;
|
const isMaximumCoupResultRequired = this.options.maximumCoupResult !== defaultCheckOptions.maximumCoupResult;
|
||||||
|
|
||||||
if (isMinimumFumbleResultRequired || isMaximumCoupResultRequired) {
|
if (isMinimumFumbleResultRequired || isMaximumCoupResultRequired) {
|
||||||
return "c" + (this.options.maximumCoupResult ?? "") + ":" + (this.options.minimumFumbleResult ?? "");
|
return `c${this.options.maximumCoupResult ?? ""}:${this.options.minimumFumbleResult ?? ""}`;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -162,12 +163,20 @@ async function askGmModifier(
|
||||||
* @param formData - The filed dialog
|
* @param formData - The filed dialog
|
||||||
*/
|
*/
|
||||||
function parseDialogFormData(formData: HTMLFormElement): Partial<IntermediateGmModifierData> {
|
function parseDialogFormData(formData: HTMLFormElement): Partial<IntermediateGmModifierData> {
|
||||||
|
const chosenCheckTargetNumber = parseInt(formData["check-target-number"]?.value);
|
||||||
|
const chosenGMModifier = parseInt(formData["gm-modifier"]?.value);
|
||||||
|
const chosenMaximumCoupResult = parseInt(formData["maximum-coup-result"]?.value);
|
||||||
|
const chosenMinimumFumbleResult = parseInt(formData["minimum-fumble-result"]?.value);
|
||||||
|
const chosenRollMode = formData["roll-mode"]?.value;
|
||||||
|
|
||||||
|
const invalidNumbers = [NaN, Infinity, -Infinity];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
checkTargetNumber: parseInt(formData["check-target-number"]?.value),
|
checkTargetNumber: invalidNumbers.includes(chosenCheckTargetNumber) ? undefined : chosenCheckTargetNumber,
|
||||||
gmModifier: parseInt(formData["gm-modifier"]?.value),
|
gmModifier: invalidNumbers.includes(chosenGMModifier) ? undefined : chosenGMModifier,
|
||||||
maximumCoupResult: parseInt(formData["maximum-coup-result"]?.value),
|
maximumCoupResult: invalidNumbers.includes(chosenMaximumCoupResult) ? undefined : chosenMaximumCoupResult,
|
||||||
minimumFumbleResult: parseInt(formData["minimum-fumble-result"]?.value),
|
minimumFumbleResult: invalidNumbers.includes(chosenMinimumFumbleResult) ? undefined : chosenMinimumFumbleResult,
|
||||||
rollMode: formData["roll-mode"]?.value,
|
rollMode: Object.values(CONST.DICE_ROLL_MODES).includes(chosenRollMode) ? chosenRollMode : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,35 +1,34 @@
|
||||||
|
import logger from "../logger";
|
||||||
|
|
||||||
|
function getNotificationFunction(type: "info" | "warn" | "error") {
|
||||||
|
return (message: string, { permanent = false, log = false }: { permanent?: boolean; log?: boolean } = {}): void => {
|
||||||
|
if (ui.notifications) {
|
||||||
|
ui.notifications[type](message, { permanent });
|
||||||
|
if (log) {
|
||||||
|
logger[type](message);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger[type](message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const notifications = {
|
const notifications = {
|
||||||
info: (message: string, { permanent = false }: { permanent?: boolean } = {}): void => {
|
info: getNotificationFunction("info"),
|
||||||
if (ui.notifications) {
|
warn: getNotificationFunction("warn"),
|
||||||
ui.notifications.info(message, { permanent });
|
error: getNotificationFunction("error"),
|
||||||
} else {
|
|
||||||
console.info(message);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
warn: (message: string, { permanent = false }: { permanent?: boolean } = {}): void => {
|
|
||||||
if (ui.notifications) {
|
|
||||||
ui.notifications.warn(message, { permanent });
|
|
||||||
} else {
|
|
||||||
console.log(message);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: (message: string, { permanent = false }: { permanent?: boolean } = {}): void => {
|
|
||||||
if (ui.notifications) {
|
|
||||||
ui.notifications.error(message, { permanent });
|
|
||||||
} else {
|
|
||||||
console.warn(message);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
notify: (
|
notify: (
|
||||||
message: string,
|
message: string,
|
||||||
type: "info" | "warning" | "error" = "info",
|
type: "info" | "warning" | "error" = "info",
|
||||||
{ permanent = false }: { permanent?: boolean } = {},
|
{ permanent = false, log = false }: { permanent?: boolean; log?: boolean } = {},
|
||||||
): void => {
|
): void => {
|
||||||
if (ui.notifications) {
|
if (ui.notifications) {
|
||||||
ui.notifications.notify(message, type, { permanent });
|
ui.notifications.notify(message, type, { permanent });
|
||||||
|
if (log) {
|
||||||
|
logger.getLoggingFunction(type)(message);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const log = { info: console.info, warning: console.warn, error: console.error }[type];
|
logger.getLoggingFunction(type)(message);
|
||||||
log(message);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue