From 5b12cd85e28c88dd0dceeeda71ea1ecc08193101 Mon Sep 17 00:00:00 2001 From: domi41 Date: Wed, 12 Aug 2020 17:13:49 +0200 Subject: [PATCH] feat: store configuration, and add more hints --- core/Config.gd | 52 +++++++++++++++++++ gui/forms/SettingsForm.gd | 12 +++-- gui/forms/twitch_config/TwitchAuthConfig.tscn | 6 ++- project.godot | 2 + 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 core/Config.gd diff --git a/core/Config.gd b/core/Config.gd new file mode 100644 index 0000000..290b00f --- /dev/null +++ b/core/Config.gd @@ -0,0 +1,52 @@ +extends Node + + +# Meant to be used as a singleton. +# Don't store Objects in here for now. + + +export(String) var file_path := "user://config.ini" + + +var __config : Dictionary + + +func get_parameter(parameter_key:String, default=null): + hydrate_lazily() + if parameter_key in self.__config: + return self.__config[parameter_key] + else: +# printerr("[Config] Unknown parameter `%s'." % parameter_key) +# assert(false) + return default + + +func set_parameter(parameter_key:String, parameter_value) -> void: + self.__config[parameter_key] = parameter_value + write_to_file(self.__config) + + +func hydrate_lazily() -> void: + if null == self.__config: + self.__config = load_from_file() + + +func write_to_file(config_to_write:Dictionary) -> void: + var file = File.new() + var opened = file.open(self.file_path, File.WRITE) + if OK != opened: + printerr("[Config] Cannot write to file `%s'." % self.file_path) + return + file.store_var(config_to_write) + file.close() + + +func load_from_file() -> Dictionary: + var file = File.new() + var opened = file.open(self.file_path, File.READ) + if OK != opened: + printerr("[Config] Cannot read from file `%s'." % self.file_path) + return {} # null + var data = file.get_var() + file.close() + return data diff --git a/gui/forms/SettingsForm.gd b/gui/forms/SettingsForm.gd index 8f5e28a..04f49cd 100644 --- a/gui/forms/SettingsForm.gd +++ b/gui/forms/SettingsForm.gd @@ -1,6 +1,12 @@ extends Control +onready var TwitchCheckButton = find_node("TwitchCheckButton", true) + + +func _ready(): + TwitchCheckButton.pressed = Config.get_parameter("twitch_provider_enabled", false) + func _on_DoneButton_pressed(): App.go_to_main_menu() @@ -10,7 +16,7 @@ func _on_TwitchConfigureButton_pressed(): App.go_to_twitch_settings() - func _on_TwitchCheckButton_toggled(button_pressed): - if button_pressed: - App.go_to_twitch_settings() + Config.set_parameter("twitch_provider_enabled", button_pressed) +# if button_pressed: +# App.go_to_twitch_settings() diff --git a/gui/forms/twitch_config/TwitchAuthConfig.tscn b/gui/forms/twitch_config/TwitchAuthConfig.tscn index cb0dfce..32e2a72 100644 --- a/gui/forms/twitch_config/TwitchAuthConfig.tscn +++ b/gui/forms/twitch_config/TwitchAuthConfig.tscn @@ -40,6 +40,7 @@ text = "TWITCH CHAT CONFIGURATION" margin_top = 18.0 margin_right = 203.0 margin_bottom = 42.0 +hint_tooltip = "May be whatever you want." size_flags_horizontal = 3 [node name="NickLabel" type="Label" parent="CenterContainer/VBoxContainer/NickContainer"] @@ -59,6 +60,7 @@ size_flags_horizontal = 3 margin_top = 46.0 margin_right = 203.0 margin_bottom = 70.0 +hint_tooltip = "Your lowercase twitch username, usually. " size_flags_horizontal = 3 [node name="ChannelLabel" type="Label" parent="CenterContainer/VBoxContainer/ChannelContainer"] @@ -71,13 +73,14 @@ text = "Channel" margin_left = 55.0 margin_right = 203.0 margin_bottom = 24.0 -hint_tooltip = "Your twitch username, usually. Usually lowercase." +hint_tooltip = "Your lowercase twitch username, usually. " size_flags_horizontal = 3 [node name="ClientIdContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer"] margin_top = 74.0 margin_right = 203.0 margin_bottom = 98.0 +hint_tooltip = "May be generated here : https://dev.twitch.tv/dashboard/apps/create" size_flags_horizontal = 3 [node name="ClientIdLabel" type="Label" parent="CenterContainer/VBoxContainer/ClientIdContainer"] @@ -103,6 +106,7 @@ text = "?" margin_top = 102.0 margin_right = 203.0 margin_bottom = 126.0 +hint_tooltip = "May be generated here : https://twitchapps.com/tmi/" size_flags_horizontal = 3 [node name="OAuthLabel" type="Label" parent="CenterContainer/VBoxContainer/OAuthContainer"] diff --git a/project.godot b/project.godot index 224be3b..a2912fa 100644 --- a/project.godot +++ b/project.godot @@ -249,12 +249,14 @@ Display=8 [application] config/name="Majority Judgment Polling for Streamers" +config/description="An application to hold majority judgment polls with your friends and communities." run/main_scene="res://gui/MainMenu.tscn" config/icon="res://icon.png" [autoload] App="*res://core/App.gd" +Config="*res://core/Config.gd" [editor_plugins]