-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cdaa7d
commit 4e26a8f
Showing
2 changed files
with
88 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,97 @@ | ||
|
||
function blockexchange.upload_mod_media(token, modname, license, source) | ||
local modpath = minetest.get_modpath(modname) | ||
local function upload_nodedefs(token, nodedefs) | ||
local promise = Promise.new() | ||
|
||
local function process_next() | ||
local nodedef = table.remove(nodedefs) | ||
if not nodedef then | ||
promise:resolve() | ||
return | ||
end | ||
blockexchange.api.create_media_nodedef(token, nodedef) | ||
:next(process_next) | ||
:catch(function(e) promise:reject(e) end) | ||
end | ||
process_next() | ||
|
||
return promise | ||
end | ||
|
||
local function upload_mediafiles(token, mediafiles) | ||
local promise = Promise.new() | ||
|
||
local function process_next() | ||
local mediafile = table.remove(mediafiles) | ||
if not mediafile then | ||
promise:resolve({}) | ||
return | ||
end | ||
blockexchange.api.create_media_mediafile(token, mediafile) | ||
:next(process_next) | ||
:catch(function(e) promise:reject(e) end) | ||
end | ||
process_next() | ||
|
||
return promise | ||
end | ||
|
||
function blockexchange.upload_mod_media(token, mod_name, license, source) | ||
local modpath = minetest.get_modpath(mod_name) | ||
|
||
return blockexchange.api.create_media_mod(token, { | ||
name = modname, | ||
name = mod_name, | ||
source = source or "", | ||
media_license = license | ||
}):next(function() | ||
local stats = { nodedefs = 0, mediafiles = 0, size = 0 } | ||
|
||
for nodename in pairs(minetest.registered_nodes) do | ||
local nodedefs = {} | ||
for nodename, def in pairs(minetest.registered_nodes) do | ||
local mn = string.gmatch(nodename, "([^:]+)")() | ||
if mn == modname then | ||
-- TODO: create nodedef | ||
if mn == mod_name then | ||
stats.nodedefs = stats.nodedefs + 1 | ||
table.insert(nodedefs, { | ||
name = nodename, | ||
mod_name = mod_name, | ||
definition = minetest.write_json({ | ||
name = nodename, | ||
drawtype = def.drawtype, | ||
paramtype = def.paramtype, | ||
paramtype2 = def.paramtype2, | ||
light_source = def.light_source, | ||
mesh = def.mesh, | ||
tiles = def.tiles, | ||
node_box = def.node_box, | ||
connects_to = def.connects_to, | ||
groups = def.groups | ||
}) | ||
}) | ||
end | ||
end | ||
local nodedef_promise = upload_nodedefs(token, nodedefs) | ||
|
||
local mediafiles = {} | ||
for _, foldername in ipairs({"textures", "models"}) do | ||
local texturepath = modpath .. "/" .. foldername | ||
local dir_list = minetest.get_dir_list(texturepath) | ||
for _, filename in pairs(dir_list) do | ||
-- TODO: texturepath .. "/" .. filename | ||
local infile = io.open(texturepath .. "/" .. filename, "rb") | ||
local data = infile:read("*a") | ||
infile:close() | ||
|
||
stats.mediafiles = stats.mediafiles + 1 | ||
stats.size = stats.size + #data | ||
table.insert(mediafiles, { | ||
name = filename, | ||
mod_name = mod_name, | ||
data = minetest.encode_base64(data) | ||
}) | ||
end | ||
end | ||
local mediafile_promise = upload_mediafiles(token, mediafiles) | ||
|
||
return { nodedefs = 0, mediafiles = 0, size = 0 } | ||
return Promise.all(nodedef_promise, mediafile_promise):next(function() | ||
return stats | ||
end) | ||
end) | ||
end |