mirror of
https://github.com/APercy/airutils.git
synced 2025-03-21 18:41:21 +00:00
filtered the textures dictionary
This commit is contained in:
parent
647a637528
commit
6f5e670324
1 changed files with 40 additions and 3 deletions
|
@ -47,10 +47,26 @@ local function getTexturesFromItem(itemDef)
|
||||||
return textures
|
return textures
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--function to remove duplicates and invalid for textlist
|
||||||
|
function filter_texture_names(list_to_test)
|
||||||
|
local hash = {}
|
||||||
|
local result = {}
|
||||||
|
for _,v in ipairs(list_to_test) do
|
||||||
|
if not string.find(v, ",") then
|
||||||
|
if (not hash[v]) then
|
||||||
|
result[#result+1] = v
|
||||||
|
hash[v] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
-- Function to list all loaded textures
|
-- Function to list all loaded textures
|
||||||
function listLoadedTextures()
|
function listLoadedTextures()
|
||||||
local loadedTextures = {}
|
local loadedTextures = {}
|
||||||
|
|
||||||
|
--nodes
|
||||||
for name, node in pairs(minetest.registered_nodes) do
|
for name, node in pairs(minetest.registered_nodes) do
|
||||||
local textures = getTexturesFromNode(node)
|
local textures = getTexturesFromNode(node)
|
||||||
|
|
||||||
|
@ -58,7 +74,10 @@ function listLoadedTextures()
|
||||||
table.insert(loadedTextures, texture)
|
table.insert(loadedTextures, texture)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
airutils.all_game_textures = filter_texture_names(loadedTextures)
|
||||||
|
|
||||||
|
--entities
|
||||||
|
loadedTextures = {}
|
||||||
for name, entityDef in pairs(minetest.registered_entities) do
|
for name, entityDef in pairs(minetest.registered_entities) do
|
||||||
local textures = getTexturesFromEntity(entityDef)
|
local textures = getTexturesFromEntity(entityDef)
|
||||||
|
|
||||||
|
@ -66,7 +85,10 @@ function listLoadedTextures()
|
||||||
table.insert(loadedTextures, texture)
|
table.insert(loadedTextures, texture)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
airutils.all_entities_textures = filter_texture_names(loadedTextures)
|
||||||
|
|
||||||
|
--items
|
||||||
|
loadedTextures = {}
|
||||||
for name, itemDef in pairs(minetest.registered_items) do
|
for name, itemDef in pairs(minetest.registered_items) do
|
||||||
local textures = getTexturesFromItem(itemDef)
|
local textures = getTexturesFromItem(itemDef)
|
||||||
|
|
||||||
|
@ -79,14 +101,13 @@ function listLoadedTextures()
|
||||||
table.insert(loadedTextures,'bubble.png')
|
table.insert(loadedTextures,'bubble.png')
|
||||||
table.insert(loadedTextures,'heart.png')
|
table.insert(loadedTextures,'heart.png')
|
||||||
end
|
end
|
||||||
|
airutils.all_items_textures = filter_texture_names(loadedTextures)
|
||||||
return loadedTextures
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function to check if a texture is in the list of loaded textures
|
-- Function to check if a texture is in the list of loaded textures
|
||||||
function airutils.isTextureLoaded(textureToFind)
|
function airutils.isTextureLoaded(textureToFind)
|
||||||
if not airutils.all_game_textures then
|
if not airutils.all_game_textures then
|
||||||
airutils.all_game_textures = listLoadedTextures()
|
listLoadedTextures()
|
||||||
end
|
end
|
||||||
local textures = airutils.all_game_textures
|
local textures = airutils.all_game_textures
|
||||||
|
|
||||||
|
@ -96,5 +117,21 @@ function airutils.isTextureLoaded(textureToFind)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
textures = airutils.all_entities_textures
|
||||||
|
|
||||||
|
for _, texture in pairs(textures) do
|
||||||
|
if texture == textureToFind then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
textures = airutils.all_items_textures
|
||||||
|
|
||||||
|
for _, texture in pairs(textures) do
|
||||||
|
if texture == textureToFind then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue