private void CreateInitialData()
        {
            _root = new Node {Name = "root"};
            _child1 = new Node {Name = "child1"};
            _child2 = new Node {Name = "child2"};
            _child1_1 = new Node { Name = "grand child 1-1" };
            _child1_2 = new Node { Name = "grand child 1-2" };
            _child1_3 = new Node { Name = "grand child 1-3" };
            _child2_1 = new Node { Name = "grand child 2-1" };
            _child2_2 = new Node { Name = "grand child 2-2" };

            _root.AddChild(_child1);
            _root.AddChild(_child2);
            _child1.AddChild(_child1_1);
            _child1.AddChild(_child1_2);
            _child1.AddChild(_child1_3);
            _child2.AddChild(_child2_1);
            _child2.AddChild(_child2_2);

            using (var session = _sessionFactory.OpenSession())
            {
                session.Save(_root);
                session.Flush();
            }
        }
Example #2
0
 public void ExecuteRecursive()
 {
     Node n = new Node { Data = 0 }, root = n;
     for (int i = 1; i < 15; i++)
     {
         Node child = new Node { Data = i };
         n.AddChild(child);
         n = child;
     }
     n.AddChild(root);
     Node clone = Serializer.DeepClone(root);
 }
Example #3
0
        public static Node Create()
        {
            var cmp = new MyCharacters();

            var node = new Node("Characters");
            node.Attach(cmp);

            node.AddChild (MyCharacter.Create ("A子"));
            node.AddChild (MyCharacter.Create ("B子"));
            node.AddChild (MyCharacter.Create ("C子"));

            return node;
        }
Example #4
0
        public static Node Create(Vector3 pos)
        {
            var cmp = new MyButtons ();

            var node = new Node ("Buttons");
            node.Attach (cmp);

            node.AddChild (MyButton.Create("Button1", "A子", new Vector3(0,0,0)));
            node.AddChild (MyButton.Create ("Button2", "B子", new Vector3 (80, 0, 0)));
            node.AddChild (MyButton.Create ("Button3", "C子", new Vector3 (160, 0, 0)));

            node.Translation = pos;

            return node;
        }
        public void ShouldErrorInvalidTopLevelStatementAndKeepParsing()
        {
            #region Arrange Invalid Token Input

            var badToken = new Token(TokenType.String, 5, 5, "for");
            var tokenList = new List<Token>
            {
                badToken,
                // and the keep parsing part
                new Token(TokenType.EndLine, 0, 4, Environment.NewLine),
                new Token(TokenType.Id, 0, 0, "syntax"),
                new Token(TokenType.Control, 0, 1, "="),
                new Token(TokenType.String, 0, 2, "\"proto3\""),
                new Token(TokenType.Control, 0, 3, ";"),
                new Token(TokenType.EndLine, 0, 4, Environment.NewLine)
            };

            #endregion Arrange Invalid Token Input

            #region Arrange Expected NodeTree Output

            // Verify we kept parsing.
            var root = new RootNode();
            var errors = new[] { new ParseError("Found an invalid top level statement at token ", badToken) };
            var syntax = new Node(NodeType.Syntax, "syntax");
            var proto3 = new Node(NodeType.StringLiteral, "proto3");
            syntax.AddChild(proto3);
            root.AddErrors(errors);
            root.AddChild(syntax);

            #endregion Arrange Expected NodeTree Output

            AssertSyntax(tokenList, root);
        }
