add saving train colors
This commit is contained in:
@@ -11,13 +11,15 @@ func _ready() -> void:
|
||||
color_picker.pressed.connect(_on_color_selected.bind(color_picker, 0))
|
||||
color_picker.deselect()
|
||||
|
||||
_set_selected_color(0, 0)
|
||||
var init_idx_1 = GameState.save_data.train_color_1_index
|
||||
_set_selected_color(init_idx_1, 0)
|
||||
|
||||
for color_picker in color_pickers_2:
|
||||
color_picker.pressed.connect(_on_color_selected.bind(color_picker, 1))
|
||||
color_picker.deselect()
|
||||
|
||||
_set_selected_color(0, 1)
|
||||
var init_idx_2 = GameState.save_data.train_color_2_index
|
||||
_set_selected_color(init_idx_2, 1)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if treno:
|
||||
@@ -29,7 +31,7 @@ func _set_selected_color(index: int, material_index: int) -> void:
|
||||
if i == index:
|
||||
color_pickers[i].select()
|
||||
selected_color = color_pickers[i].color
|
||||
_apply_train_color(selected_color, material_index)
|
||||
_apply_train_color(selected_color, material_index, index)
|
||||
else:
|
||||
color_pickers[i].deselect()
|
||||
|
||||
@@ -40,8 +42,16 @@ func _on_color_selected(selected_color_picker: TrainColorPicker, material_index:
|
||||
_set_selected_color(i, material_index)
|
||||
break
|
||||
|
||||
func _apply_train_color(color: Color, material_index: int) -> void:
|
||||
func _apply_train_color(color: Color, material_index: int, color_index: int = 0) -> void:
|
||||
var path = "res://tgcc/train/Color%s_train.tres" % ("1" if material_index == 0 else "2")
|
||||
var mat: ShaderMaterial = load(path)
|
||||
if mat:
|
||||
mat.set_shader_parameter("albedo_color", color)
|
||||
|
||||
if material_index == 0:
|
||||
GameState.save_data.train_color_1 = color.to_html()
|
||||
GameState.save_data.train_color_1_index = color_index
|
||||
else:
|
||||
GameState.save_data.train_color_2 = color.to_html()
|
||||
GameState.save_data.train_color_2_index = color_index
|
||||
GameState.save_game()
|
||||
|
||||
@@ -29,6 +29,7 @@ var is_loaded: bool = false
|
||||
func _ready() -> void:
|
||||
load_game()
|
||||
apply_video_settings()
|
||||
apply_train_colors()
|
||||
|
||||
func apply_video_settings() -> void:
|
||||
get_viewport().use_taa = save_data.anti_aliasing
|
||||
@@ -36,6 +37,16 @@ func apply_video_settings() -> void:
|
||||
get_viewport().msaa_3d = msaa_mode
|
||||
get_viewport().msaa_2d = msaa_mode
|
||||
|
||||
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))
|
||||
|
||||
match save_data.window_mode_index:
|
||||
0:
|
||||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN)
|
||||
|
||||
@@ -9,6 +9,10 @@ var anti_aliasing: bool = true
|
||||
var window_mode_index: int = 0
|
||||
var resolution_x: int = 1920
|
||||
var resolution_y: int = 1080
|
||||
var train_color_1: String = ""
|
||||
var train_color_2: String = ""
|
||||
var train_color_1_index: int = 0
|
||||
var train_color_2_index: int = 0
|
||||
|
||||
func to_dictionary() -> Dictionary:
|
||||
var serialized_collectible_ids: Array[String] = []
|
||||
@@ -23,6 +27,10 @@ func to_dictionary() -> Dictionary:
|
||||
"window_mode_index": window_mode_index,
|
||||
"resolution_x": resolution_x,
|
||||
"resolution_y": resolution_y,
|
||||
"train_color_1": train_color_1,
|
||||
"train_color_2": train_color_2,
|
||||
"train_color_1_index": train_color_1_index,
|
||||
"train_color_2_index": train_color_2_index,
|
||||
}
|
||||
|
||||
static func from_dictionary(data: Dictionary) -> SaveGameData:
|
||||
@@ -52,4 +60,16 @@ static func from_dictionary(data: Dictionary) -> SaveGameData:
|
||||
if data.has("resolution_y"):
|
||||
save_game_data.resolution_y = int(data["resolution_y"])
|
||||
|
||||
if data.has("train_color_1"):
|
||||
save_game_data.train_color_1 = str(data["train_color_1"])
|
||||
|
||||
if data.has("train_color_2"):
|
||||
save_game_data.train_color_2 = str(data["train_color_2"])
|
||||
|
||||
if data.has("train_color_1_index"):
|
||||
save_game_data.train_color_1_index = int(data["train_color_1_index"])
|
||||
|
||||
if data.has("train_color_2_index"):
|
||||
save_game_data.train_color_2_index = int(data["train_color_2_index"])
|
||||
|
||||
return save_game_data
|
||||
|
||||
Reference in New Issue
Block a user