diff --git a/cf-lib/data/Item.lua b/cf-lib/data/Item.lua index e7cc877..1cfffcf 100644 --- a/cf-lib/data/Item.lua +++ b/cf-lib/data/Item.lua @@ -42,6 +42,14 @@ function Item:assign(data) return self end +--- Deeply merges data with the item +--- Shorthand for table.merge(item.prototype, data) +--- @param data table The data to merge +function Item:merge(data) + table.merge(self.prototype, data) + return self +end + --- Sets the weight of the item calculated from given count per rocket. --- @param count number The amount of items that fit into a rocket function Item:itemsPerRocket(count) diff --git a/cf-lib/data/Recipe.lua b/cf-lib/data/Recipe.lua index 6ca5192..6eca2b6 100644 --- a/cf-lib/data/Recipe.lua +++ b/cf-lib/data/Recipe.lua @@ -42,6 +42,14 @@ function Recipe:assign(data) return self end +--- Deeply merges data with the recipe +--- Shorthand for table.merge(recipe.prototype, data) +--- @param data table The data to merge +function Recipe:merge(data) + table.merge(self.prototype, data) + return self +end + --- Adds an ingredient to the recipe --- @param ingredientName string The name of the ingredient --- @param amount number The amount of the ingredient (default: 1) @@ -62,7 +70,7 @@ function Recipe:addIngredient(ingredientName, amount) ingredient.amount_min = nil ingredient.amount_max = nil ingredient.probability = nil - return + return self end end table.insert(self.prototype.ingredients, { name = ingredientName, amount = amount, type = ingredientType }) diff --git a/cf-lib/data/Technology.lua b/cf-lib/data/Technology.lua index bf950c8..13a1dd9 100644 --- a/cf-lib/data/Technology.lua +++ b/cf-lib/data/Technology.lua @@ -50,6 +50,14 @@ function Technology:assign(data) return self end +--- Deeply merges data with the technology +--- Shorthand for table.merge(technology.prototype, data) +--- @param data table The data to merge +function Technology:merge(data) + table.merge(self.prototype, data) + return self +end + --- Sets the prerequisite for the technology --- @param prerequisites table The names of the prerequisites function Technology:setPrerequisites(prerequisites)