Allow settings.cfg to set library paths

This commit is contained in:
Luke Hubmayer-Werner 2024-05-29 22:11:01 +09:30
parent eafc64b631
commit 36f9d12054
8 changed files with 62 additions and 24 deletions

View File

@ -27,12 +27,13 @@ func _process(delta: float) -> void:
var right = Input.get_joy_axis(joypad_index, id_right) var right = Input.get_joy_axis(joypad_index, id_right)
var start = Input.get_joy_axis(joypad_index, id_start) var start = Input.get_joy_axis(joypad_index, id_start)
var back = Input.get_joy_axis(joypad_index, id_back) var back = Input.get_joy_axis(joypad_index, id_back)
$Grid/left/Label.text = "%.03f" % left var precision = "%.05f"
$Grid/down/Label.text = "%.03f" % down $Grid/left/Label.text = precision % left
$Grid/up/Label.text = "%.03f" % up $Grid/down/Label.text = precision % down
$Grid/right/Label.text = "%.03f" % right $Grid/up/Label.text = precision % up
$TopRow/lbl_start.text = "start\n%.03f" % start $Grid/right/Label.text = precision % right
$TopRow/lbl_back.text = "back\n%.03f" % back $TopRow/lbl_start.text = "start\n" + precision % start
$TopRow/lbl_back.text = "back\n" + precision % back
$Grid/left/t.modulate = color_on if Input.is_joy_button_pressed(joypad_index, id_left) else color_off $Grid/left/t.modulate = color_on if Input.is_joy_button_pressed(joypad_index, id_left) else color_off
$Grid/down/t.modulate = color_on if Input.is_joy_button_pressed(joypad_index, id_down) else color_off $Grid/down/t.modulate = color_on if Input.is_joy_button_pressed(joypad_index, id_down) else color_off

View File

@ -29,7 +29,6 @@ margin_top = 464.0
margin_right = 614.0 margin_right = 614.0
margin_bottom = 532.0 margin_bottom = 532.0
size_flags_horizontal = 4 size_flags_horizontal = 4
disabled = true
text = "Step" text = "Step"
[node name="btn_settings" type="Button" parent="VBoxContainer"] [node name="btn_settings" type="Button" parent="VBoxContainer"]

View File

@ -116,15 +116,19 @@ script = ExtResource( 1 )
[node name="Center" type="Node2D" parent="noteHandler/viewport"] [node name="Center" type="Node2D" parent="noteHandler/viewport"]
position = Vector2( 540, 540 ) position = Vector2( 540, 540 )
[node name="SlideTrailHandler" type="Node2D" parent="noteHandler/viewport/Center"] [node name="slideTrailHandler" type="Node2D" parent="noteHandler/viewport/Center"]
unique_name_in_owner = true
[node name="JudgeText" type="MeshInstance2D" parent="noteHandler/viewport/Center"] [node name="judgeText" type="MeshInstance2D" parent="noteHandler/viewport/Center"]
unique_name_in_owner = true
texture = ExtResource( 2 ) texture = ExtResource( 2 )
[node name="meshinstance" type="MeshInstance2D" parent="noteHandler/viewport/Center"] [node name="meshinstance" type="MeshInstance2D" parent="noteHandler/viewport/Center"]
unique_name_in_owner = true
material = SubResource( 2 ) material = SubResource( 2 )
[node name="notelines" type="MeshInstance2D" parent="noteHandler/viewport/Center"] [node name="notelines" type="MeshInstance2D" parent="noteHandler/viewport/Center"]
unique_name_in_owner = true
material = SubResource( 3 ) material = SubResource( 3 )
[node name="lbl_combo" type="Label" parent="noteHandler"] [node name="lbl_combo" type="Label" parent="noteHandler"]
@ -165,6 +169,11 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="square" type="Control" parent="."]
unique_name_in_owner = true
anchor_right = 1.0
anchor_bottom = 1.0
[connection signal="combo_changed" from="noteHandler" to="noteHandler/lbl_combo" method="_on_NoteHandler_combo_changed"] [connection signal="combo_changed" from="noteHandler" to="noteHandler/lbl_combo" method="_on_NoteHandler_combo_changed"]
[connection signal="finished_song" from="noteHandler" to="noteHandler/lbl_combo" method="_on_NoteHandler_finished_song"] [connection signal="finished_song" from="noteHandler" to="noteHandler/lbl_combo" method="_on_NoteHandler_finished_song"]
[connection signal="column_pressed" from="InputHandler" to="noteHandler" method="_on_InputHandler_column_pressed"] [connection signal="column_pressed" from="InputHandler" to="noteHandler" method="_on_InputHandler_column_pressed"]

View File

@ -2,8 +2,12 @@ extends Control
signal start_touchgame signal start_touchgame
signal start_stepgame signal start_stepgame
func update_libraries_text() -> void:
$lbl_settingspath.text = 'Data directories:\n' + '\n'.join(Settings.get_library_paths())
func _ready() -> void: func _ready() -> void:
$lbl_settingspath.text = "Data directory is\n" + FileLoader.userroot update_libraries_text()
Settings.connect('config_loaded', self, 'update_libraries_text')
func quit() -> void: func quit() -> void:
get_tree().quit() get_tree().quit()

View File

@ -222,7 +222,7 @@ func _draw_song_select(center: Vector2) -> Array:
if len(genres) <= 0: if len(genres) <= 0:
draw_string_centered(genreFont, Vector2(center.x, center.y-440*f_scale), 'No Songs in Library!', Color.aqua) draw_string_centered(genreFont, Vector2(center.x, center.y-440*f_scale), 'No Songs in Library!', Color.aqua)
draw_string_centered(diffNumFont, Vector2(center.x, center.y-390*f_scale), FileLoader.userroot, Color.lightgreen) draw_string_centered(diffNumFont, Vector2(center.x, center.y-390*f_scale), Settings.user_data_dir, Color.lightgreen)
return touchrects return touchrects
var ssid = self.selected_song_idx var ssid = self.selected_song_idx

