コード例 #1
0
        /// <summary>
        /// Exports the geographic data in packed string format.
        /// </summary>
        public string GetMountPointsGeoData()
        {
            JSONObject json = new JSONObject();

            for (int k = 0; k < mountPoints.Count; k++)
            {
                MountPoint mp     = mountPoints[k];
                JSONObject mpJSON = new JSONObject();
                mpJSON.AddField("Name", DataEscape(mp.name));
                int provinceUniqueID = -1;
                if (mp.provinceIndex >= 0 && mp.provinceIndex < provinces.Length)
                {
                    provinceUniqueID = provinces[mp.provinceIndex].uniqueId;
                }
                mpJSON.AddField("Province", provinceUniqueID);
                int countryUniqueID = -1;
                if (mp.countryIndex >= 0 && mp.countryIndex < countries.Length)
                {
                    countryUniqueID = countries[mp.countryIndex].uniqueId;
                }
                mpJSON.AddField("Country", countryUniqueID);
                mpJSON.AddField("Type", mp.type);
                mpJSON.AddField("X", mp.unity2DLocation.x);
                mpJSON.AddField("Y", mp.unity2DLocation.y);
                mpJSON.AddField("Id", mp.uniqueId);
                mpJSON.AddField("Attrib", mp.attrib);
                json.Add(mpJSON);
            }
            return(json.Print(true));
        }
コード例 #2
0
        public void MountPointSelect()
        {
            if (mountPointIndex < 0 || mountPointIndex > map.mountPoints.Count)
            {
                return;
            }

            // If no country is selected (the mount point could be at sea) select it
            MountPoint mp             = map.mountPoints[mountPointIndex];
            int        mpCountryIndex = mp.countryIndex;

            if (mpCountryIndex < 0)
            {
                SetInfoMsg("Country not found in this country file.");
            }

            if (countryIndex != mpCountryIndex && mpCountryIndex >= 0)
            {
                ClearSelection();
                countryIndex       = mpCountryIndex;
                countryRegionIndex = map.countries[countryIndex].mainRegionIndex;
                CountryRegionSelect();
            }

            // Just in case makes GUICountryIndex selects appropiate value in the combobox
            GUIMountPointName = mp.name;
            SyncGUIMountPointSelection();
            if (mountPointIndex >= 0)
            {
                GUIMountPointNewName = mp.name;
                GUIMountPointNewType = mp.type.ToString();
                MountPointHighlightSelection();
            }
        }
コード例 #3
0
        public MountPoint Clone()
        {
            MountPoint c = new MountPoint(name, countryIndex, provinceIndex, unity2DLocation, uniqueId, type);

            c.attrib = new JSONObject();
            c.attrib.Add(attrib);
            return(c);
        }
コード例 #4
0
        /// <summary>
        /// Reads the mount points data from a packed string.
        /// </summary>
        public void SetMountPointsGeoData(string s)
        {
            if (s.IndexOf('{') >= 0)
            {
                ReadMountPointsXML(s);
                return;
            }
            string[] mountPointsList  = s.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            int      mountPointsCount = mountPointsList.Length;

            mountPoints = new List <MountPoint>(mountPointsCount);

            for (int k = 0; k < mountPointsCount; k++)
            {
                string[] mountPointInfo = mountPointsList[k].Split(new char[] { '$' });
                if (mountPointInfo.Length < 6)
                {
                    continue;
                }
                string name         = mountPointInfo[0];
                string country      = mountPointInfo[2];
                int    countryIndex = GetCountryIndex(country);
                if (countryIndex >= 0)
                {
                    string province                  = mountPointInfo[1];
                    int    provinceIndex             = GetProvinceIndex(countryIndex, province);
                    int    type                      = int.Parse(mountPointInfo[3], Misc.InvariantCulture);
                    float  x                         = float.Parse(mountPointInfo[4], Misc.InvariantCulture);
                    float  y                         = float.Parse(mountPointInfo[5], Misc.InvariantCulture);
                    Dictionary <string, string> tags = new Dictionary <string, string>();
                    for (int t = 6; t < mountPointInfo.Length; t++)
                    {
                        string   tag     = mountPointInfo[t];
                        string[] tagInfo = tag.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
                        if (tagInfo != null && tagInfo.Length > 1)
                        {
                            string key   = tagInfo[0];
                            string value = tagInfo[1];
                            if (!tags.ContainsKey(key))
                            {
                                tags.Add(key, value);
                            }
                        }
                    }
                    int uniqueId;
                    if (mountPointInfo.Length >= 7)
                    {
                        uniqueId = int.Parse(mountPointInfo[6], Misc.InvariantCulture);
                    }
                    else
                    {
                        uniqueId = GetUniqueId(new List <IExtendableAttribute>(_countries));
                    }
                    MountPoint mountPoint = new MountPoint(name, countryIndex, provinceIndex, new Vector2(x, y), type, uniqueId);
                    mountPoints.Add(mountPoint);
                }
            }
        }
