Skip to content

Commit

Permalink
Fixed chat messages and duplicated apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Jul 1, 2024
1 parent 1fb5f35 commit a45b421
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 27 deletions.
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Item Piles Changelog

## Verison 3.0.1
## Version 3.0.2

- Fixed opening item pile interfaces would spawn duplicate windows instead of focusing existing interfaces
- Fixed item piles chat messages not working in v11

## Version 3.0.1

- Added Russian localization (thank you VirusNik21 on github!)
- Fixed players being unable to open item piles due to error
Expand Down
14 changes: 8 additions & 6 deletions src/API/chat-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import TradeAPI from "./trade-api.js";

export default class ChatAPI {

static CHAT_MESSAGE_STYLES = CONSTANTS.IS_V12 ? CONST.CHAT_MESSAGE_STYLES : CONST.CHAT_MESSAGE_TYPES;

static initialize() {

Helpers.hooks.on("preCreateChatMessage", this._preCreateChatMessage.bind(this));
Expand Down Expand Up @@ -288,7 +290,7 @@ export default class ChatAPI {

return this._createNewChatMessage(userId, {
user: game.user.id,
type: CONST.CHAT_MESSAGE_STYLES.OTHER,
type: ChatAPI.CHAT_MESSAGE_STYLES.OTHER,
content: chatCardHtml,
flavor: "Item Piles",
speaker: ChatMessage.getSpeaker({ alias: game.user.name }),
Expand Down Expand Up @@ -367,7 +369,7 @@ export default class ChatAPI {

return this._createNewChatMessage(userId, {
user: game.user.id,
type: CONST.CHAT_MESSAGE_STYLES.OTHER,
type: ChatAPI.CHAT_MESSAGE_STYLES.OTHER,
content: chatCardHtml,
flavor: "Item Piles",
speaker: ChatMessage.getSpeaker({ alias: game.user.name })
Expand All @@ -389,7 +391,7 @@ export default class ChatAPI {

return this._createNewChatMessage(game.user.id, {
user: game.user.id,
type: CONST.CHAT_MESSAGE_STYLES.OTHER,
type: ChatAPI.CHAT_MESSAGE_STYLES.OTHER,
content: chatCardHtml,
flavor: "Item Piles",
speaker: ChatMessage.getSpeaker({ alias: game.user.name }),
Expand Down Expand Up @@ -432,7 +434,7 @@ export default class ChatAPI {

return this._createNewChatMessage(game.user.id, {
user: game.user.id,
type: isPrivate ? CONST.CHAT_MESSAGE_STYLES.WHISPER : CONST.CHAT_MESSAGE_STYLES.OTHER,
type: isPrivate ? CONST.CHAT_MESSAGE_STYLES.WHISPER : ChatAPI.CHAT_MESSAGE_STYLES.OTHER,
content: chatCardHtml,
flavor: "Item Piles" + (isPrivate ? ": " + game.i18n.localize("ITEM-PILES.Chat.PrivateTrade") : ""),
speaker: ChatMessage.getSpeaker({ alias: game.user.name }),
Expand Down Expand Up @@ -478,7 +480,7 @@ export default class ChatAPI {

return this._createNewChatMessage(userId, {
user: game.user.id,
type: CONST.CHAT_MESSAGE_STYLES.OTHER,
type: ChatAPI.CHAT_MESSAGE_STYLES.OTHER,
content: chatCardHtml,
flavor: "Item Piles",
speaker: ChatMessage.getSpeaker({ alias: game.user.name }),
Expand Down Expand Up @@ -522,7 +524,7 @@ export default class ChatAPI {

return this._createNewChatMessage(game.user.id, {
user: game.user.id,
type: CONST.CHAT_MESSAGE_STYLES.OTHER,
type: ChatAPI.CHAT_MESSAGE_STYLES.OTHER,
content: chatCardHtml,
flavor: "Item Piles",
speaker: ChatMessage.getSpeaker({ alias: game.user.name }),
Expand Down
8 changes: 4 additions & 4 deletions src/applications/item-editor/item-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class ItemEditor extends SvelteApplication {
let title = game.i18n.format("ITEM-PILES.Applications.ItemEditor.Title", { item_name: item.name })
if (options.extraTitle) title += options.extraTitle;
super({
id: `item-pile-item-editor-${item.id}-${foundry.utils.randomID()}`,
id: `item-pile-item-editor-${item.uuid}-${foundry.utils.randomID()}`,
title,
svelte: {
class: ItemEditorShell,
Expand All @@ -30,12 +30,12 @@ export default class ItemEditor extends SvelteApplication {
})
}

static getActiveApp(id) {
return getActiveApps(`item-pile-item-editor-${id}`, true);
static getActiveApp(item) {
return getActiveApps(`item-pile-item-editor-${item.uuid}`, true);
}

static async show(item = false, options = {}, dialogData = {}) {
const app = this.getActiveApp(item.uuid);
const app = this.getActiveApp(item);
if (app) return app.render(false, { focus: true });
return new Promise((resolve) => {
options.resolve = resolve;
Expand Down
8 changes: 4 additions & 4 deletions src/applications/item-pile-config/item-pile-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class ItemPileConfig extends SvelteApplication {
constructor(pileActor, options = {}) {

super({
id: `item-pile-config-${pileActor.id}-${foundry.utils.randomID()}`,
id: `item-pile-config-${pileActor.uuid}-${foundry.utils.randomID()}`,
title: game.i18n.format("ITEM-PILES.Applications.ItemPileConfig.Title", { actor_name: pileActor.name }),
svelte: {
class: ItemPileConfigShell,
Expand All @@ -31,13 +31,13 @@ export default class ItemPileConfig extends SvelteApplication {
})
}

static getActiveApp(id) {
return getActiveApps(`item-pile-config-${id}`, true)
static getActiveApp(source) {
return getActiveApps(`item-pile-config-${source.uuid}`, true)
}

static async show(target, options = {}, dialogData = {}) {
const targetActor = Utilities.getActor(target);
const app = this.getActiveApp(targetActor.uuid);
const app = this.getActiveApp(targetActor);
if (app) return app.render(false, { focus: true });
return new Promise((resolve) => {
options.resolve = resolve;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class ItemPileInventoryApp extends SvelteApplication {
*/
constructor(actor, recipient, options = {}, dialogData = {}) {
super({
id: `item-pile-inventory-${actor?.token?.id ?? actor.id}-${foundry.utils.randomID()}`,
id: `item-pile-inventory-${actor?.token?.uuid ?? actor.uuid}-${foundry.utils.randomID()}`,
title: actor.name,
svelte: {
class: ItemPileInventoryShell,
Expand Down Expand Up @@ -50,16 +50,16 @@ export default class ItemPileInventoryApp extends SvelteApplication {
});
}

static getActiveApps(id) {
return Helpers.getActiveApps(`item-pile-inventory-${id}`);
static getActiveApps(source) {
return Helpers.getActiveApps(`item-pile-inventory-${source?.token?.uuid ?? source.uuid}`);
}

static async show(source, recipient = false, options = {}, dialogData = {}) {
source = Utilities.getActor(source);
recipient = Utilities.getActor(recipient);
const result = Helpers.hooks.call(CONSTANTS.HOOKS.PRE_OPEN_INTERFACE, source, recipient, options, dialogData);
if (result === false) return;
const apps = this.getActiveApps(source?.token?.uuid ?? source.uuid);
const apps = this.getActiveApps(source);
if (apps.length) {
for (let app of apps) {
app.render(false, { focus: true });
Expand Down
8 changes: 4 additions & 4 deletions src/applications/merchant-app/merchant-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class MerchantApp extends SvelteApplication {
constructor(merchant, recipient = false, options = {}, dialogData = {}) {
super({
title: `Merchant: ${merchant.name}`,
id: `item-pile-merchant-${merchant.id}-${foundry.utils.randomID()}`,
id: `item-pile-merchant-${merchant.uuid}-${foundry.utils.randomID()}`,
svelte: {
class: MerchantAppShell,
target: document.body,
Expand Down Expand Up @@ -40,16 +40,16 @@ export default class MerchantApp extends SvelteApplication {
});
}

static getActiveApp(id) {
return Helpers.getActiveApps(`item-pile-merchant-${id}`, true);
static getActiveApp(source) {
return Helpers.getActiveApps(`item-pile-merchant-${source.uuid}`, true);
}

static async show(merchant, recipient = false, options = {}, dialogData = {}) {
const merchantActor = Utilities.getActor(merchant);
const recipientActor = Utilities.getActor(recipient);
const result = Helpers.hooks.call(CONSTANTS.HOOKS.PRE_OPEN_INTERFACE, merchantActor, recipientActor, options, dialogData);
if (result === false) return;
const app = this.getActiveApp(merchant.uuid);
const app = this.getActiveApp(merchant);
if (app) return app.render(false, { focus: true });
return new Promise((resolve) => {
options.resolve = resolve;
Expand Down
8 changes: 4 additions & 4 deletions src/applications/vault-app/vault-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class VaultApp extends SvelteApplication {
*/
constructor(actor, recipient, options = {}, dialogData = {}) {
super({
id: `item-pile-vault-${actor?.token?.id ?? actor.id}-${foundry.utils.randomID()}`,
id: `item-pile-vault-${actor?.token?.uuid ?? actor.uuid}-${foundry.utils.randomID()}`,
title: actor.name,
svelte: {
class: VaultShell,
Expand Down Expand Up @@ -59,8 +59,8 @@ export default class VaultApp extends SvelteApplication {
return this.svelte.applicationShell.store;
}

static getActiveApps(id = "") {
return Helpers.getActiveApps(`item-pile-vault-${id}`);
static getActiveApps(source) {
return Helpers.getActiveApps(`item-pile-vault-${source?.token?.uuid ?? source.uuid}`);
}

static async show(source, recipient = false, options = {}, dialogData = {}) {
Expand All @@ -77,7 +77,7 @@ export default class VaultApp extends SvelteApplication {
}));
return;
}
const apps = this.getActiveApps(source?.token?.uuid ?? source.uuid);
const apps = this.getActiveApps(source);
if (apps.length) {
for (let app of apps) {
app.render(false, { focus: true });
Expand Down
1 change: 1 addition & 0 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const CONSTANTS = {

MODULE_NAME: module_name,
PATH: module_path,
IS_V12: false,

ACTOR_DELTA_PROPERTY: "delta",

Expand Down
1 change: 1 addition & 0 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Hooks.once("init", async () => {
window.ItemPiles = {
API: API
};
CONSTANTS.IS_V12 = game.release.generation >= 12;

});

Expand Down

0 comments on commit a45b421

Please sign in to comment.