mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 19:45:22 +09:00
Fixed some bugs
This commit is contained in:
@@ -47,13 +47,6 @@ local Datastore = require 'expcore.datastore' --- @dep expcore.datastore
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse' --- @dep config.expcore.command_general_parse
|
||||
|
||||
--- Stores all the players whos data failed to load
|
||||
local FailedLoad = {}
|
||||
global.failed_player_data = FailedLoad
|
||||
Event.on_load(function()
|
||||
FailedLoad = global.failed_player_data
|
||||
end)
|
||||
|
||||
--- Common player data that acts as the root store for player data
|
||||
local PlayerData = Datastore.connect('PlayerData', true) -- saveToDisk
|
||||
PlayerData:set_serializer(Datastore.name_serializer) -- use player name
|
||||
@@ -87,11 +80,10 @@ Commands.new_command('save-data', 'Writes all your player data to a file on your
|
||||
game.write_file('expgaming_player_data.json', game.table_to_json(PlayerData:get(player, {})), false, player.index)
|
||||
end)
|
||||
|
||||
--- Async function called after 10 seconds with no player data loaded
|
||||
--- Async function called after 5 seconds with no player data loaded
|
||||
local check_data_loaded = Async.register(function(player)
|
||||
local player_data = PlayerData:get(player)
|
||||
if not player_data then
|
||||
FailedLoad[player.name] = true
|
||||
player.print{'expcore-data.data-failed'}
|
||||
Datastore.ingest('request', 'PlayerData', player.name, '{"failed_load":true}')
|
||||
end
|
||||
@@ -100,8 +92,8 @@ end)
|
||||
--- When player data loads tell the player if the load had failed previously
|
||||
PlayerData:on_load(function(player_name, player_data)
|
||||
if not player_data or player_data.failed_load then return end
|
||||
if FailedLoad[player_name] then
|
||||
FailedLoad[player_name] = nil
|
||||
local existing_data = PlayerData:get(player_name)
|
||||
if existing_data and existing_data.failed_load then
|
||||
game.players[player_name].print{'expcore-data.data-restore'}
|
||||
end
|
||||
end)
|
||||
@@ -128,7 +120,7 @@ end)
|
||||
Event.add(defines.events.on_player_joined_game, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
PlayerData:request(player)
|
||||
Async.wait(600, check_data_loaded, player)
|
||||
Async.wait(300, check_data_loaded, player)
|
||||
end)
|
||||
|
||||
--- Unload player data when they leave
|
||||
@@ -136,7 +128,6 @@ Event.add(defines.events.on_player_left_game, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player_data = PlayerData:get(player)
|
||||
if player_data.failed_load then
|
||||
FailedLoad[player.name] = nil
|
||||
PlayerData:raw_set(player)
|
||||
else PlayerData:unload(player) end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user