From 975e5663c09f0d74b2d0a18a7a5ce1297362a4a2 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 02:36:08 +0200 Subject: Moved selector's action handlers outside controlpressed method --- not/Selector.lua | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index ed1813f..bd6224b 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -145,23 +145,32 @@ end function Selector:controlpressed (set, action, key) if set and self.focused then - if not self.lock then - if action == "left" then - self:setIndex(self.index - 1) - end - if action == "right" then - self:setIndex(self.index + 1) - end - -- TODO: Extend functionality on attack action in Selector. - if action == "attack" then - self.lock = true - end + local handler = self[action] + if handler then + handler(self) end + end +end - if action == "jump" then - self.lock = false - end +function Selector:left () + if not self.lock then + self:setIndex(self.index - 1) + end +end + +function Selector:right () + if not self.lock then + self:setIndex(self.index + 1) end end +function Selector:attack () + self.lock = true +end + +-- Selector doesn't actually jump, haha, I tricked you! +function Selector:jump () + self.lock = false +end + return Selector -- cgit v1.1