1
0
Fork 0

Added a return code to load_maps

Added a return code to load_maps to check for if dynamic_add_media registers a fail.
Used by mcl_itemframes when reloading a map placed into an itemframe.
This commit is contained in:
Michieal 2022-11-01 00:57:04 +00:00 committed by cora
parent 1f5b92f7bf
commit 6d1b1b3c74
1 changed files with 283 additions and 267 deletions

View File

@ -22,6 +22,9 @@ local map_textures_path = worldpath .. "/mcl_maps/"
minetest.mkdir(map_textures_path) minetest.mkdir(map_textures_path)
-- overwrite the builtin tga_encoder
dofile(modpath .. "/tga_encoder_init.lua")
local function load_json_file(name) local function load_json_file(name)
local file = assert(io.open(modpath .. "/" .. name .. ".json", "r")) local file = assert(io.open(modpath .. "/" .. name .. ".json", "r"))
local data = minetest.parse_json(file:read()) local data = minetest.parse_json(file:read())
@ -141,30 +144,43 @@ end
function mcl_maps.load_map(id, callback) function mcl_maps.load_map(id, callback)
if id == "" or creating_maps[id] then if id == "" or creating_maps[id] then
return return false
end end
local texture = "mcl_maps_map_texture_" .. id .. ".tga" local texture = "mcl_maps_map_texture_" .. id .. ".tga"
local result = true
if not loaded_maps[id] then if not loaded_maps[id] then
if not minetest.features.dynamic_add_media_table then if not minetest.features.dynamic_add_media_table then
-- minetest.dynamic_add_media() blocks in -- minetest.dynamic_add_media() blocks in
-- Minetest 5.3 and 5.4 until media loads -- Minetest 5.3 and 5.4 until media loads
loaded_maps[id] = true loaded_maps[id] = true
dynamic_add_media(map_textures_path .. texture, function() end) result = dynamic_add_media(map_textures_path .. texture, function()
if callback then callback(texture) end end)
if callback then
callback(texture)
end
else else
-- minetest.dynamic_add_media() never blocks -- minetest.dynamic_add_media() never blocks
-- in Minetest 5.5, callback runs after load -- in Minetest 5.5, callback runs after load
dynamic_add_media(map_textures_path .. texture, function() result = dynamic_add_media(map_textures_path .. texture, function()
loaded_maps[id] = true loaded_maps[id] = true
if callback then callback(texture) end if callback then
callback(texture)
end
end) end)
end end
end end
if result == false then
return false
end
if loaded_maps[id] then if loaded_maps[id] then
if callback then callback(texture) end if callback then
callback(texture)
end
return texture return texture
end end
end end