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 Global = require 'utils.global'
|
||||||
local Task = require 'utils.task'
|
local Task = require 'utils.task'
|
||||||
|
|
||||||
|
local concat = table.concat
|
||||||
|
local insert = table.insert
|
||||||
|
|
||||||
|
local donator_data_set = 'donators'
|
||||||
|
|
||||||
local donators = {} -- global register
|
local donators = {} -- global register
|
||||||
|
|
||||||
Global.register(
|
Global.register(
|
||||||
@ -48,7 +53,7 @@ local function player_joined(event)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
message = table.concat({'*** ', message, ' ***'})
|
message = concat({'*** ', message, ' ***'})
|
||||||
Task.set_timeout_in_ticks(60, print_after_timeout, {player = player, message = message})
|
Task.set_timeout_in_ticks(60, print_after_timeout, {player = player, message = message})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -79,36 +84,49 @@ end
|
|||||||
|
|
||||||
--- Sets the data for a donator
|
--- Sets the data for a donator
|
||||||
-- @param player_name <string>
|
-- @param player_name <string>
|
||||||
-- @param data <table> a table containing perk_flags and welcome_messages
|
-- @param data <table>
|
||||||
-- @return <string|nil>
|
-- @return <string|nil>
|
||||||
function Public.set_donator(player_name, data)
|
function Public.set_donator_data(player_name, data)
|
||||||
donators[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
|
end
|
||||||
|
|
||||||
--- Clears the player_ranks table and merges the entries into it
|
--- Clears the player_ranks table and merges the entries into it
|
||||||
local sync_donators_callback =
|
local sync_donators_callback =
|
||||||
Token.register(
|
Token.register(
|
||||||
function(data)
|
function(data)
|
||||||
table.clear_table(donators)
|
for k, v in pairs(data.entries) do
|
||||||
table.merge({donators, data.entries})
|
donators[k] = v
|
||||||
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
--- Signals the server to retrieve the donators data set
|
--- Signals the server to retrieve the donators data set
|
||||||
function Public.sync_donators()
|
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
|
end
|
||||||
|
|
||||||
--- Prints a list of donators
|
--- Prints a list of donators
|
||||||
function Public.print_donators()
|
function Public.print_donators()
|
||||||
local result = {}
|
local result = {}
|
||||||
|
|
||||||
for k, _ in pairs(global.donators) do
|
for k, _ in pairs(donators) do
|
||||||
table.insert(result, k)
|
insert(result, k)
|
||||||
end
|
end
|
||||||
|
|
||||||
result = table.concat(result, ', ')
|
result = concat(result, ', ')
|
||||||
Game.player_print(result)
|
Game.player_print(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -120,14 +138,12 @@ Event.add(
|
|||||||
)
|
)
|
||||||
|
|
||||||
Server.on_data_set_changed(
|
Server.on_data_set_changed(
|
||||||
'donators',
|
donator_data_set,
|
||||||
function(data)
|
function(data)
|
||||||
global.donators[data.key] = data.value
|
donators[data.key] = data.value
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Event.add(defines.events.on_player_joined_game, player_joined)
|
Event.add(defines.events.on_player_joined_game, player_joined)
|
||||||
|
|
||||||
return Public
|
return Public
|
||||||
|
@ -2,7 +2,7 @@ local Event = require 'utils.event'
|
|||||||
local Global = require 'utils.global'
|
local Global = require 'utils.global'
|
||||||
local Gui = require 'utils.gui'
|
local Gui = require 'utils.gui'
|
||||||
local Rank = require 'features.rank_system'
|
local Rank = require 'features.rank_system'
|
||||||
local Donator = require 'features.Donator'
|
local Donator = require 'features.donator'
|
||||||
local PlayerStats = require 'features.player_stats'
|
local PlayerStats = require 'features.player_stats'
|
||||||
local Utils = require 'utils.core'
|
local Utils = require 'utils.core'
|
||||||
local Report = require 'features.report'
|
local Report = require 'features.report'
|
||||||
|
@ -22,7 +22,6 @@ local Config = global.config.rank_system
|
|||||||
|
|
||||||
-- Localized functions
|
-- Localized functions
|
||||||
local format = string.format
|
local format = string.format
|
||||||
local index_in_array = table.index_of_in_array
|
|
||||||
local clamp = math.clamp
|
local clamp = math.clamp
|
||||||
|
|
||||||
-- Constants
|
-- Constants
|
||||||
@ -107,12 +106,13 @@ local function check_promote_to_auto_trusted()
|
|||||||
end
|
end
|
||||||
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 =
|
local sync_ranks_callback =
|
||||||
Token.register(
|
Token.register(
|
||||||
function(data)
|
function(data)
|
||||||
table.clear_table(player_ranks)
|
for k, v in pairs(data.entries) do
|
||||||
table.merge({player_ranks, data.entries})
|
player_ranks[k] = v
|
||||||
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -309,6 +309,10 @@ end
|
|||||||
|
|
||||||
Event.add(defines.events.on_player_joined_game, on_player_joined)
|
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(
|
Server.on_data_set_changed(
|
||||||
ranking_data_set,
|
ranking_data_set,
|
||||||
function(data)
|
function(data)
|
||||||
@ -316,36 +320,4 @@ Server.on_data_set_changed(
|
|||||||
end
|
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
|
return Public
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
local random = math.random
|
local random = math.random
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
local remove = table.remove
|
local remove = table.remove
|
||||||
local insert = table.insert
|
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local table_size = table_size
|
local table_size = table_size
|
||||||
@ -40,7 +39,7 @@ end
|
|||||||
function table.add_all(t1, t2)
|
function table.add_all(t1, t2)
|
||||||
for k, v in pairs(t2) do
|
for k, v in pairs(t2) do
|
||||||
if tonumber(k) then
|
if tonumber(k) then
|
||||||
insert(t1, v)
|
t1[#t1 + 1] = v
|
||||||
else
|
else
|
||||||
t1[k] = v
|
t1[k] = v
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user