コード例 #5
0
        public void MountPointAdd(Vector2 location, string name, int countryIndex, int provinceIndex, int type)
        {
            if (mountPoints == null)
            {
                mountPoints = new List <MountPoint>();
            }
            int        uniqueId      = GetUniqueId(new List <IExtendableAttribute>(mountPoints.ToArray()));
            MountPoint newMountPoint = new MountPoint(name, countryIndex, provinceIndex, location, uniqueId, type);

            mountPoints.Add(newMountPoint);
        }
コード例 #6
0
        /// <summary>
        /// Gets XML attributes of provided mount points in jSON format.
        /// </summary>
        public string GetMountPointsAttributes(List <MountPoint> mountPoints, bool prettyPrint = true)
        {
            JSONObject composed        = new JSONObject();
            int        mountPointCount = mountPoints.Count;

            for (int k = 0; k < mountPointCount; k++)
            {
                MountPoint mountPoint = mountPoints[k];
                composed.AddField(mountPoint.uniqueId.ToString(), mountPoint.attrib);
            }
            return(composed.Print(prettyPrint));
        }
コード例 #7
0
        /// <summary>
        /// Returns a list of mount points whose attributes matches predicate
        /// </summary>
        public List <MountPoint> GetMountPoints(AttribPredicate predicate)
        {
            List <MountPoint> selectedMountPoints = new List <MountPoint>();
            int mountPointCount = mountPoints.Count;

            for (int k = 0; k < mountPointCount; k++)
            {
                MountPoint mountPoint = mountPoints[k];
                if (predicate(mountPoint.attrib))
                {
                    selectedMountPoints.Add(mountPoint);
                }
            }
            return(selectedMountPoints);
        }
コード例 #8
0
        bool GetMountPointUnderMouse(int countryIndex, Vector2 localPoint, out int mountPointIndex)
        {
            float hitPrecission = MOUNT_POINT_HIT_PRECISION * _cityIconSize * 5.0f;

            for (int c = 0; c < mountPoints.Count; c++)
            {
                MountPoint mp = mountPoints [c];
                if (mp.countryIndex == countryIndex)
                {
                    if ((mp.unity2DLocation - localPoint).magnitude < hitPrecission)
                    {
                        mountPointIndex = c;
                        return(true);
                    }
                }
            }
            mountPointIndex = -1;
            return(false);
        }
コード例 #9
0
        void ReadMountPointsXML(string s)
        {
            JSONObject json             = new JSONObject(s);
            int        mountPointsCount = json.list.Count;

            mountPoints = new List <MountPoint> (mountPointsCount);
            for (int k = 0; k < mountPointsCount; k++)
            {
                JSONObject mpJSON           = json [k];
                string     name             = mpJSON ["Name"];
                int        countryUniqueId  = mpJSON ["Country"];
                int        countryIndex     = GetCountryIndex(countryUniqueId);
                int        provinceUniqueId = mpJSON ["Province"];
                int        provinceIndex    = GetProvinceIndex(provinceUniqueId);
                float      x = mpJSON ["X"];
                float      y = mpJSON ["Y"];
                if (x == 0 && y == 0)
                {
                    // workaround for string data: fixes old issue, no longer needed but kept for compatibility
                    float.TryParse(mpJSON ["X"], System.Globalization.NumberStyles.Float, Misc.InvariantCulture, out x);
                    float.TryParse(mpJSON ["Y"], System.Globalization.NumberStyles.Float, Misc.InvariantCulture, out y);
                }
                // Try to locate country and provinces in case data does not match
                Vector2 location = new Vector2(x, y);
                if (countryIndex < 0 && countryUniqueId > 0)
                {
                    countryIndex = GetCountryIndex(location);
                }
                if (provinceIndex < 0 && provinceUniqueId > 0)
                {
                    provinceIndex = GetProvinceIndex(location);
                }
                int        uniqueId = mpJSON ["Id"];
                int        type     = mpJSON ["Type"];
                MountPoint mp       = new MountPoint(name, countryIndex, provinceIndex, location, uniqueId, type);
                mp.attrib = mpJSON ["Attrib"];
                mountPoints.Add(mp);
            }
        }
