From 9ca1f2f262e0562ff9fefdfc53f2b4473c9d0dca Mon Sep 17 00:00:00 2001 From: Remie Richards Date: Mon, 10 Aug 2015 15:20:15 +0100 Subject: [PATCH] VV and VV Mass Modify now accept variables when editing a string variable, this allows you to embed variables in string variables, variableception. --- code/__HELPERS/type2type.dm | 43 +++++++++- code/modules/admin/verbs/massmodvar.dm | 91 +++++++++++++++++++-- code/modules/admin/verbs/modifyvariables.dm | 40 +++++++-- html/changelogs/RemieRichards-PR-11139.yml | 9 ++ 4 files changed, 171 insertions(+), 12 deletions(-) create mode 100644 html/changelogs/RemieRichards-PR-11139.yml diff --git a/code/__HELPERS/type2type.dm b/code/__HELPERS/type2type.dm index a14fa4ac40b..fe9e8a29e25 100644 --- a/code/__HELPERS/type2type.dm +++ b/code/__HELPERS/type2type.dm @@ -586,4 +586,45 @@ for(var/t in test_times) if("indigo") return "#4B0082" else - return "#FFFFFF" \ No newline at end of file + return "#FFFFFF" + + +//This is a weird one: +//It returns a list of all var names found in the string +//These vars must be in the [var_name] format +//It's only a proc because it's used in more than one place + +//Takes a string and a datum +//The string is well, obviously the string being checked +//The datum is used as a source for var names, to check validity +//Otherwise every single word could technically be a variable! +/proc/string2listofvars(var/t_string, var/datum/var_source) + if(!t_string || !var_source) + return list() + + . = list() + + var/var_found = findtext(t_string,"\[") //Not the actual variables, just a generic "should we even bother" check + if(var_found) + //Find var names + + // "A dog said hi [name]!" + // text2list() --> list("A dog said hi ","name]!" + // list2text() --> "A dog said hi name]!" + // text2list() --> list("A","dog","said","hi","name]!") + + t_string = replacetext(t_string,"\[","\[ ")//Necessary to resolve "word[var_name]" scenarios + var/list/list_value = text2list(t_string,"\[") + var/intermediate_stage = list2text(list_value) + + list_value = text2list(intermediate_stage," ") + for(var/value in list_value) + if(findtext(value,"]")) + value = text2list(value,"]") //"name]!" --> list("name","!") + for(var/A in value) + if(var_source.vars.Find(A)) + . += A + + + + diff --git a/code/modules/admin/verbs/massmodvar.dm b/code/modules/admin/verbs/massmodvar.dm index 2fcae2ed698..cf13ea9fe4c 100644 --- a/code/modules/admin/verbs/massmodvar.dm +++ b/code/modules/admin/verbs/massmodvar.dm @@ -173,38 +173,117 @@ if("text") var/new_value = input("Enter new text:","Text",O.vars[variable]) as text|null if(new_value == null) return + + var/process_vars = 0 + var/unique = 0 + if(findtext(new_value,"\[")) + process_vars = alert(usr,"\[] detected in string, process as variables?","Process Variables?","Yes","No") + if(process_vars == "Yes") + process_vars = 1 + unique = alert(usr,"Process vars unique to each instance, or same for all?","Variable Association","Unique","Same") + if(unique == "Unique") + unique = 1 + else + unique = 0 + else + process_vars = 0 + + var/pre_processing = new_value + var/list/varsvars = list() + + if(process_vars) + varsvars = string2listofvars(new_value, O) + if(varsvars.len) + for(var/V in varsvars) + new_value = replacetext(new_value,"\[[V]]","[O.vars[V]]") + O.vars[variable] = new_value + //Convert the string vars for anything that's not O if(method) if(istype(O, /mob)) for(var/mob/M in mob_list) if ( istype(M , O.type) ) - M.vars[variable] = O.vars[variable] + new_value = pre_processing //reset new_value, ready to convert it uniquely for the next iteration + + if(process_vars) + if(unique) + for(var/V in varsvars) + new_value = replacetext(new_value,"\[[V]]","[M.vars[V]]") + else + new_value = O.vars[variable] //We already processed the non-unique form for O, reuse it + + M.vars[variable] = new_value else if(istype(O, /obj)) for(var/obj/A in world) if ( istype(A , O.type) ) - A.vars[variable] = O.vars[variable] + new_value = pre_processing + + if(process_vars) + if(unique) + for(var/V in varsvars) + new_value = replacetext(new_value,"\[[V]]","[A.vars[V]]") + else + new_value = O.vars[variable] + + A.vars[variable] = new_value else if(istype(O, /turf)) for(var/turf/A in world) if ( istype(A , O.type) ) - A.vars[variable] = O.vars[variable] + new_value = pre_processing + + if(process_vars) + if(unique) + for(var/V in varsvars) + new_value = replacetext(new_value,"\[[V]]","[A.vars[V]]") + else + new_value = O.vars[variable] + + A.vars[variable] = new_value else if(istype(O, /mob)) for(var/mob/M in mob_list) if (M.type == O.type) - M.vars[variable] = O.vars[variable] + new_value = pre_processing + + if(process_vars) + if(unique) + for(var/V in varsvars) + new_value = replacetext(new_value,"\[[V]]","[M.vars[V]]") + else + new_value = O.vars[variable] + + M.vars[variable] = new_value else if(istype(O, /obj)) for(var/obj/A in world) if (A.type == O.type) - A.vars[variable] = O.vars[variable] + new_value = pre_processing + + if(process_vars) + if(unique) + for(var/V in varsvars) + new_value = replacetext(new_value,"\[[V]]","[A.vars[V]]") + else + new_value = O.vars[variable] + + A.vars[variable] = new_value else if(istype(O, /turf)) for(var/turf/A in world) if (A.type == O.type) - A.vars[variable] = O.vars[variable] + new_value = pre_processing + + if(process_vars) + if(unique) + for(var/V in varsvars) + new_value = replacetext(new_value,"\[[V]]","[A.vars[V]]") + else + new_value = O.vars[variable] + + A.vars[variable] = new_value if("num") var/new_value = input("Enter new number:","Num",\ diff --git a/code/modules/admin/verbs/modifyvariables.dm b/code/modules/admin/verbs/modifyvariables.dm index e1c1430d0e3..9cc7f8a7a76 100644 --- a/code/modules/admin/verbs/modifyvariables.dm +++ b/code/modules/admin/verbs/modifyvariables.dm @@ -28,7 +28,7 @@ var/list/VVckey_edit = list("key", "ckey") src.modify_variables(ticker) feedback_add_details("admin_verb","ETV") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! -/client/proc/mod_list_add_ass() //haha +/client/proc/mod_list_add_ass(atom/O) //haha var/class = "text" if(src.holder && src.holder.marked_datum) @@ -74,6 +74,14 @@ var/list/VVckey_edit = list("key", "ckey") if(!var_value) return + if(istext(var_value)) + if(findtext(var_value,"\[")) + var/process_vars = alert(usr,"\[] detected in string, process as variables?","Process Variables?","Yes","No") + if(process_vars == "Yes") + var/list/varsvars = string2listofvars(var_value, O) + for(var/V in varsvars) + var_value = replacetext(var_value,"\[[V]]","[O.vars[V]]") + return var_value @@ -123,12 +131,18 @@ var/list/VVckey_edit = list("key", "ckey") if(!var_value) return + if(istext(var_value)) + if(findtext(var_value,"\[")) + var/process_vars = alert(usr,"\[] detected in string, process as variables?","Process Variables?","Yes","No") + if(process_vars == "Yes") + var/list/varsvars = string2listofvars(var_value, O) + for(var/V in varsvars) + var_value = replacetext(var_value,"\[[V]]","[O.vars[V]]") + + L += var_value switch(alert("Would you like to associate a var with the list entry?",,"Yes","No")) if("Yes") - L += var_value - L[var_value] = mod_list_add_ass() //haha - if("No") - L += var_value + L[var_value] = mod_list_add_ass(O) //haha world.log << "### ListVarEdit by [src]: [O.type] [objectvar]: ADDED=[var_value]" log_admin("[key_name(src)] modified [original_name]'s [objectvar]: ADDED=[var_value]") message_admins("[key_name_admin(src)] modified [original_name]'s [objectvar]: ADDED=[var_value]") @@ -289,6 +303,14 @@ var/list/VVckey_edit = list("key", "ckey") if("text") new_var = input("Enter new text:","Text") as text + + if(findtext(new_var,"\[")) + var/process_vars = alert(usr,"\[] detected in string, process as variables?","Process Variables?","Yes","No") + if(process_vars == "Yes") + var/list/varsvars = string2listofvars(new_var, O) + for(var/V in varsvars) + new_var = replacetext(new_var,"\[[V]]","[O.vars[V]]") + if(assoc) L[assoc_key] = new_var else @@ -537,6 +559,14 @@ var/list/VVckey_edit = list("key", "ckey") if("text") var/var_new = input("Enter new text:","Text",O.vars[variable]) as null|text if(var_new==null) return + + if(findtext(var_new,"\[")) + var/process_vars = alert(usr,"\[] detected in string, process as variables?","Process Variables?","Yes","No") + if(process_vars == "Yes") + var/list/varsvars = string2listofvars(var_new, O) + for(var/V in varsvars) + var_new = replacetext(var_new,"\[[V]]","[O.vars[V]]") + O.vars[variable] = var_new if("num") diff --git a/html/changelogs/RemieRichards-PR-11139.yml b/html/changelogs/RemieRichards-PR-11139.yml new file mode 100644 index 00000000000..aa98a151c06 --- /dev/null +++ b/html/changelogs/RemieRichards-PR-11139.yml @@ -0,0 +1,9 @@ + +author: RemieRichards + +delete-after: True + + +changes: + - rscadd: "Modifying a string (Text) variable with View Variables or View Variables Mass Modify now allows you to embed variables like real byond strings, For example the variable real_name; you could set a text var to [real_name] and it would be replaced with the actual contents of the var, + This allows for Mass fixing of certain variables but it's also useful for badmin gimmickery"