Adds the sound emitter circuit component (#59866)

Adds the sound emitter circuit component. Allows the integrated circuit to play a sound of varying volume and frequency.
This commit is contained in:
Watermelon914
2021-06-30 15:38:31 -03:00
committed by GitHub
parent 6f3f14566a
commit 02f0fe75fa
5 changed files with 98 additions and 0 deletions
+10
View File
@@ -88,6 +88,16 @@
#define COMP_RADIO_PUBLIC "public"
#define COMP_RADIO_PRIVATE "private"
// Sound component
#define COMP_SOUND_BUZZ "Buzz"
#define COMP_SOUND_BUZZ_TWO "Buzz Twice"
#define COMP_SOUND_CHIME "Chime"
#define COMP_SOUND_HONK "Honk"
#define COMP_SOUND_PING "Ping"
#define COMP_SOUND_SAD "Sad Trombone"
#define COMP_SOUND_WARN "Warn"
#define COMP_SOUND_SLOWCLAP "Slow Clap"
// Security Arrest Console
#define COMP_STATE_ARREST "*Arrest*"
#define COMP_STATE_PRISONER "Incarcerated"
@@ -173,6 +173,11 @@
id = "comp_pull"
build_path = /obj/item/circuit_component/pull
/datum/design/component/soundemitter
name = "Sound Emitter Component"
id = "comp_soundemitter"
build_path = /obj/item/circuit_component/soundemitter
/datum/design/component/mmi
name = "MMI Component"
id = "comp_mmi"
@@ -219,6 +219,7 @@
"comp_random",
"comp_select_query",
"comp_self",
"comp_soundemitter",
"comp_species",
"comp_speech",
"comp_speech",
@@ -0,0 +1,81 @@
/**
* # Sound Emitter Component
*
* A component that emits a sound when it receives an input.
*/
/obj/item/circuit_component/soundemitter
display_name = "Sound Emitter"
display_desc = "A component that emits a sound when it receives an input. The frequency is a multiplier which determines the speed at which the sound is played"
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/// Volume of the sound when played
var/datum/port/input/volume
/// Frequency of the sound when played
var/datum/port/input/frequency
/// The cooldown for this component of how often it can play sounds.
var/sound_cooldown = 2 SECONDS
var/list/options_map
COOLDOWN_DECLARE(next_sound)
/obj/item/circuit_component/soundemitter/get_ui_notices()
. = ..()
. += create_ui_notice("Sound Cooldown: [DisplayTimeText(sound_cooldown)]", "orange", "stopwatch")
/obj/item/circuit_component/soundemitter/Initialize()
. = ..()
volume = add_input_port("Volume", PORT_TYPE_NUMBER, default = 35)
frequency = add_input_port("Frequency", PORT_TYPE_NUMBER, default = 0)
/obj/item/circuit_component/soundemitter/Destroy()
frequency = null
volume = null
return ..()
/obj/item/circuit_component/soundemitter/populate_options()
var/static/component_options = list(
COMP_SOUND_BUZZ,
COMP_SOUND_BUZZ_TWO,
COMP_SOUND_CHIME,
COMP_SOUND_HONK,
COMP_SOUND_PING,
COMP_SOUND_SAD,
COMP_SOUND_WARN,
COMP_SOUND_SLOWCLAP,
)
options = component_options
var/static/options_to_sound = list(
COMP_SOUND_BUZZ = 'sound/machines/buzz-sigh.ogg',
COMP_SOUND_BUZZ_TWO = 'sound/machines/buzz-two.ogg',
COMP_SOUND_CHIME = 'sound/machines/chime.ogg',
COMP_SOUND_HONK = 'sound/items/bikehorn.ogg',
COMP_SOUND_PING = 'sound/machines/ping.ogg',
COMP_SOUND_SAD = 'sound/misc/sadtrombone.ogg',
COMP_SOUND_WARN = 'sound/machines/warning-buzzer.ogg',
COMP_SOUND_SLOWCLAP = 'sound/machines/slowclap.ogg',
)
options_map = options_to_sound
/obj/item/circuit_component/soundemitter/input_received(datum/port/input/port)
. = ..()
volume.set_input(clamp(volume.input_value, 0, 100), FALSE)
frequency.set_input(clamp(frequency.input_value, -100, 100), FALSE)
if(.)
return
if(!COOLDOWN_FINISHED(src, next_sound))
return
var/sound_to_play = options_map[current_option]
if(!sound_to_play)
return
playsound(src, sound_to_play, volume.input_value, FALSE, frequency = frequency.input_value)
COOLDOWN_START(src, next_sound, sound_cooldown)
+1
View File
@@ -3577,6 +3577,7 @@
#include "code\modules\wiremod\components\action\mmi.dm"
#include "code\modules\wiremod\components\action\pull.dm"
#include "code\modules\wiremod\components\action\radio.dm"
#include "code\modules\wiremod\components\action\soundemitter.dm"
#include "code\modules\wiremod\components\action\speech.dm"
#include "code\modules\wiremod\components\atom\direction.dm"
#include "code\modules\wiremod\components\atom\gps.dm"