コード例 #1
0
ファイル: Arena.cs プロジェクト: windsurfer/FPS_Project
    public void InitSpawnPoints()
    {
        SceneTree st = GetTree();

        object[] actorSpawns = st.GetNodesInGroup("ActorSpawnPoint");
        this.actorSpawnPoints = new List <Vector3>();
        for (int i = 0; i < actorSpawns.Length; i++)
        {
            Spatial spawnPoint = actorSpawns[i] as Spatial;
            if (spawnPoint != null)
            {
                this.actorSpawnPoints.Add(spawnPoint.GetGlobalTransform().origin);
            }
        }

        object[] itemSpawns = st.GetNodesInGroup("ItemSpawnPoint");
        this.itemSpawnPoints = new List <Vector3>();
        for (int i = 0; i < itemSpawns.Length; i++)
        {
            Spatial spawnPoint = itemSpawns[i] as Spatial;
            if (spawnPoint != null)
            {
                this.itemSpawnPoints.Add(spawnPoint.GetGlobalTransform().origin);
            }
        }
    }
コード例 #2
0
        public static IEnumerable <T> GetNodesInGroup <T>([NotNull] this SceneTree sceneTree, [NotNull] string group)
        {
            Ensure.Any.IsNotNull(sceneTree, nameof(sceneTree));
            Ensure.Any.IsNotNull(group, nameof(group));

            return(sceneTree.GetNodesInGroup(group).OfType <T>());
        }
コード例 #3
0
ファイル: Util.cs プロジェクト: anguillifax/NovaLib_Utilities
 /// <summary>
 /// Searches the scene tree for a single node with the given group.
 /// </summary>
 public static Node GetNodeInGroup(this SceneTree tree, string name)
 {
     try {
         return((Node)tree.GetNodesInGroup(name)[0]);
     } catch (IndexOutOfRangeException) {
         GD.PrintErr($"Node '{name}' could not be found.");
         throw;
     }
 }
コード例 #4
0
ファイル: Util.cs プロジェクト: anguillifax/NovaLib_Utilities
 /// <summary>
 /// Search the scene tree for a single node with the given group. Function throws exception if node cannot be found / cast to given type.
 /// </summary>
 public static T GetNodeInGroup <T>(this SceneTree tree, string name)
 {
     try {
         return((T)tree.GetNodesInGroup(name)[0]);
     } catch (InvalidCastException) {
         GD.PrintErr($"Node '{name}' could not be cast to type {typeof(T).Name} found.");
         throw;
     } catch (IndexOutOfRangeException) {
         GD.PrintErr($"Node '{name}' could not be found.");
         throw;
     }
 }
コード例 #5
0
ファイル: Group.cs プロジェクト: Splagoon/ld44
        public void Call(SceneTree tree, Action <TGroupMember> action)
        {
            var nodes = tree.GetNodesInGroup(Name);

            foreach (var node in nodes)
            {
                if (node is TGroupMember)
                {
                    var castedNode = (TGroupMember)node;
                    action(castedNode);
                }
            }
        }
コード例 #6
0
 public static void ProcessNodesInGroup <T>(this SceneTree tree, string group, Action <T> action) where T : Node
 {
     foreach (var obj in tree.GetNodesInGroup(group))
     {
         try
         {
             var node = (T)obj;
             action.Invoke(node);
         }
         catch (System.InvalidCastException)
         {
             GD.PushWarning(obj.ToString() + " was found in group: " + group);
         }
     }
 }
コード例 #7
0
        public static T GetFirstNodeInGroup <T>(SceneTree tree, string nodeGroup, bool onlyOneCanExist = false) where T : Node
        {
            var nodes = tree.GetNodesInGroup(nodeGroup);

            if (onlyOneCanExist && nodes.Count != 1)
            {
                throw new Exception("There should be exactly one player in the sceneTree!");
            }

            if (nodes[0] is T)
            {
                return(nodes[0] as T);
            }

            throw new Exception("Node in group \"" + nodeGroup + "\" is not of expected Type!");
        }