Example #6
0
 public void ChangeFather(Node node)
 {
     if(fatherNode!= null)
         fatherNode.RemoveChild(this,false);
     node.AddChild(this);
     fatherNode = node;
 }
        public MoshParser(ILexer lexer)
        {
            m_startRuleToken = new Token { TokenType = TokenType.NEW_RULE };
            m_tree = new Node<string>();
            m_lexer = lexer;
            m_consumed = new Stack<Token>();
            m_err = new Queue<Error>();

            // Setup rule pre-calling conditions
            m_rulePreHook = name =>
                                {
                                    if (m_tree.Value == null)
                                    {
                                        m_tree.Value = name;
                                        return m_tree;
                                    }

                                    var tempNode = m_tree;
                                    var newTopNode = m_tree.AddChild(name);
                                    m_tree = newTopNode;
                                    return tempNode;
                                };

            // Setup rule post-calling conditions
            m_rulePostHook = node => m_tree = node;
        }
    public Node AddChild(int data)
    {
        if (Left == null)
        {
            lastPath = Direction.Left;
            Left     = new Node(data, this);
            return(this);
        }
        if (Right == null)
        {
            lastPath = Direction.Right;
            Right    = new Node(data, this);
            return(parent ?? this);
        }

        if (lastPath == Direction.Parent || parent == null && lastPath == Direction.Right)
        {
            lastPath = Direction.Left;
            return(Left.AddChild(data));
        }

        if (lastPath == Direction.Left)
        {
            lastPath = Direction.Right;
            return(Right.AddChild(data));
        }

        lastPath = Direction.Parent;
        return(parent?.AddChild(data));
    }
        public void ShouldBuildInlineComment()
        {
            #region Arrange Multiline Comment Token Input

            var tokenList = new List<Token>
            {
                new Token(TokenType.Comment, 0, 0, "\\\\"),
                new Token(TokenType.String, 0, 5, "This"),
                new Token(TokenType.String, 0, 6, "is"),
                new Token(TokenType.String, 0, 7, "a"),
                new Token(TokenType.String, 0, 8, "comment."),
                new Token(TokenType.EndLine, 0, 9, Environment.NewLine)
            };

            #endregion Arrange Multiline Comment Token Input

            #region Arrange Expected NodeTree Output

            var root = new RootNode();
            var comment = new Node(NodeType.Comment, "\\\\");
            // Bit of an issue here, notice the spaces around the NewLine, we'd like to make that go away.
            var text = "This is a comment.";
            var commentText = new Node(NodeType.CommentText, text);
            comment.AddChild(commentText);
            root.AddChild(comment);

            #endregion Arrange Expected NodeTree Output

            AssertSyntax(tokenList, root);
        }
        public void ShouldBuildImportNode()
        {
            #region Arrange Import Declaration Token Input

            var tokenList = new List<Token>
            {
                new Token(TokenType.Id, 0, 0, "import"),
                new Token(TokenType.String, 0, 1, "\"other.message\""),
                new Token(TokenType.Control, 0, 2, ";"),
                new Token(TokenType.EndLine, 0, 4, Environment.NewLine)
            };

            #endregion Arrange Import Declaration Token Input

            #region Arrange Expected NodeTree Output

            var root = new RootNode();
            var import = new Node(NodeType.Import, "import");
            var otherMessage = new Node(NodeType.StringLiteral, "other.message");
            import.AddChild(otherMessage);
            root.AddChild(import);

            #endregion Arrange Expected NodeTree Output

            AssertSyntax(tokenList, root);
        }
        public void ShouldBuildInlineStatementWithTrailingComment()
        {
            #region Arrange Inline Trailing Comment Token Input

            var tokenList = new List<Token>
            {
                new Token(TokenType.Id, 0, 0, "syntax"),
                new Token(TokenType.Control, 0, 1, "="),
                new Token(TokenType.String, 0, 2, "\"proto3\""),
                new Token(TokenType.Control, 0, 3, ";"),
                new Token(TokenType.Comment, 0, 4, "\\\\"),
                new Token(TokenType.String, 0, 5, "This"),
                new Token(TokenType.String, 0, 6, "is"),
                new Token(TokenType.String, 0, 7, "a"),
                new Token(TokenType.String, 0, 8, "comment."),
                new Token(TokenType.EndLine, 0, 9, Environment.NewLine)
            };

            #endregion Arrange Inline Trailing Comment Token Input

            #region Arrange Expected NodeTree Output

            var root = new RootNode();
            var syntax = new Node(NodeType.Syntax, "syntax");
            var proto3 = new Node(NodeType.StringLiteral, "proto3");
            var comment = new Node(NodeType.Comment, "\\\\");
            var commentText = new Node(NodeType.CommentText, "This is a comment.");
            comment.AddChild(commentText);
            syntax.AddChildren(proto3, comment);
            root.AddChild(syntax);

            #endregion Arrange Expected NodeTree Output

            AssertSyntax(tokenList, root, null);
        }
Example #12
0
        public void Test_AddChild()
        {
            var node1 = new Node ("Node1");
            var node2 = new Node ("Node2");
            var node3 = new Node ("Node3");

            node1.AddChild (node2);
            node1.AddChild (node3);

            Assert.AreEqual (2, node1.ChildCount);
            Assert.AreEqual (2, node1.Children.Count ());
            Assert.AreEqual (node2, node1.GetChild (0));
            Assert.AreEqual (node3, node1.GetChild (1));

            Assert.AreEqual (node1, node2.Parent);
            Assert.AreEqual (node1, node3.Parent);
        }
Example #13
0
        public static Node Create(Vector3 pos)
        {
            var cmp = new MyCharacterSelector ();

            var node = new Node ("CharacterSelector");
            node.Attach (cmp);

            node.AddChild (MyCharacterButton.Create ("Nayu", new Vector3 (50, 100, 0)));
            node.AddChild (MyCharacterButton.Create ("Sayaka", new Vector3 (50, 180, 0)));
            node.AddChild (MyCharacterButton.Create ("Maki", new Vector3 (50, 260, 0)));
            node.AddChild (MyCharacterButton.Create ("Lily", new Vector3 (50, 340, 0)));
            node.AddChild (MyCharacterButton.Create ("Rinko", new Vector3 (50, 420, 0)));

            node.Translation = pos;

            return node;
        }
        protected virtual Node CreateBehaviourTree()
        {
            Node pxNode = new Node();
            pxNode.SetIsLeaf( false );
            pxNode.SetTaskType<SequenceTask>();

            Node pxChild_1 = new Node();
            pxChild_1.SetIsLeaf( true );
            pxNode.SetTaskType<DebugLogTask>();
            pxNode.AddChild( pxChild_1 );

            Node pxChild_2 = new Node();
            pxChild_2.SetIsLeaf( true );
            pxNode.SetTaskType<DebugLogTask>();
            pxNode.AddChild( pxChild_2 );

            return pxNode;
        }
