Browse Source

feat: add a Demo provider, useful for demos

master
Dominique Merle 2 years ago
parent
commit
9db0ec27ee
  1. 17
      addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd
  2. 38
      addons/majority_judgment/providers/MajorityJudgmentDemoProvider.gd
  3. 4
      core/Config.gd
  4. 12
      gui/forms/SettingsForm.gd
  5. 43
      gui/forms/SettingsForm.tscn

17
addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd

@ -15,7 +15,8 @@ export(int) var candidates_labels_width := 200 # pixels
onready var ProfilesContainer = find_node("ProfilesContainer", true)
var provider:MajorityJudgmentAbstractJudgmentsProvider
var providers:Array # of MajorityJudgmentAbstractJudgmentsProvider
#var provider:MajorityJudgmentAbstractJudgmentsProvider
func _input(_event):
@ -40,9 +41,13 @@ func set_poll(__poll:MajorityJudgmentPoll):
craft_nodes()
update_nodes()
self.providers = App.get_providers()
for provider in self.providers:
start_provider(provider)
# var provider = MajorityJudgmentDemoProvider.new()
var provider = MajorityJudgmentTwitchChatProvider.new()
start_provider(provider)
# var provider = MajorityJudgmentTwitchChatProvider.new()
# start_provider(provider)
var candidates_lines_nodes := Array()
@ -163,12 +168,12 @@ func create_merit_profile_scene(gradation_size:int):
func start_provider(__provider):
self.provider = __provider
var connected = self.provider.connect(
# self.provider = __provider
var connected = __provider.connect(
"judgment_emitted",
self, "__on_judgment_emitted"
)
self.provider.start_providing()
__provider.start_providing()
var known_participants := Dictionary() # id => Participant

38
addons/majority_judgment/providers/MajorityJudgmentDemoProvider.gd

@ -2,19 +2,29 @@ extends MajorityJudgmentChatCommandJudgmentsProvider
class_name MajorityJudgmentDemoProvider
# Dummy provider, to test the app out.
func start_providing():
yield(App.timer(1), "timeout")
process_chat_command("Stup", "A0B1C3")
yield(App.timer(1), "timeout")
process_chat_command("Flip", "A0B2C1")
yield(App.timer(1), "timeout")
process_chat_command("Flip", "A1")
yield(App.timer(1), "timeout")
process_chat_command("Clap", "A3B4")
yield(App.timer(1), "timeout")
process_chat_command("Clap", "C5B3")
yield(App.timer(2), "timeout")
process_chat_command("Neo", "B5")
yield(App.timer(1), "timeout")
process_chat_command("April", "A4")
var commands = [
["Stup", "A0B1C3"],
["Flip", "A0B2C1"],
["Flip", "A1"],
["Sylvain", "A3B4"],
["Sylvain", "C5B3"],
["Julia", "A0"],
["Julia", "B1"],
["Julia", "C2"],
["Elliot", "A0B0C5"],
["Sophie", "C0"],
["Sophie", "C0A2B5"],
["Yohan", "B1A2C3"],
["Teddy", "A5"],
["Miu", "A4B2C1"],
# … add more
]
for command in commands:
yield(App.timer(1+(randi()%3)), "timeout")
process_chat_command(command[0], command[1])

4
core/Config.gd

@ -14,10 +14,10 @@ var __config : Dictionary
func get_parameter(parameter_key:String, default=null):
hydrate_lazily()
if self.__config.has(parameter_key):
# print("[Config] Reading parameter `%s' from Config." % parameter_key)
print("[Config] Reading parameter `%s' from Config." % parameter_key)
return self.__config[parameter_key]
else:
# print("[Config] Using default value for parameter `%s'." % parameter_key)
print("[Config] Using default value for parameter `%s'." % parameter_key)
return default

12
gui/forms/SettingsForm.gd

@ -2,6 +2,7 @@ extends Control
onready var TwitchCheckButton = find_node("TwitchCheckButton", true)
onready var DemoProviderCheckButton = find_node("DemoProviderCheckButton", true)
var initializing = true
func _ready():
@ -9,6 +10,10 @@ func _ready():
"provider_MajorityJudgmentTwitchChatProvider_enabled",
false
)
DemoProviderCheckButton.pressed = Config.get_parameter(
"provider_MajorityJudgmentDemoProvider_enabled",
false
)
initializing = false
@ -27,3 +32,10 @@ func _on_TwitchCheckButton_toggled(button_pressed):
)
if button_pressed and not initializing:
find_node('NoTwitchSettingsPopup', true).show_if_should()
func _on_DemoProviderCheckButton_toggled(button_pressed):
Config.set_parameter(
"provider_MajorityJudgmentDemoProvider_enabled",
button_pressed
)

