diff --git a/.luarc.json b/.luarc.json index 78e99e8..df28d4c 100644 --- a/.luarc.json +++ b/.luarc.json @@ -21,9 +21,7 @@ "diagnostics": { "libraryFiles": "Enable", "workspaceDelay": 1, - "disable": [ - "inject-field" - ], + "disable": [], "globals": [ // Smc globals: "Smc", diff --git a/mods/CORE/CraftSystem/src/CraftSystem.lua b/mods/CORE/CraftSystem/src/CraftSystem.lua index 4ca91c1..e6c1b9a 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem.lua @@ -134,7 +134,7 @@ local function getMaterials(craft, recipeIndex, count) local materialStacks = {} local materialGroups = {} - for _, itemName in ipairs(craft:getRecipe(recipeIndex)) do + for _, itemName in ipairs(craft.recipe) do local group = itemName:match('group:(%S+)') local materialCount = itemName:match('group:%S+ (%S+)') or 1 diff --git a/mods/CORE/CraftSystem/src/CraftSystem/BaseCraft.lua b/mods/CORE/CraftSystem/src/CraftSystem/BaseCraft.lua index e83ddc7..38c0edc 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/BaseCraft.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/BaseCraft.lua @@ -5,7 +5,6 @@ local CHECK = {YES = '[x]', NO = '[ ]', EMPTY = '-'} ---@class CraftSystem.BaseCraft : Class ---@field name string ---@field recipe ItemStackString[] ----@field altRecipes CraftSystem.CraftRecipe[] ---@field output ItemStackString ---@field group CraftSystem.CraftGroup local BaseCraft = Class:extend({}) @@ -13,7 +12,6 @@ local BaseCraft = Class:extend({}) ---Definition table for the `CraftSystem.BaseCraft`. ---@class CraftSystem.BaseCraftDef ---@field recipe ItemStackString[] ----@field altRecipes CraftSystem.CraftRecipe[]? ---@field output ItemStackString ---@field group CraftSystem.CraftGroup? @@ -25,7 +23,6 @@ function BaseCraft:new(name, def) local instance = self:getInstance({}) instance.name = name instance.recipe = def.recipe - instance.altRecipes = def.altRecipes or {} instance.output = def.output instance.group = def.group @@ -80,46 +77,11 @@ local function getCheckMaterialGroup(material, count, list) return CHECK.NO end ----Returns the crafting recipe corresponding to the index. ----@param index integer Recipe number. If `0` is specified, ---- the primary craft (`craft.recipe`) will be used; ---- if `1` or greater, the alternative craft ---- corresponding to the index will be used (`craft.altRecipes`). ----@return CraftSystem.CraftRecipe -function BaseCraft:getRecipe(index) - local recipe - if index == 0 or self.altRecipes == nil then - recipe = self.recipe - else - if index > #self.altRecipes then - recipe = self.altRecipes[#self.altRecipes] - else - recipe = self.altRecipes[index] - end - end - assert(recipe ~= nil) - - return recipe -end - ----@param recipeIndex integer? ----@param mainList ItemStack[]? ----@return string -function BaseCraft:recipeToString(recipeIndex, mainList) - local recipe - if recipeIndex == nil or recipeIndex == 0 or self.altRecipes == nil then - recipe = self.recipe - else - if recipeIndex > #self.altRecipes then - recipe = self.altRecipes[#self.altRecipes] - else - recipe = self.altRecipes[recipeIndex] - end - end - assert(recipe ~= nil) - +---@param mainList ItemStack[]? +---@return string +function BaseCraft:recipeToString(mainList) local recipeDesc = '' - for _, itemName in ipairs(recipe) do + for _, itemName in ipairs(self.recipe) do local group, count = itemName:match('group:(%S+)'), itemName:match('group:%S+ (%S+)') or 1 if group == nil then @@ -139,16 +101,15 @@ function BaseCraft:recipeToString(recipeIndex, mainList) return recipeDesc end ----@param recipeIndex integer? ----@param mainList ItemStack[]? ----@return string -function BaseCraft:toString(recipeIndex, mainList) +---@param mainList ItemStack[]? +---@return string +function BaseCraft:toString(mainList) local outputItem = ItemStack(self.output) local outputItemSettings = Smc.getItemDefinition(outputItem).settings local craftDesc = ('%s\n\nNeeded:\n%s'):format( outputItemSettings._title, - self:recipeToString(recipeIndex, mainList)) + self:recipeToString(mainList)) return craftDesc end diff --git a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua index 06fe318..b0d27f5 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua @@ -198,7 +198,7 @@ function ImmersiveCraft:toString(recipeIndex, mainList) local craftDesc = ('%s\n\nRecipe:\n%s\nActions:\n%s'):format( outputItemSettings._title, - BaseCraft.recipeToString(self, recipeIndex, mainList), + BaseCraft.recipeToString(self, mainList), self:recipeToString(recipeIndex, mainList)) return craftDesc diff --git a/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraftHandler.lua b/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraftHandler.lua index e614b24..b882386 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraftHandler.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraftHandler.lua @@ -51,17 +51,6 @@ function PrimitiveCraftHandler:registerCraft(craftName, def) tableInsert(self.craftsList, craft) end ----Adds alternative recipes to the craft with the specified name. ---- ----If a craft with the specified name does not exist, an error will call. ----@param craftName string ----@param recipes CraftSystem.CraftRecipe[] -function PrimitiveCraftHandler:registerAlternativeRecipes(craftName, recipes) - local craft = PrimitiveCraftHandler:getCraftByName(craftName) - - craft.altRecipes = tableJoin(craft.altRecipes or {}, recipes) -end - -- Sort the list of crafts in alphabetical order by product name and combine crafts into groups. -- Provides a convenient list of crafting items in the player's inventory. core.register_on_mods_loaded(function() diff --git a/mods/GAME/ITEMS/wood/init.lua b/mods/GAME/ITEMS/wood/init.lua index c2cd7df..188d322 100644 --- a/mods/GAME/ITEMS/wood/init.lua +++ b/mods/GAME/ITEMS/wood/init.lua @@ -291,10 +291,6 @@ local function registerWood(name, x, def) recipe = { 'wood:'..name..'_bar' }, - altRecipes = { - { 'wood:'..name..'_plank 2' }, - { 'wood:'..name..'_log'} - }, output = 'wood:'..name..'_stick 4', group = 'wood:sticks', }) diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/baseGetCraftTab.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/baseGetCraftTab.lua index c06deee..1a263be 100644 --- a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/baseGetCraftTab.lua +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/baseGetCraftTab.lua @@ -121,20 +121,14 @@ local function getCraftTabTemplate(self, playerName, tabType, tabName, handler) local item = ItemStack(craft.output) local itemDef = item:get_definition() - local recipeIndex = craftTabData.selected_recipe_index or 0 - if recipeIndex > #craft.altRecipes then - recipeIndex = #craft.altRecipes - craftTabData.selected_recipe_index = #craft.altRecipes - end - local player = core.get_player_by_name(playerName) assert(player ~= nil) local mainList = player:get_inventory():get_list('main') CraftTab :itemImage(5.5, 0.5, 2, 2, craft.output) - :label(10, 0.5, ('%s/%s'):format(recipeIndex+1, #craft.altRecipes+1)) - :textArea(5.5, 3, 5, 4, nil, nil, craft:toString(recipeIndex, mainList)) + :label(10, 0.5, ('%s/%s'):format(0+1, 'TODO')) -- TODO + :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') :button(8, 7.5,2, 1, tabType..'::'..tabName..'::craft_item', ''..tostring(itemDef.stack_max))