Example #15
0
        private static void AddClassMembers(Node<TokenInfo> node, Type type)
        {
            var globalMembers = GlobalsInfo.GetGlobalMembers(type).ToList();

            var dotDelim = node.AddChild(ConstructDelimiterNode('.'));

            AddEvents(dotDelim, globalMembers);
            AddProperties(dotDelim, globalMembers);

            AddMethods(dotDelim, globalMembers);
        }
Example #16
0
        public void TestSelfRecursive()
        {
            Node orig = new Node();
            orig.AddChild(orig);
            Assert.AreEqual(1, orig.Children.Count);
            Assert.AreSame(orig, orig.Children[0]);

            var clone = Serializer.DeepClone(orig);
            Assert.AreEqual(1, clone.Children.Count);
            Assert.AreSame(clone, clone.Children[0]);
        }
Example #17
0
        public void Spawn()
        {
            if (Spawning)
            {
                var node = Node.Instance() as Obstacle;
                node.SetPosition(Position);

                node.Connect("OverCrossed", _target, "ScorePlayer");
                node.Connect("Collided", _target, "OnPlayerCollidedObstacle");
                _target.AddChild(node);
            }
        }
Example #18
0
    void CreateInventoryNodes()
    {
        invNode = new Node("Inventory");
        for (int i = 0; i < System.Enum.GetValues(typeof(invSlot)).Length; i++)
        {
            invNode.AddChild(new Node(((invSlot)i).ToString()));
        }
        for (int i = 0; i < items.Count; i++)
        {
            ItemInfo it   = items [i].GetComponent <ItemInfo> ();
            Node     slot = invNode.children [(int)it.invSlotPos];
            string   txt  = "";
            if (itemAmts[i] > 1)
            {
                txt = it.itemName + " (" + itemAmts[i] + ")";
            }
            else
            {
                txt = it.itemName;
            }
            slot.children.Add(new Node(txt, items [i]));
        }
        for (int i = 0; i < invNode.children.Count; i++)
        {
            if (invNode.children[i].children.Count == 0)
            {
                invNode.children[i].children.Add(new Node("No Items found here."));
            }
            Node child = invNode.children [i];
            switch (i)
            {
            case 0:
                child.options.Add(new MenuOption("Equip", 'E'));
                child.options.Add(new MenuOption("Drop", 'Q'));
                break;

            case 1:
                child.options.Add(new MenuOption("Equip", 'E'));
                child.options.Add(new MenuOption("Drop", 'Q'));
                break;

            case 2:
                child.options.Add(new MenuOption("Use", 'E'));
                child.options.Add(new MenuOption("Drop", 'Q'));
                break;

            case 3:
                child.options.Add(new MenuOption("Use", 'E'));
                child.options.Add(new MenuOption("Drop", 'Q'));
                break;
            }
        }
    }
Example #19
0
        public void TestAddChild()
        {
            var parent = new Node <int>(0);
            var child  = new Node <int>(1);

            parent.AddChild(child);

            Assert.AreEqual(1, parent.Children.Count());
            Assert.AreEqual(child, parent.Children.First());
            Assert.AreEqual(1, child.Parents.Count());
            Assert.AreEqual(parent, child.Parents.First());
        }
        private void AddChild(IEnumerable<Node> draggedNodes, Node targetNode)
        {
            //build list of nodes without childs
            var list = ExcludeChild(draggedNodes);

            //change parent
            foreach (var n in list)
            {
                n.Parent.Childs.Remove(n);
                targetNode.AddChild(n);
            }
        }
Example #21
0
        public static T Instantiate <T>(this Node node, string path, Transform2D pos) where T : Node
        {
            var v = PackedSceneInstance(path);

            node.AddChild(v);
            if (node is Node2D spatial)
            {
                spatial.Transform = pos;
            }

            return(v as T);
        }
    /// <summary>
    /// Inserts a word into the trie.
    /// This method will iterate through each character in the
    /// key, and insert the char if it doesn't exist in the trie
    /// </summary>
    public void Insert(string word)
    {
        // Get a reference to the root node for traversing
        Node node     = root;
        bool isPrefix = false;

        if (word.Length <= 0)
        {
            throw new ArgumentException("Word parameter cannot be an empty string!");
        }

        // Iterate through the word, and process each char
        // one at a time
        for (int i = 0; i < word.Length; i++)
        {
            char ch = word[i];

            // If the character doesn't exist in children
            // then create a new node and append it to the
            // current nodes children
            if (!node.children.ContainsKey(ch))
            {
                Node nextNode = new Node();
                node.AddChild(nextNode, ch);
            }

            // We keep traversing the trie as long as
            // there are still characters in the word
            node = node.children[ch];
        }

        // If the current node is already an end of word
        if (node.isEndOfWord)
        {
            isPrefix = true;
        }
        // If the current node is not the root, we know we can set
        // it as an end of word
        if (node != root)
        {
            node.isEndOfWord = true;
        }

        if (isPrefix)
        {
            Console.WriteLine($"Already exists in the Trie: {word}");
        }
        else
        {
            Console.WriteLine($"Successfully inserted word: {word}");
        }
    }
