1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-16 02:47:48 +02:00

Fixes and tweaks

This commit is contained in:
Gerkiz 2024-03-28 23:37:14 +01:00
parent 84b3f3fdf6
commit dbfcdab321
10 changed files with 100 additions and 75 deletions

View File

@ -12,8 +12,6 @@ require 'maps.mountain_fortress_v3.ic.main'
require 'modules.wave_defense.main'
local Event = require 'utils.event'
local Color = require 'utils.color_presets'
local Core = require 'utils.core'
local Gui = require 'utils.gui'
local Public = require 'maps.mountain_fortress_v3.core'
local Discord = require 'utils.discord'

View File

@ -1,7 +1,7 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local Gui = require 'utils.gui'
local Token = require 'utils.token'
local Task = require 'utils.task_token'
local module_name = Gui.uid_name()
@ -21,6 +21,18 @@ Global.register(
end
)
local call_active_tab_token =
Task.register(
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
Gui.call_existing_tab(player, 'Map Info')
end
)
local Public = {}
function Public.Pop_info()
@ -39,6 +51,10 @@ local function create_map_intro(data)
line.style.top_margin = 4
line.style.bottom_margin = 4
if not map_info.localised_category then
return
end
local caption = map_info.main_caption or {map_info.localised_category .. '.map_info_main_caption'}
local sub_caption = map_info.sub_caption or {map_info.localised_category .. '.map_info_sub_caption'}
local text = map_info.text or {map_info.localised_category .. '.map_info_text'}
@ -86,12 +102,13 @@ local function create_map_intro(data)
l_3.style.vertical_align = 'center'
end
local create_map_intro_token = Token.register(create_map_intro)
local create_map_intro_token = Task.register(create_map_intro)
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if player.online_time == 0 then
Gui.call_existing_tab(player, 'Map Info')
Task.set_timeout_in_ticks(5, call_active_tab_token, {player_index = player.index})
end
end
Event.add(defines.events.on_player_joined_game, on_player_joined_game)

View File

