1
0

Code quality
Some checks failed
LÖVE Library / Lua-Testing (push) Successful in 5s
LÖVE Library / Static-Analysis (push) Failing after 3s

This commit is contained in:
Jon Michael Aanes 2024-04-26 11:56:27 +02:00
parent 1b73422a16
commit 4da6f66703
3 changed files with 14 additions and 14 deletions

View File

@ -1,4 +1,3 @@
# Spritesheet # Spritesheet
Tiny library for working with textures and animated textures. 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 - When drawing an image or animation when a shader is defined the library may
send certain useful constants along, notably `spritesheet_inverse_width` and send certain useful constants along, notably `spritesheet_inverse_width` and
`spritesheet_inverse_height`. `spritesheet_inverse_height`.

View File

@ -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 local error, error_internal do
error, error_internal = error_orig, error_orig error, error_internal = error, error
error_orig = nil local success, errorlib = pcall(require, 'errors')
local success, errorlib = pcall(require,'errors')
if success then if success then
error = errorlib 'spritesheet' error = errorlib 'spritesheet'
error_internal = error.internal error_internal = error.internal
@ -24,7 +26,7 @@ end
-- Util -- Util
local function calculate_animation_duration (self, frame_i) 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(self) == 'table')
assert(type(frame_i) == 'number') assert(type(frame_i) == 'number')
@ -119,14 +121,14 @@ local Animation = {}
Animation.__index = Animation Animation.__index = Animation
function Animation.new (self) 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(type(self.time) == 'table' or type(self.time) == 'number' and self.time > 0 or type(self.time_total) == 'number')
assert(#self > 0) assert(#self > 0)
assert(type(self.time) == 'number' or type(self.time_total) == 'number' or #self == #self.time) 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 if self.time_total then assert(self.time == nil) end
assert(self.wrap == nil or self.wrap == true or self.wrap == false) assert(self.wrap == nil or self.wrap == true or self.wrap == false)
local self = setmetatable(self, Animation) setmetatable(self, Animation)
self.duration = calculate_animation_duration(self) self.duration = calculate_animation_duration(self)
self.is_animation = true self.is_animation = true
@ -282,9 +284,9 @@ local function load_quad_data (filename)
local chunk, error_msg local chunk, error_msg
if define_love then if define_love then
chunk, error_msg = love.filesystem.load(filename..'.lua') chunk, error_msg = love.filesystem.load(filename..filetype)
else else
chunk, error_msg = loadfile(filename..'.lua') chunk, error_msg = loadfile(filename..filetype)
end end
if chunk then if chunk then

View File

@ -1 +1 @@
-- TODO require 'spritesheet'