aboutsummaryrefslogtreecommitdiff
path: root/builtin/mainmenu
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2015-07-18 14:31:34 +0200
committerest31 <MTest31@outlook.com>2015-07-21 16:58:22 +0200
commit899491325938d0b1e5bf701d33d24bb4283affaa (patch)
tree4e75c4a81854556223ccaef8ad02936fd55e82b9 /builtin/mainmenu
parentfa7fe510d9b77c0a7802604a5697de4e52cddba3 (diff)
downloadminetest-899491325938d0b1e5bf701d33d24bb4283affaa.tar.gz
minetest-899491325938d0b1e5bf701d33d24bb4283affaa.tar.bz2
minetest-899491325938d0b1e5bf701d33d24bb4283affaa.zip
Allow random menu images for subgames
Diffstat (limited to 'builtin/mainmenu')
-rw-r--r--builtin/mainmenu/textures.lua30
1 files changed, 24 insertions, 6 deletions
diff --git a/builtin/mainmenu/textures.lua b/builtin/mainmenu/textures.lua
index 56992c0c5..700bdb5cc 100644
--- a/builtin/mainmenu/textures.lua
+++ b/builtin/mainmenu/textures.lua
@@ -129,7 +129,7 @@ function mm_texture.set_generic(identifier)
end
--------------------------------------------------------------------------------
-function mm_texture.set_game(identifier,gamedetails)
+function mm_texture.set_game(identifier, gamedetails)
if gamedetails == nil then
return false
@@ -137,15 +137,33 @@ function mm_texture.set_game(identifier,gamedetails)
if mm_texture.texturepack ~= nil then
local path = mm_texture.texturepack .. DIR_DELIM ..
- gamedetails.id .. "_menu_" .. identifier .. ".png"
- if core.set_background(identifier,path) then
+ gamedetails.id .. "_menu_" .. identifier .. ".png"
+ if core.set_background(identifier, path) then
return true
end
end
- local path = gamedetails.path .. DIR_DELIM .."menu" ..
- DIR_DELIM .. identifier .. ".png"
- if core.set_background(identifier,path) then
+ -- Find out how many randomized textures the subgame provides
+ local n, filename
+ local menu_files = core.get_dir_list(gamedetails.path .. DIR_DELIM .. "menu", false)
+ for i = 1, #menu_files do
+ local filename = identifier .. "." .. i .. ".png"
+ if table.indexof(menu_files, filename) == -1 then
+ n = i - 1
+ break
+ end
+ end
+ -- Select random texture, 0 means standard texture
+ n = math.random(0, n)
+ if n == 0 then
+ filename = identifier .. ".png"
+ else
+ filename = identifier .. "." .. n .. ".png"
+ end
+
+ local path = gamedetails.path .. DIR_DELIM .. "menu" ..
+ DIR_DELIM .. filename
+ if core.set_background(identifier, path) then
return true
end