Big improvements in UX for tabletop actions
This commit is contained in:
@@ -27,10 +27,12 @@ export default async function writeActionResults(action: EngineAction) {
|
||||
content: logContents,
|
||||
creatureId: action.creatureId,
|
||||
tabletopId: action.tabletopId,
|
||||
actionId: action._id,
|
||||
});
|
||||
|
||||
// Write the bulk updates
|
||||
const bulkWritePromise = bulkWrite(creaturePropUpdates, CreatureProperties);
|
||||
// Write the bulk updates, force them to sequential mode means we immediately get the results
|
||||
// in the subscription, rather than waiting for oplog tailing to catch up
|
||||
const bulkWritePromise = bulkWrite(creaturePropUpdates, CreatureProperties, true);
|
||||
|
||||
await Promise.all([engineActionPromise, logPromise, bulkWritePromise]);
|
||||
|
||||
|
||||
@@ -116,24 +116,27 @@ export default async function applyDamagePropTask(
|
||||
if (increment > currentValue && !targetProp.ignoreLowerLimit) increment = currentValue;
|
||||
// Can't decrease damage below zero
|
||||
if (-increment > currentDamage && !targetProp.ignoreUpperLimit) increment = -currentDamage;
|
||||
damage = currentDamage + increment;
|
||||
newValue = targetProp.total - damage;
|
||||
// Write the results
|
||||
result.mutations.push({
|
||||
targetIds: [targetId],
|
||||
updates: [{
|
||||
propId: targetProp._id,
|
||||
inc: { damage: increment, value: -increment },
|
||||
type: targetProp.type,
|
||||
}],
|
||||
contents: [{
|
||||
name: increment >= 0 ? 'Attribute damaged' : 'Attribute restored',
|
||||
value: `${numberToSignedString(-increment)} ${getPropertyTitle(targetProp)}`,
|
||||
inline: true,
|
||||
...task.silent && { silenced: true },
|
||||
}]
|
||||
});
|
||||
if (targetId === action.creatureId) setScope(result, targetProp, newValue, damage);
|
||||
// Only increment if the increment is non-zero
|
||||
if (increment !== 0) {
|
||||
damage = currentDamage + increment;
|
||||
newValue = targetProp.total - damage;
|
||||
// Write the results
|
||||
result.mutations.push({
|
||||
targetIds: [targetId],
|
||||
updates: [{
|
||||
propId: targetProp._id,
|
||||
inc: { damage: increment, value: -increment },
|
||||
type: targetProp.type,
|
||||
}],
|
||||
contents: [{
|
||||
name: increment >= 0 ? 'Attribute damaged' : 'Attribute restored',
|
||||
value: `${numberToSignedString(-increment)} ${getPropertyTitle(targetProp)}`,
|
||||
inline: true,
|
||||
...task.silent && { silenced: true },
|
||||
}]
|
||||
});
|
||||
if (targetId === action.creatureId) setScope(result, targetProp, newValue, damage);
|
||||
}
|
||||
}
|
||||
await applyTriggers(action, targetProp, [targetId], 'damageTriggerIds.after', userInput);
|
||||
await applyTriggers(action, targetProp, [targetId], 'damageTriggerIds.afterChildren', userInput);
|
||||
|
||||
Reference in New Issue
Block a user