summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-09-22 19:20:30 +0200
committerAki <nthirtyone@gmail.com>2017-09-22 19:20:30 +0200
commitb9f8a7bf85c88a3955d28824627a65efa193e8ad (patch)
tree81c078c26e9b51e6458e559f1b034abe0fa49453
parent86c552cab9d245b6d58638179df2ae657ef9a5db (diff)
downloadroflnauts-b9f8a7bf85c88a3955d28824627a65efa193e8ad.zip
roflnauts-b9f8a7bf85c88a3955d28824627a65efa193e8ad.tar.gz
roflnauts-b9f8a7bf85c88a3955d28824627a65efa193e8ad.tar.bz2
Cleaned-up icons and items population for selectors in menu
-rw-r--r--config/menus/host.lua27
-rw-r--r--config/menus/select.lua31
2 files changed, 32 insertions, 26 deletions
diff --git a/config/menus/host.lua b/config/menus/host.lua
index d586388..ce67047 100644
--- a/config/menus/host.lua
+++ b/config/menus/host.lua
@@ -10,24 +10,25 @@ if background == nil or not background:is(require "not.MenuBackground") then
background = require "not.MenuBackground"(menu)
end
--- TODO: This is temporary solution for generating available maps list and portraits for them to pass to Selector.
-local icons, maps = {}, {}
-do
- local files = love.filesystem.getDirectoryItems("config/maps")
- for _,filename in pairs(files) do
- local path = string.format("config/maps/%s", filename)
- if love.filesystem.isFile(path) and filename ~= "readme.md" then
- local map = love.filesystem.load(path)()
- local i, name = map.portrait, map.name
- map.filename = path
- if i then
- table.insert(icons, love.graphics.newImage(map.portrait))
- table.insert(maps, map)
+-- TODO: loadConfigs is duplicated in menus/select and menus/host.
+local
+function loadConfigs (dir, process)
+ local items, icons = {}, {}
+ for _,file in pairs(love.filesystem.getDirectoryItems(dir)) do
+ local path = string.format("%s/%s", dir, file)
+ if love.filesystem.isFile(path) and file ~= "readme.md" then
+ local item = love.filesystem.load(path)()
+ if item and process(item, file, path) then
+ table.insert(icons, love.graphics.newImage(item.portrait))
+ table.insert(items, item)
end
end
end
+ return items, icons
end
+-- TODO: This is temporary solution for generating available maps list and portraits for them to pass to Selector.
+local maps, icons = loadConfigs("config/maps", function (map, _, path) map.filename = path; return true end)
local mapSelector = Selector(maps, nil, menu)
return {
diff --git a/config/menus/select.lua b/config/menus/select.lua
index a803295..91da7c9 100644
--- a/config/menus/select.lua
+++ b/config/menus/select.lua
@@ -14,22 +14,27 @@ if background == nil or not background:is(require "not.MenuBackground") then
background = require "not.MenuBackground"(menu)
end
--- TODO: Clean-up menus/select, menus/host and Hero after portraits split.
-local group, get
-do
- local nauts, icons = {}, {}
- local files = love.filesystem.getDirectoryItems("config/nauts")
- for _,filename in pairs(files) do
- local path = string.format("config/nauts/%s", filename)
- if love.filesystem.isFile(path) and filename ~= "readme.md" then
- local naut = love.filesystem.load(path)()
- local i, name = naut.portrait, naut.name
- if naut.available then
- table.insert(icons, love.graphics.newImage(naut.portrait))
- table.insert(nauts, naut)
+-- TODO: loadConfigs is duplicated in menus/select and menus/host.
+local
+function loadConfigs (dir, process)
+ local items, icons = {}, {}
+ for _,file in pairs(love.filesystem.getDirectoryItems(dir)) do
+ local path = string.format("%s/%s", dir, file)
+ if love.filesystem.isFile(path) and file ~= "readme.md" then
+ local item = love.filesystem.load(path)()
+ if item and process(item) then
+ table.insert(icons, love.graphics.newImage(item.portrait))
+ table.insert(items, item)
end
end
end
+ return items, icons
+end
+
+-- TODO: Clean-up menus/select, menus/host and Hero after portraits split.
+local group, get
+do
+ local nauts, icons = loadConfigs("config/nauts", function (naut) return naut.available end)
-- TODO: Find a better way to add empty and random entries to naut Selector.
table.insert(icons, 1, false)