/
coreCommands.lua
67 lines (54 loc) · 1.4 KB
/
coreCommands.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
local M = {}
---@param cmd CustomCommandData
M.__show_global_data_command = function(cmd)
local mod_name = "level"
if cmd.parameter and #cmd.parameter > 0 then
mod_name = cmd.parameter
end
local player
if cmd.player_index > 0 then
player = game.get_player(cmd.player_index)
if not (player and player.valid) then return end
end
local interface_name = "__" .. mod_name .. "__BC"
local interface = remote.interfaces[interface_name]
if interface == nil or interface.get_global_data_as_json == nil then
if player then
-- TODO: add localization
player.print("Can't get global data of it", {1, 0, 0})
else
print("Can't get global data of it")
end
return
end
local json = remote.call(interface_name, "get_global_data_as_json")
if type(json) ~= "string" or #json == 0 then
if player then
-- TODO: add localization
player.print("Global data is empty", {0, 1, 0})
else
print("Global data is empty")
end
return
end
if #json < 100 then
if player then
player.print(json)
else
print(json)
end
return
end
local file_name = "__global_data_" .. mod_name .. "_BC.json"
game.write_file(file_name, json, false, cmd.player_index)
local message = "Global data as json has been saved into script-output/" .. file_name
if player then
player.print(message)
else
print(message)
end
end
M.commands = {
__show_global_data = M.__show_global_data_command,
}
return M