Compare commits

...

5 Commits

5 changed files with 71 additions and 7 deletions

View File

@@ -1,5 +1,7 @@
#include "BuildAbilities.hpp"
#include <fstream>
#include "json.hpp"
using json = nlohmann::json;
#define GET(o, objectKey, key) \
@@ -49,6 +51,11 @@ CreatureLib::Library::TalentLibrary* BuildAbilities::Build(const std::string& pa
case json::value_t::number_float:
realParameters.Append(new CreatureLib::Library::EffectParameter(p.get<float>()));
break;
case json::value_t ::string: {
auto s = p.get<std::string>();
realParameters.Append(new CreatureLib::Library::EffectParameter(ArbUt::StringView(s.c_str(), s.length())));
break;
}
default: continue;
}
}

View File

@@ -83,6 +83,12 @@ PkmnLib::Library::ItemLibrary* BuildItems::Build(const std::string& path) {
case json::value_t::number_float:
parameters.Append(new CreatureLib::Library::EffectParameter(p.get<float>()));
break;
case json::value_t ::string: {
auto s = p.get<std::string>();
parameters.Append(
new CreatureLib::Library::EffectParameter(ArbUt::StringView(s.c_str(), s.length())));
break;
}
default: continue;
}
}
@@ -91,9 +97,44 @@ PkmnLib::Library::ItemLibrary* BuildItems::Build(const std::string& path) {
100, ArbUt::StringView(effectName.get<std::string>().c_str()), parameters);
}
CreatureLib::Library::SecondaryEffect* battleEffect = nullptr;
auto& battleEffectJson = val["battleEffect"];
if (battleEffectJson != nullptr) {
auto& effectName = battleEffectJson["name"];
auto& parametersJson = battleEffectJson["parameters"];
ArbUt::List<CreatureLib::Library::EffectParameter*> parameters;
if (parametersJson != nullptr) {
for (auto& kv : parametersJson.items()) {
auto& p = kv.value();
auto t = p.type();
switch (t) {
case json::value_t::boolean:
parameters.Append(new CreatureLib::Library::EffectParameter(p.get<bool>()));
break;
case json::value_t::number_integer:
case json::value_t::number_unsigned:
parameters.Append(new CreatureLib::Library::EffectParameter(p.get<int64_t>()));
break;
case json::value_t::number_float:
parameters.Append(new CreatureLib::Library::EffectParameter(p.get<float>()));
break;
case json::value_t ::string: {
auto s = p.get<std::string>();
parameters.Append(
new CreatureLib::Library::EffectParameter(ArbUt::StringView(s.c_str(), s.length())));
break;
}
default: continue;
}
}
}
battleEffect = new CreatureLib::Library::SecondaryEffect(
100, ArbUt::StringView(effectName.get<std::string>().c_str()), parameters);
}
auto item = new PkmnLib::Library::Item(ArbUt::StringView(_name.get<std::string>().c_str()), itemType,
CreatureLib::Library::BattleItemCategory::None, _price.get<int32_t>(),
effect, flags, _flingPower.get<uint8_t>());
effect, battleEffect, flags, _flingPower.get<uint8_t>());
lib->Insert(item->GetName(), item);
}
return lib;

View File

@@ -95,7 +95,17 @@ BattleLibrary* BuildLibrary::Build(const std::string& pathString,
continue;
std::ifstream in(dirEntry.path());
std::string contents((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
asScriptResolver->CreateScript((const char*)dirEntry.path().c_str(), contents.c_str());
const auto* p = dirEntry.path().c_str();
// Windows defines paths as widechars, so we need to convert it to a normal human const char*
#if WINDOWS
std::mbstate_t state = std::mbstate_t();
int textLen = 1 + std::wcsrtombs(NULL, &p, 0, &state);
std::vector<char> storeTextBuffer(textLen);
std::wcsrtombs(&storeTextBuffer[0], &p, textLen, &state);
asScriptResolver->CreateScript(&storeTextBuffer[0], contents.c_str());
#else
asScriptResolver->CreateScript(p, contents.c_str());
#endif
}
asScriptResolver->FinalizeModule();
ScriptsTimeMs =

View File

@@ -8,8 +8,8 @@ using json = nlohmann::json;
auto& _##objectKey = o[#objectKey]; \
if (_##objectKey.is_null()) { \
auto errorKeyFunc = [=]() { return key; }; \
std::cout << "Failed to retrieve key '" << #objectKey << "' for object with key '" << errorKeyFunc() \
<< path << "'\n"; \
std::cout << "Failed to retrieve key '" << #objectKey << "' for object with key '" << errorKeyFunc() << path \
<< "'\n"; \
return nullptr; \
}
@@ -89,6 +89,12 @@ PkmnLib::Library::MoveLibrary* BuildMoves::Build(const std::string& path,
case json::value_t::number_float:
parameters.Append(new CreatureLib::Library::EffectParameter(p.get<float>()));
break;
case json::value_t ::string: {
auto s = p.get<std::string>();
parameters.Append(new CreatureLib::Library::EffectParameter(
ArbUt::StringView(s.c_str(), s.length())));
break;
}
default: continue;
}
}

View File

@@ -135,7 +135,7 @@ const PkmnLib::Library::PokemonForme* BuildSpecies::BuildForme(const std::string
auto s = ab.value().get<std::string>();
auto tryAbility = talentLibrary->TryGet(ArbUt::StringView(s.c_str(), s.length()));
if (!tryAbility.has_value())
THROW("Unknown ability " << s);
THROW("Unknown ability ", s);
abilities.Append(tryAbility.value());
}
@@ -144,7 +144,7 @@ const PkmnLib::Library::PokemonForme* BuildSpecies::BuildForme(const std::string
auto s = ab.value().get<std::string>();
auto tryAbility = talentLibrary->TryGet(ArbUt::StringView(s.c_str(), s.length()));
if (!tryAbility.has_value())
THROW("Unknown ability " << s);
THROW("Unknown ability ", s);
hiddenAbilities.Append(tryAbility.value());
}