@ -18,7 +18,8 @@ commands.add_command(
end
local param = tostring(cmd.parameter)
if param == nil then
if param == 'nil' then
p('[ERROR] Arguments are:\nskip\toggle_es\toggle_es_boss\nspawn\nnext\nnext_50\nnext_1500\nlog_all\ndebug_health')
return
end

View File

@ -21,15 +21,6 @@ local function valid(userdata)
return true
end
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
local rand = math.random(size)
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
end
local function normalize_spawn_position()
local collapse_spawn_position = Collapse.get_position()
local inverted = Public.get('inverted')
@ -45,43 +36,26 @@ local function normalize_spawn_position()
end
local function find_initial_spot(surface, position)
local spot = Public.get('spot')
if not spot then
local pos = surface.find_non_colliding_position('rocket-silo', position, 128, 1)
if not pos then
pos = surface.find_non_colliding_position('rocket-silo', position, 148, 1)
end
if not pos then
pos = surface.find_non_colliding_position('rocket-silo', position, 164, 1)
end
if not pos then
pos = surface.find_non_colliding_position('rocket-silo', position, 200, 1)
end
if not pos then
pos = position
end
if random(1, 2) == 1 then
local random_pos = {
{x = pos.x - 10, y = pos.y - 5},
{x = pos.x + 10, y = pos.y - 5},
{x = pos.x - 10, y = pos.y - 5},
{x = pos.x + 10, y = pos.y - 5}
}
local actual_pos = shuffle(random_pos)
pos = {x = actual_pos[1].x, y = actual_pos[1].y}
end
if not pos then
pos = position
end
Public.set('spot', pos)
return pos
else
spot = Public.get('spot')
return spot
local pos = surface.find_non_colliding_position('boiler', position, 128, 1)
if not pos then
pos = surface.find_non_colliding_position('boiler', position, 148, 1)
end
if not pos then
pos = surface.find_non_colliding_position('boiler', position, 164, 1)
end
if not pos then
pos = surface.find_non_colliding_position('boiler', position, 200, 1)
end
if not pos then
pos = position
end
if not pos then
pos = position
end
Public.set('spot', pos)
return pos
end
local function is_closer(pos1, pos2, pos)
@ -186,20 +160,14 @@ local function get_spawn_pos()
local initial_position = Public.get('spawn_position')
local target = Public.get('target')
if initial_position.y - target.position.y > 10 then
local inverted = Public.get('inverted')
if inverted then
if random(1, 2) == 1 then
initial_position = {x = initial_position.x, y = initial_position.y + 30}
else
initial_position = {x = initial_position.x, y = initial_position.y + 20}
end
else
if random(1, 2) == 1 then
initial_position = {x = initial_position.x, y = initial_position.y - 30}
else
initial_position = {x = initial_position.x, y = initial_position.y - 20}
end
local inverted = Public.get('inverted')
if inverted then
if initial_position.y - target.position.y < -10 then
initial_position = {x = initial_position.x, y = initial_position.y + 50}
end
else
if initial_position.y - target.position.y > 10 then
initial_position = {x = initial_position.x, y = initial_position.y - 50}
end
end

View File

@ -46,7 +46,7 @@ local this = {
enable_autokick = false,
enable_autoban = false,
enable_jail = true,
enable_capsule_warning = true,
enable_capsule_warning = false,
enable_capsule_cursor_warning = true,
required_playtime = 2592000,
capsule_bomb_threshold = 8,

View File

@ -1,4 +1,5 @@
local DebugView = require 'utils.debug.main_view'
local Server = require 'utils.server'
commands.add_command(
'debug',
@ -14,9 +15,13 @@ commands.add_command(
return
end
-- if (player.name ~= 'Gerkiz' and not _DEBUG) then
-- return
-- end
local secs = Server.get_current_time()
local admins = Server.get_admins_data()
if secs and not admins[player.name] then
player.print('Only admins can use this command.')
return
end
DebugView.open_debug(player)
end

View File

@ -112,7 +112,7 @@ end
---@param message string
function Public.send_notification_raw(scenario_name, message)
if not scenario_name then
return error('A scenario name is required.', 2)
scenario_name = Server.get_server_name() or 'CommandHandler'
end
if not message then

View File

@ -807,13 +807,14 @@ local function draw_main_frame(player)
Public.get_main_frame(player).destroy()
end
local admins = Server.get_admins_data()
local frame, inside_frame = Public.add_main_frame_with_toolbar(player, 'left', main_frame_name, nil, close_button_name, 'Comfy Factorio')
local tabbed_pane = inside_frame.add({type = 'tabbed-pane', name = 'tabbed_pane'})
for name, callback in pairs(tabs) do
if not settings.disabled_tabs[name] then
local secs = Server.get_current_time()
if callback.only_server_sided then
local secs = Server.get_current_time()
if secs then
local tab = tabbed_pane.add({type = 'tab', caption = name, name = callback.name})
local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'})
@ -821,9 +822,15 @@ local function draw_main_frame(player)
end
elseif callback.admin == true then
if player.admin then
local tab = tabbed_pane.add({type = 'tab', caption = name, name = callback.name})
local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'})
tabbed_pane.add_tab(tab, name_frame)
if not secs then
local tab = tabbed_pane.add({type = 'tab', caption = name, name = callback.name})
local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'})
tabbed_pane.add_tab(tab, name_frame)
elseif secs and admins[player.name] then
local tab = tabbed_pane.add({type = 'tab', caption = name, name = callback.name})
local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'})
tabbed_pane.add_tab(tab, name_frame)
end
end
else
local tab = tabbed_pane.add({type = 'tab', caption = name, name = callback.name})

View File

@ -32,6 +32,7 @@ local start_data = {server_id = nil, server_name = nil, start_time = nil}
local instances = {
data = {}
}
local admins = {}
local requests = {}
local jailed_data_set = 'jailed'
local data_set_handlers = {}
@ -43,7 +44,8 @@ Global.register(
server_ups = server_ups,
start_data = start_data,
requests = requests,
instances = instances
instances = instances,
admins = admins
},
function(tbl)
server_time = tbl.server_time
@ -51,6 +53,7 @@ Global.register(
start_data = tbl.start_data
requests = tbl.requests
instances = tbl.instances
admins = tbl.admins
end
)
@ -921,6 +924,22 @@ function Public.try_get_all_data(data_set, callback_token)
output_data(message)
end
local function raise_admins(data)
if not data or not next(data) then
return
end
if admins and next(admins) then
for _, admin in pairs(admins) do
admins[admin] = nil
end
end
for _, admin in pairs(data) do
admins[admin] = true
end
end
local function data_set_changed(data)
local handlers = data_set_handlers[data.data_set]
if handlers == nil then
@ -1037,6 +1056,9 @@ end
--- Called by the web server to notify the client that a data_set has changed.
Public.raise_data_set = data_set_changed
--- Called by the web server to notify the client that a data_set has changed.
Public.raise_admins = raise_admins
--- Called by the web server to notify the client that the subscribed scenario has changed.
Public.raise_scenario_changed = scenario_changed
@ -1178,6 +1200,12 @@ function Public.get_start_data()
return start_data
end
--- Gets the server's admin list. nil if not known.
-- @return table?
function Public.get_admins_data()
return admins
end
--- If the player exists bans the player.
-- Regardless of whether or not the player exists the name is synchronized with other servers
-- and stored in the database.

View File

@ -18,6 +18,7 @@ function ServerCommands.raise_callback(func_token, data)
end
ServerCommands.raise_data_set = Server.raise_data_set
ServerCommands.raise_admins = Server.raise_admins
ServerCommands.get_tracked_data_sets = Server.get_tracked_data_sets
ServerCommands.raise_scenario_changed = Server.raise_scenario_changed