Fixed rolling straight to the log to use new parser interface
This commit is contained in:
@@ -4,11 +4,8 @@ import LogContentSchema from '/imports/api/creature/log/LogContentSchema.js';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import {assertEditPermission} from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||
import {
|
||||
parse,
|
||||
CompilationContext,
|
||||
prettifyParseError
|
||||
} from '/imports/parser/parser.js';
|
||||
import {parse, prettifyParseError} from '/imports/parser/parser.js';
|
||||
import resolve, { toString } from '/imports/parser/resolve.js';
|
||||
const PER_CREATURE_LOG_LIMIT = 100;
|
||||
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||
|
||||
@@ -175,26 +172,29 @@ const logRoll = new ValidatedMethod({
|
||||
logContent.push({name: 'Parse Error', value: error});
|
||||
}
|
||||
if (parsedResult) try {
|
||||
let rollContext = new CompilationContext();
|
||||
let compiled = parsedResult.compile(creature.variables, rollContext);
|
||||
let compiledString = compiled.toString();
|
||||
let {
|
||||
result: compiled,
|
||||
context
|
||||
} = resolve('compile', parsedResult, creature.variables);
|
||||
const compiledString = toString(compiled);
|
||||
if (!equalIgnoringWhitespace(compiledString, roll)) logContent.push({
|
||||
value: roll
|
||||
});
|
||||
logContent.push({
|
||||
value: compiledString
|
||||
});
|
||||
let rolled = compiled.roll(creature.variables, rollContext);
|
||||
let rolledString = rolled.toString();
|
||||
let {result: rolled} = resolve('roll', compiled, creature.variables, context);
|
||||
let rolledString = toString(rolled);
|
||||
if (rolledString !== compiledString) logContent.push({
|
||||
value: rolled.toString()
|
||||
});
|
||||
let result = rolled.reduce(creature.variables, rollContext);
|
||||
let resultString = result.toString();
|
||||
let {result} = resolve('reduce', rolled, creature.variables, context);
|
||||
let resultString = toString(result);
|
||||
if (resultString !== rolledString) logContent.push({
|
||||
value: resultString
|
||||
});
|
||||
} catch (e){
|
||||
console.error(e);
|
||||
logContent = [{name: 'Calculation error'}];
|
||||
}
|
||||
const log = {
|
||||
|
||||
@@ -37,6 +37,7 @@ import CreatureLogs, { logRoll } from '/imports/api/creature/log/CreatureLogs.js
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||
import { assertEditPermission } from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||
import { parse, prettifyParseError } from '/imports/parser/parser.js';
|
||||
import resolve, { toString } from '/imports/parser/resolve.js';
|
||||
import LogEntry from '/imports/ui/log/LogEntry.vue';
|
||||
|
||||
export default {
|
||||
@@ -72,8 +73,8 @@ export default {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
let compiled = result.compile(this.creature.variables);
|
||||
this.inputHint = compiled.toString();
|
||||
let {result: compiled} = resolve('compile', result, this.creature.variables);
|
||||
this.inputHint = toString(compiled);
|
||||
return;
|
||||
} catch (e){
|
||||
console.warn(e);
|
||||
|
||||
Reference in New Issue
Block a user