var qsize=mymap.get_quadrant_size()
will obtain the map's quadrant size in a script allowing it to be calculated which quadrant a particular cell position is within. When generating the cells in a quadrant not saved the quadrant's cells can be scanned in x and y for new cells on (qsize*xquad)+x,(qsize*yquad)+y
over x in range(256
), y in range(256)
where xquad
is the current x quadrant int(x_pos/qsize)
and yquad
is the current y quadrant int(y_pos/qsize)
. x_pos
and y_pos
is some cellwise location within the tilemap. The cells within the quadrant are stuck into a dictionary (to allow empty cells) and saved somewhere in user:// in json format using a File
(get_line
, store_line
) and the savegame json (to_json
to store_line
, parse_json
from get_line
).
for loading it comes down to checking if the visible portion of the map has quadrants not loaded from the saved map and loading the json files and iterating the loaded data to call set_cell as needed. one would then set some boolean mapping of map chunk x and y coordinates to indicate this chunk is now loaded. you would clear this upon entering a new map (starting the game) or if a chunk's content has been rewritten. Loading the saved map data only as needed prevents loading an entire map's content, localizing loading to the areas the player is visiting.