diff --git a/README.md b/README.md index e315467..30f7056 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - # Spritesheet Tiny library for working with textures and animated textures. @@ -8,4 +7,3 @@ Tiny library for working with textures and animated textures. - When drawing an image or animation when a shader is defined the library may send certain useful constants along, notably `spritesheet_inverse_width` and `spritesheet_inverse_height`. - diff --git a/spritesheet.lua b/spritesheet.lua index 2d35e1a..9ef9dba 100644 --- a/spritesheet.lua +++ b/spritesheet.lua @@ -1,9 +1,11 @@ +--- Library for managing spritesheets. +--- +--- Has support for both individual images in spritesheets and animations. This +--- can be specified from a lua file placed beside the spritesheet image file. -local error_orig = error local error, error_internal do - error, error_internal = error_orig, error_orig - error_orig = nil - local success, errorlib = pcall(require,'errors') + error, error_internal = error, error + local success, errorlib = pcall(require, 'errors') if success then error = errorlib 'spritesheet' error_internal = error.internal @@ -24,7 +26,7 @@ end -- Util local function calculate_animation_duration (self, frame_i) - local frame_i = frame_i or math.huge + frame_i = frame_i or math.huge assert(type(self) == 'table') assert(type(frame_i) == 'number') @@ -119,16 +121,16 @@ local Animation = {} Animation.__index = Animation function Animation.new (self) - assert(type(self) == 'table') + assert(type(self) == 'table' and self ~= Animation) assert(type(self.time) == 'table' or type(self.time) == 'number' and self.time > 0 or type(self.time_total) == 'number') assert(#self > 0) assert(type(self.time) == 'number' or type(self.time_total) == 'number' or #self == #self.time) if self.time_total then assert(self.time == nil) end assert(self.wrap == nil or self.wrap == true or self.wrap == false) - local self = setmetatable(self, Animation) - self.duration = calculate_animation_duration(self) - self.is_animation = true + setmetatable(self, Animation) + self.duration = calculate_animation_duration(self) + self.is_animation = true -- Contact frame? if self.contact_frame then @@ -282,9 +284,9 @@ local function load_quad_data (filename) local chunk, error_msg if define_love then - chunk, error_msg = love.filesystem.load(filename..'.lua') + chunk, error_msg = love.filesystem.load(filename..filetype) else - chunk, error_msg = loadfile(filename..'.lua') + chunk, error_msg = loadfile(filename..filetype) end if chunk then diff --git a/test/init.lua b/test/init.lua index 2126a4a..ef4b605 100644 --- a/test/init.lua +++ b/test/init.lua @@ -1 +1 @@ --- TODO +require 'spritesheet'