Added dice functions to parse engine
This commit is contained in:
@@ -4,7 +4,7 @@ const rollArray = {
|
||||
create({ values, diceSize, diceNum }) {
|
||||
return {
|
||||
parseType: 'rollArray',
|
||||
values,
|
||||
values: values.map(v => ({ value: v })),
|
||||
diceSize,
|
||||
diceNum,
|
||||
};
|
||||
@@ -16,10 +16,13 @@ const rollArray = {
|
||||
};
|
||||
},
|
||||
toString(node) {
|
||||
return `${node.diceNum || ''}d${node.diceSize} [ ${node.values.join(', ')} ]`;
|
||||
return `${node.diceNum || ''}d${node.diceSize} [${valuesToString(node.values)}]`;
|
||||
},
|
||||
reduce(node, scope, context) {
|
||||
const total = node.values.reduce((a, b) => a + b, 0);
|
||||
const total = node.values.reduce((a, b) => {
|
||||
if (b.disabled) return a;
|
||||
return a + b.value;
|
||||
}, 0);
|
||||
return {
|
||||
result: constant.create({
|
||||
value: total,
|
||||
@@ -29,4 +32,15 @@ const rollArray = {
|
||||
},
|
||||
}
|
||||
|
||||
function valuesToString(values) {
|
||||
return values.map(v => {
|
||||
let text = `${v.value}`;
|
||||
if (v.disabled) text = `~~${text}~~`;
|
||||
if (v.italics) text = `*${text}*`;
|
||||
if (v.bold) text = `**${text}**`;
|
||||
if (v.underline) text = `__${text}__`;
|
||||
return text;
|
||||
}).join(', ');
|
||||
}
|
||||
|
||||
export default rollArray;
|
||||
|
||||
Reference in New Issue
Block a user