mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-02-03 13:12:11 +02:00
added UPS measurement
this is done in the wrapper
This commit is contained in:
parent
85c138c1a2
commit
729c252a02
@ -8,6 +8,7 @@ require 'utils.server_commands'
|
||||
require 'utils.utils'
|
||||
require 'utils.table'
|
||||
require 'utils.freeplay'
|
||||
require 'utils.datastore.server_ups'
|
||||
require 'utils.datastore.color_data'
|
||||
require 'utils.datastore.session_data'
|
||||
require 'utils.datastore.jail_data'
|
||||
|
@ -8,7 +8,7 @@ function Public.conjure_items()
|
||||
obj_to_create = 'stone-wall',
|
||||
level = 10,
|
||||
type = 'item',
|
||||
mana_cost = 35,
|
||||
mana_cost = 60,
|
||||
tick = 100,
|
||||
enabled = true
|
||||
}
|
||||
@ -18,7 +18,7 @@ function Public.conjure_items()
|
||||
obj_to_create = 'wooden-chest',
|
||||
level = 2,
|
||||
type = 'item',
|
||||
mana_cost = 30,
|
||||
mana_cost = 50,
|
||||
tick = 100,
|
||||
enabled = true
|
||||
}
|
||||
@ -27,7 +27,7 @@ function Public.conjure_items()
|
||||
obj_to_create = 'iron-chest',
|
||||
level = 10,
|
||||
type = 'item',
|
||||
mana_cost = 40,
|
||||
mana_cost = 110,
|
||||
tick = 200,
|
||||
enabled = true
|
||||
}
|
||||
@ -36,7 +36,7 @@ function Public.conjure_items()
|
||||
obj_to_create = 'steel-chest',
|
||||
level = 15,
|
||||
type = 'item',
|
||||
mana_cost = 50,
|
||||
mana_cost = 150,
|
||||
tick = 300,
|
||||
enabled = true
|
||||
}
|
||||
@ -45,7 +45,7 @@ function Public.conjure_items()
|
||||
obj_to_create = 'transport-belt',
|
||||
level = 3,
|
||||
type = 'item',
|
||||
mana_cost = 40,
|
||||
mana_cost = 80,
|
||||
tick = 100,
|
||||
enabled = true
|
||||
}
|
||||
@ -54,7 +54,7 @@ function Public.conjure_items()
|
||||
obj_to_create = 'fast-transport-belt',
|
||||
level = 20,
|
||||
type = 'item',
|
||||
mana_cost = 50,
|
||||
mana_cost = 110,
|
||||
tick = 200,
|
||||
enabled = true
|
||||
}
|
||||
@ -63,7 +63,7 @@ function Public.conjure_items()
|
||||
obj_to_create = 'express-transport-belt',
|
||||
level = 60,
|
||||
type = 'item',
|
||||
mana_cost = 60,
|
||||
mana_cost = 150,
|
||||
tick = 300,
|
||||
enabled = true
|
||||
}
|
||||
@ -72,7 +72,7 @@ function Public.conjure_items()
|
||||
obj_to_create = 'underground-belt',
|
||||
level = 3,
|
||||
type = 'item',
|
||||
mana_cost = 40,
|
||||
mana_cost = 80,
|
||||
tick = 100,
|
||||
enabled = true
|
||||
}
|
||||
@ -81,7 +81,7 @@ function Public.conjure_items()
|
||||
obj_to_create = 'fast-underground-belt',
|
||||
level = 20,
|
||||
type = 'item',
|
||||
mana_cost = 50,
|
||||
mana_cost = 110,
|
||||
tick = 200,
|
||||
enabled = true
|
||||
}
|
||||
@ -90,7 +90,7 @@ function Public.conjure_items()
|
||||
obj_to_create = 'express-underground-belt',
|
||||
level = 60,
|
||||
type = 'item',
|
||||
mana_cost = 60,
|
||||
mana_cost = 150,
|
||||
tick = 300,
|
||||
enabled = true
|
||||
}
|
||||
@ -110,7 +110,7 @@ function Public.conjure_items()
|
||||
biter = true,
|
||||
type = 'entity',
|
||||
mana_cost = 55,
|
||||
tick = 100,
|
||||
tick = 200,
|
||||
enabled = true
|
||||
}
|
||||
spells[#spells + 1] = {
|
||||
@ -120,7 +120,7 @@ function Public.conjure_items()
|
||||
biter = true,
|
||||
type = 'entity',
|
||||
mana_cost = 55,
|
||||
tick = 100,
|
||||
tick = 200,
|
||||
enabled = true
|
||||
}
|
||||
spells[#spells + 1] = {
|
||||
@ -130,7 +130,7 @@ function Public.conjure_items()
|
||||
biter = true,
|
||||
type = 'entity',
|
||||
mana_cost = 100,
|
||||
tick = 200,
|
||||
tick = 300,
|
||||
enabled = true
|
||||
}
|
||||
spells[#spells + 1] = {
|
||||
@ -139,7 +139,7 @@ function Public.conjure_items()
|
||||
level = 70,
|
||||
type = 'entity',
|
||||
mana_cost = 100,
|
||||
tick = 200,
|
||||
tick = 300,
|
||||
enabled = true
|
||||
}
|
||||
spells[#spells + 1] = {
|
||||
@ -148,7 +148,7 @@ function Public.conjure_items()
|
||||
level = 100,
|
||||
biter = true,
|
||||
type = 'entity',
|
||||
mana_cost = 600,
|
||||
mana_cost = 800,
|
||||
tick = 1420,
|
||||
enabled = true
|
||||
}
|
||||
@ -268,7 +268,7 @@ function Public.conjure_items()
|
||||
force = 'player',
|
||||
level = 50,
|
||||
type = 'special',
|
||||
mana_cost = 200,
|
||||
mana_cost = 300,
|
||||
tick = 320,
|
||||
enabled = true
|
||||
}
|
||||
|
94
utils/datastore/server_ups.lua
Normal file
94
utils/datastore/server_ups.lua
Normal file
@ -0,0 +1,94 @@
|
||||
local Server = require 'utils.server'
|
||||
local GUI = require 'utils.gui'
|
||||
local Event = require 'utils.event'
|
||||
local Color = require 'utils.color_presets'
|
||||
|
||||
local ups_label = GUI.uid_name()
|
||||
|
||||
local function validate_player(player)
|
||||
if not player or not player.valid then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function set_location(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
local gui = player.gui
|
||||
local label = gui.screen[ups_label]
|
||||
local res = player.display_resolution
|
||||
local uis = player.display_scale
|
||||
label.location = {x = res.width - 423 * uis, y = 30 * uis}
|
||||
end
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_joined_game,
|
||||
function(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
local ups = Server.get_ups()
|
||||
local sUPS = 'SUPS = ' .. ups
|
||||
|
||||
local label = player.gui.screen[ups_label]
|
||||
|
||||
if not label or not label.valid then
|
||||
label =
|
||||
player.gui.screen.add(
|
||||
{
|
||||
type = 'label',
|
||||
name = ups_label,
|
||||
caption = sUPS
|
||||
}
|
||||
)
|
||||
local style = label.style
|
||||
style.font = 'default-game'
|
||||
end
|
||||
set_location(event)
|
||||
label.visible = false
|
||||
end
|
||||
)
|
||||
|
||||
-- Update the value each second
|
||||
Event.on_nth_tick(
|
||||
60,
|
||||
function()
|
||||
local ups = Server.get_ups()
|
||||
local caption = 'SUPS = ' .. ups
|
||||
local players = game.connected_players
|
||||
for _, player in pairs(players) do
|
||||
local label = player.gui.screen[ups_label]
|
||||
if label and label.valid then
|
||||
label.caption = caption
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
commands.add_command(
|
||||
'server-ups',
|
||||
'Toggle the server UPS display!',
|
||||
function()
|
||||
local player = game.player
|
||||
|
||||
local secs = Server.get_current_time()
|
||||
|
||||
if validate_player(player) then
|
||||
if not secs then
|
||||
return player.print('Not running on Comfy backend.', Color.warning)
|
||||
end
|
||||
|
||||
local label = player.gui.screen[ups_label]
|
||||
if not label or not label.valid then
|
||||
return
|
||||
end
|
||||
|
||||
if label.visible then
|
||||
label.visible = false
|
||||
else
|
||||
label.visible = true
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
Event.add(defines.events.on_player_display_resolution_changed, set_location)
|
||||
Event.add(defines.events.on_player_display_scale_changed, set_location)
|
@ -16,15 +16,18 @@ local serialize_options = {sparse = true, compact = true}
|
||||
local Public = {}
|
||||
|
||||
local server_time = {secs = nil, tick = 0}
|
||||
local server_ups = {ups = 60}
|
||||
local requests = {}
|
||||
|
||||
Global.register(
|
||||
{
|
||||
server_time = server_time,
|
||||
server_ups = server_ups,
|
||||
requests = requests
|
||||
},
|
||||
function(tbl)
|
||||
server_time = tbl.server_time
|
||||
server_ups = tbl.server_ups
|
||||
requests = tbl.requests
|
||||
end
|
||||
)
|
||||
@ -663,6 +666,19 @@ function Public.get_time_data_raw()
|
||||
return server_time
|
||||
end
|
||||
|
||||
--- Called by the web server to set the ups value.
|
||||
-- @param tick<number> tick
|
||||
function Public.set_ups(tick)
|
||||
server_ups.ups = tick
|
||||
end
|
||||
|
||||
--- Gets a the estimated UPS from the web panel that is sent to the server.
|
||||
-- This is calculated and measured in the wrapper.
|
||||
-- @return number
|
||||
function Public.get_ups()
|
||||
return server_ups.ups
|
||||
end
|
||||
|
||||
--- Gets an estimate of the current server time as a unix epoch timestamp.
|
||||
-- If the server time has not been set returns nil.
|
||||
-- The estimate may be slightly off if within the last minute the game has been paused, saving or overwise,
|
||||
|
@ -1,4 +1,5 @@
|
||||
local Poll = {send_poll_result_to_discord = function () end}
|
||||
local Poll = {send_poll_result_to_discord = function()
|
||||
end}
|
||||
local Token = require 'utils.token'
|
||||
local Server = require 'utils.server'
|
||||
|
||||
@ -9,7 +10,6 @@ ServerCommands = {}
|
||||
|
||||
ServerCommands.get_poll_result = Poll.send_poll_result_to_discord
|
||||
|
||||
|
||||
function ServerCommands.raise_callback(func_token, data)
|
||||
local func = Token.get(func_token)
|
||||
func(data)
|
||||
@ -23,6 +23,7 @@ function ServerCommands.server_started()
|
||||
end
|
||||
|
||||
ServerCommands.set_time = Server.set_time
|
||||
ServerCommands.set_ups = Server.set_ups
|
||||
ServerCommands.query_online_players = Server.query_online_players
|
||||
|
||||
return ServerCommands
|
||||
|
Loading…
x
Reference in New Issue
Block a user