From b0205806b171000f5740366ab42abe1e3b40a3dd Mon Sep 17 00:00:00 2001 From: Helfima Date: Sun, 17 Nov 2024 01:51:14 +0100 Subject: [PATCH] Model version modified at 2, migration to implement quality in the modules --- changelog.txt | 3 +- data/Model.lua | 2 +- edition/RecipeEdition.lua | 2 + gui/GuiElement.lua | 23 +- gui/GuiTooltip.lua | 1385 ++++++++++++++++++++--------------- info.json | 2 +- migrations/helmod_1.0.0.lua | 31 - migrations/helmod_2.0.7.lua | 88 +++ 8 files changed, 913 insertions(+), 623 deletions(-) delete mode 100644 migrations/helmod_1.0.0.lua create mode 100644 migrations/helmod_2.0.7.lua diff --git a/changelog.txt b/changelog.txt index 102d5d6..dfc0d9c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,10 +1,11 @@ --------------------------------------------------------------------------------------------------- Version: 2.0.7 -Date: 2024-11-14 +Date: 2024-11-17 Features: - Added quality selector for machine and module in recipe edition Changes: - Changed default Amount affect one = 1, Beacon by factory = 1/8 and Constant beacon = 0 (new game) + - Model version modified at 2, migration to implement quality in the modules Bugfixes: - Fix error on accumulator recipe --------------------------------------------------------------------------------------------------- diff --git a/data/Model.lua b/data/Model.lua index 426e17b..810b311 100644 --- a/data/Model.lua +++ b/data/Model.lua @@ -4,7 +4,7 @@ local Model = { ---single-line comment classname = "HMModel", - version = 1, + version = 2, beacon_combo = 4, beacon_factory = 0.5, beacon_factory_constant = 3 diff --git a/edition/RecipeEdition.lua b/edition/RecipeEdition.lua index e433a83..14843ea 100644 --- a/edition/RecipeEdition.lua +++ b/edition/RecipeEdition.lua @@ -531,6 +531,7 @@ function RecipeEdition:onEvent(event) if event.action == "factory-quality-select" then recipe.factory.quality = event.item4 ModelCompute.update(model) + self:updateFactoryInfoTool(event) self:updateFactoryInfo(event) Controller:send("on_gui_recipe_update", event) end @@ -539,6 +540,7 @@ function RecipeEdition:onEvent(event) local beacon = ModelBuilder.getCurrentBeacon(recipe) beacon.quality = event.item4 ModelCompute.update(model) + self:updateBeaconInfoTool(event) self:updateBeaconInfo(event) Controller:send("on_gui_recipe_update", event) end diff --git a/gui/GuiElement.lua b/gui/GuiElement.lua index f55f425..49c2453 100644 --- a/gui/GuiElement.lua +++ b/gui/GuiElement.lua @@ -99,8 +99,8 @@ end ------------------------------------------------------------------------------- ---Get sprite string ---@param type string ----@param name string ----@param format string? +---@param name? string +---@param format? string ---@return string function GuiElement.getSprite(type, name, format) local sprite = "" @@ -137,6 +137,25 @@ function GuiElement.getSprite(type, name, format) return sprite end +------------------------------------------------------------------------------- +---Get sprite string +---@param type string +---@param name string +---@param quality string? +---@return string +function GuiElement.getSpriteWithQuality(type, name, quality) + local sprite = "" + if type == "resource" then type = "entity" end + if type == "rocket" then type = "item" end + if Player.is_valid_sprite_path(string.format("%s/%s", type, name)) then + if quality == nil then + sprite = string.format("[%s=%s]", type, name) + else + sprite = string.format("[%s=%s,quality=%s]", type, name, quality) + end + end + return sprite +end ------------------------------------------------------------------------------- ---Get options ---@return table diff --git a/gui/GuiTooltip.lua b/gui/GuiTooltip.lua index fe78313..a8cd25c 100644 --- a/gui/GuiTooltip.lua +++ b/gui/GuiTooltip.lua @@ -1,9 +1,9 @@ ------------------------------------------------------------------------------- ---Class to help to build GuiTooltip ----@class GuiTooltip -GuiTooltip = newclass(GuiElement,function(base,...) - GuiElement.init(base,...) - base.classname = "HMGuiTooltip" +---@class GuiTooltip : GuiElement +GuiTooltip = newclass(GuiElement, function(base, ...) + GuiElement.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- @@ -11,40 +11,40 @@ end) ---@param element table ---@return GuiTooltip function GuiTooltip:element(element) - self.m_element = element - return self + self.m_element = element + return self end ------------------------------------------------------------------------------- ---Set with logistic information ---@return GuiTooltip function GuiTooltip:withLogistic() - self.m_with_logistic = true - return self + self.m_with_logistic = true + return self end ------------------------------------------------------------------------------- ---Set with energy information ---@return GuiTooltip function GuiTooltip:withEnergy() - self.m_with_energy = true - return self + self.m_with_energy = true + return self end ------------------------------------------------------------------------------- ---Set with effect information ---@return GuiTooltip function GuiTooltip:withEffectInfo(value) - self.m_with_effect_info = value - return self + self.m_with_effect_info = value + return self end ------------------------------------------------------------------------------- ---Set with product information ---@return GuiTooltip function GuiTooltip:withProductInfo() - self.m_with_product_info = true - return self + self.m_with_product_info = true + return self end ------------------------------------------------------------------------------- @@ -52,8 +52,8 @@ end ---@param control_info string ---@return GuiTooltip function GuiTooltip:withControlInfo(control_info) - self.m_with_control_info = control_info - return self + self.m_with_control_info = control_info + return self end ------------------------------------------------------------------------------- @@ -61,8 +61,143 @@ end ---@param by_limit boolean ---@return GuiTooltip function GuiTooltip:byLimit(by_limit) - self.m_by_limit = by_limit - return self + self.m_by_limit = by_limit + return self +end + + +------------------------------------------------------------------------------- +---Append title line +---@param tooltip table +---@param element_type string +---@param element_name string +---@param element_label any +---@param element_quality? string +function GuiTooltip.appendLineTitle(tooltip, element_type, element_name, element_label, element_quality) + local noQuality = true + if Player.hasFeatureQuality() and element_quality ~= nil then + local quality = Player.getQualityPrototype(element_quality) + if quality ~= nil and quality.level > 0 then + local localised_name = quality.localised_name + local color = quality.color + local color_tag = GuiElement.rgbColorTag(color) + local element_sprite = GuiElement.getSpriteWithQuality(element_type, element_name, element_quality) + table.insert(tooltip, { "", "\n", element_sprite, " ", helmod_tag.font.default_bold + , helmod_tag.color.gold, element_label, helmod_tag.color.close + , color_tag, " (", localised_name, ")", helmod_tag.color.close + , helmod_tag.font.close + }) + noQuality = false + end + end + if noQuality then + local element_sprite = GuiElement.getSprite(element_type, element_name, "[%s=%s]") + table.insert(tooltip, { "", "\n", element_sprite, " ", helmod_tag.font.default_bold + , helmod_tag.color.gold, element_label, helmod_tag.color.close + , helmod_tag.font.close + }) + end +end + +------------------------------------------------------------------------------- +---Append title line +---@param tooltip table +---@param element_type string +---@param element_name string +---@param element_amount number +---@param element_label any +---@param element_quality? string +function GuiTooltip.appendLineQuantity(tooltip, element_type, element_name, element_amount, element_label, element_quality) + local noQuality = true + if Player.hasFeatureQuality() and element_quality ~= nil then + local quality = Player.getQualityPrototype(element_quality) + if quality ~= nil and quality.level > 0 then + local localised_name = quality.localised_name + local color = quality.color + local color_tag = GuiElement.rgbColorTag(color) + local element_sprite = GuiElement.getSpriteWithQuality(element_type, element_name, element_quality) + table.insert(tooltip, { "", "\n", element_sprite, " " + , helmod_tag.font.default_bold + , helmod_tag.color.white, element_amount, helmod_tag.color.close + , helmod_tag.font.close + , " x ", helmod_tag.color.gold, element_label, helmod_tag.color.close + , color_tag, " (", localised_name, ")", helmod_tag.color.close + }) + noQuality = false + end + end + if noQuality then + local element_sprite = GuiElement.getSprite(element_type, element_name, "[%s=%s]") + table.insert(tooltip, { "", "\n", element_sprite, " " + , helmod_tag.font.default_bold + , helmod_tag.color.white, element_amount, helmod_tag.color.close + , helmod_tag.font.close + , " x ", helmod_tag.color.gold, element_label, helmod_tag.color.close + }) + end +end + +------------------------------------------------------------------------------- +---Append title line +---@param tooltip table +---@param element_type string +---@param element_name string +---@param element_amount number +---@param element_label any +---@param element_quality? string +function GuiTooltip.appendLineSubQuantity(tooltip, element_type, element_name, element_amount, element_label, element_quality) + local noQuality = true + if Player.hasFeatureQuality() and element_quality ~= nil then + local quality = Player.getQualityPrototype(element_quality) + if quality ~= nil and quality.level > 0 then + local localised_name = quality.localised_name + local color = quality.color + local color_tag = GuiElement.rgbColorTag(color) + local element_sprite = GuiElement.getSpriteWithQuality(element_type, element_name, element_quality) + table.insert(tooltip, { "", "\n", "[img=helmod-tooltip-blank]", " " + , element_sprite + , helmod_tag.font.default_bold + , helmod_tag.color.white, " ", element_amount, helmod_tag.color.close + , helmod_tag.font.close + , " x ", helmod_tag.color.gold, element_label, helmod_tag.color.close + , color_tag, " (", localised_name, ")", helmod_tag.color.close + }) + noQuality = false + end + end + if noQuality then + local element_sprite = GuiElement.getSprite(element_type, element_name, "[%s=%s]") + table.insert(tooltip, { "", "\n", "[img=helmod-tooltip-blank]", " " + , element_sprite + , helmod_tag.font.default_bold + , helmod_tag.color.white, " ", element_amount, helmod_tag.color.close + , helmod_tag.font.close + , " x ", helmod_tag.color.gold, element_label, helmod_tag.color.close + }) + end +end +------------------------------------------------------------------------------- +---Add tooltip line +---@param tooltip table +---@param icon string | nil +---@param label any +---@param value1 any +---@param value2? any +function GuiTooltip.appendLine(tooltip, icon, label, value1, value2) + if icon == nil then + icon = "[img=helmod-tooltip-blank]" + end + if value2 == nil then + table.insert(tooltip, { "", "\n", icon, " " + , helmod_tag.color.gold, label, ": ", helmod_tag.color.close + , helmod_tag.font.default_bold, value1 or 0, helmod_tag.font.close + }) + else + table.insert(tooltip, { "", "\n", icon, " " + , helmod_tag.color.gold, label, ": ", helmod_tag.color.close + , helmod_tag.font.default_bold, value1 or 0, "/", value2, helmod_tag.font.close + }) + end end ------------------------------------------------------------------------------- @@ -70,28 +205,28 @@ end ---@param tooltip table ---@param element table function GuiTooltip:appendControlInfo(tooltip, element) - if self.m_with_control_info ~= nil then - local tooltip_section = {""} - table.insert(tooltip_section, {"", "\n", "----------------------"}) - table.insert(tooltip_section, {"", "\n", helmod_tag.font.default_bold, {"tooltip.info-control"}, helmod_tag.font.close}) - if self.m_with_control_info == "contraint" then - table.insert(tooltip_section, {"", "\n", "[img=helmod-tooltip-blank]", " ", {"controls.contraint-plus"}}) - table.insert(tooltip_section, {"", "\n", "[img=helmod-tooltip-blank]", " ", {"controls.contraint-minus"}}) - end - if self.m_with_control_info == "link-intermediate" then - table.insert(tooltip_section, {"", "\n", "[img=helmod-tooltip-blank]", " ", {"controls.link-intermediate"}}) - end - if self.m_with_control_info == "module-add" then - table.insert(tooltip_section, {"", "\n", "[img=helmod-tooltip-blank]", " ", {"controls.module-add"}}) - end - if self.m_with_control_info == "module-remove" then - table.insert(tooltip_section, {"", "\n", "[img=helmod-tooltip-blank]", " ", {"controls.module-remove"}}) - end - if self.m_with_control_info == "crafting-add" then - table.insert(tooltip_section, {"", "\n", "[img=helmod-tooltip-blank]", " ", {"controls.crafting-add"}}) - end - table.insert(tooltip, tooltip_section) - end + if self.m_with_control_info ~= nil then + local tooltip_section = { "" } + table.insert(tooltip_section, { "", "\n", "----------------------" }) + table.insert(tooltip_section, { "", "\n", helmod_tag.font.default_bold, { "tooltip.info-control" }, helmod_tag.font.close }) + if self.m_with_control_info == "contraint" then + table.insert(tooltip_section, { "", "\n", "[img=helmod-tooltip-blank]", " ", { "controls.contraint-plus" } }) + table.insert(tooltip_section, { "", "\n", "[img=helmod-tooltip-blank]", " ", { "controls.contraint-minus" } }) + end + if self.m_with_control_info == "link-intermediate" then + table.insert(tooltip_section, { "", "\n", "[img=helmod-tooltip-blank]", " ", { "controls.link-intermediate" } }) + end + if self.m_with_control_info == "module-add" then + table.insert(tooltip_section, { "", "\n", "[img=helmod-tooltip-blank]", " ", { "controls.module-add" } }) + end + if self.m_with_control_info == "module-remove" then + table.insert(tooltip_section, { "", "\n", "[img=helmod-tooltip-blank]", " ", { "controls.module-remove" } }) + end + if self.m_with_control_info == "crafting-add" then + table.insert(tooltip_section, { "", "\n", "[img=helmod-tooltip-blank]", " ", { "controls.crafting-add" } }) + end + table.insert(tooltip, tooltip_section) + end end ------------------------------------------------------------------------------- @@ -99,16 +234,16 @@ end ---@param tooltip table ---@param element table function GuiTooltip:appendEnergyConsumption(tooltip, element) - if self.m_with_energy == true then - ---energy - local total_power = Format.formatNumberKilo(element.energy_total, "W") - if self.m_by_limit then - local limit_power = Format.formatNumberKilo(element.energy_limit, "W") - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.energy-consumption"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, limit_power or 0, "/", total_power, helmod_tag.font.close}) - else - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.energy-consumption"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, total_power or 0, helmod_tag.font.close}) - end - end + if self.m_with_energy == true then + ---energy + local total_power = Format.formatNumberKilo(element.energy_total, "W") + if self.m_by_limit then + local limit_power = Format.formatNumberKilo(element.energy_limit, "W") + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.energy-consumption" }, limit_power, total_power) + else + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.energy-consumption" }, total_power) + end + end end ------------------------------------------------------------------------------- @@ -116,24 +251,24 @@ end ---@param tooltip table ---@param element table function GuiTooltip:appendFlow(tooltip, element) - if self.m_with_logistic == true then - if element.type == "item" then - local item_prototype = ItemPrototype(element.name) - local stack_size = 0 - if item_prototype ~= nil then - stack_size = item_prototype:stackSize() - end - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.stack-size"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, stack_size or 0, helmod_tag.font.close}) - end - - local total_flow = Format.formatNumberElement(element.count/((element.time or 1)/60)) - if self.m_by_limit then - local limit_flow = Format.formatNumberElement(element.count_limit/((element.time or 1)/60)) - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.outflow-per-minute"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, limit_flow or 0, "/", total_flow, helmod_tag.font.close}) - else - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.outflow-per-minute"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, total_flow, helmod_tag.font.close}) - end - end + if self.m_with_logistic == true then + if element.type == "item" then + local item_prototype = ItemPrototype(element.name) + local stack_size = 0 + if item_prototype ~= nil then + stack_size = item_prototype:stackSize() + end + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.stack-size" }, stack_size) + end + + local total_flow = Format.formatNumberElement(element.count / ((element.time or 1) / 60)) + if self.m_by_limit then + local limit_flow = Format.formatNumberElement(element.count_limit / ((element.time or 1) / 60)) + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.outflow-per-minute" }, limit_flow, total_flow) + else + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.outflow-per-minute" }, total_flow) + end + end end ------------------------------------------------------------------------------- @@ -141,39 +276,43 @@ end ---@param tooltip table ---@param element table function GuiTooltip:appendEffectInfo(tooltip, element) - if self.m_with_effect_info == true then - ---energy - local sign = "" - if element.effects.consumption > 0 then sign = "+" end - local energy = Format.formatNumberKilo(element.energy, "W").." ("..sign..Format.formatPercent(element.effects.consumption).."%)" - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_label.energy"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, energy or 0, helmod_tag.font.close}) - - ---speed - local sign = "" - if element.effects.speed > 0 then sign = "+" end - local speed = Format.formatNumber(element.speed).." ("..sign..Format.formatPercent(element.effects.speed).."%)" - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_label.speed"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, speed or 0, helmod_tag.font.close}) - - ---productivity - local sign = "" - if element.effects.productivity > 0 then sign = "+" end - local productivity = sign..Format.formatPercent(element.effects.productivity).."%" - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_label.productivity"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, productivity or 0, helmod_tag.font.close}) - - ---quality - if Player.hasFeatureQuality() then - if element.effects.quality == nil then element.effects.quality = 0 end - local sign = "" - if element.effects.quality > 0 then sign = "+" end - local quality = sign..Format.formatPercent(element.effects.quality).."%" - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_label.quality"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, quality or 0, helmod_tag.font.close}) - end - - ---pollution - local pollution = Format.formatNumberElement((element.pollution or 0)*60 ) - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_label.pollution"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, pollution or 0, helmod_tag.font.close}) - - end + if self.m_with_effect_info == true then + ---energy + local sign = "" + if element.effects.consumption > 0 then sign = "+" end + local energy = Format.formatNumberKilo(element.energy, "W") .." (" .. sign .. Format.formatPercent(element.effects.consumption) .. "%)" + + GuiTooltip.appendLine(tooltip, nil, { "helmod_label.energy" }, energy) + + ---speed + local sign = "" + if element.effects.speed > 0 then sign = "+" end + local speed = Format.formatNumber(element.speed) .. " (" .. + sign .. Format.formatPercent(element.effects.speed) .. "%)" + + GuiTooltip.appendLine(tooltip, nil, { "helmod_label.speed" }, speed) + + ---productivity + local sign = "" + if element.effects.productivity > 0 then sign = "+" end + local productivity = sign .. Format.formatPercent(element.effects.productivity) .. "%" + + GuiTooltip.appendLine(tooltip, nil, { "helmod_label.productivity" }, productivity) + + ---quality + if Player.hasFeatureQuality() then + if element.effects.quality == nil then element.effects.quality = 0 end + local sign = "" + if element.effects.quality > 0 then sign = "+" end + local quality = sign .. Format.formatPercent(element.effects.quality) .. "%" + + GuiTooltip.appendLine(tooltip, nil, { "helmod_label.quality" }, quality) + end + + ---pollution + local pollution = Format.formatNumberElement((element.pollution or 0) * 60) + GuiTooltip.appendLine(tooltip, nil, { "helmod_label.pollution" }, pollution) + end end ------------------------------------------------------------------------------- @@ -181,15 +320,17 @@ end ---@param tooltip table ---@param element table function GuiTooltip.appendQuality(tooltip, element) - if Player.hasFeatureQuality() and element.quality ~= nil then - local quality = Player.getQualityPrototype(element.quality) - if quality ~= nil and quality.level > 0 then - local localised_name = quality.localised_name - local color = quality.color - local color_tag = GuiElement.rgbColorTag(color) - table.insert(tooltip, {"", "\n", string.format("[%s=%s]", "quality", element.quality), " ", helmod_tag.font.default_bold, color_tag, localised_name, helmod_tag.color.close, helmod_tag.font.close}) - end - end + if Player.hasFeatureQuality() and element.quality ~= nil then + local quality = Player.getQualityPrototype(element.quality) + if quality ~= nil and quality.level > 0 then + local localised_name = quality.localised_name + local color = quality.color + local color_tag = GuiElement.rgbColorTag(color) + table.insert(tooltip, + { "", "\n", string.format("[%s=%s]", "quality", element.quality), " ", helmod_tag.font.default_bold, + color_tag, localised_name, helmod_tag.color.close, helmod_tag.font.close }) + end + end end ------------------------------------------------------------------------------- @@ -197,50 +338,62 @@ end ---@param tooltip table ---@param element table function GuiTooltip:appendLogistic(tooltip, element) - if self.m_with_logistic == true then - local tooltip_section = {""} - table.insert(tooltip_section, {"", "\n", "----------------------"}) - table.insert(tooltip_section, {"", "\n", helmod_tag.font.default_bold, {"tooltip.info-logistic"}, helmod_tag.font.close}) - ---solid logistic - if element.type == 0 or element.type == "item" then - for _,type in pairs({"inserter", "belt", "container", "transport"}) do - local item_logistic = Player.getDefaultItemLogistic(type) - local item_prototype = Product(element) - local total_value = item_prototype:countContainer(element.count, item_logistic, element.time) - local formated_total_value = Format.formatNumberElement(total_value) - local info = "" - if type == "inserter" then - info = {"", " (", {"helmod_common.capacity"}, string.format(":%s", EntityPrototype(item_logistic):getInserterCapacity()), ")"} - end - if self.m_by_limit then - local limit_value = Format.formatNumberElement(item_prototype:countContainer(element.count_limit, item_logistic, element.time)) - table.insert(tooltip_section, {"", "\n", string.format("[%s=%s]", "entity", item_logistic), " ", helmod_tag.font.default_bold, " x ", limit_value, "/", formated_total_value, helmod_tag.font.close, info}) - else - table.insert(tooltip_section, {"", "\n", string.format("[%s=%s]", "entity", item_logistic), " ", helmod_tag.font.default_bold, " x ", formated_total_value, helmod_tag.font.close, info}) - end - end - end - ---fluid logistic - if element.type == 1 or element.type == "fluid" then - for _,type in pairs({"pipe", "container", "transport"}) do - local fluid_logistic = Player.getDefaultFluidLogistic(type) - local fluid_prototype = Product(element) - local count = element.count - if type == "pipe" then count = count / element.time end - local total_value = fluid_prototype:countContainer(count, fluid_logistic, element.time) - local formated_total_value = Format.formatNumberElement(total_value) - if self.m_by_limit then - local limit_count = element.count_limit - if type == "pipe" then limit_count = limit_count / element.time end - local limit_value = Format.formatNumberElement(fluid_prototype:countContainer(limit_count, fluid_logistic, element.time)) - table.insert(tooltip_section, {"", "\n", string.format("[%s=%s]", "entity", fluid_logistic), " ", helmod_tag.font.default_bold, " x ", limit_value, "/", formated_total_value, helmod_tag.font.close}) - else - table.insert(tooltip_section, {"", "\n", string.format("[%s=%s]", "entity", fluid_logistic), " ", helmod_tag.font.default_bold, " x ", formated_total_value, helmod_tag.font.close}) - end - end - end - table.insert(tooltip, tooltip_section) - end + if self.m_with_logistic == true then + local tooltip_section = { "" } + table.insert(tooltip_section, { "", "\n", "----------------------" }) + table.insert(tooltip_section, + { "", "\n", helmod_tag.font.default_bold, { "tooltip.info-logistic" }, helmod_tag.font.close }) + ---solid logistic + if element.type == 0 or element.type == "item" then + for _, type in pairs({ "inserter", "belt", "container", "transport" }) do + local item_logistic = Player.getDefaultItemLogistic(type) + local item_prototype = Product(element) + local total_value = item_prototype:countContainer(element.count, item_logistic, element.time) + local formated_total_value = Format.formatNumberElement(total_value) + local info = "" + if type == "inserter" then + info = { "", " (", { "helmod_common.capacity" }, string.format(":%s", + EntityPrototype(item_logistic):getInserterCapacity()), ")" } + end + if self.m_by_limit then + local limit_value = Format.formatNumberElement(item_prototype:countContainer(element.count_limit, + item_logistic, element.time)) + table.insert(tooltip_section, + { "", "\n", string.format("[%s=%s]", "entity", item_logistic), " ", helmod_tag.font.default_bold, + " x ", limit_value, "/", formated_total_value, helmod_tag.font.close, info }) + else + table.insert(tooltip_section, + { "", "\n", string.format("[%s=%s]", "entity", item_logistic), " ", helmod_tag.font.default_bold, + " x ", formated_total_value, helmod_tag.font.close, info }) + end + end + end + ---fluid logistic + if element.type == 1 or element.type == "fluid" then + for _, type in pairs({ "pipe", "container", "transport" }) do + local fluid_logistic = Player.getDefaultFluidLogistic(type) + local fluid_prototype = Product(element) + local count = element.count + if type == "pipe" then count = count / element.time end + local total_value = fluid_prototype:countContainer(count, fluid_logistic, element.time) + local formated_total_value = Format.formatNumberElement(total_value) + if self.m_by_limit then + local limit_count = element.count_limit + if type == "pipe" then limit_count = limit_count / element.time end + local limit_value = Format.formatNumberElement(fluid_prototype:countContainer(limit_count, + fluid_logistic, element.time)) + table.insert(tooltip_section, + { "", "\n", string.format("[%s=%s]", "entity", fluid_logistic), " ", helmod_tag.font + .default_bold, " x ", limit_value, "/", formated_total_value, helmod_tag.font.close }) + else + table.insert(tooltip_section, + { "", "\n", string.format("[%s=%s]", "entity", fluid_logistic), " ", helmod_tag.font + .default_bold, " x ", formated_total_value, helmod_tag.font.close }) + end + end + end + table.insert(tooltip, tooltip_section) + end end ------------------------------------------------------------------------------- @@ -248,34 +401,53 @@ end ---@param tooltip table ---@param element table function GuiTooltip:appendProductInfo(tooltip, element) - if self.m_with_product_info == true then - ---solid logistic - if element.type == 0 or element.type == "item" then - local item_prototype = ItemPrototype(element) - if item_prototype:getFuelValue() > 0 then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.fuel-value"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, Format.formatNumberKilo(item_prototype:getFuelValue() or 0, "J"), helmod_tag.font.close}) - end - end - ---fluid logistic - if element.type == 1 or element.type == "fluid" then - local fluid_prototype = FluidPrototype(element) - if fluid_prototype:getHeatCapacity() > 0 then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.heat-capacity"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, fluid_prototype:getHeatCapacity() or 0, "J", helmod_tag.font.close}) - end - if fluid_prototype:getFuelValue() > 0 then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.fuel-value"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, Format.formatNumberKilo(fluid_prototype:getFuelValue() or 0, "J"), helmod_tag.font.close}) - end - if element.temperature then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.temperature"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, element.temperature or 0, "°c", helmod_tag.font.close}) - end - if element.minimum_temperature and (element.minimum_temperature >= -1e300) then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.temperature-min"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, element.minimum_temperature or 0, "°c", helmod_tag.font.close}) - end - if element.maximum_temperature and (element.maximum_temperature <= 1e300) then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.temperature-max"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, element.maximum_temperature or 0, "°c", helmod_tag.font.close}) - end - end - end + if self.m_with_product_info == true then + ---solid logistic + if element.type == 0 or element.type == "item" then + local item_prototype = ItemPrototype(element) + if item_prototype:getFuelValue() > 0 then + local value = Format.formatNumberKilo(item_prototype:getFuelValue() or 0, "J") + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.fuel-value" }, value) + end + end + ---fluid logistic + if element.type == 1 or element.type == "fluid" then + local fluid_prototype = FluidPrototype(element) + if fluid_prototype:getHeatCapacity() > 0 then + local value = (fluid_prototype:getHeatCapacity() or 0) .. "J" + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.heat-capacity" }, value) + end + if fluid_prototype:getFuelValue() > 0 then + local value = Format.formatNumberKilo(fluid_prototype:getFuelValue() or 0, "J") + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.fuel-value" }, value) + end + if element.temperature then + local value = (element.temperature or 0) .. "°c" + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.temperature" }, value) + end + if element.minimum_temperature and (element.minimum_temperature >= -1e300) then + local value = (element.minimum_temperature or 0) .. "°c" + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.temperature-min" }, value) + end + if element.maximum_temperature and (element.maximum_temperature <= 1e300) then + local value = (element.maximum_temperature or 0) .. "°c" + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.temperature-max" }, value) + end + end + end +end + +------------------------------------------------------------------------------- +---Add tooltip line +---@param tooltip table +---@param label any +---@param value any +function GuiTooltip.appendLineDebug(tooltip, label, value) + local icon = "[img=developer]" + table.insert(tooltip, { "", "\n", icon, " " + , helmod_tag.color.white, label, ": ", helmod_tag.color.close + , helmod_tag.font.default_bold, value or "nil", helmod_tag.font.close + }) end ------------------------------------------------------------------------------- @@ -283,547 +455,586 @@ end ---@param tooltip table ---@param element table function GuiTooltip:appendDebug(tooltip, element) - ---debug - if User.getModGlobalSetting("debug_solver") == true then - table.insert(tooltip, {"", "\n", "----------------------"}) - table.insert(tooltip, {"", "\n", "[img=developer]", " ", "Id", ": ", helmod_tag.font.default_bold, element.id or "nil", helmod_tag.font.close}) - table.insert(tooltip, {"", "\n", "[img=developer]", " ", "Name", ": ", helmod_tag.font.default_bold, element.name or "nil", helmod_tag.font.close}) - table.insert(tooltip, {"", "\n", "[img=developer]", " ", "Type", ": ", helmod_tag.font.default_bold, element.type or "nil", helmod_tag.font.close}) - table.insert(tooltip, {"", "\n", "[img=developer]", " ", "State", ": ", helmod_tag.font.default_bold, element.state or 0, helmod_tag.font.close}) - table.insert(tooltip, {"", "\n", "[img=developer]", " ", "Amount", ": ", helmod_tag.font.default_bold, element.amount or 0, helmod_tag.font.close}) - table.insert(tooltip, {"", "\n", "[img=developer]", " ", "Count", ": ", helmod_tag.font.default_bold, element.count or 0, helmod_tag.font.close}) - table.insert(tooltip, {"", "\n", "[img=developer]", " ", "Count limit", ": ", helmod_tag.font.default_bold, element.count_limit or 0, helmod_tag.font.close}) - table.insert(tooltip, {"", "\n", "[img=developer]", " ", "Count deep", ": ", helmod_tag.font.default_bold, element.count_deep or 0, helmod_tag.font.close}) - end + ---debug + if User.getModGlobalSetting("debug_solver") == true then + table.insert(tooltip, { "", "\n", "----------------------" }) + GuiTooltip.appendLineDebug(tooltip, "Id", element.id) + GuiTooltip.appendLineDebug(tooltip, "Name", element.name) + GuiTooltip.appendLineDebug(tooltip, "Type", element.type) + GuiTooltip.appendLineDebug(tooltip, "State", element.state) + GuiTooltip.appendLineDebug(tooltip, "Amount", element.amount) + GuiTooltip.appendLineDebug(tooltip, "Count", element.count) + GuiTooltip.appendLineDebug(tooltip, "Count limit", element.count_limit) + GuiTooltip.appendLineDebug(tooltip, "Count deep", element.count_deep) + end end + ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltip:create() - local tooltip = {""} - if string.find(self.name[1], "edit[-]") then - local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.edit) - table.insert(tooltip, {"", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, self.name, helmod_tag.font.close, helmod_tag.color.close}) - elseif string.find(self.name[1], "add[-]") then - local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.add) - table.insert(tooltip, {"", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, self.name, helmod_tag.font.close, helmod_tag.color.close}) - elseif string.find(self.name[1], "remove[-]") then - local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.remove) - table.insert(tooltip, {"", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, self.name, helmod_tag.font.close, helmod_tag.color.close}) - elseif string.find(self.name[1], "info[-]") then - local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.info) - table.insert(tooltip, {"", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.white, helmod_tag.font.default_bold, self.name, helmod_tag.font.close, helmod_tag.color.close}) - elseif string.find(self.name[1], "set[-]default") then - local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.favorite) - table.insert(tooltip, {"", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, self.name, helmod_tag.font.close, helmod_tag.color.close}) - elseif string.find(self.name[1], "apply[-]block") then - local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.expand_right) - table.insert(self.name, {self.options.tooltip}) - table.insert(tooltip, {"", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, self.name, helmod_tag.font.close, helmod_tag.color.close}) - elseif string.find(self.name[1], "apply[-]line") then - local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.expand_right_group) - table.insert(self.name, {self.options.tooltip}) - table.insert(tooltip, {"", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, self.name, helmod_tag.font.close, helmod_tag.color.close}) - elseif string.find(self.name[1], "module[-]clear") then - local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.erase) - table.insert(tooltip, {"", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, self.name, helmod_tag.font.close, helmod_tag.color.close}) - elseif string.find(self.name[1], "pipette") then - local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.pipette) - table.insert(tooltip, {"", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, self.name, helmod_tag.font.close, helmod_tag.color.close}) - else - table.insert(tooltip, {"", "[img=helmod-tooltip-blank]", " ", helmod_tag.font.default_bold, self.name, helmod_tag.font.close}) - end - return tooltip + local tooltip = { "" } + if string.find(self.name[1], "edit[-]") then + local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.edit) + table.insert(tooltip, + { "", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, + self.name, helmod_tag.font.close, helmod_tag.color.close }) + elseif string.find(self.name[1], "add[-]") then + local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.add) + table.insert(tooltip, + { "", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, + self.name, helmod_tag.font.close, helmod_tag.color.close }) + elseif string.find(self.name[1], "remove[-]") then + local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.remove) + table.insert(tooltip, + { "", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, + self.name, helmod_tag.font.close, helmod_tag.color.close }) + elseif string.find(self.name[1], "info[-]") then + local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.info) + table.insert(tooltip, + { "", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.white, helmod_tag.font.default_bold, self + .name, helmod_tag.font.close, helmod_tag.color.close }) + elseif string.find(self.name[1], "set[-]default") then + local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.favorite) + table.insert(tooltip, + { "", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, + self.name, helmod_tag.font.close, helmod_tag.color.close }) + elseif string.find(self.name[1], "apply[-]block") then + local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.expand_right) + table.insert(self.name, { self.options.tooltip }) + table.insert(tooltip, + { "", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, + self.name, helmod_tag.font.close, helmod_tag.color.close }) + elseif string.find(self.name[1], "apply[-]line") then + local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.expand_right_group) + table.insert(self.name, { self.options.tooltip }) + table.insert(tooltip, + { "", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, + self.name, helmod_tag.font.close, helmod_tag.color.close }) + elseif string.find(self.name[1], "module[-]clear") then + local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.erase) + table.insert(tooltip, + { "", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, + self.name, helmod_tag.font.close, helmod_tag.color.close }) + elseif string.find(self.name[1], "pipette") then + local sprite_name = GuiElement.getSprite(defines.sprite_tooltip.pipette) + table.insert(tooltip, + { "", string.format("[img=%s]", sprite_name), " ", helmod_tag.color.yellow, helmod_tag.font.default_bold, + self.name, helmod_tag.font.close, helmod_tag.color.close }) + else + table.insert(tooltip, + { "", "[img=helmod-tooltip-blank]", " ", helmod_tag.font.default_bold, self.name, helmod_tag.font.close }) + end + return tooltip end ------------------------------------------------------------------------------- ---@class GuiTooltipModel : GuiTooltip -GuiTooltipModel = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipModel = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipModel:create() - local tooltip = self._super.create(self) - local element = self.m_element - local first_block = element.block_root or Model.firstChild(element.blocks or {}) - if first_block ~= nil then - local type = first_block.type - if type == nil then type = "entity" end - if type == "resource" or type == "energy" then type = "entity" end - if type == "rocket" then type = "item" end - if type == "recipe-burnt" then type = "recipe" end - local element_sprite = GuiElement.getSprite(type, first_block.name, "[%s=%s]") - table.insert(tooltip, {"", "\n", element_sprite, " ", helmod_tag.color.gold, helmod_tag.font.default_bold, Player.getLocalisedName({type=type, name=first_block.name}), helmod_tag.font.close, helmod_tag.color.close}) - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_result-panel.col-header-owner"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, element.owner or "", helmod_tag.font.close}) - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.group"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, element.group or "", helmod_tag.font.close}) - if element.note ~= nil and element.note ~= "" then - table.insert(tooltip, {"", "\n", "----------------------"}) - table.insert(tooltip, {"", "\n", helmod_tag.font.default_bold, {"helmod_common.note"}, helmod_tag.font.close}) - table.insert(tooltip, {"", "\n", element.note or ""}) - end - self:appendDebug(tooltip, element.block_root) - end - return tooltip + local tooltip = self._super.create(self) + local element = self.m_element + local first_block = element.block_root or Model.firstChild(element.blocks or {}) + if first_block ~= nil then + local type = first_block.type + if type == nil then type = "entity" end + if type == "resource" or type == "energy" then type = "entity" end + if type == "rocket" then type = "item" end + if type == "recipe-burnt" then type = "recipe" end + + local element_label = Player.getLocalisedName({ type = type, name = first_block.name }) + GuiTooltip.appendLineTitle(tooltip, type, first_block.name, element_label) + + GuiTooltip.appendLine(tooltip, nil, { "helmod_result-panel.col-header-owner" }, element.owner) + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.group" }, element.group or "") + + if element.note ~= nil and element.note ~= "" then + table.insert(tooltip, { "", "\n", "----------------------" }) + table.insert(tooltip, { "", "\n", helmod_tag.font.default_bold, { "helmod_common.note" }, helmod_tag.font + .close }) + table.insert(tooltip, { "", "\n", element.note or "" }) + end + self:appendDebug(tooltip, element.block_root) + end + return tooltip end ------------------------------------------------------------------------------- ---@class GuiTooltipRecipe : GuiTooltip -GuiTooltipRecipe = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipRecipe = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipRecipe:create() - local tooltip = self._super.create(self) - local element = self.m_element - if element ~= nil then - local recipe_prototype = RecipePrototype(element) - local icon_name, icon_type = recipe_prototype:getIcon() - local element_sprite = GuiElement.getSprite(icon_type, icon_name, "[%s=%s]") - table.insert(tooltip, {"", "\n", element_sprite, " ", helmod_tag.color.gold, helmod_tag.font.default_bold, Player.getLocalisedName({type=icon_type, name=icon_name}), helmod_tag.font.close, helmod_tag.color.close}) - ---quantity - local total_count = Format.formatNumberElement(element.count) - if self.m_by_limit then - local limit_count = Format.formatNumberElement(element.count_limit) - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.quantity"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, limit_count or 0, "/", total_count, helmod_tag.font.close}) - else - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.quantity"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, total_count or 0, helmod_tag.font.close}) - end - - self:appendProductInfo(tooltip, element); - self:appendEnergyConsumption(tooltip, element); - self:appendFlow(tooltip, element); - self:appendLogistic(tooltip, element); - self:appendControlInfo(tooltip, element); - self:appendDebug(tooltip, element) - - end - return tooltip + local tooltip = self._super.create(self) + local element = self.m_element + if element ~= nil then + local recipe_prototype = RecipePrototype(element) + local icon_name, icon_type = recipe_prototype:getIcon() + + local element_label = Player.getLocalisedName({ type = icon_type, name = icon_name }) + GuiTooltip.appendLineTitle(tooltip, icon_type, icon_name, element_label, self.m_element.quality) + + ---quantity + local total_count = Format.formatNumberElement(element.count) + if self.m_by_limit then + local limit_count = Format.formatNumberElement(element.count_limit) + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.quantity" }, limit_count, total_count) + else + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.quantity" }, total_count) + end + + self:appendProductInfo(tooltip, element); + self:appendEnergyConsumption(tooltip, element); + self:appendFlow(tooltip, element); + self:appendLogistic(tooltip, element); + self:appendControlInfo(tooltip, element); + self:appendDebug(tooltip, element) + end + return tooltip end ------------------------------------------------------------------------------- ---@class GuiTooltipElement : GuiTooltip -GuiTooltipElement = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipElement = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipElement:create() - local tooltip = self._super.create(self) - local element = self.m_element - if element ~= nil then - local type = element.type - if type == nil then type = "entity" end - if type == "resource" or type == "energy" then type = "entity" end - if type == "rocket" then type = "item" end - if type == "recipe-burnt" then type = "recipe" end - if type == "boiler" then type = "fluid" end - local element_icon = GuiElement.getSprite(type, element.name, "[%s=%s]") - table.insert(tooltip, {"", "\n", element_icon, " ", helmod_tag.color.gold, helmod_tag.font.default_bold, Player.getLocalisedName({type=type, name=element.name}), helmod_tag.font.close, helmod_tag.color.close}) - - GuiTooltip.appendQuality(tooltip, element) - - ---quantity - local total_count = Format.formatNumberElement(element.count) - if self.m_by_limit then - local count_limit = Format.formatNumberElement(element.count_limit) - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.quantity"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, count_limit or 0, "/", total_count, helmod_tag.font.close}) - else - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.quantity"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, total_count or 0, helmod_tag.font.close}) - end - - self:appendProductInfo(tooltip, element); - self:appendEnergyConsumption(tooltip, element); - self:appendEffectInfo(tooltip, element); - self:appendFlow(tooltip, element); - self:appendLogistic(tooltip, element); - self:appendControlInfo(tooltip, element); - self:appendDebug(tooltip, element) - - end - return tooltip + local tooltip = self._super.create(self) + local element = self.m_element + if element ~= nil then + local type = element.type + if type == nil then type = "entity" end + if type == "resource" or type == "energy" then type = "entity" end + if type == "rocket" then type = "item" end + if type == "recipe-burnt" then type = "recipe" end + if type == "boiler" then type = "fluid" end + + local element_label = Player.getLocalisedName({ type = type, name = element.name }) + GuiTooltip.appendLineTitle(tooltip, type, element.name, element_label, element.quality) + + ---quantity + local total_count = Format.formatNumberElement(element.count) + if self.m_by_limit then + local limit_count = Format.formatNumberElement(element.count_limit) + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.quantity" }, limit_count, total_count) + else + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.quantity" }, total_count) + end + + self:appendProductInfo(tooltip, element); + self:appendEnergyConsumption(tooltip, element); + self:appendEffectInfo(tooltip, element); + self:appendFlow(tooltip, element); + self:appendLogistic(tooltip, element); + self:appendControlInfo(tooltip, element); + self:appendDebug(tooltip, element) + end + return tooltip end ------------------------------------------------------------------------------- ---@class GuiTooltipEnergy : GuiTooltip -GuiTooltipEnergy = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipEnergy = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipEnergy:create() - local tooltip = self._super.create(self) - local element = self.m_element - if element ~= nil then - local type = element.type - if type == nil then type = "entity" end - if element == "resource" then type = "entity" end - local element_icon = GuiElement.getSprite(type, element.name, "[%s=%s]") - if defines.sprite_tooltips[element.name] ~= nil then - local sprite = GuiElement.getSprite(defines.sprite_tooltips[element.name]) - element_icon = string.format("[img=%s]", sprite) - end - table.insert(tooltip, {"", "\n", element_icon, " ", helmod_tag.color.gold, helmod_tag.font.default_bold, Player.getLocalisedName({type=type, name=element.name}), helmod_tag.font.close, helmod_tag.color.close}) - ---quantity - local total_count = Format.formatNumberKilo(element.count, "J") - if self.m_by_limit then - local limit_count = Format.formatNumberElement(element.count_limit) - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.quantity"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, limit_count or 0, "/", total_count, helmod_tag.font.close}) - else - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.quantity"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, total_count or 0, helmod_tag.font.close}) - end - - self:appendEnergyConsumption(tooltip, element); - self:appendDebug(tooltip, element) - end - return tooltip + local tooltip = self._super.create(self) + local element = self.m_element + if element ~= nil then + local type = element.type + if type == nil then type = "entity" end + if element == "resource" then type = "entity" end + local element_icon = GuiElement.getSprite(type, element.name, "[%s=%s]") + if defines.sprite_tooltips[element.name] ~= nil then + local sprite = GuiElement.getSprite(defines.sprite_tooltips[element.name]) + element_icon = string.format("[img=%s]", sprite) + end + + table.insert(tooltip, + { "", "\n", element_icon, " ", helmod_tag.color.gold, helmod_tag.font.default_bold, Player.getLocalisedName({ type = + type, name = element.name }), helmod_tag.font.close, helmod_tag.color.close }) + ---quantity + local total_count = Format.formatNumberKilo(element.count, "J") + if self.m_by_limit then + local limit_count = Format.formatNumberElement(element.count_limit) + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.quantity" }, limit_count, total_count) + else + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.quantity" }, total_count) + end + + self:appendEnergyConsumption(tooltip, element); + self:appendDebug(tooltip, element) + end + return tooltip end ------------------------------------------------------------------------------- ---@class GuiTooltipFactory : GuiTooltip -GuiTooltipFactory = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipFactory = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipFactory:create() - local tooltip = self._super.create(self) - if self.m_element then - GuiTooltipFactory.AppendFactory(tooltip, self.m_element) - end - return tooltip + local tooltip = self._super.create(self) + if self.m_element then + GuiTooltipFactory.AppendFactory(tooltip, self.m_element) + end + return tooltip end + +------------------------------------------------------------------------------- +---Append factory informations +---@param tooltip table +---@param element table function GuiTooltipFactory.AppendFactory(tooltip, element) - local type = "entity" - local prototype = EntityPrototype(element) - local element_sprite = GuiElement.getSprite(type, element.name, "[%s=%s]") - table.insert(tooltip, {"", "\n", element_sprite, " ", helmod_tag.color.gold, helmod_tag.font.default_bold, prototype:getLocalisedName(), helmod_tag.font.close, helmod_tag.color.close}) - -- [item=assembling-machine-3,quality=epic] - GuiTooltip.appendQuality(tooltip, element) - - if element.combo then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_label.beacon-on-factory"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, element.combo, helmod_tag.font.close}) - end - if element.per_factory then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_label.beacon-per-factory"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, element.per_factory, helmod_tag.font.close}) - end - if element.per_factory_constant then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_label.beacon-per-factory-constant"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, element.per_factory_constant, helmod_tag.font.close}) - end - local fuel = prototype:getFluel() - if fuel ~= nil then - if fuel.temperature then - table.insert(tooltip, {"", "\n", string.format("[%s=%s] %s °C", fuel.type, fuel.name, fuel.temperature), " ", helmod_tag.color.gold, helmod_tag.font.default_bold, Player.getLocalisedName(fuel), helmod_tag.font.close, helmod_tag.color.close}) - else - table.insert(tooltip, {"", "\n", string.format("[%s=%s]", fuel.type, fuel.name), " ", helmod_tag.color.gold, helmod_tag.font.default_bold, Player.getLocalisedName(fuel), helmod_tag.font.close, helmod_tag.color.close}) - end - end - if element.module_priority then - for _, module_priority in pairs(element.module_priority) do - local module_prototype = ItemPrototype(module_priority.name) - local amount = module_priority.amount or 0 - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", string.format("[%s=%s]", "item", module_priority.name), " ", helmod_tag.font.default_bold, amount, " x ", helmod_tag.font.close, " ", helmod_tag.color.gold, module_prototype:getLocalisedName(), helmod_tag.color.close}) - end - end + local prototype = EntityPrototype(element) + local type = "entity" + + GuiTooltip.appendLineTitle(tooltip, type, element.name, prototype:getLocalisedName(), element.quality) + + if element.combo then + GuiTooltip.appendLine(tooltip, nil, { "helmod_label.beacon-on-factory" }, element.combo) + end + if element.per_factory then + GuiTooltip.appendLine(tooltip, nil, { "helmod_label.beacon-per-factory" }, element.per_factory) + end + if element.per_factory_constant then + GuiTooltip.appendLine(tooltip, nil, { "helmod_label.beacon-per-factory-constant" }, element.per_faper_factory_constantctory) + end + local fuel = prototype:getFluel() + if fuel ~= nil then + if fuel.temperature then + table.insert(tooltip, + { "", "\n", string.format("[%s=%s] %s °C", fuel.type, fuel.name, fuel.temperature), " ", helmod_tag + .color.gold, helmod_tag.font.default_bold, Player.getLocalisedName(fuel), helmod_tag.font.close, + helmod_tag.color.close }) + else + table.insert(tooltip, + { "", "\n", string.format("[%s=%s]", fuel.type, fuel.name), " ", helmod_tag.color.gold, helmod_tag.font + .default_bold, Player.getLocalisedName(fuel), helmod_tag.font.close, helmod_tag.color.close }) + end + end + if element.module_priority then + for _, module_priority in pairs(element.module_priority) do + local type = "item" + local module_prototype = ItemPrototype(module_priority.name) + local module_priority_label = module_prototype:getLocalisedName() + local amount = module_priority.amount or 0 + + GuiTooltip.appendLineSubQuantity(tooltip, type, module_priority.name, amount, module_priority_label, module_priority.quality) + end + end end ------------------------------------------------------------------------------- ---@class GuiTooltipBeacons : GuiTooltip -GuiTooltipBeacons = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipBeacons = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipBeacons:create() - local tooltip = self._super.create(self) - if self.m_element then - for _, beacon in pairs(self.m_element) do - local beacon_tooltip = {""} - table.insert(tooltip, beacon_tooltip) - GuiTooltipFactory.AppendFactory(beacon_tooltip, beacon) - end - end - return tooltip + local tooltip = self._super.create(self) + if self.m_element then + for _, beacon in pairs(self.m_element) do + local beacon_tooltip = { "" } + table.insert(tooltip, beacon_tooltip) + GuiTooltipFactory.AppendFactory(beacon_tooltip, beacon) + end + end + return tooltip end - ------------------------------------------------------------------------------- ---@class GuiTooltipEnergyConsumption : GuiTooltip -GuiTooltipEnergyConsumption = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipEnergyConsumption = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipEnergyConsumption:create() - local tooltip = self._super.create(self) - if self.m_element then - if self.m_by_limit then - local power = Format.formatNumberKilo(self.m_element.energy_total or self.m_element.power_limit, "W") - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.energy-consumption"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, power, helmod_tag.font.close}) - else - local power = Format.formatNumberKilo(self.m_element.energy_total or self.m_element.power, "W") - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.energy-consumption"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, power, helmod_tag.font.close}) - end end - return tooltip + local tooltip = self._super.create(self) + if self.m_element then + local power = "0W" + if self.m_by_limit then + power = Format.formatNumberKilo(self.m_element.energy_total or self.m_element.power_limit, "W") + else + power = Format.formatNumberKilo(self.m_element.energy_total or self.m_element.power, "W") + end + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.energy-consumption" }, power) + end + return tooltip end ------------------------------------------------------------------------------- ---@class GuiTooltipPollution : GuiTooltip -GuiTooltipPollution = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipPollution = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipPollution:create() - local tooltip = self._super.create(self) - if self.m_element then - local pollution = self.m_element.pollution or 0 - local pollution_limit = self.m_element.pollution_limit or 0 - local total_pollution = Format.formatNumberElement(pollution) - local limit_pollution = Format.formatNumberElement(pollution_limit) - local total_flow = Format.formatNumberElement(pollution/((self.m_element.time or 1)/60)) - if self.m_by_limit then - local limit_flow = Format.formatNumberElement(pollution_limit/((self.m_element.time or 1)/60)) - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.pollution"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, limit_pollution, helmod_tag.font.close}) - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.outflow-per-minute"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, limit_flow or 0, "/", total_flow, helmod_tag.font.close}) - else - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.pollution"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, total_pollution, helmod_tag.font.close}) - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.outflow-per-minute"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, total_flow, helmod_tag.font.close}) - end - end - return tooltip + local tooltip = self._super.create(self) + if self.m_element then + local pollution = self.m_element.pollution or 0 + local pollution_limit = self.m_element.pollution_limit or 0 + local total_pollution = Format.formatNumberElement(pollution) + local limit_pollution = Format.formatNumberElement(pollution_limit) + local total_flow = Format.formatNumberElement(pollution / ((self.m_element.time or 1) / 60)) + if self.m_by_limit then + local limit_flow = Format.formatNumberElement(pollution_limit / ((self.m_element.time or 1) / 60)) + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.pollution" }, limit_pollution) + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.outflow-per-minute" }, limit_flow or 0, total_flow) + else + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.pollution" }, total_pollution) + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.outflow-per-minute" }, total_flow) + end + end + return tooltip end ------------------------------------------------------------------------------- ---@class GuiTooltipBuilding : GuiTooltip -GuiTooltipBuilding = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipBuilding = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipBuilding:create() - local tooltip = self._super.create(self) - if self.m_element then - local block = self.m_element - local overflow = false - if block.summary ~= nil then - ---factories - for _, element in pairs(block.summary.factories) do - if #tooltip < 19 then - local element_sprite = GuiElement.getSprite(element.type, element.name, "[%s=%s]") - - if self.m_by_limit then - table.insert(tooltip, {"", "\n", element_sprite, " ", helmod_tag.font.default_bold, "x ", math.ceil(element.count_limit), helmod_tag.font.close}) - else - table.insert(tooltip, {"", "\n", element_sprite, " ", helmod_tag.font.default_bold, "x ", math.ceil(element.count), helmod_tag.font.close}) - end - else - overflow = true - end - end - - ---beacons - for _, element in pairs(block.summary.beacons) do - if #tooltip < 19 then - local element_sprite = GuiElement.getSprite(element.type, element.name, "[%s=%s]") - if self.m_by_limit then - table.insert(tooltip, {"", "\n", element_sprite, " ", helmod_tag.font.default_bold, "x ", math.ceil(element.count_limit), helmod_tag.font.close}) - else - table.insert(tooltip, {"", "\n", element_sprite, " ", helmod_tag.font.default_bold, "x ", math.ceil(element.count), helmod_tag.font.close}) - end - else - overflow = true - end - end - - for _, element in pairs(block.summary.modules) do - if #tooltip < 19 then - local element_sprite = GuiElement.getSprite(element.type, element.name, "[%s=%s]") - if self.m_by_limit then - table.insert(tooltip, {"", "\n", element_sprite, " ", helmod_tag.font.default_bold, "x ", math.ceil(element.count_limit), helmod_tag.font.close}) - else - table.insert(tooltip, {"", "\n", element_sprite, " ", helmod_tag.font.default_bold, "x ", math.ceil(element.count), helmod_tag.font.close}) - end - else - overflow = true - end - end - if overflow then - table.insert(tooltip, {"", "\n", "..."}) - end - end - end - return tooltip + local tooltip = self._super.create(self) + if self.m_element then + local block = self.m_element + local overflow = false + if block.summary ~= nil then + ---factories + for _, element in pairs(block.summary.factories) do + if #tooltip < 19 then + local amount = math.ceil(element.count) + if self.m_by_limit then + amount = math.ceil(element.count_limit) + end + local element_label = Player.getLocalisedName({ type = element.type, name = element.name }) + GuiTooltip.appendLineQuantity(tooltip, element.type, element.name, amount, element_label, element.quality) + else + overflow = true + end + end + + ---beacons + for _, element in pairs(block.summary.beacons) do + if #tooltip < 19 then + local amount = math.ceil(element.count) + if self.m_by_limit then + amount = math.ceil(element.count_limit) + end + local element_label = Player.getLocalisedName({ type = element.type, name = element.name }) + GuiTooltip.appendLineQuantity(tooltip, element.type, element.name, amount, element_label, element.quality) + else + overflow = true + end + end + + for _, element in pairs(block.summary.modules) do + if #tooltip < 19 then + local amount = math.ceil(element.count) + if self.m_by_limit then + amount = math.ceil(element.count_limit) + end + local element_label = Player.getLocalisedName({ type = element.type, name = element.name }) + GuiTooltip.appendLineQuantity(tooltip, element.type, element.name, amount, element_label, element.quality) + else + overflow = true + end + end + if overflow then + table.insert(tooltip, { "", "\n", "..." }) + end + end + end + return tooltip end ------------------------------------------------------------------------------- ---@class GuiTooltipBlock : GuiTooltip -GuiTooltipBlock = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipBlock = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipBlock:create() - local tooltip = self._super.create(self) - if self.m_element then - local quantity = self.m_element.count or 0 - if self.m_by_limit then - local quantity = self.m_element.count_limit or 0 - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.quantity"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, quantity, helmod_tag.font.close}) - else - local quantity = self.m_element.count or 0 - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"helmod_common.quantity"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, quantity, helmod_tag.font.close}) - end - end - return tooltip + local tooltip = self._super.create(self) + if self.m_element then + local quantity = self.m_element.count or 0 + if self.m_by_limit then + local quantity = self.m_element.count_limit or 0 + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.quantity" }, quantity) + else + local quantity = self.m_element.count or 0 + GuiTooltip.appendLine(tooltip, nil, { "helmod_common.quantity" }, quantity) + end + end + return tooltip end ------------------------------------------------------------------------------- ---@class GuiTooltipModule : GuiTooltip -GuiTooltipModule = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipModule = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) +------------------------------------------------------------------------------- +---Add tooltip line +---@param tooltip table +---@param icon string | nil +---@param label any +---@param bonus number +function GuiTooltip.appendLineBonus(tooltip, icon, label, bonus) + if icon == nil then + icon = "[img=helmod-tooltip-blank]" + end + local bonus_positive = "+" + if bonus <= 0 then bonus_positive = "" end + if bonus ~= 0 then + table.insert(tooltip, { "", "\n", icon, " " + , helmod_tag.color.gold, label, ": ", helmod_tag.color.close + , helmod_tag.font.default_bold, bonus_positive, Format.formatPercent(bonus) or 0, "%", helmod_tag.font.close + }) + end +end + ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipModule:create() - local tooltip = self._super.create(self) - if self.m_element then - local module_prototype = ItemPrototype(self.m_element.name) - local module = module_prototype:native() - if module ~= nil then - local element_sprite = GuiElement.getSprite(self.m_element.type, self.m_element.name, "[%s=%s]") - table.insert(tooltip, {"", "\n", element_sprite, " ", helmod_tag.color.gold, helmod_tag.font.default_bold, module_prototype:getLocalisedName(), helmod_tag.font.close, helmod_tag.color.close}) - - GuiTooltip.appendQuality(tooltip, self.m_element) - - local module_effects = Player.getModuleEffects(self.m_element) - local bonus_consumption = module_effects.consumption - local bonus_speed = module_effects.speed - local bonus_productivity = module_effects.productivity - local bonus_pollution = module_effects.pollution - local bonus_quality = module_effects.quality - - local bonus_consumption_positive = "+" - if bonus_consumption <= 0 then bonus_consumption_positive = "" end - if bonus_consumption ~= 0 then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"description.consumption-bonus"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, bonus_consumption_positive, Format.formatPercent(bonus_consumption), "%", helmod_tag.font.close}) - end - local bonus_speed_positive = "+" - if bonus_speed <= 0 then bonus_speed_positive = "" end - if bonus_speed ~= 0 then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"description.speed-bonus"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, bonus_speed_positive, Format.formatPercent(bonus_speed), "%", helmod_tag.font.close}) - end - local bonus_productivity_positive = "+" - if bonus_productivity <= 0 then bonus_productivity_positive = "" end - if bonus_productivity ~= 0 then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"description.productivity-bonus"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, bonus_productivity_positive, Format.formatPercent(bonus_productivity), "%", helmod_tag.font.close}) - end - if Player.hasFeatureQuality() then - local bonus_quality_positive = "+" - if bonus_quality <= 0 then bonus_quality_positive = "" end - if bonus_quality ~= 0 then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"description.quality-bonus"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, bonus_quality_positive, Format.formatPercent(bonus_quality), "%", helmod_tag.font.close}) - end - end - local bonus_pollution_positive = "+" - if bonus_pollution <= 0 then bonus_pollution_positive = "" end - if bonus_pollution ~= 0 then - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", helmod_tag.color.gold, {"description.pollution-bonus"}, ": ", helmod_tag.color.close, helmod_tag.font.default_bold, bonus_pollution_positive, Format.formatPercent(bonus_pollution), "%", helmod_tag.font.close}) - end - self:appendControlInfo(tooltip, self.m_element.name); - end - end - return tooltip + local tooltip = self._super.create(self) + if self.m_element then + local module_prototype = ItemPrototype(self.m_element.name) + local module = module_prototype:native() + if module ~= nil then + GuiTooltip.appendLineTitle(tooltip, "item", self.m_element.name, module_prototype:getLocalisedName(), self.m_element.quality) + + local module_effects = Player.getModuleEffects(self.m_element) + local bonus_consumption = module_effects.consumption + local bonus_speed = module_effects.speed + local bonus_productivity = module_effects.productivity + local bonus_pollution = module_effects.pollution + local bonus_quality = module_effects.quality + + GuiTooltip.appendLineBonus(tooltip, nil, { "description.consumption-bonus" }, bonus_consumption) + GuiTooltip.appendLineBonus(tooltip, nil, { "description.speed-bonus" }, bonus_speed) + GuiTooltip.appendLineBonus(tooltip, nil, { "description.productivity-bonus" }, bonus_productivity) + GuiTooltip.appendLineBonus(tooltip, nil, { "description.quality-bonus" }, bonus_quality) + GuiTooltip.appendLineBonus(tooltip, nil, { "description.pollution-bonus" }, bonus_pollution) + + self:appendControlInfo(tooltip, self.m_element.name); + end + end + return tooltip end ------------------------------------------------------------------------------- ---@class GuiTooltipPriority : GuiTooltip -GuiTooltipPriority = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipPriority = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipPriority:create() - local tooltip = self._super.create(self) - if self.m_element then - for i,priority in pairs(self.m_element) do - local module_prototype = ItemPrototype(priority.name) - local element_sprite = GuiElement.getSprite("item", priority.name, "[%s=%s]") - local amount = priority.amount or 0 - table.insert(tooltip, {"", "\n", element_sprite, " ", helmod_tag.font.default_bold, amount, " x ", helmod_tag.font.close, helmod_tag.color.gold, module_prototype:getLocalisedName(), helmod_tag.color.close}) - end - end - return tooltip + local tooltip = self._super.create(self) + if self.m_element then + for i, priority in pairs(self.m_element) do + local type = "item" + local module_prototype = ItemPrototype(priority.name) + local module_priority_label = module_prototype:getLocalisedName() + local amount = priority.amount or 0 + + GuiTooltip.appendLineQuantity(tooltip, type, priority.name, amount, module_priority_label, priority.quality) + end + end + return tooltip end ------------------------------------------------------------------------------- ---@class GuiTooltipPriorities : GuiTooltip -GuiTooltipPriorities = newclass(GuiTooltip,function(base,...) - GuiTooltip.init(base,...) - base.classname = "HMGuiTooltip" +GuiTooltipPriorities = newclass(GuiTooltip, function(base, ...) + GuiTooltip.init(base, ...) + base.classname = "HMGuiTooltip" end) ------------------------------------------------------------------------------- ---Create tooltip ---@return table function GuiTooltipPriorities:create() - local tooltip = self._super.create(self) - if self.m_element then - for i,factory in pairs(self.m_element) do - GuiTooltipPriorities.AppendPriority(tooltip, factory) - end - end - return tooltip -end - -function GuiTooltipPriorities.AppendPriority(tooltip, element) - local type = "entity" - local prototype = EntityPrototype(element) - local element_sprite = GuiElement.getSprite(type, element.name, "[%s=%s]") - table.insert(tooltip, {"", "\n", element_sprite, " ", helmod_tag.color.gold, helmod_tag.font.default_bold, prototype:getLocalisedName(), helmod_tag.font.close, helmod_tag.color.close}) - if element.module_priority then - for _, module_priority in pairs(element.module_priority) do - local module_prototype = ItemPrototype(module_priority.name) - local amount = module_priority.amount or 0 - table.insert(tooltip, {"", "\n", "[img=helmod-tooltip-blank]", " ", string.format("[%s=%s]", "item", module_priority.name), " ", helmod_tag.font.default_bold, amount, " x ", helmod_tag.font.close, " ", helmod_tag.color.gold, module_prototype:getLocalisedName(), helmod_tag.color.close}) - end - end + local tooltip = self._super.create(self) + if self.m_element then + for i, factory in pairs(self.m_element) do + GuiTooltipPriorities.appendPriority(tooltip, factory) + end + end + return tooltip +end + +function GuiTooltipPriorities.appendPriority(tooltip, element) + local type = "entity" + local prototype = EntityPrototype(element) + + local element_label = prototype:getLocalisedName() + GuiTooltip.appendLineTitle(tooltip, type, element.name, element_label, element.quality) + + if element.module_priority then + for _, module_priority in pairs(element.module_priority) do + local type = "item" + local module_prototype = ItemPrototype(module_priority.name) + local module_priority_label = module_prototype:getLocalisedName() + local amount = module_priority.amount or 0 + + GuiTooltip.appendLineSubQuantity(tooltip, type, module_priority.name, amount, module_priority_label, module_priority.quality) + end + end end diff --git a/info.json b/info.json index 120f28b..16904f6 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "helmod", - "version": "2.0.6", + "version": "2.0.7", "title": "Helmod: Assistant for planning your factory", "author": "Helfima", "contact": "Helfima", diff --git a/migrations/helmod_1.0.0.lua b/migrations/helmod_1.0.0.lua deleted file mode 100644 index 95a072a..0000000 --- a/migrations/helmod_1.0.0.lua +++ /dev/null @@ -1,31 +0,0 @@ -if storage.models then - for _, model in pairs(storage.models) do - if model.blocks ~= nil and table.size(model.blocks) > 0 and model.block_root == nil then - local first = Model.firstChild(model.blocks) - model.block_root = Model.newBlock(model, { name = model.id, energy_total = 0, pollution = 0, summary = {} }) - model.block_root.parent_id = model.id - model.block_root.name = first.name - model.block_root.type = first.type - for _, block in pairs(model.blocks) do - model.block_root.children[block.id] = block - block.class = "Block" - if block.recipes ~= nil then - block.children = {} - for _, recipe in spairs(block.recipes, defines.sorters.block.sort) do - if recipe.beacon ~= nil and recipe.beacons == nil then - recipe.beacons = {} - table.insert(recipe.beacons, recipe.beacon) - end - block.children[recipe.id] = recipe - end - end - block.recipes = nil - end - ModelBuilder.rebuildParentBlockOfModel(model) - -- Force recalculation of recipe.factory.speed_total and recipe.factory.speed - -- Model and Block totals will be updated - Player.try_load_by_name(model.owner) - ModelCompute.try_update(model) - end - end -end diff --git a/migrations/helmod_2.0.7.lua b/migrations/helmod_2.0.7.lua new file mode 100644 index 0000000..208fb46 --- /dev/null +++ b/migrations/helmod_2.0.7.lua @@ -0,0 +1,88 @@ +function migration_priority(priority_module) + if priority_module == nil then return end + for _, module in pairs(priority_module) do + module.amount = module.value + module.value = nil + end +end + +function migration_modules(modules) + if modules == nil then return modules end + local new_modules= {} + local updated = false + for module_name, module_value in pairs(modules) do + if type(module_value) == "number" then + local new_module = {name=module_name, amount=module_value} + table.insert(new_modules, new_module) + updated = true + end + end + if updated then + return new_modules; + end + return modules; +end + +function migration_factory(factory) + if factory == nil then return end + if factory.modules then + local new_modules = migration_modules(factory.modules) + factory.modules = new_modules + end + if factory.priority_module then + migration_priority(factory.priority_module) + end +end + +function migration_recipe(recipe) + if recipe == nil then return end + if recipe.factory then + migration_factory(recipe.factory) + end + if recipe.beacons then + for _, beacon in pairs(recipe.beacons) do + migration_factory(beacon) + end + end +end + +function migration_block(block) + if block == nil then return end + if block.children then + for _, child in pairs(block.children) do + if child.class == "Recipe" then + migration_recipe(child) + end + end + end +end + +if storage.users then + for _, user in pairs(storage.users) do + if user.parameter then + if user.parameter.priority_modules then + for _, priority_modules in pairs(user.parameter.priority_modules) do + migration_priority(priority_modules) + end + end + if user.parameter.default_factory then + for _, default_factory in pairs(user.parameter.default_factory) do + migration_priority(default_factory.priority_module) + end + end + end + end +end + +if storage.models then + for _, model in pairs(storage.models) do + if model.block_root then + migration_block(model.block_root) + end + if model.blocks then + for _, block in pairs(model.blocks) do + migration_block(block) + end + end + end +end \ No newline at end of file