Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] [MODULAR] Add: Voice Actor Quirk #5298

Merged
merged 2 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions modular_nova/modules/voice_actor_quirk/code/alter_voice_action.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
///Action for voice_actor quirk
/datum/action/innate/alter_voice
name = "Swap Voice"
button_icon = 'icons/mob/actions/actions_spells.dmi'
button_icon_state = "swap"
check_flags = AB_CHECK_CONSCIOUS
/// The primary voice, aka the initial voice
var/primary_voice
/// The pitch of the primary voice
var/primary_pitch = 0
/// The secondary voice that can be swapped to/from at will
var/secondary_voice
/// The secondary voice's pitch
var/secondary_pitch = 0

///Sets up the voice and pitch variables.
/datum/action/innate/alter_voice/proc/setup_second_voice(mob/actor)
if(!actor.client)
return
// Set up secondary pitch
secondary_pitch = actor.client.prefs.read_preference(/datum/preference/numeric/voice_actor_pitch)
// Set up secondary voice
var/speaker = actor.client.prefs.read_preference(/datum/preference/choiced/voice_actor)
var/list/available_speakers
if(SStts.tts_enabled)
available_speakers = SStts.available_speakers
else if(fexists("data/cached_tts_voices.json"))
available_speakers = json_decode(rustg_file_read("data/cached_tts_voices.json"))
else
return
if((speaker == "Random") || !(speaker in available_speakers))
secondary_voice = pick(available_speakers)
else
secondary_voice = speaker

///Swaps between primary_voice and secondary_voice
/datum/action/innate/alter_voice/proc/swap_voice()
// If client didn't exist when action was granted, it should exist now.
if(isnull(secondary_voice))
setup_second_voice(owner)
// Block activation if second voice failed to load.
if(!active && isnull(secondary_voice))
to_chat(owner, span_userdanger("You can't remember your second voice at the moment. (Please consider reporting this on github!)"))
return
active = !active
if(active)
owner.voice = secondary_voice
owner.pitch = secondary_pitch
to_chat(owner, span_green("You are now voice acting."))
else
owner.voice = primary_voice
owner.pitch = primary_pitch
to_chat(owner, span_green("You have stopped voice acting."))
owner.balloon_alert(owner, "voice changed")
build_all_button_icons(UPDATE_BUTTON_BACKGROUND)

/datum/action/innate/alter_voice/Grant(mob/grant_to)
. = ..()
if(grant_to != owner)
return
// Set up primary pitch
if(SStts.pitch_enabled)
primary_pitch = grant_to.pitch
// Set up primary voice
primary_voice = grant_to.voice
setup_second_voice(grant_to)

/datum/action/innate/alter_voice/Remove(mob/remove_from)
if(remove_from == owner)
remove_from.voice = primary_voice
remove_from.pitch = primary_pitch
return ..()

/datum/action/innate/alter_voice/Activate()
swap_voice()

/datum/action/innate/alter_voice/Deactivate()
swap_voice()
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/datum/preference/choiced/voice_actor
savefile_key = "voice_actor"
category = PREFERENCE_CATEGORY_MANUALLY_RENDERED
savefile_identifier = PREFERENCE_CHARACTER
can_randomize = FALSE

/datum/preference/choiced/voice_actor/apply_to_human()
return

/datum/preference/choiced/voice_actor/create_default_value()
return "Random"

/datum/preference/choiced/voice_actor/is_valid(value)
if(value == "Random")
return TRUE
if(value in get_choices())
return TRUE
return FALSE

/datum/preference/choiced/voice_actor/init_possible_values()
if(SStts.tts_enabled)
var/list/speakers = SStts.available_speakers
speakers.Insert(1, "Random")
return speakers
if(fexists("data/cached_tts_voices.json"))
var/list/cached_voices = json_decode(rustg_file_read("data/cached_tts_voices.json"))
if(cached_voices)
cached_voices.Insert(1, "Random")
return cached_voices
return list("Random")

/datum/preference/numeric/voice_actor_pitch
savefile_key = "voice_actor_pitch"
category = PREFERENCE_CATEGORY_MANUALLY_RENDERED
savefile_identifier = PREFERENCE_CHARACTER
minimum = -12
maximum = 12

/datum/preference/numeric/voice_actor_pitch/apply_to_human()
return

/datum/preference/numeric/voice_actor_pitch/create_default_value()
return 0
22 changes: 22 additions & 0 deletions modular_nova/modules/voice_actor_quirk/code/voice_actor_quirk.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/datum/quirk/voice_actor
name = "Voice Actor"
desc = "You are able to swap between two different TTS voices."
icon = FA_ICON_MICROPHONE_LINES
gain_text = span_notice("You are reminded of how your other voice sounds.")
lose_text = span_warning("You suddenly forget what your other voice sounds like!")
medical_record_text = ""
value = 4
quirk_flags = QUIRK_HUMAN_ONLY

/datum/quirk_constant_data/voice_actor
associated_typepath = /datum/quirk/voice_actor
customization_options = list(/datum/preference/choiced/voice_actor, /datum/preference/numeric/voice_actor_pitch)

/datum/quirk/voice_actor/add(client/client_source)
var/datum/action/innate/alter_voice/voice_action = new
voice_action.Grant(quirk_holder)

/datum/quirk/voice_actor/remove()
var/datum/action/action_to_remove = locate(/datum/action/innate/alter_voice) in quirk_holder.actions
if(action_to_remove)
qdel(action_to_remove)
3 changes: 3 additions & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -8788,6 +8788,9 @@
#include "modular_nova\modules\verbs\code\subtle.dm"
#include "modular_nova\modules\veteran_only\code\job_types.dm"
#include "modular_nova\modules\veteran_only\code\species_types.dm"
#include "modular_nova\modules\voice_actor_quirk\code\alter_voice_action.dm"
#include "modular_nova\modules\voice_actor_quirk\code\voice_actor_preferences.dm"
#include "modular_nova\modules\voice_actor_quirk\code\voice_actor_quirk.dm"
#include "modular_nova\modules\vox_sprites\code\color.dm"
#include "modular_nova\modules\vox_sprites\code\head.dm"
#include "modular_nova\modules\vox_sprites\code\security.dm"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// THIS IS A NOVA SECTOR UI FILE
import { Feature, FeatureChoiced, FeatureNumberInput } from '../../base';
import { FeatureDropdownInput } from '../../dropdowns';

export const voice_actor: FeatureChoiced = {
name: 'Second Voice',
component: FeatureDropdownInput,
};

export const voice_actor_pitch: Feature<number> = {
name: 'Second Pitch',
component: FeatureNumberInput,
};
Loading