Class levels now recompute properly
This commit is contained in:
@@ -12,6 +12,7 @@ export default class ComputationMemo {
|
|||||||
this.skillsByAbility = {};
|
this.skillsByAbility = {};
|
||||||
this.unassignedEffects = [];
|
this.unassignedEffects = [];
|
||||||
this.classLevelsById = {};
|
this.classLevelsById = {};
|
||||||
|
this.classes = {};
|
||||||
this.togglesById = {};
|
this.togglesById = {};
|
||||||
this.toggleIds = new Set();
|
this.toggleIds = new Set();
|
||||||
// First note all the ids of all the toggles
|
// First note all the ids of all the toggles
|
||||||
|
|||||||
44
app/imports/api/creature/computation/computeLevels.js
Normal file
44
app/imports/api/creature/computation/computeLevels.js
Normal 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;
|
||||||
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
import { each, forOwn } from 'lodash';
|
import { each, forOwn } from 'lodash';
|
||||||
|
import computeLevels from '/imports/api/creature/computation/computeLevels.js';
|
||||||
import computeStat from '/imports/api/creature/computation/computeStat.js';
|
import computeStat from '/imports/api/creature/computation/computeStat.js';
|
||||||
import computeEffect from '/imports/api/creature/computation/computeEffect.js';
|
import computeEffect from '/imports/api/creature/computation/computeEffect.js';
|
||||||
import computeToggle from '/imports/api/creature/computation/computeToggle.js';
|
import computeToggle from '/imports/api/creature/computation/computeToggle.js';
|
||||||
|
|
||||||
export default function computeMemo(memo){
|
export default function computeMemo(memo){
|
||||||
|
// Compute level
|
||||||
|
computeLevels(memo);
|
||||||
// Compute all stats, even if they are overriden
|
// Compute all stats, even if they are overriden
|
||||||
forOwn(memo.statsById, stat => {
|
forOwn(memo.statsById, stat => {
|
||||||
computeStat (stat, memo);
|
computeStat (stat, memo);
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ export default function computeToggle(toggle, memo){
|
|||||||
// Do work
|
// Do work
|
||||||
if (toggle.enabled){
|
if (toggle.enabled){
|
||||||
toggle.toggleResult = true;
|
toggle.toggleResult = true;
|
||||||
|
} else if (toggle.disabled){
|
||||||
|
toggle.toggleResult = false;
|
||||||
} else if (!toggle.condition){
|
} else if (!toggle.condition){
|
||||||
toggle.toggleResult = false;
|
toggle.toggleResult = false;
|
||||||
} else if (Number.isFinite(+toggle.condition)){
|
} else if (Number.isFinite(+toggle.condition)){
|
||||||
|
|||||||
@@ -11,12 +11,6 @@ let ClassLevelSchema = new SimpleSchema({
|
|||||||
type: String,
|
type: String,
|
||||||
regEx: VARIABLE_NAME_REGEX,
|
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: {
|
level: {
|
||||||
type: SimpleSchema.Integer,
|
type: SimpleSchema.Integer,
|
||||||
defaultValue: 1,
|
defaultValue: 1,
|
||||||
|
|||||||
@@ -20,23 +20,14 @@
|
|||||||
@change="(value, ack) => $emit('change', {path: ['name'], value, ack})"
|
@change="(value, ack) => $emit('change', {path: ['name'], value, ack})"
|
||||||
/>
|
/>
|
||||||
<text-field
|
<text-field
|
||||||
label="Variable name"
|
label="Class variable name"
|
||||||
:value="model.variableName"
|
:value="model.variableName"
|
||||||
style="flex-basis: 300px;"
|
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"
|
:error-messages="errors.variableName"
|
||||||
:debounce-time="debounceTime"
|
:debounce-time="debounceTime"
|
||||||
@change="(value, ack) => $emit('change', {path: ['variableName'], value, ack})"
|
@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>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user