diff --git a/changelog.txt b/changelog.txt index de7b488..7f37822 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,15 @@ --------------------------------------------------------------------------------------------------- +Version: 2.0.5 +Date: 2024-11-06 + Changes: + - Reworked custom fluid recipe created by offshore-pump + - Implemented productivity bonus on recipe when technoly researched (need refresh sheet) + Bugfixes: + - Fix error on accumulator recipe + - Fix search recipe in boiler recipes when click a ingredient or a product + - Fix limitation message when module is not usable (module priority) + - Fix copy block parameters (copy or download) +--------------------------------------------------------------------------------------------------- Version: 2.0.4 Date: 2024-10-29 Changes: diff --git a/controller/Controller.lua b/controller/Controller.lua index 95680f0..39511f8 100644 --- a/controller/Controller.lua +++ b/controller/Controller.lua @@ -34,6 +34,7 @@ require "selector.RecipeSelector" require "selector.TechnologySelector" require "selector.ItemSelector" require "selector.FluidSelector" +require "selector.TileSelector" require "model.Prototype" require "model.ElectricPrototype" @@ -45,6 +46,7 @@ require "model.ItemPrototype" require "model.Product" require "model.RecipePrototype" require "model.Technology" +require "model.TilePrototype" ModGui = require "mod-gui" Cache = require "data.Cache" @@ -96,6 +98,7 @@ function Controller:prepare() table.insert(forms, TechnologySelector("HMTechnologySelector")) table.insert(forms, ItemSelector("HMItemSelector")) table.insert(forms, FluidSelector("HMFluidSelector")) + table.insert(forms, TileSelector("HMTileSelector")) table.insert(forms, LogisticEdition("HMLogisticEdition")) table.insert(forms, ModelEdition("HMModelEdition")) @@ -131,6 +134,7 @@ function Controller:on_init() table.insert(forms, TechnologySelector("HMTechnologySelector")) table.insert(forms, ItemSelector("HMItemSelector")) table.insert(forms, FluidSelector("HMFluidSelector")) + table.insert(forms, TileSelector("HMTileSelector")) for _,form in pairs(forms) do form:prepare() end diff --git a/data/ModelBuilder.lua b/data/ModelBuilder.lua index 83a8cd9..7fcac2c 100644 --- a/data/ModelBuilder.lua +++ b/data/ModelBuilder.lua @@ -657,10 +657,6 @@ function ModelBuilder.copyBlock(into_model, into_block, from_block) if is_block then local new_block = Model.newBlock(into_model, child) new_block.index = child_index - new_block.unlinked = child.by_factory and true or false - new_block.by_factory = child.by_factory - new_block.by_product = child.by_product - new_block.by_limit = child.by_limit into_model.blocks[new_block.id] = new_block ModelBuilder.copyBlock(into_model, new_block, child) into_block.children[new_block.id] = new_block @@ -680,8 +676,8 @@ function ModelBuilder.copyBlock(into_model, into_block, from_block) end end - if recipe.contraint ~= nil then - recipe_model.contraint = table.deepcopy(recipe.contraint) + if recipe.contraints ~= nil then + recipe_model.contraints = table.deepcopy(recipe.contraints) end into_block.children[recipe_model.id] = recipe_model child_index = child_index + 1 @@ -691,9 +687,23 @@ function ModelBuilder.copyBlock(into_model, into_block, from_block) end if into_block ~= nil then table.reindex_list(into_block.children) + into_block.unlinked = from_block.unlinked + into_block.by_factory = from_block.by_factory + into_block.by_product = from_block.by_product + into_block.by_limit = from_block.by_limit + if from_block.products ~= nil then + into_block.products = table.deepcopy(from_block.products) + end + if from_block.ingredients ~= nil then + into_block.ingredients = table.deepcopy(from_block.ingredients) + end if from_block.products_linked ~= nil then into_block.products_linked = table.deepcopy(from_block.products_linked) end + if from_block.contraints ~= nil then + into_block.contraints = table.deepcopy(from_block.contraints) + end + end end end diff --git a/data/ModelCompute.lua b/data/ModelCompute.lua index 2a1a62b..a9e7898 100644 --- a/data/ModelCompute.lua +++ b/data/ModelCompute.lua @@ -96,7 +96,6 @@ function ModelCompute.update(model) if model ~= nil and model.blocks ~= nil then -- Add parameters Model.appendParameters(model) - model.input = {} ModelCompute.updateBlock(model, model.block_root) ModelCompute.finalizeBlock(model.block_root, 1) model.version = Model.version @@ -597,13 +596,14 @@ end ---@return RecipeData function ModelCompute.computeModuleEffects(recipe, parameters) local factory = recipe.factory - factory.effects = { speed = 0, productivity = 0, consumption = 0, pollution = 0, quality = 0 } + local recipe_productivity = Player.getRecipeProductivityBonus(recipe.name) + factory.effects = { speed = 0, productivity = recipe_productivity, consumption = 0, pollution = 0, quality = 0 } if parameters ~= nil then - factory.effects.speed = parameters.effects.speed - factory.effects.productivity = parameters.effects.productivity - factory.effects.consumption = parameters.effects.consumption - factory.effects.pollution = parameters.effects.pollution - factory.effects.quality = parameters.effects.quality or 0 + factory.effects.speed = factory.effects.speed + (parameters.effects.speed or 0) + factory.effects.productivity = factory.effects.productivity + (parameters.effects.productivity or 0) + factory.effects.consumption = factory.effects.consumption + (parameters.effects.consumption or 0) + factory.effects.pollution = factory.effects.pollution + (parameters.effects.pollution or 0) + factory.effects.quality = factory.effects.quality + (parameters.effects.quality or 0) end factory.cap = { speed = 0, productivity = 0, consumption = 0, pollution = 0 } local factory_prototype = EntityPrototype(factory) diff --git a/dialog/AdminPanel.lua b/dialog/AdminPanel.lua index 70a5ced..0527f5f 100644 --- a/dialog/AdminPanel.lua +++ b/dialog/AdminPanel.lua @@ -770,6 +770,7 @@ function AdminPanel:onEvent(event) table.insert(forms, TechnologySelector("HMTechnologySelector")) table.insert(forms, ItemSelector("HMItemSelector")) table.insert(forms, FluidSelector("HMFluidSelector")) + table.insert(forms, TileSelector("HMTileSelector")) for _,form in pairs(forms) do if event.item2 == form.classname then form:prepare() diff --git a/dialog/PropertiesPanel.lua b/dialog/PropertiesPanel.lua index 07953d3..d230dea 100644 --- a/dialog/PropertiesPanel.lua +++ b/dialog/PropertiesPanel.lua @@ -184,6 +184,7 @@ function PropertiesPanel:onEvent(event) if api ~= nil then Cache.setData(self.classname, "runtime_api", api) end + self:updateData(event) end end @@ -209,18 +210,21 @@ end function PropertiesPanel:updateRuntimeApi(event) local scroll_panel = self:getRuntimeApiTab() scroll_panel.clear() - local url_frame = GuiElement.add(scroll_panel, GuiFlowH()) - url_frame.style.horizontal_spacing = 5 - GuiElement.add(url_frame, GuiLabel("json_label"):caption("URL to find Runtime API")) - local json_url = GuiElement.add(url_frame, - GuiTextField("json_url"):text("https://lua-api.factorio.com/latest/runtime-api.json")) + + + local json_table = GuiElement.add(scroll_panel, GuiTable("table-resources"):column(3)) + json_table.style.cell_padding = 5 + + GuiElement.add(json_table, GuiLabel("json_label"):caption("URL to find Runtime API")) + local json_url = GuiElement.add(json_table, GuiTextField("json_url"):text("https://lua-api.factorio.com/latest/runtime-api.json")) json_url.style.width = 600 + GuiElement.add(json_table, GuiFlow()) - local json_frame = GuiElement.add(scroll_panel, GuiFlowV()) - json_frame.style.vertical_spacing = 5 - local json_string = GuiElement.add(json_frame, GuiTextBox("json_string")) + GuiElement.add(json_table, GuiLabel("json_string_label"):caption("Json String")) + local json_string = GuiElement.add(json_table, GuiTextField("json_string")) json_string.style.width = 600 - GuiElement.add(json_frame, GuiButton(self.classname, "import-runtime-api"):caption("Import Runtime API")) + + GuiElement.add(json_table, GuiButton(self.classname, "import-runtime-api"):caption("Import Runtime API")) end ------------------------------------------------------------------------------- @@ -249,6 +253,7 @@ function PropertiesPanel:updateMenu(event) GuiElement.add(action_panel, GuiButton("HMFluidSelector", "OPEN", "HMPropertiesPanel"):caption({ "helmod_result-panel.select-button-fluid" })) GuiElement.add(action_panel, GuiButton("HMRecipeSelector", "OPEN", "HMPropertiesPanel"):caption({ "helmod_result-panel.select-button-recipe" })) GuiElement.add(action_panel, GuiButton("HMTechnologySelector", "OPEN", "HMPropertiesPanel"):caption({"helmod_result-panel.select-button-technology" })) + GuiElement.add(action_panel, GuiButton("HMTileSelector", "OPEN", "HMPropertiesPanel"):caption({ "helmod_result-panel.select-button-tile" })) end ------------------------------------------------------------------------------- @@ -282,8 +287,7 @@ function PropertiesPanel:updateData(event) data[properties.name][key] = properties end end - local result_table = GuiElement.add(content_panel, - GuiTable("table-resources"):column(#prototype_compare + 1):style("helmod_table-rule-odd")) + local result_table = GuiElement.add(content_panel, GuiTable("table-resources"):column(#prototype_compare + 1):style("helmod_table-rule-odd")) self:addTableHeader(result_table, prototype_compare) @@ -348,13 +352,17 @@ function PropertiesPanel:addTableHeader(itable, prototype_compare) icon_type = "fluid" localised_name = fluid_prototype:getLocalisedName() elseif string.find(prototype.type, "recipe") then - local recipe_protoype = RecipePrototype(prototype) - icon_type = recipe_protoype:getType() - localised_name = recipe_protoype:getLocalisedName() + local recipe_prototype = RecipePrototype(prototype) + icon_type = recipe_prototype:getType() + localised_name = recipe_prototype:getLocalisedName() elseif prototype.type == "technology" then - local technology_protoype = Technology(prototype) + local technology_prototype = Technology(prototype) icon_type = "technology" - localised_name = technology_protoype:getLocalisedName() + localised_name = technology_prototype:getLocalisedName() + elseif prototype.type == "tile" then + local tile_prototype = TilePrototype(prototype) + icon_type = "tile" + localised_name = tile_prototype:getLocalisedName() end local cell_header = GuiElement.add(itable, GuiFlowH("header", prototype.name, index)) GuiElement.add(cell_header, @@ -525,6 +533,8 @@ function PropertiesPanel:getPrototypeData(prototype) lua_prototype = RecipePrototype(prototype):native() elseif prototype.type == "technology" then lua_prototype = Technology(prototype):native() + elseif prototype.type == "tile" then + lua_prototype = TilePrototype(prototype):native() end if lua_prototype ~= nil then local properties = self:parseProperties(lua_prototype, 0) diff --git a/edition/ParametersEdition.lua b/edition/ParametersEdition.lua index 0388e1f..f16cd6e 100644 --- a/edition/ParametersEdition.lua +++ b/edition/ParametersEdition.lua @@ -61,6 +61,7 @@ function ParametersEdition:updateEffects(event) GuiElement.add(block_table, GuiLabel("label-pollution"):caption({ "description.pollution-bonus" })) GuiElement.add(block_table, GuiTextField(self.classname, "change-effect", "pollution"):text(Format.formatNumberElement((effects.pollution or 1)*100)):style("helmod_textfield")) + end ------------------------------------------------------------------------------- diff --git a/edition/RecipeEdition.lua b/edition/RecipeEdition.lua index 1466463..09227a1 100644 --- a/edition/RecipeEdition.lua +++ b/edition/RecipeEdition.lua @@ -913,8 +913,10 @@ function RecipeEdition:updateFactoryModulesPriority(factory_module_panel) local module = ItemPrototype(element.name) local tooltip = GuiTooltipModule("tooltip.add-module"):element({type="item", name=element.name}):withControlInfo(control_info) if Player.checkFactoryLimitationModule(module:native(), recipe) == false then - if (module:native().limitation_message_key ~= nil) and (module:native().limitation_message_key ~= "") then - tooltip = {"item-limitation."..module:native().limitation_message_key} + local limitation_message = Player.getFactoryLimitationModuleMessage(module:native(), recipe); + + if limitation_message ~= nil then + tooltip = limitation_message else tooltip = "" end diff --git a/gui/GuiCell.lua b/gui/GuiCell.lua index 1deb971..7c67b6b 100644 --- a/gui/GuiCell.lua +++ b/gui/GuiCell.lua @@ -193,7 +193,7 @@ function GuiCell:add_icon_info(button, info_icon) end if type == "fluid" then tooltip = "tooltip.resource-recipe" - sprite_name = GuiElement.getSprite(defines.sprite_info.developer) + sprite_name = GuiElement.getSprite(defines.sprite_info.mining) end if type == "resource" then tooltip = "tooltip.resource-recipe" diff --git a/info.json b/info.json index a91fabd..6568635 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "helmod", - "version": "2.0.4", + "version": "2.0.5", "title": "Helmod: Assistant for planning your factory", "author": "Helfima", "contact": "Helfima", diff --git a/locale/en/helmod.cfg b/locale/en/helmod.cfg index f86dfc1..6ad364f 100644 --- a/locale/en/helmod.cfg +++ b/locale/en/helmod.cfg @@ -175,6 +175,7 @@ fluid-title=Fluid selector recipe-title=Recipe selector technology-title=Technology selector container-title=Container selector +tile-title=Tile selector [helmod_product-edition-panel] title=Edit Product @@ -319,6 +320,7 @@ select-button-fluid=Select fluid select-button-recipe=Select recipe select-button-technology=Select technology select-button-container=Select container +select-button-tile=Select tile row-button-delete=X row-button-up=U row-button-down=D @@ -518,3 +520,7 @@ helmod=Helmod [helmod_bug-repport-panel] title=Bug Repport no_error=No errors to report + +[helmod_limitation] +no-module-slot=No module slot +not-allowed-category-module=Not allowed '__1__' category module \ No newline at end of file diff --git a/locale/fr/helmod.cfg b/locale/fr/helmod.cfg index 30ddf29..c5ed825 100644 --- a/locale/fr/helmod.cfg +++ b/locale/fr/helmod.cfg @@ -146,6 +146,7 @@ fluid-title=Fluid selector recipe-title=Sélecteur de recette technology-title=Sélecteur de technologie container-title=Sélecteur de conteneur +tile-title=Sélecteur de tuile [helmod_product-edition-panel] title=Edition de produit @@ -290,6 +291,7 @@ select-button-fluid=Sélectionner un fluide select-button-recipe=Sélectionner une recette select-button-technology=Sélectionner une technologie select-button-container=Sélectionner un container +select-button-tile=Sélectionner une tuile row-button-delete=X row-button-up=U row-button-down=D @@ -402,6 +404,8 @@ info-module=Information module add-module=Ajouter ce module remove-module=Supprimer ce module remove-element=Supprimer cette ligne +remove-block-confirm=Êtes-vous sûr de vouloir ce bloc ? +remove-block-cancel=Annuler la suppression de bloc remove-element_confirm=Êtes-vous sûr de vouloir cette ligne ? remove-element_cancel=Annuler la suppression de cette ligne up-element=Monter cette ligne\n__CONTROL_STYLE_BEGIN__Maj + Clic__CONTROL_STYLE_END__: Monter de __1__ lignes\n__CONTROL_STYLE_BEGIN__Ctrl + Click__CONTROL_STYLE_END__: Monter à la première ligne @@ -459,4 +463,8 @@ excessive-event-iteration=Le nombre d'itération sur les événements a été d [helmod_bug-repport-panel] title=Rapport de Bug -no_error=Aucune erreur à rapporter \ No newline at end of file +no_error=Aucune erreur à rapporter + +[helmod_limitation] +no-module-slot=Aucun emplacement pour module +not-allowed-category-module=Catégorie de module '__1__' non autorisée \ No newline at end of file diff --git a/model/EnergySourcePrototype.lua b/model/EnergySourcePrototype.lua index 37b79ee..4dd16bb 100644 --- a/model/EnergySourcePrototype.lua +++ b/model/EnergySourcePrototype.lua @@ -131,7 +131,7 @@ end ---@return number --default 0 function ElectricSourcePrototype:getInputFlowLimit() if self.lua_prototype ~= nil then - return (self.lua_prototype.input_flow_limit or 0) * 60 + return (self.lua_prototype.get_input_flow_limit() or 0) * 60 end return 0 end @@ -141,7 +141,7 @@ end ---@return number --default 0 function ElectricSourcePrototype:getOutputFlowLimit() if self.lua_prototype ~= nil then - return (self.lua_prototype.output_flow_limit or 0) * 60 + return (self.lua_prototype.get_output_flow_limit() or 0) * 60 end return 0 end diff --git a/model/Player.lua b/model/Player.lua index 1821474..07ef6ba 100644 --- a/model/Player.lua +++ b/model/Player.lua @@ -423,6 +423,16 @@ function Player.getRecipes() return prototypes.recipe end +------------------------------------------------------------------------------- +---Return recipe productivity +---@return number +function Player.getRecipeProductivityBonus(recipe_name) + local force = Player.getForce() + local recipe_force = force.recipes[recipe_name] + if recipe_force == nil then return 0 end + return recipe_force.productivity_bonus or 0 +end + ------------------------------------------------------------------------------- ---Return technologie prototypes ---@param filters table @@ -571,6 +581,63 @@ function Player.checkFactoryLimitationModule(module, lua_recipe) return true end +------------------------------------------------------------------------------- +---Check factory limitation module +---@param module table +---@param lua_recipe RecipeData +---@return table | nil +function Player.getFactoryLimitationModuleMessage(module, lua_recipe) + local factory = lua_recipe.factory + local factory_prototype = EntityPrototype(factory) + local factory_module_slots= factory_prototype:getModuleInventorySize() + if factory_module_slots == 0 then + return {"helmod_limitation.no-module-slot"} + end + local model_filter_factory_module = User.getModGlobalSetting("model_filter_factory_module") + if model_filter_factory_module == false then + return nil + end + + if lua_recipe.type ~= "resource" then + local module_prototype = ItemPrototype(module) + local module_effects = module_prototype:getModuleEffects() + local module_category = module_prototype:getCategory() + local recipe_prototype = RecipePrototype(lua_recipe) + local recipe_allowed_effects = recipe_prototype:getAllowedEffects() + local entity_prototype = EntityPrototype(factory) + local entity_allowed_effects = entity_prototype:getAllowedEffects() + local recipe_allowed_module_categories = recipe_prototype:getAllowedModuleCategories() + local entity_allowed_module_categories = entity_prototype:getAllowedModuleCategories() + + for effect_name, value in pairs(module_effects) do + local positive_effect = Player.checkPositiveEffect(effect_name, value) + if table.size(recipe_allowed_effects) > 0 then + local recipe_allowed_effect = recipe_allowed_effects[effect_name] + if recipe_allowed_effect == false and positive_effect == true then + return recipe_prototype:getAllowedEffectMessage(effect_name) + end + end + if table.size(entity_allowed_effects) > 0 then + local entity_allowed_effect = entity_allowed_effects[effect_name] + if entity_allowed_effect == false and positive_effect == true then + return recipe_prototype:getAllowedEffectMessage(effect_name) + end + end + end + if recipe_allowed_module_categories ~= nil then + if not(recipe_allowed_module_categories[module_category]) then + return {"helmod_limitation.not-allowed-category-module", module_category} + end + end + if entity_allowed_module_categories ~= nil then + if not(entity_allowed_module_categories[module_category]) then + return {"helmod_limitation.not-allowed-category-module", module_category} + end + end + end + return nil +end + local is_effect_positive = {speed=true, productivity=true, quality=true, consumption=false, pollution=false} function Player.checkPositiveEffect(name, value) @@ -648,7 +715,7 @@ function Player.getProductionsCrafting(category, lua_recipe) if category == "crafting-handonly" then productions["character"] = prototypes.entity["character"] elseif lua_recipe.name ~= nil and category == "fluid" then - for key, lua_entity in pairs(Player.getOffshorePumps(lua_recipe.name)) do + for key, lua_entity in pairs(Player.getOffshorePumps()) do productions[lua_entity.name] = lua_entity end else @@ -888,22 +955,14 @@ end ------------------------------------------------------------------------------- ---Return list of Offshore-Pump ----@param fluid_name string ---@return table -function Player.getOffshorePumps(fluid_name) +function Player.getOffshorePumps() local filters = {} table.insert(filters, { filter = "type", type = "offshore-pump", mode = "or" }) local entities = prototypes.get_entity_filtered(filters) local offshore_pump = {} for key, entity in pairs(entities) do - if entity.fluid.name == fluid_name then - for _, fluidbox in pairs(entity.fluidbox_prototypes) do - if #fluidbox.pipe_connections > 0 then - offshore_pump[key] = entity - break - end - end - end + offshore_pump[key] = entity end return offshore_pump end @@ -1041,25 +1100,19 @@ end function Player.getFluidRecipes() local recipes = {} - ---Offshore pumps - local filters = {} - table.insert(filters, { filter = "type", type = "offshore-pump", mode = "or" }) - local entities = prototypes.get_entity_filtered(filters) - for key, entity in pairs(entities) do - for _, fluidbox in pairs(entity.fluidbox_prototypes) do - if #fluidbox.pipe_connections > 0 then - local recipe = Player.buildFluidRecipe(entity.fluid.name, {}, nil) - recipe.subgroup = { name = "helmod-fluid", order = "bbbb" } - if not recipes[entity.fluid.name] then - recipes[entity.fluid.name] = recipe - end - if entity.hidden then - recipes[entity.fluid.name].hidden = true - end + local tiles = Player.getTilePrototypes() + for _, tile in pairs(tiles) do + if tile.fluid then + local recipe = Player.buildFluidRecipe(tile.fluid.name, {}, nil) + recipe.subgroup = { name = "helmod-fluid", order = "bbbb" } + if not recipes[tile.fluid.name] then + recipes[tile.fluid.name] = recipe + end + if tile.hidden then + recipes[tile.fluid.name].hidden = true end end end - return recipes end @@ -1313,13 +1366,18 @@ function Player.searchRecipe(element_name, by_ingredient) end end -- recherche dans les fluids - -- for key, recipe in pairs(Player.getFluidRecipes()) do - -- if recipe.name == element_name then - -- table.insert(recipes, {name=recipe.name, type="fluid"}) - -- end - -- end - for key, recipe in pairs(Player.getBoilerRecipes()) do - if recipe.name == element_name then + for key, recipe in pairs(Player.getFluidRecipes()) do + if recipe.name == element_name then + table.insert(recipes, {name=recipe.name, type="fluid"}) + end + end + local boiler_recipes = Player.getBoilerRecipes() + for key, recipe in pairs(boiler_recipes) do + local fluid_name = recipe.output_fluid_name + if by_ingredient == true then + fluid_name = recipe.input_fluid_name + end + if fluid_name == element_name then table.insert(recipes, { name = recipe.name, type = "boiler" }) end end @@ -1412,6 +1470,26 @@ function Player.getItemPrototypeTypes() return types end +------------------------------------------------------------------------------- +---Return tile prototypes +---@param filters? table --{{filter="fuel-category", mode="or", invert=false,["fuel-category"]="chemical"}} +---@return table +function Player.getTilePrototypes(filters) + if filters ~= nil then + return prototypes.get_tile_filtered(filters) + end + return prototypes.tile +end + +------------------------------------------------------------------------------- +---Return tile prototype +---@param name string +---@return LuaTilePrototype +function Player.getTilePrototype(name) + if name == nil then return nil end + return prototypes.tile[name] +end + ------------------------------------------------------------------------------- ---Return item prototype ---@param name string diff --git a/model/RecipePrototype.lua b/model/RecipePrototype.lua index 5bab477..0dcc37c 100644 --- a/model/RecipePrototype.lua +++ b/model/RecipePrototype.lua @@ -88,6 +88,22 @@ function RecipePrototype:getAllowedEffects() return self.lua_prototype.allowed_effects end +------------------------------------------------------------------------------- +---Return Allowed Effects +---@return table | nil +function RecipePrototype:getAllowedEffectMessage(effect_name) + if self.lua_prototype == nil then return nil end + if self.lua_prototype.effect_limitation_messages ~= nil then + local message_name = string.format("allow_%s_message", effect_name) + local effect_limitation_messages = self.lua_prototype.effect_limitation_messages + return effect_limitation_messages[message_name] + else + local message_name = string.format("item-limitation.%s-effect", effect_name) + return {message_name} + end + return nil +end + ------------------------------------------------------------------------------- ---Return Allowed Module Categories ---@return table @@ -516,9 +532,9 @@ function RecipePrototype:getHidden() elseif self.lua_type == "technology" then return false elseif self.lua_type == "fluid" then - local entities = Player.getOffshorePumps(self.lua_prototype.name) - for _, entity in pairs(entities) do - return false + local fluid = Player.getFluidPrototype(self.lua_prototype.name) + if fluid ~= nil then + return fluid.hidden end return false elseif self.lua_type == "boiler" then diff --git a/model/TilePrototype.lua b/model/TilePrototype.lua new file mode 100644 index 0000000..276277c --- /dev/null +++ b/model/TilePrototype.lua @@ -0,0 +1,28 @@ +------------------------------------------------------------------------------- +---@class TilePrototype +TilePrototype = newclass(Prototype,function(base, object) + if object ~= nil and type(object) == "string" then + Prototype.init(base, Player.getTilePrototype(object)) + elseif object ~= nil and object.name ~= nil then + Prototype.init(base, Player.getTilePrototype(object.name)) + end + base.classname = "HMTilePrototype" +end) + +------------------------------------------------------------------------------- +---Return Category +---@return string +function TilePrototype:getCategory() + if self.lua_prototype == nil then return nil end + return self.lua_prototype.category +end + +------------------------------------------------------------------------------- +---Return hidden of Prototype +---@return boolean +function TilePrototype:getHidden() + if self.lua_prototype ~= nil then + return self.lua_prototype.hidden + end + return false +end diff --git a/selector/RecipeSelector.lua b/selector/RecipeSelector.lua index 65dc18b..f0deb68 100644 --- a/selector/RecipeSelector.lua +++ b/selector/RecipeSelector.lua @@ -93,9 +93,9 @@ function RecipeSelector:updateGroups(list_products, list_ingredients, list_trans self:appendGroups(recipe, "recipe-burnt", list_products, list_ingredients, list_translate) end end - -- for key, recipe in pairs(Player.getFluidRecipes()) do - -- self:appendGroups(recipe, "fluid", list_products, list_ingredients, list_translate) - -- end + for key, recipe in pairs(Player.getFluidRecipes()) do + self:appendGroups(recipe, "fluid", list_products, list_ingredients, list_translate) + end for key, recipe in pairs(Player.getBoilerRecipes()) do self:appendGroups(recipe, "boiler", list_products, list_ingredients, list_translate) end @@ -213,7 +213,7 @@ function RecipeSelector:buildPrototypeTooltip(prototype) if prototype.type == "boiler" then entities = Player.getBoilersForRecipe(recipe_prototype) elseif prototype.type == "fluid" then - entities = Player.getOffshorePumps(prototype.name) + entities = Player.getOffshorePumps() end if table.size(entities) > 0 then table.insert(tooltip, {"", "\n", helmod_tag.font.default_bold, helmod_tag.color.gold, {"helmod_common.made-in"}, ":", helmod_tag.color.close, helmod_tag.font.close}) diff --git a/selector/TileSelector.lua b/selector/TileSelector.lua new file mode 100644 index 0000000..33934f9 --- /dev/null +++ b/selector/TileSelector.lua @@ -0,0 +1,63 @@ +require "selector.AbstractSelector" +------------------------------------------------------------------------------- +---Class to build tile selector +-- +---@module TileSelector +---@extends #AbstractSelector +-- + +TileSelector = newclass(AbstractSelector) + +------------------------------------------------------------------------------- +---After initialization +function TileSelector:afterInit() + self.hidden_option = true +end + +------------------------------------------------------------------------------- +---Return caption +---@return table +function TileSelector:getCaption() + return {"helmod_selector-panel.tile-title"} +end + +------------------------------------------------------------------------------- +---Get prototype +---@param element table +---@param type string +---@return table +function TileSelector:getPrototype(element, type) + return TilePrototype(element, type) +end + +------------------------------------------------------------------------------- +---Update groups +---@param list_products table +---@param list_ingredients table +---@param list_translate table +function TileSelector:updateGroups(list_products, list_ingredients, list_translate) + for key, item in pairs(Player.getTilePrototypes()) do + self:appendGroups(item, "tile", list_products, list_ingredients, list_translate) + end + +end + +------------------------------------------------------------------------------- +---Build prototype tooltip +---@param prototype table +---@return table +function TileSelector:buildPrototypeTooltip(prototype) + ---initalize tooltip + local tooltip = TilePrototype(prototype):getLocalisedName() + return tooltip +end + +------------------------------------------------------------------------------- +---Build prototype icon +---@param gui_element GuiLuaElement +---@param prototype table +---@param tooltip table +function TileSelector:buildPrototypeIcon(gui_element, prototype, tooltip) + local button = GuiElement.add(gui_element, GuiButtonSelectSprite(self.classname, "element-select", "tile"):choose(prototype.type, prototype.name)) + button.locked = true +end