diff --git a/addons/majority_judgment/MajorityJudgmentPoll.gd b/addons/majority_judgment/MajorityJudgmentPoll.gd index 5db5766..318b9a5 100644 --- a/addons/majority_judgment/MajorityJudgmentPoll.gd +++ b/addons/majority_judgment/MajorityJudgmentPoll.gd @@ -107,6 +107,7 @@ func add_judgment(judgment:MajorityJudgmentJudgment) -> void: (existing_judgment.candidate == judgment.candidate) ): judgments[i] = judgment + return judgments.append(judgment) diff --git a/addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd b/addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd index 4367bbf..a2744da 100644 --- a/addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd +++ b/addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd @@ -20,57 +20,60 @@ func set_poll(__poll:MajorityJudgmentPoll): craft_nodes() update_nodes() - yield(get_tree().create_timer(3), "timeout") + var provider = MajorityJudgmentDemoProvider.new() + start_provider(provider) - var j = MajorityJudgmentJudgment.new() - j.set_participant(MajorityJudgmentParticipant.make("Plume")) - j.set_grade(poll.grading.grades[2]) - j.set_candidate(poll.candidates[0]) - poll.add_judgment(j) - - var sylvain = MajorityJudgmentParticipant.make("Sylvain") - j = MajorityJudgmentJudgment.new() - j.set_participant(sylvain) - j.set_grade(poll.grading.grades[3]) - j.set_candidate(poll.candidates[0]) - poll.add_judgment(j) - j = MajorityJudgmentJudgment.new() - j.set_participant(sylvain) - j.set_grade(poll.grading.grades[3]) - j.set_candidate(poll.candidates[1]) - poll.add_judgment(j) - j = MajorityJudgmentJudgment.new() - j.set_participant(sylvain) - j.set_grade(poll.grading.grades[4]) - j.set_candidate(poll.candidates[2]) - poll.add_judgment(j) - - j = MajorityJudgmentJudgment.new() - j.set_participant(MajorityJudgmentParticipant.make("Sabre")) - j.set_grade(poll.grading.grades[5]) - j.set_candidate(poll.candidates[0]) - poll.add_judgment(j) - - update_nodes() - - yield(get_tree().create_timer(2), "timeout") - - var tiger = MajorityJudgmentParticipant.make("Tiger") - j = MajorityJudgmentJudgment.new() - j.set_participant(tiger) - j.set_grade(poll.grading.grades[4]) - j.set_candidate(poll.candidates[0]) - poll.add_judgment(j) - update_nodes() - - yield(get_tree().create_timer(2), "timeout") - - j = MajorityJudgmentJudgment.new() - j.set_participant(tiger) - j.set_grade(poll.grading.grades[1]) - j.set_candidate(poll.candidates[2]) - poll.add_judgment(j) - update_nodes() +# yield(get_tree().create_timer(3), "timeout") +# +# var j = MajorityJudgmentJudgment.new() +# j.set_participant(MajorityJudgmentParticipant.make("Plume")) +# j.set_grade(poll.grading.grades[2]) +# j.set_candidate(poll.candidates[0]) +# poll.add_judgment(j) +# +# var sylvain = MajorityJudgmentParticipant.make("Sylvain") +# j = MajorityJudgmentJudgment.new() +# j.set_participant(sylvain) +# j.set_grade(poll.grading.grades[3]) +# j.set_candidate(poll.candidates[0]) +# poll.add_judgment(j) +# j = MajorityJudgmentJudgment.new() +# j.set_participant(sylvain) +# j.set_grade(poll.grading.grades[3]) +# j.set_candidate(poll.candidates[1]) +# poll.add_judgment(j) +# j = MajorityJudgmentJudgment.new() +# j.set_participant(sylvain) +# j.set_grade(poll.grading.grades[4]) +# j.set_candidate(poll.candidates[2]) +# poll.add_judgment(j) +# +# j = MajorityJudgmentJudgment.new() +# j.set_participant(MajorityJudgmentParticipant.make("Sabre")) +# j.set_grade(poll.grading.grades[5]) +# j.set_candidate(poll.candidates[0]) +# poll.add_judgment(j) +# +# update_nodes() +# +# yield(get_tree().create_timer(2), "timeout") +# +# var tiger = MajorityJudgmentParticipant.make("Tiger") +# j = MajorityJudgmentJudgment.new() +# j.set_participant(tiger) +# j.set_grade(poll.grading.grades[4]) +# j.set_candidate(poll.candidates[0]) +# poll.add_judgment(j) +# update_nodes() +# +# yield(get_tree().create_timer(2), "timeout") +# +# j = MajorityJudgmentJudgment.new() +# j.set_participant(tiger) +# j.set_grade(poll.grading.grades[1]) +# j.set_candidate(poll.candidates[2]) +# poll.add_judgment(j) +# update_nodes() var profiles_nodes := Array() func craft_nodes(): @@ -115,8 +118,6 @@ func update_nodes(): var tally : MajorityJudgmentPollTally = get_poll().tally() var candidate_index = 0 # as they were initially written, before the sort for candidate in get_poll().get_candidates(): -# var candidate_tally := tally.get_tally_of_candidate(candidate) -# var merit_profile = candidate_tally.merit_profile var profile = profiles_nodes[candidate_index] if tally: var merit = tally.get_tally_of_candidate(candidate).merit_profile @@ -178,3 +179,39 @@ func create_merit_profile_scene(gradation_size:int): mps.set_poll(get_poll()) mps.craft_nodes(gradation_size) return mps + + +var provider:MajorityJudgmentAbstractJudgmentsProvider + +func start_provider(__provider): + self.provider = __provider + var connected = self.provider.connect( + "judgment_emitted", + self, "__on_judgment_emitted" + ) + self.provider.start_providing() + + +var known_participants := Dictionary() # id => Participant + +func get_or_create_participant(identifier:String) -> MajorityJudgmentParticipant: + if not known_participants.has(identifier): + known_participants[identifier] = MajorityJudgmentParticipant.make(identifier) + return known_participants[identifier] + + +func __on_judgment_emitted(author_identifier, grade_index, candidate_index): + # Data comes from userland, best be careful here + + + var j = MajorityJudgmentJudgment.new() + j.set_participant(get_or_create_participant(author_identifier)) + j.set_grade(poll.grading.grades[grade_index]) + j.set_candidate(poll.candidates[candidate_index]) + poll.add_judgment(j) + + update_nodes() + + + + diff --git a/addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.tscn b/addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.tscn index 5470076..f3212d2 100644 --- a/addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.tscn +++ b/addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.tscn @@ -16,7 +16,7 @@ anchor_bottom = 1.0 [node name="ProfilesContainer" type="VBoxContainer" parent="CenterContainer"] margin_left = 312.0 -margin_top = 99.0 +margin_top = 100.0 margin_right = 712.0 -margin_bottom = 499.0 +margin_bottom = 500.0 rect_min_size = Vector2( 400, 400 ) diff --git a/addons/majority_judgment/providers/MajorityJudgmentAbstractJudgmentsProvider.gd b/addons/majority_judgment/providers/MajorityJudgmentAbstractJudgmentsProvider.gd index d446355..c43ced3 100644 --- a/addons/majority_judgment/providers/MajorityJudgmentAbstractJudgmentsProvider.gd +++ b/addons/majority_judgment/providers/MajorityJudgmentAbstractJudgmentsProvider.gd @@ -1,13 +1,42 @@ extends Reference class_name MajorityJudgmentAbstractJudgmentsProvider +#class_name MajorityJudgmentAbstractProvider # perhaps this? (short = sweet) -# Abstract class for Judgment Providers +# Abstract class for (Judgment) Providers # The job of the children is to emit the judgment_emitted signal. +# +# Example providers (ideas): +# - Test/Demo providers +# - Twitch chat commands (like "A3B2C0") +# - Youtube Live chat commands (if possible) +# - IRC chat commands (low, as a bot would be better) +# - Discord, somehow +# - Riot, Jami, etc. +# - Heck, any videoconferencing software with a workable API +# +# So far, providers don't care about whether the candidate or grade indices +# are within correct range ; that work will be done by the listener to the +# "judgment_emitted" event, and it will do its best, and ignore bad data. +# +# See MajorityJudgmentLinearResultsControl.gd, that's where a (the) listener is. signal judgment_emitted( author_identifier, # String, unique per author (aka participant) - candidate_index, # int - grade_index # int (0 == REJECT, up to the grading size minus one) + grade_index, # int (0 == REJECT, up to the grading size minus one) + candidate_index # int, position in the original array of candidates ) + + +# Called by the scene managing the poll's lifecycle. +# See MajorityJudgmentLinearResultsControl.gd +# Meant to be overridden (put your logic here instead of _init) +func start_providing(): + pass + + +# Meant to be overridden. +# In here you can stop your timers, close your network connections, etc. +func stop_providing(): + pass diff --git a/addons/majority_judgment/providers/MajorityJudgmentChatCommandJudgmentsProvider.gd b/addons/majority_judgment/providers/MajorityJudgmentChatCommandJudgmentsProvider.gd index 6c25a73..da94184 100644 --- a/addons/majority_judgment/providers/MajorityJudgmentChatCommandJudgmentsProvider.gd +++ b/addons/majority_judgment/providers/MajorityJudgmentChatCommandJudgmentsProvider.gd @@ -2,17 +2,38 @@ extends MajorityJudgmentAbstractJudgmentsProvider class_name MajorityJudgmentChatCommandJudgmentsProvider +# Base class for chat command providers to extend. +# Is able to process_chat_command(). +# +# Command Syntax +# -------------- +# +# +# +# such as +# +# A2 +# +# means give grade #2 (passable) to candidate A. +# +# Grades (when there are 6): +# +# 0. TO_REJECT .0 +# 1. POOR .1 +# 2. PASSABLE .2 +# 3. GOOD .3 +# 4. VERY_GOOD .4 +# 5. EXCELLENT .5 +# +# # Command examples # ---------------- -# +# # A0 B2 c0 D1 -# +# func process_chat_command(author_identifier:String, chat_command:String): - var candidate_index := 0 - var grade_index := 0 - var regex = RegEx.new() regex.compile("(?[a-zA-Z]{1})(?[0-9]{1})") @@ -20,15 +41,14 @@ func process_chat_command(author_identifier:String, chat_command:String): if results: for result in results: var candidate_string : String = result.get_string('candidate') - var grade_string : String = result.get_string('grade') - - grade_index = str2var(grade_string) candidate_string = candidate_string.to_upper() - candidate_index = ord(candidate_string) - ord("A") + var candidate_index = ord(candidate_string) - ord("A") + var grade_string : String = result.get_string('grade') + var grade_index = str2var(grade_string) # FIXME: safer, please emit_signal( "judgment_emitted", author_identifier, - candidate_index, - grade_index + grade_index, + candidate_index ) diff --git a/addons/majority_judgment/providers/MajorityJudgmentDemoProvider.gd b/addons/majority_judgment/providers/MajorityJudgmentDemoProvider.gd new file mode 100644 index 0000000..67d82af --- /dev/null +++ b/addons/majority_judgment/providers/MajorityJudgmentDemoProvider.gd @@ -0,0 +1,20 @@ +extends MajorityJudgmentChatCommandJudgmentsProvider +class_name MajorityJudgmentDemoProvider + + +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") + diff --git a/core/App.gd b/core/App.gd index c6f3ff7..87623e4 100644 --- a/core/App.gd +++ b/core/App.gd @@ -42,5 +42,7 @@ func start_poll(poll): var _done = get_tree().change_scene("res://addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.tscn") yield(get_tree(), "idle_frame") get_tree().current_scene.set_poll(poll) - + +func timer(duration:int) -> SceneTreeTimer: + return get_tree().create_timer(duration)