Example #23
0
    private void GenerateChilds(Node <BoardValue> pNode, TicTacToe pTic, int pDepth, bool maximizer)
    {
        int gameState = pTic.IsGameOver();

        if (gameState != -1)
        {
            if (gameState == 1)
            {
                pNode.Info.Value = 10 - pDepth;
            }
            else if (gameState == 2)
            {
                pNode.Info.Value = -10 + pDepth;
            }
            else
            {
                pNode.Info.Value = 0;
            }
        }
        else
        {
            pNode.Info.Value = maximizer ? int.MinValue : int.MaxValue;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (pTic.IsValidMove(i, j))
                    {
                        Node <BoardValue> nextNode = new Node <BoardValue>(pNode)
                        {
                            Info = new BoardValue()
                        };
                        nextNode.Info.MoveMade = new Vector2(i, j);
                        pNode.AddChild(nextNode);

                        pTic.MakeMove(i, j);
                        GenerateChilds(nextNode, pTic, pDepth + 1, !maximizer);
                        pTic.UndoMove();

                        if (maximizer)
                        {
                            pNode.Info.Value = Mathf.Max(nextNode.Info.Value, pNode.Info.Value);
                        }
                        else
                        {
                            pNode.Info.Value = Mathf.Min(nextNode.Info.Value, pNode.Info.Value);
                        }
                    }
                }
            }
        }
    }
Example #24
0
 /// Place le batiment sur la map
 public void Place(Vector2 location)
 {
     if (isPlaced)
     {
         return;
     }
     this.location = location;
     isPlaced      = true;
     SetZIndex(zIndex);
     SetPosition(location);
     parent.AddChild(this);
     return;
 }
Example #25
0
    public override void FireWeapon()
    {
        StandardBullet _clone     = (StandardBullet)_bulletScene.Instance();
        Node           _sceneRoot = GetTree().Root.GetChild(0);

        _sceneRoot.AddChild(_clone);

        _clone.GlobalTransform = GlobalTransform;
        _clone.Scale           = new Vector3(4, 4, 4);
        _clone.BulletDamage    = damage;
        AmmoInWeapon--;
        Playernode.CreateSound(gunFireSound);
    }
Example #26
0
    public static void Start()
    {
        Close();
        Menu.Close();

        Items.SetupItems();

        Node SkyScene = ((PackedScene)GD.Load("res://World/SkyScene.tscn")).Instance();

        SkyScene.SetName("SkyScene");
        Game.RuntimeRoot.AddChild(SkyScene);

        TilesRoot = new Node();
        TilesRoot.SetName("TilesRoot");
        SkyScene.AddChild(TilesRoot);

        EntitiesRoot = new Node();
        EntitiesRoot.SetName("EntitiesRoot");
        SkyScene.AddChild(EntitiesRoot);

        IsOpen = true;
    }
Example #27
0
    public static T CreateInstance <T>(string path, Node parentNode = null)
    {
        PackedScene scene        = (PackedScene)ResourceLoader.Load(path);
        Node        instanceNode = scene.Instance();

        if (parentNode != null)
        {
            parentNode.AddChild(instanceNode);
        }
        T instance = (T)Convert.ChangeType(instanceNode, typeof(T));

        return(instance);
    }
Example #28
0
        static Node generateMenu()
        {
            //Génération des objets composant le menu
            Leaf pointsHelp   = new Leaf("Objectif", "points");
            Leaf infiniteHelp = new Leaf("Infini", "infinite");
            Leaf timedHelp    = new Leaf("Chronométré", "timed");
            Leaf how          = new Leaf("Comment jouer", "how");
            Leaf list         = new Leaf("Liste", "list");
            Leaf score        = new Leaf("Score", "score");
            Leaf pointsPlay   = new Leaf("Objectif", "points");
            Leaf infinitePlay = new Leaf("Infini", "infinite");
            Leaf timedPlay    = new Leaf("Chronométré", "timed");
            Leaf jouer        = new Leaf("Partie rapide", "jouer");

            Node typeHelp = new Node("Type de partie", "type", menuObserver);
            Node commands = new Node("Commandes", "commands", menuObserver);
            Node help     = new Node("Aide", "help", menuObserver);
            Node typePlay = new Node("Type de partie", "type", menuObserver);
            Node root     = new Node("Menu", "menu", menuObserver);


            //On relie les noeuds entre eux pour former l'arbre des menus
            root.AddChild(jouer);
            root.AddChild(typePlay);
            typePlay.AddChild(timedPlay);
            typePlay.AddChild(infinitePlay);
            typePlay.AddChild(pointsPlay);
            root.AddChild(score);
            root.AddChild(help);
            help.AddChild(commands);
            commands.AddChild(list);
            commands.AddChild(how);
            help.AddChild(typeHelp);
            typeHelp.AddChild(timedHelp);
            typeHelp.AddChild(infiniteHelp);
            typeHelp.AddChild(pointsHelp);

            return(root);
        }
