osb/source/game/StarStagehandDatabase.cpp

36 lines
1.0 KiB
C++
Raw Normal View History

2023-06-20 04:33:09 +00:00
#include "StarStagehandDatabase.hpp"
#include "StarStagehand.hpp"
#include "StarJsonExtra.hpp"
#include "StarRoot.hpp"
#include "StarAssets.hpp"
namespace Star {
StagehandDatabase::StagehandDatabase() {
auto assets = Root::singleton().assets();
2024-03-15 10:28:11 +00:00
auto& files = assets->scanExtension("stagehand");
2023-06-20 04:33:09 +00:00
assets->queueJsons(files);
2024-03-15 10:28:11 +00:00
for (auto& file : files) {
2023-06-20 04:33:09 +00:00
try {
auto config = assets->json(file);
String typeName = config.getString("type");
if (m_stagehandTypes.contains(typeName))
2023-06-27 10:23:44 +00:00
throw StagehandDatabaseException(strf("Repeat stagehand type name '{}'", typeName));
2023-06-20 04:33:09 +00:00
m_stagehandTypes[typeName] = config;
} catch (StarException const& e) {
2023-06-27 10:23:44 +00:00
throw StagehandDatabaseException(strf("Error loading stagehand type '{}'", file), e);
2023-06-20 04:33:09 +00:00
}
}
}
StagehandPtr StagehandDatabase::createStagehand(String const& stagehandType, Json const& extraConfig) const {
auto finalConfig = jsonMerge(m_stagehandTypes.get(stagehandType), extraConfig);
return make_shared<Stagehand>(finalConfig);
}
}