Class levels now recompute properly

This commit is contained in:
Thaum Rystra
2020-05-16 22:51:17 +02:00
parent 5c0a2a4d6c
commit ca5ded7ded
6 changed files with 52 additions and 17 deletions

View File

@@ -12,6 +12,7 @@ export default class ComputationMemo {
this.skillsByAbility = {};
this.unassignedEffects = [];
this.classLevelsById = {};
this.classes = {};
this.togglesById = {};
this.toggleIds = new Set();
// First note all the ids of all the toggles

View File

@@ -0,0 +1,44 @@
import { forOwn, has } from 'lodash';
export default function computeLevels(memo){
computeClassLevels(memo);
computeTotalLevel(memo);
}
function computeClassLevels(memo){
forOwn(memo.classLevelsById, classLevel => {
let name = classLevel.variableName;
let stat = memo.statsByVariableName[name];
if (!stat){
memo.statsByVariableName[name] = classLevel;
memo.classes[name] = classLevel;
} else if (!has(stat, 'level')){
// Stat is overriden by an attribute
return;
} else if (stat.level < classLevel.level) {
memo.statsByVariableName[name] = classLevel;
memo.classes[name] = classLevel;
}
});
}
function computeTotalLevel(memo){
let currentLevel = memo.statsByVariableName['level'];
if (!currentLevel){
currentLevel = {
value: 0,
computationDetails: {
builtIn: true,
computed: true,
}
};
memo.statsByVariableName['level'] = currentLevel;
}
// bail out if overriden by an attribute
if (!currentLevel.computationDetails.builtIn) return;
let level = 0;
for (let name in memo.classes){
level += memo.classes[name].level || 0;
}
memo.statsByVariableName['level'].value = level;
}

View File

@@ -1,9 +1,12 @@
import { each, forOwn } from 'lodash';
import computeLevels from '/imports/api/creature/computation/computeLevels.js';
import computeStat from '/imports/api/creature/computation/computeStat.js';
import computeEffect from '/imports/api/creature/computation/computeEffect.js';
import computeToggle from '/imports/api/creature/computation/computeToggle.js';
export default function computeMemo(memo){
// Compute level
computeLevels(memo);
// Compute all stats, even if they are overriden
forOwn(memo.statsById, stat => {
computeStat (stat, memo);

View File

@@ -18,6 +18,8 @@ export default function computeToggle(toggle, memo){
// Do work
if (toggle.enabled){
toggle.toggleResult = true;
} else if (toggle.disabled){
toggle.toggleResult = false;
} else if (!toggle.condition){
toggle.toggleResult = false;
} else if (Number.isFinite(+toggle.condition)){

View File

@@ -11,12 +11,6 @@ let ClassLevelSchema = new SimpleSchema({
type: String,
regEx: VARIABLE_NAME_REGEX,
},
// The variable name of the base class this level is attached to
baseClass: {
type: String,
regEx: VARIABLE_NAME_REGEX,
optional: true,
},
level: {
type: SimpleSchema.Integer,
defaultValue: 1,

View File

@@ -20,23 +20,14 @@
@change="(value, ack) => $emit('change', {path: ['name'], value, ack})"
/>
<text-field
label="Variable name"
label="Class variable name"
:value="model.variableName"
style="flex-basis: 300px;"
hint="Use this name in formulae to reference this class"
hint="This should be the same for each level in a class"
:error-messages="errors.variableName"
:debounce-time="debounceTime"
@change="(value, ack) => $emit('change', {path: ['variableName'], value, ack})"
/>
<text-field
label="Base Class Variable name"
:value="model.baseClass"
style="flex-basis: 300px;"
hint="This is the name of the class this class level belongs to"
:error-messages="errors.baseClass"
:debounce-time="debounceTime"
@change="(value, ack) => $emit('change', {path: ['baseClass'], value, ack})"
/>
</div>
</div>
</template>