From 1512ff489f74c4a41e87fe61997071dc6c5de52e Mon Sep 17 00:00:00 2001 From: whosit Date: Sun, 23 Mar 2025 18:02:33 +0300 Subject: [PATCH] draw in batches --- voting.lua | 91 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/voting.lua b/voting.lua index 32ed254..41396d0 100644 --- a/voting.lua +++ b/voting.lua @@ -7,7 +7,8 @@ local categories = {"Creativity", "Aesthetic\n Appeal", "Detail & \nExecution local num_categories = #categories local ENTRIES_PER_PAGE = 8 -- for ballots with large amount of entries local shift = 1.3 -- vertical spacing between entries - +local DRAW_DELAY = 0.1 +local ENTRIES_PER_DRAW = 3 local function show_vote_welcome() -- window shown before player can see the ballot @@ -315,7 +316,7 @@ local function show_vote_ballot(username) mem.draw_ballot_i = 1 mem.draw_ballot_page = page mem.draw_ballot_version = mem.db_version - interrupt(0.3, "draw_ballot") + interrupt(DRAW_DELAY, "draw_ballot") end local c = {} @@ -724,52 +725,56 @@ elseif event.type == "interrupt" then local choices = "1,2,3,4,5" + local i_end = i + ENTRIES_PER_DRAW - 1 -- "loop" - if i > ENTRIES_PER_PAGE then - goto done + while i <= i_end do + if i > ENTRIES_PER_PAGE then + goto done + end + + local e = entries[i + ENTRIES_PER_PAGE*page] + if not e then + goto done -- not enough entries to fill the page + end + + local id = e.id + local default_id = 1 + local e_v = votes[id] or {} -- previous votes of this player for this entry (if any) + + local y_offset = shift*i + + local v_1 = e_v[1] + local v_2 = e_v[2] + local v_3 = e_v[3] + local v_4 = e_v[4] + local id_str = "v_" .. tostring(id) + + local c = { + {command = "adddropdown", name = id_str.."_1", index_event = true, + selected_id = v_1 or default_id, + choices = choices, X = 10.8, Y = 0.5 + y_offset, W = 0.8, H = 0.8}, + + {command = "adddropdown", name = id_str.."_2", index_event = true, + selected_id = v_2 or default_id, + choices = choices, X = 12.6, Y = 0.5 + y_offset, W = 0.8, H = 0.8}, + + {command = "adddropdown", name = id_str.."_3", index_event = true, + selected_id = v_3 or default_id, + choices = choices, X = 14.4, Y = 0.5 + y_offset, W = 0.8, H = 0.8}, + + {command = "adddropdown", name = id_str.."_4", index_event = true, + selected_id = v_4 or default_id, + choices = choices, X = 16.2, Y = 0.5 + y_offset, W = 0.8, H = 0.8}, + } + + digiline_send("vote", c) + i = i + 1 end - local e = entries[i + ENTRIES_PER_PAGE*page] - if not e then - goto done -- not enough entries to fill the page - end - - local id = e.id - local default_id = 1 - local e_v = votes[id] or {} -- previous votes of this player for this entry (if any) - - local y_offset = shift*i - - local v_1 = e_v[1] - local v_2 = e_v[2] - local v_3 = e_v[3] - local v_4 = e_v[4] - local id_str = "v_" .. tostring(id) - - local c = { - {command = "adddropdown", name = id_str.."_1", index_event = true, - selected_id = v_1 or default_id, - choices = choices, X = 10.8, Y = 0.5 + y_offset, W = 0.8, H = 0.8}, - - {command = "adddropdown", name = id_str.."_2", index_event = true, - selected_id = v_2 or default_id, - choices = choices, X = 12.6, Y = 0.5 + y_offset, W = 0.8, H = 0.8}, - - {command = "adddropdown", name = id_str.."_3", index_event = true, - selected_id = v_3 or default_id, - choices = choices, X = 14.4, Y = 0.5 + y_offset, W = 0.8, H = 0.8}, - - {command = "adddropdown", name = id_str.."_4", index_event = true, - selected_id = v_4 or default_id, - choices = choices, X = 16.2, Y = 0.5 + y_offset, W = 0.8, H = 0.8}, - } - - digiline_send("vote", c) - -- continue - mem.draw_ballot_i = i + 1 + mem.draw_ballot_i = i - interrupt(0.3, "draw_ballot") + interrupt(DRAW_DELAY, "draw_ballot") ::done::