43
gui/forms/SettingsForm.tscn

@ -17,20 +17,22 @@ __meta__ = {
[node name="CenterContainer" type="CenterContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 0.943848
margin_right = 0.943848
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
margin_left = 337.0
margin_top = 188.0
margin_top = 173.0
margin_right = 687.0
margin_bottom = 412.0
margin_bottom = 427.0
[node name="TabContainer" type="TabContainer" parent="CenterContainer/VBoxContainer"]
margin_right = 350.0
margin_bottom = 200.0
rect_min_size = Vector2( 350, 200 )
margin_bottom = 230.0
rect_min_size = Vector2( 350, 230 )
[node name="Providers" type="Control" parent="CenterContainer/VBoxContainer/TabContainer"]
anchor_right = 1.0
@ -55,7 +57,7 @@ bbcode_enabled = true
bbcode_text = "Your community votes by sending commands such as \"B2\" in the chat. You must enable at least one provider or your polls will have no participants."
text = "Your community votes by sending commands such as \"B2\" in the chat. You must enable at least one provider or your polls will have no participants."
[node name="TwitchContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer"]
[node name="DemoContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer"]
margin_top = 54.0
margin_right = 342.0
margin_bottom = 94.0
@ -63,6 +65,27 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="DemoProviderCheckButton" type="CheckButton" parent="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer/DemoContainer"]
margin_right = 176.0
margin_bottom = 40.0
text = "Demo Provider"
[node name="Label" type="Label" parent="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer/DemoContainer"]
margin_left = 180.0
margin_top = 4.0
margin_right = 330.0
margin_bottom = 35.0
text = "Enable this to simulate
votes for a quick demo."
[node name="TwitchContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer"]
margin_top = 98.0
margin_right = 342.0
margin_bottom = 138.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TwitchCheckButton" type="CheckButton" parent="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer/TwitchContainer"]
margin_right = 229.0
margin_bottom = 40.0
@ -75,9 +98,9 @@ margin_bottom = 40.0
text = "Configure"
[node name="OtherContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer"]
margin_top = 98.0
margin_top = 142.0
margin_right = 342.0
margin_bottom = 138.0
margin_bottom = 182.0
__meta__ = {
"_edit_use_anchors_": false
}
@ -115,9 +138,9 @@ margin_bottom = 240.0
rect_min_size = Vector2( 350, 200 )
[node name="HBoxContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer"]
margin_top = 204.0
margin_top = 234.0
margin_right = 350.0
margin_bottom = 224.0
margin_bottom = 254.0
[node name="VSeparator" type="VSeparator" parent="CenterContainer/VBoxContainer/HBoxContainer"]
self_modulate = Color( 1, 1, 1, 0 )
@ -132,6 +155,8 @@ margin_bottom = 20.0
text = "DONE"
[node name="NoTwitchSettingsPopup" parent="." instance=ExtResource( 3 )]
visible = false
[connection signal="toggled" from="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer/DemoContainer/DemoProviderCheckButton" to="." method="_on_DemoProviderCheckButton_toggled"]
[connection signal="toggled" from="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer/TwitchContainer/TwitchCheckButton" to="." method="_on_TwitchCheckButton_toggled"]
[connection signal="pressed" from="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer/TwitchContainer/TwitchConfigureButton" to="." method="_on_TwitchConfigureButton_pressed"]
[connection signal="pressed" from="CenterContainer/VBoxContainer/HBoxContainer/DoneButton" to="." method="_on_DoneButton_pressed"]
Loading…
Cancel
Save