This commit is contained in:
2025-01-01 17:26:07 +09:00
parent 2749df9f08
commit a65a04c810
4 changed files with 42 additions and 43 deletions

View File

@@ -164,7 +164,7 @@ Commands.server = setmetatable({
--- @param msg LocalisedString? An optional message to be included when a command completes (only has an effect in command callbacks)
--- @return Commands.Status, LocalisedString # Should be returned directly without modification
function Commands.status.success(msg)
return Commands.status.success, msg or { "exp-commands.success" }
return Commands.status.success, msg == nil and { "exp-commands.success" } or msg
end
--- Used to signal an error has occurred in a command, data type parser, or permission authority
@@ -172,7 +172,7 @@ end
--- @param msg LocalisedString? An optional error message to be included in the output, a generic message is used if not provided
--- @return Commands.Status, LocalisedString # Should be returned directly without modification
function Commands.status.error(msg)
return Commands.status.error, { "exp-commands.error", msg or { "exp-commands.error-default" } }
return Commands.status.error, { "exp-commands.error", msg == nil and { "exp-commands.error-default" } or msg }
end
--- Used to signal the player is unauthorised to use a command, primarily used by permission authorities but can be used in a command callback
@@ -180,7 +180,7 @@ end
--- @param msg LocalisedString? An optional error message to be included in the output, a generic message is used if not provided
--- @return Commands.Status, LocalisedString # Should be returned directly without modification
function Commands.status.unauthorised(msg)
return Commands.status.unauthorised, msg or { "exp-commands.unauthorized", msg or { "exp-commands.unauthorized-default" } }
return Commands.status.unauthorised, { "exp-commands.unauthorized", msg == nil and { "exp-commands.unauthorized-default" } or msg }
end
--- Used to signal the player provided invalid input to an command, primarily used by data type parsers but can be used in a command callback
@@ -188,7 +188,7 @@ end
--- @param msg LocalisedString? An optional error message to be included in the output, a generic message is used if not provided
--- @return Commands.Status, LocalisedString # Should be returned directly without modification
function Commands.status.invalid_input(msg)
return Commands.status.invalid_input, msg or { "exp-commands.invalid-input" }
return Commands.status.invalid_input, msg == nil and { "exp-commands.invalid-input" } or msg
end
--- Used to signal an internal error has occurred, this is reserved for internal use only
@@ -702,7 +702,7 @@ function Commands._event_handler(event)
-- Parse the raw argument to get the correct data type
local success, status, parsed = Commands.parse_input(input, player, argument.input_parser)
if success == false then
log_command("Input parse failed", command, player, event.parameter, { status = valid_command_status[status], index = index, argument = argument, reason = parsed })
log_command("Input parse failed", command, player, event.parameter, { status = valid_command_status[status], index = index, argument = argument.name, reason = parsed })
return Commands.error{ "exp-commands.invalid-argument", argument.name, parsed }
else
arguments[index] = parsed

View File

@@ -83,7 +83,7 @@ function External.get_current_server()
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
local server_id = assert(ext.current, "No current id was found, please ensure that the external service is running")
return servers[server_id]
return assert(servers[server_id], "No details found for server with id: " .. tostring(server_id))
end
--[[-- Gets the details of the given server
@@ -97,7 +97,7 @@ local server = External.get_server_details('eu-01')
function External.get_server_details(server_id)
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
return servers[server_id]
return assert(servers[server_id], "No details found for server with id: " .. tostring(server_id))
end
--[[-- Gets the status of the given server
@@ -113,7 +113,7 @@ function External.get_server_status(server_id, raw)
assert(var, "No external data was found, use External.valid() to ensure external data exists.")
local servers = assert(var.status, "No server status was found, please ensure that the external service is running")
local current = assert(ext.current, "No current id was found, please ensure that the external service is running")
return not raw and server_id == current and "Current" or servers[server_id]
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

View File

@@ -59,8 +59,8 @@ Storage.register({
end)
--- Gets the silo data for a given silo entity
-- @tparam LuaEntity silo the rocket silo entity
-- @treturn table the data table for this silo, contains rockets launch, silo status, and its force
--- @param silo LuaEntity Rocket silo entity
--- @return table # Data table for this silo, contains rockets launch, silo status, and its force
function Rockets.get_silo_data(silo)
local position = silo.position
local silo_name = math.floor(position.x) .. ":" .. math.floor(position.y)
@@ -68,30 +68,30 @@ function Rockets.get_silo_data(silo)
end
--- Gets the silo data for a given silo entity
-- @tparam string silo_name the silo name that is stored in its data
-- @treturn table the data table for this silo, contains rockets launch, silo status, and its force
--- @param silo_name string Silo name that is stored in its data
--- @return table # Data table for this silo, contains rockets launch, silo status, and its force
function Rockets.get_silo_data_by_name(silo_name)
return rocket_silos[silo_name]
end
--- Gets the silo entity from its silo name, reverse to get_silo_data
-- @tparam string silo_name the silo name that is stored in its data
-- @treturn LuaEntity the rocket silo entity
--- @param silo_name string Silo name that is stored in its data
--- @return LuaEntity # Rocket silo entity
function Rockets.get_silo_entity(silo_name)
local data = rocket_silos[silo_name]
return data.entity
end
--- Gets the rocket stats for a force
-- @tparam string force_name the name of the force to get the stats for
-- @treturn table the table of stats for the force
--- @param force_name string Name of the force to get the stats for
--- @return table # Stats for the force
function Rockets.get_stats(force_name)
return rocket_stats[force_name] or {}
end
--- Gets all the rocket silos that belong to a force
-- @tparam string force_name the name of the force to get the silos for
-- @treturn table an array of silo data that all belong to this force
--- @param force_name string Name of the force to get the silos for
--- @return table # Array of silo data that all belong to this force
function Rockets.get_silos(force_name)
local rtn = {}
for _, silo_data in pairs(rocket_silos) do
@@ -104,23 +104,23 @@ function Rockets.get_silos(force_name)
end
--- Gets the launch time of a given rocket, due to cleaning not all counts are valid
-- @tparam string force_name the name of the force to get the count for
-- @tparam number rocket_number the number of the rocket to get the launch time for
-- @treturn number the game tick that the rocket was lanuched on
--- @param force_name string Name of the force to get the count for
--- @param rocket_number number Number of the rocket to get the launch time for
--- @return number? # Game tick that the rocket was launched on
function Rockets.get_rocket_time(force_name, rocket_number)
return rocket_times[force_name] and rocket_times[force_name][rocket_number] or nil
end
--- Gets the number of rockets that a force has launched
-- @tparam string force_name the name of the force to get the count for
-- @treturn number the number of rockets that the force has launched
--- @param force_name string the name of the force to get the count for
--- @return number # Number of rockets that the force has launched
function Rockets.get_rocket_count(force_name)
local force = game.forces[force_name]
return force.rockets_launched
end
--- Gets the total number of rockets launched by all forces
-- @treturn number the total number of rockets launched this game
--- @return number # Total number of rockets launched this game
function Rockets.get_game_rocket_count()
local rtn = 0
for _, force in pairs(game.forces) do
@@ -131,9 +131,9 @@ function Rockets.get_game_rocket_count()
end
--- Gets the rolling average time to launch a rocket
-- @tparam string force_name the name of the force to get the average for
-- @tparam number count the distance to get the rolling average over
-- @treturn number the number of ticks required to launch one rocket
--- @param force_name string Name of the force to get the average for
--- @param count number Distance to get the rolling average over
--- @return number # Number of ticks required to launch one rocket
function Rockets.get_rolling_average(force_name, count)
local force = game.forces[force_name]
local rocket_count = force.rockets_launched
@@ -147,14 +147,20 @@ function Rockets.get_rolling_average(force_name, count)
return math.floor((last_launch_time - start_rocket_time) / rocket_count)
end
--- When a launch is trigger it will wait for the silo to reset
--- @param event EventData.on_rocket_launch_ordered
Event.add(defines.events.on_rocket_launch_ordered, function(event)
local silo_data = Rockets.get_silo_data(event.rocket_silo)
silo_data.launched = silo_data.launched + 1
silo_data.awaiting_reset = true
end)
--- Event used to update the stats and the hui when a rocket is launched
--- @param event EventData.on_rocket_launched
Event.add(defines.events.on_rocket_launched, function(event)
local entity = event.rocket_silo
local silo_data = Rockets.get_silo_data(entity)
local force = event.rocket_silo.force
--- @param event EventData.on_cargo_pod_finished_ascending
Event.add(defines.events.on_cargo_pod_finished_ascending, function(event)
local force = event.cargo_pod.force
local force_name = force.name
local rockets_launched = force.rockets_launched + 1 -- Hasn't updated when this event fires
local rockets_launched = force.rockets_launched
--- Handles updates to the rocket stats
local stats = rocket_stats[force_name]
@@ -183,16 +189,6 @@ Event.add(defines.events.on_rocket_launched, function(event)
if remove_rocket > 0 and not table.contains(config.milestones, remove_rocket) then
rocket_times[force_name][remove_rocket] = nil
end
--- Adds this 1 to the launch count for this silo
silo_data.launched = silo_data.launched + 1
end)
--- When a launch is reiggered it will await reset
Event.add(defines.events.on_rocket_launch_ordered, function(event)
local entity = event.rocket_silo
local silo_data = Rockets.get_silo_data(entity)
silo_data.awaiting_reset = true
end)
--- Adds a silo to the list when it is built

View File

@@ -451,6 +451,7 @@ end
--- @class Common.copy_items_to_surface_param: Common.get_or_create_storage_param
--- @field items ItemStackIdentification[] | LuaInventory The item stacks to copy
--- @field item ItemStackIdentification? Overwritten internally
--- Insert a copy of the given items into the found entities. If no entities are found then they will be created if possible.
--- @param options Common.copy_items_to_surface_param
@@ -467,6 +468,7 @@ end
--- @class Common.move_items_to_surface_param: Common.get_or_create_storage_param
--- @field items LuaItemStack[] The item stacks to move
--- @field item ItemStackIdentification? Overwritten internally
--- Insert a copy of the given items into the found entities. If no entities are found then they will be created if possible.
--- @param options Common.move_items_to_surface_param
@@ -484,6 +486,7 @@ end
--- @class Common.transfer_inventory_to_surface_param: Common.copy_items_to_surface_param
--- @field inventory LuaInventory The inventory to transfer
--- @field items (ItemStackIdentification[] | LuaInventory)? Overwritten internally
--- Move the given inventory into the found entities. If no entities are found then they will be created if possible.
--- @param options Common.transfer_inventory_to_surface_param