139 lines
4.4 KiB
GDScript
139 lines
4.4 KiB
GDScript
extends Node
|
|
|
|
@warning_ignore("unused_signal")
|
|
signal on_game_paused
|
|
@warning_ignore("unused_signal")
|
|
signal on_game_resumed
|
|
@warning_ignore("unused_signal")
|
|
signal on_photo_highlighted(teture: Texture)
|
|
@warning_ignore("unused_signal")
|
|
signal on_enable_photo_mode_request
|
|
@warning_ignore("unused_signal")
|
|
signal on_disable_photo_mode_request
|
|
@warning_ignore("unused_signal")
|
|
signal on_photo_taken_prepare
|
|
@warning_ignore("unused_signal")
|
|
signal on_photo_taken_started
|
|
@warning_ignore("unused_signal")
|
|
signal on_photo_taken_making
|
|
@warning_ignore("unused_signal")
|
|
signal on_photo_taken_finished
|
|
@warning_ignore("unused_signal")
|
|
signal on_photo_mode_black_screen_disappeared
|
|
|
|
const SAVE_PATH: String = "user://savegame.json"
|
|
const SAVE_PASSWORD: String = "jmpgames_megapwd"
|
|
|
|
var save_data: SaveGameData = SaveGameData.new()
|
|
var is_loaded: bool = false
|
|
|
|
func _ready() -> void:
|
|
load_game()
|
|
apply_video_settings()
|
|
apply_train_colors()
|
|
|
|
func _process(delta: float) -> void:
|
|
if not get_tree().paused and is_loaded:
|
|
save_data.total_time_played_seconds += delta
|
|
|
|
func apply_video_settings() -> void:
|
|
get_viewport().use_taa = save_data.anti_aliasing
|
|
var msaa_mode = Viewport.MSAA_2X if save_data.anti_aliasing else Viewport.MSAA_DISABLED
|
|
get_viewport().msaa_3d = msaa_mode
|
|
get_viewport().msaa_2d = Viewport.MSAA_DISABLED
|
|
|
|
match save_data.window_mode_index:
|
|
0:
|
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN)
|
|
1:
|
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
|
|
2:
|
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
|
|
DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false)
|
|
|
|
if save_data.window_mode_index == 2 and save_data.resolution_x > 0 and save_data.resolution_y > 0:
|
|
DisplayServer.window_set_size(Vector2i(save_data.resolution_x, save_data.resolution_y))
|
|
|
|
# Optional: center the window if resized
|
|
var screen_position: Vector2i = DisplayServer.screen_get_position()
|
|
var screen_size: Vector2i = DisplayServer.screen_get_size()
|
|
var window_size: Vector2i = DisplayServer.window_get_size()
|
|
var screen_center := screen_position + Vector2i(
|
|
floori(float(screen_size.x) / 2.0),
|
|
floori(float(screen_size.y) / 2.0)
|
|
)
|
|
var window_half_size := Vector2i(
|
|
floori(float(window_size.x) / 2.0),
|
|
floori(float(window_size.y) / 2.0)
|
|
)
|
|
DisplayServer.window_set_position(screen_center - window_half_size)
|
|
|
|
func apply_train_colors() -> void:
|
|
if not save_data.train_color_1.is_empty():
|
|
var mat1: ShaderMaterial = load("res://tgcc/train/Color1_train.tres")
|
|
if mat1:
|
|
mat1.set_shader_parameter("albedo_color", Color(save_data.train_color_1))
|
|
if not save_data.train_color_2.is_empty():
|
|
var mat2: ShaderMaterial = load("res://tgcc/train/Color2_train.tres")
|
|
if mat2:
|
|
mat2.set_shader_parameter("albedo_color", Color(save_data.train_color_2))
|
|
|
|
#encrypted file + binary serialization (standard)
|
|
func load_game() -> void:
|
|
if not FileAccess.file_exists(SAVE_PATH):
|
|
save_data = SaveGameData.new()
|
|
is_loaded = true
|
|
return
|
|
|
|
var file := FileAccess.open_encrypted_with_pass(SAVE_PATH, FileAccess.READ, SAVE_PASSWORD)
|
|
save_data = SaveGameData.new()
|
|
if file != null:
|
|
var data = file.get_var()
|
|
file.close()
|
|
if data is Dictionary:
|
|
save_data = SaveGameData.from_dictionary(data)
|
|
#if file == null the key or the file is corrupted -> start with new data
|
|
is_loaded = true
|
|
|
|
|
|
func save_game() -> void:
|
|
var file := FileAccess.open_encrypted_with_pass(SAVE_PATH, FileAccess.WRITE, SAVE_PASSWORD)
|
|
if file == null:
|
|
push_error("Salvataggio fallito: %s" % FileAccess.get_open_error())
|
|
return
|
|
file.store_var(save_data.to_dictionary()) # binario, non JSON
|
|
file.close()
|
|
|
|
#JSon Version
|
|
#func save_game() -> void:
|
|
#var save_file = FileAccess.open(SAVE_PATH, FileAccess.WRITE)
|
|
#var json_string = JSON.stringify(save_data.to_dictionary())
|
|
#save_file.store_line(json_string)
|
|
#
|
|
#func load_game() -> void:
|
|
#if not FileAccess.file_exists(SAVE_PATH):
|
|
#save_data = SaveGameData.new()
|
|
#is_loaded = true
|
|
#return
|
|
#
|
|
#var file = FileAccess.open(SAVE_PATH, FileAccess.READ)
|
|
#var json_string = file.get_as_text()
|
|
#
|
|
#var json = JSON.new()
|
|
#var parse_result = json.parse(json_string)
|
|
#
|
|
#save_data = SaveGameData.new()
|
|
#if parse_result == OK and json.data is Dictionary:
|
|
#save_data = SaveGameData.from_dictionary(json.data)
|
|
#
|
|
#is_loaded = true
|
|
|
|
func pause_game() -> void:
|
|
get_tree().paused = true
|
|
|
|
func resume_game() -> void:
|
|
get_tree().paused = false
|
|
|
|
func quit_game() -> void:
|
|
SceneManager.quit_game()
|