1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-04 09:42:30 +02:00

Add players' logistic requests synch between instances (#1401)

This commit is contained in:
RedRafe 2024-03-08 20:32:09 +01:00 committed by GitHub
parent 6f5713b451
commit 2efc9b2604
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 396 additions and 149 deletions

View File

@ -398,10 +398,14 @@ global.config = {
first_launch_only = true
}
},
-- allows the saving and automatic loading of quickbars between maps
-- allows the (manual) saving and then (automatic) loading of players' quickbars between maps
player_quick_bars = {
enabled = true
},
-- allows the (manual) saving and then (automatic) loading of players' logistc requests between maps
player_logistic_requests = {
enabled = true
},
-- enables the redmew settings GUI
redmew_settings = {
enabled = true

View File

@ -105,6 +105,9 @@ end
if config.player_quick_bars.enabled then
require 'features.player_quick_bars'
end
if config.player_logistic_requests.enabled then
require 'features.player_logistic_requests'
end
if config.biter_corpse_remover.enabled then
require 'features.biter_corpse_remover'
end

View File

@ -0,0 +1,228 @@
-- This module saves players' logistic requests slots between maps
-- Dependencies
local Command = require 'utils.command'
local Event = require 'utils.event'
local Game = require 'utils.game'
local Global = require 'utils.global'
local Server = require 'features.server'
local Token = require 'utils.token'
local Color = require 'resources.color_presets'
local Ranks = require 'resources.ranks'
-- Constants
local data_set_name = 'player_logistic_requests'
local logistic_slots = 100
-- Localized globals
local primitives = {
server_available = nil
}
local initialized_players = {}
local initialized_forces = {}
Global.register(
{
primitives = primitives,
initialized_players = initialized_players,
initialized_forces = initialized_forces
},
function(tbl)
primitives = tbl.primitives
initialized_players = tbl.initialized_players
initialized_forces = tbl.initialized_forces
end
)
--- Scans all player's logistic request slots into a table, then saves that table server-side
local function save_bars(_, player)
if not primitives.server_available then
Game.player_print({'common.server_unavailable'}, Color.fail)
return
end
-- Player's force doesn't have logistics
local force = player.force
if not (force and force.character_logistic_requests) then
Game.player_print({'player_logistic_requests.logistics_not_available'}, Color.fail)
return
end
local bars = {}
for i = 1, logistic_slots do
local item_prot = player.get_personal_logistic_slot(i)
if item_prot and item_prot.name then
bars[i] = item_prot
end
end
Server.set_data(data_set_name, player.name, bars)
Game.player_print({'player_logistic_requests.save_bars'}, Color.success)
end
--- Returns a valid entity prototype string name or nil.
-- For invalid items, a message will be printed to the player.
local function validate_entry(item, proto_table, player)
if not (item and item.name) then
return
end
if proto_table[item.name] then
return item
end
player.print({'player_logistic_requests.incompatible_item', item.name}, Color.warning)
end
--- Sets the logistic request slots of a player.
local set_bars_callback =
Token.register(
function(data)
local bars = data.value -- will be nil if no data
if not bars then
return
end
-- Invalid player
local p_name = data.key
local player = game.get_player(p_name)
if not (player and player.valid )then
return
end
local item_prototypes = game.item_prototypes
local item
for i = 1, logistic_slots do
item = validate_entry(bars[i], item_prototypes, player)
if item then
player.set_personal_logistic_slot(i, item) -- false if personal logistics are not researched yet.
end
end
initialized_players[player.name] = true
end
)
--- Calls data from the server and sends it to the set_bars_callback
local function load_bars(_, player)
if not primitives.server_available then
Game.player_print({'common.server_unavailable'}, Color.fail)
return
end
-- Player's force doesn't have logistics
local force = player.force
if not (force and force.character_logistic_requests) then
Game.player_print({'player_logistic_requests.logistics_not_available'}, Color.fail)
return
end
Server.try_get_data(data_set_name, player.name, set_bars_callback)
Game.player_print({'player_logistic_requests.load_bars'})
end
-- Auto loads all logistic requests for players joining after logistics has been researched
local player_joined_game =
Token.register(
function(event)
-- Invalid player
local player = game.get_player(event.player_index)
if not (player and player.valid) then
return
end
-- Player already initialized
if initialized_players[player.name] then
return
end
-- Player's force doesn't have logistics
local force = player.force
if not (force and force.character_logistic_requests) then
return
end
Server.try_get_data(data_set_name, player.name, set_bars_callback)
end
)
--- Auto loads all logistic requests for connected players when logistics gets researched
local research_finished =
Token.register(
function(event)
-- Invalid tech
local tech = event.research
if not (tech and tech.valid) then
return
end
-- Already init. or logistics not available
local force = tech.force
if not force or initialized_forces[force.name] or not force.character_logistic_requests then
return
end
for _, player in pairs(force.connected_players) do
if player and player.valid and player.character and player.character.valid then
if not initialized_players[player.name] then
Server.try_get_data(data_set_name, player.name, set_bars_callback)
end
end
end
initialized_forces[force.name] = true
end
)
--- Registers the event only when the server is available.
local function register_server_start_events()
if not primitives.server_available then
Event.add_removable(defines.events.on_player_joined_game, player_joined_game)
Event.add_removable(defines.events.on_research_finished, research_finished)
primitives.server_available = true
end
end
--- Erases server-side data stored for this player's logistic requests slots
local function delete_bars(_, player)
if not primitives.server_available then
Game.player_print({'common.server_unavailable'}, Color.fail)
return
end
Server.set_data(data_set_name, player.name, nil)
Game.player_print({'player_logistic_requests.delete_bars'}, Color.success)
end
-- Events
Event.add(Server.events.on_server_started, register_server_start_events)
-- Commands
Command.add(
'logistic-requests-save',
{
description = {'command_description.logistic_requests_save'},
required_rank = Ranks.regular
},
save_bars
)
Command.add(
'logistic-requests-load',
{
description = {'command_description.logistic_requests_load'},
required_rank = Ranks.regular
},
load_bars
)
Command.add(
'logistic-requests-delete',
{
description = {'command_description.logistic_requests_delete'},
required_rank = Ranks.regular
},
delete_bars
)

View File

@ -105,9 +105,12 @@ invoke=Teleports the player to you.
tp=If blank, teleport to selected entity. mode = toggle tp mode where you can teleport to a placed ghost. player = teleport to player.
revive_ghosts=Revives the ghosts within the provided radius around you
destroy=Destroys the entity under your cursor when you run this command
quick_bar_save=Saves your quick bars server-side for future maps
quick_bar_load=Loads your quick bars from the server (overwriting existing bars)
quick_bar_delete=Erases your saved quick bars from the server
quick_bar_save=Saves your [color=yellow]quick bars[/color] server-side for future maps
quick_bar_load=Loads your [color=yellow]quick bars[/color] from the server (overwriting existing bars)
quick_bar_delete=Erases your saved [color=yellow]quick bars[/color] from the server
logistic_requests_save=Saves your [color=blue]logistic requests[/color] server-side for future maps
logistic_requests_load=Loads your [color=blue]logistic requests[/color] from the server (overwriting existing bars)
logistic_requests_delete=Erases your saved [color=blue]logistic requests[/color] from the server
set_pollution_multiplier=EXPERIMENTAL. An integer which gets multiplied by 0.01 to give the amount of pollution crash site magic crafters emit. Default is 0
get_pollution_multiplier=The current pollution multiplier for crash site. The default is 0.
perks=Lists Patreon donators that are contributing to currently active perks.

View File

@ -133,6 +133,13 @@ load_bars=Attempting to load bars from server...
delete_bars=Saved data has been removed from the server.
incompatible_item=Incompatible item found in saved data and will not be loaded: __1__
[player_logistic_requests]
save_bars=Your logistic requests have been saved to the server.
load_bars=Attempting to load logistic requests from server...
delete_bars=Saved data has been removed from the server.
logistics_not_available=Command failed: player's logistics not available
incompatible_item=Incompatible item found in saved data and will not be loaded: __1__
[player_stats]
rocks_smashed=Rocks smashed
trees_cut_down=Trees cut down

View File

@ -1,149 +1,6 @@
-- source: https://www.rapidtables.com/web/color/RGB_Color.html
return {
maroon = {r = 128, g = 0, b = 0},
dark_red = {r = 139, g = 0, b = 0},
brown = {r = 165, g = 42, b = 42},
firebrick = {r = 178, g = 34, b = 34},
crimson = {r = 220, g = 20, b = 60},
red = {r = 255, g = 0, b = 0},
tomato = {r = 255, g = 99, b = 71},
coral = {r = 255, g = 127, b = 80},
indian_red = {r = 205, g = 92, b = 92},
light_coral = {r = 240, g = 128, b = 128},
dark_salmon = {r = 233, g = 150, b = 122},
salmon = {r = 250, g = 128, b = 114},
light_salmon = {r = 255, g = 160, b = 122},
orange_red = {r = 255, g = 69, b = 0},
dark_orange = {r = 255, g = 140, b = 0},
orange = {r = 255, g = 165, b = 0},
gold = {r = 255, g = 215, b = 0},
dark_golden_rod = {r = 184, g = 134, b = 11},
golden_rod = {r = 218, g = 165, b = 32},
pale_golden_rod = {r = 238, g = 232, b = 170},
dark_khaki = {r = 189, g = 183, b = 107},
khaki = {r = 240, g = 230, b = 140},
olive = {r = 128, g = 128, b = 0},
yellow = {r = 255, g = 255, b = 0},
yellow_green = {r = 154, g = 205, b = 50},
dark_olive_green = {r = 85, g = 107, b = 47},
olive_drab = {r = 107, g = 142, b = 35},
lawn_green = {r = 124, g = 252, b = 0},
chart_reuse = {r = 127, g = 255, b = 0},
green_yellow = {r = 173, g = 255, b = 47},
dark_green = {r = 0, g = 100, b = 0},
green = {r = 0, g = 128, b = 0},
forest_green = {r = 34, g = 139, b = 34},
lime = {r = 0, g = 255, b = 0},
lime_green = {r = 50, g = 205, b = 50},
light_green = {r = 144, g = 238, b = 144},
pale_green = {r = 152, g = 251, b = 152},
dark_sea_green = {r = 143, g = 188, b = 143},
medium_spring_green = {r = 0, g = 250, b = 154},
spring_green = {r = 0, g = 255, b = 127},
sea_green = {r = 46, g = 139, b = 87},
medium_aqua_marine = {r = 102, g = 205, b = 170},
medium_sea_green = {r = 60, g = 179, b = 113},
light_sea_green = {r = 32, g = 178, b = 170},
dark_slate_gray = {r = 47, g = 79, b = 79},
teal = {r = 0, g = 128, b = 128},
dark_cyan = {r = 0, g = 139, b = 139},
aqua = {r = 0, g = 255, b = 255},
cyan = {r = 0, g = 255, b = 255},
light_cyan = {r = 224, g = 255, b = 255},
dark_turquoise = {r = 0, g = 206, b = 209},
turquoise = {r = 64, g = 224, b = 208},
medium_turquoise = {r = 72, g = 209, b = 204},
pale_turquoise = {r = 175, g = 238, b = 238},
aqua_marine = {r = 127, g = 255, b = 212},
powder_blue = {r = 176, g = 224, b = 230},
cadet_blue = {r = 95, g = 158, b = 160},
steel_blue = {r = 70, g = 130, b = 180},
corn_flower_blue = {r = 100, g = 149, b = 237},
deep_sky_blue = {r = 0, g = 191, b = 255},
dodger_blue = {r = 30, g = 144, b = 255},
light_blue = {r = 173, g = 216, b = 230},
sky_blue = {r = 135, g = 206, b = 235},
light_sky_blue = {r = 135, g = 206, b = 250},
midnight_blue = {r = 25, g = 25, b = 112},
navy = {r = 0, g = 0, b = 128},
dark_blue = {r = 0, g = 0, b = 139},
medium_blue = {r = 0, g = 0, b = 205},
blue = {r = 0, g = 0, b = 255},
royal_blue = {r = 65, g = 105, b = 225},
blue_violet = {r = 138, g = 43, b = 226},
indigo = {r = 75, g = 0, b = 130},
dark_slate_blue = {r = 72, g = 61, b = 139},
slate_blue = {r = 106, g = 90, b = 205},
medium_slate_blue = {r = 123, g = 104, b = 238},
medium_purple = {r = 147, g = 112, b = 219},
dark_magenta = {r = 139, g = 0, b = 139},
dark_violet = {r = 148, g = 0, b = 211},
dark_orchid = {r = 153, g = 50, b = 204},
medium_orchid = {r = 186, g = 85, b = 211},
purple = {r = 128, g = 0, b = 128},
thistle = {r = 216, g = 191, b = 216},
plum = {r = 221, g = 160, b = 221},
violet = {r = 238, g = 130, b = 238},
magenta = {r = 255, g = 0, b = 255},
fuchsia = {r = 255, g = 0, b = 255},
orchid = {r = 218, g = 112, b = 214},
medium_violet_red = {r = 199, g = 21, b = 133},
pale_violet_red = {r = 219, g = 112, b = 147},
deep_pink = {r = 255, g = 20, b = 147},
hot_pink = {r = 255, g = 105, b = 180},
light_pink = {r = 255, g = 182, b = 193},
pink = {r = 255, g = 192, b = 203},
antique_white = {r = 250, g = 235, b = 215},
beige = {r = 245, g = 245, b = 220},
bisque = {r = 255, g = 228, b = 196},
blanched_almond = {r = 255, g = 235, b = 205},
wheat = {r = 245, g = 222, b = 179},
corn_silk = {r = 255, g = 248, b = 220},
lemon_chiffon = {r = 255, g = 250, b = 205},
light_golden_rod_yellow = {r = 250, g = 250, b = 210},
light_yellow = {r = 255, g = 255, b = 224},
saddle_brown = {r = 139, g = 69, b = 19},
sienna = {r = 160, g = 82, b = 45},
chocolate = {r = 210, g = 105, b = 30},
peru = {r = 205, g = 133, b = 63},
sandy_brown = {r = 244, g = 164, b = 96},
burly_wood = {r = 222, g = 184, b = 135},
tan = {r = 210, g = 180, b = 140},
rosy_brown = {r = 188, g = 143, b = 143},
moccasin = {r = 255, g = 228, b = 181},
navajo_white = {r = 255, g = 222, b = 173},
peach_puff = {r = 255, g = 218, b = 185},
misty_rose = {r = 255, g = 228, b = 225},
lavender_blush = {r = 255, g = 240, b = 245},
linen = {r = 250, g = 240, b = 230},
old_lace = {r = 253, g = 245, b = 230},
papaya_whip = {r = 255, g = 239, b = 213},
sea_shell = {r = 255, g = 245, b = 238},
mint_cream = {r = 245, g = 255, b = 250},
slate_gray = {r = 112, g = 128, b = 144},
light_slate_gray = {r = 119, g = 136, b = 153},
light_steel_blue = {r = 176, g = 196, b = 222},
lavender = {r = 230, g = 230, b = 250},
floral_white = {r = 255, g = 250, b = 240},
alice_blue = {r = 240, g = 248, b = 255},
ghost_white = {r = 248, g = 248, b = 255},
honeydew = {r = 240, g = 255, b = 240},
ivory = {r = 255, g = 255, b = 240},
azure = {r = 240, g = 255, b = 255},
snow = {r = 255, g = 250, b = 250},
black = {r = 0, g = 0, b = 0},
silver = {r = 192, g = 192, b = 192},
dim_grey = {r = 105, g = 105, b = 105},
dim_gray = {r = 105, g = 105, b = 105},
grey = {r = 128, g = 128, b = 128},
gray = {r = 128, g = 128, b = 128},
dark_grey = {r = 169, g = 169, b = 169},
dark_gray = {r = 169, g = 169, b = 169},
light_grey = {r = 211, g = 211, b = 211},
light_gray = {r = 211, g = 211, b = 211},
gainsboro = {r = 220, g = 220, b = 220},
white_smoke = {r = 245, g = 245, b = 245},
white = {r = 255, g = 255, b = 255},
--- RedMew's colors
jailed = {r = 255, g = 255, b = 255},
probation = {r = 255, g = 255, b = 255},
guest = {r = 255, g = 255, b = 255},
@ -159,5 +16,150 @@ return {
success = {r = 0, g = 255, b = 0},
warning = {r = 255, g = 255, b = 0},
fail = {r = 255, g = 0, b = 0},
info = {r = 255, g = 255, b = 255}
info = {r = 255, g = 255, b = 255},
--- Color dictionary
alice_blue = {r = 240, g = 248, b = 255},
antique_white = {r = 250, g = 235, b = 215},
aqua = {r = 0, g = 255, b = 255},
aqua_marine = {r = 127, g = 255, b = 212},
azure = {r = 240, g = 255, b = 255},
beige = {r = 245, g = 245, b = 220},
bisque = {r = 255, g = 228, b = 196},
black = {r = 0, g = 0, b = 0},
blanched_almond = {r = 255, g = 235, b = 205},
blue = {r = 0, g = 0, b = 255},
blue_violet = {r = 138, g = 43, b = 226},
brown = {r = 165, g = 42, b = 42},
burly_wood = {r = 222, g = 184, b = 135},
cadet_blue = {r = 95, g = 158, b = 160},
chart_reuse = {r = 127, g = 255, b = 0},
chocolate = {r = 210, g = 105, b = 30},
coral = {r = 255, g = 127, b = 80},
corn_flower_blue = {r = 100, g = 149, b = 237},
corn_silk = {r = 255, g = 248, b = 220},
crimson = {r = 220, g = 20, b = 60},
cyan = {r = 0, g = 255, b = 255},
dark_blue = {r = 0, g = 0, b = 139},
dark_cyan = {r = 0, g = 139, b = 139},
dark_golden_rod = {r = 184, g = 134, b = 11},
dark_gray = {r = 169, g = 169, b = 169},
dark_green = {r = 0, g = 100, b = 0},
dark_grey = {r = 169, g = 169, b = 169},
dark_khaki = {r = 189, g = 183, b = 107},
dark_magenta = {r = 139, g = 0, b = 139},
dark_olive_green = {r = 85, g = 107, b = 47},
dark_orange = {r = 255, g = 140, b = 0},
dark_orchid = {r = 153, g = 50, b = 204},
dark_red = {r = 139, g = 0, b = 0},
dark_salmon = {r = 233, g = 150, b = 122},
dark_sea_green = {r = 143, g = 188, b = 143},
dark_slate_blue = {r = 72, g = 61, b = 139},
dark_slate_gray = {r = 47, g = 79, b = 79},
dark_turquoise = {r = 0, g = 206, b = 209},
dark_violet = {r = 148, g = 0, b = 211},
deep_pink = {r = 255, g = 20, b = 147},
deep_sky_blue = {r = 0, g = 191, b = 255},
dim_gray = {r = 105, g = 105, b = 105},
dim_grey = {r = 105, g = 105, b = 105},
dodger_blue = {r = 30, g = 144, b = 255},
firebrick = {r = 178, g = 34, b = 34},
floral_white = {r = 255, g = 250, b = 240},
forest_green = {r = 34, g = 139, b = 34},
fuchsia = {r = 255, g = 0, b = 255},
gainsboro = {r = 220, g = 220, b = 220},
ghost_white = {r = 248, g = 248, b = 255},
gold = {r = 255, g = 215, b = 0},
golden_rod = {r = 218, g = 165, b = 32},
gray = {r = 128, g = 128, b = 128},
green = {r = 0, g = 128, b = 0},
green_yellow = {r = 173, g = 255, b = 47},
grey = {r = 128, g = 128, b = 128},
honeydew = {r = 240, g = 255, b = 240},
hot_pink = {r = 255, g = 105, b = 180},
indian_red = {r = 205, g = 92, b = 92},
indigo = {r = 75, g = 0, b = 130},
ivory = {r = 255, g = 255, b = 240},
khaki = {r = 240, g = 230, b = 140},
lavender = {r = 230, g = 230, b = 250},
lavender_blush = {r = 255, g = 240, b = 245},
lawn_green = {r = 124, g = 252, b = 0},
lemon_chiffon = {r = 255, g = 250, b = 205},
light_blue = {r = 173, g = 216, b = 230},
light_coral = {r = 240, g = 128, b = 128},
light_cyan = {r = 224, g = 255, b = 255},
light_golden_rod_yellow = {r = 250, g = 250, b = 210},
light_gray = {r = 211, g = 211, b = 211},
light_green = {r = 144, g = 238, b = 144},
light_grey = {r = 211, g = 211, b = 211},
light_pink = {r = 255, g = 182, b = 193},
light_salmon = {r = 255, g = 160, b = 122},
light_sea_green = {r = 32, g = 178, b = 170},
light_sky_blue = {r = 135, g = 206, b = 250},
light_slate_gray = {r = 119, g = 136, b = 153},
light_steel_blue = {r = 176, g = 196, b = 222},
light_yellow = {r = 255, g = 255, b = 224},
lime = {r = 0, g = 255, b = 0},
lime_green = {r = 50, g = 205, b = 50},
linen = {r = 250, g = 240, b = 230},
magenta = {r = 255, g = 0, b = 255},
maroon = {r = 128, g = 0, b = 0},
medium_aqua_marine = {r = 102, g = 205, b = 170},
medium_blue = {r = 0, g = 0, b = 205},
medium_orchid = {r = 186, g = 85, b = 211},
medium_purple = {r = 147, g = 112, b = 219},
medium_sea_green = {r = 60, g = 179, b = 113},
medium_slate_blue = {r = 123, g = 104, b = 238},
medium_spring_green = {r = 0, g = 250, b = 154},
medium_turquoise = {r = 72, g = 209, b = 204},
medium_violet_red = {r = 199, g = 21, b = 133},
midnight_blue = {r = 25, g = 25, b = 112},
mint_cream = {r = 245, g = 255, b = 250},
misty_rose = {r = 255, g = 228, b = 225},
moccasin = {r = 255, g = 228, b = 181},
navajo_white = {r = 255, g = 222, b = 173},
navy = {r = 0, g = 0, b = 128},
old_lace = {r = 253, g = 245, b = 230},
olive = {r = 128, g = 128, b = 0},
olive_drab = {r = 107, g = 142, b = 35},
orange = {r = 255, g = 165, b = 0},
orange_red = {r = 255, g = 69, b = 0},
orchid = {r = 218, g = 112, b = 214},
pale_golden_rod = {r = 238, g = 232, b = 170},
pale_green = {r = 152, g = 251, b = 152},
pale_turquoise = {r = 175, g = 238, b = 238},
pale_violet_red = {r = 219, g = 112, b = 147},
papaya_whip = {r = 255, g = 239, b = 213},
peach_puff = {r = 255, g = 218, b = 185},
peru = {r = 205, g = 133, b = 63},
pink = {r = 255, g = 192, b = 203},
plum = {r = 221, g = 160, b = 221},
powder_blue = {r = 176, g = 224, b = 230},
purple = {r = 128, g = 0, b = 128},
red = {r = 255, g = 0, b = 0},
rosy_brown = {r = 188, g = 143, b = 143},
royal_blue = {r = 65, g = 105, b = 225},
saddle_brown = {r = 139, g = 69, b = 19},
salmon = {r = 250, g = 128, b = 114},
sandy_brown = {r = 244, g = 164, b = 96},
sea_green = {r = 46, g = 139, b = 87},
sea_shell = {r = 255, g = 245, b = 238},
sienna = {r = 160, g = 82, b = 45},
silver = {r = 192, g = 192, b = 192},
sky_blue = {r = 135, g = 206, b = 235},
slate_blue = {r = 106, g = 90, b = 205},
slate_gray = {r = 112, g = 128, b = 144},
snow = {r = 255, g = 250, b = 250},
spring_green = {r = 0, g = 255, b = 127},
steel_blue = {r = 70, g = 130, b = 180},
tan = {r = 210, g = 180, b = 140},
teal = {r = 0, g = 128, b = 128},
thistle = {r = 216, g = 191, b = 216},
tomato = {r = 255, g = 99, b = 71},
turquoise = {r = 64, g = 224, b = 208},
violet = {r = 238, g = 130, b = 238},
wheat = {r = 245, g = 222, b = 179},
white = {r = 255, g = 255, b = 255},
white_smoke = {r = 245, g = 245, b = 245},
yellow = {r = 255, g = 255, b = 0},
yellow_green = {r = 154, g = 205, b = 50},
}