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

Method PatternedNameGenerator

source/game/StarNameGenerator.cpp:8–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6namespace Star {
7
8PatternedNameGenerator::PatternedNameGenerator() {
9 auto assets = Root::singleton().assets();
10 auto &files = assets->scanExtension("namesource");
11 assets->queueJsons(files);
12 for (auto& file : files) {
13 try {
14 auto sourceConfig = assets->json(file);
15
16 if (m_markovSources.contains(sourceConfig.getString("name")))
17 throw NameGeneratorException::format("Duplicate name source '{}', config file '{}'", sourceConfig.getString("name"), file);
18
19 m_markovSources.insert(sourceConfig.getString("name"), makeMarkovSource(sourceConfig.getUInt("prefixSize", 1),
20 sourceConfig.getUInt("endSize", 1), jsonToStringList(sourceConfig.get("sourceNames"))));
21 } catch (std::exception const& e) {
22 throw NameGeneratorException(strf("Error reading name source config {}", file), e);
23 }
24 }
25
26 auto profanityFilter = assets->json("/names/profanityfilter.config").toArray();
27 for (auto& naughtyWord : profanityFilter)
28 m_profanityFilter.add(naughtyWord.toString().toLower());
29}
30
31String PatternedNameGenerator::generateName(String const& rulesAsset) const {
32 RandomSource random;

Callers

nothing calls this directly

Calls 15

singletonClass · 0.85
jsonToStringListFunction · 0.85
strfFunction · 0.85
assetsMethod · 0.80
queueJsonsMethod · 0.80
jsonMethod · 0.80
getStringMethod · 0.80
getUIntMethod · 0.80
toArrayMethod · 0.80
toLowerMethod · 0.80
formatFunction · 0.50
containsMethod · 0.45

Tested by

no test coverage detected