Files
Bubberstation/code/modules/chatter/chatter.dm
AnturK 4d6a8bc537 515 Compatibility (#71161)
Makes the code compatible with 515.1594+

Few simple changes and one very painful one.
Let's start with the easy:
* puts call behind `LIBCALL` define, so call_ext is properly used in 515
* Adds `NAMEOF_STATIC(_,X)` macro for nameof in static definitions since
src is now invalid there.
* Fixes tgui and devserver. From 515 onward the tmp3333{procid} cache
directory is not appened to base path in browser controls so we don't
check for it in base js and put the dev server dummy window file in
actual directory not the byond root.
* Renames the few things that had /final/ in typepath to ultimate since
final is a new keyword

And the very painful change:
`.proc/whatever` format is no longer valid, so we're replacing it with
new nameof() function. All this wrapped in three new macros.
`PROC_REF(X)`,`TYPE_PROC_REF(TYPE,X)`,`GLOBAL_PROC_REF(X)`. Global is
not actually necessary but if we get nameof that does not allow globals
it would be nice validation.
This is pretty unwieldy but there's no real alternative.
If you notice anything weird in the commits let me know because majority
was done with regex replace.

@tgstation/commit-access Since the .proc/stuff is pretty big change.

Co-authored-by: san7890 <the@san7890.com>
Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
2022-11-15 03:50:11 +00:00

72 lines
2.4 KiB
Plaintext

/proc/chatter(message, phomeme, atom/speaker)
// We want to transform any message into a list of numbers
// and punctuation marks
// For example:
// "Hi." -> [2, '.']
// "HALP GEROGE MELLONS, that swine, is GRIFFIN ME!"
// -> [4, 6, 7, ',', 4, 5, ',', '2', 7, 2, '!']
// "fuck,thissentenceissquashed" -> [4, ',', 21]
var/regex/R = regex("(\[\\l\\d]*)(\[^\\l\\d\\s])?", "g")
var/list/letter_count = list()
while(R.Find(message) != 0)
if(R.group[1])
letter_count += length(R.group[1])
if(R.group[2])
letter_count += R.group[2]
chatter_speak(speaker, letter_count, phomeme)
/// We're going to take a list that dictates the pace of speech, and a sentence fragment to say
/// Then say() that fragment at that pace
/// You can pass in a starting delay to wait before speaking the next sound
/proc/chatter_speak(atom/speaker, list/letter_count, phomeme, extra_delay = 0)
var/static/list/punctuation = list(",",":",";",".","?","!","\'","-")
var/delay = extra_delay
for(var/i in 1 to length(letter_count))
var/item = letter_count[i]
if (item in punctuation)
// simulate pausing in talking
// ignore semi-colons because of their use in HTML escaping
if (item in list(",", ":"))
delay += 0.3 SECONDS
if (item in list("!", "?", "."))
delay += 0.6 SECONDS
continue
if(!isnum(item))
continue
letter_count.Cut(1, i + 1)
var/list/current_context = letter_count
var/length = min(item, 10)
if (length == 0)
// "verbalise" long spaces
delay += 0.1 SECONDS
if(delay)
addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(chatter_speak_word), speaker, letter_count, phomeme, length), delay, flags = TIMER_CLIENT_TIME)
else
chatter_speak_word(speaker, current_context, phomeme, length)
break //We use the loop as a handy way of dealing with punctuation, the actual looping operation here happens in timers that call timers
/proc/chatter_speak_word(atom/speaker, list/letter_count, phomeme, length)
var/path = "sound/runtime/chatter/[phomeme]_[length].ogg"
var/loc = speaker.loc
playsound(loc, path,
vol = 40, vary = 0, extrarange = 3)
var/delay = (length + 1) * chatter_get_delay_multiplier(phomeme)
chatter_speak(speaker, letter_count, phomeme, delay)
/proc/chatter_get_delay_multiplier(phomeme)
. = 0.1 SECONDS
switch(phomeme)
if("papyrus")
. = 0.05 SECONDS
if("griffin")
. = 0.05 SECONDS
if("sans")
. = 0.07 SECONDS
if("owl")
. = 0.07 SECONDS