mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Refactored UPS monitor as clusterio plugin (#398)
* Refactor server ups * Use catalogs * Move to own plugin * Use web config * Remove External.get_server_ups * Update workspace version requirement * Remove need for storage * Add locale * Fix CI
This commit is contained in:
@@ -51,7 +51,6 @@ return {
|
||||
"modules.gui.task-list",
|
||||
"modules.gui.warp-list",
|
||||
"modules.gui.player-list",
|
||||
"modules.gui.server-ups",
|
||||
"modules.gui.bonus",
|
||||
"modules.gui.vlayer",
|
||||
"modules.gui.research",
|
||||
|
||||
@@ -116,16 +116,6 @@ function External.get_server_status(server_id, raw)
|
||||
return not raw and server_id == current and "Current" or assert(servers[server_id], "No status found for server with id: " .. tostring(server_id))
|
||||
end
|
||||
|
||||
--[[-- Gets the ups of the current server
|
||||
@usage-- Get the ups of the current server
|
||||
local server_ups = External.get_server_ups()
|
||||
|
||||
]]
|
||||
function External.get_server_ups()
|
||||
assert(var, "No external data was found, use External.valid() to ensure external data exists.")
|
||||
return assert(var.server_ups, "No server ups was found, please ensure that the external service is running")
|
||||
end
|
||||
|
||||
--[[-- Connect a player to the given server
|
||||
@tparam LuaPlayer player The player that you want to request to join a different server
|
||||
@tparam string server_id The internal id of the server to connect to, can also be any address but this will show Unknown Server
|
||||
|
||||
@@ -332,10 +332,6 @@ attempt=Attempt
|
||||
difference=Diff
|
||||
main-tooltip=Research GUI
|
||||
|
||||
[server-ups]
|
||||
description=Toggle the server UPS display.
|
||||
no-ext=No external source was found, cannot display server ups.
|
||||
|
||||
[tool]
|
||||
main-tooltip=Tool
|
||||
apply=Apply
|
||||
|
||||
@@ -340,10 +340,6 @@ attempt=用時
|
||||
difference=差距
|
||||
main-tooltip=研究介面
|
||||
|
||||
[server-ups]
|
||||
description=啟動 UPS 顯示
|
||||
no-ext=沒找到外置數據,沒法顯示。
|
||||
|
||||
[tool]
|
||||
main-tooltip=工具
|
||||
apply=應用
|
||||
|
||||
@@ -340,10 +340,6 @@ attempt=用時
|
||||
difference=差距
|
||||
main-tooltip=研究介面
|
||||
|
||||
[server-ups]
|
||||
description=啟動 UPS 顯示
|
||||
no-ext=沒找到外置數據,沒法顯示。
|
||||
|
||||
[tool]
|
||||
main-tooltip=工具
|
||||
apply=應用
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
--[[-- Gui Module - Server UPS
|
||||
- Adds a server ups counter in the top right and a command to toggle is
|
||||
@gui server-ups
|
||||
@alias server_ups
|
||||
]]
|
||||
|
||||
local Gui = require("modules/exp_gui")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local External = require("modules.exp_legacy.expcore.external") --- @dep expcore.external
|
||||
local Commands = require("modules/exp_commands")
|
||||
|
||||
--- Stores the visible state of server ups
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
||||
local UsesServerUps = PlayerData.Settings:combine("UsesServerUps")
|
||||
UsesServerUps:set_default(false)
|
||||
UsesServerUps:set_metadata{
|
||||
permission = "command/server-ups",
|
||||
stringify = function(value) return value and "Visible" or "Hidden" end,
|
||||
}
|
||||
|
||||
--- Label to show the server ups
|
||||
-- @element server_ups
|
||||
local server_ups = Gui.element("server_ups")
|
||||
:draw{
|
||||
type = "label",
|
||||
caption = "SUPS = 60.0",
|
||||
name = Gui.property_from_name,
|
||||
}
|
||||
:style{
|
||||
font = "default-game",
|
||||
}
|
||||
|
||||
--- Change the visible state when your data loads
|
||||
UsesServerUps:on_load(function(player_name, visible)
|
||||
local player = game.players[player_name]
|
||||
local label = player.gui.screen[server_ups.name]
|
||||
--- @diagnostic disable-next-line undefined-field
|
||||
if not External.valid() or not storage.ext.var.server_ups then visible = false end
|
||||
label.visible = visible or false
|
||||
end)
|
||||
|
||||
--- Toggles if the server ups is visbile
|
||||
Commands.new("server-ups", { "server-ups.description" })
|
||||
:add_aliases{ "sups", "ups" }
|
||||
:register(function(player)
|
||||
local label = player.gui.screen[server_ups.name]
|
||||
if not External.valid() then
|
||||
label.visible = false
|
||||
return Commands.status.error{ "server-ups.no-ext" }
|
||||
end
|
||||
label.visible = not label.visible
|
||||
UsesServerUps:set(player, label.visible)
|
||||
end)
|
||||
|
||||
-- Set the location of the label
|
||||
-- 1920x1080: x=1455, y=30 (ui scale 100%)
|
||||
local function set_location(event)
|
||||
local player = game.players[event.player_index]
|
||||
local label = player.gui.screen[server_ups.name]
|
||||
if not label then
|
||||
label = server_ups(player.gui.screen)
|
||||
label.visible = UsesServerUps:get(player)
|
||||
end
|
||||
local res = player.display_resolution
|
||||
local uis = player.display_scale
|
||||
-- below ups and clock
|
||||
-- label.location = {x=res.width-423*uis, y=50*uis}
|
||||
label.location = { x = res.width - 363 * uis, y = 31 * uis }
|
||||
end
|
||||
|
||||
-- Draw the label when the player joins
|
||||
Event.add(defines.events.on_player_created, set_location)
|
||||
Event.add(defines.events.on_player_joined_game, set_location)
|
||||
|
||||
-- Update the caption for all online players
|
||||
-- percentage of game speed
|
||||
Event.on_nth_tick(60, function()
|
||||
if External.valid() then
|
||||
local caption = External.get_server_ups() .. " (" .. string.format("%.1f", External.get_server_ups() * 5 / 3) .. "%)"
|
||||
for _, player in pairs(game.connected_players) do
|
||||
player.gui.screen[server_ups.name].caption = caption
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Update when res or ui scale changes
|
||||
Event.add(defines.events.on_player_display_resolution_changed, set_location)
|
||||
Event.add(defines.events.on_player_display_scale_changed, set_location)
|
||||
Reference in New Issue
Block a user