Example #1
0
        private static (ICalculationGraph, ICalculationGraphPruner) CreateCalculationGraph(
            TransformableNodeFactory nodeFactory, StatRegistry statRegistry, ValueTransformer valueTransformer,
            IEventBuffer eventBuffer)
        {
            var coreGraph = new CoreCalculationGraph(
                s => CreateStatGraph(nodeFactory, valueTransformer, eventBuffer, s), nodeFactory);
            var eventGraph = new CalculationGraphWithEvents(coreGraph);

            var defaultPruningRuleSet            = new DefaultPruningRuleSet(statRegistry);
            var defaultPruner                    = new CalculationGraphPruner(eventGraph, defaultPruningRuleSet);
            var userSpecifiedValuePruningRuleSet =
                new UserSpecifiedValuePruningRuleSet(defaultPruningRuleSet, statRegistry);
            var userSpecifiedValuePruner =
                new CalculationGraphPruner(eventGraph, userSpecifiedValuePruningRuleSet);
            var pruner = new CompositeCalculationGraphPruner(defaultPruner, userSpecifiedValuePruner);

            eventGraph.StatAdded       += StatAdded;
            eventGraph.StatRemoved     += StatRemoved;
            eventGraph.ModifierAdded   += ModifierAdded;
            eventGraph.ModifierRemoved += ModifierRemoved;
            return(eventGraph, pruner);

            void StatAdded(IStat stat)
            {
                statRegistry.Add(stat);
                valueTransformer.AddBehaviors(stat.Behaviors);
                defaultPruner.StatAdded(stat);
                userSpecifiedValuePruner.StatAdded(stat);
            }

            void StatRemoved(IStat stat)
            {
                statRegistry.Remove(stat);
                valueTransformer.RemoveBehaviors(stat.Behaviors);
                defaultPruner.StatRemoved(stat);
                userSpecifiedValuePruner.StatRemoved(stat);
            }

            void ModifierAdded(Modifier modifier)
            {
                defaultPruner.ModifierAdded(modifier);
                userSpecifiedValuePruner.ModifierAdded(modifier);
            }

            void ModifierRemoved(Modifier modifier)
            {
                defaultPruner.ModifierRemoved(modifier);
                userSpecifiedValuePruner.ModifierRemoved(modifier);
            }
        }
Example #2
0
        /// <summary>
        /// Creates an <see cref="ICalculator"/>.
        /// </summary>
        public static ICalculator Create()
        {
            var eventBuffer            = new EventBuffer();
            var innerNodeFactory       = new NodeFactory(eventBuffer);
            var nodeFactory            = new TransformableNodeFactory(innerNodeFactory, v => new TransformableValue(v));
            var statRegistryCollection = new NodeCollection <IStat>(eventBuffer);
            var statRegistry           = new StatRegistry(statRegistryCollection);
            var valueTransformer       = new ValueTransformer();

            var(graph, pruner) = CreateCalculationGraph(nodeFactory, statRegistry, valueTransformer, eventBuffer);

            var defaultView   = new DefaultViewNodeRepository(graph);
            var bufferingView = new BufferingViewNodeRepository(graph);

            innerNodeFactory.NodeRepository = defaultView;
            statRegistry.NodeRepository     = bufferingView;

            return(new Calculator(eventBuffer, graph, pruner, bufferingView, statRegistryCollection));
        }
Example #3
0
        private static PrunableCalculationGraph CreateCalculationGraph(
            TransformableNodeFactory nodeFactory, StatRegistry statRegistry, ValueTransformer valueTransformer)
        {
            var coreGraph =
                new CoreCalculationGraph(s => CreateStatGraph(nodeFactory, valueTransformer, s), nodeFactory);
            var eventGraph = new CalculationGraphWithEvents(coreGraph, StatAdded, StatRemoved);

            return(new PrunableCalculationGraph(eventGraph, statRegistry));

            void StatAdded(IStat stat)
            {
                statRegistry.Add(stat);
                valueTransformer.AddBehaviors(stat.Behaviors);
            }

            void StatRemoved(IStat stat)
            {
                statRegistry.Remove(stat);
                valueTransformer.RemoveBehaviors(stat.Behaviors);
            }
        }
Example #4
0
        /// <summary>
        /// Creates an <see cref="ICalculator"/>.
        /// </summary>
        public static ICalculator CreateCalculator()
        {
            var innerNodeFactory       = new NodeFactory();
            var nodeFactory            = new TransformableNodeFactory(innerNodeFactory, v => new TransformableValue(v));
            var statRegistryCollection = new NodeCollection <IStat>();
            var statRegistry           = new StatRegistry(statRegistryCollection);
            var valueTransformer       = new ValueTransformer();

            var prunableGraph = CreateCalculationGraph(nodeFactory, statRegistry, valueTransformer);

            var defaultView     = new DefaultViewNodeRepository(prunableGraph);
            var suspendableView = new SuspendableViewNodeRepository(prunableGraph);

            innerNodeFactory.NodeRepository = defaultView;
            statRegistry.NodeRepository     = suspendableView;

            var suspender = new SuspendableEventsComposite();

            suspender.Add(new StatGraphCollectionSuspender(prunableGraph));
            suspender.Add(statRegistryCollection);

            return(new Calculator(suspender, prunableGraph, prunableGraph, suspendableView, statRegistryCollection));
        }