Example #1
0
        private void ReadProvinceDefinition()
        {
            Provinces.Clear();

            string pathOfProvinceDefinition = $@"{Application.StartupPath}\{"definition.csv"}";

            if (!File.Exists(pathOfProvinceDefinition))
            {
                return;
            }
            string[] definitions = File.ReadAllLines(pathOfProvinceDefinition, m_encoding1252);

            foreach (string definition in definitions)
            {
                string[] listSplittedDefinition = definition.Split(';');

                if (listSplittedDefinition.Length < 5)
                {
                    continue;
                }

                int.TryParse(listSplittedDefinition[0], out int idProvince);
                int.TryParse(listSplittedDefinition[1], out int r);
                int.TryParse(listSplittedDefinition[2], out int g);
                int.TryParse(listSplittedDefinition[3], out int b);

                string nameOf = listSplittedDefinition[4];

                var provinceDefinitionItem = Provinces.Find(searchItem => ((searchItem.R == r) && (searchItem.G == g) && (searchItem.B == b)));

                if (provinceDefinitionItem == null)
                {
                    Provinces.Add(new ProvinceDefinitionItem(idProvince, r, g, b, nameOf, string.Empty));
                }
            }
        }
Example #2
0
        public void ReadMarker(string pathOfMarkerFile)
        {
            MarkerItems.Clear();

            if (!File.Exists(pathOfMarkerFile))
            {
                return;
            }
            var dictDuplicateIdProvince = new Dictionary <int, int>();

            string[] markers = File.ReadAllLines(pathOfMarkerFile, m_encoding1252);

            foreach (string marker in markers)
            {
                if (marker.Contains('#'))
                {
                    continue;
                }

                string[] listSplittedMarker = marker.Split('|');

                switch (listSplittedMarker.Length)
                {
                case 5:
                {
                    var name = listSplittedMarker[0];

                    int.TryParse(listSplittedMarker[1], out var r);
                    int.TryParse(listSplittedMarker[2], out var g);
                    int.TryParse(listSplittedMarker[3], out var b);

                    string[] listIdProvince = listSplittedMarker[4].Split(',');

                    var markerItem = MarkerItems.Find(searchItem => searchItem.R == r && searchItem.G == g && searchItem.B == b);

                    if (markerItem == null)
                    {
                        markerItem = new MarkerItem(name, r, g, b, 255, 0, "");

                        foreach (string stringIdProvince in listIdProvince)
                        {
                            int.TryParse(stringIdProvince.Trim(), out var idProvince);

                            if (idProvince <= 0 || dictDuplicateIdProvince.ContainsKey(idProvince))
                            {
                                continue;
                            }

                            var provinceDefinitionItem = Provinces.Find(findItem => findItem.Id == idProvince);

                            if (provinceDefinitionItem == null)
                            {
                                continue;
                            }
                            dictDuplicateIdProvince.Add(idProvince, idProvince);

                            markerItem.Provinces.Add(provinceDefinitionItem);
                        }

                        MarkerItems.Add(markerItem);
                    }

                    break;
                }

                case 7:
                {
                    var name = listSplittedMarker[0];

                    int.TryParse(listSplittedMarker[1], out int r);
                    int.TryParse(listSplittedMarker[2], out int g);
                    int.TryParse(listSplittedMarker[3], out int b);

                    int.TryParse(listSplittedMarker[4], out int location);

                    string[] listIdProvince = listSplittedMarker[6].Split(',');

                    var markerItem = MarkerItems.Find(searchItem => searchItem.R == r && searchItem.G == g && searchItem.B == b);

                    if (markerItem != null)
                    {
                        continue;
                    }

                    markerItem = new MarkerItem(name, r, g, b, 255, location, listSplittedMarker[5]);

                    var provinceIds = listIdProvince.Select(strId =>
                        {
                            int.TryParse(strId.Trim(), out var id);
                            return(id);
                        }).Where(id => (id <= 0 || dictDuplicateIdProvince.ContainsKey(id)) == false).ToList();

                    var provinces = provinceIds.Select(id =>
                                                       Provinces.Find(province => province.Id == id));

                    foreach (var province in provinces)
                    {
                        dictDuplicateIdProvince.Add(province.Id, province.Id);
                        markerItem.Provinces.Add(province);
                    }

                    MarkerItems.Add(markerItem);
                    break;
                }
                }
            }

            foreach (var markerItem in MarkerItems)
            {
                string[] listOutgoing = markerItem.Outgoing.Split(',');

                foreach (string outgoing in listOutgoing.Where(outgoing => outgoing.Length > 0))
                {
                    markerItem.OutgoingItems.AddRange(MarkerItems.FindAll(findItem => findItem.Name.Equals(outgoing)));
                }
            }
        }