diff --git a/addons/majority_judgment/providers/MajorityJudgmentAbstractJudgmentsProvider.gd b/addons/majority_judgment/providers/MajorityJudgmentAbstractJudgmentsProvider.gd new file mode 100644 index 0000000..d446355 --- /dev/null +++ b/addons/majority_judgment/providers/MajorityJudgmentAbstractJudgmentsProvider.gd @@ -0,0 +1,13 @@ +extends Reference +class_name MajorityJudgmentAbstractJudgmentsProvider + + +# Abstract class for Judgment Providers +# The job of the children is to emit the judgment_emitted signal. + + +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) +) diff --git a/addons/majority_judgment/providers/MajorityJudgmentChatCommandJudgmentsProvider.gd b/addons/majority_judgment/providers/MajorityJudgmentChatCommandJudgmentsProvider.gd new file mode 100644 index 0000000..6c25a73 --- /dev/null +++ b/addons/majority_judgment/providers/MajorityJudgmentChatCommandJudgmentsProvider.gd @@ -0,0 +1,34 @@ +extends MajorityJudgmentAbstractJudgmentsProvider +class_name MajorityJudgmentChatCommandJudgmentsProvider + + +# 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})") + + var results = regex.search_all(chat_command) + 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") + + emit_signal( + "judgment_emitted", + author_identifier, + candidate_index, + grade_index + ) diff --git a/tests/commands.test.gd b/tests/commands.test.gd index 5c9a8a2..180eb6a 100644 --- a/tests/commands.test.gd +++ b/tests/commands.test.gd @@ -22,6 +22,7 @@ func test_single_command(): do_test_single_command("A0", [0, 0]) do_test_single_command("B2", [1, 2]) do_test_single_command("e4", [4, 4]) + do_test_single_command("E4", [4, 4]) func do_test_single_command(command:String, expected:Array):