From 2638a5d4e959ceed1dfb8cdea4edbe05916ec890 Mon Sep 17 00:00:00 2001 From: AnturK Date: Sun, 24 May 2015 14:56:11 +0200 Subject: [PATCH 1/3] Fixes editing associative lists --- code/modules/admin/verbs/modifyvariables.dm | 76 +++++++++++++++++---- 1 file changed, 63 insertions(+), 13 deletions(-) diff --git a/code/modules/admin/verbs/modifyvariables.dm b/code/modules/admin/verbs/modifyvariables.dm index f14df6a3fc9..6d512276df8 100644 --- a/code/modules/admin/verbs/modifyvariables.dm +++ b/code/modules/admin/verbs/modifyvariables.dm @@ -142,15 +142,33 @@ var/list/VVckey_edit = list("key", "ckey") if(confirm != "Continue") return - var/list/names = sortList(L) + var/assoc = 0 + if(L.len > 0) + var/a = L[1] + if(L[a] != null) + assoc = 1 //This is pretty weak test but i can't think of anything else + usr << "List appears to be associative." - var/variable = input("Which var?","Var") as null|anything in names + "(ADD VAR)" + var/list/names = null + if(!assoc) + names = sortList(L) + + var/variable + var/assoc_key + if(assoc) + variable = input("Which var?","Var") as null|anything in L + "(ADD VAR)" + else + variable = input("Which var?","Var") as null|anything in names + "(ADD VAR)" if(variable == "(ADD VAR)") mod_list_add(L, O, original_name, objectvar) return - if(!variable) + if(assoc) + assoc_key = variable + variable = L[assoc_key] + + if(!assoc && !variable || assoc && !assoc_key) return var/default @@ -240,7 +258,12 @@ var/list/VVckey_edit = list("key", "ckey") if(holder.marked_datum && class == "marked datum ([holder.marked_datum.type])") class = "marked datum" - var/original_var = L[L.Find(variable)] + var/original_var + if(assoc) + original_var = L[assoc_key] + else + original_var = L[L.Find(variable)] + var/new_var switch(class) //Spits a runtime error if you try to modify an entry in the contents list. Dunno how to fix it, yet. @@ -249,7 +272,10 @@ var/list/VVckey_edit = list("key", "ckey") if("restore to default") new_var = initial(variable) - L[L.Find(variable)] = new_var + if(assoc) + L[assoc_key] = new_var + else + L[L.Find(variable)] = new_var if("edit referenced object") modify_variables(variable) @@ -263,35 +289,59 @@ var/list/VVckey_edit = list("key", "ckey") if("text") new_var = input("Enter new text:","Text") as text - L[L.Find(variable)] = new_var + if(assoc) + L[assoc_key] = new_var + else + L[L.Find(variable)] = new_var if("num") new_var = input("Enter new number:","Num") as num - L[L.Find(variable)] = new_var + if(assoc) + L[assoc_key] = new_var + else + L[L.Find(variable)] = new_var if("type") new_var = input("Enter type:","Type") in typesof(/obj,/mob,/area,/turf) - L[L.Find(variable)] = new_var + if(assoc) + L[assoc_key] = new_var + else + L[L.Find(variable)] = new_var if("reference") new_var = input("Select reference:","Reference") as mob|obj|turf|area in world - L[L.Find(variable)] = new_var + if(assoc) + L[assoc_key] = new_var + else + L[L.Find(variable)] = new_var if("mob reference") new_var = input("Select reference:","Reference") as mob in world - L[L.Find(variable)] = new_var + if(assoc) + L[assoc_key] = new_var + else + L[L.Find(variable)] = new_var if("file") new_var = input("Pick file:","File") as file - L[L.Find(variable)] = new_var + if(assoc) + L[assoc_key] = new_var + else + L[L.Find(variable)] = new_var if("icon") new_var = input("Pick icon:","Icon") as icon - L[L.Find(variable)] = new_var + if(assoc) + L[assoc_key] = new_var + else + L[L.Find(variable)] = new_var if("marked datum") new_var = holder.marked_datum - L[L.Find(variable)] = new_var + if(assoc) + L[assoc_key] = new_var + else + L[L.Find(variable)] = new_var world.log << "### ListVarEdit by [src]: [O.type] [objectvar]: [original_var]=[new_var]" log_admin("[key_name(src)] modified [original_name]'s [objectvar]: [original_var]=[new_var]") From 3b1a5fbdca47b8cafe890049ee421bb89b7b95c4 Mon Sep 17 00:00:00 2001 From: AnturK Date: Sun, 24 May 2015 15:11:50 +0200 Subject: [PATCH 2/3] Fixes some false positives --- code/modules/admin/verbs/modifyvariables.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/modules/admin/verbs/modifyvariables.dm b/code/modules/admin/verbs/modifyvariables.dm index 6d512276df8..a9a70330118 100644 --- a/code/modules/admin/verbs/modifyvariables.dm +++ b/code/modules/admin/verbs/modifyvariables.dm @@ -145,7 +145,7 @@ var/list/VVckey_edit = list("key", "ckey") var/assoc = 0 if(L.len > 0) var/a = L[1] - if(L[a] != null) + if(!isnum(a) && L[a] != null) assoc = 1 //This is pretty weak test but i can't think of anything else usr << "List appears to be associative." From c58142d39428581fa9d89f45e67b44f58f3a377e Mon Sep 17 00:00:00 2001 From: AnturK Date: Fri, 29 May 2015 19:42:41 +0200 Subject: [PATCH 3/3] Stability fix --- code/modules/admin/verbs/modifyvariables.dm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/modules/admin/verbs/modifyvariables.dm b/code/modules/admin/verbs/modifyvariables.dm index a9a70330118..3125067f32b 100644 --- a/code/modules/admin/verbs/modifyvariables.dm +++ b/code/modules/admin/verbs/modifyvariables.dm @@ -145,7 +145,7 @@ var/list/VVckey_edit = list("key", "ckey") var/assoc = 0 if(L.len > 0) var/a = L[1] - if(!isnum(a) && L[a] != null) + if(istext(a) && L[a] != null) assoc = 1 //This is pretty weak test but i can't think of anything else usr << "List appears to be associative." @@ -589,4 +589,4 @@ var/list/VVckey_edit = list("key", "ckey") world.log << "### VarEdit by [src]: [O.type] [variable]=[html_encode("[O.vars[variable]]")]" log_admin("[key_name(src)] modified [original_name]'s [variable] to [O.vars[variable]]") - message_admins("[key_name_admin(src)] modified [original_name]'s [variable] to [O.vars[variable]]") \ No newline at end of file + message_admins("[key_name_admin(src)] modified [original_name]'s [variable] to [O.vars[variable]]")