Tore out the old engine, left some wounds
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
|
||||
import { assert } from 'chai';
|
||||
import computeCreatureComputation from '../../computeCreatureComputation.js';
|
||||
import clean from '../../utility/cleanProp.testFn.js';
|
||||
|
||||
export default function(){
|
||||
const computation = buildComputationFromProps(testProperties);
|
||||
computeCreatureComputation(computation);
|
||||
|
||||
const prop = computation.propsById['actionId'];
|
||||
assert.equal(prop.summary.value, 'test summary 3 without referencing anything 7');
|
||||
assert.equal(prop.description.value, 'test description 12 with reference 0.25 prop');
|
||||
assert.equal(prop.uses.value, 7);
|
||||
assert.equal(prop.usesLeft, 2);
|
||||
|
||||
const itemConsumed = prop.resources.itemsConsumed[0];
|
||||
assert.equal(itemConsumed.quantity.value, 3);
|
||||
assert.equal(itemConsumed.available, 27);
|
||||
assert.equal(itemConsumed.itemName, 'Arrow');
|
||||
assert.equal(itemConsumed.itemIcon, 'itemIcon');
|
||||
assert.equal(itemConsumed.itemColor, 'itemColor');
|
||||
|
||||
const attConsumed = prop.resources.attributesConsumed[0];
|
||||
assert.equal(attConsumed.quantity.value, 4);
|
||||
assert.equal(attConsumed.available, 9);
|
||||
assert.equal(attConsumed.statId, 'resourceVarId');
|
||||
assert.equal(attConsumed.statName, 'Resource Var');
|
||||
}
|
||||
|
||||
var testProperties = [
|
||||
clean({
|
||||
_id: 'actionId',
|
||||
type: 'action',
|
||||
ancestors: [{id: 'charId'}],
|
||||
summary: {
|
||||
text: 'test summary {1 + 2} without referencing anything {3 + 4}',
|
||||
},
|
||||
description: {
|
||||
text: 'test description {inlineRef * 2} with reference {1/4} prop',
|
||||
},
|
||||
resources: {
|
||||
itemsConsumed: [{
|
||||
_id: 'itemConsumedId',
|
||||
itemId: 'arrowId',
|
||||
tag: 'arrow',
|
||||
quantity: {
|
||||
calculation: 'itemConsumedQuantity',
|
||||
},
|
||||
}],
|
||||
attributesConsumed: [{
|
||||
_id: 'attConsumedId',
|
||||
variableName: 'resourceVar',
|
||||
quantity: {
|
||||
calculation: 'resourceConsumedQuantity'
|
||||
}
|
||||
}],
|
||||
},
|
||||
uses: {
|
||||
calculation: 'nonExistantProperty + 7',
|
||||
},
|
||||
usesUsed: 5,
|
||||
}),
|
||||
clean({
|
||||
_id: 'numItemsConumedId',
|
||||
type: 'attribute',
|
||||
variableName: 'itemConsumedQuantity',
|
||||
baseValue: {
|
||||
calculation: '3',
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'numResourceConumedId',
|
||||
type: 'attribute',
|
||||
variableName: 'resourceConsumedQuantity',
|
||||
baseValue: {
|
||||
calculation: '4',
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'resourceVarId',
|
||||
name: 'Resource Var',
|
||||
type: 'attribute',
|
||||
variableName: 'resourceVar',
|
||||
baseValue: {
|
||||
calculation: '9',
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'inlineRefResourceId',
|
||||
type: 'attribute',
|
||||
variableName: 'inlineRef',
|
||||
baseValue: {
|
||||
calculation: '1 + 5',
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'arrowId',
|
||||
type: 'item',
|
||||
name: 'Arrow',
|
||||
quantity: 27,
|
||||
icon: 'itemIcon',
|
||||
color: 'itemColor',
|
||||
}),
|
||||
];
|
||||
@@ -0,0 +1,77 @@
|
||||
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
|
||||
import { assert } from 'chai';
|
||||
import computeCreatureComputation from '../../computeCreatureComputation.js';
|
||||
import clean from '../../utility/cleanProp.testFn.js';
|
||||
|
||||
export default function(){
|
||||
const computation = buildComputationFromProps(testProperties);
|
||||
computeCreatureComputation(computation);
|
||||
const prop = id => computation.propsById[id];
|
||||
assert.equal(prop('emptyId').value, 0);
|
||||
assert.equal(prop('noVariableNameId').value, 8);
|
||||
assert.equal(prop('strengthId').value, 12);
|
||||
assert.equal(prop('strengthId').modifier, 1);
|
||||
assert.equal(prop('referencesDexId').value, 4);
|
||||
assert.equal(prop('hitDiceId').constitutionMod, 5);
|
||||
}
|
||||
|
||||
var testProperties = [
|
||||
clean({
|
||||
_id: 'emptyId',
|
||||
type: 'attribute',
|
||||
attributeType: 'ability',
|
||||
}),
|
||||
clean({
|
||||
_id: 'noVariableNameId',
|
||||
type: 'attribute',
|
||||
attributeType: 'ability',
|
||||
baseValue: {
|
||||
calculation: '8'
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'strengthId',
|
||||
variableName: 'strength',
|
||||
type: 'attribute',
|
||||
attributeType: 'ability',
|
||||
baseValue: {
|
||||
calculation: '12'
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'dexterityId',
|
||||
variableName: 'dexterity',
|
||||
type: 'attribute',
|
||||
attributeType: 'ability',
|
||||
baseValue: {
|
||||
calculation: '15'
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'constitutionId',
|
||||
variableName: 'constitution',
|
||||
type: 'attribute',
|
||||
attributeType: 'ability',
|
||||
baseValue: {
|
||||
calculation: '21'
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'referencesDexId',
|
||||
variableName: 'refDex',
|
||||
type: 'attribute',
|
||||
baseValue: {
|
||||
calculation: 'dexterity.modifier + 2'
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'hitDiceId',
|
||||
variableName: 'hd',
|
||||
type: 'attribute',
|
||||
attributeType: 'hitDice',
|
||||
hitDiceSize: 'd8',
|
||||
baseValue: {
|
||||
calculation: '4'
|
||||
},
|
||||
}),
|
||||
];
|
||||
@@ -0,0 +1,60 @@
|
||||
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
|
||||
import { assert } from 'chai';
|
||||
import computeCreatureComputation from '../../computeCreatureComputation.js';
|
||||
import clean from '../../utility/cleanProp.testFn.js';
|
||||
|
||||
export default function(){
|
||||
const computation = buildComputationFromProps(testProperties);
|
||||
computeCreatureComputation(computation);
|
||||
const scope = id => computation.scope[id];
|
||||
const prop = id => computation.propsById[id];
|
||||
assert.equal(scope('level').value, 5);
|
||||
assert.equal(scope('wizard').level, 4);
|
||||
assert.equal(prop('wizzardId').level, 4);
|
||||
assert.deepEqual(prop('wizzardId').missingLevels, [3]);
|
||||
}
|
||||
|
||||
var testProperties = [
|
||||
clean({
|
||||
_id: 'wizzardId',
|
||||
type: 'class',
|
||||
variableName: 'wizard',
|
||||
classType: 'startingClass',
|
||||
ancestors: [{id: 'charId'}],
|
||||
}),
|
||||
clean({
|
||||
_id: 'rangerId',
|
||||
type: 'class',
|
||||
variableName: 'ranger',
|
||||
classType: 'multiClass',
|
||||
ancestors: [{id: 'charId'}],
|
||||
}),
|
||||
clean({
|
||||
_id: 'wiz1Id',
|
||||
type: 'classLevel',
|
||||
variableName: 'wizard',
|
||||
level: 1,
|
||||
ancestors: [{id: 'charId'}],
|
||||
}),
|
||||
clean({
|
||||
_id: 'wiz2Id',
|
||||
type: 'classLevel',
|
||||
variableName: 'wizard',
|
||||
level: 2,
|
||||
ancestors: [{id: 'charId'}],
|
||||
}),
|
||||
clean({
|
||||
_id: 'wiz4Id',
|
||||
type: 'classLevel',
|
||||
variableName: 'wizard',
|
||||
level: 4,
|
||||
ancestors: [{id: 'charId'}],
|
||||
}),
|
||||
clean({
|
||||
_id: 'rang1Id',
|
||||
type: 'classLevel',
|
||||
variableName: 'ranger',
|
||||
level: 1,
|
||||
ancestors: [{id: 'charId'}],
|
||||
}),
|
||||
];
|
||||
@@ -0,0 +1,28 @@
|
||||
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
|
||||
import { assert } from 'chai';
|
||||
import computeCreatureComputation from '../../computeCreatureComputation.js';
|
||||
import clean from '../../utility/cleanProp.testFn.js';
|
||||
|
||||
export default function(){
|
||||
const computation = buildComputationFromProps(testProperties);
|
||||
computeCreatureComputation(computation);
|
||||
const prop = id => computation.propsById[id];
|
||||
assert.equal(prop('attId').value, 6);
|
||||
}
|
||||
|
||||
var testProperties = [
|
||||
clean({
|
||||
_id: 'constId',
|
||||
type: 'constant',
|
||||
variableName: 'arrayConstant',
|
||||
calculation: '[2, 4, 6, 8, 10]',
|
||||
}),
|
||||
clean({
|
||||
_id: 'attId',
|
||||
type: 'attribute',
|
||||
baseValue: {
|
||||
calculation: 'arrayConstant[3]',
|
||||
},
|
||||
ancestors: [{id: 'charId'}],
|
||||
}),
|
||||
];
|
||||
@@ -0,0 +1,40 @@
|
||||
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
|
||||
import { assert } from 'chai';
|
||||
import computeCreatureComputation from '../../computeCreatureComputation.js';
|
||||
import clean from '../../utility/cleanProp.testFn.js';
|
||||
|
||||
export default function(){
|
||||
const computation = buildComputationFromProps(testProperties);
|
||||
computeCreatureComputation(computation);
|
||||
const scope = id => computation.scope[id];
|
||||
assert.equal(scope('blugeoningMultiplier').value, 1);
|
||||
assert.equal(scope('customDamageMultiplier').value, 0.5);
|
||||
assert.equal(scope('slashingMultiplier').value, 0);
|
||||
}
|
||||
|
||||
var testProperties = [
|
||||
clean({
|
||||
_id: 'resistanceId',
|
||||
type: 'damageMultiplier',
|
||||
damageTypes: ['blugeoning', 'customDamage'],
|
||||
value: 0.5,
|
||||
}),
|
||||
clean({
|
||||
_id: 'vulnerabilityId',
|
||||
type: 'damageMultiplier',
|
||||
damageTypes: ['blugeoning'],
|
||||
value: 2,
|
||||
}),
|
||||
clean({
|
||||
_id: 'slashResistId',
|
||||
type: 'damageMultiplier',
|
||||
damageTypes: ['slashing'],
|
||||
value: 0.5,
|
||||
}),
|
||||
clean({
|
||||
_id: 'slashInvulnId',
|
||||
type: 'damageMultiplier',
|
||||
damageTypes: ['slashing'],
|
||||
value: 0,
|
||||
}),
|
||||
];
|
||||
@@ -0,0 +1,59 @@
|
||||
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
|
||||
import { assert } from 'chai';
|
||||
import computeCreatureComputation from '../../computeCreatureComputation.js';
|
||||
import clean from '../../utility/cleanProp.testFn.js';
|
||||
|
||||
export default function(){
|
||||
const computation = buildComputationFromProps(testProperties);
|
||||
computeCreatureComputation(computation);
|
||||
const prop = id => computation.propsById[id];
|
||||
assert.equal(prop('strengthId').value, 26);
|
||||
}
|
||||
|
||||
var testProperties = [
|
||||
clean({
|
||||
_id: 'strengthId',
|
||||
variableName: 'strength',
|
||||
type: 'attribute',
|
||||
attributeType: 'ability',
|
||||
baseValue: {
|
||||
calculation: '8'
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'strength2Id',
|
||||
variableName: 'strength',
|
||||
type: 'attribute',
|
||||
attributeType: 'ability',
|
||||
baseValue: {
|
||||
calculation: '10'
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'strengthBaseId',
|
||||
type: 'effect',
|
||||
operation: 'base',
|
||||
amount: {
|
||||
calculation: '10 + 2'
|
||||
},
|
||||
stats: ['strength'],
|
||||
}),
|
||||
clean({
|
||||
_id: 'strengthAddId',
|
||||
type: 'effect',
|
||||
operation: 'add',
|
||||
amount: {
|
||||
calculation: '1'
|
||||
},
|
||||
stats: ['strength'],
|
||||
}),
|
||||
clean({
|
||||
_id: 'strengthMulId',
|
||||
type: 'effect',
|
||||
operation: 'mul',
|
||||
amount: {
|
||||
calculation: '2'
|
||||
},
|
||||
stats: ['strength'],
|
||||
}),
|
||||
];
|
||||
@@ -0,0 +1,69 @@
|
||||
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
|
||||
import { assert } from 'chai';
|
||||
import computeCreatureComputation from '../../computeCreatureComputation.js';
|
||||
import clean from '../../utility/cleanProp.testFn.js';
|
||||
|
||||
export default function(){
|
||||
const computation = buildComputationFromProps(testProperties);
|
||||
computeCreatureComputation(computation);
|
||||
const prop = id => computation.propsById[id];
|
||||
const scope = id => computation.scope[id].value;
|
||||
|
||||
assert.equal(scope('weightEquipment'), 2);
|
||||
assert.equal(scope('valueEquipment'), 3);
|
||||
|
||||
assert.equal(scope('itemsAttuned'), 1);
|
||||
|
||||
assert.equal(prop('childContainerId').carriedWeight, 23);
|
||||
assert.equal(prop('childContainerId').contentsWeight, 23);
|
||||
|
||||
assert.equal(scope('weightCarried'), 58);
|
||||
|
||||
assert.equal(scope('weightCarried'), 58);
|
||||
assert.equal(scope('valueCarried'), 71);
|
||||
|
||||
assert.equal(scope('weightTotal'), 58);
|
||||
assert.equal(scope('valueTotal'), 71);
|
||||
}
|
||||
|
||||
var testProperties = [
|
||||
clean({
|
||||
_id: 'equippedAttunedItemId',
|
||||
type: 'item',
|
||||
equipped: true,
|
||||
attuned: true,
|
||||
weight: 2,
|
||||
value: 3,
|
||||
ancestors: [{id: 'charId'}],
|
||||
}),
|
||||
clean({
|
||||
_id: 'containerId',
|
||||
type: 'container',
|
||||
carried: true,
|
||||
weight: 5,
|
||||
value: 7,
|
||||
ancestors: [{id: 'charId'}],
|
||||
}),
|
||||
clean({
|
||||
_id: 'childContainerId',
|
||||
type: 'container',
|
||||
carried: true,
|
||||
weight: 11,
|
||||
value: 13,
|
||||
ancestors: [{id: 'charId'}, {id: 'containerId'}],
|
||||
}),
|
||||
clean({
|
||||
_id: 'childItemId',
|
||||
type: 'item',
|
||||
weight: 17,
|
||||
value: 19,
|
||||
ancestors: [{id: 'charId'}, {id: 'containerId'}],
|
||||
}),
|
||||
clean({
|
||||
_id: 'grandchildItemId',
|
||||
type: 'item',
|
||||
weight: 23,
|
||||
value: 29,
|
||||
ancestors: [{id: 'charId'}, {id: 'containerId'}, {id: 'childContainerId'}],
|
||||
}),
|
||||
];
|
||||
@@ -0,0 +1,84 @@
|
||||
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
|
||||
import { assert } from 'chai';
|
||||
import computeCreatureComputation from '../../computeCreatureComputation.js';
|
||||
import clean from '../../utility/cleanProp.testFn.js';
|
||||
|
||||
export default function(){
|
||||
const computation = buildComputationFromProps(testProperties);
|
||||
computeCreatureComputation(computation);
|
||||
const prop = id => computation.propsById[id];
|
||||
|
||||
assert.equal(prop('atheleticsId').proficiency, 2, 'Inherits proficiency from ability');
|
||||
assert.equal(prop('atheleticsId').value, 7, 'calculates value correctly');
|
||||
assert.equal(prop('atheleticsId').advantage, 1, 'Inherits advantage from ability');
|
||||
assert.equal(prop('strengthSaveId').advantage, undefined, 'Saves don\'t inherit effects');
|
||||
assert.equal(prop('strengthSaveId').value, 4, 'Saves calculate correctly');
|
||||
|
||||
assert.equal(prop('acrobaticsId').value, 1);
|
||||
assert.equal(prop('toolsId').value, 7);
|
||||
}
|
||||
|
||||
var testProperties = [
|
||||
clean({
|
||||
_id: 'strengthId',
|
||||
variableName: 'strength',
|
||||
type: 'attribute',
|
||||
attributeType: 'ability',
|
||||
baseValue: {
|
||||
calculation: '12'
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'profBonusId',
|
||||
variableName: 'proficiencyBonus',
|
||||
type: 'attribute',
|
||||
attributeType: 'modifier',
|
||||
baseValue: {
|
||||
calculation: '3'
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'atheleticsId',
|
||||
variableName: 'athletics',
|
||||
type: 'skill',
|
||||
skillType: 'skill',
|
||||
ability: 'strength',
|
||||
}),
|
||||
clean({
|
||||
_id: 'acrobaticsId',
|
||||
variableName: 'acrobatics',
|
||||
type: 'skill',
|
||||
skillType: 'skill',
|
||||
baseProficiency: 0.49,
|
||||
}),
|
||||
clean({
|
||||
_id: 'toolsId',
|
||||
variableName: 'tools',
|
||||
type: 'skill',
|
||||
skillType: 'tool',
|
||||
baseProficiency: 0.5,
|
||||
baseValue: {
|
||||
calculation: '5',
|
||||
}
|
||||
}),
|
||||
clean({
|
||||
_id: 'strengthAdvantageId',
|
||||
type: 'effect',
|
||||
operation: 'advantage',
|
||||
stats: ['strength'],
|
||||
}),
|
||||
clean({
|
||||
_id: 'strengthProficiencyId',
|
||||
type: 'proficiency',
|
||||
value: 2,
|
||||
stats: ['strength'],
|
||||
}),
|
||||
clean({
|
||||
_id: 'strengthSaveId',
|
||||
variableName: 'strengthSave',
|
||||
type: 'skill',
|
||||
skillType: 'save',
|
||||
ability: 'strength',
|
||||
baseProficiency: 1,
|
||||
}),
|
||||
];
|
||||
@@ -0,0 +1,34 @@
|
||||
import computeAction from './computeAction.testFn.js';
|
||||
import computeAttribute from './computeAttribute.testFn.js';
|
||||
import computeClasses from './computeClasses.testFn.js';
|
||||
import computeConstants from './computeConstants.testFn.js';
|
||||
import computeInventory from './computeInventory.testFn.js';
|
||||
import computeDamageMultipliers from './computeDamageMultipliers.testFn.js';
|
||||
import computeEffects from './computeEffects.testFn.js';
|
||||
import computeSkills from './computeSkills.testFn.js';
|
||||
|
||||
export default [{
|
||||
text: 'Computes actions',
|
||||
fn: computeAction,
|
||||
},{
|
||||
text: 'Computes attributes',
|
||||
fn: computeAttribute,
|
||||
},{
|
||||
text: 'Computes classes',
|
||||
fn: computeClasses,
|
||||
},{
|
||||
text: 'Computes constants',
|
||||
fn: computeConstants,
|
||||
},{
|
||||
text: 'Computes inventory',
|
||||
fn: computeInventory,
|
||||
},{
|
||||
text: 'Computes damage multipliers',
|
||||
fn: computeDamageMultipliers,
|
||||
},{
|
||||
text: 'Computes effects',
|
||||
fn: computeEffects,
|
||||
},{
|
||||
text: 'Computes skills',
|
||||
fn: computeSkills,
|
||||
}];
|
||||
Reference in New Issue
Block a user