View File

@ -217,7 +217,7 @@ func _draw_song_select(center: Vector2) -> Array:
if len(genres) <= 0: if len(genres) <= 0:
draw_string_centered(genreFont, Vector2(center.x, center.y-440*f_scale), 'No Songs in Library!', Color.aqua) draw_string_centered(genreFont, Vector2(center.x, center.y-440*f_scale), 'No Songs in Library!', Color.aqua)
draw_string_centered(diffNumFont, Vector2(center.x, center.y-390*f_scale), FileLoader.userroot, Color.lightgreen) draw_string_centered(diffNumFont, Vector2(center.x, center.y-390*f_scale), Settings.user_data_dir, Color.lightgreen)
return touchrects return touchrects
var ssid = self.selected_song_idx var ssid = self.selected_song_idx

View File

@ -10,13 +10,14 @@ const NOT_FOUND := ''
const default_difficulty_keys = ['Z', 'B', 'A', 'E', 'M', 'R'] const default_difficulty_keys = ['Z', 'B', 'A', 'E', 'M', 'R']
var userroot := OS.get_user_data_dir().rstrip('/')+'/' if OS.get_name() != 'Android' else '/storage/emulated/0/RhythmGame/' var PATHS : PoolStringArray
var PATHS := PoolStringArray([userroot]) # Temporary hardcoded testing func update_library_paths() -> void:
# The following would probably work. One huge caveat is that permission needs to be manually granted by the user in app settings as we can't use OS.request_permission('WRITE_EXTERNAL_STORAGE') PATHS = Settings.get_library_paths()
# '/storage/emulated/0/Android/data/au.ufeff.rhythmgame/'
# '/sdcard/Android/data/au.ufeff.rhythmgame/'
func _ready() -> void: func _ready() -> void:
update_library_paths()
print('Library paths: ', PATHS) print('Library paths: ', PATHS)
Settings.connect('config_loaded', self, 'update_library_paths')
func find_file(name: String, print_notfound:=false) -> String: func find_file(name: String, print_notfound:=false) -> String:
@ -175,7 +176,7 @@ func load_filelist(filelist: Array, directory=''):
func save_json(filename: String, data: Dictionary): func save_json(filename: String, data: Dictionary):
filename = userroot + filename filename = Settings.user_data_dir + filename
var dir = filename.rsplit('/', true, 1)[0] var dir = filename.rsplit('/', true, 1)[0]
match FileHelpers.init_directory(dir): match FileHelpers.init_directory(dir):
OK: OK:

View File

@ -2,8 +2,17 @@
# This is mostly used so that signals can be used to respond to settings changes # This is mostly used so that signals can be used to respond to settings changes
extends Node extends Node
signal config_loaded
signal subsampling_changed(xy) signal subsampling_changed(xy)
const ANDROID_USERDIR := '/storage/emulated/0/RhythmGame/'
# The following would probably work. One huge caveat is that permission needs to be manually granted by the user in app settings as we can't use OS.request_permission('WRITE_EXTERNAL_STORAGE')
# '/storage/emulated/0/Android/data/au.ufeff.rhythmgame/'
# '/sdcard/Android/data/au.ufeff.rhythmgame/'
var user_data_dir := OS.get_user_data_dir().rstrip('/')+'/' if OS.get_name() != 'Android' else ANDROID_USERDIR
var SETTINGS_FILENAME = user_data_dir + 'settings.cfg'
var config : ConfigFile
var subsampling: Vector2 setget SSXY_set, SSXY_get var subsampling: Vector2 setget SSXY_set, SSXY_get
var subsampling_x: float setget SSX_set, SSX_get var subsampling_x: float setget SSX_set, SSX_get
var subsampling_y: float setget SSY_set, SSY_get var subsampling_y: float setget SSY_set, SSY_get
@ -26,17 +35,32 @@ func SSY_get() -> float:
func SSXY_get() -> Vector2: func SSXY_get() -> Vector2:
return Vector2(self.subsampling_x, self.subsampling_y) return Vector2(self.subsampling_x, self.subsampling_y)
func get_library_paths() -> PoolStringArray:
var paths = [user_data_dir]
const SETTINGS_FILENAME = 'user://settings.conf' var additional_paths = config.get_value('libraries', 'additional_paths', [])
# Ensure paths are valid and have trailing slash
for p in additional_paths:
if p is String:
paths.append(p.rstrip('/')+'/')
return PoolStringArray(paths)
func load_settings(): func load_settings():
var config := ConfigFile.new() config = ConfigFile.new()
config.set_value('libraries', 'additional_paths', [])
match config.load(SETTINGS_FILENAME): match config.load(SETTINGS_FILENAME):
OK: OK:
pass SSXY_set(Vector2(
config.get_value('rendering', 'subsampling_x', subsampling_x),
config.get_value('rendering', 'subsampling_y', subsampling_y)
))
emit_signal('config_loaded')
ERR_FILE_NOT_FOUND: ERR_FILE_NOT_FOUND:
save_settings() save_settings()
print('Loaded settings from ' + SETTINGS_FILENAME)
func save_settings(): func save_settings():
pass config.save(SETTINGS_FILENAME)
print('Saved settings to ' + SETTINGS_FILENAME)
func _ready():
load_settings()