vlayer auto connect circuit (#291)

* Update vlayer.lua

* Update vlayer.lua

* Update vlayer.lua

* Update vlayer.lua

* Update vlayer.lua

* Update vlayer.lua

* Update vlayer.lua

* Update vlayer.lua

* Update vlayer.lua

* Update vlayer.lua
This commit is contained in:
2024-05-28 22:59:28 +09:00
committed by GitHub
parent 9a3161d776
commit cbb5a2093b
2 changed files with 47 additions and 20 deletions

View File

@@ -269,7 +269,7 @@ end
-- @tparam MapPosition position The position on the surface to place the interface at
-- @tparam[opt] LuaPlayer player The player to show as the last user of the interface
-- @treturn LuaEntity The entity that was created for the interface
function vlayer.create_input_interface(surface, position, last_user)
function vlayer.create_input_interface(surface, position, circuit, last_user)
local interface = surface.create_entity{name='logistic-chest-storage', position=position, force='neutral'}
table.insert(vlayer_data.entity_interfaces.storage_input, interface)
@@ -277,6 +277,14 @@ function vlayer.create_input_interface(surface, position, last_user)
interface.last_user = last_user
end
if circuit then
for k, _ in pairs(circuit) do
for _, v in pairs(circuit[k]) do
interface.connect_neighbour({wire=defines.wire_type[k], target_entity=v})
end
end
end
interface.destructible = false
interface.minable = false
interface.operable = true
@@ -318,7 +326,7 @@ end
-- @tparam MapPosition position The position on the surface to place the interface at
-- @tparam[opt] LuaPlayer player The player to show as the last user of the interface
-- @treturn LuaEntity The entity that was created for the interface
function vlayer.create_output_interface(surface, position, last_user)
function vlayer.create_output_interface(surface, position, circuit, last_user)
local interface = surface.create_entity{name='logistic-chest-requester', position=position, force='neutral'}
table.insert(vlayer_data.entity_interfaces.storage_output, interface)
@@ -326,6 +334,14 @@ function vlayer.create_output_interface(surface, position, last_user)
interface.last_user = last_user
end
if circuit then
for k, _ in pairs(circuit) do
for _, v in pairs(circuit[k]) do
interface.connect_neighbour({wire=defines.wire_type[k], target_entity=v})
end
end
end
interface.destructible = false
interface.minable = false
interface.operable = true
@@ -432,7 +448,7 @@ end
-- @tparam MapPosition position The position on the surface to place the interface at
-- @tparam[opt] LuaPlayer player The player to show as the last user of the interface
-- @treturn LuaEntity The entity that was created for the interface
function vlayer.create_circuit_interface(surface, position, last_user)
function vlayer.create_circuit_interface(surface, position, circuit, last_user)
local interface = surface.create_entity{name='constant-combinator', position=position, force='neutral'}
table.insert(vlayer_data.entity_interfaces.circuit, interface)
@@ -440,6 +456,14 @@ function vlayer.create_circuit_interface(surface, position, last_user)
interface.last_user = last_user
end
if circuit then
for k, _ in pairs(circuit) do
for _, v in pairs(circuit[k]) do
interface.connect_neighbour({wire=defines.wire_type[k], target_entity=v})
end
end
end
interface.destructible = false
interface.minable = false
interface.operable = true

View File

@@ -55,6 +55,7 @@ local function vlayer_convert_chest(player)
local entity = entities[1]
local pos = entity.position
local circuit = entity.circuit_connected_entities
if (not entity.get_inventory(defines.inventory.chest).is_empty()) then
player.print('Chest is not emptied')
@@ -62,7 +63,7 @@ local function vlayer_convert_chest(player)
end
entity.destroy()
return {x=string.format('%.1f', pos.x), y=string.format('%.1f', pos.y)}
return {pos={x=string.format('%.1f', pos.x), y=string.format('%.1f', pos.y)}, circuit=circuit}
end
--- Display label for the number of solar panels
@@ -234,11 +235,11 @@ Gui.element{
}:style{
width = 160
}:on_click(function(player, element, _)
local pos = vlayer_convert_chest(player)
local res = vlayer_convert_chest(player)
if (pos) then
vlayer.create_input_interface(player.surface, pos, player)
game.print(player.name .. ' built a vlayer storage input on ' .. pos_to_gps_string(pos))
if res then
vlayer.create_input_interface(player.surface, res.pos, res.circuit, player)
game.print(player.name .. ' built a vlayer storage input on ' .. pos_to_gps_string(res.pos))
end
element.enabled = (vlayer.get_interface_counts().storage_input < config.interface_limit.storage_input)
@@ -254,11 +255,11 @@ Gui.element{
}:style{
width = 160
}:on_click(function(player, element, _)
local pos = vlayer_convert_chest(player)
local res = vlayer_convert_chest(player)
if (pos) then
vlayer.create_output_interface(player.surface, pos, player)
game.print(player.name .. ' built a vlayer storage output on ' .. pos_to_gps_string(pos))
if res then
vlayer.create_output_interface(player.surface, res.pos, res.circuit, player)
game.print(player.name .. ' built a vlayer storage output on ' .. pos_to_gps_string(res.pos))
end
element.enabled = (vlayer.get_interface_counts().storage_output < config.interface_limit.storage_output)
@@ -274,11 +275,11 @@ Gui.element{
}:style{
width = 160
}:on_click(function(player, element, _)
local pos = vlayer_convert_chest(player)
local res = vlayer_convert_chest(player)
if (pos) then
vlayer.create_circuit_interface(player.surface, pos, player)
game.print(player.name .. ' built a vlayer circuit on ' .. pos_to_gps_string(pos))
if res then
vlayer.create_circuit_interface(player.surface, res.pos, res.circuit, player)
game.print(player.name .. ' built a vlayer circuit on ' .. pos_to_gps_string(res.pos))
end
element.enabled = (vlayer.get_interface_counts().circuit < config.interface_limit.circuit)
@@ -294,11 +295,12 @@ Gui.element{
}:style{
width = 160
}:on_click(function(player, element, _)
local pos = vlayer_convert_chest(player)
local res = vlayer_convert_chest(player)
if res then
if vlayer.create_energy_interface(player.surface, res.pos, player) then
game.print(player.name .. ' built a vlayer energy interface on ' .. pos_to_gps_string(res.pos))
if (pos) then
if vlayer.create_energy_interface(player.surface, pos, player) then
game.print(player.name .. ' built a vlayer energy interface on ' .. pos_to_gps_string(pos))
else
player.print('Unable to build vlayer energy entity')
end
@@ -318,6 +320,7 @@ Gui.element{
width = 160
}:on_click(function(player, element, _)
local interface_type, interface_position = vlayer.remove_closest_interface(player.surface, player.position, 4)
if not interface_type then
return player.print('Interface not found in range, please move closer')
end