Example #29
0
    //Default code for firing a projectile.
    //Unlikely anyone will need to modify this very much.
    //But you can!
    public virtual void Fire()
    {
        string projectileScene = source.DequeueMunition();

        if (!(projectileScene is null))
        {
            Vector3 velocity = Muzzle.GlobalTransform.basis.Xform(-Vector3.Left) * muzzleVelocity;

            ProjectileProvider p = EasyInstancer.Instance <ProjectileProvider>(projectileScene);
            Projectiles.AddChild(p);
            p.Rpc("Init", Muzzle.GlobalTransform.origin, velocity);
        }
    }
Example #30
0
            private double ZValue = 0.0;                                //

            //Setup for the node
            public Node(Model model, Node parent, Transform segment, KinematicJoint joint, Objective objective)
            {
                Model  = model;
                Parent = parent;
                if (Parent != null)
                {
                    Parent.AddChild(this);
                }
                Segment   = segment;
                Chain     = new Chain(model.Root, segment);
                Joint     = joint;
                Objective = objective;
            }
Example #31
0
        private Spatial ParseNodes(Assimp.Node assimpNode, Node parent = null)
        {
            if (!assimpNode.HasMeshes && !assimpNode.HasChildren)
            {
                return(null);
            }

            if (!assimpNode.HasChildren && assimpNode.HasMeshes)
            {
                Spatial spatial;
                if (assimpNode.MeshCount == 1)
                {
                    spatial = CreateMesh(assimpNode);
                }
                else
                {
                    spatial = CreateNode(assimpNode);
                }
                if (parent != null)
                {
                    parent.AddChild(spatial);
                }
                return(spatial);
            }

            Node node = CreateNode(assimpNode);

            foreach (Assimp.Node child in assimpNode.Children)
            {
                ParseNodes(child, node);
            }

            if (parent != null)
            {
                parent.AddChild(node);
            }

            return(node);
        }
Example #32
0
    public void benchmark_icall_with_loop()
    {
        var node = new Node();

        for (var i = 0; i < 100; i++)
        {
            var child = new Node();
            node.AddChild(child);
            node.RemoveChild(child);
            child.Free();
        }
        node.Free();
    }
Example #33
0
        public void Node_SearchFindValue(int rootValue, int newNodeValue)
        {
            Node root = new Node(rootValue);

            Node newNode = new Node(newNodeValue);

            root.AddChild(newNode);

            var node = root.FindWithValue(newNodeValue);

            Assert.Equal(newNodeValue, node.Value);
            Assert.Equal(root.Right.Value, newNodeValue);
        }
Example #34
0
    public override void _Pressed()
    {
        Node oldLevel    = GetNode <Node>("/root/InGame/Level");
        Node levelParent = oldLevel.GetParent();

        levelParent.RemoveChild(oldLevel);
        oldLevel.QueueFree();

        var newLevel = Level.Instance();

        levelParent.AddChild(newLevel);
        GetNode <Sprite>("/root/InGame/LevelComplete").Visible = false;
    }
Example #35
0
    private void Shoot()
    {
        //if (!fireSfx.Playing)
        fireSfx.Play();

        var     obj     = bullet.Instance() as bullet;
        Vector3 normal  = -Transform.basis.z;
        Vector3 mnormal = normal * -100;

        obj.Init(this.Transform.origin + (normal * -6), mnormal, Rotation);
        effects.AddChild(obj);
        rateDelay -= 1.0f / fireRate;
    }
Example #36
0
        private void CreateRandomSphere(int id, Node parent)
        {
            Sphere sphere = new Sphere("Sphere " + id.ToString(), 18, 18, (float)random.NextDouble() * 1.75f + 1.25f);

            sphere.Translation = new Vector3((float)random.NextDouble() * 120 - 40,
                                             (float)random.NextDouble() * 120 - 40,
                                             (float)random.NextDouble() * 120 - 40);
            sphere.SetSolidColor(Color.DarkGray);
            sphere.Lights.MaxLights     = 4;
            sphere.Lights.GlobalAmbient = Color.Black;
            sphere.Material             = ContentManager.Load <Material>("LitBasicVertColor.tem").Clone();
            parent.AddChild(sphere);
        }
Example #37
0
    public Spatial ProduceVillager(Node unitlevel, Vector3 cellsize)
    {
        var unit_resource = (PackedScene)ResourceLoader.Load("res://Assets/Units/Unit.tscn");

        if (unit_resource != null)
        {
            var unit = (Spatial)unit_resource.Instance();
            unit.Translation = getBuildingLocation() * cellsize + Vector3.Up * 1;
            unitlevel.AddChild(unit);
            return(unit);
        }
        return(null);
    }
Example #38
0
    public static AudioStreamPlayer Create(string path, Node parent, int volume = 0)
    {
        var player = new AudioStreamPlayer
        {
            Bus      = "SoundEffects",
            Stream   = ResourceLoader.Load <AudioStream>($"res://Sound/{path}"),
            VolumeDb = volume
        };

        parent.AddChild(player);
        player.Play();
        return(player);
    }
