Created
May 13, 2013 19:25
-
-
Save bucketh3ad/5570780 to your computer and use it in GitHub Desktop.
Inventory Open/Close Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is the relevant code in its current form. | |
These two functions are responsible for closing the inventory, and should be consolidated somehow: | |
--- | |
-- Begins closing the players inventory | |
-- @return nil | |
function Inventory:close() | |
self.player.controlState:standard() | |
self:craftingClose() | |
self.pageNext = self.state | |
self.state = 'closing' | |
self:animation():resume() | |
end | |
--- | |
-- Finishes closing the players inventory | |
-- @return nil | |
function Inventory:closed() | |
self:animation():gotoFrame(5) | |
self:animation():pause() | |
self.visible = false | |
self.state = 'closed' | |
self.cursorPos = {x=0,y=0} | |
self.scrollbar = 1 | |
self.player.freeze = false | |
end | |
The above functions are called from update. | |
--- | |
-- Updates the inventory with player input | |
-- @param dt the delta time for updating the animation. | |
-- @return nil | |
function Inventory:update( dt ) | |
if not self.visible then return end | |
--Update the animations | |
self:animation():update(dt) | |
self:craftingAnimation():update(dt) | |
--If we're finished with an animation, then in some cases that means we should move to the next one. | |
if self:animation().status == "finished" then | |
if self.state == "closing" then | |
self:closed() | |
elseif self.state == "opening" then | |
self:opened() | |
end | |
end | |
if self:craftingAnimation().status == "finished" then | |
if self.craftingState == "closing" then | |
self:craftingClosed() | |
elseif self.craftingState == "opening" then | |
self:craftingOpened() | |
end | |
end | |
end | |
As you can see, there are checks in the logic for the status of an animation state. This state is caused by the first function and the check triggers the second function. I think this is the wrong way to implement all of this functionality. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment