mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 19:45:22 +09:00
103 lines
3.1 KiB
Lua
103 lines
3.1 KiB
Lua
--- Adds a science count gui to the game that shows toatal made and per minute
|
|
-- @module ExpGamingInfo.Science
|
|
-- @author Cooldude2606
|
|
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
|
-- @alais ThisModule
|
|
|
|
-- Module Require
|
|
local Gui = require('ExpGamingCore.Gui@^4.0.0')
|
|
local Game = require('FactorioStdLib.Game@^0.8.0')
|
|
|
|
-- Local Varibles
|
|
local science_packs = {
|
|
'science-pack-1',
|
|
'science-pack-2',
|
|
'science-pack-3',
|
|
'military-science-pack',
|
|
'production-science-pack',
|
|
'high-tech-science-pack',
|
|
'space-science-pack'
|
|
}
|
|
|
|
-- Module Define
|
|
local module_verbose = false
|
|
local ThisModule = {
|
|
on_init=function()
|
|
if loaded_modules['ExpGamingCore.Sync^4.0.0'] then require(module_path..'/src/sync') end
|
|
end
|
|
}
|
|
|
|
-- Global Define
|
|
local global = global{
|
|
_base={
|
|
update=0,
|
|
_update=0,
|
|
made={0,0,0,0,0,0,0},
|
|
_made={0,0,0,0,0,0,0}
|
|
}
|
|
}
|
|
|
|
-- Function Define
|
|
Gui.left.add{
|
|
name='science',
|
|
caption='item/lab',
|
|
tooltip={'ExpGamingInfo-Science.tooltip'},
|
|
draw=function(frame)
|
|
local player = Game.get_player(frame.player_index)
|
|
if not global[player.force.name] then
|
|
global[player.force.name] = table.deepcopy(global._base)
|
|
end
|
|
global = global[player.force.name]
|
|
frame.caption = {'ExpGamingInfo-Science.name'}
|
|
frame.add{
|
|
type='label',
|
|
caption={'ExpGamingInfo-Science.total'},
|
|
style='caption_label'
|
|
}
|
|
local totals = frame.add{
|
|
type='flow',
|
|
direction='vertical'
|
|
}
|
|
frame.add{
|
|
type='label',
|
|
caption={'ExpGamingInfo-Science.time'},
|
|
style='caption_label'
|
|
}
|
|
local times = frame.add{
|
|
type='flow',
|
|
direction='vertical'
|
|
}
|
|
if global.update < game.tick-100 then
|
|
global._update = global.update
|
|
global._made = table.deepcopy(global.made)
|
|
for i,name in pairs(science_packs) do
|
|
global.made[i] = player.force.item_production_statistics.get_input_count(name)
|
|
end
|
|
global.update = game.tick
|
|
end
|
|
for i,name in pairs(science_packs) do
|
|
local made = global.made[i]
|
|
if made > 0 then
|
|
totals.add{
|
|
type='label',
|
|
caption={'ExpGamingInfo-Science.format',{'ExpGamingInfo-Science.'..name},made}
|
|
}
|
|
local _made = string.format('%.2f',(made-global._made[i])/((global.update-global._update)/(3600*game.speed)))
|
|
times.add{
|
|
type='label',
|
|
caption={'ExpGamingInfo-Science.format',{'ExpGamingInfo-Science.'..name},_made}
|
|
}
|
|
end
|
|
end
|
|
end,
|
|
can_open=function(player)
|
|
if player.force.item_production_statistics.get_input_count('science-pack-1') > 0 then return true
|
|
else return {'ExpGamingInfo-Science.none'} end
|
|
end
|
|
}
|
|
|
|
-- Event Define
|
|
script.on_event(defines.events.on_research_finished,function(event) Gui.left.update('science') end)
|
|
|
|
-- Module Return
|
|
return ThisModule |