v o t e s a v i n g

This commit is contained in:
Putnam
2019-12-26 12:13:02 -08:00
parent a471e26d9c
commit f8557c8ae4
2 changed files with 40 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ SUBSYSTEM_DEF(persistence)
var/list/antag_rep = list() var/list/antag_rep = list()
var/list/antag_rep_change = list() var/list/antag_rep_change = list()
var/list/picture_logging_information = list() var/list/picture_logging_information = list()
var/list/saved_votes = list()
var/list/obj/structure/sign/picture_frame/photo_frames var/list/obj/structure/sign/picture_frame/photo_frames
var/list/obj/item/storage/photo_album/photo_albums var/list/obj/item/storage/photo_album/photo_albums
@@ -33,6 +34,7 @@ SUBSYSTEM_DEF(persistence)
LoadRecentRulesets() LoadRecentRulesets()
LoadRecentMaps() LoadRecentMaps()
LoadPhotoPersistence() LoadPhotoPersistence()
LoadSavedVotes()
if(CONFIG_GET(flag/use_antag_rep)) if(CONFIG_GET(flag/use_antag_rep))
LoadAntagReputation() LoadAntagReputation()
LoadRandomizedRecipes() LoadRandomizedRecipes()
@@ -207,6 +209,15 @@ SUBSYSTEM_DEF(persistence)
return return
antag_rep = json_decode(json) antag_rep = json_decode(json)
/datum/controller/subsystem/persistence/proc/LoadSavedVotes()
var/json_file = file("data/SavedVotes.json")
if(!fexists(json_file))
return
var/list/json = json_decode(file2text(json_file))
if(!json)
return
saved_votes = json["data"]
/datum/controller/subsystem/persistence/proc/SetUpTrophies(list/trophy_items) /datum/controller/subsystem/persistence/proc/SetUpTrophies(list/trophy_items)
for(var/A in GLOB.trophy_cases) for(var/A in GLOB.trophy_cases)
var/obj/structure/displaycase/trophy/T = A var/obj/structure/displaycase/trophy/T = A
@@ -484,3 +495,10 @@ SUBSYSTEM_DEF(persistence)
fdel(json_file) fdel(json_file)
WRITE_FILE(json_file, json_encode(file_data)) WRITE_FILE(json_file, json_encode(file_data))
/datum/controller/subsystem/persistence/proc/SaveSavedVotes()
var/json_file = file("data/SavedVotes.json")
var/list/file_data = list()
file_data["data"] = saved_votes
fdel(json_file)
WRITE_FILE(json_file, json_encode(file_data))

View File

