Skip to content

Commit 8994913

Browse files
sfan5est31
authored andcommittedJul 21, 2015
Allow random menu images for subgames
1 parent fa7fe51 commit 8994913

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed
 

Diff for: ‎builtin/common/misc_helpers.lua

+15-1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ function dump(o, indent, nested, level)
159159
return "{"..table.concat(t, ", ").."}"
160160
end
161161

162+
--------------------------------------------------------------------------------
162163
function string.split(str, delim, include_empty, max_splits, sep_is_pattern)
163164
delim = delim or ","
164165
max_splits = max_splits or -1
@@ -183,10 +184,23 @@ function string.split(str, delim, include_empty, max_splits, sep_is_pattern)
183184
return items
184185
end
185186

187+
--------------------------------------------------------------------------------
188+
function table.indexof(list, val)
189+
for i = 1, #list do
190+
if list[i] == val then
191+
return i
192+
end
193+
end
194+
return -1
195+
end
196+
197+
assert(table.indexof({"foo", "bar"}, "foo") == 1)
198+
assert(table.indexof({"foo", "bar"}, "baz") == -1)
199+
186200
--------------------------------------------------------------------------------
187201
function file_exists(filename)
188202
local f = io.open(filename, "r")
189-
if f==nil then
203+
if f == nil then
190204
return false
191205
else
192206
f:close()

Diff for: ‎builtin/mainmenu/textures.lua

+24-6
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,41 @@ function mm_texture.set_generic(identifier)
129129
end
130130

131131
--------------------------------------------------------------------------------
132-
function mm_texture.set_game(identifier,gamedetails)
132+
function mm_texture.set_game(identifier, gamedetails)
133133

134134
if gamedetails == nil then
135135
return false
136136
end
137137

138138
if mm_texture.texturepack ~= nil then
139139
local path = mm_texture.texturepack .. DIR_DELIM ..
140-
gamedetails.id .. "_menu_" .. identifier .. ".png"
141-
if core.set_background(identifier,path) then
140+
gamedetails.id .. "_menu_" .. identifier .. ".png"
141+
if core.set_background(identifier, path) then
142142
return true
143143
end
144144
end
145145

146-
local path = gamedetails.path .. DIR_DELIM .."menu" ..
147-
DIR_DELIM .. identifier .. ".png"
148-
if core.set_background(identifier,path) then
146+
-- Find out how many randomized textures the subgame provides
147+
local n, filename
148+
local menu_files = core.get_dir_list(gamedetails.path .. DIR_DELIM .. "menu", false)
149+
for i = 1, #menu_files do
150+
local filename = identifier .. "." .. i .. ".png"
151+
if table.indexof(menu_files, filename) == -1 then
152+
n = i - 1
153+
break
154+
end
155+
end
156+
-- Select random texture, 0 means standard texture
157+
n = math.random(0, n)
Has a conversation. Original line has a conversation.
158+
if n == 0 then
159+
filename = identifier .. ".png"
160+
else
161+
filename = identifier .. "." .. n .. ".png"
162+
end
163+
164+
local path = gamedetails.path .. DIR_DELIM .. "menu" ..
165+
DIR_DELIM .. filename
166+
if core.set_background(identifier, path) then
149167
return true
150168
end
151169

0 commit comments

Comments
 (0)
Please sign in to comment.