Fixed some bugs

This commit is contained in:
Cooldude2606
2020-05-29 22:57:06 +01:00
parent 0836375e02
commit 4286e25803
6 changed files with 23 additions and 31 deletions

View File

@@ -12,7 +12,6 @@ return {
'modules.commands.me', 'modules.commands.me',
'modules.commands.kill', 'modules.commands.kill',
'modules.commands.admin-chat', 'modules.commands.admin-chat',
'modules.commands.tag',
'modules.commands.teleport', 'modules.commands.teleport',
'modules.commands.cheat-mode', 'modules.commands.cheat-mode',
'modules.commands.ratio', 'modules.commands.ratio',
@@ -27,7 +26,6 @@ return {
'modules.commands.spawn', 'modules.commands.spawn',
'modules.commands.warnings', 'modules.commands.warnings',
'modules.commands.find', 'modules.commands.find',
'modules.commands.bonus',
'modules.commands.home', 'modules.commands.home',
--- Addons --- Addons
@@ -48,6 +46,9 @@ return {
'modules.data.player-colours', 'modules.data.player-colours',
'modules.data.greetings', 'modules.data.greetings',
'modules.data.quickbar', 'modules.data.quickbar',
'modules.data.alt-view',
'modules.data.tag',
'modules.data.bonus',
--- GUI --- GUI
'modules.gui.readme', 'modules.gui.readme',

View File

@@ -151,8 +151,7 @@ Roles.new_role('Supporter','Sup')
:allow{ :allow{
'command/jail', 'command/jail',
'command/unjail', 'command/unjail',
'command/join-message', 'command/join-message'
'command/save-quickbar'
} }
Roles.new_role('Partner','Part') Roles.new_role('Partner','Part')
@@ -187,7 +186,8 @@ Roles.new_role('Member','Mem')
'gui/task-list/add', 'gui/task-list/add',
'gui/task-list/edit', 'gui/task-list/edit',
'gui/warp-list/add', 'gui/warp-list/add',
'gui/warp-list/edit' 'gui/warp-list/edit',
'command/save-quickbar'
} }
Roles.new_role('Regular','Reg') Roles.new_role('Regular','Reg')

View File

@@ -153,6 +153,7 @@ local Datastores = {}
local Datastore = {} local Datastore = {}
local Data = {} local Data = {}
local copy = table.deep_copy local copy = table.deep_copy
local trace = debug.traceback
--- Save datastores in the global table --- Save datastores in the global table
global.datastores = Data global.datastores = Data
@@ -250,7 +251,6 @@ function DatastoreManager.ingest(action, datastoreName, key, valueJson)
elseif action == 'propagate' or action == 'request' then elseif action == 'propagate' or action == 'request' then
local success, value = pcall(game.json_to_table, valueJson) local success, value = pcall(game.json_to_table, valueJson)
if not success or value == nil then value = tonumber(valueJson) or valueJson end if not success or value == nil then value = tonumber(valueJson) or valueJson end
datastore:raw_set(key) -- clear any existing data
value = datastore:raise_event('on_load', key, value) value = datastore:raise_event('on_load', key, value)
datastore:set(key, value) datastore:set(key, value)
@@ -360,7 +360,7 @@ function Datastore:raw_set(key, value)
end end
end end
local function serialize_error(err) error('An error ocurred in a datastore serializer: '..err) end local function serialize_error(err) error('An error ocurred in a datastore serializer: '..trace(err)) end
--[[-- Internal, Return the serialized key --[[-- Internal, Return the serialized key
@tparam any rawKey The key that needs to be serialized, if it is already a string then it is returned @tparam any rawKey The key that needs to be serialized, if it is already a string then it is returned
@treturn string The key after it has been serialized @treturn string The key after it has been serialized
@@ -389,11 +389,11 @@ self:write_action('save', 'TestKey', 'Foo')
]] ]]
function Datastore:write_action(action, key, value) function Datastore:write_action(action, key, value)
local data = {action, self.name, '"'..key..'"'} local data = {action, self.name, key}
if value ~= nil then if value ~= nil then
data[4] = type(value) == 'table' and '"'..game.table_to_json(value)..'"' or '"'..tostring(value)..'"' data[4] = type(value) == 'table' and game.table_to_json(value) or tostring(value)
end end
game.write_file('datastore.out', table.concat(data, ' ')..'\n', true, 0) game.write_file('ext/datastore.out', table.concat(data, ' ')..'\n', true, 0)
end end
----- Datastore Local ----- Datastore Local
@@ -520,7 +520,7 @@ function Datastore:increment(key, delta)
return Datastore:set(key, value + (delta or 1)) return Datastore:set(key, value + (delta or 1))
end end
local function update_error(err) error('An error ocurred in datastore update: '..err, 2) end local function update_error(err) error('An error ocurred in datastore update: '..trace(err), 2) end
--[[-- Use a function to update the value locally, will trigger on_update then on_save, save_to_disk and auto_save is required for on_save --[[-- Use a function to update the value locally, will trigger on_update then on_save, save_to_disk and auto_save is required for on_save
@tparam any key The key that you want to apply the update to, must be a string unless a serializer is set @tparam any key The key that you want to apply the update to, must be a string unless a serializer is set
@tparam function callback The function that will be used to update the value at this key @tparam function callback The function that will be used to update the value at this key
@@ -560,7 +560,7 @@ function Datastore:remove(key)
if self.parent and self.parent.auto_save then return self.parent:save(key) end if self.parent and self.parent.auto_save then return self.parent:save(key) end
end end
local function filter_error(err) print('An error ocurred in a datastore filter:', err) end local function filter_error(err) print('An error ocurred in a datastore filter:'..trace(err)) end
--[[-- Internal, Used to filter elements from a table --[[-- Internal, Used to filter elements from a table
@tparam table tbl The table that will have the filter applied to it @tparam table tbl The table that will have the filter applied to it
@tparam[opt] function callback The function that will be used as a filter, if none giving then the provided table is returned @tparam[opt] function callback The function that will be used as a filter, if none giving then the provided table is returned
@@ -737,7 +737,7 @@ end
----- Events ----- Events
-- @section events -- @section events
local function event_error(err) print('An error ocurred in a datastore event handler:', err) end local function event_error(err) print('An error ocurred in a datastore event handler: '..trace(err)) end
--[[-- Internal, Raise an event on this datastore --[[-- Internal, Raise an event on this datastore
@tparam string event_name The name of the event to raise for this datastore @tparam string event_name The name of the event to raise for this datastore
@tparam string key The key that this event is being raised for @tparam string key The key that this event is being raised for
@@ -752,7 +752,7 @@ value = self:raise_event('on_save', key, value)
function Datastore:raise_event(event_name, key, value, source) function Datastore:raise_event(event_name, key, value, source)
-- Raise the event for the children of this datastore -- Raise the event for the children of this datastore
if source ~= 'child' and next(self.children) then if source ~= 'child' and next(self.children) then
if type(value) ~= 'table' then value = self:raw_get(key, true) end if type(value) ~= 'table' then value = {} end
for value_name, child in pairs(self.children) do for value_name, child in pairs(self.children) do
value[value_name] = child:raise_event(event_name, key, value[value_name], 'parent') value[value_name] = child:raise_event(event_name, key, value[value_name], 'parent')
end end
@@ -769,7 +769,7 @@ function Datastore:raise_event(event_name, key, value, source)
-- Raise the event for the parent of this datastore -- Raise the event for the parent of this datastore
if source ~= 'parent' and self.parent then if source ~= 'parent' and self.parent then
self.parent:raise_event(event_name, key, self.parent:raw_get(key), 'child') self.parent:raise_event(event_name, key, self.parent:raw_get(key, true), 'child')
end end
-- If this is the save event and the table is empty then return nil -- If this is the save event and the table is empty then return nil

View File

@@ -47,13 +47,6 @@ local Datastore = require 'expcore.datastore' --- @dep expcore.datastore
local Commands = require 'expcore.commands' --- @dep expcore.commands local Commands = require 'expcore.commands' --- @dep expcore.commands
require 'config.expcore.command_general_parse' --- @dep config.expcore.command_general_parse 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 --- Common player data that acts as the root store for player data
local PlayerData = Datastore.connect('PlayerData', true) -- saveToDisk local PlayerData = Datastore.connect('PlayerData', true) -- saveToDisk
PlayerData:set_serializer(Datastore.name_serializer) -- use player name 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) game.write_file('expgaming_player_data.json', game.table_to_json(PlayerData:get(player, {})), false, player.index)
end) 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 check_data_loaded = Async.register(function(player)
local player_data = PlayerData:get(player) local player_data = PlayerData:get(player)
if not player_data then if not player_data then
FailedLoad[player.name] = true
player.print{'expcore-data.data-failed'} player.print{'expcore-data.data-failed'}
Datastore.ingest('request', 'PlayerData', player.name, '{"failed_load":true}') Datastore.ingest('request', 'PlayerData', player.name, '{"failed_load":true}')
end end
@@ -100,8 +92,8 @@ end)
--- When player data loads tell the player if the load had failed previously --- When player data loads tell the player if the load had failed previously
PlayerData:on_load(function(player_name, player_data) PlayerData:on_load(function(player_name, player_data)
if not player_data or player_data.failed_load then return end if not player_data or player_data.failed_load then return end
if FailedLoad[player_name] then local existing_data = PlayerData:get(player_name)
FailedLoad[player_name] = nil if existing_data and existing_data.failed_load then
game.players[player_name].print{'expcore-data.data-restore'} game.players[player_name].print{'expcore-data.data-restore'}
end end
end) end)
@@ -128,7 +120,7 @@ end)
Event.add(defines.events.on_player_joined_game, function(event) Event.add(defines.events.on_player_joined_game, function(event)
local player = game.players[event.player_index] local player = game.players[event.player_index]
PlayerData:request(player) PlayerData:request(player)
Async.wait(600, check_data_loaded, player) Async.wait(300, check_data_loaded, player)
end) end)
--- Unload player data when they leave --- 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 = game.players[event.player_index]
local player_data = PlayerData:get(player) local player_data = PlayerData:get(player)
if player_data.failed_load then if player_data.failed_load then
FailedLoad[player.name] = nil
PlayerData:raw_set(player) PlayerData:raw_set(player)
else PlayerData:unload(player) end else PlayerData:unload(player) end
end) end)

View File

@@ -23,8 +23,8 @@ local function apply_bonus(player, amount)
end end
--- When store is updated apply new bonus to the player --- When store is updated apply new bonus to the player
PlayerBonus.on_update(function(player_name, player_bonus) PlayerBonus:on_update(function(player_name, player_bonus)
apply_bonus(game.player[player_name], player_bonus or 0) apply_bonus(game.players[player_name], player_bonus or 0)
end) end)
--- Changes the amount of bonus you receive --- Changes the amount of bonus you receive

View File

@@ -16,7 +16,7 @@ local PlayerTags = PlayerData.Settings:combine('Tag')
PlayerTags:on_update(function(player_name, player_tag) PlayerTags:on_update(function(player_name, player_tag)
local player = game.players[player_name] local player = game.players[player_name]
if player_tag == nil or player_tag == '' then if player_tag == nil or player_tag == '' then
player_tag.tag = '' player.tag = ''
else else
player.tag = '- '..player_tag player.tag = '- '..player_tag
end end