mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-03 14:53:01 +02:00
updates
This commit is contained in:
parent
018675c9c4
commit
69fa8309f0
59
control.lua
59
control.lua
@ -47,40 +47,9 @@ require 'features.gui.paint'
|
||||
require 'features.gui.score'
|
||||
require 'features.gui.popup'
|
||||
|
||||
Server.on_data_set_changed(
|
||||
'Test',
|
||||
function(data)
|
||||
game.print(serpent.block(data))
|
||||
end
|
||||
)
|
||||
|
||||
Server.on_data_set_changed(
|
||||
'Test 2',
|
||||
function(data)
|
||||
game.print(serpent.block(data))
|
||||
end
|
||||
)
|
||||
|
||||
Server.on_data_set_changed(
|
||||
'Test,2',
|
||||
function(data)
|
||||
game.print(serpent.block(data))
|
||||
end
|
||||
)
|
||||
|
||||
local Event = require('utils.event')
|
||||
Event.add(
|
||||
Server.events.on_server_started,
|
||||
function(tbl)
|
||||
game.print('on_server_started')
|
||||
print('on_server_started')
|
||||
game.print(serpent.block(tbl))
|
||||
print(serpent.block(tbl))
|
||||
end
|
||||
)
|
||||
|
||||
local Token = require('utils.global_token')
|
||||
local data_callback = Token.register(
|
||||
local data_callback =
|
||||
Token.register(
|
||||
function(data)
|
||||
game.print(serpent.line(data))
|
||||
end
|
||||
@ -93,3 +62,27 @@ end
|
||||
function get_all_data(data_set, key)
|
||||
Server.try_get_all_data(data_set, data_callback)
|
||||
end
|
||||
|
||||
local Event = require('utils.event')
|
||||
Event.add(
|
||||
Server.events.on_server_started,
|
||||
function(tbl)
|
||||
game.print('on_server_started')
|
||||
print('on_server_started')
|
||||
game.print(serpent.block(tbl))
|
||||
print(serpent.block(tbl))
|
||||
|
||||
Server.try_get_all_data('webtest', data_callback)
|
||||
end
|
||||
)
|
||||
|
||||
local data_token =
|
||||
Token.register(
|
||||
function(data)
|
||||
global.data = data.entries
|
||||
end
|
||||
)
|
||||
|
||||
function get_data_set(data_set)
|
||||
Server.try_get_all_data(data_set, data_token)
|
||||
end
|
||||
|
69
server.lua
69
server.lua
@ -129,6 +129,9 @@ function Public.set_data(data_set, key, value)
|
||||
error('key must be a string')
|
||||
end
|
||||
|
||||
data_set = data_set:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"')
|
||||
key = key:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"')
|
||||
|
||||
local message
|
||||
local vt = type(value)
|
||||
if vt == 'nil' then
|
||||
@ -155,7 +158,40 @@ function Public.set_data(data_set, key, value)
|
||||
message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, "\",value:'", value, "'}"})
|
||||
end
|
||||
|
||||
game.print(message)
|
||||
raw_print(message)
|
||||
end
|
||||
|
||||
function Public.try_get_data(data_set, key, callback_token)
|
||||
if type(data_set) ~= 'string' then
|
||||
error('data_set must be a string')
|
||||
end
|
||||
if type(key) ~= 'string' then
|
||||
error('key must be a string')
|
||||
end
|
||||
if type(callback_token) ~= 'number' then
|
||||
error('callback_token must be a number')
|
||||
end
|
||||
|
||||
-- Excessive escaping because the data is serialized twice.
|
||||
data_set = data_set:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"')
|
||||
key = key:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"')
|
||||
|
||||
local message = table.concat {data_get_tag, callback_token, ' {', 'data_set:"', data_set, '",key:"', key, '"}'}
|
||||
raw_print(message)
|
||||
end
|
||||
|
||||
function Public.try_get_all_data(data_set, callback_token)
|
||||
if type(data_set) ~= 'string' then
|
||||
error('data_set must be a string')
|
||||
end
|
||||
if type(callback_token) ~= 'number' then
|
||||
error('callback_token must be a number')
|
||||
end
|
||||
|
||||
-- Excessive escaping because the data is serialized twice.
|
||||
data_set = data_set:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"')
|
||||
|
||||
local message = table.concat {data_get_all_tag, callback_token, ' {', 'data_set:"', data_set, '"}'}
|
||||
raw_print(message)
|
||||
end
|
||||
|
||||
@ -203,6 +239,9 @@ function Public.get_tracked_data_sets()
|
||||
local message = {data_tracked_tag, '['}
|
||||
|
||||
for k, _ in pairs(data_set_handlers) do
|
||||
-- Excessive escaping because the data is serialized twice.
|
||||
k = k:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"')
|
||||
|
||||
table.insert(message, '"')
|
||||
table.insert(message, k)
|
||||
table.insert(message, '"')
|
||||
@ -217,34 +256,6 @@ function Public.get_tracked_data_sets()
|
||||
|
||||
message = table.concat(message)
|
||||
raw_print(message)
|
||||
game.print(message)
|
||||
end
|
||||
|
||||
function Public.try_get_data(data_set, key, callback_token)
|
||||
if type(data_set) ~= 'string' then
|
||||
error('data_set must be a string')
|
||||
end
|
||||
if type(key) ~= 'string' then
|
||||
error('key must be a string')
|
||||
end
|
||||
if type(callback_token) ~= 'number' then
|
||||
error('callback_token must be a number')
|
||||
end
|
||||
|
||||
local message = table.concat {data_get_tag, callback_token, ' {', 'data_set:"', data_set, '",key:"', key, '"}'}
|
||||
raw_print(message)
|
||||
end
|
||||
|
||||
function Public.try_get_all_data(data_set, callback_token)
|
||||
if type(data_set) ~= 'string' then
|
||||
error('data_set must be a string')
|
||||
end
|
||||
if type(callback_token) ~= 'number' then
|
||||
error('callback_token must be a number')
|
||||
end
|
||||
|
||||
local message = table.concat {data_get_all_tag, callback_token, ' {', 'data_set:"', data_set, '"}'}
|
||||
raw_print(message)
|
||||
end
|
||||
|
||||
return Public
|
||||
|
Loading…
x
Reference in New Issue
Block a user