X Tutup

Loading & Saving Data

intermediate tasks

World Map Strategy Kit · Common Tasks

Class: All members on this page belong to the WMSK component (namespace WorldMapStrategyKit). Access via WMSK.instance.

Loading and Saving Data

WMSK provides comprehensive methods to serialize and deserialize all map data at runtime, including countries, provinces, cities, mount points, and their attributes.

Countries Data

string GetCountriesDataJSON(bool prettyPrint = true)

Returns all country data as a JSON string.

void SetCountriesDataJSON(string json)

Loads country data from a JSON string.

string GetCountriesGeodata()

Returns countries geodata in the internal packed text format.

void SetCountriesGeodata(string s)

Loads countries geodata from packed text.

byte[] GetCountriesGeodataBinary()

Returns countries geodata as a binary byte array (compact format).

void SetCountriesGeodataBinary(byte[] data)

Loads countries geodata from a binary byte array.

Countries Attributes

string GetCountriesAttributes(bool prettyPrint = true)

Returns all country custom attributes as JSON.

string GetCountriesAttributes(List<Country> countries, bool prettyPrint = true)

Returns attributes only for the specified countries.

void SetCountriesAttributes(string jSON)

Applies custom attributes from a JSON string.

Provinces Data

string GetProvincesDataJSON(bool prettyPrint = true)

Returns all province data as JSON.

void SetProvincesDataJSON(string json)

Loads province data from JSON.

string GetProvincesGeodata() / void SetProvincesGeodata(string s)

Get/set province geodata in packed text format.

byte[] GetProvincesGeodataBinary() / void SetProvincesGeodataBinary(byte[] data)

Get/set province geodata in binary format.

string GetProvincesAttributes(bool prettyPrint = true)

Returns province custom attributes as JSON.

void SetProvincesAttributes(string jSON)

Applies province attributes from JSON.

Cities Data

string GetCitiesDataJSON(bool prettyPrint = true)

Returns all city data as JSON.

void SetCitiesDataJSON(string s)

Loads city data from JSON.

string GetCitiesGeodata() / void SetCitiesGeodata(string s)

Get/set city geodata in packed text format.

byte[] GetCitiesGeodataBinary() / void SetCitiesGeodataBinary(byte[] data)

Get/set city geodata in binary format.

string GetCitiesAttributes(bool prettyPrint = true)

Returns city custom attributes as JSON.

void SetCitiesAttributes(string jSON)

Applies city attributes from JSON.

Province Color Maps

int ImportProvincesColorMap(string filename)

Imports province definitions from a color-coded image map. Returns the number of provinces created.

Code Example

using UnityEngine;
using WorldMapStrategyKit;
using System.IO;

public class SaveLoadExample : MonoBehaviour {
    WMSK map;

    void Start() {
        map = WMSK.instance;
    }

    public void SaveGame() {
        // Save all map state to files
        File.WriteAllText("countries.json", map.GetCountriesDataJSON());
        File.WriteAllText("provinces.json", map.GetProvincesDataJSON());
        File.WriteAllText("cities.json", map.GetCitiesDataJSON());

        // Also save custom attributes
        File.WriteAllText("countryAttribs.json", map.GetCountriesAttributes());
    }

    public void LoadGame() {
        // Restore map state
        map.SetCountriesDataJSON(File.ReadAllText("countries.json"));
        map.SetProvincesDataJSON(File.ReadAllText("provinces.json"));
        map.SetCitiesDataJSON(File.ReadAllText("cities.json"));

        // Restore attributes
        map.SetCountriesAttributes(File.ReadAllText("countryAttribs.json"));

        // Refresh the map
        map.Redraw();
    }
}
Was this page helpful?
X Tutup