Add JSON-based export string format.
parent
ca02d2b79c
commit
ff994a34f2
|
@ -12,7 +12,7 @@ create HUDs on their own.
|
||||||
|
|
||||||
- `.mrkr`: Opens a formspec allowing you to display or delete markers.
|
- `.mrkr`: Opens a formspec allowing you to display or delete markers.
|
||||||
- `.add_mrkr`: Adds markers. You can use `.add_mrkr x,y,z Marker name` to add markers. Markers are (currently) cross-server, and adding a marker with (exactly) the same name as another will overwrite the original marker. If you replace `x,y,z` with `here`, the marker will be set to your current position, and replacing it with `there` will set the marker to the last `.coords` position.
|
- `.add_mrkr`: Adds markers. You can use `.add_mrkr x,y,z Marker name` to add markers. Markers are (currently) cross-server, and adding a marker with (exactly) the same name as another will overwrite the original marker. If you replace `x,y,z` with `here`, the marker will be set to your current position, and replacing it with `there` will set the marker to the last `.coords` position.
|
||||||
- `.mrkr_export`: Exports your markers to an advmarkers string. Remember to not modify the text before copying it.
|
- `.mrkr_export`: Exports your markers to an advmarkers string. Remember to not modify the text before copying it. You can use `.mrkr_export old` if you want an export string compatible with older versions of advmarkers (it should start with `M` instead of `J`). The old format will probably not work nicely with the planned server-side mod, however.
|
||||||
- `.mrkr_import`: Imports your markers from an advmarkers string (`.mrkr_import <advmarkers string>`). Any markers with the same name will not be overwritten, and if they do not have the same co-ordinates, `_` will be appended to the imported one.
|
- `.mrkr_import`: Imports your markers from an advmarkers string (`.mrkr_import <advmarkers string>`). Any markers with the same name will not be overwritten, and if they do not have the same co-ordinates, `_` will be appended to the imported one.
|
||||||
- `.mrkrthere`: Sets a marker at the last `.coords` position.
|
- `.mrkrthere`: Sets a marker at the last `.coords` position.
|
||||||
|
|
||||||
|
|
24
init.lua
24
init.lua
|
@ -76,9 +76,12 @@ end
|
||||||
-- Export markers
|
-- Export markers
|
||||||
function advmarkers.export(raw)
|
function advmarkers.export(raw)
|
||||||
local s = storage:to_table().fields
|
local s = storage:to_table().fields
|
||||||
if not raw then
|
if raw == 'M' then
|
||||||
s = minetest.compress(minetest.serialize(s))
|
s = minetest.compress(minetest.serialize(s))
|
||||||
s = 'M' .. minetest.encode_base64(s)
|
s = 'M' .. minetest.encode_base64(s)
|
||||||
|
elseif not raw then
|
||||||
|
s = minetest.compress(minetest.write_json(s))
|
||||||
|
s = 'J' .. minetest.encode_base64(s)
|
||||||
end
|
end
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
@ -86,11 +89,16 @@ end
|
||||||
-- Import markers
|
-- Import markers
|
||||||
function advmarkers.import(s)
|
function advmarkers.import(s)
|
||||||
if type(s) ~= 'table' then
|
if type(s) ~= 'table' then
|
||||||
if s:sub(1, 1) ~= 'M' then return false, 'No M' end
|
local ver = s:sub(1, 1)
|
||||||
|
if ver ~= 'M' and ver ~= 'J' then return end
|
||||||
s = minetest.decode_base64(s:sub(2))
|
s = minetest.decode_base64(s:sub(2))
|
||||||
local success, msg = pcall(minetest.decompress, s)
|
local success, msg = pcall(minetest.decompress, s)
|
||||||
if not success then return end
|
if not success then return end
|
||||||
s = minetest.deserialize(msg)
|
if ver == 'M' then
|
||||||
|
s = minetest.deserialize(msg)
|
||||||
|
else
|
||||||
|
s = minetest.parse_json(msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Iterate over markers to preserve existing ones and check for errors.
|
-- Iterate over markers to preserve existing ones and check for errors.
|
||||||
|
@ -327,12 +335,18 @@ end)
|
||||||
|
|
||||||
-- Allow string exporting
|
-- Allow string exporting
|
||||||
minetest.register_chatcommand('mrkr_export', {
|
minetest.register_chatcommand('mrkr_export', {
|
||||||
params = '',
|
params = '[old]',
|
||||||
description = 'Exports an advmarkers string containing all your markers.',
|
description = 'Exports an advmarkers string containing all your markers.',
|
||||||
func = function(param)
|
func = function(param)
|
||||||
|
local export
|
||||||
|
if param == 'old' then
|
||||||
|
export = advmarkers.export('M')
|
||||||
|
else
|
||||||
|
export = advmarkers.export()
|
||||||
|
end
|
||||||
minetest.show_formspec('advmarkers-ignore',
|
minetest.show_formspec('advmarkers-ignore',
|
||||||
'field[_;Your marker export string;' ..
|
'field[_;Your marker export string;' ..
|
||||||
minetest.formspec_escape(advmarkers.export()) .. ']')
|
minetest.formspec_escape(export) .. ']')
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue