Skip to content

Commit daee454

Browse files
flamendlessjosh-perry
authored andcommitted
added getDimensions and getJSON
1 parent 1c1e312 commit daee454

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

peachy.lua

+28-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ peachy.__index = peachy
5656
-- @return the new Peachy object.
5757
function peachy.new(dataFile, imageData, initialTag)
5858
assert(dataFile ~= nil, "No JSON data!")
59-
59+
6060
local self = setmetatable({}, peachy)
61-
61+
62+
--store the path to the passed json file
63+
self.json_path = dataFile
64+
6265
-- check if datafile is a lua table (i.e. pre decoded)
6366
if type(dataFile) == 'table' then
6467
self._jsonData = dataFile
@@ -134,6 +137,24 @@ function peachy:setFrame(frame)
134137
self.frameTimer = cron.after(self.frame.duration, self.nextFrame, self)
135138
end
136139

140+
--- Get the current frame of the current animation
141+
-- @usage
142+
-- Get the 2nd frame
143+
-- local f = sound:getFrame()
144+
--
145+
function peachy:getFrame()
146+
return self.frameIndex
147+
end
148+
149+
--- Get the json path passed in the object
150+
-- @usage
151+
-- Get the (string) JSON path
152+
-- local str_json = obj:getJSON()
153+
--
154+
function peachy:getJSON()
155+
return self.json_path
156+
end
157+
137158
--- Draw the animation's current frame in a specified location.
138159
-- @tparam number x the x position.
139160
-- @tparam number y the y position.
@@ -251,6 +272,11 @@ function peachy:getHeight()
251272
return self._jsonData.frames[self.frameIndex].frame.h
252273
end
253274

275+
--- Provides dimensions stored in the metadata of a current frame
276+
function peachy:getDimensions()
277+
return self:getWidth(), self:getHeight()
278+
end
279+
254280
--- Internal: handles the ping-pong animation type.
255281
--
256282
-- Should only be called when we actually want to bounce.

0 commit comments

Comments
 (0)