33 lines
975 B
GDScript
33 lines
975 B
GDScript
extends Node2D
|
|
|
|
@onready var WorldTiles : TileMapLayer = $TileMapLayer
|
|
|
|
var chunkPos : Vector2i = Vector2i(0,0)
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
get_tree().auto_accept_quit = false
|
|
load_game("Chunk"+str(chunkPos.x)+"_"+str(chunkPos.y), WorldTiles)
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
pass
|
|
|
|
|
|
func load_game(path:String, tile_map_layer:TileMapLayer) -> void:
|
|
var file : FileAccess = FileAccess.open(path, FileAccess.READ)
|
|
if file:
|
|
tile_map_layer.tile_map_data = file.get_var()
|
|
|
|
func save(path:String, tile_map_layer:TileMapLayer) -> void:
|
|
var file : FileAccess = FileAccess.open(path, FileAccess.WRITE)
|
|
file.store_var(tile_map_layer.tile_map_data)
|
|
file.close()
|
|
|
|
func _notification(what: int) -> void:
|
|
if what == NOTIFICATION_WM_CLOSE_REQUEST:
|
|
save("Chunk"+str(chunkPos.x)+"_"+str(chunkPos.y), WorldTiles)
|
|
get_tree().quit()
|