2022-05-15 18:29:03 +00:00
|
|
|
extends Control
|
2022-09-25 15:53:39 +00:00
|
|
|
#charFilePath will hold the file path for the character file, fileText will hold the text in the file
|
|
|
|
var charFilePath = ""
|
|
|
|
var fileText
|
2022-05-15 18:29:03 +00:00
|
|
|
|
|
|
|
func _ready() -> void:
|
2022-09-25 15:53:39 +00:00
|
|
|
#grab focus will make it so tab can be used to move between options
|
2022-05-15 18:29:03 +00:00
|
|
|
$VBoxContainer2/Title/But_ChangeScene.grab_focus()
|
2022-09-25 15:53:39 +00:00
|
|
|
|
|
|
|
var save_game = File.new()
|
|
|
|
if save_game.file_exists("user://savegame.save"):
|
|
|
|
save_game.open("user://savegame.save", File.READ)
|
|
|
|
var tempPath = save_game.get_as_text()
|
|
|
|
displayInfo(tempPath)
|
|
|
|
|
|
|
|
save_game.close()
|
2022-05-15 18:29:03 +00:00
|
|
|
|
2022-09-25 15:53:39 +00:00
|
|
|
func displayInfo(path):
|
|
|
|
var file = File.new()
|
|
|
|
#read the text in the file, save it in the variable fileText, display in textBox
|
|
|
|
file.open(path, File.READ)
|
|
|
|
|
|
|
|
fileText = file.get_as_text()
|
|
|
|
|
|
|
|
$VBoxContainer2/VBoxContainer/VBoxContainer3/textBox.visible = true
|
|
|
|
$VBoxContainer2/VBoxContainer/VBoxContainer3/textBox.text = fileText
|
|
|
|
#
|
|
|
|
|
|
|
|
#save the file path in the global var to use it in the other function
|
|
|
|
charFilePath = path
|
|
|
|
file.close()
|
|
|
|
|
2022-05-15 18:29:03 +00:00
|
|
|
|
|
|
|
func _on_Button_pressed():
|
|
|
|
$VBoxContainer2/VBoxContainer/FileDialog.popup()
|
|
|
|
|
|
|
|
func _on_FileDialog_file_selected(path):
|
2022-09-25 15:53:39 +00:00
|
|
|
displayInfo(path)
|
|
|
|
|
|
|
|
#when they've made the changes and pressed save:
|
|
|
|
func _on_Save_Button_pressed():
|
|
|
|
#open the same file so that changes can be written to it
|
2022-05-15 18:29:03 +00:00
|
|
|
var file = File.new()
|
2022-09-25 15:53:39 +00:00
|
|
|
file.open(charFilePath, File.WRITE)
|
|
|
|
|
|
|
|
#store the text from the textbox back into the file
|
|
|
|
var content = ""
|
|
|
|
var currentWord = $VBoxContainer2/VBoxContainer/VBoxContainer3/textBox.text
|
|
|
|
|
|
|
|
content = currentWord
|
|
|
|
file.store_string(content)
|
2022-05-15 18:29:03 +00:00
|
|
|
file.close()
|
2022-09-25 15:53:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_But_Remember_pressed():
|
|
|
|
#save the path of the file so that it can be automatically opened next time
|
|
|
|
var save_game = File.new()
|
|
|
|
save_game.open("user://savegame.save", File.WRITE)
|
|
|
|
save_game.store_string(charFilePath)
|
|
|
|
save_game.close()
|