-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
chatter.dm
71 lines (63 loc) · 2.37 KB
/
chatter.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/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, /proc/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