extends Node

var gameNight = 0
var stars = 0

var cameras
var locations
var cameraHelper
var game

func _ready() -> void:
	cameras = loadJSON("res://Data/cameras.json")
	locations = loadJSON("res://Data/locations.json")
	
	cameraHelper = hCamera.new()
	cameraHelper.setup(cameras)
	
	game = cGame.new()
	
	begin_game()

func begin_game():
	game._setup()
	game.nightStarted = true

func loadJSON(path: String) -> Dictionary:
	var file = FileAccess.open(path, FileAccess.READ)
	if not file:
		push_error("Failed to open JSON: %s" % path)
		return {}

	var text = file.get_as_text()
	file.close()
	
	var data = JSON.parse_string(text)
	if typeof(data) != TYPE_DICTIONARY:
		push_error("JSON did not return a dictionary: %s" % path)
		return {}
	return data

func _input(event: InputEvent) -> void:
	if event is InputEventKey:
		if event.pressed:
			if event.keycode == KEY_ESCAPE:
				get_tree().quit()
			if event.keycode == KEY_F11:
				if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN:
					DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
					DisplayServer.window_set_size(Vector2i(1152, 648))
					DisplayServer.window_set_position(Vector2i(int((DisplayServer.screen_get_size().x/2.0)-(DisplayServer.window_get_size().x/2.0)),int((DisplayServer.screen_get_size().y/2.0)-(DisplayServer.window_get_size().y/2.0))))
				else:
					DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN)