コード例 #10
0
        /// <summary>
        /// Redraws the mounts points but only in editor time. This is automatically called by Redraw(). Used internally by the Map Editor. You should not need to call this method directly.
        /// </summary>
        public void DrawMountPoints()
        {
            // Create mount points layer
            Transform t = transform.Find("Mount Points");

            if (t != null)
            {
                DestroyImmediate(t.gameObject);
            }
            if (Application.isPlaying || mountPoints == null)
            {
                return;
            }

            mountPointsLayer = new GameObject("Mount Points");
            mountPointsLayer.transform.SetParent(transform, false);

            // Draw mount points marks
            for (int k = 0; k < mountPoints.Count; k++)
            {
                MountPoint mp    = mountPoints [k];
                GameObject mpObj = Instantiate(mountPointSpot);
                mpObj.name = k.ToString();
                mpObj.transform.position = transform.TransformPoint(mp.unity2DLocation);
                if (disposalManager != null)
                {
                    disposalManager.MarkForDisposal(mpObj);
                }
                mpObj.hideFlags |= HideFlags.HideInHierarchy;
                mpObj.transform.SetParent(mountPointsLayer.transform, true);
            }

            MountPointScaler mpScaler = mountPointsLayer.GetComponent <MountPointScaler> () ?? mountPointsLayer.AddComponent <MountPointScaler> ();

            mpScaler.map = this;
            mpScaler.ScaleMountPoints();
        }
コード例 #11
0
        void UpdateProvinces()
        {
            WMSK map = WMSK.instance;

            if (committingProgress < 0.1f)
            {
                committingStatus   = "Refreshing province borders...";
                committingProgress = 0.25f;
            }
            else if (committingProgress < 0.3f)
            {
                newProvinces = ti.GetProvinces();
                if (additive)
                {
                    for (int k = 0; k < newProvinces.Length; k++)
                    {
                        map.ProvinceAdd(newProvinces [k]);
                    }
                }
                else
                {
                    map.provinces = newProvinces;
                }
                map.editor.provinceChanges = true;
                for (int k = 0; k < map.provinces.Length; k++)
                {
                    map.ProvinceSanitize(k, 5);
                }
                committingProgress = 0.4f;
            }
            else if (committingProgress < 0.5f)
            {
                committingStatus   = "Linking provinces to existing countries...";
                committingProgress = 0.6f;
            }
            else if (committingProgress < 0.7f)
            {
                // Update provinces references
                List <Province> newProvinces = new List <Province> (map.provinces.Length);
                for (int k = 0; k < map.provinces.Length; k++)
                {
                    Province prov = map.provinces [k];
                    if (prov.regions == null || prov.regions.Count == 0)
                    {
                        continue;
                    }
                    prov.regions [0].UpdatePointsAndRect(prov.regions [0].points);                      // compute rect2D and center
                    int countryIndex = map.GetCountryIndex(prov.regions [0].center);
                    if (countryIndex < 0)
                    {
                        // Check first point
                        countryIndex = map.GetCountryIndex(prov.regions [0].points [0]);
                        if (countryIndex < 0)
                        {
                            Debug.Log("Province #" + k + " has no enclosing country. Skipping.");
                            continue;
                        }
                    }
                    prov.countryIndex = countryIndex;
                    newProvinces.Add(prov);
                }
                map.provinces = newProvinces.ToArray();
                // Update country provinces
                newProvinces.Clear();
                for (int k = 0; k < map.countries.Length; k++)
                {
                    newProvinces.Clear();
                    for (int p = 0; p < map.provinces.Length; p++)
                    {
                        if (map.provinces [p].countryIndex == k)
                        {
                            newProvinces.Add(map.provinces [p]);
                        }
                    }
                    map.countries [k].provinces = newProvinces.ToArray();
                }
                committingProgress = 0.8f;
            }
            else if (committingProgress < 0.9f)
            {
                committingStatus   = "Refreshing other dependencies...";
                committingProgress = 0.95f;
            }
            else
            {
                // Update city references
                int citiesCount = map.cities.Length;
                for (int k = 0; k < citiesCount; k++)
                {
                    City city          = map.cities [k];
                    int  provinceIndex = map.GetProvinceIndex(city.unity2DLocation);
                    if (provinceIndex >= 0)
                    {
                        Province prov = map.provinces [provinceIndex];
                        if (!city.province.Equals(prov.name))
                        {
                            city.province          = prov.name;
                            city.countryIndex      = prov.countryIndex;
                            map.editor.cityChanges = true;
                        }
                    }
                    else if (city.province.Length > 0)
                    {
                        city.province          = "";
                        map.editor.cityChanges = true;
                    }
                }

                // Update mount points references
                int mpCount = map.mountPoints.Count;
                for (int k = 0; k < mpCount; k++)
                {
                    MountPoint mp            = map.mountPoints [k];
                    int        provinceIndex = map.GetProvinceIndex(mp.unity2DLocation);
                    if (provinceIndex >= 0)
                    {
                        if (mp.provinceIndex != provinceIndex)
                        {
                            mp.provinceIndex             = provinceIndex;
                            map.editor.mountPointChanges = true;
                        }
                    }
                    else
                    {
                        map.mountPoints.RemoveAt(k);
                        map.editor.mountPointChanges = true;
                        k--;
                        mpCount--;
                    }
                }
                committingProgress = 1f;
            }
        }
