MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / detectEmotes

Method detectEmotes

source/game/StarEmoteProcessor.cpp:23–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23HumanoidEmote EmoteProcessor::detectEmotes(String const& chatter) const {
24 auto isShouty = [](String const& text) -> bool {
25 int caps = 0;
26 int noCaps = 0;
27 for (auto c : text) {
28 if (String::toUpper(c) != String::toLower(c)) {
29 if (String::toUpper(c) == c)
30 caps++;
31 else
32 noCaps++;
33 }
34 }
35 return caps > noCaps;
36 };
37
38 HumanoidEmote result = HumanoidEmote::Idle;
39 if (!chatter.empty()) {
40 if (isShouty(chatter))
41 result = HumanoidEmote::Shouting;
42 else
43 result = HumanoidEmote::Blabbering;
44 }
45
46 float bestMatch = -1;
47
48 for (auto option : m_emoteBindings) {
49 auto p = chatter.find(option.text);
50 if (p == NPos)
51 continue;
52 float r = p + (float)option.text.length() * 0.01f;
53 if (r > bestMatch) {
54 bestMatch = r;
55 result = option.emote;
56 }
57 }
58 return result;
59}
60
61}

Callers 2

updateMethod · 0.80
updateMethod · 0.80

Calls 3

emptyMethod · 0.45
findMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected