mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Resolve all Luals warnings
This commit is contained in:
@@ -30,6 +30,7 @@ end
|
|||||||
--- Add a player to a permission group, requires edit_permission_group
|
--- Add a player to a permission group, requires edit_permission_group
|
||||||
--- @param player LuaPlayer Player to add to the group
|
--- @param player LuaPlayer Player to add to the group
|
||||||
--- @param group LuaPermissionGroup Group to add the player to
|
--- @param group LuaPermissionGroup Group to add the player to
|
||||||
|
--- @return boolean # True if successful
|
||||||
local function add_player_to_group(player, group)
|
local function add_player_to_group(player, group)
|
||||||
return group.add_player(player)
|
return group.add_player(player)
|
||||||
end
|
end
|
||||||
@@ -37,6 +38,7 @@ end
|
|||||||
--- Add a players to a permission group, requires edit_permission_group
|
--- Add a players to a permission group, requires edit_permission_group
|
||||||
--- @param players LuaPlayer[] Players to add to the group
|
--- @param players LuaPlayer[] Players to add to the group
|
||||||
--- @param group LuaPermissionGroup Group to add the players to
|
--- @param group LuaPermissionGroup Group to add the players to
|
||||||
|
--- @return boolean # True if successful
|
||||||
local function add_players_to_group(players, group)
|
local function add_players_to_group(players, group)
|
||||||
local add_player = group.add_player
|
local add_player = group.add_player
|
||||||
if not add_player(players[1]) then
|
if not add_player(players[1]) then
|
||||||
@@ -57,6 +59,7 @@ local add_players_to_group_async = Async.register(add_players_to_group)
|
|||||||
|
|
||||||
--- Gets the permission group proxy with the given name or group ID.
|
--- Gets the permission group proxy with the given name or group ID.
|
||||||
--- @param group_name string|uint32 The name or id of the permission group
|
--- @param group_name string|uint32 The name or id of the permission group
|
||||||
|
--- @return ExpGroup?
|
||||||
function Groups.get_group(group_name)
|
function Groups.get_group(group_name)
|
||||||
local group = game.permissions.get_group(group_name)
|
local group = game.permissions.get_group(group_name)
|
||||||
if group == nil then return nil end
|
if group == nil then return nil end
|
||||||
@@ -67,6 +70,7 @@ end
|
|||||||
|
|
||||||
--- Gets the permission group proxy for a players group
|
--- Gets the permission group proxy for a players group
|
||||||
--- @param player LuaPlayer The player to get the group of
|
--- @param player LuaPlayer The player to get the group of
|
||||||
|
--- @return ExpGroup?
|
||||||
function Groups.get_player_group(player)
|
function Groups.get_player_group(player)
|
||||||
local group = player.permission_group
|
local group = player.permission_group
|
||||||
if group == nil then return nil end
|
if group == nil then return nil end
|
||||||
@@ -77,6 +81,7 @@ end
|
|||||||
|
|
||||||
--- Creates a new permission group, requires add_permission_group
|
--- Creates a new permission group, requires add_permission_group
|
||||||
--- @param group_name string Name of the group to create
|
--- @param group_name string Name of the group to create
|
||||||
|
--- @return ExpGroup
|
||||||
function Groups.new_group(group_name)
|
function Groups.new_group(group_name)
|
||||||
local group = game.permissions.get_group(group_name)
|
local group = game.permissions.get_group(group_name)
|
||||||
assert(group == nil, "Group already exists with name: " .. group_name)
|
assert(group == nil, "Group already exists with name: " .. group_name)
|
||||||
@@ -89,6 +94,7 @@ end
|
|||||||
|
|
||||||
--- Get or create a permisison group, must use the group name not the group id
|
--- Get or create a permisison group, must use the group name not the group id
|
||||||
--- @param group_name string Name of the group to create
|
--- @param group_name string Name of the group to create
|
||||||
|
--- @return ExpGroup
|
||||||
function Groups.get_or_create(group_name)
|
function Groups.get_or_create(group_name)
|
||||||
local group = game.permissions.get_group(group_name)
|
local group = game.permissions.get_group(group_name)
|
||||||
if group then
|
if group then
|
||||||
@@ -109,7 +115,7 @@ end
|
|||||||
--- @param move_to_name string|uint32? The name or id of the permission group to move players to
|
--- @param move_to_name string|uint32? The name or id of the permission group to move players to
|
||||||
function Groups.destroy_group(group_name, move_to_name)
|
function Groups.destroy_group(group_name, move_to_name)
|
||||||
local group = game.permissions.get_group(group_name)
|
local group = game.permissions.get_group(group_name)
|
||||||
if group == nil then return nil end
|
if group == nil then return end
|
||||||
|
|
||||||
local players = group.players
|
local players = group.players
|
||||||
if #players > 0 then
|
if #players > 0 then
|
||||||
@@ -128,23 +134,30 @@ end
|
|||||||
--- Add a player to the permission group
|
--- Add a player to the permission group
|
||||||
--- @param player LuaPlayer The player to add to the group
|
--- @param player LuaPlayer The player to add to the group
|
||||||
function Groups._prototype:add_player(player)
|
function Groups._prototype:add_player(player)
|
||||||
return add_player_to_group(player, self.group) or add_player_to_group_async(player, self.group)
|
if not add_player_to_group(player, self.group) then
|
||||||
|
add_player_to_group_async(player, self.group)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Add players to the permission group
|
--- Add players to the permission group
|
||||||
--- @param players LuaPlayer[] The player to add to the group
|
--- @param players LuaPlayer[] The player to add to the group
|
||||||
function Groups._prototype:add_players(players)
|
function Groups._prototype:add_players(players)
|
||||||
return add_players_to_group(players, self.group) or add_players_to_group_async(players, self.group)
|
if not add_players_to_group(players, self.group) then
|
||||||
|
add_players_to_group_async(players, self.group)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Move all players to another group
|
--- Move all players to another group
|
||||||
--- @param other_group ExpGroup The group to move players to, default is the Default group
|
--- @param other_group ExpGroup The group to move players to, default is the Default group
|
||||||
function Groups._prototype:move_players(other_group)
|
function Groups._prototype:move_players(other_group)
|
||||||
return add_players_to_group(self.group.players, other_group.group) or add_players_to_group_async(self.group.players, other_group.group)
|
if not add_players_to_group(self.group.players, other_group.group) then
|
||||||
|
add_players_to_group_async(self.group.players, other_group.group)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Allow a set of actions for this group
|
--- Allow a set of actions for this group
|
||||||
--- @param actions defines.input_action[] Actions to allow
|
--- @param actions defines.input_action[] Actions to allow
|
||||||
|
--- @return ExpGroup
|
||||||
function Groups._prototype:allow_actions(actions)
|
function Groups._prototype:allow_actions(actions)
|
||||||
local set_allow = self.group.set_allows_action
|
local set_allow = self.group.set_allows_action
|
||||||
for _, action in ipairs(actions) do
|
for _, action in ipairs(actions) do
|
||||||
@@ -156,6 +169,7 @@ end
|
|||||||
|
|
||||||
--- Disallow a set of actions for this group
|
--- Disallow a set of actions for this group
|
||||||
--- @param actions defines.input_action[] Actions to disallow
|
--- @param actions defines.input_action[] Actions to disallow
|
||||||
|
--- @return ExpGroup
|
||||||
function Groups._prototype:disallow_actions(actions)
|
function Groups._prototype:disallow_actions(actions)
|
||||||
local set_allow = self.group.set_allows_action
|
local set_allow = self.group.set_allows_action
|
||||||
for _, action in ipairs(actions) do
|
for _, action in ipairs(actions) do
|
||||||
@@ -167,6 +181,7 @@ end
|
|||||||
|
|
||||||
--- Reset the allowed state of all actions
|
--- Reset the allowed state of all actions
|
||||||
--- @param allowed boolean? default true for allow all actions, false to disallow all actions
|
--- @param allowed boolean? default true for allow all actions, false to disallow all actions
|
||||||
|
--- @return ExpGroup
|
||||||
function Groups._prototype:reset(allowed)
|
function Groups._prototype:reset(allowed)
|
||||||
local set_allow = self.group.set_allows_action
|
local set_allow = self.group.set_allows_action
|
||||||
if allowed == nil then allowed = true end
|
if allowed == nil then allowed = true end
|
||||||
@@ -179,6 +194,7 @@ end
|
|||||||
|
|
||||||
--- Returns if the group is allowed a given action
|
--- Returns if the group is allowed a given action
|
||||||
--- @param action string|defines.input_action Actions to test
|
--- @param action string|defines.input_action Actions to test
|
||||||
|
--- @return boolean # True if successful
|
||||||
function Groups._prototype:allows(action)
|
function Groups._prototype:allows(action)
|
||||||
if type(action) == "string" then
|
if type(action) == "string" then
|
||||||
return self.group.allows_action(defines.input_action[action])
|
return self.group.allows_action(defines.input_action[action])
|
||||||
@@ -197,6 +213,7 @@ end
|
|||||||
|
|
||||||
--- Convert an array of strings into an array of action names
|
--- Convert an array of strings into an array of action names
|
||||||
--- @param actions_names string[] An array of action names
|
--- @param actions_names string[] An array of action names
|
||||||
|
--- @return defines.input_action[]
|
||||||
local function names_to_actions(actions_names)
|
local function names_to_actions(actions_names)
|
||||||
local actions, invalid, invalid_i = {}, {}, 1
|
local actions, invalid, invalid_i = {}, {}, 1
|
||||||
for i, action_name in ipairs(actions_names) do
|
for i, action_name in ipairs(actions_names) do
|
||||||
@@ -241,6 +258,7 @@ end
|
|||||||
|
|
||||||
--- Convert a json string array into an array of input actions
|
--- Convert a json string array into an array of input actions
|
||||||
--- @param json string A json string representing a string array of actions
|
--- @param json string A json string representing a string array of actions
|
||||||
|
--- @return defines.input_action[]
|
||||||
function Groups.json_to_actions(json)
|
function Groups.json_to_actions(json)
|
||||||
local tbl = json_to_table(json)
|
local tbl = json_to_table(json)
|
||||||
assert(tbl, "Invalid Json String")
|
assert(tbl, "Invalid Json String")
|
||||||
@@ -277,9 +295,10 @@ function Groups._prototype:from_json(json)
|
|||||||
assert(tbl and type(tbl[1]) == "boolean" and type(tbl[2]) == "table", "Invalid Json String")
|
assert(tbl and type(tbl[1]) == "boolean" and type(tbl[2]) == "table", "Invalid Json String")
|
||||||
|
|
||||||
if tbl[1] then
|
if tbl[1] then
|
||||||
return self:reset(true):disallow_actions(names_to_actions(tbl[2]))
|
self:reset(true):disallow_actions(names_to_actions(tbl[2]))
|
||||||
|
return
|
||||||
end
|
end
|
||||||
return self:reset(false):allow_actions(names_to_actions(tbl[2]))
|
self:reset(false):allow_actions(names_to_actions(tbl[2]))
|
||||||
end
|
end
|
||||||
|
|
||||||
return Groups
|
return Groups
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
-- @config Permission-Groups
|
-- @config Permission-Groups
|
||||||
|
|
||||||
-- local Event = require("modules/exp_legacy/utils/event") -- @dep utils.event
|
-- local Event = require("modules/exp_legacy/utils/event") -- @dep utils.event
|
||||||
local Permission_Groups = require("modules.exp_legacy.expcore.permission_groups") --- @dep expcore.permission_groups
|
local Groups = require("modules.exp_legacy.expcore.permission_groups") --- @dep expcore.permission_groups
|
||||||
|
|
||||||
Permission_Groups.new_group("Admin")
|
Groups.new_group("Admin")
|
||||||
:allow_all()
|
:allow_all()
|
||||||
:disallow{
|
:disallow{
|
||||||
"add_permission_group", -- admin
|
"add_permission_group", -- admin
|
||||||
@@ -24,7 +24,7 @@ Permission_Groups.new_group("Admin")
|
|||||||
"set_infinity_pipe_filter",
|
"set_infinity_pipe_filter",
|
||||||
}
|
}
|
||||||
|
|
||||||
Permission_Groups.new_group("Trusted")
|
Groups.new_group("Trusted")
|
||||||
:allow_all()
|
:allow_all()
|
||||||
:disallow{
|
:disallow{
|
||||||
"add_permission_group", -- admin
|
"add_permission_group", -- admin
|
||||||
@@ -42,7 +42,7 @@ Permission_Groups.new_group("Trusted")
|
|||||||
"admin_action", -- trusted
|
"admin_action", -- trusted
|
||||||
}
|
}
|
||||||
|
|
||||||
Permission_Groups.new_group("Standard")
|
Groups.new_group("Standard")
|
||||||
:allow_all()
|
:allow_all()
|
||||||
:disallow{
|
:disallow{
|
||||||
"add_permission_group", -- admin
|
"add_permission_group", -- admin
|
||||||
@@ -64,7 +64,7 @@ Permission_Groups.new_group("Standard")
|
|||||||
"set_rocket_silo_send_to_orbit_automated_mode",
|
"set_rocket_silo_send_to_orbit_automated_mode",
|
||||||
}
|
}
|
||||||
|
|
||||||
Permission_Groups.new_group("Guest")
|
Groups.new_group("Guest")
|
||||||
:allow_all()
|
:allow_all()
|
||||||
:disallow{
|
:disallow{
|
||||||
"add_permission_group", -- admin
|
"add_permission_group", -- admin
|
||||||
@@ -99,7 +99,7 @@ Permission_Groups.new_group("Guest")
|
|||||||
"flush_opened_entity_specific_fluid",
|
"flush_opened_entity_specific_fluid",
|
||||||
}
|
}
|
||||||
|
|
||||||
Permission_Groups.new_group("Restricted")
|
Groups.new_group("Restricted")
|
||||||
:disallow_all()
|
:disallow_all()
|
||||||
:allow("write_to_console")
|
:allow("write_to_console")
|
||||||
|
|
||||||
|
|||||||
@@ -210,8 +210,8 @@ Roles.new_role("Veteran", "Vet")
|
|||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
local stats = Statistics:get(player, {})
|
local stats = Statistics:get(player, {})
|
||||||
local playTime, afkTime, mapCount = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0
|
local playtime, afk_time, map_count = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0
|
||||||
return playTime - afkTime >= hours250 and mapCount >= 25
|
return playtime - afk_time >= hours250 and map_count >= 25
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -259,8 +259,8 @@ Roles.new_role("Regular", "Reg")
|
|||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
local stats = Statistics:get(player, {})
|
local stats = Statistics:get(player, {})
|
||||||
local playTime, afkTime, mapCount = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0
|
local playtime, afk_time, map_count = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0
|
||||||
return playTime - afkTime >= hours15 and mapCount >= 5
|
return playtime - afk_time >= hours15 and map_count >= 5
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -76,9 +76,12 @@ function Public.add_compilatron(entity, name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
Public.compilatrons[name] = entity
|
Public.compilatrons[name] = entity
|
||||||
local message =
|
local message = entity.surface.create_entity{
|
||||||
entity.surface.create_entity
|
name = "compi-speech-bubble",
|
||||||
{ name = "compi-speech-bubble", text = messages[name][1], position = { 0, 0 }, source = entity }
|
text = messages[name][1],
|
||||||
|
position = { 0, 0 },
|
||||||
|
source = entity,
|
||||||
|
}
|
||||||
|
|
||||||
Public.current_messages[name] = { message = message, msg_number = 1 }
|
Public.current_messages[name] = { message = message, msg_number = 1 }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -56,7 +56,14 @@ if config.decon_area then
|
|||||||
local items = e.surface.find_entities_filtered{ area = e.area, force = player.force }
|
local items = e.surface.find_entities_filtered{ area = e.area, force = player.force }
|
||||||
|
|
||||||
if #items > 250 then
|
if #items > 250 then
|
||||||
print_to_players(true, { "deconlog.decon", player.name, e.surface.name, pos_to_gps_string(e.area.left_top), pos_to_gps_string(e.area.right_bottom), format_number(#items) })
|
print_to_players(true, {
|
||||||
|
"deconlog.decon",
|
||||||
|
player.name,
|
||||||
|
e.surface.localised_name,
|
||||||
|
pos_to_gps_string(e.area.left_top),
|
||||||
|
pos_to_gps_string(e.area.right_bottom),
|
||||||
|
format_number(#items, false),
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
add_log(get_secs() .. "," .. player.name .. ",decon_area," .. e.surface.name .. "," .. pos_to_string(e.area.left_top) .. "," .. pos_to_string(e.area.right_bottom))
|
add_log(get_secs() .. "," .. player.name .. ",decon_area," .. e.surface.name .. "," .. pos_to_string(e.area.left_top) .. "," .. pos_to_string(e.area.right_bottom))
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ local directions = {
|
|||||||
["SW"] = 0.875,
|
["SW"] = 0.875,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function Angle(entity)
|
local function get_direction(entity)
|
||||||
local angle = math.atan2(entity.position.y, entity.position.x) / math.pi
|
local angle = math.atan2(entity.position.y, entity.position.x) / math.pi
|
||||||
for direction, requiredAngle in pairs(directions) do
|
for direction, required_angle in pairs(directions) do
|
||||||
if angle < requiredAngle then
|
if angle < required_angle then
|
||||||
return direction
|
return direction
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -45,14 +45,14 @@ local function station_name_changer(event)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local boundingBox = entity.bounding_box
|
local bounding_box = entity.bounding_box
|
||||||
-- expanded box for recourse search:
|
-- expanded box for recourse search:
|
||||||
local bounding2 = { { boundingBox.left_top.x - 100, boundingBox.left_top.y - 100 }, { boundingBox.right_bottom.x + 100, boundingBox.right_bottom.y + 100 } }
|
local bounding2 = { { bounding_box.left_top.x - 100, bounding_box.left_top.y - 100 }, { bounding_box.right_bottom.x + 100, bounding_box.right_bottom.y + 100 } }
|
||||||
-- gets all resources in bounding_box2:
|
-- gets all resources in bounding_box2:
|
||||||
local recourses = game.surfaces[1].find_entities_filtered{ area = bounding2, type = "resource" }
|
local recourses = game.surfaces[1].find_entities_filtered{ area = bounding2, type = "resource" }
|
||||||
if #recourses > 0 then -- save cpu time if their are no recourses in bounding_box2
|
if #recourses > 0 then -- save cpu time if their are no recourses in bounding_box2
|
||||||
local closest_distance
|
local closest_distance
|
||||||
local px, py = boundingBox.left_top.x, boundingBox.left_top.y
|
local px, py = bounding_box.left_top.x, bounding_box.left_top.y
|
||||||
local recourse_closed
|
local recourse_closed
|
||||||
|
|
||||||
-- Check which recourse is closest
|
-- Check which recourse is closest
|
||||||
@@ -77,7 +77,7 @@ local function station_name_changer(event)
|
|||||||
entity.backer_name = config.station_name:gsub("__icon__", "[img=" .. item_type .. "." .. item_name .. "]")
|
entity.backer_name = config.station_name:gsub("__icon__", "[img=" .. item_type .. "." .. item_name .. "]")
|
||||||
:gsub("__item_name__", item_name2)
|
:gsub("__item_name__", item_name2)
|
||||||
:gsub("__backer_name__", entity.backer_name)
|
:gsub("__backer_name__", entity.backer_name)
|
||||||
:gsub("__direction__", Angle(entity))
|
:gsub("__direction__", get_direction(entity))
|
||||||
:gsub("__x__", math.floor(entity.position.x))
|
:gsub("__x__", math.floor(entity.position.x))
|
||||||
:gsub("__y__", math.floor(entity.position.y))
|
:gsub("__y__", math.floor(entity.position.y))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ Statistics:on_load(function(player_name, player_statistics)
|
|||||||
if new_players[player_name] then
|
if new_players[player_name] then
|
||||||
new_players[player_name] = nil
|
new_players[player_name] = nil
|
||||||
local ctn = player_statistics.MapsPlayed
|
local ctn = player_statistics.MapsPlayed
|
||||||
player_statistics.MapsPlayed = ctn and ctn + 1 or 1
|
player_statistics["MapsPlayed"] = ctn and ctn + 1 or 1
|
||||||
end
|
end
|
||||||
|
|
||||||
return player_statistics
|
return player_statistics
|
||||||
|
|||||||
@@ -20,8 +20,11 @@ local function bonus_gui_pts_needed(player)
|
|||||||
total = total + (disp["bonus_display_" .. k .. "_slider"].slider_value / config.player_bonus[v].cost_scale * config.player_bonus[v].cost)
|
total = total + (disp["bonus_display_" .. k .. "_slider"].slider_value / config.player_bonus[v].cost_scale * config.player_bonus[v].cost)
|
||||||
end
|
end
|
||||||
|
|
||||||
total = total +
|
total = total + (
|
||||||
(disp["bonus_display_personal_battery_recharge_slider"].slider_value / config.player_special_bonus["personal_battery_recharge"].cost_scale * config.player_special_bonus["personal_battery_recharge"].cost)
|
disp["bonus_display_personal_battery_recharge_slider"].slider_value
|
||||||
|
/ config.player_special_bonus["personal_battery_recharge"].cost_scale
|
||||||
|
* config.player_special_bonus["personal_battery_recharge"].cost
|
||||||
|
)
|
||||||
|
|
||||||
return total
|
return total
|
||||||
end
|
end
|
||||||
@@ -174,15 +177,15 @@ local bonus_gui_control_reset =
|
|||||||
disp[s].slider_value = config.player_bonus[v].value
|
disp[s].slider_value = config.player_bonus[v].value
|
||||||
|
|
||||||
if config.player_bonus[v].is_percentage then
|
if config.player_bonus[v].is_percentage then
|
||||||
disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value * 100) .. " %"
|
disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value * 100, false) .. " %"
|
||||||
else
|
else
|
||||||
disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value)
|
disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value, false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local slider = disp["bonus_display_personal_battery_recharge_slider"]
|
local slider = disp["bonus_display_personal_battery_recharge_slider"]
|
||||||
slider.slider_value = config.player_special_bonus["personal_battery_recharge"].value
|
slider.slider_value = config.player_special_bonus["personal_battery_recharge"].value
|
||||||
disp[slider.tags.counter].caption = format_number(slider.slider_value)
|
disp[slider.tags.counter].caption = format_number(slider.slider_value, false)
|
||||||
|
|
||||||
local r = bonus_gui_pts_needed(player)
|
local r = bonus_gui_pts_needed(player)
|
||||||
element.parent[bonus_gui_control_pts_n_count.name].caption = r
|
element.parent[bonus_gui_control_pts_n_count.name].caption = r
|
||||||
@@ -246,9 +249,9 @@ local bonus_gui_slider =
|
|||||||
local value = bonus.value
|
local value = bonus.value
|
||||||
|
|
||||||
if bonus.is_percentage then
|
if bonus.is_percentage then
|
||||||
value = format_number(value * 100) .. " %"
|
value = format_number(value * 100, false) .. " %"
|
||||||
else
|
else
|
||||||
value = format_number(value)
|
value = format_number(value, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
local slider = parent.add{
|
local slider = parent.add{
|
||||||
@@ -279,9 +282,9 @@ local bonus_gui_slider =
|
|||||||
end)
|
end)
|
||||||
:on_value_changed(function(player, element, _event)
|
:on_value_changed(function(player, element, _event)
|
||||||
if element.tags.is_percentage then
|
if element.tags.is_percentage then
|
||||||
element.parent[element.tags.counter].caption = format_number(element.slider_value * 100) .. " %"
|
element.parent[element.tags.counter].caption = format_number(element.slider_value * 100, false) .. " %"
|
||||||
else
|
else
|
||||||
element.parent[element.tags.counter].caption = format_number(element.slider_value)
|
element.parent[element.tags.counter].caption = format_number(element.slider_value, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
local r = bonus_gui_pts_needed(player)
|
local r = bonus_gui_pts_needed(player)
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ local rawset = rawset
|
|||||||
|
|
||||||
local Public = {}
|
local Public = {}
|
||||||
|
|
||||||
local luaObject = { "{", nil, ", name = '", nil, "'}" }
|
local LuaObject = { "{", nil, ", name = '", nil, "'}" }
|
||||||
local luaPlayer = { "{LuaPlayer, name = '", nil, "', index = ", nil, "}" }
|
local LuaPlayer = { "{LuaPlayer, name = '", nil, "', index = ", nil, "}" }
|
||||||
local luaEntity = { "{LuaEntity, name = '", nil, "', unit_number = ", nil, "}" }
|
local LuaEntity = { "{LuaEntity, name = '", nil, "', unit_number = ", nil, "}" }
|
||||||
local luaGuiElement = { "{LuaGuiElement, name = '", nil, "'}" }
|
local LuaGuiElement = { "{LuaGuiElement, name = '", nil, "'}" }
|
||||||
|
|
||||||
local function get(obj, prop)
|
local function get(obj, prop)
|
||||||
return obj[prop]
|
return obj[prop]
|
||||||
@@ -59,25 +59,25 @@ local function inspect_process(item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if obj_type == "LuaPlayer" then
|
if obj_type == "LuaPlayer" then
|
||||||
luaPlayer[2] = item.name or "nil"
|
LuaPlayer[2] = item.name or "nil"
|
||||||
luaPlayer[4] = item.index or "nil"
|
LuaPlayer[4] = item.index or "nil"
|
||||||
|
|
||||||
return concat(luaPlayer)
|
return concat(LuaPlayer)
|
||||||
elseif obj_type == "LuaEntity" then
|
elseif obj_type == "LuaEntity" then
|
||||||
luaEntity[2] = item.name or "nil"
|
LuaEntity[2] = item.name or "nil"
|
||||||
luaEntity[4] = item.unit_number or "nil"
|
LuaEntity[4] = item.unit_number or "nil"
|
||||||
|
|
||||||
return concat(luaEntity)
|
return concat(LuaEntity)
|
||||||
elseif obj_type == "LuaGuiElement" then
|
elseif obj_type == "LuaGuiElement" then
|
||||||
local name = item.name
|
local name = item.name
|
||||||
luaGuiElement[2] = gui_names and gui_names[name] or name or "nil"
|
LuaGuiElement[2] = gui_names and gui_names[name] or name or "nil"
|
||||||
|
|
||||||
return concat(luaGuiElement)
|
return concat(LuaGuiElement)
|
||||||
else
|
else
|
||||||
luaObject[2] = obj_type
|
LuaObject[2] = obj_type
|
||||||
luaObject[4] = get_name_safe(item)
|
LuaObject[4] = get_name_safe(item)
|
||||||
|
|
||||||
return concat(luaObject)
|
return concat(LuaObject)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ local label_width = {
|
|||||||
local short_time_format = ExpUtil.format_time_factory_locale{ format = "short", coefficient = 3600, hours = true, minutes = true }
|
local short_time_format = ExpUtil.format_time_factory_locale{ format = "short", coefficient = 3600, hours = true, minutes = true }
|
||||||
|
|
||||||
local function format_number_n(n)
|
local function format_number_n(n)
|
||||||
return format_number(math.floor(n)) .. string.format("%.2f", n % 1):sub(2)
|
return format_number(math.floor(n), false) .. string.format("%.2f", n % 1):sub(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local PlayerStats = PlayerData.Statistics
|
local PlayerStats = PlayerData.Statistics
|
||||||
@@ -96,7 +96,7 @@ local pd_data_set =
|
|||||||
for _, stat_name in pairs(PlayerData.Statistics.metadata.display_order) do
|
for _, stat_name in pairs(PlayerData.Statistics.metadata.display_order) do
|
||||||
local child = PlayerData.Statistics[stat_name]
|
local child = PlayerData.Statistics[stat_name]
|
||||||
local metadata = child.metadata
|
local metadata = child.metadata
|
||||||
local value = metadata.stringify_short and metadata.stringify_short(0) or metadata.stringify and metadata.stringify(0) or format_number(0)
|
local value = metadata.stringify_short and metadata.stringify_short(0) or metadata.stringify and metadata.stringify(0) or format_number(0, false)
|
||||||
label(disp, label_width["name"], metadata.name or { "exp-statistics." .. stat_name }, metadata.tooltip or { "exp-statistics." .. stat_name .. "-tooltip" })
|
label(disp, label_width["name"], metadata.name or { "exp-statistics." .. stat_name }, metadata.tooltip or { "exp-statistics." .. stat_name .. "-tooltip" })
|
||||||
label(disp, label_width["count"], { "readme.data-format", value, metadata.unit or "" }, metadata.value_tooltip or { "exp-statistics." .. stat_name .. "-tooltip" }, stat_name)
|
label(disp, label_width["count"], { "readme.data-format", value, metadata.unit or "" }, metadata.value_tooltip or { "exp-statistics." .. stat_name .. "-tooltip" }, stat_name)
|
||||||
end
|
end
|
||||||
@@ -119,7 +119,7 @@ local function pd_update(table, player_name)
|
|||||||
elseif metadata.stringify then
|
elseif metadata.stringify then
|
||||||
value = metadata.stringify(value or 0)
|
value = metadata.stringify(value or 0)
|
||||||
else
|
else
|
||||||
value = format_number(value or 0)
|
value = format_number(value or 0, false)
|
||||||
end
|
end
|
||||||
table[stat_name].caption = { "readme.data-format", value, metadata.unit or "" }
|
table[stat_name].caption = { "readme.data-format", value, metadata.unit or "" }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ define_tab({ "readme.data-tab" }, { "readme.data-tooltip" },
|
|||||||
if metadata.stringify then
|
if metadata.stringify then
|
||||||
value = metadata.stringify(value)
|
value = metadata.stringify(value)
|
||||||
else
|
else
|
||||||
value = format_number(value or 0)
|
value = format_number(value or 0, false)
|
||||||
end
|
end
|
||||||
Gui.centered_label(statistics, 150, metadata.name or { "exp-statistics." .. name }, metadata.tooltip or { "exp-statistics." .. name .. "-tooltip" })
|
Gui.centered_label(statistics, 150, metadata.name or { "exp-statistics." .. name }, metadata.tooltip or { "exp-statistics." .. name .. "-tooltip" })
|
||||||
Gui.centered_label(statistics, 130, { "readme.data-format", value, metadata.unit or "" }, metadata.value_tooltip or { "exp-statistics." .. name .. "-tooltip" })
|
Gui.centered_label(statistics, 130, { "readme.data-format", value, metadata.unit or "" }, metadata.value_tooltip or { "exp-statistics." .. name .. "-tooltip" })
|
||||||
|
|||||||
@@ -144,12 +144,11 @@ local subfooter_frame =
|
|||||||
style = "subfooter_frame",
|
style = "subfooter_frame",
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
):style
|
):style{
|
||||||
{
|
padding = 5,
|
||||||
padding = 5,
|
use_header_filler = false,
|
||||||
use_header_filler = false,
|
horizontally_stretchable = true,
|
||||||
horizontally_stretchable = true,
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
--- Label element preset
|
--- Label element preset
|
||||||
@@ -351,22 +350,21 @@ local task_message_textfield =
|
|||||||
name = Gui.unique_static_name,
|
name = Gui.unique_static_name,
|
||||||
type = "text-box",
|
type = "text-box",
|
||||||
text = "",
|
text = "",
|
||||||
}:style
|
}:style{
|
||||||
{
|
maximal_width = 268,
|
||||||
maximal_width = 268,
|
minimal_height = 100,
|
||||||
minimal_height = 100,
|
horizontally_stretchable = true,
|
||||||
horizontally_stretchable = true,
|
}
|
||||||
}
|
|
||||||
:on_text_changed(
|
:on_text_changed(
|
||||||
function(player, element, _)
|
function(player, element, _)
|
||||||
local isEditing = PlayerIsEditing:get(player)
|
local is_editing = PlayerIsEditing:get(player)
|
||||||
local isCreating = PlayerIsCreating:get(player)
|
local is_creating = PlayerIsCreating:get(player)
|
||||||
|
|
||||||
local valid = string.len(element.text) > 5
|
local valid = string.len(element.text) > 5
|
||||||
|
|
||||||
if isCreating then
|
if is_creating then
|
||||||
element.parent.actions[task_create_confirm_button.name].enabled = valid
|
element.parent.actions[task_create_confirm_button.name].enabled = valid
|
||||||
elseif isEditing then
|
elseif is_editing then
|
||||||
element.parent.actions[task_edit_confirm_button.name].enabled = valid
|
element.parent.actions[task_edit_confirm_button.name].enabled = valid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -676,8 +674,8 @@ PlayerSelected:on_update(
|
|||||||
local task_list_element = frame.container.scroll.task_list
|
local task_list_element = frame.container.scroll.task_list
|
||||||
local view_flow = frame.container.view
|
local view_flow = frame.container.view
|
||||||
local edit_flow = frame.container.edit
|
local edit_flow = frame.container.edit
|
||||||
local isEditing = PlayerIsEditing:get(player)
|
local is_editing = PlayerIsEditing:get(player)
|
||||||
local isCreating = PlayerIsCreating:get(player)
|
local is_creating = PlayerIsCreating:get(player)
|
||||||
|
|
||||||
-- If the selection has an previous state re-enable the button list element
|
-- If the selection has an previous state re-enable the button list element
|
||||||
if prev_state then
|
if prev_state then
|
||||||
@@ -692,12 +690,12 @@ PlayerSelected:on_update(
|
|||||||
update_task_view_footer(player, curr_state)
|
update_task_view_footer(player, curr_state)
|
||||||
|
|
||||||
-- If a player is creating then remove the creation dialogue
|
-- If a player is creating then remove the creation dialogue
|
||||||
if isCreating then
|
if is_creating then
|
||||||
PlayerIsCreating:set(player, false)
|
PlayerIsCreating:set(player, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Depending on if the player is currently editing change the current task edit footer to the current task
|
-- Depending on if the player is currently editing change the current task edit footer to the current task
|
||||||
if isEditing then
|
if is_editing then
|
||||||
update_task_edit_footer(player, curr_state)
|
update_task_edit_footer(player, curr_state)
|
||||||
Tasks.set_editing(prev_state, player.name, nil)
|
Tasks.set_editing(prev_state, player.name, nil)
|
||||||
Tasks.set_editing(curr_state, player.name, true)
|
Tasks.set_editing(curr_state, player.name, true)
|
||||||
@@ -756,8 +754,8 @@ local function role_update_event(event)
|
|||||||
local has_permission = check_player_permissions(player)
|
local has_permission = check_player_permissions(player)
|
||||||
local add_new_task_element = container.header.alignment[add_new_task.name]
|
local add_new_task_element = container.header.alignment[add_new_task.name]
|
||||||
add_new_task_element.visible = has_permission
|
add_new_task_element.visible = has_permission
|
||||||
local isCreating = PlayerIsCreating:get(player)
|
local is_creating = PlayerIsCreating:get(player)
|
||||||
if isCreating and not has_permission then
|
if is_creating and not has_permission then
|
||||||
PlayerIsCreating:set(player, false)
|
PlayerIsCreating:set(player, false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -487,14 +487,14 @@ Event.on_nth_tick(config.update_tick_gui, function(_)
|
|||||||
local vlayer_display = {
|
local vlayer_display = {
|
||||||
[vlayer_gui_display_item_solar_count.name] = {
|
[vlayer_gui_display_item_solar_count.name] = {
|
||||||
val = (items_alloc["solar-panel"] / math.max(items["solar-panel"], 1)),
|
val = (items_alloc["solar-panel"] / math.max(items["solar-panel"], 1)),
|
||||||
cap = format_number(items_alloc["solar-panel"]) .. " / " .. format_number(items["solar-panel"]),
|
cap = format_number(items_alloc["solar-panel"], false) .. " / " .. format_number(items["solar-panel"], false),
|
||||||
},
|
},
|
||||||
[vlayer_gui_display_item_accumulator_count.name] = {
|
[vlayer_gui_display_item_accumulator_count.name] = {
|
||||||
val = (items_alloc["accumulator"] / math.max(items["accumulator"], 1)),
|
val = (items_alloc["accumulator"] / math.max(items["accumulator"], 1)),
|
||||||
cap = format_number(items_alloc["accumulator"]) .. " / " .. format_number(items["accumulator"]),
|
cap = format_number(items_alloc["accumulator"], false) .. " / " .. format_number(items["accumulator"], false),
|
||||||
},
|
},
|
||||||
[vlayer_gui_display_signal_remaining_surface_area_count.name] = {
|
[vlayer_gui_display_signal_remaining_surface_area_count.name] = {
|
||||||
cap = format_number(stats.remaining_surface_area),
|
cap = format_number(stats.remaining_surface_area, false),
|
||||||
},
|
},
|
||||||
[vlayer_gui_display_signal_sustained_count.name] = {
|
[vlayer_gui_display_signal_sustained_count.name] = {
|
||||||
cap = format_energy(stats.energy_sustained, "W"),
|
cap = format_energy(stats.energy_sustained, "W"),
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ local EntityProtection = require("modules.exp_legacy.modules.control.protection"
|
|||||||
local format_string = string.format
|
local format_string = string.format
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
|
|
||||||
local SelectionName_Entity = "ExpCommand_ProtectEntity"
|
local SelectionNameEntity = "ExpCommand_ProtectEntity"
|
||||||
local SelectionName_Area = "ExpCommand_ProtectArea"
|
local SelectionNameArea = "ExpCommand_ProtectArea"
|
||||||
|
|
||||||
local renders = {} --- @type table<number, table<string, LuaRenderObject>> Stores all renders for a player
|
local renders = {} --- @type table<number, table<string, LuaRenderObject>> Stores all renders for a player
|
||||||
Storage.register({
|
Storage.register({
|
||||||
@@ -95,11 +95,11 @@ end
|
|||||||
Commands.new("protect-entity", { "exp-commands_protection.description-entity" })
|
Commands.new("protect-entity", { "exp-commands_protection.description-entity" })
|
||||||
:add_aliases{ "pe" }
|
:add_aliases{ "pe" }
|
||||||
:register(function(player)
|
:register(function(player)
|
||||||
if Selection.is_selecting(player, SelectionName_Entity) then
|
if Selection.is_selecting(player, SelectionNameEntity) then
|
||||||
Selection.stop(player)
|
Selection.stop(player)
|
||||||
return Commands.status.success{ "exp-commands_protection.exit-entity" }
|
return Commands.status.success{ "exp-commands_protection.exit-entity" }
|
||||||
else
|
else
|
||||||
Selection.start(player, SelectionName_Entity)
|
Selection.start(player, SelectionNameEntity)
|
||||||
return Commands.status.success{ "exp-commands_protection.enter-entity" }
|
return Commands.status.success{ "exp-commands_protection.enter-entity" }
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -108,17 +108,17 @@ Commands.new("protect-entity", { "exp-commands_protection.description-entity" })
|
|||||||
Commands.new("protect-area", { "exp-commands_protection.description-area" })
|
Commands.new("protect-area", { "exp-commands_protection.description-area" })
|
||||||
:add_aliases{ "pa" }
|
:add_aliases{ "pa" }
|
||||||
:register(function(player)
|
:register(function(player)
|
||||||
if Selection.is_selecting(player, SelectionName_Entity) then
|
if Selection.is_selecting(player, SelectionNameEntity) then
|
||||||
Selection.stop(player)
|
Selection.stop(player)
|
||||||
return Commands.status.success{ "exp-commands_protection.exit-area" }
|
return Commands.status.success{ "exp-commands_protection.exit-area" }
|
||||||
else
|
else
|
||||||
Selection.start(player, SelectionName_Entity)
|
Selection.start(player, SelectionNameEntity)
|
||||||
return Commands.status.success{ "exp-commands_protection.enter-area" }
|
return Commands.status.success{ "exp-commands_protection.enter-area" }
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- When an area is selected to add protection to entities
|
--- When an area is selected to add protection to entities
|
||||||
Selection.on_selection(SelectionName_Entity, function(event)
|
Selection.on_selection(SelectionNameEntity, function(event)
|
||||||
--- @cast event EventData.on_player_selected_area
|
--- @cast event EventData.on_player_selected_area
|
||||||
local player = game.players[event.player_index]
|
local player = game.players[event.player_index]
|
||||||
for _, entity in ipairs(event.entities) do
|
for _, entity in ipairs(event.entities) do
|
||||||
@@ -130,7 +130,7 @@ Selection.on_selection(SelectionName_Entity, function(event)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
--- When an area is selected to remove protection from entities
|
--- When an area is selected to remove protection from entities
|
||||||
Selection.on_alt_selection(SelectionName_Entity, function(event)
|
Selection.on_alt_selection(SelectionNameEntity, function(event)
|
||||||
--- @cast event EventData.on_player_alt_selected_area
|
--- @cast event EventData.on_player_alt_selected_area
|
||||||
local player = game.players[event.player_index]
|
local player = game.players[event.player_index]
|
||||||
for _, entity in ipairs(event.entities) do
|
for _, entity in ipairs(event.entities) do
|
||||||
@@ -142,7 +142,7 @@ Selection.on_alt_selection(SelectionName_Entity, function(event)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
--- When an area is selected to add protection to the area
|
--- When an area is selected to add protection to the area
|
||||||
Selection.on_selection(SelectionName_Area, function(event)
|
Selection.on_selection(SelectionNameArea, function(event)
|
||||||
--- @cast event EventData.on_player_selected_area
|
--- @cast event EventData.on_player_selected_area
|
||||||
local surface = event.surface
|
local surface = event.surface
|
||||||
local area = expand_area(event.area)
|
local area = expand_area(event.area)
|
||||||
@@ -160,7 +160,7 @@ Selection.on_selection(SelectionName_Area, function(event)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
--- When an area is selected to remove protection from the area
|
--- When an area is selected to remove protection from the area
|
||||||
Selection.on_alt_selection(SelectionName_Area, function(event)
|
Selection.on_alt_selection(SelectionNameArea, function(event)
|
||||||
--- @cast event EventData.on_player_alt_selected_area
|
--- @cast event EventData.on_player_alt_selected_area
|
||||||
local surface = event.surface
|
local surface = event.surface
|
||||||
local area = expand_area(event.area)
|
local area = expand_area(event.area)
|
||||||
@@ -177,7 +177,7 @@ end)
|
|||||||
|
|
||||||
--- When selection starts show all protected entities and protected areas
|
--- When selection starts show all protected entities and protected areas
|
||||||
local function on_player_selection_start(event)
|
local function on_player_selection_start(event)
|
||||||
if event.selection ~= SelectionName_Entity and event.selection ~= SelectionName_Area then return end
|
if event.selection ~= SelectionNameEntity and event.selection ~= SelectionNameArea then return end
|
||||||
local player = game.players[event.player_index]
|
local player = game.players[event.player_index]
|
||||||
local surface = player.surface -- Allow remote view
|
local surface = player.surface -- Allow remote view
|
||||||
renders[player.index] = {}
|
renders[player.index] = {}
|
||||||
@@ -211,7 +211,7 @@ end
|
|||||||
|
|
||||||
--- When selection ends hide protected entities and protected areas
|
--- When selection ends hide protected entities and protected areas
|
||||||
local function on_player_selection_end(event)
|
local function on_player_selection_end(event)
|
||||||
if event.selection ~= SelectionName_Entity and event.selection ~= SelectionName_Area then return end
|
if event.selection ~= SelectionNameEntity and event.selection ~= SelectionNameArea then return end
|
||||||
for _, render in pairs(renders[event.player_index]) do
|
for _, render in pairs(renders[event.player_index]) do
|
||||||
if render.valid then render.destroy() end
|
if render.valid then render.destroy() end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user