Exemplo n.º 1
0
        private Node SpawnNodeType(string NodeTypeString, string ParentPath, string NodeName, int NetworkMaster,
                                   Vector3 SpawnPos)
        {
            MDLog.Log(LOG_CAT, MDLogLevel.Debug,
                      $"Spawning Node. Type: {NodeTypeString} ParentPath: {ParentPath} Name: {NodeName} Master: {NetworkMaster}");
            Node Parent = GetNodeOrNull(ParentPath);

            if (Parent == null)
            {
                MDLog.Error(LOG_CAT, $"Could not find Parent with path {ParentPath}");
                return(null);
            }

            Type NodeType = Type.GetType(NodeTypeString);

            if (NodeType == null)
            {
                MDLog.Error(LOG_CAT, $"Could not find Type {NodeTypeString}");
                return(null);
            }

            Node NewNode = Activator.CreateInstance(NodeType) as Node;

            NewNode.Name = NodeName;
            NewNode.SetNetworkMaster(NetworkMaster);
            NetworkedTypes.Add(NewNode, NodeTypeString);
            OrderedNetworkedNodes.Add(NewNode);

            Node2D  NewNode2D      = NewNode as Node2D;
            Spatial NewNodeSpatial = NewNode as Spatial;

            if (NewNode2D != null)
            {
                NewNode2D.Position = SpawnPos.To2D();
            }
            else if (NewNodeSpatial != null)
            {
                NewNodeSpatial.Translation = SpawnPos;
            }

            Parent.AddChild(NewNode);
            OnNetworkNodeAdded(NewNode);
            return(NewNode);
        }
Exemplo n.º 2
0
        private Node SpawnNodeScene(string ScenePath, string ParentPath, string NodeName, int NetworkMaster,
                                    Vector3 SpawnPos)
        {
            MDLog.Log(LOG_CAT, MDLogLevel.Debug,
                      $"Spawning Node. Scene: {ScenePath} ParentPath: {ParentPath} Name: {NodeName} Master: {NetworkMaster}");
            Node Parent = GetNodeOrNull(ParentPath);

            if (Parent == null)
            {
                MDLog.Error(LOG_CAT, $"Could not find Parent with path: {ParentPath}");
                return(null);
            }

            PackedScene Scene = LoadScene(ScenePath);

            if (Scene == null)
            {
                return(null);
            }

            Node NewNode = Scene.Instance();

            NewNode.Name = NodeName;
            NewNode.SetNetworkMaster(NetworkMaster);
            NetworkedScenes.Add(NewNode, ScenePath);
            OrderedNetworkedNodes.Add(NewNode);

            Node2D  NewNode2D      = NewNode as Node2D;
            Spatial NewNodeSpatial = NewNode as Spatial;

            if (NewNode2D != null)
            {
                NewNode2D.Position = SpawnPos.To2D();
            }
            else if (NewNodeSpatial != null)
            {
                NewNodeSpatial.Translation = SpawnPos;
            }

            Parent.AddChild(NewNode);
            OnNetworkNodeAdded(NewNode);
            return(NewNode);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Simple argument parser that generates a dictionary of arguments passed to the game application to their values.
        /// Expects arguments to begin with ARG_PREFIX value.
        /// </summary>
        public static void PopulateArgs()
        {
            if (_args != null)
            {
                // We already parsed args
                return;
            }

            string[] ArgArray = Environment.GetCommandLineArgs();
            MDLog.Log(LOG_CAT, MDLogLevel.Info, "Populating Arguments: " + string.Join(" ", ArgArray));

            _args = new Dictionary <string, string>();
            foreach (string Arg in ArgArray)
            {
                string ThisArg = Arg.ToLower();
                if (!ThisArg.BeginsWith(ARG_PREFIX))
                {
                    // TODO - Log non prefix arg or change to support non-prefixed?
                    continue;
                }

                string NoPrefixArg = ThisArg.Substring(ARG_PREFIX.Length);

                // Does this arg have a value?
                int EqualIndex = NoPrefixArg.IndexOf('=');
                if (EqualIndex > 0)
                {
                    string ArgKey = NoPrefixArg.Substring(0, EqualIndex);
                    string ArgVal = NoPrefixArg.Substring(EqualIndex + 1);
                    _args.Add(ArgKey, ArgVal);
                }
                else
                {
                    _args.Add(NoPrefixArg, "");
                }
            }
        }