-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
92 additions
and
226 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class_name AudioSettings | ||
extends Control | ||
|
||
signal loaded() | ||
|
||
const AUDIO_SECTION = "audio" | ||
|
||
var _logger = Logger.new("AudioSettings") | ||
|
||
func load_settings(config: ConfigFile): | ||
for i in range(0, AudioServer.bus_count): | ||
var name = AudioServer.get_bus_name(i) | ||
var value = config.get_value(AUDIO_SECTION, name) | ||
if value != null: | ||
var split = str(value).split(";") | ||
_logger.debug("Loading audio setting for %s: %s" % [name, value]) | ||
AudioServer.set_bus_volume_db(i, float(split[0])) | ||
AudioServer.set_bus_mute(i, split.size() > 1 and split[1] == "true") | ||
|
||
loaded.emit() | ||
|
||
func save_settings(config: ConfigFile): | ||
for i in range(0, AudioServer.bus_count): | ||
var name = AudioServer.get_bus_name(i) | ||
var value = AudioServer.get_bus_volume_db(i) | ||
var muted = AudioServer.is_bus_mute(i) | ||
_logger.debug("Saving audio setting for %s: %s, %s" % [name, value, muted]) | ||
config.set_value(AUDIO_SECTION, name, "%s;%s" % [value, muted]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class_name Settings | ||
extends Control | ||
|
||
const CONFIG_FILE = "user://settings.cfg" | ||
|
||
@onready var _audio := $Audio | ||
|
||
var _logger = Logger.new("Settings") | ||
var _config = ConfigFile.new() | ||
|
||
func _ready(): | ||
_load_settings() | ||
|
||
func _load_settings(): | ||
var error = _config.load(CONFIG_FILE) | ||
if error != OK: | ||
_logger.error("Failed to load settings: %s" % error) | ||
|
||
_logger.debug("Loading settings") | ||
_audio.load_settings(_config) | ||
|
||
func _exit_tree(): | ||
_save_config() | ||
|
||
func _save_config(): | ||
if Env.is_web(): return | ||
|
||
_logger.debug("Saving settings") | ||
_audio.save_settings(_config) | ||
_config.save(CONFIG_FILE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters