Add config file to save last used folder
This commit is contained in:
parent
93ba9e644b
commit
26caf7e05a
|
@ -1,8 +1,10 @@
|
|||
extends Node
|
||||
const CONFIG_FILENAME := 'user://config.ini'
|
||||
|
||||
var base_resolution: Vector2 = Vector2(ProjectSettings.get_setting('display/window/size/width'), ProjectSettings.get_setting('display/window/size/height')) # Vector2(640, 360)
|
||||
var shrink_timer := Timer.new()
|
||||
var last_resolution_pre_shrink := Vector2.ZERO
|
||||
var config := ConfigFile.new()
|
||||
|
||||
var SNES_PSX_addresses := load_tsv('res://data/SNES_PSX_addresses.tsv')
|
||||
|
||||
|
@ -219,7 +221,22 @@ static func game_time_frames_to_hhmm(game_time_frames: int) -> String:
|
|||
var game_hours = game_minutes / 60
|
||||
return '%d:%02d' % [game_hours, game_minutes % 60]
|
||||
|
||||
func load_config():
|
||||
match self.config.load(CONFIG_FILENAME):
|
||||
OK:
|
||||
print('loaded config.ini')
|
||||
var err:
|
||||
print('failed to load config.ini: %d'%err)
|
||||
|
||||
func save_config():
|
||||
match self.config.save(CONFIG_FILENAME):
|
||||
OK:
|
||||
print('saved config.ini')
|
||||
var err:
|
||||
print('failed to save config.ini: %d'%err)
|
||||
|
||||
func _ready():
|
||||
load_config()
|
||||
match shrink_timer.connect('timeout', self, 'shrink_to_integer'):
|
||||
OK:
|
||||
pass
|
||||
|
|
|
@ -213,9 +213,15 @@ func _ready() -> void:
|
|||
else:
|
||||
home_path = OS.get_environment('HOME')
|
||||
# dir.open(OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS))
|
||||
var error = dir.open(home_path)
|
||||
if error == OK:
|
||||
match dir.open(Common.config.get_value('filesystem', 'last_used_directory', home_path)):
|
||||
OK:
|
||||
update_view()
|
||||
_:
|
||||
match dir.open(home_path):
|
||||
OK:
|
||||
update_view()
|
||||
_:
|
||||
print_debug('Failed to open last dir or home dir')
|
||||
btn_load.connect('pressed', self, 'activate_current_entry')
|
||||
btn_debug.connect('pressed', self, '_on_debug_pressed')
|
||||
RomLoader.connect('rom_loaded', self, '_on_rom_loaded')
|
||||
|
@ -223,6 +229,12 @@ func _ready() -> void:
|
|||
print(ProjectSettings.globalize_path('user://'))
|
||||
print(ProjectSettings.globalize_path(dir.get_current_dir()))
|
||||
|
||||
func _update_config() -> void:
|
||||
var d = self.dir.get_current_dir()
|
||||
if d != Common.config.get_value('filesystem', 'last_used_directory'):
|
||||
Common.config.set_value('filesystem', 'last_used_directory', self.dir.get_current_dir())
|
||||
Common.save_config()
|
||||
|
||||
func _set_mode(new_mode) -> void:
|
||||
match new_mode:
|
||||
SELECT_ROM:
|
||||
|
@ -231,9 +243,11 @@ func _set_mode(new_mode) -> void:
|
|||
SELECT_SAVE:
|
||||
$'%lbl_prompt'.text = "Select a save file from your device's storage"
|
||||
btn_debug.disabled = false
|
||||
_update_config()
|
||||
COMPLETE:
|
||||
$'%lbl_prompt'.text = "Save file loaded"
|
||||
btn_debug.disabled = false
|
||||
_update_config()
|
||||
current_mode = new_mode
|
||||
update_view()
|
||||
init_labels()
|
||||
|
|
Loading…
Reference in New Issue