mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Merge branch 'dev' into dev4
This commit is contained in:
@@ -91,8 +91,8 @@ return {
|
||||
'modules.gui.server-ups',
|
||||
'modules.gui.vlayer',
|
||||
'modules.gui.research',
|
||||
'modules.gui.module',
|
||||
'modules.gui.surveillance',
|
||||
|
||||
'modules.graftorio.require', -- graftorio
|
||||
|
||||
--- Config Files
|
||||
|
||||
@@ -283,7 +283,8 @@ local default = Roles.new_role('Guest','')
|
||||
'gui/warp-list',
|
||||
'gui/readme',
|
||||
'gui/vlayer',
|
||||
'gui/research'
|
||||
'gui/research',
|
||||
'gui/module'
|
||||
}
|
||||
|
||||
--- Jail role
|
||||
|
||||
20
config/module.lua
Normal file
20
config/module.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
return {
|
||||
-- type of machine to handle together
|
||||
default_module_row_count = 4,
|
||||
module_slot_max = 4,
|
||||
machine_prod_disallow = {
|
||||
['beacon'] = true
|
||||
},
|
||||
machine = {
|
||||
['electric-mining-drill'] = 'effectivity-module',
|
||||
['assembling-machine-2'] = 'productivity-module',
|
||||
['assembling-machine-3'] = 'productivity-module-3',
|
||||
['electric-furnace'] = 'productivity-module-3',
|
||||
['beacon'] = 'speed-module-3',
|
||||
['oil-refinery'] = 'productivity-module-3',
|
||||
['chemical-plant'] = 'productivity-module-3',
|
||||
['centrifuge'] = 'productivity-module-3',
|
||||
['lab'] = 'productivity-module-3',
|
||||
['rocket-silo'] = 'productivity-module-3'
|
||||
}
|
||||
}
|
||||
@@ -211,3 +211,6 @@ toggle-msg=Fast decon has been __1__
|
||||
|
||||
[vlayer]
|
||||
main-tooltip=Enable Vlayer GUI
|
||||
|
||||
[module]
|
||||
main-tooltip=Enable Module GUI
|
||||
|
||||
@@ -211,3 +211,6 @@ toggle-msg=樹木快速拆除已 __1__
|
||||
|
||||
[vlayer]
|
||||
main-tooltip=Enable Vlayer GUI
|
||||
|
||||
[module]
|
||||
main-tooltip=Enable Module GUI
|
||||
|
||||
@@ -211,3 +211,6 @@ toggle-msg=樹木快速拆除已 __1__
|
||||
|
||||
[vlayer]
|
||||
main-tooltip=Enable Vlayer GUI
|
||||
|
||||
[module]
|
||||
main-tooltip=Enable Module GUI
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
local format_time = _C.format_time
|
||||
local format_time = _C.format_time --- @dep expcore.common
|
||||
local format_number = require('util').format_number --- @dep util
|
||||
local config = require 'config.deconlog' --- @dep config.deconlog
|
||||
|
||||
local filepath = "log/decon.log"
|
||||
@@ -21,7 +22,7 @@ local function pos_to_string(pos)
|
||||
end
|
||||
|
||||
local function pos_to_gps_string(pos)
|
||||
return '[gps=' .. tostring(pos.x) .. ',' .. tostring(pos.y) .. ']'
|
||||
return '[gps=' .. string.format('%.1f', pos.x) .. ',' .. string.format('%.1f', pos.y) .. ']'
|
||||
end
|
||||
|
||||
--- Print a message to all players who match the value of admin
|
||||
@@ -39,6 +40,10 @@ end)
|
||||
|
||||
if config.decon_area then
|
||||
Event.add(defines.events.on_player_deconstructed_area, function (e)
|
||||
if e.alt then
|
||||
return
|
||||
end
|
||||
|
||||
local player = game.get_player(e.player_index)
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then
|
||||
return
|
||||
@@ -47,7 +52,7 @@ if config.decon_area then
|
||||
local items = e.surface.find_entities_filtered{area=e.area, force=player.force}
|
||||
|
||||
if #items > 250 then
|
||||
print_to_players(true, player.name .. ' tried to deconstruct the area ' .. pos_to_gps_string(e.area.left_top) .. ' to ' .. pos_to_gps_string(e.area.right_bottom) .. ' that have ' .. #items .. ' items, but were not allowed.')
|
||||
print_to_players(true, player.name .. ' tried to deconstruct the area ' .. pos_to_gps_string(e.area.left_top) .. ' to ' .. pos_to_gps_string(e.area.right_bottom) .. ' that have ' .. format_number(#items) .. ' items, but were not allowed.')
|
||||
end
|
||||
|
||||
add_log(get_secs() .. "," .. player.name .. ",decon_area," .. pos_to_string(e.area.left_top) .. "," .. pos_to_string(e.area.right_bottom))
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local config = require 'config.personal_logistic' --- @dep config.personal-logistic
|
||||
|
||||
--[[
|
||||
Command 2:
|
||||
add filter based of inventory
|
||||
local function pl(type, target, amount)
|
||||
local c
|
||||
local s
|
||||
|
||||
Command 3:
|
||||
add filter of those not in inventory: all 0
|
||||
game.item_prototypes
|
||||
if type == 'p' then
|
||||
c = target.clear_personal_logistic_slot
|
||||
s = target.set_personal_logistic_slot
|
||||
|
||||
Command 4:
|
||||
Spidertron request
|
||||
]]
|
||||
elseif type == 's' then
|
||||
c = target.clear_vehicle_logistic_slot
|
||||
s = target.set_vehicle_logistic_slot
|
||||
|
||||
local function pl(player, amount)
|
||||
local c = player.clear_personal_logistic_slot
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
for k, v in pairs(config.request) do
|
||||
for _, v in pairs(config.request) do
|
||||
c(config.start + v.key)
|
||||
end
|
||||
|
||||
if (amount == 0) then
|
||||
return
|
||||
else
|
||||
local stats = player.force.item_production_statistics
|
||||
local s = player.set_personal_logistic_slot
|
||||
local stats = target.force.item_production_statistics
|
||||
|
||||
for k, v in pairs(config.request) do
|
||||
local v_min = math.ceil(v.min * amount)
|
||||
@@ -63,13 +63,20 @@ local function pl(player, amount)
|
||||
end
|
||||
end
|
||||
|
||||
Commands.new_command('personal-logistic', 'Set Personal Logistic (0 to cancel all)')
|
||||
Commands.new_command('personal-logistic', 'Set Personal Logistic (0 to cancel all) (Select spidertron to edit spidertron)')
|
||||
:add_param('amount', 'integer-range', 0, 10)
|
||||
:add_alias('pl')
|
||||
:register(function(player, amount)
|
||||
if player.force.technologies['logistic-robotics'].researched then
|
||||
pl(player, amount / 10)
|
||||
return Commands.success
|
||||
if player.selected ~= nil then
|
||||
if player.selected.name == 'spidertron' then
|
||||
pl('s', player.selected, amount / 10)
|
||||
return Commands.success
|
||||
end
|
||||
else
|
||||
pl('p', player, amount / 10)
|
||||
return Commands.success
|
||||
end
|
||||
else
|
||||
player.print('Player logistic not researched')
|
||||
end
|
||||
|
||||
266
modules/gui/module.lua
Normal file
266
modules/gui/module.lua
Normal file
@@ -0,0 +1,266 @@
|
||||
---- module inserter
|
||||
-- @addon module
|
||||
|
||||
local Gui = require 'expcore.gui' --- @dep expcore.gui
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
local config = require 'config.module' --- @dep config.module
|
||||
local Selection = require 'modules.control.selection' --- @dep modules.control.selection
|
||||
local SelectionModuleArea = 'ModuleArea'
|
||||
|
||||
--- align an aabb to the grid by expanding it
|
||||
local function aabb_align_expand(aabb)
|
||||
return {
|
||||
left_top = {x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y)},
|
||||
right_bottom = {x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y)}
|
||||
}
|
||||
end
|
||||
|
||||
local module_container
|
||||
|
||||
local machine_name = {}
|
||||
|
||||
for k, _ in pairs(config.machine) do
|
||||
table.insert(machine_name, k)
|
||||
end
|
||||
|
||||
--[[
|
||||
local module_allowed = {}
|
||||
|
||||
for _, r in pairs(game.item_prototypes['productivity-module'].limitations) do
|
||||
module_allowed[r] = true
|
||||
end
|
||||
]]
|
||||
|
||||
local module_allowed = {
|
||||
['advanced-circuit'] = true,
|
||||
['automation-science-pack'] = true,
|
||||
['battery'] = true,
|
||||
['chemical-science-pack'] = true,
|
||||
['copper-cable'] = true,
|
||||
['copper-plate'] = true,
|
||||
['electric-engine-unit'] = true,
|
||||
['electronic-circuit'] = true,
|
||||
['empty-barrel'] = true,
|
||||
['engine-unit'] = true,
|
||||
['explosives'] = true,
|
||||
['flying-robot-frame'] = true,
|
||||
['iron-gear-wheel'] = true,
|
||||
['iron-plate'] = true,
|
||||
['iron-stick'] = true,
|
||||
['logistic-science-pack'] = true,
|
||||
['low-density-structure'] = true,
|
||||
['lubricant'] = true,
|
||||
['military-science-pack'] = true,
|
||||
['nuclear-fuel'] = true,
|
||||
['plastic-bar'] = true,
|
||||
['processing-unit'] = true,
|
||||
['production-science-pack'] = true,
|
||||
['rocket-control-unit'] = true,
|
||||
['rocket-fuel'] = true,
|
||||
['rocket-part'] = true,
|
||||
['steel-plate'] = true,
|
||||
['stone-brick'] = true,
|
||||
['sulfur'] = true,
|
||||
['sulfuric-acid'] = true,
|
||||
['uranium-fuel-cell'] = true,
|
||||
['utility-science-pack'] = true,
|
||||
['basic-oil-processing'] = true,
|
||||
['advanced-oil-processing'] = true,
|
||||
['coal-liquefaction'] = true,
|
||||
['heavy-oil-cracking'] = true,
|
||||
['light-oil-cracking'] = true,
|
||||
['solid-fuel-from-light-oil'] = true,
|
||||
['solid-fuel-from-petroleum-gas'] = true,
|
||||
['solid-fuel-from-heavy-oil'] = true,
|
||||
['uranium-processing'] = true,
|
||||
['nuclear-fuel-reprocessing'] = true,
|
||||
['kovarex-enrichment-process'] = true
|
||||
}
|
||||
|
||||
local elem_filter = {
|
||||
name = {{
|
||||
filter = 'name',
|
||||
name = machine_name
|
||||
}},
|
||||
normal = {{
|
||||
filter = 'type',
|
||||
type = 'module'
|
||||
}},
|
||||
prod = {{
|
||||
filter = 'type',
|
||||
type = 'module'
|
||||
}, {
|
||||
filter = 'name',
|
||||
name = 'productivity',
|
||||
invert = true
|
||||
}}
|
||||
}
|
||||
|
||||
local function clear_module(player, area, machine)
|
||||
for _, entity in pairs(player.surface.find_entities_filtered{area=area, name=machine, force=player.force}) do
|
||||
for _, r in pairs(player.surface.find_entities_filtered{position=entity.position, name='item-request-proxy', force=player.force}) do
|
||||
if r ~= nil then
|
||||
r.destroy{raise_destroy=true}
|
||||
end
|
||||
end
|
||||
|
||||
local m_current_module = entity.get_module_inventory()
|
||||
|
||||
if m_current_module ~= nil then
|
||||
local m_current_module_content = m_current_module.get_contents()
|
||||
|
||||
if m_current_module_content ~= nil then
|
||||
for k, m in pairs(m_current_module_content) do
|
||||
player.surface.spill_item_stack(entity.bounding_box.left_top, {name=k, count=m}, true, player.force, false)
|
||||
end
|
||||
end
|
||||
|
||||
m_current_module.clear()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function apply_module(player, area, machine, module)
|
||||
for _, entity in pairs(player.surface.find_entities_filtered{area=area, name=machine, force=player.force}) do
|
||||
local m_current_recipe = entity.get_recipe()
|
||||
|
||||
-- insert
|
||||
if m_current_recipe ~= nil then
|
||||
if module_allowed[m_current_recipe.name] ~= nil then
|
||||
if module_allowed[m_current_recipe.name] then
|
||||
entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=module}
|
||||
end
|
||||
end
|
||||
else
|
||||
entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=module}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- when an area is selected to add protection to the area
|
||||
Selection.on_selection(SelectionModuleArea, function(event)
|
||||
local area = aabb_align_expand(event.area)
|
||||
local player = game.get_player(event.player_index)
|
||||
|
||||
if player == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local frame = Gui.get_left_element(player, module_container)
|
||||
|
||||
for i=1, config.default_module_row_count do
|
||||
local m_machine = frame.container.scroll.table['module_mm_' .. i .. '_0'].elem_value
|
||||
|
||||
if m_machine ~= nil then
|
||||
local m_module = {}
|
||||
|
||||
for j=1, config.module_slot_max do
|
||||
local mmo = frame.container.scroll.table['module_mm_' .. i .. '_' .. j].elem_value
|
||||
|
||||
if mmo ~= nil then
|
||||
if m_module[mmo] == nil then
|
||||
m_module[mmo] = 1
|
||||
else
|
||||
m_module[mmo] = m_module[mmo] + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if m_module ~= nil then
|
||||
clear_module(player, area, m_machine)
|
||||
apply_module(player, area, m_machine, m_module)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local function row_set(player, element)
|
||||
local frame = Gui.get_left_element(player, module_container)
|
||||
|
||||
if frame.container.scroll.table[element .. '0'].elem_value ~= nil then
|
||||
for i=1, config.module_slot_max do
|
||||
if i <= game.entity_prototypes[frame.container.scroll.table[element .. '0'].elem_value].module_inventory_size then
|
||||
frame.container.scroll.table[element .. i].enabled = true
|
||||
frame.container.scroll.table[element .. i].elem_value = config.machine[frame.container.scroll.table[element .. '0'].elem_value]
|
||||
else
|
||||
frame.container.scroll.table[element .. i].enabled = false
|
||||
frame.container.scroll.table[element .. i].elem_value = nil
|
||||
end
|
||||
frame.container.scroll.table[element .. i].elem_filters = elem_filter.normal
|
||||
end
|
||||
else
|
||||
local mf = elem_filter.normal
|
||||
|
||||
if config.machine_prod_disallow[element.elem_value] ~= nil then
|
||||
if config.machine_prod_disallow[element.elem_value] then
|
||||
mf = elem_filter.prod
|
||||
end
|
||||
end
|
||||
|
||||
for i=1, config.module_slot_max do
|
||||
frame.container.scroll.table[element .. i].enabled = true
|
||||
frame.container.scroll.table[element .. i].elem_filters = mf
|
||||
frame.container.scroll.table[element .. i].elem_value = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local button_apply =
|
||||
Gui.element{
|
||||
name = 'module_b',
|
||||
type = 'button',
|
||||
caption = 'Apply',
|
||||
style = 'button'
|
||||
}:on_click(function(player)
|
||||
if Selection.is_selecting(player, SelectionModuleArea) then
|
||||
Selection.stop(player)
|
||||
else
|
||||
Selection.start(player, SelectionModuleArea)
|
||||
end
|
||||
end)
|
||||
|
||||
module_container =
|
||||
Gui.element(function(event_trigger, parent)
|
||||
local container = Gui.container(parent, event_trigger, (config.module_slot_max + 2) * 36)
|
||||
Gui.header(container, 'Module Inserter', '', true)
|
||||
|
||||
local scroll_table = Gui.scroll_table(container, (config.module_slot_max + 2) * 36, config.module_slot_max + 1)
|
||||
|
||||
for i=1, config.default_module_row_count do
|
||||
scroll_table.add{
|
||||
name = 'module_mm_' .. i .. '_0',
|
||||
type = 'choose-elem-button',
|
||||
elem_type = 'entity',
|
||||
elem_filters = elem_filter.name,
|
||||
style = 'slot_button'
|
||||
}
|
||||
|
||||
for j=1, config.module_slot_max do
|
||||
scroll_table.add{
|
||||
name = 'module_mm_' .. i .. '_' .. j,
|
||||
type = 'choose-elem-button',
|
||||
elem_type = 'item',
|
||||
elem_filters = elem_filter.normal,
|
||||
style = 'slot_button'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
button_apply(container)
|
||||
|
||||
return container.parent
|
||||
end)
|
||||
:add_to_left_flow()
|
||||
|
||||
Gui.left_toolbar_button('item/productivity-module-3', {'module.main-tooltip'}, module_container, function(player)
|
||||
return Roles.player_allowed(player, 'gui/module')
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_gui_elem_changed, function(event)
|
||||
if event.element.name:sub(1, 10) == 'module_mm_' then
|
||||
if event.element.name:sub(-1) == '0' then
|
||||
row_set(game.players[event.player_index], 'module_mm_' .. event.element.name:sub(-3):sub(1, 1) .. '_')
|
||||
end
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user