Skip to content

Commit

Permalink
[MIRROR] General maintainence for Ore Silo (#616)
Browse files Browse the repository at this point in the history
* General maintainence for Ore Silo (#81016)

## About The Pull Request
1. **Qol**(Hopefully not an issue for feature freeze)
- Adds Screen tips & examines for screwdriver, crowbar & multitool acts
   - Examining ore silo will now display its stored materials
- Location name is attached to the machine name and it greys out when
pausing the machine to make it more noticable that it is paused
   - Made window wider

2. **Code Improvements**
   - Auto docs procs & vars for ore silo log entry
- Fixed return values of all tool acts i.e. no more returning
`TRUE/FALSE` but the actual item interaction flags
- UI no longer computes `REF` for each machine which is expensive but
instead uses the index value in the list
   - Moved global variables to their corresponding files
- Ore silo no longer starts processing round start. That proc just ended
itself anyway so why even bother registering

3. **Fixes**
- If a machine was disconnected via the ore silo UI, attempting to
reconnect that machine would cause a runtime at `RegisterSignal` in
`multitool_act` because it was already registered in `Initialize`. It
now unregisters the signal when disconnecting so that's fixed
- Each machine element in the UI does not have a unique key because it
used `key={machine.name}`. This meant after disconnecting a machine the
UI buttons would get grouped together and the pause & disconnect buttons
would not function properly. Now it uses `index` which is unique thus
fixing that problem

## Changelog
:cl:
qol: added more screen tips & examines for ore silo, made UI wider,
attach location name to each machine & grey out paused machines to make
it more noticeable.
code: auto docs proc & vars for silo log entry. Fixed return values of
all tool acts
fix: ore silo UI now functions correctly after removing an entry from
the UI
fix: no runtimes when connecting a machine to silo that was previously
disconnected via the ore silo UI
/:cl:

* General maintainence for Ore Silo

---------

Co-authored-by: SyncIt21 <[email protected]>
  • Loading branch information
2 people authored and FFMirrorBot committed Jan 25, 2024
1 parent c18c4c3 commit 9b6e993
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 67 deletions.
2 changes: 2 additions & 0 deletions code/_globalvars/lists/silo.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
///List of logs shared by all silos
GLOBAL_LIST_EMPTY(silo_access_logs)
2 changes: 2 additions & 0 deletions code/_globalvars/silo.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
///The global ore silo shared by all machines at round start
GLOBAL_DATUM(ore_silo_default, /obj/machinery/ore_silo)
4 changes: 3 additions & 1 deletion code/datums/components/material/remote_materials.dm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ handles linking back and forth.
silo.ore_connected_machines -= src
silo.holds -= src
silo = null
UnregisterSignal(parent, COMSIG_ATOM_ATTACKBY)
mat_container = null
return ..()

Expand Down Expand Up @@ -134,6 +135,7 @@ handles linking back and forth.
silo.ore_connected_machines -= src
silo = null
mat_container = null
UnregisterSignal(parent, COMSIG_ATOM_ATTACKBY)
if (allow_standalone)
_MakeLocal()

Expand Down Expand Up @@ -185,7 +187,7 @@ handles linking back and forth.
if(!(mat_container_flags & MATCONTAINER_NO_INSERT))
RegisterSignal(parent, COMSIG_ATOM_ATTACKBY, TYPE_PROC_REF(/datum/component/remote_materials, SiloAttackBy))
to_chat(user, span_notice("You connect [parent] to [silo] from the multitool's buffer."))
return ITEM_INTERACT_BLOCKING
return ITEM_INTERACT_SUCCESS

/**
* Checks if the param silo is in the same level as this components parent i.e. connected machine, rcd, etc
Expand Down
170 changes: 118 additions & 52 deletions code/modules/mining/machine_silo.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
GLOBAL_DATUM(ore_silo_default, /obj/machinery/ore_silo)
GLOBAL_LIST_EMPTY(silo_access_logs)

/obj/machinery/ore_silo
name = "ore silo"
desc = "An all-in-one bluespace storage and transmission system for the station's mineral distribution needs."
Expand All @@ -9,9 +6,8 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
density = TRUE
circuit = /obj/item/circuitboard/machine/ore_silo
interaction_flags_machine = INTERACT_MACHINE_WIRES_IF_OPEN|INTERACT_MACHINE_ALLOW_SILICON|INTERACT_MACHINE_OPEN_SILICON
processing_flags = NONE

/// The machine UI's page of logs showing ore history.
var/log_page = 1
/// List of all connected components that are on hold from accessing materials.
var/list/holds = list()
/// List of all components that are sharing ores with this silo.
Expand All @@ -21,6 +17,7 @@ GLOBAL_LIST_EMPTY(silo_access_logs)

/obj/machinery/ore_silo/Initialize(mapload)
. = ..()

var/static/list/materials_list = list(
/datum/material/iron,
/datum/material/glass,
Expand All @@ -38,6 +35,7 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
/datum/component/material_container, \
materials_list, \
INFINITY, \
MATCONTAINER_EXAMINE, \
container_signals = list( \
COMSIG_MATCONTAINER_ITEM_CONSUMED = TYPE_PROC_REF(/obj/machinery/ore_silo, on_item_consumed), \
COMSIG_MATCONTAINER_SHEETS_RETRIEVED = TYPE_PROC_REF(/obj/machinery/ore_silo, log_sheets_ejected), \
Expand All @@ -46,6 +44,7 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
)
if (!GLOB.ore_silo_default && mapload && is_station_level(z))
GLOB.ore_silo_default = src
register_context()

/obj/machinery/ore_silo/Destroy()
if (GLOB.ore_silo_default == src)
Expand All @@ -59,6 +58,30 @@ GLOBAL_LIST_EMPTY(silo_access_logs)

return ..()

/obj/machinery/ore_silo/examine(mob/user)
. = ..()
. += span_notice("It can be linked to techfabs, circuit printers and protolathes with a multitool.")
. += span_notice("Its maintainence panel can be [EXAMINE_HINT("screwed")] [panel_open ? "closed" : "open"].")
if(panel_open)
. += span_notice("The whole machine can be [EXAMINE_HINT("pried")] apart.")

/obj/machinery/ore_silo/add_context(atom/source, list/context, obj/item/held_item, mob/user)
. = NONE
if(isnull(held_item))
return

if(held_item.tool_behaviour == TOOL_SCREWDRIVER)
context[SCREENTIP_CONTEXT_LMB] = "[panel_open ? "Close" : "Open"] Panel"
return CONTEXTUAL_SCREENTIP_SET

if(held_item.tool_behaviour == TOOL_MULTITOOL)
context[SCREENTIP_CONTEXT_LMB] = "Log Silo"
return CONTEXTUAL_SCREENTIP_SET

if(panel_open && held_item.tool_behaviour == TOOL_CROWBAR)
context[SCREENTIP_CONTEXT_LMB] = "Deconstruct"
return CONTEXTUAL_SCREENTIP_SET

/obj/machinery/ore_silo/proc/on_item_consumed(datum/component/material_container/container, obj/item/item_inserted, last_inserted_id, mats_consumed, amount_inserted, atom/context)
SIGNAL_HANDLER

Expand All @@ -72,10 +95,19 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
silo_log(context, "ejected", -sheets.amount, "[sheets.singular_name]", sheets.custom_materials)

/obj/machinery/ore_silo/screwdriver_act(mob/living/user, obj/item/tool)
return default_deconstruction_screwdriver(user, icon_state, icon_state, tool)
. = ITEM_INTERACT_BLOCKING
if(default_deconstruction_screwdriver(user, icon_state, icon_state, tool))
return ITEM_INTERACT_SUCCESS

/obj/machinery/ore_silo/crowbar_act(mob/living/user, obj/item/tool)
return default_deconstruction_crowbar(tool)
. = ITEM_INTERACT_BLOCKING
if(default_deconstruction_crowbar(tool))
return ITEM_INTERACT_SUCCESS

/obj/machinery/ore_silo/multitool_act(mob/living/user, obj/item/multitool/I)
I.set_buffer(src)
balloon_alert(user, "saved to multitool buffer")
return ITEM_INTERACT_SUCCESS

/obj/machinery/ore_silo/ui_assets(mob/user)
return list(
Expand All @@ -92,37 +124,35 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
return materials.ui_static_data()

/obj/machinery/ore_silo/ui_data(mob/user)
var/list/data = list(
"materials" = materials.ui_data()
)
var/list/data = list()

data["materials"] = materials.ui_data()

var/list/connected_data
data["machines"] = list()
for(var/datum/component/remote_materials/remote as anything in ore_connected_machines)
var/atom/parent = remote.parent
var/icon/parent_icon = icon(initial(parent.icon), initial(parent.icon_state), frame = 1)
var/list/remote_data = list(
"ref" = REF(remote),
"icon" = icon2base64(parent_icon),
"name" = parent.name,
"onHold" = holds[remote] ? TRUE : FALSE,
"location" = get_area_name(parent, TRUE)
data["machines"] += list(
list(
"icon" = icon2base64(icon(initial(parent.icon), initial(parent.icon_state), frame = 1)),
"name" = parent.name,
"onHold" = !!holds[remote],
"location" = get_area_name(parent, TRUE)
)
)
LAZYADD(connected_data, list(remote_data))
LAZYSET(data, "machines", connected_data)

var/list/logs_data
data["logs"] = list()
for(var/datum/ore_silo_log/entry as anything in GLOB.silo_access_logs[REF(src)])
var/list/log_data = list(
"rawMaterials" = entry.get_raw_materials(""),
"machineName" = entry.machine_name,
"areaName" = entry.area_name,
"action" = entry.action,
"amount" = entry.amount,
"time" = entry.timestamp,
"noun" = entry.noun
data["logs"] += list(
list(
"rawMaterials" = entry.get_raw_materials(""),
"machineName" = entry.machine_name,
"areaName" = entry.area_name,
"action" = entry.action,
"amount" = entry.amount,
"time" = entry.timestamp,
"noun" = entry.noun
)
)
LAZYADD(logs_data, list(log_data))
LAZYSET(data, "logs", logs_data)

return data

Expand All @@ -133,31 +163,53 @@ GLOBAL_LIST_EMPTY(silo_access_logs)

switch(action)
if("remove")
var/datum/component/remote_materials/remote = locate(params["ref"]) in ore_connected_machines
remote?.disconnect_from(src)
var/index = params["id"]
if(isnull(index))
return

index = text2num(index)
if(isnull(index))
return

var/datum/component/remote_materials/remote = ore_connected_machines[index]
if(isnull(remote))
return

remote.disconnect_from(src)
return TRUE

if("hold")
var/datum/component/remote_materials/remote = locate(params["ref"]) in ore_connected_machines
remote?.toggle_holding()
var/index = params["id"]
if(isnull(index))
return

index = text2num(index)
if(isnull(index))
return

var/datum/component/remote_materials/remote = ore_connected_machines[index]
if(isnull(remote))
return

remote.toggle_holding()
return TRUE

if("eject")
var/datum/material/ejecting = locate(params["ref"])
var/amount = text2num(params["amount"])
if(!isnum(amount) || !istype(ejecting))
return TRUE
if(!istype(ejecting))
return

var/amount = params["amount"]
if(isnull(amount))
return

amount = text2num(amount)
if(isnull(amount))
return

materials.retrieve_sheets(amount, ejecting, drop_location())
return TRUE

/obj/machinery/ore_silo/multitool_act(mob/living/user, obj/item/multitool/I)
. = ..()
if (istype(I))
I.set_buffer(src)
balloon_alert(user, "saved to multitool buffer")
return TRUE

/**
* Creates a log entry for depositing/withdrawing from the silo both ingame and in text based log
*
Expand All @@ -171,6 +223,7 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
/obj/machinery/ore_silo/proc/silo_log(obj/machinery/M, action, amount, noun, list/mats)
if (!length(mats))
return

var/datum/ore_silo_log/entry = new(M, action, amount, noun, mats)
var/list/datum/ore_silo_log/logs = GLOB.silo_access_logs[REF(src)]
if(!LAZYLEN(logs))
Expand All @@ -180,20 +233,21 @@ GLOBAL_LIST_EMPTY(silo_access_logs)

flick("silo_active", src)

/obj/machinery/ore_silo/examine(mob/user)
. = ..()
. += span_notice("[src] can be linked to techfabs, circuit printers and protolathes with a multitool.")

///The log entry for an ore silo action
/datum/ore_silo_log
var/name // for VV
var/formatted // for display

///The time of action
var/timestamp
///The name of the machine that remotely acted on the ore silo
var/machine_name
///The area of the machine that remotely acted on the ore silo
var/area_name
///The actual action performed by the machine
var/action
///An short verb describing the action
var/noun
///The amount of items affected by this action e.g. print quantity, sheets ejected etc.
var/amount
///List of individual materials used in the action
var/list/materials

/datum/ore_silo_log/New(obj/machinery/M, _action, _amount, _noun, list/mats=list())
Expand All @@ -219,6 +273,12 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
data,
)

/**
* Merges a silo log entry with this one
* Arguments
*
* * datum/ore_silo_log/other - the other silo entry we are trying to merge with this one
*/
/datum/ore_silo_log/proc/merge(datum/ore_silo_log/other)
if (other == src || action != other.action || noun != other.noun)
return FALSE
Expand All @@ -231,6 +291,12 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
materials[each] += other.materials[each]
return TRUE

/**
* Returns list/materials but with each entry joined by an seperator to create 1 string
* Arguments
*
* * separator - the string used to concatenate all entries in list/materials
*/
/datum/ore_silo_log/proc/get_raw_materials(separator)
var/list/msg = list()
for(var/key in materials)
Expand Down
2 changes: 2 additions & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@
#include "code\_globalvars\phobias.dm"
#include "code\_globalvars\rcd.dm"
#include "code\_globalvars\religion.dm"
#include "code\_globalvars\silo.dm"
#include "code\_globalvars\tgui.dm"
#include "code\_globalvars\time_vars.dm"
#include "code\_globalvars\lists\achievements.dm"
Expand All @@ -635,6 +636,7 @@
#include "code\_globalvars\lists\rcd.dm"
#include "code\_globalvars\lists\reagents.dm"
#include "code\_globalvars\lists\rtd.dm"
#include "code\_globalvars\lists\silo.dm"
#include "code\_globalvars\lists\typecache.dm"
#include "code\_globalvars\lists\wiremod.dm"
#include "code\_globalvars\lists\xenobiology.dm"
Expand Down
Loading

0 comments on commit 9b6e993

Please sign in to comment.