Add some support for feature flags in addition to making roll modes work with custom chat formats
This commit is contained in:
parent
f238db1c4d
commit
444af027b3
7 changed files with 88 additions and 7 deletions
|
|
@ -24,6 +24,7 @@ async function rollDice() {
|
|||
],
|
||||
});
|
||||
const [ statBase, successThreshold, critsEnabled ] = Object.values(answers);
|
||||
const rollMode = game.settings.get(`core`, `rollMode`);
|
||||
|
||||
let successes = 0;
|
||||
const results = [];
|
||||
|
|
@ -39,12 +40,19 @@ async function rollDice() {
|
|||
}
|
||||
}
|
||||
|
||||
const m = new ChatMessage({
|
||||
const chatData = ChatMessage.applyRollMode(
|
||||
{
|
||||
title: `Dice Pool`,
|
||||
content: `Rolled: ${results.join(`, `)}<br>Successes: ${successes}`,
|
||||
});
|
||||
m.applyRollMode(game.settings.get(`core`, `rollMode`));
|
||||
ui.chat.postOne(m);
|
||||
content: `Rolled: ${taf.utils.hideMessageText(results.join(`, `))}<br>Successes: ${taf.utils.hideMessageText(successes)}`,
|
||||
flags: { taf: {
|
||||
rollModedContent: true,
|
||||
rollMode,
|
||||
} },
|
||||
},
|
||||
rollMode,
|
||||
);
|
||||
|
||||
await ChatMessage.implementation.create(chatData);
|
||||
}
|
||||
|
||||
rollDice()
|
||||
3
src/consts.mjs
Normal file
3
src/consts.mjs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export const FEATURE_FLAGS = Object.freeze({
|
||||
ROLLMODECONTENT: `Roll Mode Message Content`,
|
||||
});
|
||||
21
src/hooks/renderChatMessage.mjs
Normal file
21
src/hooks/renderChatMessage.mjs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { FEATURE_FLAGS } from "../consts.mjs";
|
||||
|
||||
Hooks.on(`renderChatMessage`, (msg, html) => {
|
||||
|
||||
// Short-Circuit when the flag isn't set for the message
|
||||
if (msg.getFlag(`taf`, `rollModedContent`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const featureFlags = game.settings.get(game.system.id, `flags`);
|
||||
const featureFlagEnabled = featureFlags.includes(FEATURE_FLAGS.ROLLMODECONTENT);
|
||||
|
||||
const contentElement = html.find(`.message-content`)[0];
|
||||
let content = contentElement.innerHTML;
|
||||
if (featureFlagEnabled && msg.blind && !game.user.isGM) {
|
||||
content = content.replace(/-=.*?=-/gm, `???`);
|
||||
} else {
|
||||
content = content.replace(/-=|=-/gm, ``);
|
||||
}
|
||||
contentElement.innerHTML = content;
|
||||
});
|
||||
|
|
@ -7,7 +7,12 @@ import { ItemProxy } from "./documents/Item/_proxy.mjs";
|
|||
// DataModel Imports
|
||||
import { PlayerData } from "./documents/Actor/Player/Model.mjs";
|
||||
|
||||
// Hook Imports
|
||||
import "./hooks/renderChatMessage.mjs";
|
||||
import "./hooks/hotReload.mjs";
|
||||
|
||||
// Misc Imports
|
||||
import "./utils/globalTaf.mjs";
|
||||
import "./utils/logger.mjs";
|
||||
import "./utils/DialogManager.mjs";
|
||||
import { registerCustomComponents } from "./components/_index.mjs";
|
||||
|
|
|
|||
|
|
@ -1 +1,24 @@
|
|||
export function registerWorldSettings() {};
|
||||
import { FEATURE_FLAGS } from "../consts.mjs";
|
||||
|
||||
export function registerWorldSettings() {
|
||||
game.settings.register(game.system.id, `flags`, {
|
||||
name: `Feature Flags`,
|
||||
hint: `World-based feature flags that are used to enable/disable specific behaviours`,
|
||||
scope: `world`,
|
||||
type: new foundry.data.fields.SetField(
|
||||
new foundry.data.fields.StringField(
|
||||
{
|
||||
empty: false,
|
||||
trim: true,
|
||||
options: Object.values(FEATURE_FLAGS),
|
||||
},
|
||||
),
|
||||
{
|
||||
required: false,
|
||||
initial: new Set(),
|
||||
},
|
||||
),
|
||||
config: true,
|
||||
requiresReload: true,
|
||||
});
|
||||
};
|
||||
|
|
|
|||
10
src/utils/feature_flags/rollModeMessageContent.mjs
Normal file
10
src/utils/feature_flags/rollModeMessageContent.mjs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { FEATURE_FLAGS } from "../../consts.mjs";
|
||||
|
||||
export function hideMessageText(content) {
|
||||
const featureFlags = game.settings.get(game.system.id, `flags`);
|
||||
const hideContent = featureFlags.includes(FEATURE_FLAGS.ROLLMODECONTENT);
|
||||
if (hideContent) {
|
||||
return `-=${content}=-`;
|
||||
}
|
||||
return content;
|
||||
};
|
||||
11
src/utils/globalTaf.mjs
Normal file
11
src/utils/globalTaf.mjs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { FEATURE_FLAGS } from "../consts.mjs";
|
||||
import { hideMessageText } from "./feature_flags/rollModeMessageContent.mjs";
|
||||
|
||||
globalThis.taf = Object.freeze({
|
||||
utils: {
|
||||
hideMessageText,
|
||||
},
|
||||
const: {
|
||||
FEATURE_FLAGS,
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue