From 3e8e361c8c6b9a7d02361c2f72a20e5e41873052 Mon Sep 17 00:00:00 2001 From: rom Date: Sun, 25 Apr 2021 18:59:28 +0200 Subject: settings --- components/Settings.gd | 37 +++++++++++++++++++++++++++++++++++++ project.godot | 4 ++++ scenes/levels/base_level.gd | 12 +++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 components/Settings.gd diff --git a/components/Settings.gd b/components/Settings.gd new file mode 100644 index 0000000..f6f0b41 --- /dev/null +++ b/components/Settings.gd @@ -0,0 +1,37 @@ +extends Node + +var sound_level : int = 100 + +########## +# LOADER # +########## + +onready var _file = File.new() +const _SETTINGS_PATH = "user://settings.json" + +func _save_data(): + return { + 'sound_level': sound_level, + } + +func _load_data(json): + sound_level = json['sound_level'] + +func _load(): + if _file.file_exists(_SETTINGS_PATH): + return + _file.open(_SETTINGS_PATH, File.READ) + var text = _file.get_as_text() + var json = parse_json(text) + _load_data(json) + _file.close() + +func save(): + var json = _save_data() + var text = to_json(json) + _file.open(_SETTINGS_PATH, File.WRITE) + _file.store_string(text) + _file.close() + + + diff --git a/project.godot b/project.godot index c22efe0..851e9f0 100644 --- a/project.godot +++ b/project.godot @@ -54,6 +54,10 @@ config/name="Deeper but Lighter" run/main_scene="res://scenes/menu.tscn" config/icon="res://icon.png" +[autoload] + +Settings="*res://components/Settings.gd" + [display] window/size/width=1280 diff --git a/scenes/levels/base_level.gd b/scenes/levels/base_level.gd index 9a2a618..d3a17a6 100644 --- a/scenes/levels/base_level.gd +++ b/scenes/levels/base_level.gd @@ -39,7 +39,7 @@ func _add_hooks(): _loaded_level.connect("lost_heart", self, "_on_Level_lost_heart") func _on_Level_level_finished(): - pass # TODO + _load_next_level() func _on_Level_lost_heart(): _health -= 1 @@ -47,6 +47,16 @@ func _on_Level_lost_heart(): pass # TODO: lose scenario _health_bar.set_health(_health) +func _load_next_level(): + _unload_current_level() + _current_level += 1 + if _current_level > _levels.size(): + get_tree().change_scene("res://scenes/menu.tscn") + _load_current_level() + +func _unload_current_level(): + pass + func _load_current_level(): if _loaded_level != null: push_error("Tried to load level, while another level was already loaded.") -- cgit