Example #39
0
 public void AddConnection(Node node1, Node node2)
 {
     if (!nodes.Contains(node1))
     {
         nodes.Add(node1);
     }
     if (!nodes.Contains(node2))
     {
         nodes.Add(node2);
     }
     node1.AddChild(node2);
     node2.AddChild(node1);
 }
Example #40
0
        public AudioStreamPlayer PlaySfxLoop(AudioStreamOGGVorbis stream, Node owner,
                                             string bus = "SfxA")
        {
            AudioStreamPlayer player = new AudioStreamPlayer();

            player.SetStream(stream);
            player.SetBus(bus);
            owner.AddChild(player);

            player.Play();
            Logger.Debug("Play Sfx Loop: " + stream.ResourcePath);
            return(player);
        }
Example #41
0
        public void TestSelfRecursive()
        {
            Node orig = new Node();

            orig.AddChild(orig);
            Assert.Single(orig.Children);
            Assert.Same(orig, orig.Children[0]);

            var clone = Serializer.DeepClone(orig);

            Assert.Single(clone.Children);
            Assert.Same(clone, clone.Children[0]);
        }
        public void ShouldNotTransferAttributesPastParagraph()
        {
            var attributeCopierAnalyzer = new AttributeCopierAnalyzer();

            var body = new Node(KeywordToken.Body);

            body.AddChild(_paragraph);
            attributeCopierAnalyzer.Analyze(body);

            Assert.Throws <KeyNotFoundException>(() => body.GetAttribute("testAttr"));
            Assert.AreEqual("testAttr2Value", body.Children[0].GetAttribute("testAttr2"));
            Assert.AreEqual("testAttrValue", body.Children[0].GetAttribute("testAttr"));
        }
Example #43
0
    public void SpawnCoins()
    {
        AudioStreamPlayer a = (AudioStreamPlayer)GetNode("LevelSound");

        for (int i = 0; i < Level + 4; i++)
        {
            var c = (Coin)CoinScene.Instance();
            Coins.AddChild(c);
            a.Play();
            c.GlobalPosition = new Vector2(Rand.Next(0, Convert.ToInt32(Screensize.x)),
                                           Rand.Next(0, Convert.ToInt32(Screensize.y)));
        }
    }
Example #44
0
    private void SpawnReef(int spawnStartIndex)
    {
        Vector2 tempStartPosition = ((Position2D)GetNode("PlayerShipPoints/" + spawnStartIndex.ToString())).GetPosition();

        tempStartPosition.y = tempStartPosition.y + distanceFromPlayerShipPoint;

        ReefObject obj = (ReefObject)reefs.Instance();

        reefPool.AddChild(obj);
        obj.Position = tempStartPosition;
        obj.Rotation = 0;
        obj.SetLinearVelocity(new Vector2(70, 0).Rotated((float)aimToPosition));
    }
Example #45
0
    public Node SwitchToScene(Node newSceneRoot, bool keepOldRoot = false)
    {
        var oldRoot = GetTree().CurrentScene;

        GetTree().CurrentScene = null;

        if (oldRoot != null)
        {
            internalRootNode.RemoveChild(oldRoot);
        }

        internalRootNode.AddChild(newSceneRoot);
        GetTree().CurrentScene = newSceneRoot;

        if (!keepOldRoot)
        {
            oldRoot?.QueueFree();
            return(null);
        }

        return(oldRoot);
    }
Example #46
0
        public void TestSelfRecursive()
        {
            Node orig = new Node();

            orig.AddChild(orig);
            Assert.AreEqual(1, orig.Children.Count);
            Assert.AreSame(orig, orig.Children[0]);

            var clone = Serializer.DeepClone(orig);

            Assert.AreEqual(1, clone.Children.Count);
            Assert.AreSame(clone, clone.Children[0]);
        }
Example #47
0
        public static Node Create(Vector3 pos)
        {
            var cmp = new MyDisplayPanel ();

            var spr = new Sprite (800, 220);
            spr.AddTexture (new Texture ("media/雪の舞う花の夢.png"));

            var node = new Node ("DisplayPanel");
            node.Attach (cmp);
            node.Attach (spr);

            node.AddChild(MyTextBox.Create(new Vector3(250, 70, 0)));
            node.AddChild(MyFaceWindow.Create(new Vector3(50,65,0)));
            node.AddChild (MyNamePlate.Create (new Vector3 (70, 20, 0)));

            node.DrawPriority = -10;
            foreach (var n in node.Downwards) {
                n.DrawPriority = -10;
            }

            node.Translation = pos;

            return node;
        }
