Author Topic: Question about Cities  (Read 3753 times)

manmap

  • Newbie
  • *
  • Posts: 2
    • View Profile
Question about Cities
« on: October 10, 2015, 10:53:01 AM »
Hello everyone,

I was just checking the World Political Map - 2D Edition and it looks very good.
Before buying it, I would like to know few things:
1. How easy is it to access city information from your own code?
2. Is it possible to modify the city information while the game is running and if it's so, how difficult the saving would be?


Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 8300
    • View Profile
    • Kronnect
Re: Question about Cities
« Reply #1 on: October 10, 2015, 11:26:07 AM »
Hello manmap,

Cities expose an API to access its information:

  • The most immediate access is directly through the "cities" list which provides you a complete list of City objects in the asset (+1200).
    Each City object has a name, country which belongs to, metro population (city + surroundings) and unity2DLocation which defines its location over the plane. EDIT: APIs are also included for lat/lon conversion.
  • In addition to this you have several APIs like GetCityIndex (name), GetCityNames (retrieves a complete list of names), FlyToCity (to navigate to that city location).

2D Edition includes an editor to modify the frontiers and cities. You can add new cities, rename, move or delete any of them. All editing occurs in editor time and affects the included catalog (backup functionality is included).

At runtime you can simply make any modifications to the Cities list, serialize the list or copy its fields to a comma separated string and save it into the resource you want (text file, database, ...), and later load it replacing the cities list and calling Redraw() method to update their representation on the globe. That's all. We don't provide loading/saving changes during runtime because each user has their own formats/requirements but it's quite straightforward.

For instance, to get a string with all cities info you could do:

Code: [Select]
/// <summary>
/// Exports the geographic data in packed string format.
/// </summary>
public string GetCityGeoData () {
StringBuilder sb = new StringBuilder ();
for (int k=0; k<map.cities.Count; k++) {
City city = map.cities[k];
if (k > 0)
sb.Append ("|");
sb.Append (city.name + "$");
sb.Append (city.country + "$");
sb.Append (city.population + "$");
sb.Append (city.unity2DLocation.x + "$");
sb.Append (city.unity2DLocation.y);
}
return sb.ToString ();
}

« Last Edit: October 10, 2015, 12:32:55 PM by Kronnect »

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 8300
    • View Profile
    • Kronnect
Re: Question about Cities
« Reply #2 on: October 10, 2015, 11:40:39 AM »
Indeed, above function is part of the Editor component. If you want to have that API as part of the asset and use it at runtime, let me know and I'll add two new methods: one to retrieve cities info in a string suitable for storing/retrieving and other to load it and refresh the internal structures and representation. That way you just will have to use two lines of code :)

manmap

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Question about Cities
« Reply #3 on: October 10, 2015, 01:25:02 PM »
Hello Kronnect and thanks for giving such informative answer  :).

About adding new methods: I think it would be very nice if you could do that.
Additionally it would be excellent if there was a method  such as "GetCitiesFromCountry", which would return all the cities belonging to given country.

Anyhow based on this info, this asset already seems to be suitable for this project's needs and I will most likely buy it, when the project starts.
Thank you again for giving such an excellent customer service!



Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 8300
    • View Profile
    • Kronnect
Re: Question about Cities
« Reply #4 on: October 10, 2015, 06:09:35 PM »
Count on that. Will be included in next beta.