示例#1
0
        private void writeButton_Click(object sender, EventArgs e)
        {
            int id = Province.ProvincesUnordered.Count;

            int[] colour = { (int)redInput.Value, (int)greenInput.Value, (int)blueInput.Value };
            if (!Province.Create(id, colour))
            {
                return;
            }
            Province p = Province.Get(id);

            p.Type      = (ProvinceType)provTypeInput.SelectedItem;
            p.Terrain   = (Terrain)terrainInput.SelectedItem;
            p.Continent = (Continent)continentInput.SelectedItem;
            p.Coastal   = (bool)coastalInput.SelectedItem;
            State s = (State)stateInput.SelectedItem;

            s.Provinces.Add(p);
            Province.Save();

            string regionFile = regionFiles.Find(x => x.Split(@"\").Last().StartsWith($"{regionInput.SelectedItem}-"));

            string[] regionFileContents = File.ReadAllLines(regionFile);
            regionFileContents[4] += $" {id}";
            File.WriteAllLines(regionFile, regionFileContents);

            statusLabel.Text = $"Province {id} successfully written";

            Reset();
        }
示例#2
0
文件: Parser.cs 项目: TFPAcer/HOI4MI
        public static bool ParseProvinceDef(string path)
        {
            string[] lines = File.ReadAllLines(path);
            string[] data;
            foreach (string l in lines)
            {
                data = l.Split(';');
                int   id  = -1;
                int[] rgb = new int[3];
                if (!int.TryParse(data[0], out id))
                {
                    Status = $"malformed province ID in line {l}";
                    return(false);
                }
                if (!int.TryParse(data[1], out rgb[0]))
                {
                    Status = $"malformed R for province {id}";
                    return(false);
                }
                if (!int.TryParse(data[2], out rgb[1]))
                {
                    Status = $"malformed G for province {id}";
                    return(false);
                }
                if (!int.TryParse(data[3], out rgb[2]))
                {
                    Status = $"malformed B for province {id}";
                    return(false);
                }

                if (Province.Create(id, rgb))
                {
                    Province p = Province.Get(id);
                    p.Type = data[4] switch {
                        "sea" => ProvinceType.Sea,
                        "lake" => ProvinceType.Lake,
                        _ => ProvinceType.Land,
                    };
                    p.Coastal = data[5] == "true";
                    p.Terrain = data[6] switch {
                        "ocean" => Terrain.Ocean,
                        "lake" => Terrain.Lake,
                        "forest" => Terrain.Forest,
                        "hills" => Terrain.Hills,
                        "mountain" => Terrain.Mountain,
                        "plains" => Terrain.Plains,
                        "urban" => Terrain.Urban,
                        "jungle" => Terrain.Jungle,
                        "marsh" => Terrain.Marsh,
                        "desert" => Terrain.Desert,
                        "water_fjords" => Terrain.Water_Fjords,
                        "water_shallow_sea" => Terrain.Water_Shallow_Sea,
                        "water_deep_ocean" => Terrain.Water_Deep_Ocean,
                        _ => Terrain.Unknown,
                    };
                    if (!int.TryParse(data[7], out int continent))
                    {
                        Status = $"malformed continent for province {id}";
                        return(false);
                    }
                    p.Continent = (Continent)continent;
                    p.SetUnmodified();
                }

                else
                {
                    Status = $"Error creating province {id}.\n{Province.Status}";
                    return(false);
                }
            }
            return(true);
        }