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;
});
}

View File

@@ -6,6 +6,7 @@
<script>
import MarkdownText from '/imports/ui/components/MarkdownText.vue';
import embedInlineCalculations from '/imports/api/creature/computation/afterComputation/embedInlineCalculations.js';
export default {
components: {
@@ -26,13 +27,8 @@ export default {
},
computed: {
computedValue(){
if (!this.string) return '';
if (this.inactive) return this.string;
let index = 0;
return this.string.replace(/\{([^{}]*)\}/g, () => {
let comp = this.calculations && this.calculations[index++];
return comp && comp.result;
});
return embedInlineCalculations(this.string, this.calculations);
}
}
}

View File

@@ -30,14 +30,23 @@
v-if="content.result"
class="subheading font-weight-bold mx-1"
>{{ content.result }}</span>
{{ content.details }}
<markdown-text
v-if="content.details"
class="details"
:markdown="content.details"
/>
</div>
</v-card-text>
</v-card>
</template>
<script>
import MarkdownText from '/imports/ui/components/MarkdownText.vue';
export default {
components: {
MarkdownText,
},
props: {
model: {
type: Object,
@@ -51,4 +60,7 @@ export default {
.content-line {
min-height: 24px;
}
.content-line .details {
display: inline-block;
}
</style>