Improvements and fixes

This commit is contained in:
MrStonedOne
2016-11-26 23:11:38 -08:00
parent 76e1c6916f
commit 1f8d998600
8 changed files with 249 additions and 152 deletions
+13 -18
View File
@@ -378,34 +378,29 @@ var/list/TYPES_SHORTCUTS = list(
/mob = "M"
)
/proc/make_types_fancy(var/list/types)
if (ispath(types))
types = list(types)
. = list()
for(var/type in types)
var/typename = "[type]"
for (var/tn in TYPES_SHORTCUTS)
if (copytext(typename,1, length("[tn]/")+1)=="[tn]/" /*findtextEx(typename,"[tn]/",1,2)*/ )
typename = TYPES_SHORTCUTS[tn]+copytext(typename,length("[tn]/"))
break
.[typename] = type
/proc/get_fancy_list_of_atom_types()
var/static/list/pre_generated_list
if (!pre_generated_list) //init
var/list/temp = sortList(typesof(/atom))
pre_generated_list = new(temp.len)
for(var/type in temp)
var/typename = "[type]"
for (var/tn in TYPES_SHORTCUTS)
if (copytext(typename,1, length("[tn]/")+1)=="[tn]/" /*findtextEx(typename,"[tn]/",1,2)*/ )
typename = TYPES_SHORTCUTS[tn]+copytext(typename,length("[tn]/"))
break
pre_generated_list[typename] = type
pre_generated_list = make_types_fancy(typesof(/atom))
return pre_generated_list
/proc/get_fancy_list_of_datum_types()
var/static/list/pre_generated_list
if (!pre_generated_list) //init
var/list/temp = sortList(typesof(/datum) - typesof(/atom))
pre_generated_list = new(temp.len)
for(var/type in temp)
var/typename = "[type]"
for (var/tn in TYPES_SHORTCUTS)
if (copytext(typename,1, length("[tn]/")+1)=="[tn]/" /*findtextEx(typename,"[tn]/",1,2)*/ )
typename = TYPES_SHORTCUTS[tn]+copytext(typename,length("[tn]/"))
break
pre_generated_list[typename] = type
pre_generated_list = make_types_fancy(sortList(typesof(/datum) - typesof(/atom)))
return pre_generated_list
+32 -49
View File
@@ -3,22 +3,13 @@
set name = "Mass Edit Variables"
set desc="(target) Edit all instances of a target item's variables"
var/method = 0 //0 means strict type detection while 1 means this type and all subtypes (IE: /obj/item with this set to 1 will set it to ALL itms)
var/method = 0 //0 means strict type detection while 1 means this type and all subtypes (IE: /obj/item with this set to 1 will set it to ALL items)
if(!check_rights(R_VAREDIT))
return
if(A && A.type)
if(typesof(A.type))
switch(input("Strict object type detection?") as null|anything in list("Strictly this type","This type and subtypes", "Cancel"))
if("Strictly this type")
method = 0
if("This type and subtypes")
method = 1
if("Cancel")
return
if(null)
return
method = vv_subtype_prompt(A.type)
src.massmodify_variables(A, var_name, method)
feedback_add_details("admin_verb","MEV") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
@@ -106,8 +97,9 @@
switch(class)
if(VV_RESTORE_DEFAULT)
src << "Finding items"
var/list/items = get_all_of_type(O.type, !method)
src << "Finding items..."
var/list/items = get_all_of_type(O.type, method)
src << "Changing [items.len] items..."
for(var/thing in items)
if (!thing)
continue
@@ -119,36 +111,26 @@
CHECK_TICK
if(VV_TEXT)
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/list/varsvars = vv_parse_text(O, new_value)
var/pre_processing = new_value
var/list/varsvars = list()
if(process_vars && !unique)
varsvars = string2listofvars(new_value, O)
if(varsvars.len)
var/unique
if (varsvars && varsvars.len)
unique = alert(usr, "Process vars unique to each instance, or same for all?", "Variable Association", "Unique", "Same")
if(unique == "Unique")
unique = TRUE
else
unique = FALSE
for(var/V in varsvars)
new_value = replacetext(new_value,"\[[V]]","[O.vars[V]]")
src << "Finding items"
var/list/items = get_all_of_type(O.type, !method)
src << "Finding items..."
var/list/items = get_all_of_type(O.type, method)
src << "Changing [items.len] items..."
for(var/thing in items)
if (!thing)
continue
var/datum/D = thing
if(process_vars && unique)
if(unique)
new_value = pre_processing
for(var/V in varsvars)
new_value = replacetext(new_value,"\[[V]]","[D.vars[V]]")
@@ -169,8 +151,9 @@
many = FALSE
var/type = value["type"]
src << "Finding items"
var/list/items = get_all_of_type(O.type, !method)
src << "Finding items..."
var/list/items = get_all_of_type(O.type, method)
src << "Changing [items.len] items..."
for(var/thing in items)
if (!thing)
continue
@@ -186,8 +169,9 @@
CHECK_TICK
else
src << "Finding items"
var/list/items = get_all_of_type(O.type, !method)
src << "Finding items..."
var/list/items = get_all_of_type(O.type, method)
src << "Changing [items.len] items..."
for(var/thing in items)
if (!thing)
continue
@@ -200,25 +184,24 @@
var/count = rejected+accepted
if (!count)
src << "No objects found"
return
if (!accepted)
if (!rejected)
src << "No objects found"
else
src << "Every object rejected your edit"
//return
src << "Every object rejected your edit"
return
if (rejected)
src << "[rejected] out of [count] objects rejected your edit"
world.log << "### MassVarEdit by [src]: [O.type] (A/R [accepted]/[rejected]) [variable]=[html_encode("[O.vars[variable]]")]([list2params(value)])"
log_admin("[key_name(src)] mass modified [accepted] [original_name]' [variable] to [O.vars[variable]]")
message_admins("[key_name_admin(src)] mass modified [accepted] [original_name]' [variable] to [O.vars[variable]]")
log_admin("[key_name(src)] mass modified [original_name]'s [variable] to [O.vars[variable]] ([accepted] objects modified)")
message_admins("[key_name_admin(src)] mass modified [original_name]'s [variable] to [O.vars[variable]] ([accepted] objects modified)")
/proc/get_all_of_type(var/T, stricttype = FALSE)
/proc/get_all_of_type(var/T, subtypes = TRUE)
var/list/typecache = list()
typecache[T] = 1
if (!stricttype)
if (subtypes)
typecache = typecacheof(typecache)
. = list()
if (ispath(T, /mob))
+143 -44
View File
@@ -57,9 +57,7 @@ var/list/VVpixelmovement = list("step_x", "step_y", "bound_height", "bound_width
VV_MESSAGE,
VV_ICON,
VV_ATOM_REFERENCE,
//#ifdef TESTING
//VV_DATUM_REFERENCE,
//#endif TESTING
VV_DATUM_REFERENCE,
VV_MOB_REFERENCE,
VV_CLIENT,
VV_ATOM_TYPE,
@@ -98,21 +96,27 @@ var/list/VVpixelmovement = list("step_x", "step_y", "bound_height", "bound_width
if (.["value"] == null)
.["class"] = null
return
if (VV_NUM)
.["value"] = input("Enter new number:", "Num", current_value) as null|num
if (.["value"] == null)
.["class"] = null
return
if (VV_ATOM_TYPE)
.["value"] = input("Enter type:", "Type", current_value) as null|anything in get_fancy_list_of_atom_types()
.["value"] = pick_closest_path(FALSE)
if (.["value"] == null)
.["class"] = null
return
if (VV_DATUM_TYPE)
.["value"] = input("Enter type:", "Type", current_value) as null|anything in get_fancy_list_of_datum_types()
.["value"] = pick_closest_path(FALSE, get_fancy_list_of_datum_types())
if (.["value"] == null)
.["class"] = null
return
if (VV_TYPE)
var/type = current_value
do
@@ -125,67 +129,171 @@ var/list/VVpixelmovement = list("step_x", "step_y", "bound_height", "bound_width
.["class"] = null
return
.["value"] = type
if (VV_ATOM_REFERENCE)
.["value"] = input("Select reference:", "Reference", current_value) as null|mob|obj|turf|area in world
if (.["value"] == null)
var/type = pick_closest_path(FALSE)
var/subtypes = vv_subtype_prompt(type)
if (subtypes == null)
.["class"] = null
return
var/list/things = vv_reference_list(type, subtypes)
var/value = input("Select reference:", "Reference", current_value) as null|anything in things
if (!value)
.["class"] = null
return
.["value"] = things[value]
if (VV_DATUM_REFERENCE)
var/type = pick_closest_path(FALSE, get_fancy_list_of_datum_types())
var/subtypes = vv_subtype_prompt(type)
if (subtypes == null)
.["class"] = null
return
var/list/things = vv_reference_list(type, subtypes)
var/value = input("Select reference:", "Reference", current_value) as null|anything in things
if (!value)
.["class"] = null
return
.["value"] = things[value]
if (VV_MOB_REFERENCE)
.["value"] = input("Select reference:", "Reference", current_value) as null|mob in world
if (.["value"] == null)
var/type = pick_closest_path(FALSE, filter_fancy_list(get_fancy_list_of_datum_types(), /mob))
var/subtypes = vv_subtype_prompt(type)
if (subtypes == null)
.["class"] = null
return
var/list/things = vv_reference_list(type, subtypes)
var/value = input("Select reference:", "Reference", current_value) as null|anything in things
if (!value)
.["class"] = null
return
.["value"] = things[value]
if (VV_CLIENT)
.["value"] = input("Select reference:", "Reference", current_value) as null|anything in clients
if (.["value"] == null)
.["class"] = null
return
if (VV_FILE)
.["value"] = input("Pick file:", "File") as null|file
if (.["value"] == null)
.["class"] = null
return
if (VV_ICON)
.["value"] = input("Pick icon:", "Icon") as null|icon
if (.["value"] == null)
.["class"] = null
return
if (VV_MARKED_DATUM)
.["value"] = holder.marked_datum
if (.["value"] == null)
.["class"] = null
return
if (VV_NEW_ATOM)
var/type = input("Enter type:", "Type", current_value) as null|anything in get_fancy_list_of_atom_types()
var/type = pick_closest_path(FALSE)
if (!type)
.["class"] = null
return
.["value"] = new type()
.["type"] = type
.["value"] = new type()
if (VV_NEW_DATUM)
var/type = input("Enter type:", "Type", current_value) as null|anything in get_fancy_list_of_datum_types()
var/type = pick_closest_path(FALSE, get_fancy_list_of_datum_types())
if (!type)
.["class"] = null
return
.["value"] = new type()
.["type"] = type
.["value"] = new type()
if (VV_NEW_TYPE)
var/type = current_value
var/error = ""
do
type = input("Enter type:", "Type", type) as null|text
type = input("Enter type:[error]", "Type", type) as null|text
if (!type)
break
type = text2path(type)
error = "\nType not found, Please try again"
while(!type)
if (!type)
.["class"] = null
return
.["value"] = new type()
.["type"] = type
.["value"] = new type()
if (VV_NEW_LIST)
.["value"] = list()
.["type"] = /list
/client/proc/vv_parse_text(O, new_var)
if(O && findtext(new_var,"\["))
var/process_vars = alert(usr,"\[] detected in string, process as variables?","Process Variables?","Yes","No")
if(process_vars == "Yes")
. = string2listofvars(new_var, O)
//do they want you to include subtypes?
//FALSE = no subtypes, strict exact type pathing (or the type doesn't have subtypes)
//TRUE = Yes subtypes
//NULL = User cancelled at the prompt or invalid type given
/client/proc/vv_subtype_prompt(var/type)
if (!ispath(type))
return
var/list/subtypes = subtypesof(type)
if (!subtypes || !subtypes.len)
return FALSE
if (subtypes && subtypes.len)
switch(alert("Strict object type detection?", "Type detection", "Strictly this type","This type and subtypes", "Cancel"))
if("Strictly this type")
return FALSE
if("This type and subtypes")
return TRUE
else
return
/client/proc/vv_reference_list(type, subtypes)
. = list()
var/list/types = list(type)
if (subtypes)
types = typesof(type)
var/list/fancytypes = make_types_fancy(types)
for(var/fancytype in fancytypes) //swap the assoication
types[fancytypes[fancytype]] = fancytype
var/things = get_all_of_type(type, subtypes)
var/i = 0
for(var/thing in things)
var/datum/D = thing
i++
//try one of 3 methods to shorten the type text:
// fancy type,
// fancy type with the base type removed from the begaining,
// the type with the base type removed from the begaining
var/fancytype = types[D.type]
if (findtext(fancytype, types[type]))
fancytype = copytext(fancytype, lentext(types[type])+1)
var/shorttype = copytext("[D.type]", lentext("[type]")+1)
if (lentext(shorttype) > lentext(fancytype))
shorttype = fancytype
if (!lentext(shorttype))
shorttype = "/"
.["[D]([shorttype])\ref[D]#[i]"] = D
/client/proc/mod_list_add_ass(atom/O) //hehe
var/list/L = vv_get_value(restricted_classes = list(VV_RESTORE_DEFAULT))
@@ -195,12 +303,9 @@ var/list/VVpixelmovement = list("step_x", "step_y", "bound_height", "bound_width
var/var_value = L["value"]
if(class == VV_TEXT || class == VV_MESSAGE)
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]]")
var/list/varsvars = vv_parse_text(O, var_value)
for(var/V in varsvars)
var_value = replacetext(var_value,"\[[V]]","[O.vars[V]]")
return var_value
@@ -213,12 +318,9 @@ var/list/VVpixelmovement = list("step_x", "step_y", "bound_height", "bound_width
var/var_value = LL["value"]
if(class == VV_TEXT || class == VV_MESSAGE)
if(O && 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]]")
var/list/varsvars = vv_parse_text(O, var_value)
for(var/V in varsvars)
var_value = replacetext(var_value,"\[[V]]","[O.vars[V]]")
var/list/newlist = L.Copy()
newlist += var_value
@@ -248,9 +350,15 @@ var/list/VVpixelmovement = list("step_x", "step_y", "bound_height", "bound_width
var/list/names = null
var/list/names = list()
for (var/i in 1 to L.len)
names["#[i] [L[i]] = [L[L[i]]]"] = i
var/key = L[i]
var/value
if (IS_NORMAL_LIST(L) && !isnum(key))
value = L[key]
if (value == null)
value = "null"
names["#[i] [key] = [value]"] = i
if (!index)
var/variable = input("Which var?","Var") as null|anything in names + "(ADD VAR)" + "(CLEAR NULLS)" + "(CLEAR DUPES)" + "(SHUFFLE)"
@@ -370,12 +478,9 @@ var/list/VVpixelmovement = list("step_x", "step_y", "bound_height", "bound_width
return
if(VV_TEXT)
if(O && 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]]")
var/list/varsvars = vv_parse_text(O, new_var)
for(var/V in varsvars)
new_var = replacetext(new_var,"\[[V]]","[O.vars[V]]")
if(assoc)
@@ -475,9 +580,6 @@ var/list/VVpixelmovement = list("step_x", "step_y", "bound_height", "bound_width
var/original_name = "[O]"
if(holder.marked_datum && class == "marked datum ([holder.marked_datum.type])")
class = "marked datum"
switch(class)
if(VV_LIST)
if(!istype(var_value,/list))
@@ -490,12 +592,9 @@ var/list/VVpixelmovement = list("step_x", "step_y", "bound_height", "bound_width
var_new = initial(O.vars[variable])
if(VV_TEXT)
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]]")
var/list/varsvars = vv_parse_text(O, var_new)
for(var/V in varsvars)
var_new = replacetext(var_new,"\[[V]]","[O.vars[V]]")
if (O.vv_edit_var(variable, var_new) == FALSE)