Improved log entries for actions

This commit is contained in:
Stefan Zermatten
2021-02-11 16:08:31 +02:00
parent 439eadf079
commit 92a5c1e6c3
5 changed files with 59 additions and 15 deletions

View File

@@ -1,4 +1,5 @@
import spendResources from '/imports/api/creature/actions/spendResources.js'
import embedInlineCalculations from '/imports/api/creature/computation/afterComputation/embedInlineCalculations.js';
export default function applyAction({prop, log}){
spendResources(prop);
@@ -6,4 +7,18 @@ export default function applyAction({prop, log}){
if (log.content.length){
log.content.push({name: prop.name});
}
if (prop.summary){
log.content.push({
details: embedInlineCalculations(
prop.summary, prop.summaryCalculations
),
});
}
if (prop.description){
log.content.push({
details: embedInlineCalculations(
prop.description, prop.descriptionCalculations
),
});
}
}

View File

@@ -36,18 +36,31 @@ export default function applyDamage({
damageType: prop.damageType,
amount: result,
});
insertCreatureLog.call({
log: {
text: `Recieved ${damageDealt} ${prop.damageType}${prop.damageType !== 'healing'? ' damage': ''}`,
creatureId: target._id,
}
});
if (target._id !== creature._id){
if (target._id === creature._id){
log.content.push({
result: damageDealt,
details: `${prop.damageType}${prop.damageType !== 'healing'? ' damage': ''}` +
details: `${prop.damageType}`+
`${prop.damageType !== 'healing' ? ' damage': ''} to self`,
});
} else {
log.content.push({
resultPrefix: 'Dealt ',
result: damageDealt,
details: `${prop.damageType}` +
`${prop.damageType !== 'healing'? ' damage': ''}` +
`${target.name && ' to '}${target.name}`,
});
insertCreatureLog.call({
log: {
content: [{
resultPrefix: 'Recieved ',
result: damageDealt,
details: `${prop.damageType}` +
`${prop.damageType !== 'healing'? ' damage': ''}`
}],
creatureId: target._id,
}
});
}
});
} else {

View File

@@ -0,0 +1,8 @@
export default function embedInlineCalculations(string, calculations){
if (!string) return '';
let index = 0;
return string.replace(/\{([^{}]*)\}/g, () => {
let comp = calculations && calculations[index++];
return comp && comp.result;
});
}