Exemple #1
0
        /// <summary>
        /// Load maps based on INI info as well as those in the custom maps directory.
        /// </summary>
        public void LoadMaps()
        {
            Logger.Log("Loading maps.");

            IniFile mpMapsIni = new IniFile(ProgramConstants.GamePath + ClientConfiguration.Instance.MPMapsIniPath);

            LoadGameModes(mpMapsIni);
            LoadGameModeAliases(mpMapsIni);
            LoadMultiMaps(mpMapsIni);
            LoadCustomMaps();

            GameModes.RemoveAll(g => g.Maps.Count < 1);

            MapLoadingComplete?.Invoke(this, EventArgs.Empty);
        }
        public void LoadMaps()
        {
            Logger.Log("Loading maps.");

            IniFile mpMapsIni = new IniFile(ProgramConstants.GamePath + ClientConfiguration.Instance.MPMapsIniPath);

            var gmAliases = mpMapsIni.GetSectionKeys("GameModeAliases");

            if (gmAliases != null)
            {
                foreach (string key in gmAliases)
                {
                    GameModeAliases.Add(key, mpMapsIni.GetStringValue("GameModeAliases", key, string.Empty).Split(
                                            new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                }
            }

            List <string> keys = mpMapsIni.GetSectionKeys("MultiMaps");

            if (keys == null)
            {
                Logger.Log("Loading multiplayer map list failed!!!");
                return;
            }

            List <Map> maps = new List <Map>();

            foreach (string key in keys)
            {
                string mapFilePath = mpMapsIni.GetStringValue("MultiMaps", key, string.Empty);

                if (!File.Exists(ProgramConstants.GamePath + mapFilePath + MAP_FILE_EXTENSION))
                {
                    Logger.Log("Map " + mapFilePath + " doesn't exist!");
                    continue;
                }

                Map map = new Map(mapFilePath, true);

                if (!map.SetInfoFromINI(mpMapsIni, GameModeAliases))
                {
                    continue;
                }

                maps.Add(map);
            }

            foreach (Map map in maps)
            {
                foreach (string gameMode in map.GameModes)
                {
                    GameMode gm = GameModes.Find(g => g.Name == gameMode);

                    if (gm == null)
                    {
                        gm = new GameMode(gameMode.Replace(";", string.Empty));
                        GameModes.Add(gm);
                    }

                    gm.Maps.Add(map);
                }
            }

            List <Map> customMaps = new List <Map>();

            if (!Directory.Exists(ProgramConstants.GamePath + CUSTOM_MAPS_DIRECTORY))
            {
                Logger.Log("Custom maps directory does not exist!");
            }
            else
            {
                string[] files = Directory.GetFiles(ProgramConstants.GamePath + CUSTOM_MAPS_DIRECTORY, "*.map");

                foreach (string file in files)
                {
                    string baseFilePath = file.Substring(ProgramConstants.GamePath.Length);
                    baseFilePath = baseFilePath.Substring(0, baseFilePath.Length - 4);

                    Map map = new Map(baseFilePath, false);
                    if (map.SetInfoFromMap(file, GameModeAliases))
                    {
                        customMaps.Add(map);
                    }
                }
            }

            string[] allowedGameModes = ClientConfiguration.Instance.GetAllowedGameModes.Split(',');

            foreach (Map map in customMaps)
            {
                foreach (string gameMode in map.GameModes)
                {
                    GameMode gm = GameModes.Find(g => g.Name == gameMode);

                    if (!allowedGameModes.Contains(gameMode))
                    {
                        continue;
                    }

                    if (gm == null)
                    {
                        gm = new GameMode(gameMode);
                        GameModes.Add(gm);
                    }

                    gm.Maps.Add(map);
                }
            }

            MapLoadingComplete?.Invoke(this, EventArgs.Empty);
        }