Skip to content

Commit

Permalink
Changed code for better speed on recipe selector
Browse files Browse the repository at this point in the history
Changed code for better speed on recipe selector
Fixed some minor bug
  • Loading branch information
Helfima committed Sep 2, 2017
1 parent a259254 commit e2906e8
Show file tree
Hide file tree
Showing 14 changed files with 595 additions and 376 deletions.
63 changes: 58 additions & 5 deletions core/elementGui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -855,10 +855,10 @@ end
-- @param #lua_product element
-- @param #string container name
--
-- @return #number
-- @return #table
--
function ElementGui.getTooltipProduct(element, container)
Logging:debug(ElementGui.classname, "getTooltip", element, container)
Logging:debug(ElementGui.classname, "getTooltipProduct", element, container)
local tooltip = {"tooltip.cargo-info", EntityPrototype.load(container).getLocalisedName()}
local total_tooltip = {"tooltip.cargo-info-element", {"helmod_common.total"}, Format.formatNumberElement(Product.countContainer(element.count, container))}
if element.limit_count ~= nil then
Expand All @@ -879,10 +879,10 @@ end
--
-- @param #string module_name
--
-- @return #number
-- @return #table
--
function ElementGui.getTooltipModule(module_name)
Logging:debug(ElementGui.classname, "getTooltip", module_name)
Logging:debug(ElementGui.classname, "getTooltipModule", module_name)
local tooltip = nil
if module_name == nil then return nil end
local module = ItemPrototype.load(module_name).native()
Expand All @@ -891,9 +891,62 @@ function ElementGui.getTooltipModule(module_name)
local speed = Format.formatPercent(Player.getModuleBonus(module.name, "speed"))
local productivity = Format.formatPercent(Player.getModuleBonus(module.name, "productivity"))
local pollution = Format.formatPercent(Player.getModuleBonus(module.name, "pollution"))
tooltip = ({"tooltip.module-description" , ItemPrototype.getLocalisedName(), consumption, speed, productivity, pollution})
tooltip = {"tooltip.module-description" , ItemPrototype.getLocalisedName(), consumption, speed, productivity, pollution}
end
return tooltip
end

