コード例 #1
0
        public void When_AddNode_Expect_NodeAdded()
        {
            NodeGraph nodeGraph = new NodeGraph();

            Node node = new Node(1, 1, 1);

            nodeGraph.AddNode(node);

            Assert.AreEqual(1, nodeGraph.Nodes.Count);
            Assert.AreEqual(node.coordinate, nodeGraph.Nodes[0].coordinate);
            Assert.AreNotEqual(node.index, nodeGraph.Nodes[0].index);
        }
コード例 #2
0
        public void When_AddNodeWithMultipleNeighbors_Expect_AllLinked(NodeGraph nodeGraph)
        {
            Node newNode = new Node(5, 5, 5);

            Node neighbor1 = nodeGraph.Nodes[0];
            Node neighbor2 = nodeGraph.Nodes[1];

            nodeGraph.AddNode(newNode, neighbor1, neighbor2);

            Assert.That(nodeGraph.AreLinked(newNode, neighbor1));
            Assert.That(nodeGraph.AreLinked(newNode, neighbor2));
        }
コード例 #3
0
    public virtual void SpawnNode(Type type, Vector2 position)
    {
        Node node = graph.AddNode(type);

        node.position = position;

        if (node is NTNode)
        {
            node.name = ((NTNode)node).GetDisplayName();
        }

        Refresh();
    }
コード例 #4
0
 private static void AddRequired(NodeGraph graph, Type type, ref Vector2 position)
 {
     if (!graph.nodes.Any(x => x.GetType() == type))
     {
         xNode.Node node = graph.AddNode(type);
         node.position = position;
         position.x   += 200;
         if (node.name == null || node.name.Trim() == "")
         {
             node.name = NodeEditorUtilities.NodeDefaultName(type);
         }
         if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(graph)))
         {
             AssetDatabase.AddObjectToAsset(node, graph);
         }
     }
 }
コード例 #5
0
    public void LoadMechanicGraph(int inputSeed = -1)
    {
        List <NodeGrammar> grammars = new List <NodeGrammar>();

        foreach (var grammar in _nodeGrammars)
        {
            grammars.AddRange(NodeGrammar.ImportGrammars(Application.streamingAssetsPath + "/Grammar/Node/" + grammar + ".json"));
        }

        // generate a simple left hand side for now
        var inputGraph = new NodeGraph();

        inputGraph.AddNode(new Node()
        {
            Node_text = "S"
        });

        var seed = _randomString ? UnityEngine.Random.Range(0, 1000) : _seed;

        if (inputSeed != -1)
        {
            seed = inputSeed;
        }

        var stringgrams = GrammarUtils.ImportGrammars(Application.streamingAssetsPath + "/Grammar/String/" + _stringGrammar + ".json");
        var inputString = GrammarUtils.ApplyGrammars(ref stringgrams, _inputString, seed);

        Debug.Log("mechanic generated with input string " + inputString);
        Debug.Log("Seed: " + seed);
        FindObjectOfType <SeedDisplay>()?.DisplaySeed(seed);
        _mechanicGraph = GrammarUtils.ApplyNodeGrammars(inputString, ref grammars, inputGraph, seed);
        AnalyseMechanicNodes();


        AdjustBalance();
        AnalyseMechanicNodes();
        ApplySignifiers();

        NodeBehaviour.Callbacks      = new Stack <NodeActivationCallBack>();
        NodeBehaviour.PlayerAttacks  = GetComponent <PlayerAttackControl>();
        NodeBehaviour.PlayerMovement = GetComponent <PlayerMovement>();
    }
コード例 #6
0
    public static NodeGraph CreateFromBinary(byte[] value)
    {
        ByteBuffer buffer = new ByteBuffer(value);
        NodeGraph  data   = new NodeGraph();

        data.ToRect();
        data.Name       = buffer.ReadString();
        data.Type       = (NODETYPE)buffer.ReadByte();
        data.ScriptName = buffer.ReadString();
        data.Weight     = buffer.ReadInt32();
        data.NodeRect.x = buffer.ReadFloat();
        data.NodeRect.y = buffer.ReadFloat();
        int count = buffer.ReadInt32();

        for (int i = 0; i < count; ++i)
        {
            data.AddNode(CreateFromBinary(buffer.ReadBytes()));
        }
        return(data);
    }
コード例 #7
0
        public void When_AddNodeWithSameLocation_Expect_NoChange()
        {
            NodeGraph nodeGraph = new NodeGraph();

            Node firstNode  = new Node(1, 1, 1);
            Node secondNode = new Node(2, 2, 2);
            Node thirdNode  = new Node(3, 3, 3);

            nodeGraph.AddNode(firstNode);
            nodeGraph.AddNode(secondNode);
            nodeGraph.AddNode(thirdNode);

            Node testNode = new Node(1, 1, 1);

            nodeGraph.AddNode(testNode);
            nodeGraph.AddNode(testNode, secondNode);
            nodeGraph.AddNode(testNode, secondNode, thirdNode);
            nodeGraph.AddNode(testNode, testNode);

            Assert.AreEqual(3, nodeGraph.Nodes.Count);
        }
