From 84acff1107021c28e9e40eade9c5f694b3f7cacb Mon Sep 17 00:00:00 2001 From: PJB3005 Date: Sun, 14 Aug 2016 20:19:15 +0200 Subject: [PATCH] Allows admins to edit transform matrices. (#11226) * Allows admins to edit transform matrices. * Manual and reset. * Fix non-numbers. --- code/__HELPERS/_macros.dm | 2 + code/datums/datumvars.dm | 20 ++++++- code/modules/admin/verbs/massmodvar.dm | 51 +++++++++++++++- code/modules/admin/verbs/modifyvariables.dm | 65 ++++++++++++++++++++- 4 files changed, 133 insertions(+), 5 deletions(-) diff --git a/code/__HELPERS/_macros.dm b/code/__HELPERS/_macros.dm index 6da4a840157..908ec031ea0 100644 --- a/code/__HELPERS/_macros.dm +++ b/code/__HELPERS/_macros.dm @@ -133,6 +133,8 @@ #define isatom(A) (istype(A, /atom)) +#define ismatrix(A) (istype(A, /matrix)) + //Macros for antags #define isvampire(H) ((H.mind in ticker.mode.vampires) || H.mind.vampire) diff --git a/code/datums/datumvars.dm b/code/datums/datumvars.dm index e4c32df0dd1..e8b07085902 100644 --- a/code/datums/datumvars.dm +++ b/code/datums/datumvars.dm @@ -262,6 +262,9 @@ if(istype(D,/atom)) body += "" + if (hasvar(D, "transform")) + body += "" + body += "" body += "" @@ -1021,4 +1024,19 @@ body callatomproc(DAT) //Yes it could be a datum, technically but eh - return + else if (href_list["edit_transform"]) + if (!check_rights(R_DEBUG)) + return + + var/datum/DAT = locate(href_list["edit_transform"]) + if (!hasvar(DAT, "transform")) + to_chat(src, "This object does not have a transform variable to edit!") + return + + var/matrix/M = DAT.vars["transform"] // It's like using a colon but without the colon! + + if (!istype(M)) + to_chat(src, "Transform is not set to a /matrix.") + return + + DAT.vars["transform"] = modify_matrix_menu(M) diff --git a/code/modules/admin/verbs/massmodvar.dm b/code/modules/admin/verbs/massmodvar.dm index 69da4fe5a0d..f740f49f105 100644 --- a/code/modules/admin/verbs/massmodvar.dm +++ b/code/modules/admin/verbs/massmodvar.dm @@ -76,6 +76,10 @@ var_value = "[bicon(var_value)]" default = "icon" + else if(ismatrix(var_value)) + to_chat(usr, "Variable appears to be MATRIX.") + default = "matrix" + else if(istype(var_value,/atom) || istype(var_value,/datum)) to_chat(usr, "Variable appears to be TYPE.") default = "type" @@ -117,7 +121,7 @@ to_chat(usr, "If a direction, direction is: [dir]") var/class = input("What kind of variable?","Variable Type",default) as null|anything in list("text", - "num","type","icon","file","edit referenced object","restore to default") + "num","type","icon","file","matrix", "edit referenced object","restore to default") if(!class) return @@ -441,5 +445,48 @@ if (A.type == O.type) A.vars[variable] = O.vars[variable] + if ("matrix") + var/matrix/new_value = modify_matrix_menu(O.vars[variable], verbose = FALSE) + if (!new_value) + return + + O.vars[variable] = new_value + if(method) + if(istype(O, /mob)) + for(var/mob/M in mob_list) + if ( istype(M , O.type) ) + M.vars[variable] = O.vars[variable] + + else if(istype(O, /obj)) + for(var/obj/A in world) + if ( istype(A , O.type) ) + A.vars[variable] = O.vars[variable] + + else if(istype(O, /turf)) + var/count = 0 + for(var/turf/A in turfs) + count++ + if(!(count % 50000)) sleep(world.tick_lag) + if ( istype(A , O.type) ) + A.vars[variable] = O.vars[variable] + else + if(istype(O, /mob)) + for(var/mob/M in mob_list) + if (M.type == O.type) + M.vars[variable] = O.vars[variable] + + else if(istype(O, /obj)) + for(var/obj/A in world) + if (A.type == O.type) + A.vars[variable] = O.vars[variable] + + else if(istype(O, /turf)) + var/count = 0 + for(var/turf/A in turfs) + count++ + if(!(count % 50000)) sleep(world.tick_lag) + if (A.type == O.type) + A.vars[variable] = O.vars[variable] + log_admin("[key_name(src)] mass modified [original_name]'s [variable] to [O.vars[variable]]") - message_admins("[key_name_admin(src)] mass modified [original_name]'s [variable] to [O.vars[variable]]", 1) \ No newline at end of file + message_admins("[key_name_admin(src)] mass modified [original_name]'s [variable] to [O.vars[variable]]", 1) diff --git a/code/modules/admin/verbs/modifyvariables.dm b/code/modules/admin/verbs/modifyvariables.dm index b81f4270865..748480ce9b2 100644 --- a/code/modules/admin/verbs/modifyvariables.dm +++ b/code/modules/admin/verbs/modifyvariables.dm @@ -367,6 +367,10 @@ var/list/forbidden_varedit_object_types = list( var_value = "[bicon(var_value)]" class = "icon" + else if(ismatrix(var_value)) + to_chat(usr, "Variable appears to be MATRIX.") + class = "matrix" + else if(istype(var_value,/atom) || istype(var_value,/datum)) to_chat(usr, "Variable appears to be TYPE.") class = "type" @@ -423,6 +427,10 @@ var/list/forbidden_varedit_object_types = list( var_value = "[bicon(var_value)]" default = "icon" + else if(ismatrix(var_value)) + to_chat(usr, "Variable appears to be MATRIX.") + default = "matrix" + else if(istype(var_value,/atom) || istype(var_value,/datum)) to_chat(usr, "Variable appears to be TYPE.") default = "type" @@ -465,10 +473,10 @@ var/list/forbidden_varedit_object_types = list( if(src.holder && src.holder.marked_datum) class = input("What kind of variable?","Variable Type",default) as null|anything in list("text", - "num","type","reference","mob reference", "icon","file","list","edit referenced object","restore to default","marked datum ([holder.marked_datum.type])") + "num","type","reference","mob reference", "icon","file","list","matrix","edit referenced object","restore to default","marked datum ([holder.marked_datum.type])") else class = input("What kind of variable?","Variable Type",default) as null|anything in list("text", - "num","type","reference","mob reference", "icon","file","list","edit referenced object","restore to default") + "num","type","reference","mob reference", "icon","file","list","matrix","edit referenced object","restore to default") if(!class) return @@ -560,7 +568,60 @@ var/list/forbidden_varedit_object_types = list( if("marked datum") O.vars[variable] = holder.marked_datum + if("matrix") + var/matrix/var_new = modify_matrix_menu(O.vars[variable]) + if (!var_new) + return + + O.vars[variable] = var_new + 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]]", 1) +/client/proc/modify_matrix_menu(var/matrix/M = matrix(), var/verbose = TRUE) + if (verbose) + to_chat(src, "Current matrix: a: [M.a], b: [M.b], c: [M.c], d: [M.d], e: [M.e], f: [M.f].") + + var/input = input("Which action do you want to apply to this matrix?") as null|anything in list("Scale", "Translate", "Turn", "Manual","Reset") + if (!input) + return + + switch (input) + if ("Scale") + var/x = input("X scale") as num + var/y = input("Y scale") as num + + M.Scale(x, y) + + if ("Translate") + var/x = input("X amount") as num + var/y = input("Y amount") as num + + M.Translate(x, y) + + if ("Turn") + var/angle = input("Angle (clockwise)") as num + + M.Turn(angle) + + if ("Reset") + M = matrix() + + if ("Manual") + var/list/numbers = splittext(input("Enter the matrix components as a comma separated list.") as text|null, ",") + if (!numbers || numbers.len != 6) + to_chat(src, "Cancelled or not enough arguments provided.") + + else + var/list/newnumbers = list() + for (var/number in numbers) + number = text2num(number) || 0 + newnumbers += number + + M = matrix(newnumbers[1], newnumbers[2], newnumbers[3], newnumbers[4], newnumbers[5], newnumbers[6]) + + if (verbose) + to_chat(src, "New matrix: a: [M.a], b: [M.b], c: [M.c], d: [M.d], e: [M.e], f: [M.f].") + + return M