Skip to content

Instantly share code, notes, and snippets.

@Oipo
Created September 1, 2019 22:11
Show Gist options
  • Save Oipo/3057bb984eb268f5380165fc566e397f to your computer and use it in GitHub Desktop.
Save Oipo/3057bb984eb268f5380165fc566e397f to your computer and use it in GitHub Desktop.
optional<spawner_script> get_spawner_script(string const &script_file) {
string actual_script_file = "assets/scripts/spawners/" + script_file + ".yml";
spawner_script script;
spdlog::trace("{} loading script {}", __FUNCTION__, actual_script_file);
try {
YAML::Node config = YAML::LoadFile(actual_script_file);
script.respawn_rate = config["respawnRate"].as<uint32_t>();
script.initial_spawn = config["initialSpawn"].as<uint32_t>();
script.max_creatures = config["maxCreatures"].as<uint32_t>();
script.spawn_radius = config["spawnRadius"].as<uint32_t>();
script.random_walk_radius = config["randomWalkRadius"].as<uint32_t>();
script.leash_radius = config["leashRadius"].as<uint32_t>();
/*for(auto it = begin(config["npcIds"]); it != end(config["npcIds"]); it++) {
spdlog::trace("{} npc id", __FUNCTION__);
//script.npc_ids.emplace_back(it->second["chance"].as<uint32_t >(), it->first.as<string>());
}*/
for(const auto &kv : config["npcIds"]) {
auto npc_name = kv.begin()->first.as<string>();
//uint32_t chance = (kv.begin()++)->second.as<uint32_t>();
spdlog::trace("{} npc id {}", __FUNCTION__, npc_name);
bool second = false;
for(const auto &kv2 : kv) {
spdlog::trace("{} kv2 {}", __FUNCTION__, kv2.first.as<string>());
if(!second) {
second = true;
} else {
spdlog::trace("{} kv2 second {}", __FUNCTION__, kv2.second.as<uint32_t>());
}
}
script.npc_ids.emplace_back(kv.begin()->second["chance"].as<uint32_t >(), kv.begin()->first.as<string>());
}
} catch (const YAML::InvalidNode &e) {
spdlog::error("{} invalid node at {}:{}:{} - \"{}\"", __FUNCTION__, e.mark.line, e.mark.column, e.mark.pos, e.msg);
return {};
} catch (const YAML::BadFile &e) {
spdlog::error("{} couldn't find file because \"{}\"", __FUNCTION__, e.msg);
return {};
}
return script;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment