alow commas in entries and make scores configurable
This commit is contained in:
parent
da92f24071
commit
2b34e2ec74
45
voting.lua
45
voting.lua
@ -3,7 +3,10 @@
|
||||
-- FIXME: I was sleepy: make sure when entries are added/removed, all mappings are in sync
|
||||
-- FIXME: "results" view not opening when there are no votes?
|
||||
|
||||
local categories = {"Creativity", "Aesthetic Appeal", "Detail & Execution", "Use of space"} -- used for buttons and current sort
|
||||
local categories = {"Creativity", "Aesthetic Appeal", "Detail & Execution", "Use of space"}
|
||||
local num_categories = #categories
|
||||
local min_cat_score = 1
|
||||
local max_cat_score = 3
|
||||
local ENTRIES_PER_PAGE = 8 -- for ballots with large amount of entries
|
||||
|
||||
function show_vote_welcome()
|
||||
@ -102,7 +105,6 @@ function show_admin_edit()
|
||||
for _,e in ipairs(mem.entries) do
|
||||
table.insert(list_entries, string.format("%s|[%s] - %s", e.accepted and "#00FF00[+]" or "[-]", e.user or "", e.title or ""))
|
||||
end
|
||||
local list_str = table.concat(list_entries, ",") -- TODO sanitize?
|
||||
|
||||
local entry = mem.entries[mem.admin_entries_idx] or {}
|
||||
digiline_send("admin",
|
||||
@ -114,7 +116,7 @@ function show_admin_edit()
|
||||
real_coordinates = true,
|
||||
locked = true, -- does not prevent someone from looking at it :(
|
||||
},
|
||||
{command = "addtextlist", name = "entries", listelements = list_str, transparent = false, selected_id = mem.admin_entries_idx, X = 0.5, Y = 0.5, W = 11.0, H = 6.0},
|
||||
{command = "addtextlist", name = "entries", listelements = list_entries, transparent = false, selected_id = mem.admin_entries_idx, X = 0.5, Y = 0.5, W = 11.0, H = 6.0},
|
||||
{command = "addtextarea", name = "", label = "Coordinates:", default = entry.coords or "<NONE>", X = 0.5, Y = 7.0, W = 11.0, H = 0.5},
|
||||
{command = "addtextarea", name = "", label = "Description:", default = entry.description or "<NONE>", X = 0.5, Y = 8, W = 11.0, H = 2.0},
|
||||
|
||||
@ -150,16 +152,20 @@ function show_admin_results()
|
||||
-- for all entries, check all known votes and add them up, using defaults if none
|
||||
-- TODO can be made more efficient probably
|
||||
local total_scores = {}
|
||||
for i, e in ipairs(mem.ballot_entries) do
|
||||
for b_i, e in ipairs(mem.ballot_entries) do
|
||||
local id = e.id
|
||||
local entry_scores = {0,0,0,0} -- need initial values for when there's no votes yet
|
||||
total_scores[i] = entry_scores
|
||||
local entry_scores = {}
|
||||
-- need initial values for when there's no votes yet:
|
||||
for c_i = 1, num_categories do
|
||||
entry_scores[c_i] = 0
|
||||
end
|
||||
total_scores[b_i] = entry_scores
|
||||
entry_scores.id = id
|
||||
for _,player_votes in pairs(mem.votes) do
|
||||
local entry_votes = player_votes[id] or {} -- nil if didn't cast any votes for this entry
|
||||
for i=1,4 do
|
||||
local vote = (entry_votes[i] or 1) -- 1 is the default vote
|
||||
entry_scores[i] = (entry_scores[i] or 0) + vote
|
||||
for c_i = 1, num_categories do
|
||||
local vote = (entry_votes[c_i] or 1) -- 1 is the default vote
|
||||
entry_scores[c_i] = (entry_scores[c_i] or 0) + vote
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -182,7 +188,6 @@ function show_admin_results()
|
||||
local sum = s[1] + s[2] + s[3] + s[4]
|
||||
table.insert(entry_list, string.format("%03d||%03d|%03d|%03d|%03d -- %s", sum, s[1], s[2], s[3], s[4], name))
|
||||
end
|
||||
entry_list = table.concat(entry_list, ",")
|
||||
|
||||
digiline_send("admin",
|
||||
{
|
||||
@ -276,13 +281,17 @@ function show_vote_ballot(username)
|
||||
break -- not enough entries to fill the page
|
||||
end
|
||||
local id = e.id
|
||||
local choices = {}
|
||||
for idx = 0, (max_cat_score - min_cat_score) do
|
||||
choices[idx+1] = tostring(idx + min_cat_score)
|
||||
end
|
||||
local e_v = votes[id] or {} -- previous votes of this player for this entry (if any)
|
||||
table.insert(c, {command = "addimage", texture_name = "halo.png^[colorize:#222233", X = 0.5, Y = 0.4 + shift*i, W = 16.8, H = 1})
|
||||
table.insert(c, {command = "addlabel", label = e.title, X = 0.8, Y = 0.9 + shift*i})
|
||||
table.insert(c, {command = "adddropdown", name = string.format("v_%d_1", id), index_event = true, selected_id = e_v[1] or 1, choices = {[1] = "1", [2] = "2", [3] = "3"}, X = 10.8, Y = 0.5 + shift*i, W = 0.8, H = 0.8})
|
||||
table.insert(c, {command = "adddropdown", name = string.format("v_%d_2", id), index_event = true, selected_id = e_v[2] or 1, choices = {[1] = "1", [2] = "2", [3] = "3"}, X = 12.6, Y = 0.5 + shift*i, W = 0.8, H = 0.8})
|
||||
table.insert(c, {command = "adddropdown", name = string.format("v_%d_3", id), index_event = true, selected_id = e_v[3] or 1, choices = {[1] = "1", [2] = "2", [3] = "3"}, X = 14.4, Y = 0.5 + shift*i, W = 0.8, H = 0.8})
|
||||
table.insert(c, {command = "adddropdown", name = string.format("v_%d_4", id), index_event = true, selected_id = e_v[4] or 1, choices = {[1] = "1", [2] = "2", [3] = "3"}, X = 16.2, Y = 0.5 + shift*i, W = 0.8, H = 0.8})
|
||||
table.insert(c, {command = "adddropdown", name = string.format("v_%d_1", id), index_event = true, selected_id = e_v[1] or 1, choices = choices, X = 10.8, Y = 0.5 + shift*i, W = 0.8, H = 0.8})
|
||||
table.insert(c, {command = "adddropdown", name = string.format("v_%d_2", id), index_event = true, selected_id = e_v[2] or 1, choices = choices, X = 12.6, Y = 0.5 + shift*i, W = 0.8, H = 0.8})
|
||||
table.insert(c, {command = "adddropdown", name = string.format("v_%d_3", id), index_event = true, selected_id = e_v[3] or 1, choices = choices, X = 14.4, Y = 0.5 + shift*i, W = 0.8, H = 0.8})
|
||||
table.insert(c, {command = "adddropdown", name = string.format("v_%d_4", id), index_event = true, selected_id = e_v[4] or 1, choices = choices, X = 16.2, Y = 0.5 + shift*i, W = 0.8, H = 0.8})
|
||||
end
|
||||
|
||||
-- snow number of pages and page flipping buttons
|
||||
@ -472,10 +481,10 @@ elseif event.type == "digiline" then
|
||||
show_error("#FF0000", "ERROR: Please enter the name of submission!")
|
||||
return
|
||||
end
|
||||
if title:find(",", 1, true) then
|
||||
show_error("#FF0000", "ERROR: Submission name can't have commas!")
|
||||
return
|
||||
end
|
||||
-- if title:find(",", 1, true) then
|
||||
-- show_error("#FF0000", "ERROR: Submission name can't have commas!")
|
||||
-- return
|
||||
-- end
|
||||
|
||||
sub.title = title
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user