-
Notifications
You must be signed in to change notification settings - Fork 0
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
11 changed files
with
602 additions
and
0 deletions.
There are no files selected for viewing
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,142 @@ | ||
extends Node | ||
|
||
# ============================================================================== | ||
|
||
|
||
signal setting_created(_name, _setting) | ||
signal setting_removed(_name, _setting) | ||
|
||
signal settings_pre_saved(_resource) | ||
signal settings_post_saved(_resource) | ||
signal settings_pre_loaded(_resource) | ||
signal settings_post_loaded(_resource) | ||
|
||
|
||
# ============================================================================== | ||
|
||
|
||
var settings: Dictionary = {} | ||
|
||
|
||
# ============================================================================== | ||
|
||
|
||
func add_setting(key: String, value = null) -> Setting: | ||
|
||
if (settings.has(key) == true): | ||
push_warning("Setting \"{name}\" already exist.".format( | ||
{ "name":key } | ||
)) | ||
return null | ||
|
||
var setting: = Setting.new() | ||
setting.set_default(value) | ||
setting.set_value(value) | ||
|
||
settings[key] = setting | ||
emit_signal("setting_created",key,setting) | ||
return setting | ||
|
||
|
||
func get_setting(key: String) -> Setting: | ||
var c: Setting = settings.get(key,null) | ||
|
||
if (is_instance_valid(c) == false): | ||
return null | ||
|
||
return c | ||
|
||
|
||
func remove_setting(key: String) -> void: | ||
var c: Setting = settings.get(key,null) | ||
|
||
if ((is_instance_valid(c) == false) or (settings.erase(key) == false)): | ||
push_warning("Setting \"{name}\" does not exist.".format( | ||
{ "name":key } | ||
)) | ||
return | ||
|
||
emit_signal("setting_removed",key,c) | ||
|
||
|
||
# ============================================================================== | ||
|
||
|
||
func get_setting_or_add(key: String, value = null) -> Setting: | ||
|
||
if (settings.has(key) == true): | ||
return settings.get(key, null) | ||
|
||
return add_setting(key, value) | ||
|
||
|
||
# ============================================================================== | ||
|
||
|
||
func open_settings(path: String, create_new: bool = true) -> bool: | ||
|
||
if (ResourceLoader.exists(path) == false): | ||
push_error("Setting resource \"{path}\" does not exist.".format( | ||
{ "path":path } | ||
)) | ||
return false | ||
|
||
var resource: = ResourceLoader.load(path) as SettingsResource | ||
|
||
if (is_instance_valid(resource) == false): | ||
push_error("Setting resource \"path}\" failed to load.".format( | ||
{ "path":path } | ||
)) | ||
return false | ||
|
||
emit_signal("settings_pre_loaded", resource) | ||
|
||
for key in resource.settings: | ||
|
||
if (settings.has(key) == true): | ||
get_setting(key).set_value(resource.settings[key]) | ||
|
||
elif (create_new == true): | ||
add_setting(key, resource.settings[key]) | ||
|
||
emit_signal("settings_post_loaded", resource) | ||
|
||
return true | ||
|
||
|
||
func save_settings(path: String, override: bool = false) -> bool: | ||
var save: = Dictionary() | ||
var resource: SettingsResource = null | ||
|
||
if (override == false): | ||
|
||
if (ResourceLoader.exists(path) == true): | ||
resource = ResourceLoader.load(path) | ||
|
||
if (is_instance_valid(resource) == true): | ||
save = resource.settings | ||
|
||
for key in settings: | ||
var s: Setting = settings[key] | ||
|
||
if (s.is_archivable() == true): | ||
save[key] = s.get_value() | ||
|
||
if (is_instance_valid(resource) == false): | ||
resource = SettingsResource.new() | ||
|
||
resource.settings = save | ||
emit_signal("settings_pre_saved", resource) | ||
|
||
if (ResourceSaver.save(path, resource) != OK): | ||
push_error("Setting resource \"{path}\" failed to save.".format( | ||
{ "path":path } | ||
)) | ||
return false | ||
|
||
emit_signal("settings_post_saved", resource) | ||
|
||
return true | ||
|
||
|
||
# ============================================================================== |
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,6 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res:https://addons/SettingsCore/SettingsServer.gd" type="Script" id=1] | ||
|
||
[node name="SettingsServer" type="Node"] | ||
script = ExtResource( 1 ) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,35 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res:https://.import/icon.png-a8deda2e4d6ba83a13280b7f7cba25ee.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res:https://addons/SettingsCore/icon.png" | ||
dest_files=[ "res:https://.import/icon.png-a8deda2e4d6ba83a13280b7f7cba25ee.stex" ] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/lossy_quality=0.7 | ||
compress/hdr_mode=0 | ||
compress/bptc_ldr=0 | ||
compress/normal_map=0 | ||
flags/repeat=0 | ||
flags/filter=true | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
flags/srgb=2 | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/HDR_as_SRGB=false | ||
process/invert_color=false | ||
process/normal_map_invert_y=false | ||
stream=false | ||
size_limit=0 | ||
detect_3d=true | ||
svg/scale=1.0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,35 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res:https://.import/icon.svg-baef823118583d4ef8f2b0dc96f9da5d.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res:https://addons/SettingsCore/icon.svg" | ||
dest_files=[ "res:https://.import/icon.svg-baef823118583d4ef8f2b0dc96f9da5d.stex" ] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/lossy_quality=0.7 | ||
compress/hdr_mode=0 | ||
compress/bptc_ldr=0 | ||
compress/normal_map=0 | ||
flags/repeat=0 | ||
flags/filter=true | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
flags/srgb=2 | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/HDR_as_SRGB=false | ||
process/invert_color=false | ||
process/normal_map_invert_y=false | ||
stream=false | ||
size_limit=0 | ||
detect_3d=true | ||
svg/scale=1.0 |
Oops, something went wrong.