diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
commit | 6352e8e3196f78388b6c771073f9e03eaa612673 (patch) | |
tree | e23772f79a7fbc41bc9108951e9e136857484bf4 /source/game/StarEmoteProcessor.cpp | |
parent | 6741a057e5639280d85d0f88ba26f000baa58f61 (diff) |
everything everywhere
all at once
Diffstat (limited to 'source/game/StarEmoteProcessor.cpp')
-rw-r--r-- | source/game/StarEmoteProcessor.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/source/game/StarEmoteProcessor.cpp b/source/game/StarEmoteProcessor.cpp new file mode 100644 index 0000000..8bcf960 --- /dev/null +++ b/source/game/StarEmoteProcessor.cpp @@ -0,0 +1,61 @@ +#include "StarEmoteProcessor.hpp" +#include "StarJsonExtra.hpp" +#include "StarAssets.hpp" +#include "StarRoot.hpp" + +namespace Star { + +EmoteProcessor::EmoteProcessor() { + auto assets = Root::singleton().assets(); + + m_emoteBindings.clear(); + auto cfg = assets->json("/emotes.config"); + for (auto binding : cfg.get("emoteBindings").iterateObject()) { + for (auto text : binding.second.toArray()) { + EmoteBinding emoteBinding; + emoteBinding.emote = HumanoidEmoteNames.getLeft(binding.first); + emoteBinding.text = text.toString(); + m_emoteBindings.append(emoteBinding); + } + } +} + +HumanoidEmote EmoteProcessor::detectEmotes(String const& chatter) const { + auto isShouty = [](String const& text) -> bool { + int caps = 0; + int noCaps = 0; + for (auto c : text) { + if (String::toUpper(c) != String::toLower(c)) { + if (String::toUpper(c) == c) + caps++; + else + noCaps++; + } + } + return caps > noCaps; + }; + + HumanoidEmote result = HumanoidEmote::Idle; + if (!chatter.empty()) { + if (isShouty(chatter)) + result = HumanoidEmote::Shouting; + else + result = HumanoidEmote::Blabbering; + } + + float bestMatch = -1; + + for (auto option : m_emoteBindings) { + auto p = chatter.find(option.text); + if (p == NPos) + continue; + float r = p + (float)option.text.length() * 0.01f; + if (r > bestMatch) { + bestMatch = r; + result = option.emote; + } + } + return result; +} + +} |