コード例 #1
0
    /// <summary>
    /// Creates a Logic Graph from the data in this Class
    /// </summary>
    public LogicChip getLogicGraph()
    {
        LogicChip result = new LogicChip(this.Width, this.Height, this.Name);

        foreach (GraphComponentData gcd in this.Components)
        {
            Type           type           = Type.GetType(gcd.Type);
            LightComponent lightComponent = null;

            if (type.IsSubclassOf(typeof(LightComponent)))
            {
                if (!type.IsSubclassOf(typeof(LinkComponent)))
                {
                    lightComponent = (LightComponent)Activator.CreateInstance(
                        type, new object[] {
                        new Vector2Int(gcd.Position[0], gcd.Position[1]),
                        gcd.Rotaiton,
                        gcd.Flipped
                    });
                }
                else
                {
                    if (type == typeof(GraphOutput))
                    {
                        lightComponent = new GraphOutput(new Vector2Int(gcd.Position[0], gcd.Position[1]),
                                                         gcd.Rotaiton,
                                                         gcd.Flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.SEND));
                    }
                    else if (type == typeof(GraphInput))
                    {
                        lightComponent = new GraphInput(new Vector2Int(gcd.Position[0], gcd.Position[1]),
                                                        gcd.Rotaiton,
                                                        gcd.Flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.RECEIVE));
                    }
                    else
                    {
                        throw new Exception(type + " is not supported when loading data");
                    }
                }

                if (type.IsSubclassOf(typeof(LogicComponent)))
                {
                    LogicComponent logic = (LogicComponent)lightComponent;
                    logic.setState();
                }
            }
            else
            {
                throw new Exception("Type " + type + " is not accepted from LogicGraphData");
            }

            if (lightComponent != null)
            {
                lightComponent.setValues(gcd.Values);
                result.LightGraph.addComponent(lightComponent);
            }
        }

        return(result);
    }
コード例 #2
0
    public bool removeComponent(LightComponent component)
    {
        //removes the component from the graph
        bool result = false;

        List <LightComponent> all = this.getAllGraphComponents();
        int counter = 0;

        while (counter < all.Count && !result)
        {
            if (all[counter].Equals(component))
            {
                if (component.GetType().IsSubclassOf(typeof(LogicComponent)))
                {
                    result = this.logicComponents.Remove((LogicComponent)component);
                }
                else if (component.GetType().IsSubclassOf(typeof(PassiveComponent)))
                {
                    result = this.passiveComponents.Remove((PassiveComponent)component);
                }
                else if (component.GetType().IsSubclassOf(typeof(LinkComponent)))
                {
                    //ExtensionConnection[]
                    if (component.GetType() == typeof(GraphInput))
                    {
                        GraphInput rec = (GraphInput)component;
                        result = this.logicGraph.removeReceiveBridge(rec.getExtensionConnection());
                        this.linkComponents.Remove(rec);
                    }
                    else if (component.GetType() == typeof(GraphOutput))
                    {
                        GraphOutput send = (GraphOutput)component;
                        result = this.logicGraph.removeSendBridge(send.getExtensionConnection());
                        this.linkComponents.Remove(send);
                    }
                    else
                    {
                        throw new System.Exception(component.GetType() + " can not be removed to the Logic Graph");
                    }
                }
                else
                {
                    throw new Exception("TypeNotFound: type " + component.GetType() + " is not a subclass on the looked at classes");
                }
            }
            counter++;
        }

        if (result == true)
        {
            //redundent statement but i like it

            this.LGUtilities.disconnectGraph();
            this.LGUtilities.connectGraph();
        }

        return(result);
    }
コード例 #3
0
ファイル: Open.xaml.cs プロジェクト: kaareHH/Evacuate
        /* Handler for when the start button is pressed. Starts the program (Skal implementeres)
         * if all fields are filled out
         */
        public void StartPathCalculation(object sender, EventArgs e)
        {
            Controller DataController = new Controller();

            if (CheckIfEverythingIsSet())
            {
                // MessageBoxResult Result = MessageBox.Show("Calculation should run now (PlaceHolder)");
                FileInformation MapPath;
                double          StepWidth            = 0,
                                StepHeight           = 0,
                                doorleafsRoomDoor    = 0,
                                doorleafsHallwayDoor = 0,
                                doorleafsEscapeDoor  = 0;
                int AgentsPerNode                    = 0;

                // Sends the path for the selected map in Gui to the GenerateMap controller
                MapPath = FloorPlan.SelectedItem as FileInformation;
                DataController.GenerateMap(MapPath.FilePath);

                // Sends the width and heigth of staircases to the SetStaircases controller
                if (double.TryParse(stairWidth.Text, out StepWidth) && double.TryParse(stairRise.Text, out StepHeight))
                {
                    DataController.SetStaircases(StepWidth, StepHeight);
                }

                // Sends the amount of agents per node to the SpawnAgentsOnNodes controller
                if (int.TryParse(totalInput.Text, out AgentsPerNode))
                {
                    DataController.SpawnAgentsOnNodes(AgentsPerNode);
                }
                // Send the amount of doorleafs for hallway doors to the SetDoors controller
                if (double.TryParse(HallwayDoorleafAmount.Text, out doorleafsHallwayDoor))
                {
                    DataController.SetDoors <HallwayDoor>(doorleafsHallwayDoor);
                }
                // Send the amount of doorleafs for room doors to the SetDoors controller
                if (double.TryParse(RoomDoorleafAmount.Text, out doorleafsRoomDoor))
                {
                    DataController.SetDoors <RoomDoor>(doorleafsRoomDoor);
                }
                // Send the amount of doorleafs for escape doors to the SetDoors controller
                if (double.TryParse(EscapeDoorleafAmount.Text, out doorleafsEscapeDoor))
                {
                    DataController.SetDoors <ExitDoor>(doorleafsRoomDoor);
                }

                GraphData = DataController.RunProgram();
                GraphOutput test = new GraphOutput(GraphData);
            }

            else
            {
                MessageBoxResult Result = MessageBox.Show("All fields must be filled out");
            }
        }
コード例 #4
0
        private static void ConvertToEmbed()
        {
            var selection = GraphWindow.active?.reference?.graph?.Canvas().selection;

            if (selection != null && selection.Count > 0)
            {
                Undo.RegisterCompleteObjectUndo(GraphWindow.active?.reference.rootObject, "Add Sub Graph to Script Graph");

                var superUnit       = new NestedNode();
                var superUnitGraph  = new FlowGraph();
                var superUnitCanvas = superUnitGraph.Canvas <FlowCanvas>();
                var elements        = selection.ToList();

                superUnit.position = GetNestedNodePosition(elements);

                ((FlowGraph)GraphWindow.active.reference.graph).units.Add(superUnit);

                superUnit.nest.SwitchToEmbed(superUnitGraph);

                CopyElementsToGraph(superUnitCanvas);

                var graphInput  = new GraphInput();
                var graphOutput = new GraphOutput();

                var listWithoutInputOutput = ((FlowGraph)GraphWindow.active.reference.graph).units.ToList();

                superUnitGraph.units.Add(graphInput);
                superUnitGraph.units.Add(graphOutput);

                CopyControlConnectionData(superUnitGraph, graphInput, graphOutput, GetControlIndices(selection, superUnit));
                CopyValueConnectionData(superUnitGraph, graphInput, graphOutput, GetValueIndices(selection, superUnit));
                CopyInvalidConnectionData(superUnitGraph, graphInput, graphOutput, GetInvalidIndices(selection, superUnit));

                SetInputOutputPosition(superUnitGraph, graphInput, graphOutput);

                superUnitGraph.pan = superUnit.position;

                RemoveUnusedDefinitions(superUnitGraph);

                superUnitGraph.PortDefinitionsChanged();

                GraphWindow.active.reference.graph.Canvas <FlowCanvas>().DeleteSelection();
                GraphWindow.active.reference.graph.Canvas <FlowCanvas>().selection.Add(superUnit);
            }
        }
コード例 #5
0
    private LightComponent duplicateAt(Type type, Vector2Int position, int rotation, bool flipped)
    {
        //makes a duplicate of the component passed in

        LightComponent result = null;

        if (type == typeof(AndGate))
        {
            result = new AndGate(position, rotation, flipped);
        }
        else if (type == typeof(OrGate))
        {
            result = new OrGate(position, rotation, flipped);
        }
        else if (type == typeof(NotGate))
        {
            result = new NotGate(position, rotation, flipped);
        }
        else if (type == typeof(BufferGate))
        {
            result = new BufferGate(position, rotation, flipped);
        }
        else if (type == typeof(NandGate))
        {
            result = new NandGate(position, rotation, flipped);
        }
        else if (type == typeof(XorGate))
        {
            result = new XorGate(position, rotation, flipped);
        }
        else if (type == typeof(XnorGate))
        {
            result = new XnorGate(position, rotation, flipped);
        }
        else if (type == typeof(NorGate))
        {
            result = new NorGate(position, rotation, flipped);
        }
        else if (type == typeof(Splitter))
        {
            result = new Splitter(position, rotation, flipped);
        }
        else if (type == typeof(Reflector))
        {
            result = new Reflector(position, rotation, flipped);
        }
        else if (type == typeof(GraphOutput))
        {
            result = new GraphOutput(position, rotation, flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.SEND));
        }
        else if (type == typeof(GraphInput))
        {
            result = new GraphInput(position, rotation, flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.RECEIVE));
        }
        else
        {
            throw new System.Exception(type + " was not found when selecting the from the logic graph editor");
        }

        return(result);
    }
