Skip to content

Instantly share code, notes, and snippets.

@bucketh3ad
Last active December 17, 2015 06:39
Show Gist options
  • Save bucketh3ad/5566850 to your computer and use it in GitHub Desktop.
Save bucketh3ad/5566850 to your computer and use it in GitHub Desktop.
A small part of the inventory refactor for journey to hawkthorne -bucketh3ad
BEFORE:
function Inventory:keypressed( button )
if self:isOpen() then
if button == 'SELECT' then
self:close()
end
if button == 'RIGHT' then
self:right()
end
if button == 'LEFT' then
self:left()
end
if button == 'UP' then
self:up()
end
if button == 'DOWN' then
self:down()
end
if button == 'ATTACK' then
self:select()
end
end
end
AFTER:
---
-- Handles player input while in the inventory
-- @return nil
function Inventory:keypressed( button )
local keys = {
RIGHT = self.right,
LEFT = self.left,
UP = self.up,
DOWN = self.down,
ATTACK = self.select,
SELECT = self.close
}
if self:isOpen() and keys[button] ~= nil then keys[button]() end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment