2021-01-14 20:35:30 +10:30
# A slightly redundant proxy to ProjectSettings
# This is mostly used so that signals can be used to respond to settings changes
extends Node
2024-05-29 22:11:01 +09:30
signal config_loaded
2021-01-14 20:35:30 +10:30
signal subsampling_changed ( xy )
2024-05-29 22:11:01 +09:30
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
2021-01-14 20:35:30 +10:30
var subsampling : Vector2 setget SSXY_set , SSXY_get
var subsampling_x : float setget SSX_set , SSX_get
var subsampling_y : float setget SSY_set , SSY_get
func SSX_set ( x : float ) :
ProjectSettings . set_setting ( ' rendering/quality/subsampling/x ' , x )
emit_signal ( ' subsampling_changed ' , self . subsampling )
func SSY_set ( y : float ) :
ProjectSettings . set_setting ( ' rendering/quality/subsampling/y ' , y )
emit_signal ( ' subsampling_changed ' , self . subsampling )
func SSXY_set ( xy : Vector2 ) :
ProjectSettings . set_setting ( ' rendering/quality/subsampling/x ' , xy . x )
ProjectSettings . set_setting ( ' rendering/quality/subsampling/y ' , xy . y )
emit_signal ( ' subsampling_changed ' , self . subsampling )
func SSX_get ( ) - > float :
return ProjectSettings . get_setting ( ' rendering/quality/subsampling/x ' )
func SSY_get ( ) - > float :
return ProjectSettings . get_setting ( ' rendering/quality/subsampling/y ' )
func SSXY_get ( ) - > Vector2 :
return Vector2 ( self . subsampling_x , self . subsampling_y )
2021-02-07 00:17:27 +10:30
2024-05-29 22:11:01 +09:30
func get_library_paths ( ) - > PoolStringArray :
var paths = [ user_data_dir ]
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 )
2021-02-07 00:17:27 +10:30
func load_settings ( ) :
2024-05-29 22:11:01 +09:30
config = ConfigFile . new ( )
config . set_value ( ' libraries ' , ' additional_paths ' , [ ] )
2021-02-07 00:17:27 +10:30
match config . load ( SETTINGS_FILENAME ) :
OK :
2024-05-29 22:11:01 +09:30
SSXY_set ( Vector2 (
config . get_value ( ' rendering ' , ' subsampling_x ' , subsampling_x ) ,
config . get_value ( ' rendering ' , ' subsampling_y ' , subsampling_y )
) )
emit_signal ( ' config_loaded ' )
2021-02-07 00:17:27 +10:30
ERR_FILE_NOT_FOUND :
save_settings ( )
2024-05-29 22:11:01 +09:30
print ( ' Loaded settings from ' + SETTINGS_FILENAME )
2021-02-07 00:17:27 +10:30
func save_settings ( ) :
2024-05-29 22:11:01 +09:30
config . save ( SETTINGS_FILENAME )
print ( ' Saved settings to ' + SETTINGS_FILENAME )
func _ready ( ) :
load_settings ( )