this repo has no description

Better save management

Changed files
+128 -35
Atproto
gdscript
+16 -1
Atproto/AtProtoSaveFactory.cs
··· 13 .Named("AtProtoSave") 14 .Patching("res://Scenes/Singletons/UserSave/usersave.gdc") 15 .AddRule(new TransformationRuleBuilder() 16 .Named("save_file") 17 .Matching(TransformationPatternFactory.CreateGdSnippetPattern( 18 "\"locked_refs\": PlayerData.locked_refs, \n\t}\n", 2)) 19 .Do(Operation.Append) 20 - .With("var atproto = $\"/root/Atproto\"\nif atproto.AtProtoClient.connected() && atproto.save_loaded != null:\n\tatproto.AtProtoClient.save_file()\n", 1)).Build(); 21 } 22 }
··· 13 .Named("AtProtoSave") 14 .Patching("res://Scenes/Singletons/UserSave/usersave.gdc") 15 .AddRule(new TransformationRuleBuilder() 16 + .Named("ready_slot_condition") 17 + .Matching(TransformationPatternFactory.CreateGdSnippetPattern("_load_save(last_loaded_slot)", 2)) 18 + .Do(Operation.ReplaceAll) 19 + .With(""" 20 + var Atproto = $"/root/Atproto" 21 + if last_loaded_slot != Atproto.ATPROTO_SLOT or Atproto.config.Autoload: 22 + _load_save(last_loaded_slot) 23 + else: 24 + last_loaded_slot = -1 25 + """, 2) 26 + ) 27 + .AddRule(new TransformationRuleBuilder() 28 .Named("save_file") 29 .Matching(TransformationPatternFactory.CreateGdSnippetPattern( 30 "\"locked_refs\": PlayerData.locked_refs, \n\t}\n", 2)) 31 .Do(Operation.Append) 32 + .With("var atproto = $\"/root/Atproto\"\nif atproto.can_save_to_atproto():\n\tatproto.AtProtoClient.save_file()\n", 1) 33 + ) 34 + 35 + .Build(); 36 } 37 }
+31 -9
gdscript/mods/Atproto/atproto_client.gd
··· 2 3 # Signals 4 signal connection(suceeded) 5 6 # AtProto 7 var did ··· 228 func get_saves(callback: FuncRef): 229 list_records(callback, "dev.regnault.webfishing.savefile") 230 231 - func save_file(callback: FuncRef = null): 232 - if !connected(): return 233 var save_data = { 234 "inventory": PlayerData.inventory, 235 "hotbar": PlayerData.hotbar, ··· 317 for letter in save_data.inbound_mail: 318 for item in letter.items: 319 item.size = str(item.size) 320 save_data.at_type = "dev.regnault.webfishing.save" 321 322 - if Atproto.save_loaded: 323 put_record(Atproto.save_loaded, save_data) 324 - else: 325 - create_record(save_data, callback) 326 - 327 func load_save(uri: String): 328 var splitted_uri = uri.split("/") 329 var did = splitted_uri[2] ··· 334 335 func _after_get_save(save_record): 336 var save = save_record.value 337 338 var modified_journal: Dictionary = {} 339 for area in save.journal: ··· 415 PlayerData._missing_quest_check() 416 PlayerData._unlock_defaults() 417 418 - Atproto.config.Save = save_record.uri 419 - Atproto.save_loaded = save_record.uri 420 - PopupMessage._show_popup("AtProto save file loaded") 421
··· 2 3 # Signals 4 signal connection(suceeded) 5 + signal savefile_loaded(uri) 6 + 7 + # State 8 + var can_save = true 9 10 # AtProto 11 var did ··· 232 func get_saves(callback: FuncRef): 233 list_records(callback, "dev.regnault.webfishing.savefile") 234 235 + 236 + func get_save_data(): 237 var save_data = { 238 "inventory": PlayerData.inventory, 239 "hotbar": PlayerData.hotbar, ··· 321 for letter in save_data.inbound_mail: 322 for item in letter.items: 323 item.size = str(item.size) 324 + 325 + return save_data 326 + 327 + func save_file(callback: FuncRef = null, creation = false): 328 + if UserSave.current_loaded_slot != Atproto.ATPROTO_SLOT: 329 + return 330 + if !connected(): return 331 + 332 + var save_data = get_save_data() 333 save_data.at_type = "dev.regnault.webfishing.save" 334 335 + if Atproto.save_loaded != "": 336 put_record(Atproto.save_loaded, save_data) 337 + 338 + func create_save(callback: FuncRef = null): 339 + if !connected(): return 340 + var save_data = get_save_data() 341 + save_data.at_type = "dev.regnault.webfishing.save" 342 + create_record(save_data, callback) 343 + 344 func load_save(uri: String): 345 var splitted_uri = uri.split("/") 346 var did = splitted_uri[2] ··· 351 352 func _after_get_save(save_record): 353 var save = save_record.value 354 + 355 + UserSave._load_save(Atproto.ATPROTO_SLOT) 356 357 var modified_journal: Dictionary = {} 358 for area in save.journal: ··· 434 PlayerData._missing_quest_check() 435 PlayerData._unlock_defaults() 436 437 + can_save = false 438 + UserSave._save_slot(Atproto.ATPROTO_SLOT) 439 + can_save = true 440 + 441 + emit_signal("savefile_loaded", save_record.uri) 442 + 443
+9 -13
gdscript/mods/Atproto/main.gd
··· 1 extends Node 2 3 var config: Dictionary 4 var save_loaded: String 5 var default_config: Dictionary = {} 6 ··· 17 func _enter_tree(): 18 AtProtoClient = AtProtoClient_t.new() 19 add_child(AtProtoClient) 20 get_tree().connect("node_added", self, "_add_atproto_menu") 21 22 23 func _ready() -> void: 24 - print("QUOTA:", Steam.getQuota()) 25 - TackleBox.connect("mod_config_updated", self, "_on_config_update") 26 - 27 _init_config() 28 29 func _init_config(): ··· 36 if config.Autoconnect == true: 37 AtProtoClient.login(config.Handle, config.Password) 38 39 - 40 func _save_config(): 41 TackleBox.set_mod_config(name, config) 42 43 - func _on_config_update(mod_id: String, new_config: Dictionary) -> void: 44 - if mod_id != name: 45 - return 46 - if config.hash() == new_config.hash(): 47 - return 48 - config = new_config 49 - if config.Handle != "" and config.Password != "": 50 - AtProtoClient.login(config.Handle, config.Password) 51 - 52 func _add_atproto_menu(node: Node): 53 if node.name == "main_menu": 54 var atproto_menu: Node = AtProtoMenu.instance() ··· 70 71 if config.Save != "" and config.Autoload and AtProtoClient.connected(): 72 AtProtoClient.load_save(config.Save)
··· 1 extends Node 2 3 var config: Dictionary 4 + 5 + const ATPROTO_SLOT = 99 6 var save_loaded: String 7 var default_config: Dictionary = {} 8 ··· 19 func _enter_tree(): 20 AtProtoClient = AtProtoClient_t.new() 21 add_child(AtProtoClient) 22 + AtProtoClient.connect("savefile_loaded", self, "set_save_file") 23 get_tree().connect("node_added", self, "_add_atproto_menu") 24 25 26 func _ready() -> void: 27 _init_config() 28 29 func _init_config(): ··· 36 if config.Autoconnect == true: 37 AtProtoClient.login(config.Handle, config.Password) 38 39 func _save_config(): 40 TackleBox.set_mod_config(name, config) 41 42 func _add_atproto_menu(node: Node): 43 if node.name == "main_menu": 44 var atproto_menu: Node = AtProtoMenu.instance() ··· 60 61 if config.Save != "" and config.Autoload and AtProtoClient.connected(): 62 AtProtoClient.load_save(config.Save) 63 + 64 + func can_save_to_atproto(): 65 + return AtProtoClient.can_save && UserSave.current_loaded_slot == ATPROTO_SLOT && AtProtoClient.connected() 66 + 67 + func set_save_file(save_uri): 68 + save_loaded = save_uri
+1
gdscript/mods/Atproto/ui/buttons/atproto.gd
··· 3 4 func _on_mods_pressed() -> void: 5 var atproto_menu = $"../../atproto_config" 6 atproto_menu.visible = true
··· 3 4 func _on_mods_pressed() -> void: 5 var atproto_menu = $"../../atproto_config" 6 + atproto_menu._refresh() 7 atproto_menu.visible = true
+54 -3
gdscript/mods/Atproto/ui/menus/atproto_config.gd
··· 1 extends Node 2 3 onready var Atproto := $"/root/Atproto" 4 const AtProtoNewSaveMenu := preload("res://mods/Atproto/ui/menus/new_save.tscn") 5 6 signal setup_done() ··· 11 var Saves : VBoxContainer 12 13 func _ready(): 14 Settings = $"%atproto_settings" 15 Credentials = Settings.get_node("credentials") 16 Saves = Settings.get_node("saves") ··· 70 load_save_button.disabled = true 71 new_save_button.disabled = true 72 73 emit_signal("setup_done") 74 75 func _on_apply_pressed() -> void: ··· 127 func after_login(_a = null): 128 Atproto.AtProtoClient.get_saves(funcref(self, "init_saves")) 129 130 131 # SAVES 132 133 func _on_load_save_button_down(): 134 var save: OptionButton = Saves.get_node("save").get_node("OptionButton") 135 Atproto.AtProtoClient.load_save(save.get_selected_metadata()) 136 pass 137 138 139 func _on_new_save_button_down(): 140 SaveMenu.visible = true 141 - pass # Replace with function body. 142 143 # Create Save Menu 144 func init_save_menu(): ··· 154 var backup = backup_save() 155 if !duplicate: 156 PlayerData._reset_save() 157 - Atproto.AtProtoClient.save_file(funcref(self, "create_save_file")) 158 close_save_menu() 159 restore_save(backup) 160 pass 161 162 func create_save_file(save_record): 163 var file_name = SaveMenu.get_node("save_menu/Panel/save_name/LineEdit").text 164 var uri = save_record.uri 165 - Atproto.AtProtoClient.create_save_file(uri, file_name, funcref(self, "after_login")) 166 pass 167 168 func backup_save():
··· 1 extends Node 2 3 onready var Atproto := $"/root/Atproto" 4 + 5 const AtProtoNewSaveMenu := preload("res://mods/Atproto/ui/menus/new_save.tscn") 6 7 signal setup_done() ··· 12 var Saves : VBoxContainer 13 14 func _ready(): 15 + Atproto.AtProtoClient.connect("savefile_loaded", self, "set_save_file") 16 Settings = $"%atproto_settings" 17 Credentials = Settings.get_node("credentials") 18 Saves = Settings.get_node("saves") ··· 72 load_save_button.disabled = true 73 new_save_button.disabled = true 74 75 + _refresh() 76 emit_signal("setup_done") 77 78 func _on_apply_pressed() -> void: ··· 130 func after_login(_a = null): 131 Atproto.AtProtoClient.get_saves(funcref(self, "init_saves")) 132 133 + func _refresh(): 134 + $"%atproto_settings/save_info".text = get_loaded_save_info() 135 136 + func get_loaded_save_info(): 137 + if UserSave.current_loaded_slot != Atproto.ATPROTO_SLOT: 138 + return "No AtProto save loaded" 139 + else: 140 + var save_option: OptionButton = Saves.get_node("save").get_node("OptionButton") 141 + var i = 0 142 + while i < save_option.get_item_count(): 143 + var metadata = save_option.get_item_metadata(i) 144 + if metadata == Atproto.save_loaded: 145 + return save_option.get_item_text(i) + " is currently loaded" 146 + i+=1 147 + return "Invalid save file loaded" 148 # SAVES 149 150 + func set_save_file(save_uri): 151 + Atproto.config.Save = save_uri 152 + PopupMessage._show_popup("AtProto save loaded : " + get_current_save_name()) 153 + _refresh() 154 + pass 155 + 156 func _on_load_save_button_down(): 157 var save: OptionButton = Saves.get_node("save").get_node("OptionButton") 158 Atproto.AtProtoClient.load_save(save.get_selected_metadata()) 159 pass 160 161 162 + func get_current_save_name() -> String: 163 + if UserSave.current_loaded_slot != 99: 164 + return "Slot " + str(UserSave.current_loaded_slot + 1) 165 + 166 + var save_option: OptionButton = Saves.get_node("save").get_node("OptionButton") 167 + var i = 0 168 + while i < save_option.get_item_count(): 169 + var metadata = save_option.get_item_metadata(i) 170 + if metadata == Atproto.save_loaded: 171 + return save_option.get_item_text(i) 172 + i+=1 173 + return "" 174 + 175 func _on_new_save_button_down(): 176 + var current = get_current_save_name() 177 + if current != "": 178 + SaveMenu.get_node("save_menu/duplicate").text = "Duplicate " + current 179 + SaveMenu.get_node("save_menu/duplicate").disabled = false 180 + else: 181 + SaveMenu.get_node("save_menu/duplicate").text = "Invalid Save" 182 + SaveMenu.get_node("save_menu/duplicate").disabled = true 183 + 184 SaveMenu.visible = true 185 + 186 187 # Create Save Menu 188 func init_save_menu(): ··· 198 var backup = backup_save() 199 if !duplicate: 200 PlayerData._reset_save() 201 + Atproto.AtProtoClient.create_save(funcref(self, "create_save_file")) 202 close_save_menu() 203 restore_save(backup) 204 pass 205 206 + func save_file_created(record): 207 + var file_name = SaveMenu.get_node("save_menu/Panel/save_name/LineEdit").text 208 + PopupMessage._show_popup("AtProto save created : " + file_name) 209 + SaveMenu.get_node("save_menu/Panel/save_name/LineEdit").text = "" 210 + after_login() 211 + pass 212 + 213 func create_save_file(save_record): 214 var file_name = SaveMenu.get_node("save_menu/Panel/save_name/LineEdit").text 215 var uri = save_record.uri 216 + Atproto.AtProtoClient.create_save_file(uri, file_name, funcref(self, "save_file_created")) 217 pass 218 219 func backup_save():
+8 -1
gdscript/mods/Atproto/ui/menus/atproto_config.tscn
··· 88 [node name="atproto_settings" type="VBoxContainer" parent="Panel/Panel/ScrollContainer"] 89 unique_name_in_owner = true 90 margin_right = 704.0 91 - margin_bottom = 356.0 92 size_flags_horizontal = 3 93 custom_constants/separation = 40 94 ··· 236 margin_bottom = 32.0 237 size_flags_horizontal = 3 238 text = "Load Save" 239 240 [node name="Loader" type="Panel" parent="Panel"] 241 visible = false
··· 88 [node name="atproto_settings" type="VBoxContainer" parent="Panel/Panel/ScrollContainer"] 89 unique_name_in_owner = true 90 margin_right = 704.0 91 + margin_bottom = 428.0 92 size_flags_horizontal = 3 93 custom_constants/separation = 40 94 ··· 236 margin_bottom = 32.0 237 size_flags_horizontal = 3 238 text = "Load Save" 239 + 240 + [node name="save_info" type="Label" parent="Panel/Panel/ScrollContainer/atproto_settings"] 241 + margin_top = 396.0 242 + margin_right = 704.0 243 + margin_bottom = 428.0 244 + text = "[No Save File Loaded]" 245 + align = 1 246 247 [node name="Loader" type="Panel" parent="Panel"] 248 visible = false
+9 -8
gdscript/mods/Atproto/ui/menus/new_save.tscn
··· 22 corner_radius_bottom_left = 16 23 24 [node name="Node2D" type="Control"] 25 - margin_right = 1920.0 26 - margin_bottom = 1080.0 27 theme = ExtResource( 1 ) 28 29 [node name="background" type="ColorRect" parent="."] 30 anchor_right = 1.0 31 anchor_bottom = 1.0 32 - margin_left = -67.0 33 - margin_top = 17.0 34 - margin_right = 1853.0 35 - margin_bottom = 1097.0 36 size_flags_horizontal = 3 37 size_flags_vertical = 3 38 color = Color( 0.0627451, 0.109804, 0.192157, 0.431373 ) ··· 90 size_flags_horizontal = 3 91 92 [node name="Label" type="Label" parent="save_menu/Panel/save_name"] 93 - margin_right = 521.0 94 margin_bottom = 32.0 95 text = "Save Name" 96 align = 1 97 98 [node name="LineEdit" type="LineEdit" parent="save_menu/Panel/save_name"] 99 margin_top = 36.0 100 - margin_right = 521.0 101 margin_bottom = 68.0 102 size_flags_horizontal = 3 103 ··· 149 margin_top = -56.0 150 margin_right = 0.287964 151 margin_bottom = 24.0 152 rect_pivot_offset = Vector2( 89, 24 ) 153 text = "Duplicate Save" 154 script = ExtResource( 2 )
··· 22 corner_radius_bottom_left = 16 23 24 [node name="Node2D" type="Control"] 25 + anchor_right = 1.0 26 + anchor_bottom = 1.0 27 theme = ExtResource( 1 ) 28 29 [node name="background" type="ColorRect" parent="."] 30 anchor_right = 1.0 31 anchor_bottom = 1.0 32 + margin_left = -83.0 33 + margin_top = -47.0 34 + margin_right = 33.0 35 + margin_bottom = 29.0 36 size_flags_horizontal = 3 37 size_flags_vertical = 3 38 color = Color( 0.0627451, 0.109804, 0.192157, 0.431373 ) ··· 90 size_flags_horizontal = 3 91 92 [node name="Label" type="Label" parent="save_menu/Panel/save_name"] 93 + margin_right = 520.0 94 margin_bottom = 32.0 95 text = "Save Name" 96 align = 1 97 98 [node name="LineEdit" type="LineEdit" parent="save_menu/Panel/save_name"] 99 margin_top = 36.0 100 + margin_right = 520.0 101 margin_bottom = 68.0 102 size_flags_horizontal = 3 103 ··· 149 margin_top = -56.0 150 margin_right = 0.287964 151 margin_bottom = 24.0 152 + grow_horizontal = 0 153 rect_pivot_offset = Vector2( 89, 24 ) 154 text = "Duplicate Save" 155 script = ExtResource( 2 )