Rolls now work in actions
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
import applyAction from '/imports/api/creature/actions/applyAction.js';
|
import applyAction from '/imports/api/creature/actions/applyAction.js';
|
||||||
import applyAdjustment from '/imports/api/creature/actions/applyAdjustment.js';
|
import applyAdjustment from '/imports/api/creature/actions/applyAdjustment.js';
|
||||||
import applyAttack from '/imports/api/creature/actions/applyAttack.js';
|
import applyAttack from '/imports/api/creature/actions/applyAttack.js';
|
||||||
import applyDamage from '/imports/api/creature/actions/applyDamage.js';
|
|
||||||
import applyBuff from '/imports/api/creature/actions/applyBuff.js';
|
import applyBuff from '/imports/api/creature/actions/applyBuff.js';
|
||||||
|
import applyDamage from '/imports/api/creature/actions/applyDamage.js';
|
||||||
|
import applyRoll from '/imports/api/creature/actions/applyRoll.js';
|
||||||
import applyToggle from '/imports/api/creature/actions/applyToggle.js';
|
import applyToggle from '/imports/api/creature/actions/applyToggle.js';
|
||||||
|
|
||||||
function applyProperty(options){
|
function applyProperty(options){
|
||||||
@@ -42,7 +43,7 @@ function applyProperty(options){
|
|||||||
case 'toggle':
|
case 'toggle':
|
||||||
return applyToggle(options);
|
return applyToggle(options);
|
||||||
case 'roll':
|
case 'roll':
|
||||||
// applyRoll(options);
|
applyRoll(options);
|
||||||
break;
|
break;
|
||||||
case 'savingThrow':
|
case 'savingThrow':
|
||||||
// applySavingThrow(options);
|
// applySavingThrow(options);
|
||||||
|
|||||||
32
app/imports/api/creature/actions/applyRoll.js
Normal file
32
app/imports/api/creature/actions/applyRoll.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import evaluateString from '/imports/api/creature/computation/afterComputation/evaluateString.js';
|
||||||
|
|
||||||
|
export default function applyRoll({
|
||||||
|
prop,
|
||||||
|
creature,
|
||||||
|
actionContext,
|
||||||
|
log,
|
||||||
|
}){
|
||||||
|
let scope = {
|
||||||
|
...creature.variables,
|
||||||
|
...actionContext,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
var {result, errors} = evaluateString(prop.roll, scope, 'reduce');
|
||||||
|
actionContext[prop.variableName] = result;
|
||||||
|
log.content.push({
|
||||||
|
name: prop.name,
|
||||||
|
resultPrefix: prop.variableName + ' = ' + prop.roll + ' = ',
|
||||||
|
result,
|
||||||
|
});
|
||||||
|
if (errors.length) {
|
||||||
|
log.content.push({
|
||||||
|
error: errors.join(', '),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e){
|
||||||
|
log.content.push({
|
||||||
|
error: e.toString(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import evaluateString from '/imports/api/creature/computation/afterComputation/evaluateString.js';
|
import evaluateString from '/imports/api/creature/computation/afterComputation/evaluateString.js';
|
||||||
|
|
||||||
export default function applyDamage({
|
export default function applyToggle({
|
||||||
prop,
|
prop,
|
||||||
creature,
|
creature,
|
||||||
actionContext,
|
actionContext,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||||
|
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rolls are children to actions or other rolls, they are triggered with 0 or
|
* Rolls are children to actions or other rolls, they are triggered with 0 or
|
||||||
@@ -20,6 +21,17 @@ import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
|||||||
* child rolls are applied
|
* child rolls are applied
|
||||||
*/
|
*/
|
||||||
let RollSchema = new SimpleSchema({
|
let RollSchema = new SimpleSchema({
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
defaultValue: 'New Roll',
|
||||||
|
},
|
||||||
|
// The technical, lowercase, single-word name used in formulae
|
||||||
|
variableName: {
|
||||||
|
type: String,
|
||||||
|
regEx: VARIABLE_NAME_REGEX,
|
||||||
|
min: 2,
|
||||||
|
defaultValue: 'newRoll',
|
||||||
|
},
|
||||||
// The roll, can be simplified, but only computed in context
|
// The roll, can be simplified, but only computed in context
|
||||||
roll: {
|
roll: {
|
||||||
type: String,
|
type: String,
|
||||||
|
|||||||
@@ -1,5 +1,21 @@
|
|||||||
<template lang="html">
|
<template lang="html">
|
||||||
<div class="roll-form">
|
<div class="roll-form">
|
||||||
|
<div class="layout row wrap">
|
||||||
|
<text-field
|
||||||
|
label="Name"
|
||||||
|
:value="model.name"
|
||||||
|
:error-messages="errors.name"
|
||||||
|
@change="change('name', ...arguments)"
|
||||||
|
/>
|
||||||
|
<text-field
|
||||||
|
label="Variable name"
|
||||||
|
:value="model.variableName"
|
||||||
|
style="flex-basis: 300px;"
|
||||||
|
hint="Use this name in action formulae to refer to the result of this roll"
|
||||||
|
:error-messages="errors.variableName"
|
||||||
|
@change="change('variableName', ...arguments)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<text-field
|
<text-field
|
||||||
ref="focusFirst"
|
ref="focusFirst"
|
||||||
label="Roll"
|
label="Roll"
|
||||||
|
|||||||
Reference in New Issue
Block a user