forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor tts to use middleware and constant data (#902)
## Что этот PR делает Рефактор префов ТТСа, перенос константной информации в json asset ## Почему это хорошо для игры Возможно будет быстрее подгружаться меню префов
- Loading branch information
Showing
6 changed files
with
139 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
modular_bandastation/tts/code/preferences/tts_preference_middleware.dm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
GLOBAL_LIST_EMPTY(human_to_tts) | ||
|
||
/datum/preference_middleware/text_to_speech | ||
action_delegations = list( | ||
"listen" = PROC_REF(listen_voice), | ||
"select_voice" = PROC_REF(select_voice), | ||
) | ||
|
||
/datum/preference_middleware/text_to_speech/get_ui_data(mob/user) | ||
var/list/data = list() | ||
data["tts_seed"] = preferences.read_preference(/datum/preference/text/tts_seed) | ||
data["tts_enabled"] = CONFIG_GET(flag/tts_enabled) | ||
return data | ||
|
||
/datum/preference_middleware/text_to_speech/get_constant_data() | ||
var/list/data = list() | ||
data["providers"] = get_tts_providers_ui_data() | ||
data["seeds"] = get_tts_seeds_ui_data() | ||
data["phrases"] = TTS_PHRASES | ||
return data | ||
|
||
/datum/preference_middleware/text_to_speech/proc/get_tts_providers_ui_data() | ||
var/list/providers = list() | ||
for(var/_provider in SStts220.tts_providers) | ||
var/datum/tts_provider/provider = SStts220.tts_providers[_provider] | ||
providers += list(list( | ||
"name" = provider.name, | ||
"is_enabled" = provider.is_enabled, | ||
)) | ||
return providers | ||
|
||
/datum/preference_middleware/text_to_speech/proc/get_tts_seeds_ui_data() | ||
var/list/seeds = list() | ||
for(var/_seed in SStts220.tts_seeds) | ||
var/datum/tts_seed/seed = SStts220.tts_seeds[_seed] | ||
seeds += list(list( | ||
"name" = seed.name, | ||
"value" = seed.value, | ||
"category" = seed.category, | ||
"gender" = seed.gender, | ||
"provider" = initial(seed.provider.name), | ||
"donator_level" = seed.required_donator_level, | ||
)) | ||
return seeds | ||
|
||
/datum/preference_middleware/text_to_speech/proc/listen_voice(list/params, mob/user) | ||
var/seed_name = params["seed"] | ||
if(!seed_name) | ||
return FALSE | ||
|
||
var/datum/tts_seed/seed = SStts220.tts_seeds[seed_name] | ||
if(!seed) | ||
return FALSE | ||
|
||
var/phrase = params["phrase"] | ||
if(!phrase || !(phrase in TTS_PHRASES)) | ||
phrase = pick(TTS_PHRASES) | ||
|
||
INVOKE_ASYNC(SStts220, TYPE_PROC_REF(/datum/controller/subsystem/tts220, get_tts), null, usr, phrase, seed, FALSE) | ||
|
||
return FALSE | ||
|
||
/datum/preference_middleware/text_to_speech/proc/select_voice(list/params, mob/user) | ||
var/seed_name = params["seed"] | ||
if(!seed_name || !SStts220.tts_seeds[seed_name]) | ||
return FALSE | ||
|
||
preferences.update_preference(GLOB.preference_entries[/datum/preference/text/tts_seed], seed_name) | ||
return TRUE |
28 changes: 28 additions & 0 deletions
28
modular_bandastation/tts/code/preferences/tts_preferences.dm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/datum/preference/text/tts_seed | ||
savefile_key = "tts_seed" | ||
savefile_identifier = PREFERENCE_CHARACTER | ||
|
||
/datum/preference/text/tts_seed/apply_to_human(mob/living/carbon/human/target, value) | ||
var/datum/tts_seed/seed = SStts220.tts_seeds[value] | ||
if(!seed) | ||
seed = SStts220.tts_seeds[SStts220.get_random_seed(target)] | ||
|
||
target.AddComponent(/datum/component/tts_component, seed) | ||
target.dna.tts_seed_dna = seed | ||
GLOB.human_to_tts["[target.real_name]"] = seed | ||
|
||
/datum/preference/numeric/sound_tts_volume_radio | ||
category = PREFERENCE_CATEGORY_GAME_PREFERENCES | ||
savefile_key = "sound_tts_volume_radio" | ||
savefile_identifier = PREFERENCE_PLAYER | ||
|
||
minimum = 0 | ||
maximum = 200 | ||
|
||
/datum/preference/numeric/sound_tts_volume_radio/create_default_value() | ||
return maximum / 2 | ||
|
||
/mob/living/carbon/human/randomize_human_appearance(randomize_flags) | ||
. = ..() | ||
var/datum/component/tts_component/tts_component = GetComponent(/datum/component/tts_component) | ||
tts_component.tts_seed = tts_component.get_random_tts_seed_by_gender() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters