当前位置: 首页>>代码示例>>C#>>正文


C# Arguments.GetValue方法代码示例

本文整理汇总了C#中System.Arguments.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Arguments.GetValue方法的具体用法?C# Arguments.GetValue怎么用?C# Arguments.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Arguments的用法示例。


在下文中一共展示了Arguments.GetValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var arguments = new Arguments(args);
            Log.AddChannel("debug", "dedicated-debug.log");
            Log.AddChannel("perf", "dedicated-perf.log");
            Log.AddChannel("server", "dedicated-server.log");
            Log.AddChannel("nat", "dedicated-nat.log");

            // Special case handling of Game.Mod argument: if it matches a real filesystem path
            // then we use this to override the mod search path, and replace it with the mod id
            var modArgument = arguments.GetValue("Game.Mod", null);
            string customModPath = null;
            if (modArgument != null && (File.Exists(modArgument) || Directory.Exists(modArgument)))
            {
                customModPath = modArgument;
                arguments.ReplaceValue("Game.Mod", Path.GetFileNameWithoutExtension(modArgument));
            }

            // HACK: The engine code assumes that Game.Settings is set.
            // This isn't nearly as bad as ModData, but is still not very nice.
            Game.InitializeSettings(arguments);
            var settings = Game.Settings.Server;

            var mod = Game.Settings.Game.Mod;
            var mods = new InstalledMods(customModPath);

            // HACK: The engine code *still* assumes that Game.ModData is set
            var modData = Game.ModData = new ModData(mods[mod], mods);
            modData.MapCache.LoadMaps();

            settings.Map = modData.MapCache.ChooseInitialMap(settings.Map, new MersenneTwister());

            Console.WriteLine("[{0}] Starting dedicated server for mod: {1}", DateTime.Now.ToString(settings.TimestampFormat), mod);
            while (true)
            {
                var server = new Server(new IPEndPoint(IPAddress.Any, settings.ListenPort), settings, modData, true);

                while (true)
                {
                    Thread.Sleep(1000);
                    if (server.State == ServerState.GameStarted && server.Conns.Count < 1)
                    {
                        Console.WriteLine("[{0}] No one is playing, shutting down...", DateTime.Now.ToString(settings.TimestampFormat));
                        server.Shutdown();
                        break;
                    }
                }

                Console.WriteLine("[{0}] Starting a new server instance...", DateTime.Now.ToString(settings.TimestampFormat));
            }
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:51,代码来源:Program.cs

示例2: Settings

        public Settings(string file, Arguments args)
        {
            SettingsFile = file;
            Sections = new Dictionary<string, object>()
            {
                {"Player", Player},
                {"Game", Game},
                {"Sound", Sound},
                {"Graphics", Graphics},
                {"Server", Server},
                {"Debug", Debug},
            };

            // Override fieldloader to ignore invalid entries
            var err1 = FieldLoader.UnknownFieldAction;
            var err2 = FieldLoader.InvalidValueAction;

            FieldLoader.UnknownFieldAction = (s,f) =>
            {
                Console.WriteLine( "Ignoring unknown field `{0}` on `{1}`".F( s, f.Name ) );
            };

            if (File.Exists(SettingsFile))
            {
                var yaml = MiniYaml.DictFromFile(SettingsFile);

                foreach (var kv in Sections)
                    if (yaml.ContainsKey(kv.Key))
                        LoadSectionYaml(yaml[kv.Key], kv.Value);
            }

            // Override with commandline args
            foreach (var kv in Sections)
                foreach (var f in kv.Value.GetType().GetFields())
                    if (args.Contains(kv.Key+"."+f.Name))
                        FieldLoader.LoadField( kv.Value, f.Name, args.GetValue(kv.Key+"."+f.Name, "") );

            FieldLoader.UnknownFieldAction = err1;
            FieldLoader.InvalidValueAction = err2;
        }
开发者ID:Ray-B,项目名称:OpenRA,代码行数:40,代码来源:Settings.cs

示例3: StartGame

        public void StartGame(Arguments args)
        {
            Ui.ResetAll();
            Game.Settings.Save();

            // Check whether the mod content is installed
            // TODO: The installation code has finally been beaten into shape, so we can
            // finally move it all into the planned "Manage Content" panel in the modchooser mod.
            var installData = Game.ModData.Manifest.Get<ContentInstaller>();
            var installModContent = !installData.TestFiles.All(f => GlobalFileSystem.Exists(f));
            var installModMusic = args != null && args.Contains("Install.Music");

            if (installModContent || installModMusic)
            {
                var widgetArgs = new WidgetArgs()
                {
                    { "continueLoading", () => Game.InitializeMod(Game.Settings.Game.Mod, args) },
                };

                if (installData.BackgroundWidget != null)
                    Ui.LoadWidget(installData.BackgroundWidget, Ui.Root, widgetArgs);

                var menu = installModContent ? installData.MenuWidget : installData.MusicMenuWidget;
                Ui.OpenWindow(menu, widgetArgs);

                return;
            }

            // Join a server directly
            var connect = string.Empty;
            if (args != null)
            {
                if (args.Contains("Launch.Connect"))
                    connect = args.GetValue("Launch.Connect", null);

                if (args.Contains("Launch.URI"))
                {
                    connect = args.GetValue("Launch.URI", null);
                    if (connect != null)
                    {
                        connect = connect.Replace("openra://", "");
                        connect = connect.TrimEnd('/');
                    }
                }
            }

            if (!string.IsNullOrEmpty(connect))
            {
                var parts = connect.Split(':');

                if (parts.Length == 2)
                {
                    var host = parts[0];
                    var port = Exts.ParseIntegerInvariant(parts[1]);
                    Game.LoadShellMap();
                    Game.RemoteDirectConnect(host, port);
                    return;
                }
            }

            // Load a replay directly
            var replayFilename = args != null ? args.GetValue("Launch.Replay", null) : null;
            if (!string.IsNullOrEmpty(replayFilename))
            {
                var replayMeta = ReplayMetadata.Read(replayFilename);
                if (ReplayUtils.PromptConfirmReplayCompatibility(replayMeta, Game.LoadShellMap))
                    Game.JoinReplay(replayFilename);

                if (replayMeta != null)
                {
                    var mod = replayMeta.GameInfo.Mod;
                    if (mod != null && mod != Game.ModData.Manifest.Mod.Id && ModMetadata.AllMods.ContainsKey(mod))
                        Game.InitializeMod(mod, args);
                }

                return;
            }

            Game.LoadShellMap();
            Game.Settings.Save();
        }
开发者ID:ushardul,项目名称:OpenRA,代码行数:81,代码来源:BlankLoadScreen.cs


注:本文中的System.Arguments.GetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。