extends Node # Localization configuration on linux # $HOME/.local/share/godot/app_userdata/Khanat var font_size = 14 var SettingsFile = "user://settings.cfg" var screen_number = 0 var screen_orientation = 0 var window_maximized:bool = false var video_default:bool = true var window_fullscreen:bool = true var window_borderless:bool = false var window_resizable:bool = true var window_size_x = 0 var window_size_y = 0 var window_always_on_top:bool = true var debug:bool = true var sound_lvl_music = 50 var sound_lvl_effect = 50 var sound_lvl_global = 50 var mute:bool = false var playermusic:bool = false var queuemusic = [] onready var rand = RandomNumberGenerator.new() func msg_debug(text): if debug: var frame = get_stack()[1] print("DEBUG [%s:%d] %s" % [frame.source, frame.line, text] ) func msg_info(text): var frame = get_stack()[1] print("INFO [%s:%d] %s" % [frame.source, frame.line, text] ) func msg_error(text): var frame = get_stack()[1] print("ERROR [%s:%d] %s" % [frame.source, frame.line, text] ) # Called when the node enters the scene tree for the first time. func _ready(): load_config() rand.randomize() msg_debug("load end") func set_playermusic(state): Config.msg_debug("player music:" + str(state)) self.playermusic = state #MusicManager.load_playlist() #load_playlist func get_playermusic(): return self.playermusic func set_window_fullscreen(value: bool): #if ProjectSettings.has_setting( "display/window/size/fullscreen" ): # ProjectSettings.set_setting("display/window/size/fullscreen", value) window_fullscreen = value if video_default == false: OS.window_fullscreen = window_fullscreen func set_window_borderless(value: bool): #if ProjectSettings.has_setting( "display/window/size/borderless" ): # ProjectSettings.set_setting("display/window/size/borderless", value) window_borderless = value if video_default == false: OS.window_borderless = window_borderless func set_window_resizable(value: bool): #if ProjectSettings.has_setting( "display/window/size/resizable" ): # ProjectSettings.set_setting("display/window/size/resizable", value) window_resizable = value if video_default == false: OS.window_resizable = window_resizable func set_window_width(value: int): #if ProjectSettings.has_setting( "display/window/size/width" ): # ProjectSettings.set_setting("display/window/size/width", value) window_size_x = value if video_default == false: OS.window_size.x = window_size_x #OS.window_fullscreen = ProjectSettings.get_setting("display/window/size/width") func set_window_height(value: int): #if ProjectSettings.has_setting( "display/window/size/height" ): # ProjectSettings.set_setting("display/window/size/height", value) window_size_y = value if video_default == false: OS.window_size.y = window_size_y #OS.window_fullscreen = ProjectSettings.get_setting("display/window/size/height") func set_font_size(value: int): font_size = value if video_default == false: pass func set_video_default(value): video_default = value func set_window_always_on_top(value: bool): window_always_on_top = value if video_default == false: OS.set_window_always_on_top(window_always_on_top) func set_current_screen(value: int): screen_number = int(value) if video_default == false: OS.current_screen = screen_number func set_screen_orientation(value: int): if video_default == false: screen_orientation = int(value) OS.set_screen_orientation(screen_orientation) func set_window_maximized(value: bool): if value: window_maximized = true else: window_maximized = false if not video_default: OS.set_window_maximized(window_maximized) func enable_window_default(): # display/window/handheld/orientation if ProjectSettings.has_setting( "display/window/handheld/orientation" ): var num = 0 var default_orientation = ProjectSettings.get_setting("display/window/handheld/orientation") match default_orientation: "landscape": num = 0 "portrait": num = 1 "reverse_landscape": num = 2 "reverse_portrait": num = 3 "sensor_landscape": num = 4 "sensor_portrait": num = 5 "sensor": num = 6 _: num = 6 OS.set_screen_orientation(num) OS.set_window_maximized(window_maximized) OS.current_screen = screen_number # display/window/size/always_on_top if ProjectSettings.has_setting( "display/window/size/always_on_top" ): OS.set_window_always_on_top( ProjectSettings.get_setting( "display/window/size/always_on_top" ) ) #OS.window_size.x = window_size_x #OS.window_size.y = window_size_y if ProjectSettings.has_setting( "display/window/size/fullscreen" ): OS.window_fullscreen = ProjectSettings.get_setting( "display/window/size/fullscreen" ) if ProjectSettings.has_setting( "display/window/size/borderless" ): OS.window_borderless = ProjectSettings.get_setting( "display/window/size/borderless" ) if ProjectSettings.has_setting( "display/window/size/resizable" ): OS.window_resizable = ProjectSettings.get_setting( "display/window/size/resizable" ) func disable_window_default(): OS.set_screen_orientation(screen_orientation) OS.set_window_maximized(window_maximized) OS.current_screen = screen_number OS.set_window_always_on_top(window_always_on_top) #OS.window_size.x = window_size_x #OS.window_size.y = window_size_y OS.window_fullscreen = window_fullscreen OS.window_borderless = window_borderless OS.window_resizable = window_resizable func set_sound_mute(value: bool): Config.msg_debug("mute:" + str(value)) mute = value func save_config(): var config_file = ConfigFile.new() config_file.set_value( "theme", "font_size", 14 ) config_file.set_value( "display", "default", video_default ) config_file.set_value( "display", "fullscreen", OS.window_fullscreen ) config_file.set_value( "display", "borderless", OS.window_borderless ) config_file.set_value( "display", "resizable", OS.window_resizable ) #config_file.set_value( "display", "width", int( OS.window_size.x ) ) #config_file.set_value( "display", "height", int( OS.window_size.y ) ) config_file.set_value( "display", "window_always_on_top", OS.keep_screen_on ) config_file.set_value( "display", "screen_orientation", OS.get_screen_orientation() ) config_file.set_value( "display", "current_screen", screen_number ) config_file.set_value( "display", "window_maximized", window_maximized ) config_file.set_value( "sound", "global_level", sound_lvl_global ) config_file.set_value( "sound", "music_level", sound_lvl_music ) config_file.set_value( "sound", "effect_level", sound_lvl_effect ) config_file.set_value( "sound", "mute", mute ) config_file.set_value( "sound", "playermusic", playermusic ) var posmusic = 0 for child in queuemusic: #Config.msg_debug("" + child ) config_file.set_value( "playermusic", str(posmusic), child ) posmusic += 1 config_file.save( SettingsFile ) #print("[res://ressources/scripts/config/config.gd] save_config") func load_config(): var config_file = ConfigFile.new() var err = config_file.load( SettingsFile ) if err == ERR_CANT_OPEN or err == ERR_FILE_NOT_FOUND: # On suppose que le fichier n'existe pas encore, donc on le crée. #print("[res://ressources/scripts/config/config.gd] Error to read, recreate config") save_config() elif not err == OK: print("[res://ressources/scripts/config/config.gd] Error code when loading user://settings.cfg file: ", err) font_size = config_file.get_value("theme", "font_size", false) video_default = config_file.get_value("display", "default", true) set_window_fullscreen(config_file.get_value("display", "fullscreen", true)) set_window_borderless(config_file.get_value("display", "borderless", false)) set_window_resizable(config_file.get_value("display", "resizable", true)) set_window_always_on_top(config_file.get_value("display", "window_always_on_top", true)) set_screen_orientation(config_file.get_value("display", "screen_orientation", 0)) set_current_screen(config_file.get_value("display", "current_screen", 0)) #set_window_width(config_file.get_value("display", "width", OS.window_size.x)) #set_window_height(config_file.get_value("display", "height", OS.window_size.y)) set_window_maximized(config_file.get_value("display", "window_maximized", OS.window_maximized)) sound_lvl_global = config_file.get_value("sound", "global_level", 100) sound_lvl_music = config_file.get_value("sound", "music_level", 100) sound_lvl_effect = config_file.get_value("sound", "effect_level", 100) mute = config_file.get_value("sound", "mute", false) playermusic = config_file.get_value("sound", "playermusic", false) for key in config_file.get_section_keys( "playermusic" ): var file = config_file.get_value( "playermusic", key, "" ) # Config.msg_debug( "playermusic:" + key + " " + str(file) ) queuemusic.append(file)