You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
181 lines
5.1 KiB
181 lines
5.1 KiB
extends Control
|
|
|
|
|
|
const MeritProfileScene = preload("res://addons/majority_judgment/nodes/MajorityJudgmentMeritProfileControl.tscn")
|
|
|
|
|
|
export(Resource) var poll setget set_poll, get_poll
|
|
|
|
|
|
#func _ready():
|
|
# set_poll(load("res://test_poll.tres"))
|
|
|
|
|
|
func get_poll() -> MajorityJudgmentPoll:
|
|
return poll
|
|
|
|
|
|
func set_poll(__poll:MajorityJudgmentPoll):
|
|
poll = __poll
|
|
craft_nodes()
|
|
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():
|
|
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 = create_merit_profile_scene(6)
|
|
if tally:
|
|
profile.refresh(tally.get_tally_of_candidate(candidate).merit_profile)
|
|
var height = profile.compute_height()
|
|
# profile.margin_top = candidate_index * 50
|
|
# profile.margin_left = 0
|
|
# profile.margin_right = 0
|
|
# profile.margin_bottom = candidate_index * 50 + 42
|
|
profile.rect_min_size = Vector2(400, height)
|
|
|
|
var container = $CenterContainer/ProfilesContainer
|
|
|
|
var wrapper = HBoxContainer.new()
|
|
var candidate_label = Label.new()
|
|
candidate_label.text = candidate.get_name()
|
|
candidate_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
# candidate_label.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
|
candidate_label.rect_min_size = Vector2(70, height)
|
|
candidate_label.valign = Label.VALIGN_CENTER
|
|
candidate_label.align = Label.ALIGN_RIGHT
|
|
wrapper.add_child(candidate_label)
|
|
wrapper.add_child(profile)
|
|
container.add_child(wrapper)
|
|
|
|
|
|
profiles_nodes.append(profile)
|
|
|
|
candidate_index += 1
|
|
|
|
|
|
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
|
|
profile.refresh(merit)
|
|
else:
|
|
var merit = poll.get_dummy_merit_profile(candidate)
|
|
profile.refresh(merit)
|
|
|
|
candidate_index += 1
|
|
|
|
|
|
#func test():
|
|
# var poll : MajorityJudgmentPoll = MajorityJudgmentPoll.make(
|
|
# "Test",
|
|
# MajorityJudgmentGrading.make_quality_6(),
|
|
# [
|
|
# MajorityJudgmentCandidate.make("Candidate A"),
|
|
# MajorityJudgmentCandidate.make("Candidate B"),
|
|
# MajorityJudgmentCandidate.make("Candidate C"),
|
|
# ]
|
|
# )
|
|
#
|
|
# var poll_tally = MajorityJudgmentPollTally.new()
|
|
# poll_tally.poll = poll
|
|
# var candidate_tallies = Array()
|
|
# var candidate_tally := MajorityJudgmentCandidateTally.new()
|
|
# candidate_tally.poll = poll
|
|
# candidate_tally.merit_profile = MajorityJudgmentCandidateMeritProfile.new()
|
|
# candidate_tally.merit_profile.grades = [
|
|
# 10,
|
|
# 2,
|
|
# 5,
|
|
# 7,
|
|
# 1,
|
|
# 11,
|
|
# ]
|
|
# candidate_tally.merit_profile.candidate_tally = candidate_tally
|
|
# candidate_tallies.append(candidate_tally)
|
|
# create_merit_profile_scene(candidate_tally.merit_profile)
|
|
#
|
|
## candidate_tally = MajorityJudgmentCandidateTally.new()
|
|
## candidate_tally.merit_profile = MajorityJudgmentCandidateMeritProfile.new()
|
|
## candidate_tally.merit_profile.grades = [
|
|
## 2,
|
|
## 7,
|
|
## 10,
|
|
## 11,
|
|
## 1,
|
|
## 5,
|
|
## ]
|
|
## candidate_tallies.append(candidate_tally)
|
|
## create_merit_profile_scene(candidate_tally.merit_profile)
|
|
#
|
|
# poll_tally.candidates_tallies = candidate_tallies
|
|
|
|
|
|
func create_merit_profile_scene(gradation_size:int):
|
|
var mps = MeritProfileScene.instance()
|
|
mps.set_poll(get_poll())
|
|
mps.craft_nodes(gradation_size)
|
|
return mps
|