コード例 #6
0
        private static void SetInputOutputPosition(FlowGraph graph, GraphInput input, GraphOutput output)
        {
            var posXIn  = 0f;
            var posYIn  = 0f;
            var posXOut = 0f;
            var posYOut = 0f;

            for (int i = 0; i < graph.units.Count; i++)
            {
                if (posXIn >= graph.units[i].position.x)
                {
                    posXIn = graph.units[i].position.x;
                    posYIn = graph.units[i].position.y;
                }

                if (graph.units[i].position.x <= posXOut)
                {
                    posXOut = graph.units[i].position.x;
                    posYOut = graph.units[i].position.y;
                }
            }

            input.position  = new Vector2(posXIn - 240, posYIn);
            output.position = new Vector2(posXOut + 240, posYOut);
        }
コード例 #7
0
 private static void CopyInvalidConnectionData(FlowGraph superUnitGraph, GraphInput graphInput, GraphOutput graphOutput, List <ConnectionData> connectionData)
 {
     for (int i = 0; i < connectionData.Count; i++)
     {
         superUnitGraph.invalidConnections.Add(new InvalidConnection(superUnitGraph.units[connectionData[i].sourceUnitIndex].invalidOutputs.ToList()[connectionData[i].sourceOutputIndex] as IUnitOutputPort,
                                                                     superUnitGraph.units[connectionData[i].destinationUnitIndex].invalidInputs.ToList()[connectionData[i].destinationInputIndex] as IUnitInputPort));
     }
 }
コード例 #8
0
        private static void CopyValueConnectionData(FlowGraph superUnitGraph, GraphInput graphInput, GraphOutput graphOutput, List <ConnectionData> connectionData)
        {
            List <string> keys = new List <string>();

            for (int i = 0; i < connectionData.Count; i++)
            {
                var index = i;

                var _key = GetKeyName(connectionData[i], keys);

                if (!keys.Contains(_key))
                {
                    keys.Add(_key);
                }

                switch (connectionData[index].source)
                {
                case ConnectionDataSource.GraphInput:
                    var def       = connectionData[index].valueType.Default();
                    var isDefault = def != null;
                    superUnitGraph.valueInputDefinitions.Add(new ValueInputDefinition()
                    {
                        key  = _key,
                        type = connectionData[index].valueType
                    });
                    superUnitGraph.PortDefinitionsChanged();
                    graphInput.valueOutputs.Single((op) => { return(op.key == _key); }).ConnectToValid(superUnitGraph.units[connectionData[index].destinationUnitIndex].valueInputs.ToList()[connectionData[index].destinationInputIndex] as ValueInput);
                    connectionData[index].subgraph.valueInputs.Single((op) => { return(op.key == _key); }).ConnectToValid(connectionData[index].externalPort as ValueOutput);
                    break;

                case ConnectionDataSource.GraphOutput:
                    superUnitGraph.valueOutputDefinitions.Add(new ValueOutputDefinition()
                    {
                        key  = _key,
                        type = connectionData[index].valueType,
                    });
                    superUnitGraph.PortDefinitionsChanged();
                    graphOutput.valueInputs.Single((op) => { return(op.key == _key); }).ConnectToValid(superUnitGraph.units[connectionData[index].sourceUnitIndex].valueOutputs.ToList()[connectionData[index].sourceOutputIndex] as ValueOutput);
                    connectionData[index].subgraph.valueOutputs.Single((op) => { return(op.key == _key); }).ConnectToValid(connectionData[index].externalPort as ValueInput);
                    break;

                case ConnectionDataSource.Node:
                    superUnitGraph.valueConnections.Add(new ValueConnection(superUnitGraph.units[connectionData[index].sourceUnitIndex].valueOutputs.ToList()[connectionData[index].sourceOutputIndex] as ValueOutput,
                                                                            superUnitGraph.units[connectionData[index].destinationUnitIndex].valueInputs.ToList()[connectionData[index].destinationInputIndex] as ValueInput));
                    break;
                }
            }
        }
