extends Node
signal spawn_player(xform)


# Declare member variables here. Examples:
# var a = 2
# var b = "text"


# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

var save_data = {}
var camp: Node
var camp_site: int = -1
var camp_level: int = 0
var bandits_count: int = 0
var camp_dwellings = {}
func prepare_save_data():
	var cam = get_tree().root.get_camera()
	var player = cam.get_meta("player")
	if player:
		save_data.player_xform = var2str(player.global_transform)
		save_data.player_stats = player.get_meta("stats")
	save_data.world = RoadsData.save_data()
#	save_data.dialogue = Dialogic.export()
#	save_data.scenery = scenery
#	state_list.save()
#	if save_data.dormitory.has("quests"):
#		print(save_data.dormitory.quests.running)
#	save_data.prologue = prologue_state.save()
	save_data.inventory = inventory.items
#	save_data.dormitory = dormitory_state.save()
#	save_data.roommates = characters.roommates
#	save_data.player_room_id = player.get_meta("room_id")
#	save_data.quests = questman.save()
	save_data.traffic_state = streaming.traffic_rnd.state
	var b = freezer.prepare_save_data()
	while b == false:
		yield(get_tree(), "idle_frame")
		b = freezer.prepare_save_data()
	save_data.camp_level = camp_level
	save_data.bandits_count = bandits_count
	save_data.camp_dwellings = var2str(camp_dwellings)

# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass

func restart_scene():
	var cam = get_viewport().get_camera()
	if cam && cam.has_meta("player"):
		var player = cam.get_meta("player")
		if player:
			player.remove_meta("cam")
			player.remove_meta("fps_cam")
			player = null
		get_viewport().get_camera().remove_meta("player")
	if save_data.has("inventory"):
		inventory.items = save_data.inventory
	var new_scene = load("res://world.tscn")
	streaming.done = false
	if save_data.has("camp_level"):
		camp_level = save_data.camp_level
	if save_data.has("bandits_count"):
		bandits_count = save_data.bandits_count
	if save_data.has("camp_dwellings"):
		camp_dwellings = str2var(save_data.camp_dwellings)
	get_tree().change_scene_to(new_scene)
var player_spawned = false
var castle1_captured = false
