osb/source/game/StarItemRecipe.cpp
2023-06-20 14:33:09 +10:00

47 lines
1.4 KiB
C++

#include "StarItemRecipe.hpp"
#include "StarRoot.hpp"
#include "StarItemDatabase.hpp"
#include "StarJsonExtra.hpp"
namespace Star {
Json ItemRecipe::toJson() {
JsonArray inputList;
for (auto input : inputs)
inputList.append(input.toJson());
return JsonObject{
{"currencyInputs", jsonFromMap(currencyInputs)},
{"input", inputList},
{"output", output.toJson()},
{"duration", duration},
{"groups", jsonFromStringSet(groups)},
{"collectables", jsonFromMap(collectables)},
{"matchInputParameters", matchInputParameters}
};
}
bool ItemRecipe::isNull() {
return currencyInputs.size() == 0 && inputs.size() == 0 && output.isNull();
}
bool ItemRecipe::operator==(ItemRecipe const& rhs) const {
return std::tie(currencyInputs, inputs, output) == std::tie(rhs.currencyInputs, rhs.inputs, rhs.output);
}
bool ItemRecipe::operator!=(ItemRecipe const& rhs) const {
return std::tie(currencyInputs, inputs, output) != std::tie(rhs.currencyInputs, rhs.inputs, rhs.output);
}
std::ostream& operator<<(std::ostream& os, ItemRecipe const& recipe) {
os << "CurrencyInputs: " << recipe.currencyInputs << "Inputs: " << recipe.inputs << "\nOutput: " << recipe.output
<< "\nDuration: " << recipe.duration << "\nGroups: " << recipe.groups;
return os;
}
size_t hash<ItemRecipe>::operator()(ItemRecipe const& v) const {
return hashOf(v.currencyInputs.keys(), v.currencyInputs.values(), v.inputs, v.output);
}
}