コード例 #8
0
    List <Vector3> GetSpawnPoints(string name)
    {
        List <Vector3> ret = new List <Vector3>();

        SceneTree            st   = GetTree();
        List <System.Object> objs = Util.ArrayToList(st.GetNodesInGroup(name));

        foreach (System.Object obj in objs)
        {
            Spatial spat = obj as Spatial;
            if (spat != null)
            {
                ret.Add(spat.GetGlobalTransform().origin);
            }
        }

        return(ret);
    }
コード例 #9
0
ファイル: Catchup.cs プロジェクト: Radbuglet/Overlords
        public static InvalidCatchupException ApplyCatchupInfo(this SceneTree tree, Dictionary data)
        {
            const string errorPrefix = "Catchup info target entry is malformed and was ignored: ";

            Debug.Assert(_catchupPhase == CatchupApplicationPhase.NotCatchingUp);

            // Deliver catchup "RPCs"
            _catchupPhase = CatchupApplicationPhase.ApplyingInfo;
            foreach (var pathRaw in data.Keys)
            {
                // Parse path
                if (!(pathRaw is NodePath path))
                {
                    GD.PushWarning(errorPrefix + "key was not a node path.");
                    continue;
                }

                GD.Print($"Catching up node at \"{path}\"");

                var node = tree.Root.GetNodeOrNull <IRequiresCatchup>(path);
                if (node == null)
                {
                    GD.PushWarning(errorPrefix +
                                   $"specified node does not exist or does not implement {nameof(IRequiresCatchup)}.");
                    continue;
                }

                if (!((Node)node).IsInGroup(GroupRequiresCatchup))
                {
                    GD.PushWarning(errorPrefix + "specified node at is not flagged as currently requiring catchup.");
                    continue;
                }

                // Attempt to apply catchup
                try
                {
                    node.HandleCatchupState(data[pathRaw]);
                    ((Node)node).RemoveFromGroup(GroupRequiresCatchup);
                }
                catch (InvalidCatchupException e)
                {
                    e.Instigator  = (Node)node;
                    _catchupPhase = CatchupApplicationPhase.NotCatchingUp;
                    return(e);
                }
            }

            // Ensure that all nodes requiring catchup have been caught up
            if (tree.DoesAnythingRequireCatchup())
            {
                _catchupPhase = CatchupApplicationPhase.NotCatchingUp;
                var list  = new StringBuilder();
                var first = true;
                foreach (var node in tree.GetNodesInGroup(GroupRequiresCatchup).Cast <Node>())
                {
                    if (!first)
                    {
                        list.Append(",");
                    }
                    first = false;
                    list.Append(node.GetPath());
                }
                return(new InvalidCatchupException($"At least one node marked as currently requiring catchup has not been caught up.\nNodes: {list}"));
            }

            // Perform macro catchup validation
            _catchupPhase = CatchupApplicationPhase.SecondPass;
            foreach (var(node, validator) in tree.EnumerateGroupMembers <IMacroCatchupValidator>(GroupMacroCatchupValidator))
            {
                try
                {
                    validator.ValidateCatchupState();
                }
                catch (InvalidCatchupException e)
                {
                    e.Instigator  = node;
                    _catchupPhase = CatchupApplicationPhase.NotCatchingUp;
                    return(e);
                }

                node.RemoveFromGroup(GroupMacroCatchupValidator);
            }

            // Announce catchup finish
            foreach (var(node, awaiter) in tree.EnumerateGroupMembers <ICatchupAwaiter>(GroupCatchupAwaiter))
            {
                awaiter._CaughtUp();
                node.RemoveFromGroup(GroupCatchupAwaiter);
            }

            _catchupPhase = CatchupApplicationPhase.NotCatchingUp;
            return(null);
        }
コード例 #10
0
ファイル: Catchup.cs プロジェクト: Radbuglet/Overlords
 // Flagging methods
 public static bool DoesAnythingRequireCatchup(this SceneTree tree)
 {
     return(tree.GetNodesInGroup(GroupRequiresCatchup).Count != 0);
 }
コード例 #11
0
        public static IEnumerable <T> GetNodesInGroup <T>(this SceneTree tree, string group) where T : class
        {
            Ensure.That(tree, nameof(tree)).IsNotNull();

            return(tree.GetNodesInGroup(group).Cast <Node>().Bind(n => n.OfType <T>()));
        }