1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-05 22:53:39 +02:00

Porting to fix merge conflict

This commit is contained in:
SimonFlapse 2019-01-25 17:18:02 +01:00
parent c40412d871
commit d7aafbf285

View File

@ -1,6 +1,7 @@
local Gui = require 'utils.gui' local Gui = require 'utils.gui'
local Utils = require 'utils.core' local Utils = require 'utils.core'
local Game = require 'utils.game' local Game = require 'utils.game'
local Command = require 'utils.command'
local close_name = Gui.uid_name() local close_name = Gui.uid_name()
@ -85,94 +86,80 @@ Gui.on_click(
) )
-- Creates a popup dialog for all players -- Creates a popup dialog for all players
local function popup(cmd) local function popup(args)
local player = game.player local message = args.message:gsub('\\n', '\n')
if player and not player.admin then
Utils.cant_run(cmd.name)
return
end
local message = cmd.parameter
if not message then
Game.player_print('Usage: /popup <message>')
return
end
message = message:gsub('\\n', '\n')
for _, p in ipairs(game.connected_players) do for _, p in ipairs(game.connected_players) do
show_popup(p, message) show_popup(p, message)
end end
Game.player_print('Popup sent') Game.player_print('Popup sent')
Utils.print_admins(Utils.get_actor() .. ' sent a popup to all players', false) Utils.print_admins(Utils.get_actor() .. ' sent a popup to all players', nil)
end end
-- Creates a popup dialog for all players, specifically for the server upgrading factorio versions -- Creates a popup dialog for all players, specifically for the server upgrading factorio versions
local function popup_update(cmd) local function popup_update(args)
local player = game.player local message = 'Server is updating to ' .. args.version .. '\nWe will be back in a minute'
if player and not player.admin then
Utils.cant_run(cmd.name)
return
end
if not cmd.parameter then
Game.player_print('Usage: /popup-update <factorio_version>')
return
end
local message = 'Server is updating to ' .. cmd.parameter .. '\nWe will be back in a minute'
for _, p in ipairs(game.connected_players) do for _, p in ipairs(game.connected_players) do
show_popup(p, message, "Incoming update!", 11) show_popup(p, message, "Incoming update!", 11)
end end
Game.player_print('Popup sent') Game.player_print('Popup sent')
Utils.print_admins(Utils.get_actor() .. ' sent a popup to all players', false) Utils.print_admins(Utils.get_actor() .. ' sent a popup to all players', nil)
end end
-- Creates a popup dialog for the specifically targetted player -- Creates a popup dialog for the specifically targetted player
local function popup_player(cmd) local function popup_player(args)
local player = game.player local target_name = args.player
if player and not player.admin then
Utils.cant_run(cmd.name)
return
end
local message = cmd.parameter
if not message then
Game.player_print('Usage: /popup <player> <message>')
return
end
local start_index, end_index = message:find(' ')
if not start_index then
Game.player_print('Usage: /popup <player> <message>')
return
end
local target_name = message:sub(1, start_index - 1)
local target = game.players[target_name] local target = game.players[target_name]
if not target then if not target then
Game.player_print('Player ' .. target_name .. ' not found.') Game.player_print('Player ' .. target_name .. ' not found.')
return return
end end
message = message:sub(end_index, #message):gsub('\\n', '\n') local message = args.message:gsub('\\n', '\n')
show_popup(target, message) show_popup(target, message)
Game.player_print('Popup sent') Game.player_print('Popup sent')
end end
commands.add_command('popup', '<message> - Shows a popup to all connected players (Admins only)', popup) Command.add(
'popup',
{
description = 'Shows a popup to all connected players',
arguments = {'message'},
admin_only = true,
capture_excess_arguments = true,
allowed_by_server = true
},
popup
)
commands.add_command( Command.add(
'popup-update', 'popup-update',
'<version> - Shows an update popup to all connected players (Admins only)', {
description = 'Shows an update popup to all connected players',
arguments = {'version'},
admin_only = true,
capture_excess_arguments = true,
allowed_by_server = true
},
popup_update popup_update
) )
commands.add_command('popup-player', '<player> <message> - Shows a popup to the players (Admins only)', popup_player) Command.add(
'popup-player',
{
description = 'Shows a popup to the player.',
arguments = {'player', 'message'},
admin_only = true,
capture_excess_arguments = true,
allowed_by_server = true
},
popup_player
)
local Public = {} local Public = {}
@ -184,7 +171,7 @@ local Public = {}
]] ]]
function Public.player(player, message, title, icon_id) function Public.player(player, message, title, icon_id)
show_popup(player, message, title, icon_id) show_popup(player, message, title, icon_id)
end end
--[[-- --[[--
Shows a popup dialog to all connected players. Shows a popup dialog to all connected players.