Example #48
0
 /// <summary>
 /// PSVX精灵类
 /// </summary>
 /// <param name='scene'>
 /// 精灵所在场景
 /// </param>
 /// <param name='path'>
 /// 精灵纹理
 /// </param>
 /// <param name='vector'>
 /// 精灵坐标
 /// </param>
 /// <param name='cutImage'>
 /// 切分的块数
 /// </param>
 /// <param name='showPiece'>
 /// 显示的图片部分坐标
 /// </param>
 public SpriteX(Node node, string path, Vector2 vector, Vector2i cutImage, Vector2i showPiece)
 {
     this.fatherNode = node;
     node.AddChild (this);
     Scheduler.Instance.Schedule (this, UpdateFrame, 0.0f, false);
     if(System.IO.File.Exists(@"/Application/Content/Pic/" + path))
         texture = new Texture2D (@"/Application/Content/Pic/" + path, false);
     else
         DebugScene.Instance.WriteLine("未找到文件:Pic/" + path);
     this.TextureInfo = new TextureInfo (texture, new Vector2i (cutImage.Y, cutImage.X), TRS.Quad0_1);
     this.TileIndex2D = new Vector2i (showPiece.Y - 1, cutImage.X - showPiece.X);
     this.Quad.S = new Vector2 (texture.Width / cutImage.Y, texture.Height / cutImage.X);
     this.CenterSprite (TRS.Local.TopLeft);
     this.Position = new Vector2 (vector.X, 544.0f - vector.Y);
 }
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            Dictionary<int, Node> nodes = new Dictionary<int, Node>();

            for (int i = 0; i < N - 1; i++)
            {
                string connection = Console.ReadLine();
                string[] separatedConection = connection.Split(new char[] {'(',')','<','-',' '},StringSplitOptions.RemoveEmptyEntries);
                int parent = int.Parse(separatedConection[0]);
                int child = int.Parse(separatedConection[1]);

                Node parentNode;
                Node childNode=new Node(0);

                if (nodes.ContainsKey(parent))
                {
                    parentNode = nodes[parent];
                }
                else
                {
                    parentNode = new Node(parent);
                    nodes.Add(parent,parentNode);
                }

                if (nodes.ContainsKey(child))
                {
                    childNode = nodes[child];
                }
                else
                {
                    parentNode.AddChild(childNode);
                    childNode.AddChild(parentNode);
                }

                foreach (var node in nodes)
                {
                    if(node.Value.NumberOfChildren==1)
                    {
                        usedNodes.Clear();
                        DFS(node.Value,0);
                    }
                }

            }
            Console.WriteLine(maxSum);
        }
Example #50
0
 // Слить две кучи
 private static Node Merge(Node a, Node b)
 {
     if (a == null)
         return b;
     if (b == null)
         return a;
     if (a.key < b.key)
     {
         a.AddChild(b);
         return a;
     }
     else
     {
         b.AddChild(a);
         return b;
     }
 }
 private void CreateTree()
 {
     root = new Node("Root");
     for (int i = 0; i < 1000; i++)
     {
         var n = new Node("Node " + i);
         root.AddChild(n);
         for (int j = 0; j < 10; j++)
         {
             var subNode = new Node("SubNode " + i + "-" + j);
             n.AddChild(subNode);
             for (int k = 0; k < 10; k++)
             {
                 var subSubNode = new Node("SubNode " + i + "-" + j + "-" + k);
                 subNode.AddChild(subSubNode);
             }
         }
     }
 }
        /// <summary>
        /// Finds all paths between two Node values using recursively BFS algorithm.
        /// </summary>
        /// <param name="parentNode">The startup Node value.</param>
        /// <param name="leaf">The final (max) Node value.</param>
        private void FindAllPathsBFS(Node<int> parentNode, Node<int> leaf)
        {
            // Adds childs with calculated values to parentNode
            foreach (var operation in this.operations)
            {
                var newNodeValue = operation(parentNode.Value);

                // Adds childs only if its value <= m
                if (newNodeValue <= leaf.Value)
                {
                    parentNode.AddChild(new Node<int>(newNodeValue));
                }
            }

            // Repeats recursively steps above for each childs of parentNode
            foreach (var child in parentNode.Childs)
            {
                this.FindAllPathsBFS(child, leaf);
            }
        }
Example #53
0
        public static Node Create(Vector3 pos)
        {
            var cmp = new MyRader ();
            cmp.points = new Node ();
            cmp.points.DrawPriority = -2;

            // 背景
            var spr = new Sprite (120, 180);
            spr.Color = new Color (255, 255, 255, 128);

            var node = new Node ("Rader");
            node.AddChild (cmp.points);
            node.Attach (cmp);
            node.Attach (spr);
            node.DrawPriority = -2;

            node.Translation = pos;

            return node;
        }
Example #54
0
        public static Node Create()
        {
            var cmp = new MyCharacterHolder ();

               var node = new Node ("Characters");
               node.Attach (cmp);

               node.AddChild (MyCharacter.Create ("Mayuto", new Vector3 (0, 0, 0)));
               node.AddChild (MyCharacter.Create ("Nayu", new Vector3 (0, 0, 0)));
               node.AddChild (MyCharacter.Create ("Sayaka", new Vector3 (0, 0, 0)));
               node.AddChild (MyCharacter.Create ("Maki", new Vector3 (0, 0, 0)));
               node.AddChild (MyCharacter.Create ("Lily", new Vector3 (0, 0, 0)));
               node.AddChild (MyCharacter.Create ("Rinko", new Vector3 (0, 0, 0)));

               return node;
        }
