mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-02-09 13:37:02 +02:00
Minimap addition
This commit is contained in:
parent
62d2069a25
commit
037f11463d
@ -135,6 +135,11 @@ local function construct_wagon_doors(icw, wagon)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.kill_minimap(player)
|
||||
local element = player.gui.left.icw_map
|
||||
if element then element.destroy() end
|
||||
end
|
||||
|
||||
function Public.kill_wagon(icw, entity)
|
||||
if not Constants.wagon_types[entity.type] then return end
|
||||
local wagon = icw.wagons[entity.unit_number]
|
||||
@ -148,6 +153,7 @@ function Public.kill_wagon(icw, entity)
|
||||
else
|
||||
e.player.teleport(wagon.entity.position, wagon.entity.surface)
|
||||
end
|
||||
Public.kill_minimap(e.player)
|
||||
else
|
||||
e.die()
|
||||
end
|
||||
@ -223,7 +229,8 @@ function Public.create_wagon_room(icw, wagon)
|
||||
table_insert(vectors, {x, y})
|
||||
end
|
||||
end
|
||||
local position = {x = area.right_bottom.x * 0.5 + (-1 + math_random(0, 2)), y = area.right_bottom.y * 0.5 + (-4 + math_random(0, 8))}
|
||||
local position = {x = area.left_top.x + (area.right_bottom.x - area.left_top.x) * 0.5, y = area.left_top.y + (area.right_bottom.y - area.left_top.y) * 0.5}
|
||||
position = {x = position.x + (-1 + math_random(0, 2)), y = position.y + (-4 + math_random(0, 8))}
|
||||
for _, v in pairs(vectors) do
|
||||
table_insert(tiles, {name = "water", position = {position.x + v[1], position.y + v[2]}})
|
||||
end
|
||||
@ -298,6 +305,7 @@ function Public.create_wagon(icw, created_entity)
|
||||
}
|
||||
Public.create_wagon_room(icw, icw.wagons[created_entity.unit_number])
|
||||
request_reconstruction(icw)
|
||||
return icw.wagons[created_entity.unit_number]
|
||||
end
|
||||
|
||||
function Public.add_wagon_entity_count(icw, added_entity)
|
||||
@ -343,6 +351,7 @@ function Public.use_cargo_wagon_door(icw, player, door)
|
||||
player.teleport(position, surface)
|
||||
icw.players[player.index] = 2
|
||||
player.driving = true
|
||||
Public.kill_minimap(player)
|
||||
else
|
||||
local surface = wagon.surface
|
||||
local area = wagon.area
|
||||
@ -452,4 +461,35 @@ function Public.item_transfer(icw)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.draw_minimap(player, surface, position)
|
||||
local element = player.gui.left.icw_map
|
||||
if not element then
|
||||
element = player.gui.left.add({
|
||||
type = "camera",
|
||||
name = "icw_map",
|
||||
position = position,
|
||||
surface_index = surface.index,
|
||||
zoom = 0.30,
|
||||
})
|
||||
element.style.margin = 2
|
||||
element.style.minimal_height = 360
|
||||
element.style.minimal_width = 360
|
||||
return
|
||||
end
|
||||
|
||||
element.position = position
|
||||
element.surface_index = surface.index
|
||||
end
|
||||
|
||||
function Public.update_minimap(icw)
|
||||
for k, player in pairs(game.connected_players) do
|
||||
if player.character and player.character.valid then
|
||||
local wagon = get_wagon_for_entity(icw, player.character)
|
||||
if wagon then
|
||||
Public.draw_minimap(player, wagon.entity.surface, wagon.entity.position)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Public
|
@ -13,7 +13,14 @@ Global.register(
|
||||
end
|
||||
)
|
||||
|
||||
function Public.reset_tables()
|
||||
function Public.reset()
|
||||
if icw.surfaces then
|
||||
for k, surface in pairs(icw.surfaces) do
|
||||
if surface and surface.valid then
|
||||
game.delete_surface(surface)
|
||||
end
|
||||
end
|
||||
end
|
||||
for k, v in pairs(icw) do icw[k] = nil end
|
||||
icw.doors = {}
|
||||
icw.wagons = {}
|
||||
@ -45,7 +52,7 @@ end
|
||||
|
||||
local function on_built_entity(event)
|
||||
local created_entity = event.created_entity
|
||||
Functions.create_wagon(icw, created_entity)
|
||||
Functions.create_wagon(icw, created_entity)
|
||||
Functions.add_wagon_entity_count(icw, created_entity)
|
||||
end
|
||||
|
||||
@ -59,7 +66,7 @@ local function on_player_driving_changed_state(event)
|
||||
local player = game.players[event.player_index]
|
||||
Functions.use_cargo_wagon_door(icw, player, event.entity)
|
||||
end
|
||||
|
||||
--[[
|
||||
local function on_player_created(event)
|
||||
local player = game.players[event.player_index]
|
||||
player.insert({name = "cargo-wagon", count = 5})
|
||||
@ -68,10 +75,32 @@ local function on_player_created(event)
|
||||
player.insert({name = "locomotive", count = 5})
|
||||
player.insert({name = "rail", count = 100})
|
||||
end
|
||||
]]
|
||||
local function on_gui_closed(event)
|
||||
local entity = event.entity
|
||||
if not entity then return end
|
||||
if not entity.valid then return end
|
||||
Functions.kill_minimap(game.players[event.player_index])
|
||||
end
|
||||
|
||||
local function on_gui_opened(event)
|
||||
local entity = event.entity
|
||||
if not entity then return end
|
||||
if not entity.valid then return end
|
||||
if not entity.unit_number then return end
|
||||
local wagon = icw.wagons[entity.unit_number]
|
||||
if not wagon then return end
|
||||
Functions.draw_minimap(game.players[event.player_index], wagon.surface, {wagon.area.left_top.x + (wagon.area.right_bottom.x - wagon.area.left_top.x) * 0.5, wagon.area.left_top.y + (wagon.area.right_bottom.y - wagon.area.left_top.y) * 0.5})
|
||||
end
|
||||
|
||||
local function on_player_died(event)
|
||||
Functions.kill_minimap(game.players[event.player_index])
|
||||
end
|
||||
|
||||
local function on_tick()
|
||||
local tick = game.tick
|
||||
if tick % 60 == 0 then Functions.item_transfer(icw) end
|
||||
if tick % 300 == 0 then Functions.update_minimap(icw) end
|
||||
|
||||
if not icw.rebuild_tick then return end
|
||||
if icw.rebuild_tick ~= tick then return end
|
||||
@ -80,22 +109,28 @@ local function on_tick()
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
Public.reset_tables()
|
||||
Public.reset()
|
||||
end
|
||||
|
||||
function Public.get_table()
|
||||
return icw
|
||||
end
|
||||
|
||||
function Public.register_wagon(wagon_entity)
|
||||
return Functions.create_wagon(icw, wagon_entity)
|
||||
end
|
||||
|
||||
Event.on_init(on_init)
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
Event.add(defines.events.on_player_driving_changed_state, on_player_driving_changed_state)
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_built_entity, on_built_entity)
|
||||
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
||||
Event.add(defines.events.on_player_created, on_player_created)
|
||||
Event.add(defines.events.on_player_died, on_player_died)
|
||||
--Event.add(defines.events.on_player_created, on_player_created)
|
||||
Event.add(defines.events.on_gui_closed, on_gui_closed)
|
||||
Event.add(defines.events.on_gui_opened, on_gui_opened)
|
||||
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
||||
Event.add(defines.events.on_robot_mined_entity, on_robot_mined_entity)
|
||||
|
||||
|
||||
return Public
|
Loading…
x
Reference in New Issue
Block a user