mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-08 00:39:30 +02:00
spaghett mode toggle
This commit is contained in:
parent
ba4ea57617
commit
4e3a07d806
@ -2,6 +2,57 @@
|
||||
|
||||
local Tabs = require 'comfy_panel.main'
|
||||
|
||||
local spaghett_entity_blacklist = {
|
||||
["logistic-chest-requester"] = true,
|
||||
["logistic-chest-buffer"] = true,
|
||||
["logistic-chest-active-provider"] = true,
|
||||
}
|
||||
|
||||
local function spaghett_deny_building(event)
|
||||
local spaghett = global.comfy_panel_config.spaghett
|
||||
if not spaghett.enabled then return end
|
||||
local entity = event.created_entity
|
||||
if not entity.valid then return end
|
||||
if not spaghett_entity_blacklist[event.created_entity.name] then return end
|
||||
|
||||
if event.player_index then
|
||||
game.players[event.player_index].insert({name = entity.name, count = 1})
|
||||
else
|
||||
local inventory = event.robot.get_inventory(defines.inventory.robot_cargo)
|
||||
inventory.insert({name = entity.name, count = 1})
|
||||
end
|
||||
|
||||
event.created_entity.surface.create_entity({
|
||||
name = "flying-text",
|
||||
position = entity.position,
|
||||
text = "Spaghett Mode Active!",
|
||||
color = {r=0.98, g=0.66, b=0.22}
|
||||
})
|
||||
|
||||
entity.destroy()
|
||||
end
|
||||
|
||||
local function spaghett()
|
||||
local spaghett = global.comfy_panel_config.spaghett
|
||||
if spaghett.enabled then
|
||||
for _, f in pairs(game.forces) do
|
||||
if f.technologies["logistic-system"].researched then
|
||||
spaghett.undo[f.index] = true
|
||||
end
|
||||
f.technologies["logistic-system"].enabled = false
|
||||
f.technologies["logistic-system"].researched = false
|
||||
end
|
||||
else
|
||||
for _, f in pairs(game.forces) do
|
||||
f.technologies["logistic-system"].enabled = true
|
||||
if spaghett.undo[f.index] then
|
||||
f.technologies["logistic-system"].researched = true
|
||||
spaghett.undo[f.index] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local functions = {
|
||||
["comfy_panel_spectator_switch"] = function(event)
|
||||
if event.element.switch_state == "left" then
|
||||
@ -18,7 +69,7 @@ local functions = {
|
||||
global.auto_hotbar_enabled[event.player_index] = false
|
||||
end
|
||||
end,
|
||||
["map_settings_blueprint_toggle"] = function(event)
|
||||
["comfy_panel_blueprint_toggle"] = function(event)
|
||||
if event.element.switch_state == "left" then
|
||||
game.permissions.get_group("Default").set_allows_action(defines.input_action.grab_blueprint_record, true)
|
||||
game.permissions.get_group("Default").set_allows_action(defines.input_action.import_blueprint_string, true)
|
||||
@ -28,7 +79,15 @@ local functions = {
|
||||
game.permissions.get_group("Default").set_allows_action(defines.input_action.import_blueprint_string, false)
|
||||
game.permissions.get_group("Default").set_allows_action(defines.input_action.import_blueprint, false)
|
||||
end
|
||||
end,
|
||||
end,
|
||||
["comfy_panel_spaghett_toggle"] = function(event)
|
||||
if event.element.switch_state == "left" then
|
||||
global.comfy_panel_config.spaghett.enabled = true
|
||||
else
|
||||
global.comfy_panel_config.spaghett.enabled = nil
|
||||
end
|
||||
spaghett()
|
||||
end,
|
||||
}
|
||||
|
||||
local function add_switch(element, switch_state, name, description_main, description)
|
||||
@ -103,7 +162,14 @@ local build_config_gui = (function (player, frame)
|
||||
|
||||
local switch_state = "right"
|
||||
if game.permissions.get_group("Default").allows_action(defines.input_action.import_blueprint) then switch_state = "left" end
|
||||
local switch = add_switch(frame, switch_state, "map_settings_blueprint_toggle", "Blueprint Library", "Toggles the usage of blueprint strings and the library.")
|
||||
local switch = add_switch(frame, switch_state, "comfy_panel_blueprint_toggle", "Blueprint Library", "Toggles the usage of blueprint strings and the library.")
|
||||
if not admin then switch.ignored_by_interaction = true end
|
||||
|
||||
frame.add({type = "line"})
|
||||
|
||||
local switch_state = "right"
|
||||
if global.comfy_panel_config.spaghett.enabled then switch_state = "left" end
|
||||
local switch = add_switch(frame, switch_state, "comfy_panel_spaghett_toggle", "Spaghett Mode", "Disables the Logistic System research.\nRequester, buffer or active-provider containers can not be built.")
|
||||
if not admin then switch.ignored_by_interaction = true end
|
||||
|
||||
frame.add({type = "line"})
|
||||
@ -116,7 +182,7 @@ local build_config_gui = (function (player, frame)
|
||||
end
|
||||
end)
|
||||
|
||||
local function on_gui_click(event)
|
||||
local function on_gui_switch_state_changed(event)
|
||||
if not event.element then return end
|
||||
if not event.element.valid then return end
|
||||
if functions[event.element.name] then
|
||||
@ -125,8 +191,30 @@ local function on_gui_click(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_force_created(event)
|
||||
spaghett()
|
||||
end
|
||||
|
||||
local function on_built_entity(event)
|
||||
spaghett_deny_building(event)
|
||||
end
|
||||
|
||||
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 = {}
|
||||
end
|
||||
|
||||
comfy_panel_tabs["Config"] = build_config_gui
|
||||
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.add(defines.events.on_gui_click, on_gui_click)
|
||||
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)
|
||||
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
Loading…
Reference in New Issue
Block a user