@@ -18,6 +18,7 @@ SUBSYSTEM_DEF(vote)
var/list/choice_descs = list() // optional descriptions var/list/choice_descs = list() // optional descriptions
var/list/voted = list() var/list/voted = list()
var/list/voting = list() var/list/voting = list()
var/list/saved = list()
var/list/generated_actions = list() var/list/generated_actions = list()
var/next_pop = 0 var/next_pop = 0
@@ -29,6 +30,7 @@ SUBSYSTEM_DEF(vote)
if(mode) if(mode)
if(end_time < world.time) if(end_time < world.time)
result() result()
SSpersistence.SaveSavedVotes()
for(var/client/C in voting) for(var/client/C in voting)
C << browse(null, "window=vote;can_close=0") C << browse(null, "window=vote;can_close=0")
reset() reset()
@@ -282,6 +284,7 @@ SUBSYSTEM_DEF(vote)
voted += usr.ckey voted += usr.ckey
voted[usr.ckey] = list() voted[usr.ckey] = list()
voted[usr.ckey] += vote voted[usr.ckey] += vote
saved -= usr.ckey
return 0 return 0
/datum/controller/subsystem/vote/proc/initiate_vote(vote_type, initiator_key, hideresults, votesystem = PLURALITY_VOTING, forced = FALSE)//CIT CHANGE - adds hideresults argument to votes to allow for obfuscated votes /datum/controller/subsystem/vote/proc/initiate_vote(vote_type, initiator_key, hideresults, votesystem = PLURALITY_VOTING, forced = FALSE)//CIT CHANGE - adds hideresults argument to votes to allow for obfuscated votes
@@ -367,6 +370,9 @@ SUBSYSTEM_DEF(vote)
C.player_details.player_actions += V C.player_details.player_actions += V
V.Grant(C.mob) V.Grant(C.mob)
generated_actions += V generated_actions += V
if((vote_type in SSpersistence.saved_votes) && (C.ckey in SSpersistence.saved_votes[vote_type]))
voted[C.ckey] = SSpersistence.saved_votes[vote_type][C.ckey]
saved += C.ckey
if(forced) if(forced)
var/datum/browser/popup = new(C, "vote", "Voting Panel",nwidth=600,nheight=700) var/datum/browser/popup = new(C, "vote", "Voting Panel",nwidth=600,nheight=700)
popup.set_window_options("can_close=0") popup.set_window_options("can_close=0")
@@ -399,8 +405,6 @@ SUBSYSTEM_DEF(vote)
if(RANKED_CHOICE_VOTING) if(RANKED_CHOICE_VOTING)
var/list/myvote = voted[C.ckey] var/list/myvote = voted[C.ckey]
. += "<h3>Vote by order of preference. Revoting will demote to the bottom. 1 is your favorite, and higher numbers are worse.</h3>" . += "<h3>Vote by order of preference. Revoting will demote to the bottom. 1 is your favorite, and higher numbers are worse.</h3>"
if(myvote && myvote.len < choices.len)
. += "<h1>Please rank all your preferences. You have not done so.</h1>"
. += "Time Left: [DisplayTimeText(end_time-world.time)]<hr><ul>" . += "Time Left: [DisplayTimeText(end_time-world.time)]<hr><ul>"
switch(vote_system) switch(vote_system)
if(PLURALITY_VOTING, APPROVAL_VOTING) if(PLURALITY_VOTING, APPROVAL_VOTING)
@@ -417,6 +421,7 @@ SUBSYSTEM_DEF(vote)
. += "<li>[ivotedforthis ? "<b>" : ""]<a href='?src=[REF(src)];vote=[i]'>[choices[i]]</a> ([obfuscated ? (admin ? "??? ([votes])" : "???") : votes] votes)[ivotedforthis ? "</b>" : ""]</li>" // CIT CHANGE - adds obfuscated votes . += "<li>[ivotedforthis ? "<b>" : ""]<a href='?src=[REF(src)];vote=[i]'>[choices[i]]</a> ([obfuscated ? (admin ? "??? ([votes])" : "???") : votes] votes)[ivotedforthis ? "</b>" : ""]</li>" // CIT CHANGE - adds obfuscated votes
if(choice_descs.len >= i) if(choice_descs.len >= i)
. += "<li>[choice_descs[i]]</li>" . += "<li>[choice_descs[i]]</li>"
. += "</ul><hr>"
if(RANKED_CHOICE_VOTING) if(RANKED_CHOICE_VOTING)
var/list/myvote = voted[C.ckey] var/list/myvote = voted[C.ckey]
for(var/i=1,i<=choices.len,i++) for(var/i=1,i<=choices.len,i++)
@@ -427,7 +432,12 @@ SUBSYSTEM_DEF(vote)
. += "<li><a href='?src=[REF(src)];vote=[i]'>[choices[i]]</a></li>" . += "<li><a href='?src=[REF(src)];vote=[i]'>[choices[i]]</a></li>"
if(choice_descs.len >= i) if(choice_descs.len >= i)
. += "<li>[choice_descs[i]]</li>" . += "<li>[choice_descs[i]]</li>"
. += "</ul><hr>" . += "</ul><hr>"
if(!(C.ckey in saved))
. += "(<a href='?src=[REF(src)];vote=save'>Save vote</a>)"
else
. += "(Saved!)"
. += "(<a href='?src=[REF(src)];vote=reset'>Reset votes</a>)"
if(admin) if(admin)
. += "(<a href='?src=[REF(src)];vote=cancel'>Cancel Vote</a>) " . += "(<a href='?src=[REF(src)];vote=cancel'>Cancel Vote</a>) "
else else
@@ -485,6 +495,15 @@ SUBSYSTEM_DEF(vote)
if("custom") if("custom")
if(usr.client.holder) if(usr.client.holder)
initiate_vote("custom",usr.key) initiate_vote("custom",usr.key)
if("reset")
if(usr.ckey in voted)
voted -= usr.ckey
if("save")
if(usr.ckey in voted)
if(!(mode in SSpersistence.saved_votes))
SSpersistence.saved_votes[mode] = list()
SSpersistence.saved_votes[mode][usr.ckey] = voted[usr.ckey]
saved += usr.ckey
else else
submit_vote(round(text2num(href_list["vote"]))) submit_vote(round(text2num(href_list["vote"])))
usr.vote() usr.vote()