Gestion des choix de combat par flags

Utiliser des flags sur les ChatMessage de choix de combat permet:

- de conserver les informations même après un refresh
- de simplifier un peu (pas besoin de gérer un stockage custom)
This commit is contained in:
Vincent Vandemeulebrouck
2022-01-29 23:33:31 +01:00
parent 3abaf4e944
commit c0442f607c
2 changed files with 43 additions and 118 deletions

View File

@ -1,5 +1,7 @@
import { Misc } from "./misc.js";
import { SYSTEM_SOCKET_ID } from "./constants.js";
import { SYSTEM_RDD, SYSTEM_SOCKET_ID } from "./constants.js";
export const MESSAGE_DATA = 'message-data';
/**
* Class providing helper methods to get the list of users, and
@ -160,4 +162,20 @@ export class ChatUtility {
}
}
static async setMessageData(chatMessage, key, data) {
if (data) {
await chatMessage.setFlag(SYSTEM_RDD, key, JSON.stringify(data));
}
}
static getMessageData(chatMessage, key) {
const json = chatMessage.getFlag(SYSTEM_RDD, key);
return json ? JSON.parse(json) : undefined;
}
static getChatMessage(event) {
const chatMessageId = $(event.currentTarget).closest('.chat-message').attr('data-message-id');
return game.messages.get(chatMessageId);
}
}