mirror of
https://github.com/APercy/airutils.git
synced 2025-03-21 18:41:21 +00:00
added texture management
This commit is contained in:
parent
a7e6f705be
commit
29a8456ebd
2 changed files with 100 additions and 0 deletions
1
init.lua
1
init.lua
|
@ -55,6 +55,7 @@ dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "inventory_management.lu
|
||||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "light.lua")
|
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "light.lua")
|
||||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "physics_lib.lua")
|
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "physics_lib.lua")
|
||||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "init.lua")
|
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "init.lua")
|
||||||
|
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "texture_management.lua")
|
||||||
|
|
||||||
local is_biofuel_installed = false
|
local is_biofuel_installed = false
|
||||||
if biomass then
|
if biomass then
|
||||||
|
|
99
texture_management.lua
Normal file
99
texture_management.lua
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
-- Function to extract textures from a node definition
|
||||||
|
local function getTexturesFromNode(node)
|
||||||
|
local textures = {}
|
||||||
|
|
||||||
|
if node.tiles then
|
||||||
|
if type(node.tiles) == "string" then
|
||||||
|
table.insert(textures, node.tiles)
|
||||||
|
elseif type(node.tiles) == "table" then
|
||||||
|
for _, tile in pairs(node.tiles) do
|
||||||
|
if type(tile) == "string" then
|
||||||
|
table.insert(textures, tile)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return textures
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Function to extract textures from an entity definition
|
||||||
|
local function getTexturesFromEntity(entityDef)
|
||||||
|
local textures = {}
|
||||||
|
|
||||||
|
if entityDef.textures then
|
||||||
|
if type(entityDef.textures) == "string" then
|
||||||
|
table.insert(textures, entityDef.textures)
|
||||||
|
elseif type(entityDef.textures) == "table" then
|
||||||
|
for _, texture in pairs(entityDef.textures) do
|
||||||
|
if type(texture) == "string" then
|
||||||
|
table.insert(textures, texture)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return textures
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Function to extract textures from an item definition
|
||||||
|
local function getTexturesFromItem(itemDef)
|
||||||
|
local textures = {}
|
||||||
|
|
||||||
|
if itemDef.inventory_image then
|
||||||
|
table.insert(textures, itemDef.inventory_image)
|
||||||
|
end
|
||||||
|
|
||||||
|
return textures
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Function to list all loaded textures
|
||||||
|
function listLoadedTextures()
|
||||||
|
local loadedTextures = {}
|
||||||
|
|
||||||
|
for name, node in pairs(minetest.registered_nodes) do
|
||||||
|
local textures = getTexturesFromNode(node)
|
||||||
|
|
||||||
|
for _, texture in pairs(textures) do
|
||||||
|
table.insert(loadedTextures, texture)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for name, entityDef in pairs(minetest.registered_entities) do
|
||||||
|
local textures = getTexturesFromEntity(entityDef)
|
||||||
|
|
||||||
|
for _, texture in pairs(textures) do
|
||||||
|
table.insert(loadedTextures, texture)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for name, itemDef in pairs(minetest.registered_items) do
|
||||||
|
local textures = getTexturesFromItem(itemDef)
|
||||||
|
|
||||||
|
for _, texture in pairs(textures) do
|
||||||
|
table.insert(loadedTextures, texture)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if airutils.is_minetest then
|
||||||
|
table.insert(loadedTextures,'bubble.png')
|
||||||
|
table.insert(loadedTextures,'heart.png')
|
||||||
|
end
|
||||||
|
|
||||||
|
return loadedTextures
|
||||||
|
end
|
||||||
|
|
||||||
|
airutils.all_game_textures = listLoadedTextures()
|
||||||
|
|
||||||
|
-- Function to check if a texture is in the list of loaded textures
|
||||||
|
function airutils.isTextureLoaded(textureToFind)
|
||||||
|
local textures = airutils.all_game_textures
|
||||||
|
|
||||||
|
for _, texture in pairs(textures) do
|
||||||
|
if texture == textureToFind then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue