Skip to content

Commit

Permalink
Merge pull request #125 from Anthial/v12-compatibility
Browse files Browse the repository at this point in the history
Added basic Foundry V12 compatibility.
  • Loading branch information
PatrickBauer authored Dec 1, 2024
2 parents 0f94654 + 8a911b5 commit 5e35a77
Show file tree
Hide file tree
Showing 31 changed files with 443 additions and 405 deletions.
632 changes: 332 additions & 300 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"terser-webpack-plugin": "^5.3.9",
"ts-loader": "^9.4.4",
"typescript": "^5.1.6",
"webpack": "^5.88.2",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-import-glob-loader": "^1.6.3"
Expand Down
4 changes: 2 additions & 2 deletions src/module/actor/FateActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class FateActor extends Actor {
data.token = data.token || {};

// Set basic token data for newly created actors.
mergeObject(
foundry.utils.mergeObject(
data.token,
{
vision: true,
Expand All @@ -39,7 +39,7 @@ export class FateActor extends Actor {
);

// Overwrite specific token data (used for template actors)
mergeObject(
foundry.utils.mergeObject(
data.token,
{
img: CONST.DEFAULT_TOKEN,
Expand Down
6 changes: 3 additions & 3 deletions src/module/actor/sheets/CharacterSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class CharacterSheet extends ActorSheet<CharacterSheetOptions> {
};

// @ts-ignore
return mergeObject(super.defaultOptions, sheetOptions);
return foundry.utils.mergeObject(super.defaultOptions, sheetOptions);
}

get template(): string {
Expand Down Expand Up @@ -90,7 +90,7 @@ export class CharacterSheet extends ActorSheet<CharacterSheetOptions> {

// Add actor, actor data and item
// @ts-ignore
data.actor = duplicate(this.actor);
data.actor = foundry.utils.duplicate(this.actor);
data.data = data.actor.system;
data.items = this.actor.items.map((item) => item);
data.items.sort((a: ItemData, b: ItemData) => (a.sort || 0) - (b.sort || 0));
Expand All @@ -108,7 +108,7 @@ export class CharacterSheet extends ActorSheet<CharacterSheetOptions> {

// Allow every item type to add data to the actorsheet
for (const itemType in CONFIG.FateX.itemClasses) {
data = CONFIG.FateX.itemClasses[itemType].getActorSheetData(data, this);
data = await CONFIG.FateX.itemClasses[itemType].getActorSheetData(data, this);
}

return data;
Expand Down
6 changes: 3 additions & 3 deletions src/module/actor/sheets/GroupSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class GroupSheet extends ActorSheet {
* Sets the default options for every actor group sheet
*/
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["fatex fatex-sheet sheet actor_group_overview actor_group_overview--front"],
resizable: true,
template: "/systems/fatex/templates/actor/group.hbs",
Expand All @@ -39,7 +39,7 @@ export class GroupSheet extends ActorSheet {
});
}

getData() {
async getData() {
// Basic fields and flags
const data: any = {
owner: this.actor.isOwner,
Expand All @@ -52,7 +52,7 @@ export class GroupSheet extends ActorSheet {
};

// Add actor, actor data and item
data.actor = duplicate(this.actor);
data.actor = foundry.utils.duplicate(this.actor);
data.data = data.actor;
data.items = this.actor.items.map((i) => foundry.utils.duplicate(i));
data.items.sort((a: ItemData, b: ItemData) => (a.sort || 0) - (b.sort || 0));
Expand Down
6 changes: 3 additions & 3 deletions src/module/actor/sheets/InlineActorSheetFate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GroupSheet } from "./GroupSheet";

export class InlineActorSheetFate extends CharacterSheet {
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
return foundry.utils.mergeObject(super.defaultOptions, {
group: undefined,
width: "auto",
height: "auto",
Expand All @@ -17,8 +17,8 @@ export class InlineActorSheetFate extends CharacterSheet {
});
}

getData(_options?: Application.RenderOptions) {
const data = super.getData();
async getData(_options?: Application.RenderOptions) {
const data = await super.getData();

if (this.options.referenceID) {
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion src/module/applications/sheet-setup/SheetSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class SheetSetup extends FormApplication<any, any, FateActor> {
}

static get defaultOptions() {
return mergeObject(super.defaultOptions, {
return foundry.utils.mergeObject(super.defaultOptions, {
title: game.i18n.localize("FAx.Apps.Setup.Title"),
template: "/systems/fatex/templates/apps/sheet-setup.hbs",
resizable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ActorDataProperties } from "@league-of-foundry-developers/foundry-vtt-t

export class TemplateActorPicker extends TemplateActorSettings {
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
return foundry.utils.mergeObject(super.defaultOptions, {
title: game.i18n.format("SIDEBAR.Create", { type: game.i18n.localize("DOCUMENT.Actor") }),
template: "/systems/fatex/templates/apps/template-actors-picker.hbs",
id: "template-actor-picker",
Expand All @@ -16,8 +16,8 @@ export class TemplateActorPicker extends TemplateActorSettings {
});
}

getData() {
const data = super.getData();
async getData() {
const data = await super.getData();

// @ts-ignore
data.AppTitle = game.i18n.format("SIDEBAR.Create", { type: game.i18n.localize("DOCUMENT.Actor") });
Expand Down Expand Up @@ -69,7 +69,7 @@ export class TemplateActorPicker extends TemplateActorSettings {
e.stopPropagation();

const data = e.currentTarget.dataset;
const template = duplicate(game.actors?.get(data.template));
const template = foundry.utils.duplicate(game.actors?.get(data.template));
const fatexFlags = template.flags?.fatex as Record<string, unknown>;

// Add current template as a flag for later use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SheetSetup } from "../sheet-setup/SheetSetup";

export class TemplateActorSettings extends FormApplication<any, any, any> {
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
return foundry.utils.mergeObject(super.defaultOptions, {
title: game.i18n.localize("FAx.Settings.Templates.App.Title"),
template: "/systems/fatex/templates/apps/template-actors.hbs",
id: "template-actors",
Expand All @@ -13,7 +13,7 @@ export class TemplateActorSettings extends FormApplication<any, any, any> {
});
}

getData() {
async getData() {
const filteredActors = duplicate(game.actors?.filter((actor) => (actor as FateActor).isTemplateActor) as Record<any, any>[]);

filteredActors.forEach((actorDocument) => {
Expand Down
2 changes: 1 addition & 1 deletion src/module/chat/FateChatCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class FateChatCard extends FateChatCardDataModel {
const chatData = {
user: game.user?.id,
speaker: this.speaker,
type: CONST.CHAT_MESSAGE_TYPES.ROLL,
rollMode: game.settings.get("core", "rollMode"),
content: content,
flags: {
Expand All @@ -30,6 +29,7 @@ export class FateChatCard extends FateChatCardDataModel {
},
};

ChatMessage.applyRollMode(chatData, game.settings.get("core", "rollMode"))
const message = await ChatMessage.create(chatData);

this.updateSource({ messageId: message.id });
Expand Down
8 changes: 5 additions & 3 deletions src/module/chat/FateRoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export class FateRoll extends FateRollDataModel {
}

const rollMode = this.options.rollmode ?? ROLL_MODES["4dF"];
const roll = new Roll(rollMode).roll({ async: false });
const rollThrough = new Roll(rollMode);
const roll = await rollThrough.evaluate();

if (this.is2d6Roll) {
this.updateSource({
Expand All @@ -59,7 +60,8 @@ export class FateRoll extends FateRollDataModel {
}

async rollMagic(userId = "", magicCount: number) {
const roll = new Roll(`${magicCount}dM + ${4 - magicCount}dF`).roll({ async: false });
const rollThrough = new Roll(`${magicCount}dM + ${4 - magicCount}dF`);
const roll = await rollThrough.evaluate();

this.updateSource({
faces: [...roll.terms[0].results, ...roll.terms[2].results].map((r) => r.count ?? r.result),
Expand Down Expand Up @@ -108,7 +110,7 @@ export class FateRoll extends FateRollDataModel {
}

get ladder() {
const total = Math.clamped(this.total, -4, 8);
const total = Math.clamp(this.total, -4, 8);
const totalString = (total < 0 ? "-" : "+").concat(Math.abs(total).toString());

return game.i18n.localize(`FAx.Global.Ladder.${totalString}`);
Expand Down
8 changes: 4 additions & 4 deletions src/module/components/Automation/Automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Automation extends BaseComponent {
html.find(".fatex-js-remove-skill-reference").on("click", (e) => this._onRemoveReference.call(this, e, sheet));
}

static getSheetData(sheetData, sheet) {
static async getSheetData(sheetData, sheet) {
const skillReferences = this.getSkillReferences(sheet.document).map((ref, index) => {
ref.index = index;
return ref;
Expand Down Expand Up @@ -154,7 +154,7 @@ export class Automation extends BaseComponent {
*/
static async addSkillReference(document, type = TYPES.STATUS) {
const currentReferences = this.getSkillReferences(document);
const references = duplicate(currentReferences);
const references = foundry.utils.duplicate(currentReferences);

references.push({
type: type,
Expand All @@ -173,7 +173,7 @@ export class Automation extends BaseComponent {

static async changeSkillReference(document, index, field, value) {
const currentReferences = this.getSkillReferences(document);
const references = duplicate(currentReferences);
const references = foundry.utils.duplicate(currentReferences);
const reference = references[index];

// Change field on reference to new value
Expand Down Expand Up @@ -242,7 +242,7 @@ export class Automation extends BaseComponent {
}

static getActorSkillByName(actor, skillId) {
const actorData = duplicate(actor);
const actorData = foundry.utils.duplicate(actor);
const items = actorData.items;

// Filter single actors skills by id
Expand Down
2 changes: 1 addition & 1 deletion src/module/components/BaseComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class BaseComponent {
/**
* Allows each component to add data to sheets.
*/
static getSheetData(sheetData, _sheet) {
static async getSheetData(sheetData, _sheet) {
return sheetData;
}
}
8 changes: 4 additions & 4 deletions src/module/components/SubItems/SubItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ export class SubItems extends BaseComponent {
});
}

static getSheetData(sheetData, _sheet) {
static async getSheetData(sheetData, _sheet) {
// @ts-ignore
//sheetData.subItems = game.items?.contents.filter((item) => item.data.type == "extra" && item.system.parentID == _sheet.document.id);
//console.log(sheetData);
sheetData.subItems = game.items?.contents.filter((item) => item.system.type == "extra" && item.system.parentID == _sheet.document.id);
console.log(sheetData);
return sheetData;
}

static _onCreateSubItem(_event, sheet) {
const extraData = {
type: "extra",
name: "Test-Sub-Item",
data: {
system: {
description: "",
parentID: sheet.document.id,
},
Expand Down
4 changes: 2 additions & 2 deletions src/module/features/MagicSystem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-nocheck
export class MagicDie extends FateDie {
export class MagicDie extends foundry.dice.terms.FateDie {
static DENOMINATION = "m";

roll({ minimize = false, maximize = false } = {}) {
Expand All @@ -14,7 +14,7 @@ export class MagicDie extends FateDie {
return roll;
}
}

export class MagicSystem {
static hooks() {
Hooks.once("init", () => {
Expand Down
7 changes: 5 additions & 2 deletions src/module/item/BaseItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export abstract class BaseItem {
/**
* Allows each item to add data to its own sheet.
*/
static getSheetData(sheetData, _item) {
static async getSheetData(sheetData, _item) {
return sheetData;
}

/**
* Allows each item to add data to its owners actorsheet.
*/
static getActorSheetData(sheetData, _actor) {
static async getActorSheetData(sheetData, _actor) {
return sheetData;
}

Expand Down Expand Up @@ -76,6 +76,9 @@ export abstract class BaseItem {
e.stopPropagation();

const data = e.currentTarget.dataset;
sheet.actor.items.map((item) => {
console.log("SHEET ITEMS" + item)
})
const item = sheet.actor.items.get(data.item);

if (item) {
Expand Down
8 changes: 4 additions & 4 deletions src/module/item/ItemSheetFate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export class ItemSheetFate extends ItemSheet {
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["fatex", "fatex-sheet", "fatex-sheet--item", "sheet"],
scrollY: [".fatex-desk__content"],
width: 575,
});
}

getData() {
async getData() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let data: any = super.getData();

Expand All @@ -20,12 +20,12 @@ export class ItemSheetFate extends ItemSheet {
data.isOwnedBy = this.actor ? this.actor.name : false;

// Let every item type manipulate its own sheet data
data = CONFIG.FateX.itemClasses[this.item.type]?.getSheetData(data, this) || data;
data = await CONFIG.FateX.itemClasses[this.item.type]?.getSheetData(data, this) || data;

// Let every component manipulate an items' sheet data
for (const sheetComponent in CONFIG.FateX.sheetComponents.item) {
if (Object.prototype.hasOwnProperty.call(CONFIG.FateX.sheetComponents.item, sheetComponent)) {
data = CONFIG.FateX.sheetComponents.item[sheetComponent].getSheetData(data, this);
data = await CONFIG.FateX.sheetComponents.item[sheetComponent].getSheetData(data, this);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/module/item/consequence/ConsequenceItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ConsequenceItem extends BaseItem {
if (item) {
item.update(
{
"data.active": !item.system.active,
"system.active": !item.system.active,
},
{}
);
Expand All @@ -65,7 +65,7 @@ export class ConsequenceItem extends BaseItem {
if (item) {
item.update(
{
"data.value": input,
"system.value": input,
},
{}
);
Expand Down
11 changes: 6 additions & 5 deletions src/module/item/extra/ExtraItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ export class ExtraItem extends StuntItem {
return "extra";
}

static getActorSheetData(sheetData) {
sheetData = StuntItem.getActorSheetData(sheetData);
static async getActorSheetData(sheetData) {
sheetData = await StuntItem.getActorSheetData(sheetData);

for (const extra of sheetData.extras) {
// @ts-ignore
extra.system.description = TextEditor.enrichHTML(extra.system.description, { async: false });
extra.system.description = await TextEditor.enrichHTML(extra.system.description, { async: true });
}

return sheetData;
}

static getSheetData(sheetData) {
static async getSheetData(sheetData) {
// @ts-ignore
sheetData.enrichedDescription = TextEditor.enrichHTML(sheetData.system.description, { async: false });
sheetData.enrichedDescription = await TextEditor.enrichHTML(sheetData.system.description, { async: true });
}

}
Loading

0 comments on commit 5e35a77

Please sign in to comment.