CraftSystem (and other): Changing the approach to the crafting system. Adding crafting types, correcting calls to the crafting system

This commit is contained in:
Van
2026-05-03 22:31:50 +03:00
parent 35699c1489
commit c143e95b27
10 changed files with 204 additions and 123 deletions

View File

@@ -1,8 +1,9 @@
local stringMatch = string.match
local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
local CraftSystem = Smc.requireCraftSystem()
local PrimitiveCraftHandler = Smc.requireCraftSystemPrimitiveCraftHandler()
local InventoryCraftHandler = CraftSystem:getPrimitiveCraftHandler('inside_player_inventory')
local require = Mod.getInfo('smc__ui__player_inventory').require
@@ -413,7 +414,7 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('.+::craft_item', function(play
-- We get the recipe selected in the crafting menu.
local craftName = PlayerInventoryUI:getContex(playerName, tabType..'_tab_craft_selected_craft')
local recipeIndex = PlayerInventoryUI:getContex(playerName, tabType..'_tab_craft_selected_recipe_index') or 0
local craft = PrimitiveCraftHandler:getCraftByName(craftName)
local craft = InventoryCraftHandler:getCraftByName(craftName)
-- We create an ItemStack of the crafted item by multiplying
-- its count by a multiplier - the number of items the player wants to craft at once.

View File

@@ -3,9 +3,10 @@ local mathFloor = math.floor
---Number of crafting recipes on one menu page.
local PAGE_NUMBER_ITEMS = 20
local PrimitiveCraftHandler = Smc.requireCraftSystemPrimitiveCraftHandler()
local Formspec = Smc.requireFormspec()
local CraftSystem = Smc.requireCraftSystem()
local InventoryCraftHandler = CraftSystem:getPrimitiveCraftHandler('inside_player_inventory')
---A text indicator of the presence or absence
---of a material in the player's inventory.
@@ -92,13 +93,13 @@ local function getCraftTab(self, playerName, tabType)
local crafts
if searchFieldValue ~= '' and searchFieldValue ~= nil then
---@type CraftSystem.PrimitiveCraft[]
crafts = PrimitiveCraftHandler:getLearnedCraftsMatch(playerName, searchFieldValue)
crafts = InventoryCraftHandler:getLearnedCraftsMatch(playerName, searchFieldValue)
elseif selectedGroup == nil then
---@type (CraftSystem.PrimitiveCraft[]|CraftSystem.PrimitiveCraft)[]
crafts = PrimitiveCraftHandler:getLearnedCrafts(playerName)
crafts = InventoryCraftHandler:getLearnedCrafts(playerName)
else
---@type CraftSystem.PrimitiveCraft[]
crafts = PrimitiveCraftHandler:getCraftsByGroup(selectedGroup)
crafts = InventoryCraftHandler:getCraftsByGroup(selectedGroup)
end
local craftsListForm = Formspec:new()
@@ -171,7 +172,7 @@ local function getCraftTab(self, playerName, tabType)
:label(2.5,8.5, ('%s/%s'):format(pageNumber, pagesMax))
if selectedCraft ~= '' then
local craft = PrimitiveCraftHandler:getCraftByName(selectedCraft)
local craft = InventoryCraftHandler:getCraftByName(selectedCraft)
local item = ItemStack(craft.output)
local itemDef = item:get_definition()