diff options
author | rom <romangraef@gmail.com> | 2021-04-25 18:59:28 +0200 |
---|---|---|
committer | rom <romangraef@gmail.com> | 2021-04-25 18:59:38 +0200 |
commit | 3e8e361c8c6b9a7d02361c2f72a20e5e41873052 (patch) | |
tree | 3b6dda00cf4566ffd30a8a6933e4d7c0f93da9e1 | |
parent | 86c8cf34d53290df113a97c051acade184e4f2f3 (diff) | |
download | ldjam48-3e8e361c8c6b9a7d02361c2f72a20e5e41873052.tar.gz ldjam48-3e8e361c8c6b9a7d02361c2f72a20e5e41873052.tar.bz2 ldjam48-3e8e361c8c6b9a7d02361c2f72a20e5e41873052.zip |
settings
-rw-r--r-- | components/Settings.gd | 37 | ||||
-rw-r--r-- | project.godot | 4 | ||||
-rw-r--r-- | scenes/levels/base_level.gd | 12 |
3 files changed, 52 insertions, 1 deletions
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.") |