Skip to content

Commit

Permalink
Add luacheck support and fix identified issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ebeneliason committed Apr 14, 2023
1 parent 96456f3 commit bba33ec
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
stds.easypattern = require "luacheck/Luacheck"

std = "lua54+playdate+easypattern"

operators = {"+=", "-=", "*=", "/="}
12 changes: 6 additions & 6 deletions EasyPattern.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local CACHE_EXP <const> = 1 / 60 -- max FPS

-- Animated patterns with easing, made easy.
--
-- SAMPLE USAGE:
-- SAMPLE USAGE:
--
-- local checkerboard = {0xF0F0, 0xF0F0, 0xF0F0, 0xF0F0, 0x0F0F, 0x0F0F, 0x0F0F, 0x0F0F}
-- local easyCheckerboard = EasyPattern {
Expand Down Expand Up @@ -197,12 +197,12 @@ function EasyPattern:init(params)
self:updatePatternImage()
end

function setColor(color)
function EasyPattern:setColor(color)
self.color = color
self:updatePatternImage()
end

function setBackgroundColor(color)
function EasyPattern:setBackgroundColor(color)
self.bgColor = color
self:updatePatternImage()
end
Expand Down Expand Up @@ -242,8 +242,8 @@ function EasyPattern:getPhases()
end

-- calculate the effective time param for each axis accounting for offsets, speed scaling, and looping
tx = (t * self.xSpeed + self.xPhaseOffset) % self.xPhaseDuration
ty = (t * self.ySpeed + self.yPhaseOffset) % self.yPhaseDuration
local tx = (t * self.xSpeed + self.xPhaseOffset) % self.xPhaseDuration
local ty = (t * self.ySpeed + self.yPhaseOffset) % self.yPhaseDuration

-- handle animation reversal when crossing the animation duration bounds
if self.xReverses and self._ptx > tx then
Expand All @@ -270,7 +270,7 @@ function EasyPattern:getPhases()
if self.yReversed then yPhase = PTTRN_SIZE - yPhase - 1 end

-- determine if we're dirty and cache the computed phase values along with a timestamp
dirty = xPhase ~= self._xPhase or yPhase ~= self._yPhase
local dirty = xPhase ~= self._xPhase or yPhase ~= self._yPhase
self._xPhase = xPhase
self._yPhase = yPhase
self._pt = t
Expand Down
34 changes: 34 additions & 0 deletions luacheck/Luacheck.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- EasyPattern globals
--
-- This file can also be used with toyboxpy (https://toyboxpy.io):
--
-- 1. Add this to your project's .luacheckrc:
-- require "toyboxes/luacheck" (stds, files)
--
-- 2. Add 'toyboxes' to your std:
-- std = "lua54+playdate+toyboxes"

return {
globals = {
EasyPattern = {
fields = {
super = {
fields = {
className = {},
init = {}
},
},
className = {},
init = {},
setColor = {},
setBackgroundColor = {},
setPattern = {},
setDitherPattern = {},
updatePatternImage = {},
getPhases = {},
isDirty = {},
apply = {}
}
},
}
}

0 comments on commit bba33ec

Please sign in to comment.