Files
Bubberstation/code/modules/buildmode/bm_mode.dm
Watermelon914 375a20e49b Refactors most spans into span procs (#59645)
Converts most spans into span procs. Mostly used regex for this and sorted out any compile time errors afterwards so there could be some bugs.
Was initially going to do defines, but ninja said to make it into a proc, and if there's any overhead, they can easily be changed to defines.

Makes it easier to control the formatting and prevents typos when creating spans as it'll runtime if you misspell instead of silently failing.
Reduces the code you need to write when writing spans, as you don't need to close the span as that's automatically handled by the proc.

(Note from Lemon: This should be converted to defines once we update the minimum version to 514. Didn't do it now because byond pain and such)
2021-06-14 13:03:53 -07:00

91 lines
2.3 KiB
Plaintext

/datum/buildmode_mode
var/key = "oops"
var/datum/buildmode/BM
// would corner selection work better as a component?
var/use_corner_selection = FALSE
var/list/preview
var/turf/cornerA
var/turf/cornerB
/datum/buildmode_mode/New(datum/buildmode/BM)
src.BM = BM
preview = list()
return ..()
/datum/buildmode_mode/Destroy()
cornerA = null
cornerB = null
QDEL_LIST(preview)
preview = null
return ..()
/datum/buildmode_mode/proc/enter_mode(datum/buildmode/BM)
return
/datum/buildmode_mode/proc/exit_mode(datum/buildmode/BM)
return
/datum/buildmode_mode/proc/get_button_iconstate()
return "buildmode_[key]"
/datum/buildmode_mode/proc/show_help(client/c)
CRASH("No help defined, yell at a coder")
/datum/buildmode_mode/proc/change_settings(client/c)
to_chat(c, span_warning("There is no configuration available for this mode"))
return
/datum/buildmode_mode/proc/Reset()
deselect_region()
/datum/buildmode_mode/proc/select_tile(turf/T, corner_to_select)
var/overlaystate
BM.holder.images -= preview
switch(corner_to_select)
if(AREASELECT_CORNERA)
overlaystate = "greenOverlay"
if(AREASELECT_CORNERB)
overlaystate = "blueOverlay"
var/image/I = image('icons/turf/overlays.dmi', T, overlaystate)
I.plane = ABOVE_LIGHTING_PLANE
preview += I
BM.holder.images += preview
return T
/datum/buildmode_mode/proc/highlight_region(region)
BM.holder.images -= preview
for(var/t in region)
var/image/I = image('icons/turf/overlays.dmi', t, "redOverlay")
I.plane = ABOVE_LIGHTING_PLANE
preview += I
BM.holder.images += preview
/datum/buildmode_mode/proc/deselect_region()
BM.holder.images -= preview
preview.Cut()
cornerA = null
cornerB = null
/datum/buildmode_mode/proc/handle_click(client/c, params, object)
var/list/modifiers = params2list(params)
if(use_corner_selection)
if(LAZYACCESS(modifiers, LEFT_CLICK))
if(!cornerA)
cornerA = select_tile(get_turf(object), AREASELECT_CORNERA)
return
if(cornerA && !cornerB)
cornerB = select_tile(get_turf(object), AREASELECT_CORNERB)
to_chat(c, span_boldwarning("Region selected, if you're happy with your selection left click again, otherwise right click."))
return
handle_selected_area(c, params)
deselect_region()
else
to_chat(c, span_notice("Region selection canceled!"))
deselect_region()
return
/datum/buildmode_mode/proc/handle_selected_area(client/c, params)