コード例 #12
0
        void UpdateCountries()
        {
            WMSK map = WMSK.instance;

            if (committingProgress < 0.1f)
            {
                committingStatus   = "Refreshing country frontiers...";
                committingProgress = 0.25f;
            }
            else if (committingProgress < 0.3f)
            {
                newCountries = ti.GetCountries();
                if (additive)
                {
                    for (int k = 0; k < newCountries.Length; k++)
                    {
                        map.CountryAdd(newCountries [k]);
                    }
                }
                else
                {
                    map.countries = newCountries;
                }
                map.editor.countryChanges = true;
                for (int k = 0; k < map.countries.Length; k++)
                {
                    map.CountrySanitize(k, 5);
                }
                committingProgress = 0.4f;
            }
            else if (committingProgress < 0.5f)
            {
                committingStatus   = "Refreshing provinces...";
                committingProgress = 0.6f;
            }
            else if (committingProgress < 0.7f)
            {
                // Update provinces references
                List <Province> newProvinces = new List <Province> (map.provinces.Length);
                for (int k = 0; k < map.provinces.Length; k++)
                {
                    Province prov = map.provinces [k];
                    if (prov.regions == null)
                    {
                        map.ReadProvincePackedString(prov);
                        if (prov.regions == null)
                        {
                            prov.center = new Vector2(-1000, -1000);
                        }
                    }
                    int countryIndex = map.GetCountryIndex(prov.center);
                    if (countryIndex < 0)
                    {
                        // Province deleted/ignored
                        map.editor.provinceChanges = true;
                    }
                    else if (prov.countryIndex != countryIndex)
                    {
                        prov.countryIndex          = countryIndex;
                        map.editor.provinceChanges = true;
                        newProvinces.Add(prov);
                    }
                }
                map.provinces = newProvinces.ToArray();
                // Update country provinces
                newProvinces.Clear();
                for (int k = 0; k < map.countries.Length; k++)
                {
                    newProvinces.Clear();
                    for (int p = 0; p < map.provinces.Length; p++)
                    {
                        if (map.provinces [p].countryIndex == k)
                        {
                            newProvinces.Add(map.provinces [p]);
                        }
                    }
                    map.countries [k].provinces = newProvinces.ToArray();
                }
                committingProgress = 0.8f;
            }
            else if (committingProgress < 0.9f)
            {
                committingStatus   = "Refreshing other dependencies...";
                committingProgress = 0.95f;
            }
            else
            {
                // Update city references
                int         citiesCount = map.cities.Length;
                List <City> cities      = new List <City>(map.cities);
                for (int k = 0; k < citiesCount; k++)
                {
                    City city         = cities [k];
                    int  countryIndex = map.GetCountryIndex(city.unity2DLocation);
                    if (countryIndex >= 0)
                    {
                        if (city.countryIndex != countryIndex)
                        {
                            city.countryIndex      = countryIndex;
                            map.editor.cityChanges = true;
                        }
                    }
                    else
                    {
                        cities.RemoveAt(k);
                        map.editor.cityChanges = true;
                        k--;
                        citiesCount--;
                    }
                }
                map.cities = cities.ToArray();

                // Update mount points references
                if (map.mountPoints != null)
                {
                    int mpCount = map.mountPoints.Count;
                    for (int k = 0; k < mpCount; k++)
                    {
                        MountPoint mp           = map.mountPoints [k];
                        int        countryIndex = map.GetCountryIndex(mp.unity2DLocation);
                        if (countryIndex >= 0)
                        {
                            if (mp.countryIndex != countryIndex)
                            {
                                mp.countryIndex = countryIndex;
                                map.editor.mountPointChanges = true;
                            }
                        }
                        else
                        {
                            map.mountPoints.RemoveAt(k);
                            map.editor.mountPointChanges = true;
                            k--;
                            mpCount--;
                        }
                    }
                }
                committingProgress = 1f;
            }
        }