コード例 #9
0
 public BReceiver(Rect rect, GraphOutput output, int stateNumber) : base(rect)
 {
     this.stateNumber = stateNumber;
     this.graphOutput = output;
 }
コード例 #10
0
    public void Simulation()
    {
        var playerInput = this.playerInputCollector.GetPlayerInput();

        var innerInput = new InnerInput
        {
            userCount = new UserCount
            {
                counts = new Dictionary <UserSegment, long>
                {
                    { UserSegment.MuKakin, this.userCountProgress.MukakinUserCounts.Last() },
                    { UserSegment.BiKakin, this.userCountProgress.BikakinUserCounts.Last() },
                    { UserSegment.TyuKakin, this.userCountProgress.TyukakinUserCounts.Last() },
                    { UserSegment.JuKakin, this.userCountProgress.JukakinUserCounts.Last() },
                    { UserSegment.Sekiyuo, this.userCountProgress.SekiyuoCounts.Last() }
                }
            },
            satisfaction = new UserSatisfaction
            {
                value = this.satisfactionProgress.satisFactions.Last()
            }
        };

        var graphOutput = new GraphOutput();

        var imValues = new IntermediateValues
        {
            kindness  = 0f,
            bonusRate = 1f
        };

        var calculationHalfway = new CalculationHalfway
        {
            playerInput = playerInput,
            innerInput  = innerInput,
            graphOutput = graphOutput,
            imValues    = imValues
        };

        var result = this.calculator.Calc(calculationHalfway);

        // Update Progresses
        var profit = result.graphOutput.balance.income - result.graphOutput.balance.expenditure;

        this.moneyProgress.moneys.Add(this.moneyProgress.moneys.Last() + profit);

        var opens = result.graphOutput.opness.opens;

        if (opens != null)
        {
            this.commandOpenness.Ceiling       = opens.Contains(UpdateTarget.Ceiling);
            this.commandOpenness.CompleteGacha = opens.Contains(UpdateTarget.CompleteGacha);
        }

        this.userCountProgress.MukakinUserCounts.Add(result.innerInput.userCount.counts[UserSegment.MuKakin]);
        this.userCountProgress.BikakinUserCounts.Add(result.innerInput.userCount.counts[UserSegment.BiKakin]);
        this.userCountProgress.TyukakinUserCounts.Add(result.innerInput.userCount.counts[UserSegment.TyuKakin]);
        this.userCountProgress.JukakinUserCounts.Add(result.innerInput.userCount.counts[UserSegment.JuKakin]);
        this.userCountProgress.SekiyuoCounts.Add(result.innerInput.userCount.counts[UserSegment.Sekiyuo]);

        this.satisfactionProgress.satisFactions.Add(result.innerInput.satisfaction.value);

        this.termProgress.currentTerm++;

        if (this.termProgress.currentTerm % 4 == 0)
        {
            this.commandOpenness.ConfirmGacha = true;
        }
        else
        {
            this.commandOpenness.ConfirmGacha = false;
        }

        if (this.termProgress.currentTerm % 5 == 0)
        {
            this.commandOpenness.Update = true;
        }
        else
        {
            this.commandOpenness.Update = false;
        }

        if (this.termProgress.currentTerm == 9)
        {
            this.commandOpenness.HukubukuroGacha = true;
        }
        else
        {
            this.commandOpenness.HukubukuroGacha = false;
        }

        if (this.satisfactionProgress.satisFactions.Last() < 5f)
        {
            this.commandOpenness.StoneDistribution = true;
        }
        else
        {
            this.commandOpenness.StoneDistribution = false;
        }

        // Save Premium Gacha rates
        var premiumRates = playerInput.gachaParams[GachaCategory.Premium].rates;

        this.premiumGachaRate.nRate   = premiumRates.rates[GachaRarity.N];
        this.premiumGachaRate.rRate   = premiumRates.rates[GachaRarity.R];
        this.premiumGachaRate.srRate  = premiumRates.rates[GachaRarity.SR];
        this.premiumGachaRate.ssrRate = premiumRates.rates[GachaRarity.SSR];
        this.premiumGachaRate.urRate  = premiumRates.rates[GachaRarity.UR];
        this.premiumGachaRate.lrRate  = premiumRates.rates[GachaRarity.LR];
    }
コード例 #11
0
 public bool Connectable(GraphOutput output, GraphInput input)
 {
     return(output != null && input != null && output.connectTypeId == input.connectTypeId &&
            output.body is GraphNode_Mission);
 }
コード例 #12
0
 public bool Connectable(GraphOutput output, GraphInput input)
 {
     return(input.body is GraphNode_Mission);
 }