Skip to content

Commit

Permalink
Added the calculation of the number of block
Browse files Browse the repository at this point in the history
Added the calculation of the number of block
Added number of block display
  • Loading branch information
Helfima committed Aug 23, 2016
1 parent d43fed5 commit b097a9d
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 51 deletions.
2 changes: 1 addition & 1 deletion helmod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Logging.console = false
--===========================
function helmod:on_init(event)
self.name = "helmod"
self.version = "0.2.2"
self.version = "0.2.3"
self.loaded = false;

self.playerController = PlayerController:new()
Expand Down
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.2.2",
"version": "0.2.3",
"title": "Helmod: Assistant to plan its base.",
"author": "Helfima",
"contact": "Helfima",
Expand Down
3 changes: 3 additions & 0 deletions locale/en/locale.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ refresh=Refresh
close=Close

[helmod_label]
electrical-consumption=Electrical consumption:
block-number=Block number:
limit=Max per block
energy-nominal=Nominal Energy
speed-nominal=Nominal Speed
module-slots=Module Slots
Expand Down
27 changes: 26 additions & 1 deletion planner/plannerModel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function PlannerModel.methods:createProductionBlockModel(player, recipe)
local inputModel = {}
inputModel.id = "block_"..model.block_id
inputModel.name = recipe.name
inputModel.count = 0
inputModel.count = 1
inputModel.active = true
inputModel.power = 0
inputModel.ingredients = {}
Expand Down Expand Up @@ -136,6 +136,9 @@ function PlannerModel.methods:createFactoryModel(player, name, count)
factoryModel.speed_nominal = 0.5
factoryModel.speed = 0
factoryModel.module_slots = 2
-- limit infini = 0
factoryModel.limit = 0
factoryModel.limit_count = count
-- modules
factoryModel.modules = {}

