mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
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:
@@ -269,7 +269,7 @@ end
|
|||||||
-- @tparam MapPosition position The position on the surface to place the interface at
|
-- @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
|
-- @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
|
-- @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'}
|
local interface = surface.create_entity{name='logistic-chest-storage', position=position, force='neutral'}
|
||||||
table.insert(vlayer_data.entity_interfaces.storage_input, interface)
|
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
|
interface.last_user = last_user
|
||||||
end
|
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.destructible = false
|
||||||
interface.minable = false
|
interface.minable = false
|
||||||
interface.operable = true
|
interface.operable = true
|
||||||
@@ -318,7 +326,7 @@ end
|
|||||||
-- @tparam MapPosition position The position on the surface to place the interface at
|
-- @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
|
-- @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
|
-- @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'}
|
local interface = surface.create_entity{name='logistic-chest-requester', position=position, force='neutral'}
|
||||||
table.insert(vlayer_data.entity_interfaces.storage_output, interface)
|
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
|
interface.last_user = last_user
|
||||||
end
|
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.destructible = false
|
||||||
interface.minable = false
|
interface.minable = false
|
||||||
interface.operable = true
|
interface.operable = true
|
||||||
@@ -432,7 +448,7 @@ end
|
|||||||
-- @tparam MapPosition position The position on the surface to place the interface at
|
-- @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
|
-- @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
|
-- @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'}
|
local interface = surface.create_entity{name='constant-combinator', position=position, force='neutral'}
|
||||||
table.insert(vlayer_data.entity_interfaces.circuit, interface)
|
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
|
interface.last_user = last_user
|
||||||
end
|
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.destructible = false
|
||||||
interface.minable = false
|
interface.minable = false
|
||||||
interface.operable = true
|
interface.operable = true
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ local function vlayer_convert_chest(player)
|
|||||||
|
|
||||||
local entity = entities[1]
|
local entity = entities[1]
|
||||||
local pos = entity.position
|
local pos = entity.position
|
||||||
|
local circuit = entity.circuit_connected_entities
|
||||||
|
|
||||||
if (not entity.get_inventory(defines.inventory.chest).is_empty()) then
|
if (not entity.get_inventory(defines.inventory.chest).is_empty()) then
|
||||||
player.print('Chest is not emptied')
|
player.print('Chest is not emptied')
|
||||||
@@ -62,7 +63,7 @@ local function vlayer_convert_chest(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
entity.destroy()
|
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
|
end
|
||||||
|
|
||||||
--- Display label for the number of solar panels
|
--- Display label for the number of solar panels
|
||||||
@@ -234,11 +235,11 @@ Gui.element{
|
|||||||
}:style{
|
}:style{
|
||||||
width = 160
|
width = 160
|
||||||
}:on_click(function(player, element, _)
|
}:on_click(function(player, element, _)
|
||||||
local pos = vlayer_convert_chest(player)
|
local res = vlayer_convert_chest(player)
|
||||||
|
|
||||||
if (pos) then
|
if res then
|
||||||
vlayer.create_input_interface(player.surface, pos, player)
|
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(pos))
|
game.print(player.name .. ' built a vlayer storage input on ' .. pos_to_gps_string(res.pos))
|
||||||
end
|
end
|
||||||
|
|
||||||
element.enabled = (vlayer.get_interface_counts().storage_input < config.interface_limit.storage_input)
|
element.enabled = (vlayer.get_interface_counts().storage_input < config.interface_limit.storage_input)
|
||||||
@@ -254,11 +255,11 @@ Gui.element{
|
|||||||
}:style{
|
}:style{
|
||||||
width = 160
|
width = 160
|
||||||
}:on_click(function(player, element, _)
|
}:on_click(function(player, element, _)
|
||||||
local pos = vlayer_convert_chest(player)
|
local res = vlayer_convert_chest(player)
|
||||||
|
|
||||||
if (pos) then
|
if res then
|
||||||
vlayer.create_output_interface(player.surface, pos, player)
|
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(pos))
|
game.print(player.name .. ' built a vlayer storage output on ' .. pos_to_gps_string(res.pos))
|
||||||
end
|
end
|
||||||
|
|
||||||
element.enabled = (vlayer.get_interface_counts().storage_output < config.interface_limit.storage_output)
|
element.enabled = (vlayer.get_interface_counts().storage_output < config.interface_limit.storage_output)
|
||||||
@@ -274,11 +275,11 @@ Gui.element{
|
|||||||
}:style{
|
}:style{
|
||||||
width = 160
|
width = 160
|
||||||
}:on_click(function(player, element, _)
|
}:on_click(function(player, element, _)
|
||||||
local pos = vlayer_convert_chest(player)
|
local res = vlayer_convert_chest(player)
|
||||||
|
|
||||||
if (pos) then
|
if res then
|
||||||
vlayer.create_circuit_interface(player.surface, pos, player)
|
vlayer.create_circuit_interface(player.surface, res.pos, res.circuit, player)
|
||||||
game.print(player.name .. ' built a vlayer circuit on ' .. pos_to_gps_string(pos))
|
game.print(player.name .. ' built a vlayer circuit on ' .. pos_to_gps_string(res.pos))
|
||||||
end
|
end
|
||||||
|
|
||||||
element.enabled = (vlayer.get_interface_counts().circuit < config.interface_limit.circuit)
|
element.enabled = (vlayer.get_interface_counts().circuit < config.interface_limit.circuit)
|
||||||
@@ -294,11 +295,12 @@ Gui.element{
|
|||||||
}:style{
|
}:style{
|
||||||
width = 160
|
width = 160
|
||||||
}:on_click(function(player, element, _)
|
}: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
|
else
|
||||||
player.print('Unable to build vlayer energy entity')
|
player.print('Unable to build vlayer energy entity')
|
||||||
end
|
end
|
||||||
@@ -318,6 +320,7 @@ Gui.element{
|
|||||||
width = 160
|
width = 160
|
||||||
}:on_click(function(player, element, _)
|
}:on_click(function(player, element, _)
|
||||||
local interface_type, interface_position = vlayer.remove_closest_interface(player.surface, player.position, 4)
|
local interface_type, interface_position = vlayer.remove_closest_interface(player.surface, player.position, 4)
|
||||||
|
|
||||||
if not interface_type then
|
if not interface_type then
|
||||||
return player.print('Interface not found in range, please move closer')
|
return player.print('Interface not found in range, please move closer')
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user