From dd9245c6b22f756bc439960afabf5793634c45f5 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 22 Sep 2017 01:32:45 +0200 Subject: Split nauts.lua into several files now used by Hero and Menu --- config/menus/select.lua | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'config/menus') diff --git a/config/menus/select.lua b/config/menus/select.lua index fee7c94..0d8bef9 100644 --- a/config/menus/select.lua +++ b/config/menus/select.lua @@ -14,25 +14,40 @@ if background == nil or not background:is(require "not.MenuBackground") then background = require "not.MenuBackground"(menu) end --- TODO: Temporary group for naut selectors. This isn't production code at any means! +-- TODO: Icons for nauts and maps are still waiting to get their assets split. local group, get do local atlas = love.graphics.newImage("assets/portraits.png") - local nauts = require("config.nauts") - local icons = {} - for i=0,#nauts-1 do - table.insert(icons, love.graphics.newQuad(i*28, 0, 28, 27, 1176, 27)) + 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.newQuad((i-1)*28, 0, 28, 27, 1176, 27)) + table.insert(nauts, naut) + end + end end + -- TODO: Find a better way to add empty and random entries to naut Selector. + table.insert(icons, 1, love.graphics.newQuad((1-1)*28, 0, 28, 27, 1176, 27)) + table.insert(nauts, 1, {name = "empty"}) + table.insert(icons, 2, love.graphics.newQuad((2-1)*28, 0, 28, 27, 1176, 27)) + table.insert(nauts, 2, {name = "random"}) + group = Group(menu) local function attack (self) if not self.lock then - if self.index == 1 then + local selected = self:getSelected() + if selected.name == "empty" then return end - if self.index == 2 then + if selected.name == "random" then self.index = self:rollRandom({1, 2}) end if self:isUnique() then @@ -46,6 +61,9 @@ do :set("icons_atlas", atlas) :set("icons_quads", icons) :set("attack", attack) + :set("getText", function (self) + return string.upper(self:getSelected().name) + end) end group:set("margin", 16) -- cgit v1.1 From 118c64c62bb19239a28da08f928c2f8e74655f08 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 22 Sep 2017 18:01:09 +0200 Subject: Split map icons, menu now uses them --- config/menus/host.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'config/menus') diff --git a/config/menus/host.lua b/config/menus/host.lua index c8ef4d8..571fc50 100644 --- a/config/menus/host.lua +++ b/config/menus/host.lua @@ -21,7 +21,7 @@ do local i, name = map.portrait, map.name map.filename = path if i then - table.insert(icons, love.graphics.newQuad((i-1)*76, 0, 76, 37, 608, 37)) + table.insert(icons, love.graphics.newImage(map.portrait)) table.insert(maps, map) end end @@ -35,8 +35,7 @@ return { mapSelector :setPosition(width/2-40, 40) :set("shape", Selector.SHAPE_PANORAMA) - :set("icons_quads", icons) - :set("icons_atlas", love.graphics.newImage("assets/maps.png")) + :set("icons", icons) :set("getText", function (self) return self:getSelected().name end) -- cgit v1.1 From e5ad6ac474423176f13a70ae30904aaa48365eda Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 22 Sep 2017 18:02:03 +0200 Subject: Split portraits, menu now should use them --- config/menus/select.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'config/menus') diff --git a/config/menus/select.lua b/config/menus/select.lua index 0d8bef9..fb99780 100644 --- a/config/menus/select.lua +++ b/config/menus/select.lua @@ -14,7 +14,7 @@ if background == nil or not background:is(require "not.MenuBackground") then background = require "not.MenuBackground"(menu) end --- TODO: Icons for nauts and maps are still waiting to get their assets split. +-- TODO: Clean-up menus/select, menus/host and Hero after portraits split. local group, get do local atlas = love.graphics.newImage("assets/portraits.png") @@ -26,16 +26,16 @@ do local naut = love.filesystem.load(path)() local i, name = naut.portrait, naut.name if naut.available then - table.insert(icons, love.graphics.newQuad((i-1)*28, 0, 28, 27, 1176, 27)) + table.insert(icons, love.graphics.newImage(naut.portrait)) table.insert(nauts, naut) end end end -- TODO: Find a better way to add empty and random entries to naut Selector. - table.insert(icons, 1, love.graphics.newQuad((1-1)*28, 0, 28, 27, 1176, 27)) + table.insert(icons, 1, false) table.insert(nauts, 1, {name = "empty"}) - table.insert(icons, 2, love.graphics.newQuad((2-1)*28, 0, 28, 27, 1176, 27)) + table.insert(icons, 2, love.graphics.newImage("assets/portraits/random.png")) table.insert(nauts, 2, {name = "random"}) group = Group(menu) @@ -59,7 +59,7 @@ do for i,_ in pairs(Controller.getSets()) do group:addChild(Selector(nauts, group, menu)) :set("icons_atlas", atlas) - :set("icons_quads", icons) + :set("icons", icons) :set("attack", attack) :set("getText", function (self) return string.upper(self:getSelected().name) -- cgit v1.1 From b29adf54e26d16ec7f78e9dd865bc1ce807d3f14 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 22 Sep 2017 18:04:52 +0200 Subject: Removed obsolete attempts to load portraits atlas --- config/menus/select.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'config/menus') diff --git a/config/menus/select.lua b/config/menus/select.lua index fb99780..a803295 100644 --- a/config/menus/select.lua +++ b/config/menus/select.lua @@ -17,7 +17,6 @@ end -- TODO: Clean-up menus/select, menus/host and Hero after portraits split. local group, get do - local atlas = love.graphics.newImage("assets/portraits.png") local nauts, icons = {}, {} local files = love.filesystem.getDirectoryItems("config/nauts") for _,filename in pairs(files) do @@ -58,7 +57,6 @@ do for i,_ in pairs(Controller.getSets()) do group:addChild(Selector(nauts, group, menu)) - :set("icons_atlas", atlas) :set("icons", icons) :set("attack", attack) :set("getText", function (self) -- cgit v1.1 From 704fa62d2f75e9fca66d94bb809d14785178abed Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 22 Sep 2017 18:18:18 +0200 Subject: Removed obsolete icons functions --- config/menus/host.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config/menus') diff --git a/config/menus/host.lua b/config/menus/host.lua index 571fc50..d586388 100644 --- a/config/menus/host.lua +++ b/config/menus/host.lua @@ -10,7 +10,7 @@ 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. See also: `iconsList`. +-- 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") -- cgit v1.1 From b9f8a7bf85c88a3955d28824627a65efa193e8ad Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 22 Sep 2017 19:20:30 +0200 Subject: Cleaned-up icons and items population for selectors in menu --- config/menus/host.lua | 27 ++++++++++++++------------- config/menus/select.lua | 31 ++++++++++++++++++------------- 2 files changed, 32 insertions(+), 26 deletions(-) (limited to 'config/menus') 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) -- cgit v1.1 From eabad160152f5bf6e7dd442de46b135a1a59f75e Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 22 Sep 2017 19:38:01 +0200 Subject: Changed name of local button --- config/menus/select.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'config/menus') diff --git a/config/menus/select.lua b/config/menus/select.lua index 91da7c9..6dc9d01 100644 --- a/config/menus/select.lua +++ b/config/menus/select.lua @@ -8,7 +8,7 @@ local Group = require "not.Group" local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() local bx = width/2-29 -local start_Button = Button(menu) +local startButton = Button(menu) if background == nil or not background:is(require "not.MenuBackground") then background = require "not.MenuBackground"(menu) @@ -85,7 +85,7 @@ end return { background, group, - start_Button + startButton :setText("Force start") :setPosition(bx,134) :set("isEnabled", function () @@ -123,7 +123,7 @@ return { self.the_final_countdown = 9 end if self.the_final_countdown < 0 then - start_Button:active() + startButton:active() end end) , -- cgit v1.1