コード例 #8
0
        private void AddNodeWithNonExistentNeighborByBadIndex()
        {
            // Build CoreLinkedNodeGraph for helper function
            NodeGraph nodeGraph  = new NodeGraph();
            Node      node       = new Node(1, 1, 1);
            Node      secondNode = new Node(2, 2, 2);
            Node      thirdNode  = new Node(3, 3, 3);
            Node      fourthNode = new Node(4, 4, 4);
            Node      fifthNode  = new Node(5, 5, 5);

            nodeGraph.AddNode(node);
            nodeGraph.AddNode(secondNode, node);
            nodeGraph.AddNode(thirdNode, node);
            nodeGraph.AddNode(fourthNode, node);
            nodeGraph.AddNode(fifthNode, node);

            Node newNode = new Node(6, 6, 6);

            nodeGraph.AddNode(newNode, 12515);
        }
コード例 #9
0
ファイル: Sink.cs プロジェクト: benjohns1/processor-game
 public bool Init(NodeGraph g)
 {
     return(g.AddNode(sink));
 }
コード例 #10
0
    /// <summary>
    /// Processes the designer components into the network data structure.
    /// </summary>
    public void PreCalculate()
    {
        // Retrieve nodes from the scene.
        FloorNode[]     fNodes = transform.GetComponentsInChildren <FloorNode>();
        ClimbableNode[] cNodes = transform.GetComponentsInChildren <ClimbableNode>();

        // Convert the nodes into a smaller data structure.
        List <Path> floorPaths = new List <Path>();

        foreach (FloorNode fNode in fNodes)
        {
            floorPaths.Add(new Path(fNode.transform.position,
                                    (Vector2)fNode.transform.position + Vector2.right * fNode.Length));
        }
        List <Path> climbablePaths = new List <Path>();

        foreach (ClimbableNode cNode in cNodes)
        {
            climbablePaths.Add(new Path(cNode.transform.position,
                                        (Vector2)cNode.transform.position + Vector2.up * cNode.Length));
        }
        // Create a list to keep track of all of the junctions.
        List <Junction> junctionsAccumulator = new List <Junction>();

        // For each floor node-path from the scene:
        foreach (Path fPath in floorPaths)
        {
            // Check for connections with climbable node-paths:
            foreach (Path cPath in climbablePaths)
            {
                // Is there an x intersection?
                if (cPath.start.x >= fPath.start.x && cPath.start.x <= fPath.end.x)
                {
                    // Is there a y intersection?
                    if (fPath.start.y >= cPath.start.y && fPath.start.y <= cPath.end.y)
                    {
                        // Add the junction to both paths.
                        Junction junction = new Junction(fPath, cPath, cPath.start.x - fPath.start.x,
                                                         fPath.start.y - cPath.start.y);
                        fPath.junctions.Add(junction);
                        cPath.junctions.Add(junction);
                        junctionsAccumulator.Add(junction);
                    }
                }
            }
        }

        graphIndices = new Dictionary <Junction, int>();
        nodeGraph    = new NodeGraph();
        int insertionIndex = 0;

        foreach (Path path in floorPaths)
        {
            path.junctions.Sort();
            for (int i = 0; i < path.junctions.Count; i++)
            {
                nodeGraph.AddNode(new GraphNode(path.junctions[i].intersection));
                graphIndices.Add(path.junctions[i], insertionIndex);
                insertionIndex++;
            }
            for (int i = 0; i < path.junctions.Count - 1; i++)
            {
                GraphNode before = nodeGraph.Nodes[graphIndices[path.junctions[i]]];
                GraphNode after  = nodeGraph.Nodes[graphIndices[path.junctions[i + 1]]];
                before.AddLink(after);
                after.AddLink(before);
            }
        }
        foreach (Path path in climbablePaths)
        {
            path.junctions.Sort();
            for (int i = 0; i < path.junctions.Count - 1; i++)
            {
                GraphNode before = nodeGraph.Nodes[graphIndices[path.junctions[i]]];
                GraphNode after  = nodeGraph.Nodes[graphIndices[path.junctions[i + 1]]];
                before.AddLink(after);
                after.AddLink(before);
            }
        }

        // Combine and post paths and junctions.
        floorPaths.AddRange(climbablePaths);
        Paths     = floorPaths.ToArray();
        Junctions = junctionsAccumulator.ToArray();


        // Notify anyone that is listening for path changes.
        OnNetworkChanged?.Invoke();
    }
コード例 #11
0
 public bool Init(NodeGraph g)
 {
     return(g.AddNode(source));
 }