CraftSystem: return alt recipes, add player crafts cache, support learned recipes
This commit is contained in:
@@ -489,11 +489,16 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::alt_recipe_back', fu
|
||||
|
||||
local playerName = player:get_player_name()
|
||||
local craftTabData = PlayerInventoryUI:getTabCraftData(playerName, tabType, tabName)
|
||||
local recipeIndex = craftTabData.selected_recipe_index or 0
|
||||
local recipeIndex = craftTabData.selected_recipe_index or 1
|
||||
recipeIndex = recipeIndex - 1
|
||||
|
||||
if recipeIndex < 0 then
|
||||
recipeIndex = 0
|
||||
local handler = craftTabData.handler
|
||||
local craft = handler:getCraftByName(craftTabData.selected_craft)
|
||||
local crafts = handler:getLearnedCraftsByOutput(playerName, craft.output)
|
||||
assert(crafts ~= nil)
|
||||
|
||||
if recipeIndex < 1 then
|
||||
recipeIndex = 1
|
||||
end
|
||||
|
||||
craftTabData.selected_recipe_index = recipeIndex
|
||||
@@ -508,9 +513,18 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::alt_recipe_forward',
|
||||
|
||||
local playerName = player:get_player_name()
|
||||
local craftTabData = PlayerInventoryUI:getTabCraftData(playerName, tabType, tabName)
|
||||
local recipeIndex = craftTabData.selected_recipe_index or 0
|
||||
local recipeIndex = craftTabData.selected_recipe_index or 1
|
||||
recipeIndex = recipeIndex + 1
|
||||
|
||||
local handler = craftTabData.handler
|
||||
local craft = handler:getCraftByName(craftTabData.selected_craft)
|
||||
local crafts = handler:getLearnedCraftsByOutput(playerName, craft.output)
|
||||
assert(crafts ~= nil)
|
||||
|
||||
if recipeIndex > #crafts then
|
||||
recipeIndex = #crafts
|
||||
end
|
||||
|
||||
craftTabData.selected_recipe_index = recipeIndex
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
end)
|
||||
@@ -537,7 +551,7 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('.+::%S+::%S+::item_button',fun
|
||||
|
||||
local playerName = player:get_player_name()
|
||||
local craftTabData = PlayerInventoryUI:getTabCraftData(playerName, tabType, tabName)
|
||||
craftTabData.selected_recipe_index = 0
|
||||
craftTabData.selected_recipe_index = 1
|
||||
craftTabData.selected_craft = craftName
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
end)
|
||||
|
||||
@@ -41,10 +41,10 @@ local function getCraftTabTemplate(self, playerName, tabType, tabName, handler)
|
||||
crafts = handler:getLearnedCraftsMatch(playerName, searchFieldValue)
|
||||
elseif selectedGroup == nil then
|
||||
---@type (CraftSystem.PrimitiveCraft[]|CraftSystem.PrimitiveCraft)[]
|
||||
crafts = handler:getLearnedCrafts(playerName)
|
||||
crafts = handler:getLearnedGroupedCrafts(playerName)
|
||||
else
|
||||
---@type CraftSystem.PrimitiveCraft[]
|
||||
crafts = handler:getCraftsByGroup(selectedGroup)
|
||||
crafts = handler:getLearnedCraftsByGroup(playerName, selectedGroup)
|
||||
end
|
||||
|
||||
local craftsListForm = Formspec:new()
|
||||
@@ -117,7 +117,10 @@ local function getCraftTabTemplate(self, playerName, tabType, tabName, handler)
|
||||
:label(2.5,8.5, ('%s/%s'):format(pageNumber, pagesMax))
|
||||
|
||||
if selectedCraft ~= '' then
|
||||
local recipeIndex = craftTabData.selected_recipe_index or 1
|
||||
local craft = handler:getCraftByName(selectedCraft)
|
||||
craft = handler:getLearnedCraftsByOutput(playerName, craft.output)[recipeIndex]
|
||||
|
||||
local item = ItemStack(craft.output)
|
||||
local itemDef = item:get_definition()
|
||||
|
||||
@@ -125,9 +128,12 @@ local function getCraftTabTemplate(self, playerName, tabType, tabName, handler)
|
||||
assert(player ~= nil)
|
||||
local mainList = player:get_inventory():get_list('main')
|
||||
|
||||
local craftsByOutput = handler:getLearnedCraftsByOutput(playerName, craft.output)
|
||||
local recipeIndex = craftTabData.selected_recipe_index or 1
|
||||
|
||||
CraftTab
|
||||
:itemImage(5.5, 0.5, 2, 2, craft.output)
|
||||
:label(10, 0.5, ('%s/%s'):format(0+1, 'TODO')) -- TODO
|
||||
:label(10, 0.5, ('%s/%s'):format(recipeIndex, #craftsByOutput))
|
||||
:textArea(5.5, 3, 5, 4, nil, nil, craft:toString(mainList))
|
||||
:button(5.5, 7.5, 0.5, 1, tabType..'::'..tabName..'::alt_recipe_back', '<')
|
||||
:button(6, 7.5, 2, 1, tabType..'::'..tabName..'::craft_item', '1')
|
||||
|
||||
Reference in New Issue
Block a user