Use builtin version when available

This commit is contained in:
Danielv123 committed 2024-12-01 09:14:04 +00:00
1 parent 85cdbb1185
commit 54411bc327
1 file changed
+14 -11
+14 -11
View File
@@ -146,18 +146,21 @@ end
--- Select the appropriate polyfill implementation
if major_v1_1 then
-- Game is not always available so it needs to be called within another function
-- Can not use ... here because of luals type suggestion breaking when it is used
-- TODO maybe include a version that does not require game?
if game ~= nil then
compat.table_to_json = function(tbl) return game.table_to_json(tbl) end
compat.json_to_table = function(json) return game.json_to_table(json) end
compat.write_file = function(filename, data, append, for_player) return game.write_file(filename, data, append, for_player) end
else
compat.table_to_json = json.encode
compat.json_to_table = json.decode
compat.table_to_json = function(tbl)
if game then
compat.table_to_json = game.table_to_json
return game.table_to_json(tbl)
end
return json.encode(tbl)
end
compat.json_to_table = function(json)
if game then
compat.json_to_table = game.json_to_table
return game.json_to_table(json)
end
return json.decode(json)
end
compat.write_file = function(filename, data, append, for_player) return game.write_file(filename, data, append, for_player) end
elseif major_v2 then
compat.table_to_json = helpers.table_to_json
compat.json_to_table = helpers.json_to_table