CraftSystem: minor fixes

This commit is contained in:
Van
2026-03-28 17:00:54 +03:00
parent 53801a56a8
commit 2935c4d10b
3 changed files with 15 additions and 6 deletions

View File

@@ -1,3 +1,5 @@
local PLAYERS_KNOW_ALL_RECIPES = true
---Abstract class for handling crafting. ---Abstract class for handling crafting.
---@class CraftSystem.BaseCraftHandler ---@class CraftSystem.BaseCraftHandler
---@field craftsByName table<string, CraftSystem.BaseCraft> ---@field craftsByName table<string, CraftSystem.BaseCraft>
@@ -36,10 +38,17 @@ end
---@param playerName string ---@param playerName string
---@return table<string, CraftSystem.BaseCraft> ---@return table<string, CraftSystem.BaseCraft>
function BaseCraftHandler:getLearnedCrafts(playerName) function BaseCraftHandler:getLearnedCrafts(playerName)
local crafts = self.learnedCrafts[playerName] if PLAYERS_KNOW_ALL_RECIPES then
return self.craftsByName
end
assert(crafts ~= nil, ('There is no primitive crafting data for a player named `%s`.'):format( local crafts = self.learnedCrafts[playerName]
playerName)) print(playerName)
if crafts == nil then
crafts = {}
self.learnedCrafts[playerName] = crafts
end
return crafts return crafts
end end

View File

@@ -18,7 +18,7 @@ local PrimitiveCraft = extend(BaseCraft, {})
---@class CraftSystem.PrimitiveCraftDef : CraftSystem.BaseCraftDef ---@class CraftSystem.PrimitiveCraftDef : CraftSystem.BaseCraftDef
---@field output string ---@field output string
---@field recipe CraftSystem.CraftRecipe ---@field recipe CraftSystem.CraftRecipe
---@field returnItems ItemStackString[] ---@field returnItems ItemStackString[]?
---@param name string ---@param name string
---@param def CraftSystem.PrimitiveCraftDef ---@param def CraftSystem.PrimitiveCraftDef

View File

@@ -15,8 +15,8 @@ local PrimitiveCraft = require('CraftSystem.PrimitiveCraft')
---simple crafting based on a recipe-result scheme. ---simple crafting based on a recipe-result scheme.
---@class CraftSystem.PrimitiveCraftHandler : CraftSystem.BaseCraftHandler ---@class CraftSystem.PrimitiveCraftHandler : CraftSystem.BaseCraftHandler
---@field getCraftByName fun(self, craftName:string):CraftSystem.PrimitiveCraft ---@field getCraftByName fun(self, craftName:string):CraftSystem.PrimitiveCraft
---@field getCraftsByGroup fun(self, craftGroup):CraftSystem.PrimitiveCraft[] ---@field getCraftsByGroup fun(self, craftGroup:string):CraftSystem.PrimitiveCraft[]
---@field getLearnedCrafts fun(self, playerName):table<string, CraftSystem.PrimitiveCraft> ---@field getLearnedCrafts fun(self, playerName:string):table<string, CraftSystem.PrimitiveCraft>
local PrimitiveCraftHandler = extend(BaseCraftHandler, {}) local PrimitiveCraftHandler = extend(BaseCraftHandler, {})
---Register a primitive craft that does not require special interaction. ---Register a primitive craft that does not require special interaction.