mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-14 19:03:21 +00:00
# MAINTAINER - USE THE BUTTON THAT SAYS "MERGE MASTER" THEN SET THE PR TO AUTO-MERGE! IT'S MUCH EASIER FOR ME TO FIX THINGS BEFORE THEY SKEW RATHER THAN AFTER THE FACT. ## About The Pull Request Hey there, This took a while to do, but here's the gist: Python file now regexes every file in `/code` except for those that have some valid reason to be tacking on more global defines. Some of those reasons are simply just that I don't have the time right now (doing what you see in this PR took a few hours) to refactor and parse what should belong and what should be thrown out. For the time being though, this PR will at least _halt_ people making the mistake of not `#undef`ing any files they `#define` "locally", or within the scope of a file. Most people forget to do this and this leads to a lot of mess later on due to how many variables can be unmanaged on the global level. I've made this mistake, you've made this mistake, it's a common thing. Let's automatically check for it so it can be fixed no-stress. Scenarios this PR corrects: * Forgetting to undef a define but undeffing others. * Not undeffing any defines in your file. * Earmarking a define as a "file local" define, but not defining it. * Having a define be a "file local" define, but having it be used elsewhere. * Having a "local" define not even be in the file that it only shows up in. * Having a completely unused define* (* I kept some of these because they seemed important... Others were junked.) ## Why It's Good For The Game If you wanna use it across multiple files, no reason to not make it a global define (maybe there's a few reasons but let's assume that this is the 95% case). Let me know if you don't like how I re-arranged some of the defines and how you'd rather see it be implemented, and I'd be happy to do that. This was mostly just "eh does it need it or not" sorta stuff. I used a pretty cool way to detect if we should use the standardized GitHub "error" output, you can see the results of that here https://github.com/san7890/bruhstation/actions/runs/4549766579/jobs/8022186846#step:7:792 ## Changelog Nothing that really concerns players. (I fixed up all this stuff using vscode, no regexes beyond what you see in the python script. sorry downstreams)
158 lines
4.1 KiB
Plaintext
158 lines
4.1 KiB
Plaintext
/datum/component/construction
|
|
var/list/steps
|
|
var/result
|
|
var/index = 1
|
|
var/desc
|
|
|
|
/datum/component/construction/Initialize()
|
|
if(!isatom(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
|
|
RegisterSignal(parent, COMSIG_PARENT_EXAMINE, PROC_REF(examine))
|
|
RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, PROC_REF(action))
|
|
update_parent(index)
|
|
|
|
/datum/component/construction/proc/examine(datum/source, mob/user, list/examine_list)
|
|
SIGNAL_HANDLER
|
|
|
|
if(desc)
|
|
examine_list += desc
|
|
|
|
/datum/component/construction/proc/on_step()
|
|
if(index > steps.len)
|
|
spawn_result()
|
|
else
|
|
update_parent(index)
|
|
|
|
/datum/component/construction/proc/action(datum/source, obj/item/I, mob/living/user)
|
|
SIGNAL_HANDLER
|
|
ASYNC //This proc will never actually sleep, it calls do_after with a time of 0.
|
|
. = check_step(I, user)
|
|
return .
|
|
|
|
/datum/component/construction/proc/update_index(diff)
|
|
index += diff
|
|
on_step()
|
|
|
|
/datum/component/construction/proc/check_step(obj/item/I, mob/living/user)
|
|
var/diff = is_right_key(I)
|
|
if(diff && custom_action(I, user, diff))
|
|
update_index(diff)
|
|
return TRUE
|
|
return FALSE
|
|
|
|
/datum/component/construction/proc/is_right_key(obj/item/I) // returns index step
|
|
var/list/L = steps[index]
|
|
if(check_used_item(I, L["key"]))
|
|
return FORWARD //to the first step -> forward
|
|
else if(check_used_item(I, L["back_key"]))
|
|
return BACKWARD //to the last step -> backwards
|
|
return FALSE
|
|
|
|
/datum/component/construction/proc/check_used_item(obj/item/I, key)
|
|
if(!key)
|
|
return FALSE
|
|
|
|
if(ispath(key) && istype(I, key))
|
|
return TRUE
|
|
|
|
else if(I.tool_behaviour == key)
|
|
return TRUE
|
|
|
|
return FALSE
|
|
|
|
/datum/component/construction/proc/custom_action(obj/item/I, mob/living/user, diff)
|
|
var/target_index = index + diff
|
|
var/list/current_step = steps[index]
|
|
var/list/target_step
|
|
|
|
if(target_index > 0 && target_index <= steps.len)
|
|
target_step = steps[target_index]
|
|
|
|
. = TRUE
|
|
|
|
if(I.tool_behaviour)
|
|
. = I.use_tool(parent, user, 0, volume=50)
|
|
|
|
else if(diff == FORWARD)
|
|
switch(current_step["action"])
|
|
if(ITEM_DELETE)
|
|
. = user.transferItemToLoc(I, parent)
|
|
if(.)
|
|
qdel(I)
|
|
|
|
if(ITEM_MOVE_INSIDE)
|
|
. = user.transferItemToLoc(I, parent)
|
|
|
|
// Using stacks
|
|
else
|
|
if(isstack(I))
|
|
. = I.use_tool(parent, user, 0, volume=50, amount=current_step["amount"])
|
|
|
|
|
|
// Going backwards? Undo the last action. Drop/respawn the items used in last action, if any.
|
|
if(. && diff == BACKWARD && target_step && !target_step["no_refund"])
|
|
var/target_step_key = target_step["key"]
|
|
|
|
switch(target_step["action"])
|
|
if(ITEM_DELETE)
|
|
new target_step_key(drop_location())
|
|
|
|
if(ITEM_MOVE_INSIDE)
|
|
var/obj/item/located_item = locate(target_step_key) in parent
|
|
if(located_item)
|
|
located_item.forceMove(drop_location())
|
|
|
|
else
|
|
if(ispath(target_step_key, /obj/item/stack))
|
|
new target_step_key(drop_location(), target_step["amount"])
|
|
|
|
/datum/component/construction/proc/spawn_result()
|
|
// Some constructions result in new components being added.
|
|
if(ispath(result, /datum/component))
|
|
parent.AddComponent(result)
|
|
qdel(src)
|
|
|
|
else if(ispath(result, /atom))
|
|
new result(drop_location())
|
|
qdel(parent)
|
|
|
|
/datum/component/construction/proc/update_parent(step_index)
|
|
var/list/step = steps[step_index]
|
|
var/atom/parent_atom = parent
|
|
|
|
if(step["desc"])
|
|
desc = step["desc"]
|
|
|
|
if(step["icon_state"])
|
|
parent_atom.icon_state = step["icon_state"]
|
|
|
|
/datum/component/construction/proc/drop_location()
|
|
var/atom/parent_atom = parent
|
|
return parent_atom.drop_location()
|
|
|
|
|
|
|
|
// Unordered construction.
|
|
// Takes a list of part types, to be added in any order, as steps.
|
|
// Calls spawn_result() when every type has been added.
|
|
/datum/component/construction/unordered/check_step(obj/item/I, mob/living/user)
|
|
for(var/typepath in steps)
|
|
if(istype(I, typepath) && custom_action(I, user, typepath))
|
|
steps -= typepath
|
|
on_step()
|
|
return TRUE
|
|
return FALSE
|
|
|
|
/datum/component/construction/unordered/on_step()
|
|
if(!steps.len)
|
|
spawn_result()
|
|
else
|
|
update_parent(steps.len)
|
|
|
|
/datum/component/construction/unordered/update_parent(steps_left)
|
|
return
|
|
|
|
/datum/component/construction/unordered/custom_action(obj/item/I, mob/living/user, typepath)
|
|
return TRUE
|