diff --git a/abm.lua b/abm.lua index f7f0cf7..7d2fc0d 100644 --- a/abm.lua +++ b/abm.lua @@ -8,9 +8,9 @@ local abm_mapped_keys = { "catch_up" } -minetest.register_on_mods_loaded(function() +mtinfo.export_abms = function() local data = {} mtinfo.map_list(data, minetest.registered_abms, abm_mapped_keys) mtinfo.export_json(mtinfo.basepath.."/data/abm.js", data, "mtinfo.abm") -end) +end diff --git a/app/index.html b/app/index.html index a1fb545..71f14d5 100644 --- a/app/index.html +++ b/app/index.html @@ -21,16 +21,24 @@ - + + + + + - + + - + + + + diff --git a/app/js/components/node-detail.js b/app/js/components/node-detail.js new file mode 100644 index 0000000..584f347 --- /dev/null +++ b/app/js/components/node-detail.js @@ -0,0 +1,21 @@ + +Vue.component("node-detail", { + props: ["node"], + template: /*html*/` +
+

{{ node.description }} {{ node.name }}

+ Diggable + Pointable + Airlike + Walkable +

Stack-max: {{ node.stack_max }}

+

Light-source: {{ node.light_source }}

+

Groups

+ +
+ ` +}); diff --git a/app/js/components/node-info.js b/app/js/components/node-info.js index 4910c2f..5b4526b 100644 --- a/app/js/components/node-info.js +++ b/app/js/components/node-info.js @@ -1,35 +1,30 @@ -Vue.component("node-list", { - template: /*html*/` -
-

Node list

- - - - - - - - - - - - - - - -
ModImageNodename
{{ nodename.substring(0, nodename.indexOf(":")) }} - - - - {{ nodename }} - -
-
- ` -}); Vue.component("node-info", { props: ["name"], + created: function(){ + //TODO: debug + const nodename = this.name; + const nodedef = mtinfo.nodes[this.name]; + console.log(nodedef); + + if (mtinfo.abm_nodenames[this.name]){ + console.log("abm nodename", mtinfo.abm_nodenames[this.name]); + } + if (mtinfo.abm_neighbors[this.name]){ + console.log("abm neighbor", mtinfo.abm_neighbors[this.name]); + } + if (nodedef.groups){ + Object.keys(nodedef.groups).forEach(function(group){ + const name = "group:" + group; + if (mtinfo.abm_nodenames[name]){ + console.log("abm group nodename", mtinfo.abm_nodenames[name]); + } + if (mtinfo.abm_neighbors[name]){ + console.log("abm group neighbor", mtinfo.abm_neighbors[name]); + } + }); + } + }, computed: { previewImage: function(){ return mtinfo.imageresolver(mtinfo.nodes[this.name]); @@ -37,98 +32,23 @@ Vue.component("node-info", { }, template: /*html*/`
-

Node info: {{ name }}

-
-        {{ JSON.stringify(mtinfo.nodes[name]) }}
-      
-
+
- - - + + + + + +
No preview available
-
+
+
` }); - - -Vue.component("node-preview-normal", { - props: ["node"], - computed: { - frontStyle: function(){ - let texture = "pics/unknown_node.png"; - if (this.node.tiles){ - if (this.node.tiles.length >= 3) { - // x+ - texture = "textures/" + mtinfo.stripimagetransforms(this.node.tiles[2]); - } else { - // last tile - texture = "textures/" + mtinfo.stripimagetransforms(this.node.tiles[this.node.tiles.length-1]); - } - } - - return { - "transform-origin": "0 0", - "position": "absolute", - "width": "100px", - "height": "100px", - "background-image": "url('" + texture + "')", - "background-size": "cover", - "transform": "rotate(0deg) skewY(30deg) scaleX(0.864) translate(31px, 69px)" - }; - }, - sideStyle: function(){ - let texture = "pics/unknown_node.png"; - if (this.node.tiles){ - if (this.node.tiles.length >= 5) { - // z+ - texture = "textures/" + mtinfo.stripimagetransforms(this.node.tiles[4]); - } else { - // last tile - texture = "textures/" + mtinfo.stripimagetransforms(this.node.tiles[this.node.tiles.length-1]); - } - } - - return { - "transform-origin": "0 0", - "position": "absolute", - "width": "100px", - "height": "100px", - "background-image": "url('" + texture + "')", - "background-size": "cover", - "transform": "rotate(-30deg) skewX(-30deg) translate(130px, 173px) scaleY(0.864)" - }; - }, - topStyle: function(){ - let texture = "pics/unknown_node.png"; - if (this.node.tiles && this.node.tiles.length >= 1){ - texture = "textures/" + mtinfo.stripimagetransforms(this.node.tiles[0]); - } - - return { - "transform-origin": "0 0", - "position": "absolute", - "width": "100px", - "height": "100px", - "background-image": "url('" + texture + "')", - "background-size": "cover", - "transform": "rotate(210deg) skew(-30deg) translate(-200px, -60px) scaleY(0.864)" - }; - } - }, - template: /*html*/` -
-

Preview: {{ node.name }}

-
-
-
-
- ` -}); diff --git a/app/js/components/node-list.js b/app/js/components/node-list.js new file mode 100644 index 0000000..c7bfc59 --- /dev/null +++ b/app/js/components/node-list.js @@ -0,0 +1,29 @@ +Vue.component("node-list", { + template: /*html*/` +
+

Node list

+ + + + + + + + + + + + + + + +
ModImageNodename
{{ nodename.substring(0, nodename.indexOf(":")) }} + + + + {{ nodename }} + +
+
+ ` +}); diff --git a/app/js/components/node-preview-inventoryimage.js b/app/js/components/node-preview-inventoryimage.js new file mode 100644 index 0000000..b79c4d8 --- /dev/null +++ b/app/js/components/node-preview-inventoryimage.js @@ -0,0 +1,12 @@ + +Vue.component("node-preview-inventoryimage", { + props: ["node"], + computed: { + imgsrc: function(){ + return `textures/${this.node.inventory_image}`; + } + }, + template: /*html*/` + + ` +}); diff --git a/app/js/components/node-preview-normal.js b/app/js/components/node-preview-normal.js new file mode 100644 index 0000000..e5422e6 --- /dev/null +++ b/app/js/components/node-preview-normal.js @@ -0,0 +1,67 @@ + +const common_attributes = { + "transform-origin": "0 0", + "position": "absolute", + "width": "100px", + "height": "100px", + "background-size": "cover", + "image-rendering": "crisp-edges" +}; + +Vue.component("node-preview-normal", { + props: ["node"], + computed: { + frontStyle: function(){ + let texture = "pics/unknown_node.png"; + if (this.node.tiles){ + if (this.node.tiles.length >= 3) { + // x+ + texture = "textures/" + mtinfo.stripimagetransforms(this.node.tiles[2]); + } else { + // last tile + texture = "textures/" + mtinfo.stripimagetransforms(this.node.tiles[this.node.tiles.length-1]); + } + } + + return Object.assign({}, common_attributes, { + "background-image": "url('" + texture + "')", + "transform": "rotate(0deg) skewY(30deg) scaleX(0.864) translate(31px, 69px)" + }); + }, + sideStyle: function(){ + let texture = "pics/unknown_node.png"; + if (this.node.tiles){ + if (this.node.tiles.length >= 5) { + // z+ + texture = "textures/" + mtinfo.stripimagetransforms(this.node.tiles[4]); + } else { + // last tile + texture = "textures/" + mtinfo.stripimagetransforms(this.node.tiles[this.node.tiles.length-1]); + } + } + + return Object.assign({}, common_attributes, { + "background-image": "url('" + texture + "')", + "transform": "rotate(-30deg) skewX(-30deg) translate(130px, 173px) scaleY(0.864)" + }); + }, + topStyle: function(){ + let texture = "pics/unknown_node.png"; + if (this.node.tiles && this.node.tiles.length >= 1){ + texture = "textures/" + mtinfo.stripimagetransforms(this.node.tiles[0]); + } + + return Object.assign({}, common_attributes, { + "background-image": "url('" + texture + "')", + "transform": "rotate(210deg) skew(-30deg) translate(-200px, -60px) scaleY(0.864)" + }); + } + }, + template: /*html*/` +
+
+
+
+
+ ` +}); diff --git a/app/js/main.js b/app/js/main.js index 73bdb8c..b59d94d 100644 --- a/app/js/main.js +++ b/app/js/main.js @@ -16,5 +16,3 @@ new Vue({ el: "#app", router: router }); - -console.log("OK"); diff --git a/app/js/util/compute_abm_nodes.js b/app/js/util/compute_abm_nodes.js new file mode 100644 index 0000000..e15815f --- /dev/null +++ b/app/js/util/compute_abm_nodes.js @@ -0,0 +1,25 @@ +/* +pre-compute abm name/group maps +mtinfo.abm = []; + +mtinfo.abm_nodenames[nodename_or_group] = abm +mtinfo.abm_neighbors[nodename_or_group] = abm +*/ + +mtinfo.abm_nodenames = {}; +mtinfo.abm_neighbors = {}; + +mtinfo.abm.forEach(function(abm){ + abm.nodenames.forEach(function(nodename){ + mtinfo.abm_nodenames[nodename] = abm; + }); + if (abm.neighbors){ + if (typeof(abm.neighbors) == "string"){ + mtinfo.abm_neighbors[abm.neighbors] = abm; + } else { + abm.neighbors.forEach(function(nodename){ + mtinfo.abm_neighbors[nodename] = abm; + }); + } + } +}); diff --git a/common.lua b/common.lua index 5b41b4b..f856fb2 100644 --- a/common.lua +++ b/common.lua @@ -12,6 +12,10 @@ function mtinfo.map_list(target, list, keys, filter) if def[key] and def[key] ~= 0 then -- only export fields that are populated item[key] = def[key] + if key == "description" then + -- translate content + item[key] = minetest.get_translated_string("", def[key]) + end end end target[name] = item @@ -56,8 +60,8 @@ end 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) + if err or not f then + error("error while opening " .. fname .. " " .. (err or "")) end f:write(varname .. "=") f:write(data_string) diff --git a/init.lua b/init.lua index 2829853..9194c38 100644 --- a/init.lua +++ b/init.lua @@ -14,9 +14,29 @@ dofile(MP .. "/lbm.lua") dofile(MP .. "/recipes.lua") dofile(MP .. "/textures.lua") --- copy static assets -minetest.mkdir(mtinfo.basepath .. "/data") -mtinfo.copyrecursive(MP .. "/app/pics", mtinfo.basepath .. "/pics") -mtinfo.copyrecursive(MP .. "/app/js", mtinfo.basepath .. "/js") -mtinfo.copyrecursive(MP .. "/app/css", mtinfo.basepath .. "/css") -mtinfo.copyfile(MP .. "/app/index.html", mtinfo.basepath .. "/index.html") +minetest.register_on_mods_loaded(function() + + -- workaround for empty translations, defer a globalstep until everything is initialized + minetest.after(0, function() + local start = minetest.get_us_time() + + -- export data + mtinfo.export_nodes() + mtinfo.export_lbms() + mtinfo.export_abms() + mtinfo.export_items() + mtinfo.export_recipes() + mtinfo.export_tools() + + -- copy static assets + minetest.mkdir(mtinfo.basepath) + minetest.mkdir(mtinfo.basepath .. "/data") + mtinfo.copyrecursive(MP .. "/app/pics", mtinfo.basepath .. "/pics") + mtinfo.copyrecursive(MP .. "/app/js", mtinfo.basepath .. "/js") + mtinfo.copyrecursive(MP .. "/app/css", mtinfo.basepath .. "/css") + mtinfo.copyfile(MP .. "/app/index.html", mtinfo.basepath .. "/index.html") + + local diff = minetest.get_us_time() - start + print("[mtinfo] export took " .. diff .. " us") + end) +end) diff --git a/items.lua b/items.lua index 6d6d2f8..7a58f57 100644 --- a/items.lua +++ b/items.lua @@ -8,9 +8,9 @@ local item_mapped_keys = { "range" } -minetest.register_on_mods_loaded(function() +mtinfo.export_items = function() local data = {} mtinfo.map_list(data, minetest.registered_items, item_mapped_keys) mtinfo.export_json(mtinfo.basepath.."/data/items.js", data, "mtinfo.items") -end) +end diff --git a/lbm.lua b/lbm.lua index eba99bd..da6d0e4 100644 --- a/lbm.lua +++ b/lbm.lua @@ -6,9 +6,9 @@ local lbm_mapped_keys = { "run_at_every_load" } -minetest.register_on_mods_loaded(function() +mtinfo.export_lbms = function() local data = {} mtinfo.map_list(data, minetest.registered_lbms, lbm_mapped_keys) mtinfo.export_json(mtinfo.basepath.."/data/lbm.js", data, "mtinfo.lbm") -end) +end diff --git a/nodes.lua b/nodes.lua index 249723b..48fca94 100644 --- a/nodes.lua +++ b/nodes.lua @@ -26,7 +26,7 @@ local node_mapped_keys = { "drop" } -minetest.register_on_mods_loaded(function() +mtinfo.export_nodes = function() local data = {} mtinfo.map_list(data, minetest.registered_nodes, node_mapped_keys, function(def) @@ -37,4 +37,4 @@ minetest.register_on_mods_loaded(function() end end) mtinfo.export_json(mtinfo.basepath.."/data/nodes.js", data, "mtinfo.nodes") -end) +end diff --git a/recipes.lua b/recipes.lua index cc7f6b0..e88e2dd 100644 --- a/recipes.lua +++ b/recipes.lua @@ -1,5 +1,5 @@ -minetest.register_on_mods_loaded(function() +mtinfo.export_recipes = function() local data = {} for name in pairs(minetest.registered_nodes) do @@ -7,4 +7,4 @@ minetest.register_on_mods_loaded(function() end mtinfo.export_json(mtinfo.basepath.."/data/recipes.js", data, "mtinfo.recipes") -end) +end diff --git a/tools.lua b/tools.lua index 067064d..fe21790 100644 --- a/tools.lua +++ b/tools.lua @@ -8,9 +8,9 @@ local tool_mapped_keys = { "range" } -minetest.register_on_mods_loaded(function() +mtinfo.export_tools = function() local data = {} mtinfo.map_list(data, minetest.registered_tools, tool_mapped_keys) mtinfo.export_json(mtinfo.basepath.."/data/tools.js", data, "mtinfo.tools") -end) +end