Allow paintable deletion
parent
73eba66b0a
commit
22b12126e1
|
@ -292,8 +292,12 @@ function def:on_activate()
|
||||||
end, true)
|
end, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO (engine change needed) remove directory using `minetest.rmdir(self:_get_dir_path())` on object removal
|
-- TODO (engine change needed) call this on object removal
|
||||||
-- See https://github.com/minetest/minetest/pull/11931
|
-- See https://github.com/minetest/minetest/pull/11931
|
||||||
|
function def:_delete()
|
||||||
|
epidermis.mark_for_deletion(self._.id)
|
||||||
|
self.object:remove()
|
||||||
|
end
|
||||||
|
|
||||||
function def:_get_intersection_infos(mt_pos, mt_direction)
|
function def:_get_intersection_infos(mt_pos, mt_direction)
|
||||||
local intersection_infos = {}
|
local intersection_infos = {}
|
||||||
|
@ -404,7 +408,7 @@ function def:_show_control_panel(player)
|
||||||
end
|
end
|
||||||
local backface_culling = self._.backface_culling
|
local backface_culling = self._.backface_culling
|
||||||
epidermis.show_formspec(player, table.concat{
|
epidermis.show_formspec(player, table.concat{
|
||||||
"size[5.5,1,false]",
|
"size[6.25,1,false]",
|
||||||
"real_coordinates[true]",
|
"real_coordinates[true]",
|
||||||
image_button(true, 0.25, "backface_culling", (backface_culling and "backface_visible" or "backface_hidden"),
|
image_button(true, 0.25, "backface_culling", (backface_culling and "backface_visible" or "backface_hidden"),
|
||||||
(backface_culling and "Show" or "Hide") .. " back faces"),
|
(backface_culling and "Show" or "Hide") .. " back faces"),
|
||||||
|
@ -415,7 +419,8 @@ function def:_show_control_panel(player)
|
||||||
image_button(false, 2.75, "preview_texture", "checker", "Open texture preview"),
|
image_button(false, 2.75, "preview_texture", "checker", "Open texture preview"),
|
||||||
image_button(false, 3.5, "upload", "upload", "Upload to SkinDB"),
|
image_button(false, 3.5, "upload", "upload", "Upload to SkinDB"),
|
||||||
image_button(false, 4, "download", "download", "Pick from SkinDB"),
|
image_button(false, 4, "download", "download", "Pick from SkinDB"),
|
||||||
image_button(true, 4.75, "close", "cross", "Close"),
|
image_button(false, 4.75, "delete", "bin", "Delete"),
|
||||||
|
image_button(true, 5.5, "close", "cross", "Close"),
|
||||||
}, function(fields)
|
}, function(fields)
|
||||||
if fields.backface_culling then
|
if fields.backface_culling then
|
||||||
self:_set_backface_culling(not self._.backface_culling)
|
self:_set_backface_culling(not self._.backface_culling)
|
||||||
|
@ -434,6 +439,8 @@ function def:_show_control_panel(player)
|
||||||
end)
|
end)
|
||||||
elseif fields.preview_texture then
|
elseif fields.preview_texture then
|
||||||
self:_show_texture_preview(player)
|
self:_show_texture_preview(player)
|
||||||
|
elseif fields.delete then
|
||||||
|
self:_show_delete_formspec(player)
|
||||||
elseif fields.upload then
|
elseif fields.upload then
|
||||||
self:_show_upload_formspec(player)
|
self:_show_upload_formspec(player)
|
||||||
elseif fields.download then
|
elseif fields.download then
|
||||||
|
@ -461,6 +468,22 @@ function def:_show_texture_preview(player)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function def:_show_delete_formspec(player)
|
||||||
|
epidermis.show_formspec(player, table.concat{
|
||||||
|
"size[6,1,false]",
|
||||||
|
"real_coordinates[true]",
|
||||||
|
"label[0.25,0.5;Irreversably delete paintable?]",
|
||||||
|
"image_button_exit[4.75,0.25;0.5,0.5;epidermis_check.png;confirm;]";
|
||||||
|
"tooltip[confirm;Confirm]",
|
||||||
|
"image_button_exit[5.25,0.25;0.5,0.5;epidermis_cross.png;close;]",
|
||||||
|
"tooltip[close;Close]",
|
||||||
|
}, function(fields)
|
||||||
|
if fields.confirm then
|
||||||
|
self:_delete()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
function def:_show_upload_formspec(player, message)
|
function def:_show_upload_formspec(player, message)
|
||||||
local context = {}
|
local context = {}
|
||||||
epidermis.show_formspec(player, table.concat{
|
epidermis.show_formspec(player, table.concat{
|
||||||
|
|
|
@ -55,31 +55,48 @@ end)
|
||||||
-- Remove unused textures & store highest texture ID
|
-- Remove unused textures & store highest texture ID
|
||||||
local epidermi_texture_path = epidermis.paths.dynamic_textures.epidermi
|
local epidermi_texture_path = epidermis.paths.dynamic_textures.epidermi
|
||||||
for _, dirname in ipairs(minetest.get_dir_list(epidermi_texture_path, true)) do
|
for _, dirname in ipairs(minetest.get_dir_list(epidermi_texture_path, true)) do
|
||||||
|
local dir_path = concat_path{epidermi_texture_path, dirname}
|
||||||
local highest_number
|
local highest_number
|
||||||
local last_filename
|
local last_filename
|
||||||
|
local used = false
|
||||||
local function remove_if_unused(filename)
|
local function remove_if_unused(filename)
|
||||||
if not used_textures[filename] then
|
if used_textures[filename] then
|
||||||
assert(os.remove(concat_path{epidermi_texture_path, dirname, filename}))
|
used = true
|
||||||
|
else
|
||||||
|
assert(os.remove(concat_path{dir_path, filename}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for _, filename in ipairs(minetest.get_dir_list(concat_path{epidermi_texture_path, dirname}, false)) do
|
local filenames = minetest.get_dir_list(dir_path, false)
|
||||||
local number = filename:match("^" .. modlib.text.escape_magic_chars(dirname) .. "_(%d+)%.png$")
|
local delete = modlib.table.contains(filenames, "delete")
|
||||||
if number then
|
if delete then
|
||||||
number = tonumber(number)
|
-- Move deletion marker to end through a swap so that it is deleted last
|
||||||
if last_filename then
|
filenames[#filenames], filenames[delete] = filenames[delete], filenames[#filenames]
|
||||||
if number > highest_number then
|
end
|
||||||
remove_if_unused(last_filename)
|
for _, filename in ipairs(filenames) do
|
||||||
|
if delete then
|
||||||
|
remove_if_unused(filename)
|
||||||
|
else
|
||||||
|
local number = filename:match("^" .. modlib.text.escape_magic_chars(dirname) .. "_(%d+)%.png$")
|
||||||
|
if number then
|
||||||
|
number = tonumber(number)
|
||||||
|
if last_filename then
|
||||||
|
if number > highest_number then
|
||||||
|
remove_if_unused(last_filename)
|
||||||
|
highest_number = number
|
||||||
|
last_filename = filename
|
||||||
|
else
|
||||||
|
remove_if_unused(filename)
|
||||||
|
end
|
||||||
|
else
|
||||||
highest_number = number
|
highest_number = number
|
||||||
last_filename = filename
|
last_filename = filename
|
||||||
else
|
|
||||||
remove_if_unused(filename)
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
highest_number = number
|
|
||||||
last_filename = filename
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if not used and (delete or #filenames == 0) then
|
||||||
|
assert(os.remove(dir_path))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function epidermis.get_epidermis_path(paintable_id, texture_id)
|
function epidermis.get_epidermis_path(paintable_id, texture_id)
|
||||||
|
@ -117,6 +134,14 @@ function epidermis.write_epidermis(paintable_id, texture_id, raw_png_data)
|
||||||
return path, texture_name
|
return path, texture_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function epidermis.mark_for_deletion(paintable_id)
|
||||||
|
assert(modlib.file.write_unsafe(concat_path{
|
||||||
|
epidermi_texture_path,
|
||||||
|
("epidermis_paintable_%d"):format(paintable_id),
|
||||||
|
"delete"
|
||||||
|
}, ""))
|
||||||
|
end
|
||||||
|
|
||||||
-- SkinDB
|
-- SkinDB
|
||||||
|
|
||||||
function epidermis.write_skindb_skin(id, raw_png_data, meta_data)
|
function epidermis.write_skindb_skin(id, raw_png_data, meta_data)
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 103 B |
Loading…
Reference in New Issue