| 623 | } |
| 624 | |
| 625 | List<ItemRecipe> CraftingPane::determineRecipes() { |
| 626 | HashSet<ItemRecipe> recipes; |
| 627 | auto itemDb = Root::singleton().itemDatabase(); |
| 628 | |
| 629 | StringSet categoryFilter; |
| 630 | if (auto categoriesGroup = fetchChild<ButtonGroupWidget>("categories")) { |
| 631 | if (auto selectedCategories = categoriesGroup->checkedButton()) { |
| 632 | for (auto group : selectedCategories->data().getArray("filter")) |
| 633 | categoryFilter.add(group.toString()); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | HashSet<Rarity> rarityFilter; |
| 638 | if (auto raritiesGroup = fetchChild<ButtonGroupWidget>("rarities")) { |
| 639 | if (auto selectedRarities = raritiesGroup->checkedButton()) { |
| 640 | for (auto entry : jsonToStringSet(selectedRarities->data().getArray("rarity"))) |
| 641 | rarityFilter.add(RarityNames.getLeft(entry)); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | String filterText; |
| 646 | if (auto filterWidget = fetchChild<TextBoxWidget>("filter")) |
| 647 | filterText = filterWidget->getText(); |
| 648 | |
| 649 | bool filterHaveMaterials = false; |
| 650 | if (m_filterHaveMaterials) |
| 651 | filterHaveMaterials = m_filterHaveMaterials->isChecked(); |
| 652 | |
| 653 | if (m_settings.getBool("printer", false)) { |
| 654 | auto objectDatabase = Root::singleton().objectDatabase(); |
| 655 | |
| 656 | StringList itemList; |
| 657 | if (m_player->isAdmin()) |
| 658 | itemList = objectDatabase->allObjects(); |
| 659 | else |
| 660 | itemList = StringList::from(m_player->log()->scannedObjects()); |
| 661 | |
| 662 | filter(itemList, [objectDatabase, itemDb](String const& itemName) { |
| 663 | if (objectDatabase->isObject(itemName)) { |
| 664 | if (auto objectConfig = objectDatabase->getConfig(itemName)) |
| 665 | return objectConfig->printable && itemDb->hasItem(itemName); |
| 666 | } |
| 667 | return false; |
| 668 | }); |
| 669 | |
| 670 | float printTime = m_settings.getFloat("printTime", 0); |
| 671 | float printFactor = m_settings.getFloat("printCostFactor", 1.0); |
| 672 | for (auto& itemName : itemList) { |
| 673 | ItemRecipe recipe; |
| 674 | recipe.output = ItemDescriptor(itemName, 1); |
| 675 | auto recipeItem = itemDb->itemShared(recipe.output); |
| 676 | int itemPrice = int(recipeItem->price() * printFactor); |
| 677 | recipe.currencyInputs["money"] = itemPrice; |
| 678 | recipe.outputRarity = recipeItem->rarity(); |
| 679 | recipe.duration = printTime; |
| 680 | recipe.guiFilterString = ItemDatabase::guiFilterString(recipeItem); |
| 681 | recipe.groups = StringSet{objectDatabase->getConfig(itemName)->category}; |
| 682 | recipes.add(recipe); |
nothing calls this directly
no test coverage detected