Skip to content

Commit

Permalink
Fixes for foundry v12.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcglincy committed Jul 2, 2024
1 parent 13574a6 commit 6d45719
Show file tree
Hide file tree
Showing 33 changed files with 263 additions and 148 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 4.0.0

- Foundry v12 compatibility.

# 3.0.1

- Fix hub sheet defense rating not populating from frame.
Expand Down
27 changes: 12 additions & 15 deletions module/actor/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ import AddItemDialog from "../dialog/add-item-dialog.js";
import AttackDialog from "../dialog/attack-dialog.js";
import { diceSound, showDice } from "../dice.js";
import { regenerateCharacter, regenerateNpc } from "../generator.js";
import {
ITEMS_PACK,
TABLES_PACK,
documentFromPack,
simpleData,
tableFromPack,
} from "../packutils.js";
import { ITEMS_PACK, TABLES_PACK } from "../packs.js";
import { documentFromPack, simpleData } from "../packutils.js";

/**
* @extends {Actor}
Expand Down Expand Up @@ -41,7 +36,9 @@ export class DISActor extends Actor {
vision: true,
};
}
mergeObject(data.prototypeToken, defaults, { overwrite: false });
foundry.utils.mergeObject(data.prototypeToken, defaults, {
overwrite: false,
});
return super.create(data, options);
}

Expand Down Expand Up @@ -167,7 +164,7 @@ export class DISActor extends Actor {
`${d20Formula} + @abilities.${ability}.value`,
this.getRollData()
);
abilityRoll.evaluate({ async: false });
await abilityRoll.evaluate();
await showDice(abilityRoll);

const targetDR = 12;
Expand Down Expand Up @@ -296,7 +293,7 @@ export class DISActor extends Actor {
`${d20Formula} + @abilities.${attackAbility}.value`,
rollData
);
attackRoll.evaluate({ async: false });
await attackRoll.evaluate();
await showDice(attackRoll);

// use the active die result, in case of advantage/disadvantage
Expand Down Expand Up @@ -326,10 +323,10 @@ export class DISActor extends Actor {
}
damageText = `Damage: ${damageFormula}`;
damageRoll = new Roll(damageFormula);
damageRoll.evaluate({ async: false });
await damageRoll.evaluate();
// TODO: including crit die in max formula means crits are less likely to reduce target condition
const maxDamageRoll = new Roll(damageFormula);
maxDamageRoll.evaluate({ async: false, maximize: true });
await maxDamageRoll.evaluate({ maximize: true });
const isMaxDamage = damageRoll.total == maxDamageRoll.total;
if (isMaxDamage) {
maxDamageOutcome = game.i18n.localize("DIS.MaxDamageOutcome");
Expand Down Expand Up @@ -403,7 +400,7 @@ export class DISActor extends Actor {
"Morale"
)}`;
const moraleRoll = new Roll("2d6");
moraleRoll.evaluate({ async: false });
await moraleRoll.evaluate();
await showDice(moraleRoll);
let moraleOutcome;
if (moraleRoll.total > this.system.morale) {
Expand Down Expand Up @@ -433,7 +430,7 @@ export class DISActor extends Actor {
const cardTitle = `${game.i18n.localize("Reaction")}`;
const reactionText = "2D6";
const reactionRoll = new Roll("2d6");
reactionRoll.evaluate({ async: false });
await reactionRoll.evaluate();
await showDice(reactionRoll);
let reactionOutcome;
if (reactionRoll.total === 2) {
Expand Down Expand Up @@ -499,7 +496,7 @@ export class DISActor extends Actor {
flavor: `${game.i18n.localize("DIS.VoidCorruption")}?`,
});
if (roll.total <= this.system.voidPoints.value) {
const table = await tableFromPack(TABLES_PACK, "Void Corruption");
const table = await documentFromPack(TABLES_PACK, "Void Corruption");
await table.draw();
}
}
Expand Down
6 changes: 3 additions & 3 deletions module/actor/sheet/character-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import DISActorSheet from "./actor-sheet.js";
export class DISCharacterSheet extends DISActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["deathinspace", "sheet", "actor", "character"],
template: "systems/deathinspace/templates/actor/character-sheet.html",
width: 730,
Expand All @@ -33,8 +33,8 @@ export class DISCharacterSheet extends DISActorSheet {
}

/** @override */
getData() {
const superData = super.getData();
async getData() {
const superData = await super.getData();
const data = superData.data;
data.config = CONFIG.DIS;
this.prepareCharacterItems(data);
Expand Down
6 changes: 3 additions & 3 deletions module/actor/sheet/hub-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import DISActorSheet from "./actor-sheet.js";
export class DISHubSheet extends DISActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["deathinspace", "sheet", "actor", "hub"],
template: "systems/deathinspace/templates/actor/hub-sheet.html",
width: 730,
Expand All @@ -28,8 +28,8 @@ export class DISHubSheet extends DISActorSheet {
}

/** @override */
getData() {
const superData = super.getData();
async getData() {
const superData = await super.getData();
const data = superData.data;
const byName = (a, b) => (a.name > b.name ? 1 : b.name > a.name ? -1 : 0);
data.system.frame = data.items
Expand Down
6 changes: 3 additions & 3 deletions module/actor/sheet/npc-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import DISActorSheet from "./actor-sheet.js";
export class DISNpcSheet extends DISActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["deathinspace", "sheet", "actor", "npc"],
template: "systems/deathinspace/templates/actor/npc-sheet.html",
width: 730,
Expand Down Expand Up @@ -37,8 +37,8 @@ export class DISNpcSheet extends DISActorSheet {
}

/** @override */
getData() {
const superData = super.getData();
async getData() {
const superData = await super.getData();
const data = superData.data;
data.config = CONFIG.DIS;
this.prepareNpcItems(data);
Expand Down
12 changes: 6 additions & 6 deletions module/dice.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/**
* Add a show-dice promise to the given array if Dice So Nice is available.
*/
export const addShowDicePromise = (promises, roll) => {
export function addShowDicePromise(promises, roll) {
if (game.dice3d) {
// we pass synchronize=true so DSN dice appear on all players' screens
promises.push(game.dice3d.showForRoll(roll, game.user, true, null, false));
}
};
}

/**
* Show roll in Dice So Nice if it's available.
*/
export const showDice = async (roll) => {
export async function showDice(roll) {
if (game.dice3d) {
// we pass synchronize=true so DSN dice appear on all players' screens
await game.dice3d.showForRoll(roll, game.user, true, null, false);
}
};
}

/**
* Dice sound to use for ChatMessage.
* False if Dice So Nice is available.
*/
export const diceSound = () => {
export function diceSound() {
if (game.dice3d) {
// let Dice So Nice do it
return null;
} else {
return CONFIG.sounds.dice;
}
};
}
Loading

0 comments on commit 6d45719

Please sign in to comment.