export data as js-files with global storage

makes it possible to view it locally without webserver
This commit is contained in:
BuckarooBanzay 2020-02-19 20:39:44 +01:00
parent bd443bfc9b
commit c3f1070630
9 changed files with 18 additions and 13 deletions

View File

@ -12,5 +12,5 @@ minetest.register_on_mods_loaded(function()
local data = {}
mtinfo.map_list(data, minetest.registered_abms, abm_mapped_keys)
mtinfo.export_json(mtinfo.basepath.."/data/abm.json", data)
mtinfo.export_json(mtinfo.basepath.."/data/abm.js", data, "mtinfo.abm")
end)

View File

@ -13,6 +13,7 @@
mtinfo = {};
</script>
<script src="js/util/imageresolver.js"></script>
<script src="data/nodes.js"></script>
<script src="js/index.js"></script>
</body>
</html>

View File

@ -1,11 +1,11 @@
m.request("./data/nodes.json")
.then(nodes => {
const list = [];
function init(){
Object.keys(nodes)
.map(name => nodes[name])
var list = [];
Object.keys(mtinfo.nodes)
.map(name => mtinfo.nodes[name])
.forEach(node => list.push(node));
let rows = list
@ -31,4 +31,6 @@ m.request("./data/nodes.json")
]);
m.render(document.getElementById("app"), table);
});
}
init();

View File

@ -48,12 +48,14 @@ function mtinfo.copyrecursive(src, target)
end
end
function mtinfo.export_json(fname, data)
function mtinfo.export_json(fname, data, varname)
local f = io.open(fname, "w")
local data_string, err = minetest.write_json(data)
if err then
error(err)
end
f:write(varname .. "=")
f:write(data_string)
f:write(";")
io.close(f)
end

View File

@ -12,5 +12,5 @@ minetest.register_on_mods_loaded(function()
local data = {}
mtinfo.map_list(data, minetest.registered_items, item_mapped_keys)
mtinfo.export_json(mtinfo.basepath.."/data/items.json", data)
mtinfo.export_json(mtinfo.basepath.."/data/items.js", data, "mtinfo.items")
end)

View File

@ -10,5 +10,5 @@ minetest.register_on_mods_loaded(function()
local data = {}
mtinfo.map_list(data, minetest.registered_lbms, lbm_mapped_keys)
mtinfo.export_json(mtinfo.basepath.."/data/lbm.json", data)
mtinfo.export_json(mtinfo.basepath.."/data/lbm.js", data, "mtinfo.lbm")
end)

View File

@ -36,5 +36,5 @@ minetest.register_on_mods_loaded(function()
return true
end
end)
mtinfo.export_json(mtinfo.basepath.."/data/nodes.json", data)
mtinfo.export_json(mtinfo.basepath.."/data/nodes.js", data, "mtinfo.nodes")
end)

View File

@ -6,5 +6,5 @@ minetest.register_on_mods_loaded(function()
data[name] = minetest.get_all_craft_recipes(name)
end
mtinfo.export_json(mtinfo.basepath.."/data/recipes.json", data)
mtinfo.export_json(mtinfo.basepath.."/data/recipes.js", data, "mtinfo.recipes")
end)

View File

@ -12,5 +12,5 @@ minetest.register_on_mods_loaded(function()
local data = {}
mtinfo.map_list(data, minetest.registered_tools, tool_mapped_keys)
mtinfo.export_json(mtinfo.basepath.."/data/tools.json", data)
mtinfo.export_json(mtinfo.basepath.."/data/tools.js", data, "mtinfo.tools")
end)