diff options
-rw-r--r-- | assets/portraits.png | bin | 24594 -> 23640 bytes | |||
-rw-r--r-- | nautsicons.lua | 4 | ||||
-rw-r--r-- | nautslist.lua | 1 | ||||
-rw-r--r-- | selector.lua | 66 |
4 files changed, 54 insertions, 17 deletions
diff --git a/assets/portraits.png b/assets/portraits.png Binary files differindex 0664be6..c9bbfed 100644 --- a/assets/portraits.png +++ b/assets/portraits.png diff --git a/nautsicons.lua b/nautsicons.lua index e35fa61..6c09a8f 100644 --- a/nautsicons.lua +++ b/nautsicons.lua @@ -1,6 +1,6 @@ -- Spritesheet for character portraits local nauts = require "nautslist" -local w, h = 980, 27 +local w, h = 1008, 27 local icons = {} local i = 0 @@ -8,4 +8,4 @@ for _,naut in pairs(nauts) do icons[naut] = love.graphics.newQuad(i*28, 0, 28, 27, w, h) i = i + 1 end -return icons
\ No newline at end of file +return icons diff --git a/nautslist.lua b/nautslist.lua index 6a9a77f..d0c7a61 100644 --- a/nautslist.lua +++ b/nautslist.lua @@ -2,6 +2,7 @@ -- icons list is generated from this file return { "empty", -- empty + "random", --random "froggo", -- froggy "cowboy", -- lonestar "honic", -- leon diff --git a/selector.lua b/selector.lua index de20699..851e451 100644 --- a/selector.lua +++ b/selector.lua @@ -106,24 +106,12 @@ end -- Cycle through list on given number function Selector:next(n) - local total = #self.list local current = self.selections[n] - local locked = self:isLocked(n) - if not locked then - self.selections[n] = (current % total) + 1 - end + self:setSelection(n, current + 1) end function Selector:previous(n) - local total = #self.list local current = self.selections[n] - local locked = self:isLocked(n) - if not locked then - if current == 1 then - self.selections[n] = total - else - self.selections[n] = current - 1 - end - end + self:setSelection(n, current - 1) end -- Get number associated with a given set @@ -140,6 +128,24 @@ function Selector:isLocked(n) return self.locks[n] end +-- Sets value of selection of given number. Returns old. +function Selector:setSelection(n, new) + -- Functception. It sounds like fun but it isn't. + local function limit(new, total) + if new > total then + return limit(new - total, total) + elseif new < 1 then + return limit(total + new, total) + else + return new + end + end + local n = n or 1 + local old = self.selections[n] + self.selections[n] = limit(new, #self.list) + return old +end + -- Get value of selection of given number function Selector:getSelection(n) local n = n or 1 @@ -179,6 +185,29 @@ function Selector:getFullSelection(allowed) return t end +-- Rolls and returns random selection from list that is not locked. +function Selector:rollRandom(avoids) + -- Me: You should make it simpler. + -- Inner me: Nah, it works. Leave it. + -- Me: Ok, let's leave it as it is. + local avoids = avoids or {} + local total = #self.list + local random = love.math.random(1, total) + local eligible = true + for _,avoid in ipairs(avoids) do + if random == avoid then + eligible = false + break + end + end + if not eligible or self:isLocked(random) then + table.insert(avoids, random) + return self:rollRandom(avoid) + else + return random + end +end + -- Draw single block of Selector function Selector:drawBlock(n, x, y, scale) if self.quads == nil or self.sprite == nil then return end @@ -253,8 +282,15 @@ function Selector:controlpressed(set, action, key) if action == "left" and not locked then self:previous(n) end if action == "right" and not locked then self:next(n) end if action == "attack" then - if (self:getSelection(n) ~= 1 or self.first) and self:isUnique(n) then + local name = self:getListValue(self:getSelection(n)) + if name == "random" then + self:setSelection(n, self:rollRandom({1})) -- avoid empty naut self.locks[n] = true + else + -- If not empty or if first is allowed. Additionaly must be unique selection. + if (self:getSelection(n) ~= 1 or self.first) and self:isUnique(n) then + self.locks[n] = true + end end end if action == "jump" then |