Added global store type

This commit is contained in:
Cooldude2606
2019-05-05 13:35:48 +01:00
parent 86daedf4f5
commit 6b14fe9649
5 changed files with 22 additions and 9 deletions

View File

@@ -218,7 +218,7 @@
]] ]]
local Game = require 'utils.game' local Game = require 'utils.game'
local player_return = ext_require('expcore.common','player_return') local player_return,write_json = ext_require('expcore.common','player_return','write_json')
local Commands = { local Commands = {
defines={ -- common values are stored error like signals defines={ -- common values are stored error like signals
@@ -580,14 +580,14 @@ end
-- logs command usage to file -- logs command usage to file
local function command_log(player,command,comment,params,raw,details) local function command_log(player,command,comment,params,raw,details)
local player_name = player and player.name or '<Server>' local player_name = player and player.name or '<Server>'
game.write_file('log/commands.log',game.table_to_json{ write_json('log/commands.log',{
player_name=player_name, player_name=player_name,
command_name=command.name, command_name=command.name,
comment=comment, comment=comment,
details=details, details=details,
params=params, params=params,
raw=raw raw=raw
}..'\n',true,0) })
end end
--- Main event function that is ran for all commands, used internally please avoid direct use --- Main event function that is ran for all commands, used internally please avoid direct use

View File

@@ -123,6 +123,13 @@ function Public.player_return(value,colour,player)
else rcon.print(returnAsString) end else rcon.print(returnAsString) end
end end
--- Writes a table object to a file in json format
-- @tparam path string the path of the file to write include / to use dir
-- @tpatam tbl table the table that will be converted to a json string and wrote to file
function Public.write_json(path,tbl)
game.write_file(path,game.table_to_json(tbl)..'\n',true,0)
end
--- Calls a require that will not error if the file is not found --- Calls a require that will not error if the file is not found
-- @usage local file = opt_require('file.not.present') -- will not cause any error -- @usage local file = opt_require('file.not.present') -- will not cause any error
-- @tparam path string the path that you want to require -- @tparam path string the path that you want to require

View File

@@ -160,6 +160,7 @@ local Global = require 'utils.global'
local Event = require 'utils.event' local Event = require 'utils.event'
local Groups = require 'expcore.permission_groups' local Groups = require 'expcore.permission_groups'
local Colours = require 'resources.color_presets' local Colours = require 'resources.color_presets'
local write_json = ext_require('expcore.common','write_json')
local Roles = { local Roles = {
config={ config={
@@ -223,12 +224,12 @@ local function emit_player_roles_updated(player,type,roles,by_player_name,skip_g
by_player_index=by_player_index, by_player_index=by_player_index,
roles=roles roles=roles
}) })
game.write_file('log/roles.log',game.table_to_json{ write_json('log/roles.log',{
player_name=player.name, player_name=player.name,
by_player_name=by_player_name, by_player_name=by_player_name,
type=type, type=type,
roles_changed=role_names roles_changed=role_names
}..'\n',true,0) })
end end
--- Returns a string which contains all roles in index order displaying all data for them --- Returns a string which contains all roles in index order displaying all data for them

View File

@@ -20,7 +20,7 @@
game - this will store all a single value so any sub_location string can be used, this is the general case so you really can store what game - this will store all a single value so any sub_location string can be used, this is the general case so you really can store what
ever values you want to in this and watch for external updates, this would be used when its not a local varible for example if you are ever values you want to in this and watch for external updates, this would be used when its not a local varible for example if you are
watching the number of online players. watching the number of online players.
global - WIP this will store all of its data in an external source indepentent of the lua code, this means that you can store data between global - this will store all of its data in an external source indepentent of the lua code, this means that you can store data between
maps and even instances, when the value is updated it will trigger an emit where some external code should send a message to the other maps and even instances, when the value is updated it will trigger an emit where some external code should send a message to the other
connected instances to update they value. lcoal set -> emit update -> local setter -> remote set -> remote setter connected instances to update they value. lcoal set -> emit update -> local setter -> remote set -> remote setter
@@ -61,7 +61,7 @@
local Global = require 'utils.global' local Global = require 'utils.global'
local Event = require 'utils.event' local Event = require 'utils.event'
local Game = require 'utils.game' local Game = require 'utils.game'
local Enum = ext_require('expcore.common','enum') local Enum,write_json = ext_require('expcore.common','enum','write_json')
local Store = { local Store = {
data={}, data={},
@@ -98,7 +98,11 @@ end
--- Emits an event to the external store that a value was updated --- Emits an event to the external store that a value was updated
local function set_global_location_value(location,sub_location,value) local function set_global_location_value(location,sub_location,value)
-- not yet impimented, this will emit to a file in some way to set the value in an external database write_json('log/store.log',{
location=location,
sub_location=sub_location,
value=value
})
end end
--- Register a new location to store a value, the valu returned from getter will be watched for updates --- Register a new location to store a value, the valu returned from getter will be watched for updates

View File

@@ -9,7 +9,8 @@ local interface_modules = {
['Commands']=Commands, ['Commands']=Commands,
['output']=Common.player_return, ['output']=Common.player_return,
['Group']='expcore.permission_groups', ['Group']='expcore.permission_groups',
['Roles']='expcore.roles' ['Roles']='expcore.roles',
['Store']='expcore.store'
} }
-- loads all the modules given in the above table -- loads all the modules given in the above table