mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 04:06:39 +09:00
Added ExpGamingInfo
This commit is contained in:
103
modules/ExpGamingInfo/Science/control.lua
Normal file
103
modules/ExpGamingInfo/Science/control.lua
Normal file
@@ -0,0 +1,103 @@
|
||||
--- 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('FactoiorStdLib.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={'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 = {'science.name'}
|
||||
frame.add{
|
||||
type='label',
|
||||
caption={'science.total'},
|
||||
style='caption_label'
|
||||
}
|
||||
local totals = frame.add{
|
||||
type='flow',
|
||||
direction='vertical'
|
||||
}
|
||||
frame.add{
|
||||
type='label',
|
||||
caption={'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={'science.format',{'science.'..name},made}
|
||||
}
|
||||
local _made = string.format('%.2f',(made-global._made[i])/((global.update-global._update)/(3600*game.speed)))
|
||||
times.add{
|
||||
type='label',
|
||||
caption={'science.format',{'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 {'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
|
||||
Reference in New Issue
Block a user