UI work to improve look and feel of Viewers

This commit is contained in:
Stefan Zermatten
2021-10-17 23:28:39 +02:00
parent 247353f0ed
commit bc6c857b6b
13 changed files with 420 additions and 196 deletions

View File

@@ -1,6 +1,7 @@
import _variable from './computeByType/computeVariable.js';
import action from './computeByType/computeAction.js';
import attribute from './computeByType/computeAttribute.js';
import skill from './computeByType/computeSkill.js';
import slot from './computeByType/computeSlot.js';
import container from './computeByType/computeContainer.js';
@@ -9,6 +10,7 @@ export default Object.freeze({
action,
attribute,
container,
skill,
slot,
spell: action,
});

View File

@@ -0,0 +1,28 @@
// If we compute this skill without a variable name, it just
// uses its base value, proficiency, and damage since no effects can target it
// If this skill does have a variable name, it is recomputed later
// by computeVariableAsSkill
export default function computeSkill(computation, node){
const prop = node.data;
prop.proficiency = prop.baseProficiency;
let profBonus = computation.scope['proficiencyBonus']?.value || 0;
// Multiply the proficiency bonus by the actual proficiency
if(prop.proficiency === 0.49){
// Round down proficiency bonus in the special case
profBonus = Math.floor(profBonus * 0.5);
} else {
profBonus = Math.ceil(profBonus * prop.proficiency);
}
const ability = computation.scope[prop.ability];
prop.abilityMod = ability?.modifier || 0;
const base = prop.baseValue?.value || 0;
let result = base + prop.abilityMod + profBonus;
if (Number.isFinite(result)){
result = Math.floor(result);
}
prop.value = result;
}

View File

@@ -15,6 +15,7 @@ export default function(){
assert.equal(scope('strength').modifier, 1);
assert.equal(prop('referencesDexId').value, 4);
assert.equal(prop('hitDiceId').constitutionMod, 5);
assert.equal(prop('overriddenDexId').overridden, true, 'override properties with the same variable name');
assert.equal(
prop('parseErrorId').baseValue.value, null,
'Parse errors should null the value'
@@ -44,11 +45,22 @@ var testProperties = [
calculation: '12'
},
}),
clean({
_id: 'overriddenDexId',
variableName: 'dexterity',
type: 'attribute',
attributeType: 'ability',
order: 1,
baseValue: {
calculation: '15'
},
}),
clean({
_id: 'dexterityId',
variableName: 'dexterity',
type: 'attribute',
attributeType: 'ability',
order: 2,
baseValue: {
calculation: '15'
},