use a normal text file instead
This commit is contained in:
parent
4f6ff6c2e7
commit
112c5d070d
@ -77,30 +77,26 @@ namespace bots
|
|||||||
|
|
||||||
void load_bot_data()
|
void load_bot_data()
|
||||||
{
|
{
|
||||||
static const char* bots_json = "h1-mod/bots.json";
|
static const char* bots_txt = "h1-mod/bots.txt";
|
||||||
|
|
||||||
std::string bots_content;
|
std::string bots_content;
|
||||||
|
if (!utils::io::read_file(bots_txt, &bots_content))
|
||||||
if (!utils::io::read_file(bots_json, &bots_content))
|
|
||||||
{
|
{
|
||||||
console::error(utils::string::va("%s was not found.\n", bots_json));
|
console::error(utils::string::va("%s was not found.\n", bots_txt));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rapidjson::Document bots;
|
auto names = utils::string::split(bots_content, '\n');
|
||||||
bots.Parse(bots_content.data());
|
for (auto& name : names)
|
||||||
|
|
||||||
// must be in a ["name1, "name2", "name3"] format
|
|
||||||
if (!bots.IsArray())
|
|
||||||
{
|
{
|
||||||
console::error("bots.json must be a array of names.\n");
|
name = utils::string::replace(name, "\r", "");
|
||||||
return;
|
#ifdef DEBUG
|
||||||
|
console::info(utils::string::va("Loading name '%s' for bot names...\n", name.data()));
|
||||||
|
#endif
|
||||||
|
if (!name.empty())
|
||||||
|
{
|
||||||
|
bot_names.emplace_back(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto names = bots.GetArray();
|
|
||||||
for (const auto& name : names)
|
|
||||||
{
|
|
||||||
bot_names.emplace_back(std::string(name.GetString()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +109,10 @@ namespace bots
|
|||||||
load_bot_data();
|
load_bot_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
console::info(utils::string::va("Bot ID is %d\n", bot_id));
|
||||||
|
#endif
|
||||||
|
|
||||||
// only use bot names once, no dupes in names
|
// only use bot names once, no dupes in names
|
||||||
if (!bot_names.empty() && bot_id < bot_names.size())
|
if (!bot_names.empty() && bot_id < bot_names.size())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user