MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / parseRecipe

Method parseRecipe

source/game/StarItemDatabase.cpp:353–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

351}
352
353ItemRecipe 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
386HashSet<ItemRecipe> const& ItemDatabase::allRecipes() const {
387 return m_recipes;

Callers 2

recipeForMaterialsMethod · 0.80
determineRecipesMethod · 0.80

Calls 15

ItemDescriptorClass · 0.85
singletonClass · 0.85
jsonToStringListFunction · 0.85
strfFunction · 0.85
getArrayMethod · 0.80
currencyTypeMethod · 0.80
totalValueMethod · 0.80
getFloatMethod · 0.80
toFloatMethod · 0.80
jsonMethod · 0.80
assetsMethod · 0.80
getBoolMethod · 0.80

Tested by

no test coverage detected