Example #55
0
        public static Node Create(Vector3 pos)
        {
            var cmp = new MyPlatform ();

            var node = new Node ("Platform");
            node.AddChild (CreateFloor ("Ground", 0, 580, 800, 20, new Quaternion (0, 0, 0, 1)));
            node.AddChild (CreateFloor ("Floor1", 10, 450, 650, 20, new Quaternion (3, 0, 0, 1)));
            node.AddChild (CreateFloor ("Floor2", 100, 350, 690, 20, new Quaternion (-3, 0, 0, 1)));
            node.AddChild (CreateFloor ("Floor3", 10, 180, 650, 20, new Quaternion (3, 0, 0, 1)));
            node.AddChild (CreateFloor ("LeftWall", 0, 0, 600, 20, new Quaternion (90, 0, 0, 1)));
            node.AddChild (CreateFloor ("RightWall1", 820, 0, 600, 20, new Quaternion (90, 0, 0, 1)));
            node.Attach (cmp);

            node.Translation = pos;

            return node;
        }
Example #56
0
		public HttpDataQuery(HttpRequest request)
		{
			Cmd = request.Form["act"];
			Queries = new Node();
			Queries["cmd"] = new Node(Cmd, NodeType.String);
			Queries["curtstyle"] = new Node(NodeType.String);
			Queries["fields"] = new Node("name", NodeType.Object);
			//select [pagesize] [fields] from [tables] [wheres] [orders]
			//select [pagesize] [fields] from [tables] where [pk] not in select [excludes] from [tables] [wheres] [orders]
			Queries.AddChild("select", NodeType.Object);
			Queries["select"]["fields"] = new Node("#name", NodeType.Array);
			Queries["select"]["tables"] = new Node("#name", NodeType.Array);
			Queries["select"]["wheres"] = new Node("#list", NodeType.Object);
			Queries["select"]["orders"] = new Node("#list", NodeType.Object);
			Queries["select"]["pagesize"] = new Node("#num", NodeType.Empty);
			Queries["select"]["pageskip"] = new Node("#num", NodeType.Empty);
			Queries["select"]["curtpage"] = new Node("#num", NodeType.Empty);
			Queries["select"]["pk"] = new Node("#name", NodeType.Object);
			Form = request.Form;
			Qstyle = Form["qstyle"];
			Queries.SetValue(Qstyle, NodeType.String, "curtstyle");
			if (string.IsNullOrEmpty(Qstyle))
			{
				Qstyle = "select";
			}
			if (string.IsNullOrEmpty(Cmd))
			{
				Cmd = "normal";
			}
			Node Root = Queries["select"];
			OnParse = ParseTypes;
			EnumNames(null);
			OnParse = ParseNames;
			EnumNames(Root);
			Sql = MakeSql();
		}
Example #57
0
 /// <summary>
 /// Builds a Tree from the given start Cell (Cells points to other cells)
 /// Also calls CreateEnemyWaypoints with the last Node it visits to ensure the deepest path
 /// </summary>
 /// <param name="maze">The starting Cell</param>
 private void CreateTreeFromMaze(Cell start)
 {
     Queue<Node> fringe = new Queue<Node>();
     Node currentNode = new Node(null, start);
     fringe.Enqueue(currentNode);
     do
     {
         currentNode = fringe.Dequeue();
         CreateResourcesFromCell(currentNode.data);
         for (int i = 0; i < 4; i++) { if (currentNode.data.adjacentCells[i] != null && !currentNode.data.walls[i]) { currentNode.AddChild(currentNode.data.adjacentCells[i]); } }
         foreach (Node child in currentNode.children) { fringe.Enqueue(child); }
     } while (fringe.Count > 0);
     CreateEnemyWaypoints(currentNode);
 }
        private Node ParseSyntax()
        {
            var syntax = _tokens.Dequeue(); // Pop off syntax token.

            var assignment = _tokens.Dequeue();
            if (!_parser.IsAssignment(assignment.Lexeme))
            {
                _errors.Add(new ParseError("Expected an assignment after syntax token, found ", assignment));
                return null;
            }
            var proto3 = ParseStringLiteral();

            if (ReferenceEquals(proto3, null))
            {
                _errors.Add(new ParseError("Expected a string literal after syntax assignment, found token ", _tokens.Peek()));
                return null;
            }

            TerminateSingleLineStatement();

            var syntaxNode = new Node(NodeType.Syntax, syntax.Lexeme);
            syntaxNode.AddChild(proto3);

            ScoopComment(syntaxNode);
            DumpEndline();

            return syntaxNode;
        }
 private void ScoopComment(Node parent)
 {
     var trailing = _tokens.Peek();
     if (!_parser.IsInlineComment(trailing.Lexeme)) return;
     var commentNode = ParseInlineComment();
     parent.AddChild(commentNode);
 }
Example #60
0
 public GameObject(Node node)
 {
     fatherNode = node;
     node.AddChild(this);
     Sce.Pss.HighLevel.GameEngine2D.Scheduler.Instance.Schedule(this, UpdateFrame, 0.0f, false);
 }