mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-08 00:39:30 +02:00
Merge pull request #42 from ComfyFactory/remove_ups_heavy_functions
Removal of global variables and removed laggy functions
This commit is contained in:
commit
249246ddba
@ -1,6 +1,5 @@
|
||||
-- config tab --
|
||||
|
||||
local Antigrief = require 'antigrief'
|
||||
local Event = require 'utils.event'
|
||||
local Color = require 'utils.color_presets'
|
||||
local SessionData = require 'utils.datastore.session_data'
|
||||
local Utils = require 'utils.core'
|
||||
@ -8,9 +7,24 @@ local Tabs = require 'comfy_panel.main'
|
||||
local SpamProtection = require 'utils.spam_protection'
|
||||
local BottomFrame = require 'comfy_panel.bottom_frame'
|
||||
local Token = require 'utils.token'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local module_name = 'Config'
|
||||
|
||||
local this = {
|
||||
gui_config = {
|
||||
spaghett = {},
|
||||
poll_trusted = false
|
||||
}
|
||||
}
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
function(tbl)
|
||||
this = tbl
|
||||
end
|
||||
)
|
||||
|
||||
local spaghett_entity_blacklist = {
|
||||
['logistic-chest-requester'] = true,
|
||||
['logistic-chest-buffer'] = true,
|
||||
@ -30,7 +44,7 @@ local function get_actor(event, prefix, msg, admins_only)
|
||||
end
|
||||
|
||||
local function spaghett_deny_building(event)
|
||||
local spaghett = global.comfy_panel_config.spaghett
|
||||
local spaghett = this.gui_config.spaghett
|
||||
if not spaghett.enabled then
|
||||
return
|
||||
end
|
||||
@ -62,7 +76,7 @@ local function spaghett_deny_building(event)
|
||||
end
|
||||
|
||||
local function spaghett()
|
||||
local spaghetti = global.comfy_panel_config.spaghett
|
||||
local spaghetti = this.gui_config.spaghett
|
||||
if spaghetti.enabled then
|
||||
for _, f in pairs(game.forces) do
|
||||
if f.technologies['logistic-system'].researched then
|
||||
@ -139,10 +153,10 @@ local functions = {
|
||||
end,
|
||||
['comfy_panel_spaghett_toggle'] = function(event)
|
||||
if event.element.switch_state == 'left' then
|
||||
global.comfy_panel_config.spaghett.enabled = true
|
||||
this.gui_config.spaghett.enabled = true
|
||||
get_actor(event, '{Spaghett}', 'has enabled spaghett mode!')
|
||||
else
|
||||
global.comfy_panel_config.spaghett.enabled = nil
|
||||
this.gui_config.spaghett.enabled = nil
|
||||
get_actor(event, '{Spaghett}', 'has disabled spaghett mode!')
|
||||
end
|
||||
spaghett()
|
||||
@ -171,10 +185,10 @@ local functions = {
|
||||
local poll_function = {
|
||||
['comfy_panel_poll_trusted_toggle'] = function(event)
|
||||
if event.element.switch_state == 'left' then
|
||||
global.comfy_panel_config.poll_trusted = true
|
||||
this.gui_config.poll_trusted = true
|
||||
get_actor(event, '{Poll Mode}', 'has disabled non-trusted people to do polls.')
|
||||
else
|
||||
global.comfy_panel_config.poll_trusted = false
|
||||
this.gui_config.poll_trusted = false
|
||||
get_actor(event, '{Poll Mode}', 'has allowed non-trusted people to do polls.')
|
||||
end
|
||||
end,
|
||||
@ -206,67 +220,67 @@ local antigrief_functions = {
|
||||
local fortress_functions = {
|
||||
['comfy_panel_disable_fullness'] = function(event)
|
||||
local Fullness = is_loaded('modules.check_fullness')
|
||||
local this = Fullness.get()
|
||||
local Module = Fullness.get()
|
||||
if event.element.switch_state == 'left' then
|
||||
this.fullness_enabled = true
|
||||
Module.fullness_enabled = true
|
||||
get_actor(event, '{Fullness}', 'has enabled the inventory fullness function.')
|
||||
else
|
||||
this.fullness_enabled = false
|
||||
Module.fullness_enabled = false
|
||||
get_actor(event, '{Fullness}', 'has disabled the inventory fullness function.')
|
||||
end
|
||||
end,
|
||||
['comfy_panel_offline_players'] = function(event)
|
||||
local WPT = is_loaded('maps.mountain_fortress_v3.table')
|
||||
local this = WPT.get()
|
||||
local Module = WPT.get()
|
||||
if event.element.switch_state == 'left' then
|
||||
this.offline_players_enabled = true
|
||||
Module.offline_players_enabled = true
|
||||
get_actor(event, '{Offline Players}', 'has enabled the offline player function.')
|
||||
else
|
||||
this.offline_players_enabled = false
|
||||
Module.offline_players_enabled = false
|
||||
get_actor(event, '{Offline Players}', 'has disabled the offline player function.')
|
||||
end
|
||||
end,
|
||||
['comfy_panel_collapse_grace'] = function(event)
|
||||
local WPT = is_loaded('maps.mountain_fortress_v3.table')
|
||||
local this = WPT.get()
|
||||
local Module = WPT.get()
|
||||
if event.element.switch_state == 'left' then
|
||||
this.collapse_grace = true
|
||||
Module.collapse_grace = true
|
||||
get_actor(event, '{Collapse}', 'has enabled the collapse function. Collapse will occur after wave 100!')
|
||||
else
|
||||
this.collapse_grace = false
|
||||
Module.collapse_grace = false
|
||||
get_actor(event, '{Collapse}', 'has disabled the collapse function. You must reach zone 2 for collapse to occur!')
|
||||
end
|
||||
end,
|
||||
['comfy_panel_spill_items_to_surface'] = function(event)
|
||||
local WPT = is_loaded('maps.mountain_fortress_v3.table')
|
||||
local this = WPT.get()
|
||||
local Module = WPT.get()
|
||||
if event.element.switch_state == 'left' then
|
||||
this.spill_items_to_surface = true
|
||||
Module.spill_items_to_surface = true
|
||||
get_actor(event, '{Item Spill}', 'has enabled the ore spillage function. Ores now drop to surface when mining.')
|
||||
else
|
||||
this.spill_items_to_surface = false
|
||||
Module.spill_items_to_surface = false
|
||||
get_actor(event, '{Item Spill}', 'has disabled the item spillage function. Ores no longer drop to surface when mining.')
|
||||
end
|
||||
end,
|
||||
['comfy_panel_void_or_tile'] = function(event)
|
||||
local WPT = is_loaded('maps.mountain_fortress_v3.table')
|
||||
local this = WPT.get()
|
||||
local Module = WPT.get()
|
||||
if event.element.switch_state == 'left' then
|
||||
this.void_or_tile = 'out-of-map'
|
||||
Module.void_or_tile = 'out-of-map'
|
||||
get_actor(event, '{Void}', 'has changes the tiles of the zones to: out-of-map (void)')
|
||||
else
|
||||
this.void_or_tile = 'lab-dark-2'
|
||||
Module.void_or_tile = 'lab-dark-2'
|
||||
get_actor(event, '{Void}', 'has changes the tiles of the zones to: dark-tiles (flammable tiles)')
|
||||
end
|
||||
end,
|
||||
['comfy_panel_trusted_only_car_tanks'] = function(event)
|
||||
local WPT = is_loaded('maps.mountain_fortress_v3.table')
|
||||
local this = WPT.get()
|
||||
local Module = WPT.get()
|
||||
if event.element.switch_state == 'left' then
|
||||
this.trusted_only_car_tanks = true
|
||||
Module.trusted_only_car_tanks = true
|
||||
get_actor(event, '{Market}', 'has changed so only trusted people can buy car/tanks.', true)
|
||||
else
|
||||
this.trusted_only_car_tanks = false
|
||||
Module.trusted_only_car_tanks = false
|
||||
get_actor(event, '{Market}', 'has changed so everybody can buy car/tanks.', true)
|
||||
end
|
||||
end
|
||||
@ -407,7 +421,7 @@ local function build_config_gui(data)
|
||||
scroll_pane.add({type = 'line'})
|
||||
|
||||
switch_state = 'right'
|
||||
if global.comfy_panel_config.spaghett.enabled then
|
||||
if this.gui_config.spaghett.enabled then
|
||||
switch_state = 'left'
|
||||
end
|
||||
add_switch(
|
||||
@ -421,7 +435,7 @@ local function build_config_gui(data)
|
||||
if poll then
|
||||
scroll_pane.add({type = 'line'})
|
||||
switch_state = 'right'
|
||||
if global.comfy_panel_config.poll_trusted then
|
||||
if this.gui_config.poll_trusted then
|
||||
switch_state = 'left'
|
||||
end
|
||||
add_switch(scroll_pane, switch_state, 'comfy_panel_poll_trusted_toggle', 'Poll mode', 'Disables non-trusted plebs to create polls.')
|
||||
@ -442,7 +456,7 @@ local function build_config_gui(data)
|
||||
if AG.enabled then
|
||||
switch_state = 'left'
|
||||
end
|
||||
add_switch(scroll_pane, switch_state, 'comfy_panel_disable_antigrief', 'Antigrief', 'Left = Enables antigrief / Right = Disables antigrief')
|
||||
add_switch(scroll_pane, switch_state, 'comfy_panel_disable_antigrief', 'Antigrief', 'Toggle antigrief function.')
|
||||
scroll_pane.add({type = 'line'})
|
||||
|
||||
if is_loaded('maps.biter_battles_v2.main') then
|
||||
@ -515,9 +529,9 @@ local function build_config_gui(data)
|
||||
scroll_pane.add({type = 'line'})
|
||||
|
||||
local WPT = is_loaded('maps.mountain_fortress_v3.table')
|
||||
local this = WPT.get()
|
||||
local Module = WPT.get()
|
||||
switch_state = 'right'
|
||||
if this.offline_players_enabled then
|
||||
if Module.offline_players_enabled then
|
||||
switch_state = 'left'
|
||||
end
|
||||
add_switch(
|
||||
@ -531,7 +545,7 @@ local function build_config_gui(data)
|
||||
scroll_pane.add({type = 'line'})
|
||||
|
||||
switch_state = 'right'
|
||||
if this.collapse_grace then
|
||||
if Module.collapse_grace then
|
||||
switch_state = 'left'
|
||||
end
|
||||
add_switch(
|
||||
@ -545,7 +559,7 @@ local function build_config_gui(data)
|
||||
scroll_pane.add({type = 'line'})
|
||||
|
||||
switch_state = 'right'
|
||||
if this.spill_items_to_surface then
|
||||
if Module.spill_items_to_surface then
|
||||
switch_state = 'left'
|
||||
end
|
||||
add_switch(
|
||||
@ -558,14 +572,14 @@ local function build_config_gui(data)
|
||||
scroll_pane.add({type = 'line'})
|
||||
|
||||
switch_state = 'right'
|
||||
if this.void_or_tile then
|
||||
if Module.void_or_tile then
|
||||
switch_state = 'left'
|
||||
end
|
||||
add_switch(scroll_pane, switch_state, 'comfy_panel_void_or_tile', 'Void Tiles', 'Left = Changes the tiles to out-of-map.\nRight = Changes the tiles to lab-dark-2')
|
||||
scroll_pane.add({type = 'line'})
|
||||
|
||||
switch_state = 'right'
|
||||
if this.trusted_only_car_tanks then
|
||||
if Module.trusted_only_car_tanks then
|
||||
switch_state = 'left'
|
||||
end
|
||||
add_switch(
|
||||
@ -646,18 +660,8 @@ local function on_robot_built_entity(event)
|
||||
spaghett_deny_building(event)
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
global.comfy_panel_config = {}
|
||||
global.comfy_panel_config.spaghett = {}
|
||||
global.comfy_panel_config.spaghett.undo = {}
|
||||
global.comfy_panel_config.poll_trusted = false
|
||||
global.comfy_panel_disable_antigrief = false
|
||||
end
|
||||
|
||||
Tabs.add_tab_to_gui({name = module_name, id = build_config_gui_token, admin = false})
|
||||
|
||||
local Event = require 'utils.event'
|
||||
Event.on_init(on_init)
|
||||
Event.add(defines.events.on_gui_switch_state_changed, on_gui_switch_state_changed)
|
||||
Event.add(defines.events.on_force_created, on_force_created)
|
||||
Event.add(defines.events.on_built_entity, on_built_entity)
|
||||
|
@ -143,15 +143,6 @@ local function add_global_stats(frame, player)
|
||||
killcount_label.style.font = 'default-listbox'
|
||||
killcount_label.style.font_color = {r = 0.9, g = 0.9, b = 0.9}
|
||||
killcount_label.style.minimal_width = 145
|
||||
|
||||
local floatingScore_label =
|
||||
t.add {
|
||||
type = 'checkbox',
|
||||
caption = 'Show floating numbers',
|
||||
state = global.show_floating_killscore[player.name],
|
||||
name = 'show_floating_killscore_texts'
|
||||
}
|
||||
floatingScore_label.style.font_color = {r = 0.8, g = 0.8, b = 0.8}
|
||||
end
|
||||
|
||||
local function show_score(data)
|
||||
@ -277,12 +268,6 @@ local function on_player_joined_game(event)
|
||||
if not this.sort_by[player.name] then
|
||||
this.sort_by[player.name] = {method = 'descending', column = 'killscore'}
|
||||
end
|
||||
if not global.show_floating_killscore then
|
||||
global.show_floating_killscore = {}
|
||||
end
|
||||
if not global.show_floating_killscore[player.name] then
|
||||
global.show_floating_killscore[player.name] = false
|
||||
end
|
||||
end
|
||||
|
||||
local function on_gui_click(event)
|
||||
@ -313,12 +298,6 @@ local function on_gui_click(event)
|
||||
return
|
||||
end
|
||||
|
||||
-- Handles click on the checkbox, for floating score
|
||||
if name == 'show_floating_killscore_texts' then
|
||||
global.show_floating_killscore[player.name] = element.state
|
||||
return
|
||||
end
|
||||
|
||||
-- Handles click on a score header
|
||||
local element_to_column = {
|
||||
['score_killscore'] = 'killscore',
|
||||
@ -445,16 +424,6 @@ local function on_entity_died(event)
|
||||
Public.init_player_table(player)
|
||||
local score = this.score_table[player.force.name].players[player.name]
|
||||
score.killscore = score.killscore + entity_score_values[event.entity.name]
|
||||
if global.show_floating_killscore[player.name] then
|
||||
event.entity.surface.create_entity(
|
||||
{
|
||||
name = 'flying-text',
|
||||
position = event.entity.position,
|
||||
text = tostring(entity_score_values[event.entity.name]),
|
||||
color = player.chat_color
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1127,10 +1127,6 @@ local on_player_joined_game = function(event)
|
||||
for item, amount in pairs(starting_items) do
|
||||
player.insert({name = item, count = amount})
|
||||
end
|
||||
|
||||
if global.show_floating_killscore then
|
||||
global.show_floating_killscore[player.name] = false
|
||||
end
|
||||
end
|
||||
|
||||
local spawn = player.force.get_spawn_position(surface)
|
||||
|
@ -19,10 +19,6 @@ local function on_player_joined_game(event)
|
||||
pos = player.character.surface.find_non_colliding_position('character', {0, -40}, 50, 1)
|
||||
game.forces.player.set_spawn_position(pos, player.character.surface)
|
||||
player.teleport(pos, player.character.surface)
|
||||
|
||||
if global.show_floating_killscore then
|
||||
global.show_floating_killscore[player.name] = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -994,7 +994,6 @@ end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
local show_floating_killscore = FDT.get('show_floating_killscore')
|
||||
local active_surface_index = FDT.get('active_surface_index')
|
||||
|
||||
if player.online_time == 0 then
|
||||
@ -1003,9 +1002,6 @@ local function on_player_joined_game(event)
|
||||
player.insert({name = 'raw-fish', count = 3})
|
||||
player.insert({name = 'firearm-magazine', count = 16})
|
||||
player.insert({name = 'iron-plate', count = 32})
|
||||
if show_floating_killscore then
|
||||
FDT.get().show_floating_killscore[player.name] = false
|
||||
end
|
||||
end
|
||||
|
||||
local surface = game.surfaces[active_surface_index]
|
||||
|
@ -50,7 +50,6 @@ function Public.reset_table()
|
||||
this.wave_grace_period = game.tick + 3600 * 20
|
||||
this.boss_biters = {}
|
||||
this.acid_lines_delay = {}
|
||||
this.show_floating_killscore = {}
|
||||
this.entity_limits = {
|
||||
['gun-turret'] = {placed = 1, limit = 1, str = 'gun turret', slot_price = 75},
|
||||
['laser-turret'] = {placed = 0, limit = 1, str = 'laser turret', slot_price = 300},
|
||||
|
@ -1158,13 +1158,9 @@ local function on_player_joined_game(event)
|
||||
|
||||
if player.online_time < 1 then
|
||||
player.insert({name = 'pistol', count = 1})
|
||||
--player.insert({name = "iron-axe", count = 1})
|
||||
player.insert({name = 'raw-fish', count = 3})
|
||||
player.insert({name = 'firearm-magazine', count = 16})
|
||||
player.insert({name = 'iron-plate', count = 32})
|
||||
if global.show_floating_killscore then
|
||||
global.show_floating_killscore[player.name] = false
|
||||
end
|
||||
end
|
||||
|
||||
local surface = game.surfaces['fish_defender']
|
||||
|
@ -1037,10 +1037,6 @@ local function on_player_joined_game(event)
|
||||
for item, amount in pairs(starting_items) do
|
||||
player.insert({name = item, count = amount})
|
||||
end
|
||||
|
||||
if global.show_floating_killscore then
|
||||
global.show_floating_killscore[player.name] = false
|
||||
end
|
||||
end
|
||||
|
||||
local spawn = player.force.get_spawn_position(surface)
|
||||
|
@ -159,9 +159,6 @@ local function on_player_joined_game(event)
|
||||
player.insert({name = 'raw-fish', count = 3})
|
||||
player.insert({name = 'firearm-magazine', count = 16})
|
||||
player.insert({name = 'iron-plate', count = 32})
|
||||
if global.show_floating_killscore then
|
||||
global.show_floating_killscore[player.name] = false
|
||||
end
|
||||
end
|
||||
|
||||
local surface = game.surfaces['mountain_fortress']
|
||||
|
@ -684,9 +684,6 @@ local function on_player_joined_game(event)
|
||||
player.insert({name = 'firearm-magazine', count = 32})
|
||||
player.insert({name = 'iron-plate', count = 64})
|
||||
player.insert({name = 'stone', count = 32})
|
||||
if global.show_floating_killscore then
|
||||
global.show_floating_killscore[player.name] = false
|
||||
end
|
||||
end
|
||||
|
||||
local surface = game.surfaces['nightfall']
|
||||
|
@ -560,9 +560,6 @@ local function on_player_joined_game(event)
|
||||
end
|
||||
end
|
||||
if player.online_time < 10 then
|
||||
if global.show_floating_killscore then
|
||||
global.show_floating_killscore[player.name] = true
|
||||
end
|
||||
player.insert {name = 'iron-plate', count = 32}
|
||||
player.insert {name = 'pistol', count = 1}
|
||||
player.insert {name = 'firearm-magazine', count = 64}
|
||||
|
@ -152,9 +152,6 @@ local function on_player_joined_game(event)
|
||||
player.insert({name = 'wood', count = 16})
|
||||
player.insert({name = 'firearm-magazine', count = 16})
|
||||
player.insert({name = 'iron-plate', count = 32})
|
||||
if global.show_floating_killscore then
|
||||
global.show_floating_killscore[player.name] = false
|
||||
end
|
||||
end
|
||||
|
||||
local surface = game.surfaces['stoneblock']
|
||||
|
@ -445,9 +445,6 @@ local function on_player_joined_game(event)
|
||||
player.insert({name = 'land-mine', count = 5})
|
||||
player.insert({name = 'light-armor', count = 1})
|
||||
player.insert({name = 'firearm-magazine', count = 128})
|
||||
if global.show_floating_killscore then
|
||||
global.show_floating_killscore[player.name] = false
|
||||
end
|
||||
end
|
||||
|
||||
local surface = game.surfaces['territorial_control']
|
||||
|
@ -1,4 +1,16 @@
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local this = {
|
||||
player_floaty_chat = {}
|
||||
}
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
function(tbl)
|
||||
this = tbl
|
||||
end
|
||||
)
|
||||
|
||||
local function on_console_chat(event)
|
||||
if not event.message then
|
||||
@ -17,9 +29,9 @@ local function on_console_chat(event)
|
||||
y_offset = -4.5
|
||||
end
|
||||
|
||||
if global.player_floaty_chat[player.index] then
|
||||
rendering.destroy(global.player_floaty_chat[player.index])
|
||||
global.player_floaty_chat[player.index] = nil
|
||||
if this.player_floaty_chat[player.index] then
|
||||
rendering.destroy(this.player_floaty_chat[player.index])
|
||||
this.player_floaty_chat[player.index] = nil
|
||||
end
|
||||
|
||||
local players = {}
|
||||
@ -32,7 +44,7 @@ local function on_console_chat(event)
|
||||
return
|
||||
end
|
||||
|
||||
global.player_floaty_chat[player.index] =
|
||||
this.player_floaty_chat[player.index] =
|
||||
rendering.draw_text {
|
||||
text = event.message,
|
||||
surface = player.surface,
|
||||
@ -53,9 +65,4 @@ local function on_console_chat(event)
|
||||
}
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
global.player_floaty_chat = {}
|
||||
end
|
||||
|
||||
Event.on_init(on_init)
|
||||
Event.add(defines.events.on_console_chat, on_console_chat)
|
||||
|
@ -8,10 +8,10 @@ local debug_getupvalue = debug.getupvalue
|
||||
-- this
|
||||
local Debug = {}
|
||||
|
||||
global.debug_message_count = 0
|
||||
|
||||
---@return number next index
|
||||
local function increment()
|
||||
global.debug_message_count = global.debug_message_count or {}
|
||||
|
||||
local next = global.debug_message_count + 1
|
||||
global.debug_message_count = next
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user