timepiece circuit module (#62039)

Adds a circuit component that outputs the station time in chosen format and unit of time when triggered. The options are currently 24-hour and 12-hour for the time format, hours, minutes and seconds for the unit of time.
The component is called timepiece because clock was already taken by another component that sends signal outputs at intervals.
This commit is contained in:
Ghom
2021-10-12 14:32:30 +01:00
committed by GitHub
parent ae9ff1b7ee
commit 6c5766c62e
5 changed files with 91 additions and 0 deletions
@@ -0,0 +1,68 @@
#define COMP_TIMEPIECE_TWENTYFOUR_HOUR "24-Hour"
#define COMP_TIMEPIECE_TWELVE_HOUR "12-Hour"
#define COMP_TIMEPIECE_SECONDS "Seconds"
#define COMP_TIMEPIECE_MINUTES "Minutes"
#define COMP_TIMEPIECE_HOURS "Hours"
/**
* # Timepiece Component
*
* returns the current station time.
*/
/obj/item/circuit_component/timepiece
display_name = "Timepiece"
desc = "A component that outputs the current station time. The text output port is used for time formats while the numerical output port is used for units of time."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/// The time format of the text output
var/datum/port/input/option/format
/// The unit of time for the numerical output
var/datum/port/input/option/time_unit
/// The output for 24/12 hour formats
var/datum/port/output/text_output
/// seconds, minutes, hours.
var/datum/port/output/num_output
/obj/item/circuit_component/timepiece/populate_ports()
text_output = add_output_port("Time Format", PORT_TYPE_STRING)
num_output = add_output_port("Unit of Time", PORT_TYPE_NUMBER)
/obj/item/circuit_component/timepiece/populate_options()
var/static/format_options = list(
COMP_TIMEPIECE_TWENTYFOUR_HOUR, // Station time is expressed in 24-h in the status tab. So this is the default.
COMP_TIMEPIECE_TWELVE_HOUR,
)
format = add_option_port("Time Format", format_options)
var/static/unit_options = list(
COMP_TIMEPIECE_HOURS,
COMP_TIMEPIECE_MINUTES,
COMP_TIMEPIECE_SECONDS,
)
time_unit = add_option_port("Unit of Time", unit_options)
/obj/item/circuit_component/timepiece/input_received(datum/port/input/port)
var/time
switch(format.value)
if(COMP_TIMEPIECE_TWENTYFOUR_HOUR)
time = station_time_timestamp()
if(COMP_TIMEPIECE_TWELVE_HOUR)
time = time_to_twelve_hour(station_time())
text_output.set_output(time)
switch(time_unit.value)
if(COMP_TIMEPIECE_HOURS)
time = round(station_time() / (1 HOURS))
if(COMP_TIMEPIECE_MINUTES)
time = round(station_time() / (1 MINUTES))
if(COMP_TIMEPIECE_SECONDS)
time = round(station_time() / (1 SECONDS))
num_output.set_output(time)
#undef COMP_TIMEPIECE_TWENTYFOUR_HOUR
#undef COMP_TIMEPIECE_TWELVE_HOUR
#undef COMP_TIMEPIECE_SECONDS
#undef COMP_TIMEPIECE_MINUTES
#undef COMP_TIMEPIECE_HOURS