Browse Source

feat: store configuration, and add more hints

master
Dominique Merle 2 years ago
parent
commit
5b12cd85e2
  1. 52
      core/Config.gd
  2. 12
      gui/forms/SettingsForm.gd
  3. 6
      gui/forms/twitch_config/TwitchAuthConfig.tscn
  4. 2
      project.godot

52
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

12
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()

6
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"]

2
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]

Loading…
Cancel
Save