2019-03-03 03:17:13 +02:00
|
|
|
local Event = require 'utils.event'
|
|
|
|
local Global = require 'utils.global'
|
|
|
|
local Game = require 'utils.game'
|
|
|
|
local RS = require 'map_gen.shared.redmew_surface'
|
|
|
|
|
|
|
|
local chart_tags = {}
|
|
|
|
|
|
|
|
Global.register(
|
|
|
|
{
|
|
|
|
chart_tags = chart_tags
|
|
|
|
},
|
|
|
|
function(tbl)
|
|
|
|
chart_tags = tbl.chart_tags
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
local function console_chat(event)
|
|
|
|
if not event.player_index or event.player_index == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local player = Game.get_player_by_index(event.player_index)
|
|
|
|
local player_force = player.force
|
|
|
|
for _, force in pairs(game.forces) do
|
|
|
|
if (string.find(force.name, 'quadrant')) ~= nil or force.name == 'player' then
|
|
|
|
if force.name ~= player_force.name then
|
2019-03-03 17:32:08 +02:00
|
|
|
if player.tag ~= '' then
|
2019-03-03 03:17:13 +02:00
|
|
|
force.print(player.name .. ' ' .. player.tag .. ': ' .. event.message, player.chat_color)
|
|
|
|
else
|
|
|
|
force.print(player.name .. ': ' .. event.message, player.chat_color)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-03 12:20:56 +02:00
|
|
|
local function create_tag(creating_force, data, remove)
|
2019-03-03 03:17:13 +02:00
|
|
|
local surface = RS.get_surface()
|
|
|
|
local tags
|
|
|
|
for _, force in pairs(game.forces) do
|
|
|
|
if (string.find(force.name, 'quadrant')) ~= nil then
|
|
|
|
if force.name ~= creating_force.name then
|
|
|
|
local old_tag =
|
|
|
|
force.find_chart_tags(
|
|
|
|
surface,
|
|
|
|
{{data.position.x - 0.5, data.position.y - 0.5}, {data.position.x + 0.5, data.position.y + 0.5}}
|
|
|
|
)[1]
|
|
|
|
if old_tag and old_tag.valid then
|
|
|
|
if remove then
|
|
|
|
old_tag.destroy()
|
|
|
|
else
|
2019-03-03 12:20:56 +02:00
|
|
|
if data.icon ~= nil then
|
|
|
|
old_tag.icon = data.icon
|
|
|
|
end
|
|
|
|
if data.last_user ~= nil then
|
|
|
|
old_tag.last_user = data.last_user
|
|
|
|
end
|
|
|
|
if data.text ~= nil then
|
|
|
|
old_tag.text = data.text
|
|
|
|
end
|
2019-03-03 03:17:13 +02:00
|
|
|
end
|
2019-03-03 12:20:56 +02:00
|
|
|
elseif not remove then
|
2019-03-03 03:17:13 +02:00
|
|
|
force.add_chart_tag(surface, data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function chart_tag_event(event, remove)
|
|
|
|
local tag = event.tag
|
|
|
|
local force = event.force
|
|
|
|
local modify = false
|
|
|
|
if remove ~= nil and not remove then
|
|
|
|
modify = true
|
|
|
|
end
|
|
|
|
remove = remove ~= nil and remove or false
|
|
|
|
if string.find(force.name, 'quadrant') == nil then
|
|
|
|
return
|
|
|
|
end
|
2019-03-03 12:20:56 +02:00
|
|
|
if chart_tags.position ~= nil and not modify and not remove then
|
2019-03-03 03:17:13 +02:00
|
|
|
if chart_tags.position.x == tag.position.x and chart_tags.position.y == tag.position.y then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
elseif modify and chart_tags.text == tag.text and chart_tags.icon == tag.icon then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
chart_tags = {icon = tag.icon, position = tag.position, text = tag.text, last_user = tag.last_user}
|
2019-03-03 12:20:56 +02:00
|
|
|
if remove then
|
|
|
|
chart_tags['remove'] = remove
|
|
|
|
end
|
2019-03-03 03:17:13 +02:00
|
|
|
create_tag(force, chart_tags, remove)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function chart_tag_modified(event)
|
|
|
|
chart_tag_event(event, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function chart_tag_remove(event)
|
|
|
|
chart_tag_event(event, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
Event.add(defines.events.on_chart_tag_added, chart_tag_event)
|
|
|
|
Event.add(defines.events.on_chart_tag_modified, chart_tag_modified)
|
2019-03-03 12:20:56 +02:00
|
|
|
Event.add(defines.events.on_chart_tag_removed, chart_tag_remove)
|
|
|
|
local function research_finished(event)
|
|
|
|
if event.by_script then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local technology = event.research
|
|
|
|
local player_force = technology.force
|
|
|
|
|
|
|
|
for _, force in pairs(game.forces) do
|
|
|
|
if (string.find(force.name, 'quadrant')) ~= nil then
|
|
|
|
force.print(
|
|
|
|
'[img=item/automation-science-pack] New research complete: [technology=' .. technology.name .. ']'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-03-03 03:17:13 +02:00
|
|
|
|
|
|
|
Event.add(defines.events.on_console_chat, console_chat)
|
2019-03-03 12:20:56 +02:00
|
|
|
Event.add(defines.events.on_research_finished, research_finished)
|