Expand Down Expand Up @@ -611,6 +614,9 @@ function PlannerModel.methods:updateFactory(player, blockId, key, options)
if options.module_slots ~= nil then
recipe.factory.module_slots = options.module_slots
end
if options.limit ~= nil then
recipe.factory.limit = options.limit
end
model.needPrepare = true
end
end
Expand Down Expand Up @@ -1073,6 +1079,9 @@ function PlannerModel.methods:computeProductionBlock(player, element, maxLoop, l
end
end

-- ratio pour le calcul du nombre de block
local ratio = 1
local ratioRecipe = nil
-- calcul ordonnee sur les recipes du block
local ingredients = nil
for _, recipe in spairs(recipes,function(t,a,b) return t[b].index > t[a].index end) do
Expand Down Expand Up @@ -1111,6 +1120,22 @@ function PlannerModel.methods:computeProductionBlock(player, element, maxLoop, l
self:computeFactory(player, recipe)

element.power = element.power + recipe.energy_total

if type(recipe.factory.limit) == "number" and recipe.factory.limit > 0 then
local currentRatio = recipe.factory.limit/recipe.factory.count
if currentRatio < ratio then
ratio = currentRatio
ratioRecipe = recipe.index
-- block number
element.count = math.ceil(recipe.factory.count/recipe.factory.limit)
end
end
end

-- calcul ratio
for _, recipe in spairs(recipes,function(t,a,b) return t[b].index > t[a].index end) do
recipe.factory.limit_count = math.ceil(recipe.factory.count*ratio)
if ratioRecipe ~= nil and ratioRecipe == recipe.index then recipe.factory.limit_count = recipe.factory.limit end
end
end
end
Expand Down
43 changes: 27 additions & 16 deletions planner/plannerRecipeEdition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ function PlannerRecipeEdition.methods:updateRecipeInfo(player, element, action,
end

local tablePanel = self:addGuiTable(infoPanel,"table-info",2)
self:addIconButton(tablePanel, "recipe", "recipe", recipe.name)
self:addSpriteIconButton(tablePanel, "recipe", "recipe", recipe.name)
self:addGuiLabel(tablePanel, "label", recipe.name)

-- self:addGuiLabel(tablePanel, "label-active", "Active")
Expand Down Expand Up @@ -469,7 +469,7 @@ function PlannerRecipeEdition.methods:updateRecipeIngredients(player, element, a
end
local tablePanel= self:addGuiTable(ingredientsPanel, "table-ingredients", 6)
for key, ingredient in pairs(recipe.ingredients) do
self:addIconButton(tablePanel, "item=ID=", self.player:getItemIconType(ingredient), ingredient.name)
self:addSpriteIconButton(tablePanel, "item=ID=", self.player:getIconType(ingredient), ingredient.name)
self:addGuiLabel(tablePanel, ingredient.name, ingredient.amount)
end
end
Expand Down Expand Up @@ -499,7 +499,7 @@ function PlannerRecipeEdition.methods:updateRecipeProducts(player, element, acti
end
local tablePanel= self:addGuiTable(productsPanel, "table-products", 6)
for key, product in pairs(recipe.products) do
self:addIconButton(tablePanel, "item=ID=", self.player:getItemIconType(product), product.name)
self:addSpriteIconButton(tablePanel, "item=ID=", self.player:getIconType(product), product.name)
self:addGuiLabel(tablePanel, product.name, product.amount)
end
end
Expand Down Expand Up @@ -530,7 +530,7 @@ function PlannerRecipeEdition.methods:updateFactoryInfo(player, element, action,
end

local headerPanel = self:addGuiTable(infoPanel,"table-header",2)
self:addIconButton(headerPanel, "icon", factory.type, factory.name)
self:addSpriteIconButton(headerPanel, "icon", self.player:getIconType(factory), factory.name)
self:addGuiLabel(headerPanel, "label", factory.name)

local inputPanel = self:addGuiTable(infoPanel,"table-input",2)
Expand All @@ -544,6 +544,9 @@ function PlannerRecipeEdition.methods:updateFactoryInfo(player, element, action,
self:addGuiLabel(inputPanel, "label-module-slots", ({"helmod_label.module-slots"}))
self:addGuiText(inputPanel, "module-slots", factory.module_slots, "helmod_textfield")

self:addGuiLabel(inputPanel, "label-limit", ({"helmod_label.limit"}))
self:addGuiText(inputPanel, "limit", factory.limit, "helmod_textfield")

self:addGuiLabel(inputPanel, "label-energy", ({"helmod_label.energy"}))
self:addGuiLabel(inputPanel, "energy", factory.energy)

Expand All @@ -569,13 +572,15 @@ end
--
function PlannerRecipeEdition.methods:updateFactoryModulesSelector(player, element, action, item, item2, item3)
local selectorPanel = self:getFactoryModulesSelectorPanel(player)
local model = self.model:getModel(player)
if selectorPanel["modules"] == nil then
local model = self.model:getModel(player)

local recipe = model.blocks[item].recipes[item2]
local recipe = model.blocks[item].recipes[item2]

local tableModulesPanel = self:addGuiTable(selectorPanel,"modules",4)
for k, module in pairs(self.player:getModules()) do
self:addSpriteIconButton(tableModulesPanel, self:classname().."=factory-module-add=ID="..item.."="..recipe.name.."=", "item", module.name)
local tableModulesPanel = self:addGuiTable(selectorPanel,"modules",4)
for k, module in pairs(self.player:getModules()) do
self:addSpriteIconButton(tableModulesPanel, self:classname().."=factory-module-add=ID="..item.."="..recipe.name.."=", "item", module.name)
end
end
end

Expand Down Expand Up @@ -689,7 +694,7 @@ function PlannerRecipeEdition.methods:updateBeaconInfo(player, element, action,
end

local headerPanel = self:addGuiTable(infoPanel,"table-header",2)
self:addIconButton(headerPanel, "icon", beacon.type, beacon.name)
self:addSpriteIconButton(headerPanel, "icon", self.player:getIconType(beacon), beacon.name)
self:addGuiLabel(headerPanel, "label", beacon.name)

local inputPanel = self:addGuiTable(infoPanel,"table-input",2)
Expand Down Expand Up @@ -759,13 +764,15 @@ end
--
function PlannerRecipeEdition.methods:updateBeaconModulesSelector(player, element, action, item, item2, item3)
local selectorPanel = self:getBeaconModulesSelectorPanel(player)
local model = self.model:getModel(player)
if selectorPanel["modules"] == nil then
local model = self.model:getModel(player)

local recipe = model.blocks[item].recipes[item2]

local tableModulesPanel = self:addGuiTable(selectorPanel,"modules",4)
for k, module in pairs(self.player:getModules()) do
self:addSpriteIconButton(tableModulesPanel, self:classname().."=beacon-module-add=ID="..item.."="..recipe.name.."=", "item", module.name)
local recipe = model.blocks[item].recipes[item2]

local tableModulesPanel = self:addGuiTable(selectorPanel,"modules",4)
for k, module in pairs(self.player:getModules()) do
self:addSpriteIconButton(tableModulesPanel, self:classname().."=beacon-module-add=ID="..item.."="..recipe.name.."=", "item", module.name)
end
end
end

Expand Down Expand Up @@ -865,6 +872,10 @@ function PlannerRecipeEdition.methods:on_event(player, element, action, item, it
options["module_slots"] = self:getInputNumber(inputPanel["module-slots"])
end

if inputPanel["limit"] ~= nil then
options["limit"] = self:getInputNumber(inputPanel["limit"])
end

self.model:updateFactory(player, item, item2, options)
self.model:update(player)
self:updateFactoryInfo(player, element, action, item, item2, item3)
Expand Down
49 changes: 30 additions & 19 deletions planner/plannerResult.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ function PlannerResult.methods:init(parent)
self.SUMMARY_TAB = "summary"
self.RESOURCES_TAB = "resources"

self.sectionItemStyle = "helmod_block-item-section-frame"
self.scrollItemStyle = "helmod_block-item-scroll"
self.sectionItemStyle1 = "helmod_block-item-section-frame1"
self.scrollItemStyle1 = "helmod_block-item-scroll1"

self.sectionItemStyle2 = "helmod_block-item-section-frame2"
self.scrollItemStyle2 = "helmod_block-item-scroll2"

self.scrollDataStyle = "helmod_block-list-scroll"
end

Expand Down Expand Up @@ -434,10 +438,27 @@ function PlannerResult.methods:updateProductionBlock(player, item, item2, item3)
if countRecipes > 0 then

local element = model.blocks[blockId]

local firstRow = self:addGuiFlowH(resultPanel, "first-row")
-- info panel
local blockPanel = self:addGuiFrameV(firstRow, "block", self.sectionItemStyle1, ({"helmod_common.block"}))
local blockScroll = self:addGuiScrollPane(blockPanel, "block-scroll", self.scrollItemStyle1, "auto", "auto")
local blockTable = self:addGuiTable(blockScroll,"output-table",4)

self:addGuiLabel(blockTable, "label-power", ({"helmod_label.electrical-consumption"}))
if model.summary ~= nil then
self:addGuiLabel(blockTable, "power", self:formatNumberKilo(element.power, "W"),"helmod_label-right-70")
end

self:addGuiLabel(blockTable, "label-count", ({"helmod_label.block-number"}))
if model.summary ~= nil then
self:addGuiLabel(blockTable, "count", element.count,"helmod_label-right-70")
end

-- ouput panel
local outputPanel = self:addGuiFrameV(resultPanel, "output", self.sectionItemStyle, ({"helmod_common.output"}))
local outputScroll = self:addGuiScrollPane(outputPanel, "output-scroll", self.scrollItemStyle, "auto", "auto")
local outputTable = self:addGuiTable(outputScroll,"output-table",8)
local outputPanel = self:addGuiFrameV(firstRow, "output", self.sectionItemStyle1, ({"helmod_common.output"}))
local outputScroll = self:addGuiScrollPane(outputPanel, "output-scroll", self.scrollItemStyle1, "auto", "auto")
local outputTable = self:addGuiTable(outputScroll,"output-table",4)
if element.products ~= nil then
for r, product in pairs(element.products) do
-- product = {type="item", name="steel-plate", amount=8}
Expand All @@ -448,8 +469,8 @@ function PlannerResult.methods:updateProductionBlock(player, item, item2, item3)
end

-- input panel
local inputPanel = self:addGuiFrameV(resultPanel, "input", self.sectionItemStyle, ({"helmod_common.input"}))
local outputScroll = self:addGuiScrollPane(inputPanel, "output-scroll", self.scrollItemStyle, "auto", "auto")
local inputPanel = self:addGuiFrameV(resultPanel, "input", self.sectionItemStyle2, ({"helmod_common.input"}))
local outputScroll = self:addGuiScrollPane(inputPanel, "output-scroll", self.scrollItemStyle2, "auto", "auto")
local inputTable = self:addGuiTable(outputScroll,"input-table",8)
if element.ingredients ~= nil then
for r, ingredient in pairs(element.ingredients) do
Expand Down Expand Up @@ -489,16 +510,6 @@ function PlannerResult.methods:updateProductionBlock(player, item, item2, item3)
for _, recipe in spairs(model.blocks[blockId].recipes, function(t,a,b) if model.order.ascendant then return t[b][model.order.name] > t[a][model.order.name] else return t[b][model.order.name] < t[a][model.order.name] end end) do
self:addProductionBlockRow(player, resultTable, blockId, recipe)
end

for i = 1, 3 + extra_cols, 1 do
self:addGuiLabel(resultTable, "blank-"..i, "")
end
self:addGuiLabel(resultTable, "foot-1", ({"helmod_result-panel.col-header-total"}))
if model.summary ~= nil then
self:addGuiLabel(resultTable, "energy", self:formatNumberKilo(element.power, "W"),"helmod_label-right-70")
end
self:addGuiLabel(resultTable, "blank-pro", "")
self:addGuiLabel(resultTable, "blank-ing", "")
end
end

Expand Down Expand Up @@ -854,7 +865,7 @@ function PlannerResult.methods:addProductionBlockRow(player, guiTable, blockId,
index = index + 1
end
end
self:addGuiLabel(guiFactory, factory.name, self:formatNumber(factory.count), "helmod_label-right")
self:addGuiLabel(guiFactory, factory.name, self:formatNumber(factory.limit_count).."/"..self:formatNumber(factory.count), "helmod_label-right")

-- col beacon
local guiBeacon = self:addGuiFlowH(guiTable,"beacon"..recipe.name)
Expand All @@ -868,7 +879,7 @@ function PlannerResult.methods:addProductionBlockRow(player, guiTable, blockId,
index = index + 1
end
end
self:addGuiLabel(guiBeacon, beacon.name, beacon.count, "helmod_label-right")
self:addGuiLabel(guiBeacon, beacon.name, self:formatNumber(beacon.count), "helmod_label-right")

-- col energy
local guiEnergy = self:addGuiFlowH(guiTable,"energy"..recipe.name, "helmod_align-right-flow")
Expand Down
41 changes: 28 additions & 13 deletions prototypes/style.lua
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ default_gui["helmod_label-right-100"] = {
default_gui["helmod_menu_frame_style"] = {
type = "frame_style",
parent = "frame_style",
minimal_width = 900,
minimal_width = 940,
resize_row_to_width = true
}

Expand Down Expand Up @@ -407,8 +407,7 @@ default_gui["helmod_result"] = {
minimal_height = 500,
flow_style = {
horizontal_spacing = 0,
vertical_spacing = 0,
resize_row_to_width = true
vertical_spacing = 0
}
}

Expand All @@ -427,34 +426,50 @@ default_gui["helmod_align-right-flow"] = {
align = "right"
}

default_gui["helmod_block-item-section-frame"] = {
default_gui["helmod_block-item-section-frame1"] = {
type = "frame_style",
parent = "frame_style",
minimal_width = 920,
maximal_width = 920
minimal_width = 465,
maximal_width = 465
}

default_gui["helmod_block-item-scroll"] = {
default_gui["helmod_block-item-scroll1"] = {
type = "scroll_pane_style",
parent = "scroll_pane_style",
minimal_width = 898,
maximal_width = 898,
minimal_width = 438,
maximal_width = 438,
minimal_height = 36,
maximal_height = 72
}

default_gui["helmod_block-item-section-frame2"] = {
type = "frame_style",
parent = "frame_style",
minimal_width = 940,
maximal_width = 940
}

default_gui["helmod_block-item-scroll2"] = {
type = "scroll_pane_style",
parent = "scroll_pane_style",
minimal_width = 918,
maximal_width = 918,
minimal_height = 36,
maximal_height = 72
}

default_gui["helmod_block-list-section-frame"] = {
type = "frame_style",
parent = "frame_style",
minimal_width = 920,
maximal_width = 920
minimal_width = 940,
maximal_width = 940
}

default_gui["helmod_block-list-scroll"] = {
type = "scroll_pane_style",
parent = "scroll_pane_style",
minimal_width = 898,
maximal_width = 898,
minimal_width = 918,
maximal_width = 918,
minimal_height = 516,
maximal_height = 516
}
Expand Down

0 comments on commit b097a9d

Please sign in to comment.