mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
Many fixes and tweaks
This commit is contained in:
parent
e0e536a83a
commit
e0b59e5fe6
@ -6,6 +6,11 @@ local table = require 'utils.table'
|
||||
local Global = require 'utils.global'
|
||||
local Task = require 'utils.task'
|
||||
|
||||
local concat = table.concat
|
||||
local insert = table.insert
|
||||
|
||||
local donator_data_set = 'donators'
|
||||
|
||||
local donators = {} -- global register
|
||||
|
||||
Global.register(
|
||||
@ -48,7 +53,7 @@ local function player_joined(event)
|
||||
return
|
||||
end
|
||||
|
||||
message = table.concat({'*** ', message, ' ***'})
|
||||
message = concat({'*** ', message, ' ***'})
|
||||
Task.set_timeout_in_ticks(60, print_after_timeout, {player = player, message = message})
|
||||
end
|
||||
|
||||
@ -79,36 +84,49 @@ end
|
||||
|
||||
--- Sets the data for a donator
|
||||
-- @param player_name <string>
|
||||
-- @param data <table> a table containing perk_flags and welcome_messages
|
||||
-- @param data <table>
|
||||
-- @return <string|nil>
|
||||
function Public.set_donator(player_name, data)
|
||||
function Public.set_donator_data(player_name, data)
|
||||
donators[player_name] = data
|
||||
Server.set_data('donators', player_name, data)
|
||||
Server.set_data(donator_data_set, player_name, data)
|
||||
end
|
||||
|
||||
--- Changes the data for a donator with any data that is sent, but does not change any other
|
||||
-- @param player_name <string>
|
||||
-- @param data <table>
|
||||
-- @return <string|nil>
|
||||
function Public.change_donator_data(player_name, data)
|
||||
for k, v in pairs(data) do
|
||||
donators[player_name][k] = v
|
||||
end
|
||||
|
||||
Server.set_data(donator_data_set, player_name, donators[player_name])
|
||||
end
|
||||
|
||||
--- Clears the player_ranks table and merges the entries into it
|
||||
local sync_donators_callback =
|
||||
Token.register(
|
||||
function(data)
|
||||
table.clear_table(donators)
|
||||
table.merge({donators, data.entries})
|
||||
for k, v in pairs(data.entries) do
|
||||
donators[k] = v
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
--- Signals the server to retrieve the donators data set
|
||||
function Public.sync_donators()
|
||||
Server.try_get_all_data('donators', sync_donators_callback)
|
||||
Server.try_get_all_data(donator_data_set, sync_donators_callback)
|
||||
end
|
||||
|
||||
--- Prints a list of donators
|
||||
function Public.print_donators()
|
||||
local result = {}
|
||||
|
||||
for k, _ in pairs(global.donators) do
|
||||
table.insert(result, k)
|
||||
for k, _ in pairs(donators) do
|
||||
insert(result, k)
|
||||
end
|
||||
|
||||
result = table.concat(result, ', ')
|
||||
result = concat(result, ', ')
|
||||
Game.player_print(result)
|
||||
end
|
||||
|
||||
@ -120,14 +138,12 @@ Event.add(
|
||||
)
|
||||
|
||||
Server.on_data_set_changed(
|
||||
'donators',
|
||||
donator_data_set,
|
||||
function(data)
|
||||
global.donators[data.key] = data.value
|
||||
donators[data.key] = data.value
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
|
||||
Event.add(defines.events.on_player_joined_game, player_joined)
|
||||
|
||||
return Public
|
||||
|
@ -2,7 +2,7 @@ local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local Gui = require 'utils.gui'
|
||||
local Rank = require 'features.rank_system'
|
||||
local Donator = require 'features.Donator'
|
||||
local Donator = require 'features.donator'
|
||||
local PlayerStats = require 'features.player_stats'
|
||||
local Utils = require 'utils.core'
|
||||
local Report = require 'features.report'
|
||||
|
@ -22,7 +22,6 @@ local Config = global.config.rank_system
|
||||
|
||||
-- Localized functions
|
||||
local format = string.format
|
||||
local index_in_array = table.index_of_in_array
|
||||
local clamp = math.clamp
|
||||
|
||||
-- Constants
|
||||
@ -107,12 +106,13 @@ local function check_promote_to_auto_trusted()
|
||||
end
|
||||
end
|
||||
|
||||
--- Clears the player_ranks table and merges the entries into it
|
||||
--- On callback, overwrites player rank entries with data entries
|
||||
local sync_ranks_callback =
|
||||
Token.register(
|
||||
function(data)
|
||||
table.clear_table(player_ranks)
|
||||
table.merge({player_ranks, data.entries})
|
||||
for k, v in pairs(data.entries) do
|
||||
player_ranks[k] = v
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
@ -309,6 +309,10 @@ end
|
||||
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined)
|
||||
|
||||
Event.add(Server.events.on_server_started, Public.sync_ranks)
|
||||
|
||||
Event.on_nth_tick(nth_tick, check_promote_to_auto_trusted)
|
||||
|
||||
Server.on_data_set_changed(
|
||||
ranking_data_set,
|
||||
function(data)
|
||||
@ -316,36 +320,4 @@ Server.on_data_set_changed(
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
Event.add(
|
||||
Server.events.on_server_started,
|
||||
function()
|
||||
Public.sync_rankings()
|
||||
end
|
||||
)
|
||||
|
||||
Event.on_nth_tick(nth_tick, check_promote_to_auto_trusted)
|
||||
|
||||
if _DEBUG then
|
||||
--- Takes a table of old ranks, converts those ranks to correcponding entries in new_ranks and uploads everything to the upload_target dataset
|
||||
-- @param old_ranks <table> an array of ranks you want to change *from*
|
||||
-- @param new_ranks <table> an array of ranks you want to change *to*
|
||||
-- Note: old_ranks and new_ranks must have the same index key
|
||||
-- @param upload_target <string> the data set to upload to (this way you can test your migration to a dummy data set before changing the real one)
|
||||
-- @param yes_im_sure <boolean> Are you really sure you want to change the existing data set?
|
||||
function Public.migrate_data(old_ranks, new_ranks, upload_target, yes_im_sure)
|
||||
if ranking_data_set == upload_target and not yes_im_sure then
|
||||
return
|
||||
end
|
||||
|
||||
for k, v in pairs(player_ranks) do
|
||||
local index = index_in_array(old_ranks, v)
|
||||
if index then
|
||||
player_ranks[k] = new_ranks[index]
|
||||
end
|
||||
Server.set_data(upload_target, k, player_ranks[k])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Public
|
||||
|
@ -2,7 +2,6 @@
|
||||
local random = math.random
|
||||
local floor = math.floor
|
||||
local remove = table.remove
|
||||
local insert = table.insert
|
||||
local tonumber = tonumber
|
||||
local pairs = pairs
|
||||
local table_size = table_size
|
||||
@ -40,7 +39,7 @@ end
|
||||
function table.add_all(t1, t2)
|
||||
for k, v in pairs(t2) do
|
||||
if tonumber(k) then
|
||||
insert(t1, v)
|
||||
t1[#t1 + 1] = v
|
||||
else
|
||||
t1[k] = v
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user