Merge feature-nested-sets into develop

This commit is contained in:
ThaumRystra
2023-12-18 18:27:17 +02:00
523 changed files with 5492 additions and 3763 deletions

View File

@@ -1,6 +1,6 @@
import { EJSON } from 'meteor/ejson';
import createGraph, { Graph } from 'ngraph.graph';
import getEffectivePropTags from '/imports/api/engine/computation/utility/getEffectivePropTags.js';
import getEffectivePropTags from '/imports/api/engine/computation/utility/getEffectivePropTags';
interface CreatureProperty {
_id: string;

View File

@@ -1,7 +1,10 @@
import walkDown from '/imports/api/engine/computation/utility/walkdown.js';
import { CreatureProperty } from '/imports/api/creature/creatureProperties/CreatureProperties';
import walkDown from '/imports/api/engine/computation/utility/walkdown';
import { TreeNode } from '/imports/api/parenting/parentingFunctions';
import { isSpell } from '/imports/api/properties/Spells';
export default function computeInactiveStatus(node) {
const prop = node.node;
export default function computeInactiveStatus(node: TreeNode<CreatureProperty>): void {
const prop = node.doc;
if (!isActive(prop)) {
// Mark prop inactive due to self
prop.inactive = true;
@@ -10,22 +13,21 @@ export default function computeInactiveStatus(node) {
if (!childrenActive(prop)) {
// Mark children as inactive due to ancestor
walkDown(node.children, child => {
child.node.inactive = true;
child.node.deactivatedByAncestor = true;
child.doc.inactive = true;
child.doc.deactivatedByAncestor = true;
});
}
}
function isActive(prop) {
function isActive(prop: CreatureProperty): boolean {
if (prop.disabled) return false;
switch (prop.type) {
// Unprepared spells are inactive
case 'spell': return !!prop.prepared || !!prop.alwaysPrepared;
default: return true;
if (isSpell(prop)) {
return !!prop.prepared || !!prop.alwaysPrepared;
}
return true;
}
function childrenActive(prop) {
function childrenActive(prop): boolean {
// Children of disabled properties are always inactive
if (prop.disabled) return false;
switch (prop.type) {

View File

@@ -3,11 +3,11 @@
* before `spacesLeft` can be computed
*/
export default function computeSlotQuantityFilled(node, dependencyGraph) {
let slot = node.node;
let slot = node.doc;
if (slot.type !== 'propertySlot') return;
slot.totalFilled = 0;
node.children.forEach(child => {
let childProp = child.node;
let childProp = child.doc;
dependencyGraph.addLink(slot._id, childProp._id, 'slotFill');
if (
Number.isFinite(childProp.slotQuantityFilled)

View File

@@ -1,8 +1,8 @@
import walkDown from '/imports/api/engine/computation/utility/walkdown.js';
import { getEffectTagTargets } from '/imports/api/engine/computation/buildComputation/linkTypeDependencies.js';
import walkDown from '/imports/api/engine/computation/utility/walkdown';
import { getEffectTagTargets } from '/imports/api/engine/computation/buildComputation/linkTypeDependencies';
export default function computeToggleDependencies(node, dependencyGraph, computation, forest) {
const prop = node.node;
const prop = node.doc
// Only for toggles
if (prop.type !== 'toggle') return;
@@ -11,12 +11,12 @@ export default function computeToggleDependencies(node, dependencyGraph, computa
getEffectTagTargets(prop, computation).forEach(targetId => {
const target = forest.nodeIndex[targetId];
if (!target) return;
target.node._computationDetails.toggleAncestors.push(prop);
dependencyGraph.addLink(target.node._id, prop._id, 'toggle');
target.doc._computationDetails.toggleAncestors.push(prop);
dependencyGraph.addLink(target.doc._id, prop._id, 'toggle');
walkDown(target.children, child => {
// The child nodes depend on the toggle
child.node._computationDetails.toggleAncestors.push(prop);
dependencyGraph.addLink(child.node._id, prop._id, 'toggle');
child.doc._computationDetails.toggleAncestors.push(prop);
dependencyGraph.addLink(child.doc._id, prop._id, 'toggle');
});
});
}
@@ -26,7 +26,7 @@ export default function computeToggleDependencies(node, dependencyGraph, computa
walkDown(node.children, child => {
// The child nodes depend on the toggle
child.node._computationDetails.toggleAncestors.push(prop);
dependencyGraph.addLink(child.node._id, prop._id, 'toggle');
child.doc._computationDetails.toggleAncestors.push(prop);
dependencyGraph.addLink(child.doc._id, prop._id, 'toggle');
});
}

View File

@@ -1,5 +1,4 @@
import findAncestorByType from '/imports/api/engine/computation/utility/findAncestorByType.js';
import { traverse } from '/imports/parser/resolve.js';
import { traverse } from '/imports/parser/resolve';
export default function linkCalculationDependencies(dependencyGraph, prop, { propsById }) {
prop._computationDetails.calculations.forEach(calcObj => {
@@ -57,3 +56,14 @@ function getAncestorProp(type, memo, prop, propsById) {
return ancestorProp;
}
}
function findAncestorByType(prop, type, propsById) {
if (!prop || !prop.parentId) return;
let parentProp = prop;
while (parentProp) {
parentProp = propsById[parentProp.parentId];
if (parentProp?.type === type) {
return parentProp;
}
}
}

View File

@@ -10,7 +10,7 @@ export default function linkInventory(forest, dependencyGraph) {
while (stack.length) {
const top = stack[stack.length - 1];
const prop = top.node;
const prop = top.doc;
if (prop._computationDetails.inventoryChildrenVisited) {
if (prop.type === 'container') containerStack.pop();
stack.pop();
@@ -18,7 +18,7 @@ export default function linkInventory(forest, dependencyGraph) {
} else {
// Add all containers to the stack when we first visit them
if (prop.type === 'container') {
containerStack.push(top.node);
containerStack.push(top.doc);
}
// Push children onto the stack and mark this as children are visited
stack.push(...top.children);

View File

@@ -1,9 +1,9 @@
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX.js';
import { prettifyParseError, parse } from '/imports/parser/parser.js';
import applyFnToKey from '/imports/api/engine/computation/utility/applyFnToKey.js';
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX';
import { prettifyParseError, parse } from '/imports/parser/parser';
import applyFnToKey from '/imports/api/engine/computation/utility/applyFnToKey';
import { get, set, unset } from 'lodash';
import errorNode from '/imports/parser/parseTree/error.js';
import cyrb53 from '/imports/api/engine/computation/utility/cyrb53.js';
import errorNode from '/imports/parser/parseTree/error';
import cyrb53 from '/imports/api/engine/computation/utility/cyrb53';
export default function parseCalculationFields(prop, schemas) {
discoverInlineCalculationFields(prop, schemas);

View File

@@ -1,4 +1,4 @@
import applyFnToKey from '../utility/applyFnToKey.js';
import applyFnToKey from '../utility/applyFnToKey';
import { unset } from 'lodash';
export default function removeSchemaFields(schemas, prop) {

View File

@@ -1,9 +1,11 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import clean from '../../utility/cleanProp.testFn.js';
import clean from '../../utility/cleanProp.testFn';
import { applyNestedSetProperties } from '/imports/api/parenting/parentingFunctions';
export default function () {
let computation = buildComputationFromProps(testProperties);
const bySelf = (propId, note) => assertDeactivatedBySelf(computation, propId, note);
const byAncestor = (propId, note) => assertDeactivatedByAncestor(computation, propId, note);
const active = (propId, note) => assertActive(computation, propId, note);
@@ -51,66 +53,68 @@ var testProperties = [
clean({
_id: 'itemUnequippedId',
type: 'item',
ancestors: [{ id: 'charId' }],
parentId: 'charId',
}),
clean({
_id: 'itemUnequippedChildId',
type: 'folder',
ancestors: [{ id: 'charId' }, { id: 'itemUnequippedId' }],
parentId: 'itemUnequippedId',
}),
clean({
_id: 'itemEquippedId',
type: 'item',
equipped: true,
ancestors: [{ id: 'charId' }],
parentId: 'charId',
}),
clean({
_id: 'itemEquippedChildId',
type: 'folder',
ancestors: [{ id: 'charId' }, { id: 'itemEquippedId' }],
parentId: 'itemEquippedId',
}),
// Spells
clean({
_id: 'spellPreparedId',
type: 'spell',
ancestors: [{ id: 'charId' }],
parentId: 'charId',
prepared: true,
}),
clean({
_id: 'spellPreparedChildId',
type: 'folder',
ancestors: [{ id: 'charId' }, { id: 'spellPreparedId' }],
parentId: 'spellPreparedId',
}),
clean({
_id: 'spellAlwaysPreparedId',
type: 'spell',
ancestors: [{ id: 'charId' }],
parentId: 'charId',
alwaysPrepared: true,
}),
clean({
_id: 'spellAlwaysPreparedChildId',
type: 'folder',
ancestors: [{ id: 'charId' }, { id: 'spellAlwaysPreparedId' }],
parentId: 'spellAlwaysPreparedId',
}),
clean({
_id: 'spellUnpreparedId',
type: 'spell',
ancestors: [{ id: 'charId' }],
parentId: 'charId',
}),
clean({
_id: 'spellUnpreparedChildId',
type: 'folder',
ancestors: [{ id: 'charId' }, { id: 'spellUnpreparedId' }],
parentId: 'spellUnpreparedId',
}),
// Notes
clean({
_id: 'NoteId',
type: 'note',
ancestors: [{ id: 'charId' }],
parentId: 'charId',
}),
clean({
_id: 'NoteChildId',
type: 'folder',
ancestors: [{ id: 'charId' }, { id: 'NoteId' }],
parentId: 'NoteId',
}),
];
applyNestedSetProperties(testProperties);

View File

@@ -1,6 +1,7 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import clean from '../../utility/cleanProp.testFn.js';
import clean from '../../utility/cleanProp.testFn';
import { applyNestedSetProperties } from '/imports/api/parenting/parentingFunctions';
export default function () {
const computation = buildComputationFromProps(testProperties);
@@ -13,7 +14,6 @@ var testProperties = [
clean({
_id: 'slotId',
type: 'propertySlot',
ancestors: [{ id: 'charId' }],
}),
// Children
clean({
@@ -21,16 +21,18 @@ var testProperties = [
type: 'folder',
slotQuantityFilled: 3,
slotFillerType: 'item',
ancestors: [{ id: 'charId' }, { id: 'slotId' }],
parentId: 'slotId',
}),
clean({
_id: 'slotChildId',
type: 'item',
ancestors: [{ id: 'charId' }, { id: 'slotId' }],
parentId: 'slotId',
}),
clean({
_id: 'slotGrandchildId',
type: 'effect',
ancestors: [{ id: 'charId' }, { id: 'slotId' }, { id: 'slotChildId' }],
parentId: 'slotChildId',
}),
];
applyNestedSetProperties(testProperties);

View File

@@ -1,8 +1,9 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import clean from '../../utility/cleanProp.testFn.js';
import clean from '../../utility/cleanProp.testFn';
import { applyNestedSetProperties } from '/imports/api/parenting/parentingFunctions';
export default function(){
export default function () {
const computation = buildComputationFromProps(testProperties);
const hasLink = computation.dependencyGraph.hasLink;
assert.include(
@@ -37,38 +38,37 @@ var testProperties = [
_id: 'enabledToggleId',
type: 'toggle',
enabled: true,
ancestors: [{id: 'charId'}],
}),
clean({
_id: 'disabledToggleId',
type: 'toggle',
disabled: true,
ancestors: [{id: 'charId'}],
}),
clean({
_id: 'conditionToggleId',
type: 'toggle',
ancestors: [{id: 'charId'}],
}),
// Children
clean({
_id: 'enabledToggleChildId',
type: 'folder',
ancestors: [{id: 'charId'}, {id: 'enabledToggleId'}],
parentId: 'enabledToggleId',
}),
clean({
_id: 'disabledToggleChildId',
type: 'folder',
ancestors: [{id: 'charId'}, {id: 'disabledToggleId'}],
parentId: 'disabledToggleId',
}),
clean({
_id: 'conditionToggleChildId',
type: 'folder',
ancestors: [{id: 'charId'}, {id: 'conditionToggleId'}],
parentId: 'conditionToggleId',
}),
clean({
_id: 'conditionToggleGrandChildId',
type: 'folder',
ancestors: [{id: 'charId'}, {id: 'conditionToggleId'}, {id: 'conditionToggleChildId'}],
parentId: 'conditionToggleChildId',
}),
];
applyNestedSetProperties(testProperties);

View File

@@ -1,8 +1,9 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import clean from '../../utility/cleanProp.testFn.js';
import clean from '../../utility/cleanProp.testFn';
import { applyNestedSetProperties } from '/imports/api/parenting/parentingFunctions';
export default function(){
export default function () {
const computation = buildComputationFromProps(testProperties);
const hasLink = computation.dependencyGraph.hasLink;
const prop = (id) => computation.propsById[id];
@@ -32,7 +33,6 @@ var testProperties = [
clean({
_id: 'spellListId',
type: 'spellList',
ancestors: [{id: 'charId'}],
}),
clean({
_id: 'childId',
@@ -40,7 +40,7 @@ var testProperties = [
description: {
text: 'DC {#spellList.dc} save or suck'
},
ancestors: [{id: 'charId'}, {id: 'spellListId'}],
parentId: 'spellListId',
}),
clean({
_id: 'grandchildId',
@@ -48,7 +48,7 @@ var testProperties = [
dc: {
calculation: '#spellList.dc + strength + wisdom.modifier'
},
ancestors: [{id: 'charId'}, {id: 'spellListId'}, {id: 'childId'}],
parentId: 'childId',
}),
clean({
_id: 'strengthId',
@@ -57,6 +57,7 @@ var testProperties = [
baseValue: {
calculation: '15 + ',
},
ancestors: [{id: 'charId'}],
}),
];
applyNestedSetProperties(testProperties);

View File

@@ -1,8 +1,9 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import clean from '../../utility/cleanProp.testFn.js';
import clean from '../../utility/cleanProp.testFn';
import { applyNestedSetProperties } from '/imports/api/parenting/parentingFunctions';
export default function(){
export default function () {
const computation = buildComputationFromProps(testProperties);
const hasLink = computation.dependencyGraph.hasLink;
@@ -62,28 +63,28 @@ var testProperties = [
type: 'item',
equipped: true,
attuned: true,
ancestors: [{id: 'charId'}],
}),
clean({
_id: 'containerId',
type: 'container',
carried: true,
ancestors: [{id: 'charId'}],
}),
clean({
_id: 'childContainerId',
type: 'container',
carried: true,
ancestors: [{id: 'charId'}, {id: 'containerId'}],
}),
clean({
_id: 'childItemId',
type: 'item',
ancestors: [{id: 'charId'}, {id: 'containerId'}],
parentId: 'containerId',
}),
clean({
_id: 'grandchildItemId',
type: 'item',
ancestors: [{id: 'charId'}, {id: 'containerId'}, {id: 'childContainerId'}],
parentId: 'childContainerId',
}),
clean({
_id: 'childItemId',
type: 'item',
parentId: 'containerId',
}),
];
applyNestedSetProperties(testProperties);

View File

@@ -1,8 +1,8 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import clean from '../../utility/cleanProp.testFn.js';
import clean from '../../utility/cleanProp.testFn';
export default function(){
export default function () {
const computation = buildComputationFromProps(testProperties);
const getLink = computation.dependencyGraph.hasLink;
const getNode = computation.dependencyGraph.getNode;
@@ -22,6 +22,5 @@ var testProperties = [
_id: 'strengthId',
type: 'attribute',
variableName: 'strength',
ancestors: [{id: 'charId'}],
}),
];

View File

@@ -1,19 +1,19 @@
import { nodeArrayToTree } from '/imports/api/parenting/nodesToTree.js';
import { docsToForest } from '/imports/api/parenting/parentingFunctions';
import { DenormalisedOnlyCreaturePropertySchema as denormSchema }
from '/imports/api/creature/creatureProperties/CreatureProperties.js';
import { getProperties, getCreature, getVariables } from '/imports/api/engine/loadCreatures.js';
import computedOnlySchemas from '/imports/api/properties/computedOnlyPropertySchemasIndex.js';
import computedSchemas from '/imports/api/properties/computedPropertySchemasIndex.js';
import linkInventory from './buildComputation/linkInventory.js';
import walkDown from './utility/walkdown.js';
import parseCalculationFields from './buildComputation/parseCalculationFields.js';
import computeInactiveStatus from './buildComputation/computeInactiveStatus.js';
import computeToggleDependencies from './buildComputation/computeToggleDependencies.js';
import linkCalculationDependencies from './buildComputation/linkCalculationDependencies.js';
import linkTypeDependencies from './buildComputation/linkTypeDependencies.js';
import computeSlotQuantityFilled from './buildComputation/computeSlotQuantityFilled.js';
import CreatureComputation from './CreatureComputation.ts';
import removeSchemaFields from './buildComputation/removeSchemaFields.js';
from '/imports/api/creature/creatureProperties/CreatureProperties';
import { getProperties, getCreature, getVariables } from '/imports/api/engine/loadCreatures';
import computedOnlySchemas from '/imports/api/properties/computedOnlyPropertySchemasIndex';
import computedSchemas from '/imports/api/properties/computedPropertySchemasIndex';
import linkInventory from './buildComputation/linkInventory';
import walkDown from './utility/walkdown';
import parseCalculationFields from './buildComputation/parseCalculationFields';
import computeInactiveStatus from './buildComputation/computeInactiveStatus';
import computeToggleDependencies from './buildComputation/computeToggleDependencies';
import linkCalculationDependencies from './buildComputation/linkCalculationDependencies';
import linkTypeDependencies from './buildComputation/linkTypeDependencies';
import computeSlotQuantityFilled from './buildComputation/computeSlotQuantityFilled';
import CreatureComputation from './CreatureComputation';
import removeSchemaFields from './buildComputation/removeSchemaFields';
/**
* Store index of properties
@@ -86,7 +86,7 @@ export function buildComputationFromProps(properties, creature, variables) {
});
// Get all the properties as trees based on their ancestors
let forest = nodeArrayToTree(properties);
let forest = docsToForest(properties);
// Walk the property trees computing things that need to be inherited
walkDown(forest, node => {
computeInactiveStatus(node);

View File

@@ -1,16 +1,16 @@
import '/imports/api/simpleSchemaConfig.js';
import { buildComputationFromProps } from './buildCreatureComputation.js';
import '/imports/api/simpleSchemaConfig';
import { buildComputationFromProps } from './buildCreatureComputation';
import { assert } from 'chai';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
import computeInactiveStatus from './buildComputation/tests/computeInactiveStatus.testFn.js';
import computeSlotQuantityFilled from './buildComputation/tests/computeSlotQuantityFilled.testFn.js';
import computeToggleDependencies from './buildComputation/tests/computeToggleDependencies.testFn.js';
import linkCalculationDependencies from './buildComputation/tests/linkCalculationDependencies.testFn.js';
import linkInventory from './buildComputation/tests/linkInventory.testFn.js';
import linkTypeDependencies from './buildComputation/tests/linkTypeDependencies.testFn.js';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
import computeInactiveStatus from './buildComputation/tests/computeInactiveStatus.testFn';
import computeSlotQuantityFilled from './buildComputation/tests/computeSlotQuantityFilled.testFn';
import computeToggleDependencies from './buildComputation/tests/computeToggleDependencies.testFn';
import linkCalculationDependencies from './buildComputation/tests/linkCalculationDependencies.testFn';
import linkInventory from './buildComputation/tests/linkInventory.testFn';
import linkTypeDependencies from './buildComputation/tests/linkTypeDependencies.testFn';
describe('buildComputation', function(){
it('Builds something at all', function(){
describe('buildComputation', function () {
it('Builds something at all', function () {
let computation = buildComputationFromProps(testProperties);
assert.exists(computation);
});
@@ -37,7 +37,7 @@ var testProperties = [
}),
];
function clean(prop){
function clean(prop) {
let schema = CreatureProperties.simpleSchema(prop);
return schema.clean(prop);
}

View File

@@ -1,14 +1,13 @@
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 pointBuy from './computeByType/computePointBuy.js';
import propertySlot from './computeByType/computeSlot.js';
import container from './computeByType/computeContainer.js';
import spellList from './computeByType/computeSpellList.js';
import toggle from './computeByType/computeToggle.js';
import trigger from './computeByType/computeTrigger.js'
import _calculation from './computeByType/computeCalculation.js';
import _variable from './computeByType/computeVariable';
import action from './computeByType/computeAction';
import attribute from './computeByType/computeAttribute';
import skill from './computeByType/computeSkill';
import pointBuy from './computeByType/computePointBuy';
import propertySlot from './computeByType/computeSlot';
import container from './computeByType/computeContainer';
import spellList from './computeByType/computeSpellList';
import toggle from './computeByType/computeToggle';
import _calculation from './computeByType/computeCalculation';
export default Object.freeze({
_variable,

View File

@@ -1,8 +1,8 @@
import call from '/imports/parser/parseTree/call.js';
import constant from '/imports/parser/parseTree/constant.js';
import operator from '/imports/parser/parseTree/operator.js';
import parenthesis from '/imports/parser/parseTree/parenthesis.js';
import resolve, { toPrimitiveOrString } from '/imports/parser/resolve.js';
import call from '/imports/parser/parseTree/call';
import constant from '/imports/parser/parseTree/constant';
import operator from '/imports/parser/parseTree/operator';
import parenthesis from '/imports/parser/parseTree/parenthesis';
import resolve, { toPrimitiveOrString } from '/imports/parser/resolve';
export default function computeCalculation(computation, node) {
const calcObj = node.data;

View File

@@ -1,5 +1,5 @@
import aggregate from './computeVariable/aggregate/index.js';
import { safeStrip } from '/imports/api/engine/computation/utility/stripFloatingPointOddities.js';
import aggregate from './computeVariable/aggregate/index';
import { safeStrip } from '/imports/api/engine/computation/utility/stripFloatingPointOddities';
export default function computeContainer(computation, node) {
if (!node.data) node.data = {};

View File

@@ -1,5 +1,5 @@
import { has } from 'lodash';
import resolveCalculationNode from '/imports/api/engine/computation/computeComputation/computeByType/computeCalculation.js';
import { resolveCalculationNode } from '/imports/api/engine/computation/computeComputation/computeByType/computeCalculation';
export default function computePointBuy(computation, node) {
const prop = node.data;

View File

@@ -1,12 +1,11 @@
import aggregate from './computeVariable/aggregate/index.js';
import computeVariableAsAttribute from './computeVariable/computeVariableAsAttribute.js';
import computeVariableAsSkill from './computeVariable/computeVariableAsSkill.js';
import computeVariableAsConstant from './computeVariable/computeVariableAsConstant.js';
import computeVariableAsClass from './computeVariable/computeVariableAsClass.js';
import computeVariableAsToggle from './computeVariable/computeVariableAsToggle.js';
import computeImplicitVariable from './computeVariable/computeImplicitVariable.js';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
import { computedInlineCalculationField } from '/imports/api/properties/subSchemas/inlineCalculationField';
import aggregate from './computeVariable/aggregate/index';
import computeVariableAsAttribute from './computeVariable/computeVariableAsAttribute';
import computeVariableAsSkill from './computeVariable/computeVariableAsSkill';
import computeVariableAsConstant from './computeVariable/computeVariableAsConstant';
import computeVariableAsClass from './computeVariable/computeVariableAsClass';
import computeVariableAsToggle from './computeVariable/computeVariableAsToggle';
import computeImplicitVariable from './computeVariable/computeImplicitVariable';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
export default function computeVariable(computation, node) {
const scope = computation.scope;

View File

@@ -12,7 +12,7 @@ export default function aggregateDefinition({ node, linkedNode, link }) {
!definingProp ||
prop.type !== 'pointBuyRow' && (
definingProp.type === 'pointBuyRow' ||
prop.order > definingProp.order
prop.left > definingProp.left
)
) {
// override the current defining prop

View File

@@ -10,7 +10,7 @@ export default function aggregateEventDefinition({ node, linkedNode, link }) {
// Find the last defining event
if (
!definingEvent ||
prop.order > definingEvent.order
prop.left > definingEvent.left
) {
// override the current defining prop
if (definingEvent) definingEvent.overridden = true;

View File

@@ -1,10 +1,10 @@
import definition from './aggregateDefinition.js';
import damageMultiplier from './aggregateDamageMultiplier.js';
import effect from './aggregateEffect.js';
import eventDefinition from './aggregateEventDefinition.js';
import proficiency from './aggregateProficiency.js';
import classLevel from './aggregateClassLevel.js';
import inventory from './aggregateInventory.js';
import definition from './aggregateDefinition';
import damageMultiplier from './aggregateDamageMultiplier';
import effect from './aggregateEffect';
import eventDefinition from './aggregateEventDefinition';
import proficiency from './aggregateProficiency';
import classLevel from './aggregateClassLevel';
import inventory from './aggregateInventory';
export default Object.freeze({
classLevel,

View File

@@ -1,61 +1,61 @@
import getAggregatorResult from './getAggregatorResult.js';
import getAggregatorResult from './getAggregatorResult';
/*
* Variables with effects, proficiencies, or damage multipliers but no defining
* properties are added to the scope as implicit variables
*/
export default function computeImplicitVariable(node){
const prop = {};
export default function computeImplicitVariable(node) {
const prop = {};
// Combine damage multipliers
if (node.data.immunity){
if (node.data.immunity) {
prop.immunity = node.data.immunity;
prop.immunities = node.data.immunities;
}
if (node.data.resistance){
if (node.data.resistance) {
prop.resistance = node.data.resistance;
prop.resistances = node.data.resistances;
}
if (node.data.vulnerability){
if (node.data.vulnerability) {
prop.vulnerability = node.data.vulnerability;
prop.vulnerabilities = node.data.vulnerabilities;
}
const result = getAggregatorResult(node);
if (result !== undefined){
prop.value = result;
}
if (node.data.proficiency !== undefined){
prop.proficiency = node.data.proficiency;
}
const result = getAggregatorResult(node);
if (result !== undefined) {
prop.value = result;
}
if (node.data.proficiency !== undefined) {
prop.proficiency = node.data.proficiency;
}
// denormalise class level aggregator
let classLevelAgg = node.data.classLevelAggregator;
if (classLevelAgg){
prop.level = classLevelAgg.level;
}
// denormalise class level aggregator
let classLevelAgg = node.data.classLevelAggregator;
if (classLevelAgg) {
prop.level = classLevelAgg.level;
}
// denormalise the effect aggregator fields
const aggregator = node.data.effectAggregator;
if (aggregator){
if (aggregator.advantage && !aggregator.disadvantage){
prop.advantage = 1;
} else if (aggregator.disadvantage && !aggregator.advantage){
prop.advantage = -1;
} else {
prop.advantage = 0;
}
// Passive bonus
prop.passiveBonus = aggregator.passiveAdd;
// conditional benefits
prop.conditionalBenefits = aggregator.conditional;
// Roll bonuses
prop.rollBonus = aggregator.rollBonus;
// Forced to fail
prop.fail = aggregator.fail;
// Rollbonus
prop.rollBonuses = aggregator.rollBonus;
}
// denormalise the effect aggregator fields
const aggregator = node.data.effectAggregator;
if (aggregator) {
if (aggregator.advantage && !aggregator.disadvantage) {
prop.advantage = 1;
} else if (aggregator.disadvantage && !aggregator.advantage) {
prop.advantage = -1;
} else {
prop.advantage = 0;
}
// Passive bonus
prop.passiveBonus = aggregator.passiveAdd;
// conditional benefits
prop.conditionalBenefits = aggregator.conditional;
// Roll bonuses
prop.rollBonus = aggregator.rollBonus;
// Forced to fail
prop.fail = aggregator.fail;
// Rollbonus
prop.rollBonuses = aggregator.rollBonus;
}
return prop;
}
return prop;
}

View File

@@ -1,4 +1,4 @@
import getAggregatorResult from './getAggregatorResult.js';
import getAggregatorResult from './getAggregatorResult';
export default function computeVariableAsAttribute(computation, node, prop) {
let result = getAggregatorResult(node) || 0;

View File

@@ -1,6 +1,6 @@
import { parse } from '/imports/parser/parser.js';
import { parse } from '/imports/parser/parser';
export default function computeVariableAsConstant(computation, node, prop){
export default function computeVariableAsConstant(computation, node, prop) {
let string = prop.calculation;
if (!string) return;
let parseNode;

View File

@@ -1,4 +1,4 @@
import aggregate from './aggregate/index.js';
import aggregate from './aggregate/index';
export default function computeVariableAsSkill(computation, node, prop) {
// Skills are based on some ability Modifier

View File

@@ -1,6 +1,6 @@
import getAggregatorResult from './getAggregatorResult.js';
import getAggregatorResult from './getAggregatorResult';
export default function computeVariableAsToggle(computation, node, prop){
export default function computeVariableAsToggle(computation, node, prop) {
let result = getAggregatorResult(node, prop) || 0;
prop.value = !!result || !!prop.enabled || !!prop.condition?.value;

View File

@@ -1,4 +1,4 @@
import stripFloatingPointOddities from '/imports/api/engine/computation/utility/stripFloatingPointOddities.js';
import stripFloatingPointOddities from '/imports/api/engine/computation/utility/stripFloatingPointOddities';
export default function getAggregatorResult(node) {
// Work out the base value as the greater of the deining stat value

View File

@@ -1,9 +1,9 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import computeCreatureComputation from '../../computeCreatureComputation.js';
import clean from '../../utility/cleanProp.testFn.js';
import computeCreatureComputation from '../../computeCreatureComputation';
import clean from '../../utility/cleanProp.testFn';
export default function(){
export default function () {
const computation = buildComputationFromProps(testProperties);
computeCreatureComputation(computation);
@@ -33,7 +33,6 @@ var testProperties = [
clean({
_id: 'actionId',
type: 'action',
ancestors: [{id: 'charId'}],
summary: {
text: 'test summary {1 + 2} without referencing anything {3 + 4}',
},
@@ -61,14 +60,17 @@ var testProperties = [
calculation: 'nonExistantProperty + 7',
},
usesUsed: 5,
left: 1,
right: 2,
}),
clean({
_id: 'rolledDescriptionId',
type: 'action',
ancestors: [{id: 'charId'}],
summary: {
text: 'test roll gets compiled {4 + (2 + 2)} properly',
},
left: 3,
right: 4,
}),
clean({
_id: 'numItemsConumedId',
@@ -77,6 +79,8 @@ var testProperties = [
baseValue: {
calculation: '3',
},
left: 5,
right: 6,
}),
clean({
_id: 'numResourceConumedId',
@@ -85,6 +89,8 @@ var testProperties = [
baseValue: {
calculation: '4',
},
left: 7,
right: 8,
}),
clean({
_id: 'resourceVarId',
@@ -94,6 +100,8 @@ var testProperties = [
baseValue: {
calculation: '9',
},
left: 9,
right: 10,
}),
clean({
_id: 'inlineRefResourceId',
@@ -102,6 +110,8 @@ var testProperties = [
baseValue: {
calculation: '1 + 5',
},
left: 11,
right: 12,
}),
clean({
_id: 'arrowId',
@@ -110,5 +120,7 @@ var testProperties = [
quantity: 27,
icon: 'itemIcon',
color: 'itemColor',
left: 13,
right: 14,
}),
];

View File

@@ -1,7 +1,7 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import computeCreatureComputation from '../../computeCreatureComputation.js';
import clean from '../../utility/cleanProp.testFn.js';
import computeCreatureComputation from '../../computeCreatureComputation';
import clean from '../../utility/cleanProp.testFn';
export default function () {
const computation = buildComputationFromProps(testProperties);
@@ -27,6 +27,8 @@ var testProperties = [
_id: 'emptyId',
type: 'attribute',
attributeType: 'ability',
left: 1,
right: 2,
}),
clean({
_id: 'noVariableNameId',
@@ -35,6 +37,8 @@ var testProperties = [
baseValue: {
calculation: '8'
},
left: 3,
right: 4,
}),
clean({
_id: 'strengthId',
@@ -44,6 +48,8 @@ var testProperties = [
baseValue: {
calculation: '12'
},
left: 5,
right: 6,
}),
clean({
_id: 'overriddenDexId',
@@ -54,6 +60,8 @@ var testProperties = [
baseValue: {
calculation: '15'
},
left: 7,
right: 8,
}),
clean({
_id: 'dexterityId',
@@ -64,6 +72,8 @@ var testProperties = [
baseValue: {
calculation: '15'
},
left: 9,
right: 10,
}),
clean({
_id: 'constitutionId',
@@ -73,6 +83,8 @@ var testProperties = [
baseValue: {
calculation: '21'
},
left: 11,
right: 12,
}),
clean({
_id: 'referencesDexId',
@@ -81,6 +93,8 @@ var testProperties = [
baseValue: {
calculation: 'dexterity.modifier + 2'
},
left: 13,
right: 14,
}),
clean({
_id: 'hitDiceId',
@@ -91,6 +105,8 @@ var testProperties = [
baseValue: {
calculation: '4'
},
left: 15,
right: 16,
}),
clean({
_id: 'parseErrorId',
@@ -100,5 +116,7 @@ var testProperties = [
baseValue: {
calculation: '12 +'
},
left: 17,
right: 18,
}),
];

View File

@@ -1,9 +1,10 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import computeCreatureComputation from '../../computeCreatureComputation.js';
import clean from '../../utility/cleanProp.testFn.js';
import computeCreatureComputation from '../../computeCreatureComputation';
import clean from '../../utility/cleanProp.testFn';
import { applyNestedSetProperties } from '/imports/api/parenting/parentingFunctions';
export default function(){
export default function () {
const computation = buildComputationFromProps(testProperties);
computeCreatureComputation(computation);
const scope = id => computation.scope[id];
@@ -20,41 +21,37 @@ var testProperties = [
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'}],
}),
];
applyNestedSetProperties(testProperties);

View File

@@ -1,9 +1,10 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import computeCreatureComputation from '../../computeCreatureComputation.js';
import clean from '../../utility/cleanProp.testFn.js';
import computeCreatureComputation from '../../computeCreatureComputation';
import clean from '../../utility/cleanProp.testFn';
import { applyNestedSetProperties } from '/imports/api/parenting/parentingFunctions';
export default function(){
export default function () {
const computation = buildComputationFromProps(testProperties);
computeCreatureComputation(computation);
const prop = id => computation.propsById[id];
@@ -23,6 +24,7 @@ var testProperties = [
baseValue: {
calculation: 'arrayConstant[3]',
},
ancestors: [{id: 'charId'}],
}),
];
applyNestedSetProperties(testProperties);

View File

@@ -1,9 +1,9 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import computeCreatureComputation from '../../computeCreatureComputation.js';
import clean from '../../utility/cleanProp.testFn.js';
import computeCreatureComputation from '../../computeCreatureComputation';
import clean from '../../utility/cleanProp.testFn';
export default function(){
export default function () {
const computation = buildComputationFromProps(testProperties);
computeCreatureComputation(computation);
const scope = id => computation.scope[id];

View File

@@ -1,7 +1,7 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import computeCreatureComputation from '../../computeCreatureComputation.js';
import { propsFromForest } from '/imports/api/properties/tests/propTestBuilder.testFn.js';
import computeCreatureComputation from '../../computeCreatureComputation';
import clean from '../../utility/cleanProp.testFn';
export default function () {
const computation = buildComputationFromProps(testProperties);

View File

@@ -1,9 +1,10 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import computeCreatureComputation from '../../computeCreatureComputation.js';
import clean from '../../utility/cleanProp.testFn.js';
import computeCreatureComputation from '../../computeCreatureComputation';
import clean from '../../utility/cleanProp.testFn';
import { applyNestedSetProperties, compareOrder } from '/imports/api/parenting/parentingFunctions';
export default function(){
export default function () {
const computation = buildComputationFromProps(testProperties);
computeCreatureComputation(computation);
const prop = id => computation.propsById[id];
@@ -13,9 +14,8 @@ export default function(){
assert.equal(scope('valueEquipment'), 3);
assert.equal(scope('itemsAttuned'), 1);
assert.equal(prop('childContainerId').carriedWeight, 69);
assert.equal(prop('childContainerId').contentsWeight, 69);
assert.equal(prop('childContainerId').carriedWeight, 69, 'Calculates container carried weight correctly');
assert.equal(prop('childContainerId').contentsWeight, 69, 'Calculates container contents weight correctly');
assert.equal(scope('weightCarried'), 104);
assert.equal(scope('valueCarried'), 129);
@@ -32,7 +32,6 @@ var testProperties = [
attuned: true,
weight: 2,
value: 3,
ancestors: [{id: 'charId'}],
}),
clean({
_id: 'containerId',
@@ -40,22 +39,13 @@ var testProperties = [
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'}],
parentId: 'containerId',
}),
clean({
_id: 'grandchildItemId',
@@ -63,6 +53,16 @@ var testProperties = [
weight: 23, // 69 total
value: 29, // 87 total
quantity: 3,
ancestors: [{id: 'charId'}, {id: 'containerId'}, {id: 'childContainerId'}],
parentId: 'childContainerId',
}),
clean({
_id: 'childContainerId',
type: 'container',
carried: true,
weight: 11,
value: 13,
parentId: 'containerId',
}),
];
applyNestedSetProperties(testProperties);
testProperties.sort(compareOrder);

View File

@@ -1,10 +1,12 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import computeCreatureComputation from '../../computeCreatureComputation.js';
import clean from '../../utility/cleanProp.testFn.js';
import computeCreatureComputation from '../../computeCreatureComputation';
import clean from '../../utility/cleanProp.testFn';
import { applyNestedSetProperties, compareOrder } from '/imports/api/parenting/parentingFunctions';
export default function () {
const computation = buildComputationFromProps(testProperties);
const hasLink = computation.dependencyGraph.hasLink;
computeCreatureComputation(computation);
const prop = id => computation.propsById[id];
assert.equal(
@@ -38,7 +40,6 @@ var testProperties = [
clean({
_id: 'actionId',
type: 'action',
ancestors: [{ id: 'charId' }],
attackRoll: {
calculation: 'strength.modifier',
},
@@ -48,7 +49,6 @@ var testProperties = [
_id: 'profBonusId',
type: 'attribute',
variableName: 'proficiencyBonus',
ancestors: [{ id: 'charId' }],
baseValue: {
calculation: '13'
},
@@ -62,3 +62,5 @@ var testProperties = [
targetTags: ['martial weapon']
}),
];
applyNestedSetProperties(testProperties);
testProperties.sort(compareOrder);

View File

@@ -1,9 +1,9 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation';
import { assert } from 'chai';
import computeCreatureComputation from '../../computeCreatureComputation.js';
import clean from '../../utility/cleanProp.testFn.js';
import computeCreatureComputation from '../../computeCreatureComputation';
import clean from '../../utility/cleanProp.testFn';
export default function(){
export default function () {
const computation = buildComputationFromProps(testProperties);
computeCreatureComputation(computation);
const prop = id => computation.propsById[id];

View File

@@ -1,14 +1,12 @@
import computeAction from './computeAction.testFn.js';
import computeAttribute from './computeAttribute.testFn.js';
import computeCalculations from './computeCalculations.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';
import computePointBuys from './computePointBuys.testFn.js';
import computeProficiencies from './computeProficiencies.testFn.js';
import computeAction from './computeAction.testFn';
import computeAttribute from './computeAttribute.testFn';
import computeClasses from './computeClasses.testFn';
import computeConstants from './computeConstants.testFn';
import computeInventory from './computeInventory.testFn';
import computeDamageMultipliers from './computeDamageMultipliers.testFn';
import computeEffects from './computeEffects.testFn';
import computeSkills from './computeSkills.testFn';
import computeProficiencies from './computeProficiencies.testFn';
export default [{
text: 'Computes actions',

View File

@@ -1,7 +1,7 @@
import computeToggles from '/imports/api/engine/computation/computeComputation/computeToggles.js';
import computeByType from '/imports/api/engine/computation/computeComputation/computeByType.js';
import embedInlineCalculations from './utility/embedInlineCalculations.js';
import { removeEmptyCalculations } from './buildComputation/parseCalculationFields.js';
import computeToggles from '/imports/api/engine/computation/computeComputation/computeToggles';
import computeByType from '/imports/api/engine/computation/computeComputation/computeByType';
import embedInlineCalculations from './utility/embedInlineCalculations';
import { removeEmptyCalculations } from './buildComputation/parseCalculationFields';
import path from 'ngraph.path';
export default function computeCreatureComputation(computation) {

View File

@@ -1,11 +1,11 @@
import computeCreatureComputation from './computeCreatureComputation.js';
import { buildComputationFromProps } from './buildCreatureComputation.js';
import computeCreatureComputation from './computeCreatureComputation';
import { buildComputationFromProps } from './buildCreatureComputation';
import { assert } from 'chai';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
import computeTests from './computeComputation/tests/index.js';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
import computeTests from './computeComputation/tests/index';
describe('Compute compuation', function(){
it('Computes something at all', function(){
describe('Compute compuation', function () {
it('Computes something at all', function () {
let computation = buildComputationFromProps(testProperties);
computeCreatureComputation(computation);
assert.exists(computation);
@@ -28,7 +28,7 @@ var testProperties = [
}),
];
function clean(prop){
function clean(prop) {
let schema = CreatureProperties.simpleSchema(prop);
return schema.clean(prop);
}

View File

@@ -1,9 +1,9 @@
import applyFnToKey from './applyFnToKey.js';
import applyFnToKey from './applyFnToKey';
import { assert } from 'chai';
import { get } from 'lodash';
describe('apply function to key', function(){
it('uses a basic key correctly', function(){
describe('apply function to key', function () {
it('uses a basic key correctly', function () {
let obj = getStartingObject();
applyFnToKey(obj, 'fox.name', (doc, key) => {
assert.equal(obj, doc);
@@ -11,7 +11,7 @@ describe('apply function to key', function(){
assert.equal(get(doc, key), 'foxy');
});
});
it('uses a single nested key correctly', function(){
it('uses a single nested key correctly', function () {
let obj = getStartingObject();
let foxSounds = [];
applyFnToKey(obj, 'fox.sound.$', (doc, key) => {
@@ -21,7 +21,7 @@ describe('apply function to key', function(){
assert.include(foxSounds, 'tjoef');
assert.include(foxSounds, 'kek');
});
it('uses a double nested key correctly', function(){
it('uses a double nested key correctly', function () {
let obj = getStartingObject();
let birdSounds = [];
applyFnToKey(obj, 'birds.$.sound.$', (doc, key) => {
@@ -33,7 +33,7 @@ describe('apply function to key', function(){
});
});
function getStartingObject(){
function getStartingObject() {
return {
fox: {
name: 'foxy',
@@ -48,7 +48,7 @@ function getStartingObject(){
sound: [
'koer',
]
},{
}, {
name: 'parrot',
sound: [
'hello',

View File

@@ -1,6 +1,9 @@
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
export default function cleanProp(prop){
export default function cleanProp(prop) {
if (!prop.root) {
prop.root = { collection: 'creatures', id: 'testCreature' }
}
let schema = CreatureProperties.simpleSchema(prop);
return schema.clean(prop);
}

View File

@@ -1,6 +1,6 @@
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX.js';
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX';
export default function embedInlineCalculations(inlineCalcObj){
export default function embedInlineCalculations(inlineCalcObj) {
const string = inlineCalcObj.text;
const calculations = inlineCalcObj.inlineCalculations;
if (!string || !calculations) return;

View File

@@ -1,10 +0,0 @@
export default function findAncestorByType(prop, type, propsById){
if (!prop || !prop.ancestors) return;
let ancestor;
for (let i = prop.ancestors.length - 1; i >= 0; i--){
ancestor = propsById[prop.ancestors[i].id];
if (ancestor && ancestor.type === type){
return ancestor;
}
}
}

View File

@@ -1,7 +1,7 @@
import { Meteor } from 'meteor/meteor'
import { EJSON } from 'meteor/ejson';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
import propertySchemasIndex from '/imports/api/properties/computedOnlyPropertySchemasIndex.js';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
import propertySchemasIndex from '/imports/api/properties/computedOnlyPropertySchemasIndex';
export default function writeAlteredProperties(computation) {
let bulkWriteOperations = [];

View File

@@ -1,9 +1,9 @@
import Creatures from '/imports/api/creature/creatures/Creatures.js';
import Creatures from '/imports/api/creature/creatures/Creatures';
export default function(creatureId, errors = []){
if (errors.length){
Creatures.update(creatureId, {$set: {computeErrors: errors}});
export default function (creatureId, errors = []) {
if (errors.length) {
Creatures.update(creatureId, { $set: { computeErrors: errors } });
} else {
Creatures.update(creatureId, {$unset: {computeErrors: 1}});
Creatures.update(creatureId, { $unset: { computeErrors: 1 } });
}
}

View File

@@ -1,5 +1,5 @@
import CreatureVariables from '/imports/api/creature/creatures/CreatureVariables.js';
import Creatures from '/imports/api/creature/creatures/Creatures.js';
import CreatureVariables from '/imports/api/creature/creatures/CreatureVariables';
import Creatures from '/imports/api/creature/creatures/Creatures';
import { EJSON } from 'meteor/ejson';
export default function writeScope(creatureId, computation) {
@@ -27,7 +27,6 @@ export default function writeScope(creatureId, computation) {
// Remove large properties that aren't likely to be accessed
delete scope[key].parent;
delete scope[key].ancestors;
// Remove empty keys
for (const subKey in scope[key]) {