-------------------------------------------------------------------------------
-- Get tooltip for recipe
--
-- @function [parent=#ElementGui] getTooltipRecipe
--
-- @param #table prototype
--
-- @return #table
--

local cache_tooltip_recipe = {}

function ElementGui.getTooltipRecipe(prototype)
Logging:debug(ElementGui.classname, "getTooltipRecipe", prototype)
RecipePrototype.load(prototype)
if RecipePrototype.native() == nil then return nil end
if cache_tooltip_recipe[prototype.name] ~= nil then return cache_tooltip_recipe[prototype.name] end
-- initalize tooltip
local tooltip = {"tooltip.recipe-info"}
-- insert __1__ value
table.insert(tooltip, RecipePrototype.getLocalisedName())

-- insert __2__ value
local lastTooltip = tooltip
for _,element in pairs(RecipePrototype.getProducts()) do
local product = Product.load(element)
local count = Product.getElementAmount(element)
local name = Product.getLocalisedName()
local currentTooltip = {"tooltip.recipe-info-element", count, name}
-- insert le dernier tooltip dans le precedent
table.insert(lastTooltip, currentTooltip)
lastTooltip = currentTooltip
end
-- finalise la derniere valeur
table.insert(lastTooltip, "")

-- insert __3__ value
local lastTooltip = tooltip
for _,element in pairs(RecipePrototype.getIngredients()) do
local product = Product.load(element)
local count = Product.getElementAmount(element)
local name = Product.getLocalisedName()
local currentTooltip = {"tooltip.recipe-info-element", count, name}
-- insert le dernier tooltip dans le precedent
table.insert(lastTooltip, currentTooltip)
lastTooltip = currentTooltip
end
-- finalise la derniere valeur
table.insert(lastTooltip, "")
cache_tooltip_recipe[prototype.name] = tooltip
return tooltip
end

return ElementGui
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
"name": "helmod",
"version": "0.6.2",
"version": "0.6.3",
"title": "Helmod: Assistant to plan its base.",
"author": "Helfima",
"contact": "Helfima",
Expand Down
12 changes: 12 additions & 0 deletions model/EntityPrototype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ function EntityPrototype.getType()
return lua_entity_prototype.type
end

-------------------------------------------------------------------------------
-- Return valid
--
-- @function [parent=#EntityPrototype] getValid
--
-- @return #boolean
--
function EntityPrototype.getValid()
if lua_entity_prototype == nil then return false end
return lua_entity_prototype.valid
end

-------------------------------------------------------------------------------
-- Return energy usage per second
--
Expand Down
12 changes: 12 additions & 0 deletions model/FluidPrototype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ function FluidPrototype.native()
return lua_fluid_prototype
end

-------------------------------------------------------------------------------
-- Return valid
--
-- @function [parent=#FluidPrototype] getValid
--
-- @return #boolean
--
function FluidPrototype.getValid()
if lua_fluid_prototype == nil then return false end
return lua_fluid_prototype.valid
end

-------------------------------------------------------------------------------
-- Return localised name
--
Expand Down
12 changes: 12 additions & 0 deletions model/ItemPrototype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ function ItemPrototype.native()
return lua_item_prototype
end

-------------------------------------------------------------------------------
-- Return valid
--
-- @function [parent=#ItemPrototype] getValid
--
-- @return #boolean
--
function ItemPrototype.getValid()
if lua_item_prototype == nil then return false end
return lua_item_prototype.valid
end

-------------------------------------------------------------------------------
-- Return localised name
--
Expand Down
4 changes: 4 additions & 0 deletions model/Player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -789,14 +789,18 @@ end
--
-- @return #table entity prototype
--
local cache_resources = nil

function Player.getResources()
if cache_resources ~= nil then return cache_resources end
local items = {}
for _,item in pairs(game.entity_prototypes) do
--Logging:debug(Player.classname, "getItemsPrototype(type):", item.name, item.group.name, item.subgroup.name)
if item.name ~= nil and item.resource_category ~= nil then
table.insert(items,item)
end
end
cache_resources = items
return items
end

Expand Down
65 changes: 65 additions & 0 deletions model/Technology.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,69 @@ function Technology.native()
return lua_technology
end

-------------------------------------------------------------------------------
-- Return localised name
--
-- @function [parent=#Technology] getLocalisedName
--
-- @return #number default 0
--
function Technology.getLocalisedName()
if lua_technology ~= nil then
if Player.getSettings("display_real_name", true) then
return lua_technology.name
end
return lua_technology.localised_name
end
return "unknow"
end

-------------------------------------------------------------------------------
-- Return valid
--
-- @function [parent=#Technology] getValid
--
-- @return #boolean
--
function Technology.getValid()
if lua_technology == nil then return false end
return lua_technology.valid
end

-------------------------------------------------------------------------------
-- Return level
--
-- @function [parent=#Technology] getLevel
--
-- @return #number
--
function Technology.getLevel()
if lua_technology == nil then return 0 end
return lua_technology.level
end

-------------------------------------------------------------------------------
-- Return formula
--
-- @function [parent=#Technology] getFormula
--
-- @return #string
--
function Technology.getFormula()
if lua_technology == nil then return nil end
return lua_technology.research_unit_count_formula
end

-------------------------------------------------------------------------------
-- Return ingredients
--
-- @function [parent=#Technology] getIngredients
--
-- @return #table
--
function Technology.getIngredients()
if lua_technology == nil then return {} end
return lua_technology.research_unit_ingredients or {}
end

return Technology
Loading

0 comments on commit e2906e8

Please sign in to comment.