コード例 #13
0
        IEnumerator  UpdateCountries()
        {
            Country[] _countries = _map.countries;
            for (int k = 0; k < _countries.Length; k++)
            {
                if (k % 10 == 0)
                {
                    if (hexifyContext.progress != null)
                    {
                        if (hexifyContext.progress((float)k / _countries.Length, hexifyContext.title, "Pass 6/6: updating countries..."))
                        {
                            cancelled = true;
                            hexifyContext.finish(true);
                            yield break;
                        }
                    }
                    yield return(null);
                }

                Country country = _countries [k];
                _map.CountrySanitize(k, 3, false);
                if (country.regions.Count == 0)
                {
                    if (_map.CountryDelete(k, true, false))
                    {
                        _countries = _map.countries;
                        k--;
                    }
                }
                else
                {
                    _map.RefreshCountryGeometry(country);
                }
            }

            // Update cities and mount points
            City[] cities    = _map.cities;
            int    cityCount = cities.Length;

            for (int k = 0; k < cityCount; k++)
            {
                City city         = cities [k];
                int  countryIndex = _map.GetCountryIndex(city.unity2DLocation);
                if (city.countryIndex != countryIndex)
                {
                    city.countryIndex = countryIndex;
                    city.province     = "";                 // clear province since it does not apply anymore
                }
            }
            int mountPointCount = _map.mountPoints.Count;

            for (int k = 0; k < mountPointCount; k++)
            {
                MountPoint mp           = _map.mountPoints [k];
                int        countryIndex = _map.GetCountryIndex(mp.unity2DLocation);
                if (mp.countryIndex != countryIndex)
                {
                    mp.countryIndex  = countryIndex;
                    mp.provinceIndex = -1;                      // same as cities - province cleared in case it's informed since it does not apply anymore
                }
            }
        }
コード例 #14
0
        IEnumerator UpdateProvinces()
        {
            Province[] _provinces = _map.provinces;

            for (int k = 0; k < _provinces.Length; k++)
            {
                if (k % 10 == 0)
                {
                    if (hexifyContext.progress != null)
                    {
                        if (hexifyContext.progress((float)k / _provinces.Length, hexifyContext.title, "Pass 6/6: updating provinces..."))
                        {
                            cancelled = true;
                            hexifyContext.finish(true);
                            yield break;
                        }
                    }
                    yield return(null);
                }

                _map.ProvinceSanitize(k, 3, true);
                if (_provinces[k].regions.Count == 0)
                {
                    if (_map.ProvinceDelete(k))
                    {
                        _provinces = _map.provinces;
                        k--;
                    }
                }
            }

            // Update cities and mount points
            Province province;

            City[] cities    = _map.cities;
            int    cityCount = cities.Length;

            for (int k = 0; k < cityCount; k++)
            {
                City city          = cities [k];
                int  provinceIndex = _map.GetProvinceIndex(city.unity2DLocation);
                if (provinceIndex >= 0)
                {
                    province = _map.provinces [provinceIndex];
                    if (city.province != province.name)
                    {
                        city.province     = province.name;
                        city.countryIndex = province.countryIndex;
                    }
                }
            }
            int mountPointCount = _map.mountPoints.Count;

            for (int k = 0; k < mountPointCount; k++)
            {
                MountPoint mp            = _map.mountPoints [k];
                int        provinceIndex = _map.GetProvinceIndex(mp.unity2DLocation);
                if (provinceIndex >= 0)
                {
                    if (mp.provinceIndex != provinceIndex)
                    {
                        province         = _map.provinces [provinceIndex];
                        mp.countryIndex  = province.countryIndex;
                        mp.provinceIndex = provinceIndex;
                    }
                }
            }
        }