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.
---@class CraftSystem.BaseCraftHandler
---@field craftsByName table<string, CraftSystem.BaseCraft>
@@ -36,10 +38,17 @@ end
---@param playerName string
---@return table<string, CraftSystem.BaseCraft>
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(
playerName))
local crafts = self.learnedCrafts[playerName]
print(playerName)
if crafts == nil then
crafts = {}
self.learnedCrafts[playerName] = crafts
end
return crafts
end

View File

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

View File

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