| 351 | } |
| 352 | |
| 353 | ItemRecipe ItemDatabase::parseRecipe(Json const& config) const { |
| 354 | ItemRecipe res; |
| 355 | try { |
| 356 | res.currencyInputs = jsonToMapV<StringMap<uint64_t>>(config.get("currencyInputs", JsonObject()), mem_fn(&Json::toUInt)); |
| 357 | |
| 358 | // parse currency items into currency inputs |
| 359 | for (auto input : config.getArray("input")) { |
| 360 | auto id = ItemDescriptor(input); |
| 361 | if (itemType(id.name()) == ItemType::CurrencyItem) { |
| 362 | auto currencyItem = as<CurrencyItem>(itemShared(id)); |
| 363 | res.currencyInputs[currencyItem->currencyType()] += currencyItem->totalValue(); |
| 364 | } else { |
| 365 | res.inputs.push_back(id); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | res.output = ItemDescriptor(config.get("output")); |
| 370 | res.duration = config.getFloat("duration", Root::singleton().assets()->json("/items/defaultParameters.config:defaultCraftDuration").toFloat()); |
| 371 | res.groups = StringSet::from(jsonToStringList(config.get("groups", JsonArray()))); |
| 372 | if (auto item = ItemDatabase::itemShared(res.output)) { |
| 373 | res.outputRarity = item->rarity(); |
| 374 | res.guiFilterString = guiFilterString(item); |
| 375 | } |
| 376 | res.collectables = jsonToMapV<StringMap<String>>(config.get("collectables", JsonObject()), mem_fn(&Json::toString)); |
| 377 | res.matchInputParameters = config.getBool("matchInputParameters", false); |
| 378 | |
| 379 | } catch (JsonException const& e) { |
| 380 | throw RecipeException(strf("Recipe missing required ingredient: {}", outputException(e, false))); |
| 381 | } |
| 382 | |
| 383 | return res; |
| 384 | } |
| 385 | |
| 386 | HashSet<ItemRecipe> const& ItemDatabase::allRecipes() const { |
| 387 | return m_recipes; |
no test coverage detected