this repo has no description

Better save management

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