Hid silenced content from the logs

This commit is contained in:
Thaum Rystra
2024-10-30 17:53:39 +02:00
parent 2a5a97f04a
commit 84282cef6c
23 changed files with 163 additions and 46 deletions

View File

@@ -26,7 +26,13 @@ export default class TaskResult {
this.scope = {};
}
// Appends the log content to the latest mutation
appendLog(content: LogContent, targetIds: string[]) {
appendLog(content: LogContent & { silenced: boolean }, targetIds: string[]) {
// Create a shallow copy of the content
const logContent: LogContent = { ...content };
// remove false silenced properties
if (!logContent.silenced) {
delete logContent.silenced;
}
if (!this.mutations.length) {
this.mutations.push({ targetIds, contents: [] });
}
@@ -34,7 +40,7 @@ export default class TaskResult {
if (!latestMutation.contents) {
latestMutation.contents = [];
}
latestMutation.contents.push(content);
latestMutation.contents.push(logContent);
}
appendParserContextErrors(context: Context, targetIds) {
if (!context.errors?.length) return;

View File

@@ -22,6 +22,7 @@ export default async function applySpellProperty(
result.appendLog({
name: 'Error casting spell',
value: 'No spell was selected',
silenced: false,
}, [action.creatureId]);
return;
}
@@ -32,6 +33,7 @@ export default async function applySpellProperty(
result.appendLog({
name: 'Error casting spell',
value: 'The chosen spell was not found',
silenced: false,
}, [action.creatureId]);
return;
}
@@ -80,7 +82,8 @@ function logCastingMessage(slotLevel: number, castOptions, result: TaskResult, p
// Post the message
if (message) {
result.appendLog({
name: `Casting at level ${slotLevel}`
name: `Casting at level ${slotLevel}`,
silenced: prop.silent,
}, targetIds);
}
}

View File

@@ -74,7 +74,7 @@ export default async function applyCheckTask(
name: checkName,
inline: true,
...dc !== null && { value: `DC **${dc}**` },
...task?.silent && { silenced: task.silent }
silenced: task.silent ?? false,
}, [targetId]);
// Roll the dice
@@ -108,7 +108,7 @@ export default async function applyCheckTask(
name: rollName,
value: `${resultPrefix}\n**${totalValue}**`,
inline: true,
...task?.silent && { silenced: task.silent }
silenced: task.silent ?? false,
}, [targetId]);
// After check triggers

View File

@@ -73,7 +73,7 @@ export default async function applyDamagePropTask(
value: `${statName}${operation === 'set' ? ' set to' : ''}` +
` ${value}`,
inline: true,
...task.silent && { silenced: true },
silenced: task.silent ?? false,
}, task.targetIds);
}

View File

@@ -20,10 +20,16 @@ export default async function applyResetTask(
// Print a title for rest events
switch (task.eventName) {
case 'shortRest':
result.appendLog({ name: 'Short Rest' }, task.targetIds);
result.appendLog({
name: 'Short Rest',
silenced: task.silent ?? false,
}, task.targetIds);
break;
case 'longRest':
result.appendLog({ name: 'Long Rest' }, task.targetIds);
result.appendLog({
name: 'Long Rest',
silenced: task.silent ?? false,
}, task.targetIds);
break;
}