mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Fixed Existing Lua Check Errors
This commit is contained in:
@@ -20,7 +20,7 @@ local time_formats = {
|
||||
}
|
||||
|
||||
--- Check if a player is allowed to use certain interactions
|
||||
local function check_player_permissions(player,action)
|
||||
local function check_player_permissions(player, action)
|
||||
if not config.progress['allow_'..action] then
|
||||
return false
|
||||
end
|
||||
@@ -30,7 +30,7 @@ local function check_player_permissions(player,action)
|
||||
end
|
||||
|
||||
if config.progress[action..'_role_permission']
|
||||
and not Roles.player_allowed(player,config.progress[action..'_role_permission']) then
|
||||
and not Roles.player_allowed(player, config.progress[action..'_role_permission']) then
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -46,7 +46,7 @@ Gui.element{
|
||||
tooltip = {'rocket-info.toggle-rocket-tooltip'}
|
||||
}
|
||||
:style(Gui.sprite_style(16))
|
||||
:on_click(function(_,element,_)
|
||||
:on_click(function(_, element, _)
|
||||
local rocket_silo_name = element.parent.name:sub(8)
|
||||
local rocket_silo = Rockets.get_silo_entity(rocket_silo_name)
|
||||
if rocket_silo.auto_launch then
|
||||
@@ -68,21 +68,21 @@ Gui.element{
|
||||
sprite = 'utility/center',
|
||||
tooltip = {'rocket-info.launch-tooltip'}
|
||||
}
|
||||
:style(Gui.sprite_style(16,-1))
|
||||
:on_click(function(player,element,_)
|
||||
:style(Gui.sprite_style(16, -1))
|
||||
:on_click(function(player, element, _)
|
||||
local rocket_silo_name = element.parent.name:sub(8)
|
||||
local silo_data = Rockets.get_silo_data_by_name(rocket_silo_name)
|
||||
if silo_data.entity.launch_rocket() then
|
||||
element.enabled = false
|
||||
else
|
||||
player.print({'rocket-info.launch-failed'},Colors.orange_red)
|
||||
player.print({'rocket-info.launch-failed'}, Colors.orange_red)
|
||||
end
|
||||
end)
|
||||
|
||||
--- XY cords that allow zoom to map when pressed
|
||||
-- @element silo_cords
|
||||
local silo_cords =
|
||||
Gui.element(function(event_trigger,parent,silo_data)
|
||||
Gui.element(function(event_trigger, parent, silo_data)
|
||||
local silo_name = silo_data.silo_name
|
||||
local pos = silo_data.position
|
||||
local name = config.progress.allow_zoom_to_map and event_trigger or nil
|
||||
@@ -94,13 +94,13 @@ Gui.element(function(event_trigger,parent,silo_data)
|
||||
name = 'label-x-'..silo_name,
|
||||
caption = silo_name
|
||||
}
|
||||
flow_x.style.padding = {0,2,0,1}
|
||||
flow_x.style.padding = {0, 2,0, 1}
|
||||
|
||||
-- Add the x cord label
|
||||
flow_x.add{
|
||||
type = 'label',
|
||||
name = name,
|
||||
caption = {'rocket-info.progress-x-pos',pos.x},
|
||||
caption = {'rocket-info.progress-x-pos', pos.x},
|
||||
tooltip = tooltip
|
||||
}
|
||||
|
||||
@@ -110,32 +110,32 @@ Gui.element(function(event_trigger,parent,silo_data)
|
||||
name = 'label-y-'..silo_name,
|
||||
caption = silo_name
|
||||
}
|
||||
flow_y.style.padding = {0,2,0,1}
|
||||
flow_y.style.padding = {0, 2,0, 1}
|
||||
|
||||
-- Add the y cord label
|
||||
flow_y.add{
|
||||
type = 'label',
|
||||
name = name,
|
||||
caption = {'rocket-info.progress-y-pos',pos.y},
|
||||
caption = {'rocket-info.progress-y-pos', pos.y},
|
||||
tooltip = tooltip
|
||||
}
|
||||
|
||||
end)
|
||||
:on_click(function(player,element,_)
|
||||
:on_click(function(player, element, _)
|
||||
local rocket_silo_name = element.parent.caption
|
||||
local rocket_silo = Rockets.get_silo_entity(rocket_silo_name)
|
||||
player.zoom_to_world(rocket_silo.position,2)
|
||||
player.zoom_to_world(rocket_silo.position, 2)
|
||||
end)
|
||||
|
||||
--- Base element for each rocket in the progress list
|
||||
-- @element rocket_entry
|
||||
local rocket_entry =
|
||||
Gui.element(function(_,parent,silo_data)
|
||||
Gui.element(function(_, parent, silo_data)
|
||||
local silo_name = silo_data.silo_name
|
||||
local player = Gui.get_player_from_element(parent)
|
||||
|
||||
-- Add the toggle auto launch if the player is allowed it
|
||||
if check_player_permissions(player,'toggle_active') then
|
||||
if check_player_permissions(player, 'toggle_active') then
|
||||
local flow = parent.add{ type = 'flow', name = 'toggle-'..silo_name}
|
||||
local button = toggle_launch(flow)
|
||||
button.tooltip = silo_data.toggle_tooltip
|
||||
@@ -143,17 +143,17 @@ Gui.element(function(_,parent,silo_data)
|
||||
end
|
||||
|
||||
-- Add the remote launch if the player is allowed it
|
||||
if check_player_permissions(player,'remote_launch') then
|
||||
if check_player_permissions(player, 'remote_launch') then
|
||||
local flow = parent.add{ type = 'flow', name = 'launch-'..silo_name}
|
||||
local button = launch_rocket(flow)
|
||||
button.enabled = silo_data.allow_launch
|
||||
end
|
||||
|
||||
-- Draw the silo cords element
|
||||
silo_cords(parent,silo_data)
|
||||
silo_cords(parent, silo_data)
|
||||
|
||||
-- Add a progress label
|
||||
local alignment = Gui.alignment(parent,silo_name)
|
||||
local alignment = Gui.alignment(parent, silo_name)
|
||||
local element =
|
||||
alignment.add{
|
||||
type = 'label',
|
||||
@@ -169,7 +169,7 @@ end)
|
||||
--- Data label which contains a name and a value label pair
|
||||
-- @element data_label
|
||||
local data_label =
|
||||
Gui.element(function(_,parent,label_data)
|
||||
Gui.element(function(_, parent, label_data)
|
||||
local data_name = label_data.name
|
||||
local data_subname = label_data.subname
|
||||
local data_fullname = data_subname and data_name..data_subname or data_name
|
||||
@@ -178,13 +178,13 @@ Gui.element(function(_,parent,label_data)
|
||||
local name_label = parent.add{
|
||||
type = 'label',
|
||||
name = data_fullname..'-label',
|
||||
caption = {'rocket-info.data-caption-'..data_name,data_subname},
|
||||
tooltip = {'rocket-info.data-tooltip-'..data_name,data_subname}
|
||||
caption = {'rocket-info.data-caption-'..data_name, data_subname},
|
||||
tooltip = {'rocket-info.data-tooltip-'..data_name, data_subname}
|
||||
}
|
||||
name_label.style.padding = {0,2}
|
||||
name_label.style.padding = {0, 2}
|
||||
|
||||
--- Right aligned label to store the data
|
||||
local alignment = Gui.alignment(parent,data_fullname)
|
||||
local alignment = Gui.alignment(parent, data_fullname)
|
||||
local element =
|
||||
alignment.add{
|
||||
type = 'label',
|
||||
@@ -192,17 +192,17 @@ Gui.element(function(_,parent,label_data)
|
||||
caption = label_data.value,
|
||||
tooltip = label_data.tooltip
|
||||
}
|
||||
element.style.padding = {0,2}
|
||||
element.style.padding = {0, 2}
|
||||
|
||||
return element
|
||||
end)
|
||||
|
||||
-- Used to update the captions and tooltips on the data labels
|
||||
local function update_data_labels(parent,data_label_data)
|
||||
local function update_data_labels(parent, data_label_data)
|
||||
for _, label_data in ipairs(data_label_data) do
|
||||
local data_name = label_data.subname and label_data.name..label_data.subname or label_data.name
|
||||
if not parent[data_name] then
|
||||
data_label(parent,label_data)
|
||||
data_label(parent, label_data)
|
||||
else
|
||||
local data_label_element = parent[data_name].label
|
||||
data_label_element.tooltip = label_data.tooltip
|
||||
@@ -220,7 +220,7 @@ local function get_progress_data(force_name)
|
||||
if not rocket_silo or not rocket_silo.valid then
|
||||
-- Remove from list if not valid
|
||||
force_silos[silo_data.name] = nil
|
||||
table.insert(progress_data,{
|
||||
table.insert(progress_data, {
|
||||
silo_name = silo_data.name,
|
||||
remove = true
|
||||
})
|
||||
@@ -228,14 +228,14 @@ local function get_progress_data(force_name)
|
||||
else
|
||||
-- Get the progress caption and tooltip
|
||||
local progress_color = Colors.white
|
||||
local progress_caption = {'rocket-info.progress-caption',rocket_silo.rocket_parts}
|
||||
local progress_tooltip = {'rocket-info.progress-tooltip',silo_data.launched or 0}
|
||||
local progress_caption = {'rocket-info.progress-caption', rocket_silo.rocket_parts}
|
||||
local progress_tooltip = {'rocket-info.progress-tooltip', silo_data.launched or 0}
|
||||
local status = rocket_silo.status == defines.entity_status.waiting_to_launch_rocket
|
||||
if status and silo_data.awaiting_reset then
|
||||
progress_caption = {'rocket-info.progress-launched'}
|
||||
progress_color = Colors.green
|
||||
elseif status then
|
||||
progress_caption = {'rocket-info.progress-caption',100}
|
||||
progress_caption = {'rocket-info.progress-caption', 100}
|
||||
progress_color = Colors.cyan
|
||||
else
|
||||
silo_data.awaiting_reset = false
|
||||
@@ -250,7 +250,7 @@ local function get_progress_data(force_name)
|
||||
end
|
||||
|
||||
-- Insert the gui data
|
||||
table.insert(progress_data,{
|
||||
table.insert(progress_data, {
|
||||
silo_name = silo_data.name,
|
||||
position = rocket_silo.position,
|
||||
allow_launch = not silo_data.awaiting_reset and status or false,
|
||||
@@ -267,7 +267,7 @@ local function get_progress_data(force_name)
|
||||
end
|
||||
|
||||
--- Update the build progress section
|
||||
local function update_build_progress(parent,progress_data)
|
||||
local function update_build_progress(parent, progress_data)
|
||||
local show_message = true
|
||||
for _, silo_data in ipairs(progress_data) do
|
||||
parent.parent.no_silos.visible = false
|
||||
@@ -285,7 +285,7 @@ local function update_build_progress(parent,progress_data)
|
||||
elseif not progress_label then
|
||||
-- Add the rocket to the list
|
||||
show_message = false
|
||||
rocket_entry(parent,silo_data)
|
||||
rocket_entry(parent, silo_data)
|
||||
|
||||
else
|
||||
show_message = false
|
||||
@@ -323,7 +323,7 @@ local function get_stats_data(force_name)
|
||||
-- Format the first launch data
|
||||
if config.stats.show_first_rocket then
|
||||
local value = stats.first_launch or 0
|
||||
table.insert(stats_data,{
|
||||
table.insert(stats_data, {
|
||||
name = 'first-launch',
|
||||
value = time_formats.caption_hours(value),
|
||||
tooltip = time_formats.tooltip_hours(value)
|
||||
@@ -333,7 +333,7 @@ local function get_stats_data(force_name)
|
||||
-- Format the last launch data
|
||||
if config.stats.show_last_rocket then
|
||||
local value = stats.last_launch or 0
|
||||
table.insert(stats_data,{
|
||||
table.insert(stats_data, {
|
||||
name = 'last-launch',
|
||||
value = time_formats.caption_hours(value),
|
||||
tooltip = time_formats.tooltip_hours(value)
|
||||
@@ -343,7 +343,7 @@ local function get_stats_data(force_name)
|
||||
-- Format fastest launch data
|
||||
if config.stats.show_fastest_rocket then
|
||||
local value = stats.fastest_launch or 0
|
||||
table.insert(stats_data,{
|
||||
table.insert(stats_data, {
|
||||
name = 'fastest-launch',
|
||||
value = time_formats.caption_hours(value),
|
||||
tooltip = time_formats.tooltip_hours(value)
|
||||
@@ -354,18 +354,18 @@ local function get_stats_data(force_name)
|
||||
if config.stats.show_total_rockets then
|
||||
local total_rockets = Rockets.get_game_rocket_count()
|
||||
total_rockets = total_rockets == 0 and 1 or total_rockets
|
||||
local percentage = math.round(force_rockets/total_rockets,3)*100
|
||||
table.insert(stats_data,{
|
||||
local percentage = math.round(force_rockets/total_rockets, 3)*100
|
||||
table.insert(stats_data, {
|
||||
name = 'total-rockets',
|
||||
value = force_rockets,
|
||||
tooltip = {'rocket-info.value-tooltip-total-rockets',percentage}
|
||||
tooltip = {'rocket-info.value-tooltip-total-rockets', percentage}
|
||||
})
|
||||
end
|
||||
|
||||
-- Format game avg data
|
||||
if config.stats.show_game_avg then
|
||||
local avg = force_rockets > 0 and math.floor(game.tick/force_rockets) or 0
|
||||
table.insert(stats_data,{
|
||||
table.insert(stats_data, {
|
||||
name = 'avg-launch',
|
||||
value = time_formats.caption(avg),
|
||||
tooltip = time_formats.tooltip(avg)
|
||||
@@ -373,9 +373,9 @@ local function get_stats_data(force_name)
|
||||
end
|
||||
|
||||
-- Format rolling avg data
|
||||
for _,avg_over in pairs(config.stats.rolling_avg) do
|
||||
local avg = Rockets.get_rolling_average(force_name,avg_over)
|
||||
table.insert(stats_data,{
|
||||
for _, avg_over in pairs(config.stats.rolling_avg) do
|
||||
local avg = Rockets.get_rolling_average(force_name, avg_over)
|
||||
table.insert(stats_data, {
|
||||
name = 'avg-launch-n',
|
||||
subname = avg_over,
|
||||
value = time_formats.caption(avg),
|
||||
@@ -392,17 +392,17 @@ local function get_milestone_data(force_name)
|
||||
local force_rockets = Rockets.get_rocket_count(force_name)
|
||||
local milestone_data = {}
|
||||
|
||||
for _,milestone in ipairs(config.milestones) do
|
||||
for _, milestone in ipairs(config.milestones) do
|
||||
if milestone <= force_rockets then
|
||||
local time = Rockets.get_rocket_time(force_name,milestone)
|
||||
table.insert(milestone_data,{
|
||||
local time = Rockets.get_rocket_time(force_name, milestone)
|
||||
table.insert(milestone_data, {
|
||||
name = 'milestone-n',
|
||||
subname = milestone,
|
||||
value = time_formats.caption_hours(time),
|
||||
tooltip = time_formats.tooltip_hours(time)
|
||||
})
|
||||
else
|
||||
table.insert(milestone_data,{
|
||||
table.insert(milestone_data, {
|
||||
name = 'milestone-n',
|
||||
subname = milestone,
|
||||
value = {'rocket-info.data-caption-milestone-next'},
|
||||
@@ -425,7 +425,7 @@ Gui.element{
|
||||
tooltip = {'rocket-info.toggle-section-tooltip'}
|
||||
}
|
||||
:style(Gui.sprite_style(20))
|
||||
:on_click(function(_,element,_)
|
||||
:on_click(function(_, element, _)
|
||||
local header_flow = element.parent
|
||||
local flow_name = header_flow.caption
|
||||
local flow = header_flow.parent.parent[flow_name]
|
||||
@@ -443,7 +443,7 @@ end)
|
||||
-- Draw a section header and main scroll
|
||||
-- @element rocket_list_container
|
||||
local section =
|
||||
Gui.element(function(_,parent,section_name,table_size)
|
||||
Gui.element(function(_, parent, section_name, table_size)
|
||||
-- Draw the header for the section
|
||||
local header = Gui.header(
|
||||
parent,
|
||||
@@ -458,7 +458,7 @@ Gui.element(function(_,parent,section_name,table_size)
|
||||
toggle_section(header)
|
||||
|
||||
-- Table used to store the data
|
||||
local scroll_table = Gui.scroll_table(parent,215,table_size,section_name)
|
||||
local scroll_table = Gui.scroll_table(parent, 215, table_size, section_name)
|
||||
scroll_table.parent.visible = false
|
||||
|
||||
-- Return the flow table
|
||||
@@ -468,9 +468,9 @@ end)
|
||||
--- Main gui container for the left flow
|
||||
-- @element rocket_list_container
|
||||
local rocket_list_container =
|
||||
Gui.element(function(event_trigger,parent)
|
||||
Gui.element(function(event_trigger, parent)
|
||||
-- Draw the internal container
|
||||
local container = Gui.container(parent,event_trigger,200)
|
||||
local container = Gui.container(parent, event_trigger, 200)
|
||||
|
||||
-- Set the container style
|
||||
local style = container.style
|
||||
@@ -480,27 +480,27 @@ Gui.element(function(event_trigger,parent)
|
||||
local force_name = player.force.name
|
||||
-- Draw stats section
|
||||
if config.stats.show_stats then
|
||||
update_data_labels(section(container,'stats',2),get_stats_data(force_name))
|
||||
update_data_labels(section(container, 'stats', 2), get_stats_data(force_name))
|
||||
end
|
||||
|
||||
-- Draw milestones section
|
||||
if config.milestones.show_milestones then
|
||||
update_data_labels(section(container,'milestones',2),get_milestone_data(force_name))
|
||||
update_data_labels(section(container, 'milestones', 2), get_milestone_data(force_name))
|
||||
end
|
||||
|
||||
-- Draw build progress list
|
||||
if config.progress.show_progress then
|
||||
local col_count = 3
|
||||
if check_player_permissions(player,'remote_launch') then col_count = col_count+1 end
|
||||
if check_player_permissions(player,'toggle_active') then col_count = col_count+1 end
|
||||
local progress = section(container,'progress',col_count)
|
||||
if check_player_permissions(player, 'remote_launch') then col_count = col_count+1 end
|
||||
if check_player_permissions(player, 'toggle_active') then col_count = col_count+1 end
|
||||
local progress = section(container, 'progress', col_count)
|
||||
-- Label used when there are no active silos
|
||||
local no_silos = progress.parent.add{
|
||||
type = 'label',
|
||||
name = 'no_silos',
|
||||
caption = {'rocket-info.progress-no-silos'}
|
||||
}
|
||||
no_silos.style.padding = {1,2}
|
||||
no_silos.style.padding = {1, 2}
|
||||
update_build_progress(progress, get_progress_data(force_name))
|
||||
end
|
||||
|
||||
@@ -508,13 +508,13 @@ Gui.element(function(event_trigger,parent)
|
||||
return container.parent
|
||||
end)
|
||||
:add_to_left_flow(function(player)
|
||||
return player.force.rockets_launched > 0 and Roles.player_allowed(player,'gui/rocket-info')
|
||||
return player.force.rockets_launched > 0 and Roles.player_allowed(player, 'gui/rocket-info')
|
||||
end)
|
||||
|
||||
--- Button on the top flow used to toggle the container
|
||||
-- @element toggle_left_element
|
||||
Gui.left_toolbar_button('entity/rocket-silo', {'rocket-info.main-tooltip'}, rocket_list_container, function(player)
|
||||
return Roles.player_allowed(player,'gui/rocket-info')
|
||||
return Roles.player_allowed(player, 'gui/rocket-info')
|
||||
end)
|
||||
|
||||
--- Update the gui for all players on a force
|
||||
@@ -522,21 +522,21 @@ local function update_rocket_gui_all(force_name)
|
||||
local stats = get_stats_data(force_name)
|
||||
local milestones = get_milestone_data(force_name)
|
||||
local progress = get_progress_data(force_name)
|
||||
for _,player in pairs(game.forces[force_name].players) do
|
||||
local frame = Gui.get_left_element(player,rocket_list_container)
|
||||
for _, player in pairs(game.forces[force_name].players) do
|
||||
local frame = Gui.get_left_element(player, rocket_list_container)
|
||||
local container = frame.container
|
||||
update_data_labels(container.stats.table,stats)
|
||||
update_data_labels(container.milestones.table,milestones)
|
||||
update_build_progress(container.progress.table,progress)
|
||||
update_data_labels(container.stats.table, stats)
|
||||
update_data_labels(container.milestones.table, milestones)
|
||||
update_build_progress(container.progress.table, progress)
|
||||
end
|
||||
end
|
||||
|
||||
--- Event used to update the stats when a rocket is launched
|
||||
Event.add(defines.events.on_rocket_launched,function(event)
|
||||
Event.add(defines.events.on_rocket_launched, function(event)
|
||||
local force = event.rocket_silo.force
|
||||
update_rocket_gui_all(force.name)
|
||||
if force.rockets_launched == 1 then
|
||||
for _,player in pairs(force.players) do
|
||||
for _, player in pairs(force.players) do
|
||||
Gui.update_top_flow(player)
|
||||
end
|
||||
end
|
||||
@@ -545,23 +545,23 @@ end)
|
||||
--- Update only the progress gui for a force
|
||||
local function update_rocket_gui_progress(force_name)
|
||||
local progress = get_progress_data(force_name)
|
||||
for _,player in pairs(game.forces[force_name].players) do
|
||||
local frame = Gui.get_left_element(player,rocket_list_container)
|
||||
for _, player in pairs(game.forces[force_name].players) do
|
||||
local frame = Gui.get_left_element(player, rocket_list_container)
|
||||
local container = frame.container
|
||||
update_build_progress(container.progress.table,progress)
|
||||
update_build_progress(container.progress.table, progress)
|
||||
end
|
||||
end
|
||||
|
||||
--- Event used to set a rocket silo to be awaiting reset
|
||||
Event.add(defines.events.on_rocket_launch_ordered,function(event)
|
||||
Event.add(defines.events.on_rocket_launch_ordered, function(event)
|
||||
local silo = event.rocket_silo
|
||||
local silo_data = Rockets.get_silo_data(silo)
|
||||
silo_data.awaiting_reset = true
|
||||
update_rocket_gui_progress(silo.force.name)
|
||||
end)
|
||||
|
||||
Event.on_nth_tick(150,function()
|
||||
for _,force in pairs(game.forces) do
|
||||
Event.on_nth_tick(150, function()
|
||||
for _, force in pairs(game.forces) do
|
||||
if #Rockets.get_silos(force.name) > 0 then
|
||||
update_rocket_gui_progress(force.name)
|
||||
end
|
||||
@@ -576,20 +576,20 @@ local function on_built(event)
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_built_entity,on_built)
|
||||
Event.add(defines.events.on_robot_built_entity,on_built)
|
||||
Event.add(defines.events.on_built_entity, on_built)
|
||||
Event.add(defines.events.on_robot_built_entity, on_built)
|
||||
|
||||
--- Redraw the progress section on role change
|
||||
local function role_update_event(event)
|
||||
if not config.progress.show_progress then return end
|
||||
local player = game.players[event.player_index]
|
||||
local container = Gui.get_left_element(player,rocket_list_container).container
|
||||
local container = Gui.get_left_element(player, rocket_list_container).container
|
||||
local progress_scroll = container.progress
|
||||
Gui.destroy_if_valid(progress_scroll.table)
|
||||
|
||||
local col_count = 3
|
||||
if check_player_permissions(player,'remote_launch') then col_count = col_count+1 end
|
||||
if check_player_permissions(player,'toggle_active') then col_count = col_count+1 end
|
||||
if check_player_permissions(player, 'remote_launch') then col_count = col_count+1 end
|
||||
if check_player_permissions(player, 'toggle_active') then col_count = col_count+1 end
|
||||
local progress = progress_scroll.add{
|
||||
type = 'table',
|
||||
name = 'table',
|
||||
@@ -599,7 +599,7 @@ local function role_update_event(event)
|
||||
update_build_progress(progress, get_progress_data(player.force.name))
|
||||
end
|
||||
|
||||
Event.add(Roles.events.on_role_assigned,role_update_event)
|
||||
Event.add(Roles.events.on_role_unassigned,role_update_event)
|
||||
Event.add(Roles.events.on_role_assigned, role_update_event)
|
||||
Event.add(Roles.events.on_role_unassigned, role_update_event)
|
||||
|
||||
return rocket_list_container
|
||||
Reference in New Issue
Block a user