Fixing UI for 2.1 data changes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import TaskResult from './tasks/TaskResult';
|
||||
import LogContentSchema from '/imports/api/creature/log/LogContentSchema';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
|
||||
const EngineActions = new Mongo.Collection<EngineAction>('actions');
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { EngineAction } from '/imports/api/engine/action/EngineActions';
|
||||
|
||||
export async function writeChangedAction(originalAction: EngineAction, action: EngineAction) {
|
||||
console.warn('writeChangedAction not implemented.');
|
||||
}
|
||||
@@ -8,8 +8,6 @@ import {
|
||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
|
||||
import { assertEditPermission } from '/imports/api/creature/creatures/creaturePermissions';
|
||||
import { damagePropertyWork } from '/imports/api/creature/creatureProperties/methods/damageProperty';
|
||||
import { doActionWork } from '/imports/api/engine/actions/doAction';
|
||||
import ActionContext from '/imports/api/engine/actions/ActionContext';
|
||||
|
||||
// TODO Migrate this to the new action engine
|
||||
|
||||
@@ -48,6 +46,8 @@ const doAction = new ValidatedMethod({
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({ spellId, slotId, ritual, targetIds = [], scope = {} }) {
|
||||
console.warn('Do cast spell not implemented');
|
||||
return;
|
||||
// Get action context
|
||||
let spell = CreatureProperties.findOne(spellId);
|
||||
const creatureId = spell.root.id;
|
||||
|
||||
@@ -24,6 +24,8 @@ const doCheck = new ValidatedMethod({
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({ propId, scope }) {
|
||||
console.warn('do check not implemented');
|
||||
return;
|
||||
const prop = CreatureProperties.findOne(propId);
|
||||
if (!prop) throw new Meteor.Error('not-found', 'The property was not found');
|
||||
const creatureId = prop.root.id;
|
||||
|
||||
@@ -3,6 +3,9 @@ import SimpleSchema from 'simpl-schema';
|
||||
import EngineActions from '/imports/api/engine/action/EngineActions';
|
||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions';
|
||||
import { getCreature } from '/imports/api/engine/loadCreatures';
|
||||
import { EJSON } from 'meteor/ejson';
|
||||
import { applyAction } from '/imports/api/engine/action/functions/applyAction';
|
||||
import { writeChangedAction } from '../functions/writeChangedAction';
|
||||
|
||||
export const runAction = new ValidatedMethod({
|
||||
name: 'actions.runAction',
|
||||
|
||||
@@ -8,12 +8,12 @@ interface CreatureProperty {
|
||||
}
|
||||
|
||||
export default class CreatureComputation {
|
||||
originalPropsById: object;
|
||||
propsById: object;
|
||||
propsWithTag: object;
|
||||
scope: object;
|
||||
originalPropsById: Record<string, CreatureProperty>;
|
||||
propsById: Record<string, CreatureProperty>;
|
||||
propsWithTag: Record<string, string[]>;
|
||||
scope: Record<string, any>;
|
||||
props: Array<CreatureProperty>;
|
||||
dependencyGraph: Graph;
|
||||
dependencyGraph: Graph<any, string>;
|
||||
errors: Array<object>;
|
||||
creature: object;
|
||||
variables: object;
|
||||
|
||||
@@ -27,7 +27,7 @@ function isActive(prop: CreatureProperty): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
function childrenActive(prop): boolean {
|
||||
function childrenActive(prop: CreatureProperty): boolean {
|
||||
// Children of disabled properties are always inactive
|
||||
if (prop.disabled) return false;
|
||||
switch (prop.type) {
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import walkDown from '/imports/api/engine/computation/utility/walkdown';
|
||||
import { getEffectTagTargets } from '/imports/api/engine/computation/buildComputation/linkTypeDependencies';
|
||||
import { Forest, TreeNode } from '/imports/api/parenting/parentingFunctions';
|
||||
import { CreatureProperty } from '/imports/api/creature/creatureProperties/CreatureProperties';
|
||||
import CreatureComputation from '/imports/api/engine/computation/CreatureComputation';
|
||||
|
||||
export default function computeToggleDependencies(node, dependencyGraph, computation, forest) {
|
||||
export default function computeToggleDependencies(
|
||||
node: TreeNode<CreatureProperty>, computation: CreatureComputation, forest: Forest<CreatureProperty>
|
||||
) {
|
||||
const prop = node.doc
|
||||
// Only for toggles
|
||||
if (prop.type !== 'toggle') return;
|
||||
@@ -12,11 +17,11 @@ export default function computeToggleDependencies(node, dependencyGraph, computa
|
||||
const target = forest.nodeIndex[targetId];
|
||||
if (!target) return;
|
||||
target.doc._computationDetails.toggleAncestors.push(prop);
|
||||
dependencyGraph.addLink(target.doc._id, prop._id, 'toggle');
|
||||
computation.dependencyGraph.addLink(target.doc._id, prop._id, 'toggle');
|
||||
walkDown(target.children, child => {
|
||||
// The child nodes depend on the toggle
|
||||
child.doc._computationDetails.toggleAncestors.push(prop);
|
||||
dependencyGraph.addLink(child.doc._id, prop._id, 'toggle');
|
||||
computation.dependencyGraph.addLink(child.doc._id, prop._id, 'toggle');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -27,6 +32,6 @@ export default function computeToggleDependencies(node, dependencyGraph, computa
|
||||
walkDown(node.children, child => {
|
||||
// The child nodes depend on the toggle
|
||||
child.doc._computationDetails.toggleAncestors.push(prop);
|
||||
dependencyGraph.addLink(child.doc._id, prop._id, 'toggle');
|
||||
computation.dependencyGraph.addLink(child.doc._id, prop._id, 'toggle');
|
||||
});
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
export default function linkInventory(forest, dependencyGraph) {
|
||||
// The stack of properties to still navigate
|
||||
const stack = [...forest];
|
||||
const stack = [...forest.trees];
|
||||
// The current containers we are inside of
|
||||
const containerStack = [];
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { applyNestedSetProperties, calculateNestedSetOperations } from '/imports/api/parenting/parentingFunctions';
|
||||
import { DenormalisedOnlyCreaturePropertySchema as denormSchema }
|
||||
import { applyNestedSetProperties } from '/imports/api/parenting/parentingFunctions';
|
||||
import { CreatureProperty, DenormalisedOnlyCreaturePropertySchema as denormSchema }
|
||||
from '/imports/api/creature/creatureProperties/CreatureProperties';
|
||||
import { getProperties, getCreature, getVariables } from '/imports/api/engine/loadCreatures';
|
||||
import computedOnlySchemas from '/imports/api/properties/computedOnlyPropertySchemasIndex';
|
||||
@@ -29,7 +29,7 @@ import removeSchemaFields from './buildComputation/removeSchemaFields';
|
||||
* computed toggles
|
||||
*/
|
||||
|
||||
export default function buildCreatureComputation(creatureId) {
|
||||
export default function buildCreatureComputation(creatureId: string) {
|
||||
const creature = getCreature(creatureId);
|
||||
const variables = getVariables(creatureId);
|
||||
const properties = getProperties(creatureId);
|
||||
@@ -37,7 +37,9 @@ export default function buildCreatureComputation(creatureId) {
|
||||
return computation;
|
||||
}
|
||||
|
||||
export function buildComputationFromProps(properties, creature, variables) {
|
||||
export function buildComputationFromProps(
|
||||
properties: CreatureProperty[], creature, variables
|
||||
) {
|
||||
|
||||
const computation = new CreatureComputation(properties, creature, variables);
|
||||
// Dependency graph where edge(a, b) means a depends on b
|
||||
@@ -89,13 +91,13 @@ export function buildComputationFromProps(properties, creature, variables) {
|
||||
const forest = applyNestedSetProperties(properties);
|
||||
|
||||
// Walk the property trees computing things that need to be inherited
|
||||
walkDown(forest, node => {
|
||||
walkDown(forest.trees, node => {
|
||||
computeInactiveStatus(node);
|
||||
});
|
||||
// Inactive status must be complete for the whole tree before toggle deps
|
||||
// are calculated
|
||||
walkDown(forest, node => {
|
||||
computeToggleDependencies(node, dependencyGraph, computation, forest);
|
||||
walkDown(forest.trees, node => {
|
||||
computeToggleDependencies(node, computation, forest);
|
||||
computeSlotQuantityFilled(node, dependencyGraph);
|
||||
});
|
||||
|
||||
@@ -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 async function () {
|
||||
const computation = buildComputationFromProps(testProperties);
|
||||
|
||||
@@ -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 { propsFromForest } from '/imports/api/properties/tests/propTestBuilder.testFn';
|
||||
|
||||
export default async function () {
|
||||
const computation = buildComputationFromProps(testProperties);
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
export default function walkDown(tree, callback){
|
||||
let stack = [...tree];
|
||||
while(stack.length){
|
||||
let node = stack.pop();
|
||||
callback(node, stack);
|
||||
stack.push(...node.children);
|
||||
}
|
||||
}
|
||||
14
app/imports/api/engine/computation/utility/walkdown.ts
Normal file
14
app/imports/api/engine/computation/utility/walkdown.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { TreeDoc } from '/imports/api/parenting/ChildSchema';
|
||||
import { TreeNode } from '/imports/api/parenting/parentingFunctions';
|
||||
|
||||
export default function walkDown<T extends TreeDoc>(
|
||||
trees: TreeNode<T>[], callback: (node: TreeNode<T>, stack: TreeNode<T>[]) => any
|
||||
) {
|
||||
const stack = [...trees];
|
||||
while (stack.length) {
|
||||
const node = stack.pop();
|
||||
if (!node) return;
|
||||
callback(node, stack);
|
||||
stack.push(...node.children);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,6 @@ async function computeComputation(computation, creatureId) {
|
||||
logError.location = e.stack.split('\n')[1];
|
||||
}
|
||||
console.error(logError);
|
||||
throw e;
|
||||
} finally {
|
||||
checkPropertyCount(computation)
|
||||
writeErrors(creatureId, computation.errors);
|
||||
|
||||
@@ -52,7 +52,7 @@ export function getSingleProperty(creatureId: string, propertyId: string) {
|
||||
return prop;
|
||||
}
|
||||
|
||||
export function getProperties(creatureId) {
|
||||
export function getProperties(creatureId: string): CreatureProperty[] {
|
||||
const creature = loadedCreatures.get(creatureId);
|
||||
if (creature) {
|
||||
const props = Array.from(creature.properties.values());
|
||||
@@ -94,7 +94,7 @@ export function getPropertiesOfType(creatureId, propType) {
|
||||
return props;
|
||||
}
|
||||
|
||||
export function getCreature(creatureId) {
|
||||
export function getCreature(creatureId: string) {
|
||||
const loadedCreature = loadedCreatures.get(creatureId);
|
||||
const loadedCreatureDoc = loadedCreature?.creature;
|
||||
if (loadedCreatureDoc) {
|
||||
@@ -106,7 +106,7 @@ export function getCreature(creatureId) {
|
||||
return creature;
|
||||
}
|
||||
|
||||
export function getVariables(creatureId) {
|
||||
export function getVariables(creatureId: string) {
|
||||
const loadedCreature = loadedCreatures.get(creatureId);
|
||||
const loadedVariables = loadedCreature?.variables;
|
||||
if (loadedVariables) {
|
||||
|
||||
Reference in New Issue
Block a user