mirror of
https://github.com/aseprite/aseprite.git
synced 2024-12-28 15:20:15 +00:00
New tests for layers/frames/cels/tags/slices
This commit is contained in:
parent
2a9062ee99
commit
b6c2a43f9e
37
scripts/cels.lua
Normal file
37
scripts/cels.lua
Normal file
@ -0,0 +1,37 @@
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
do
|
||||
local s = Sprite(32, 32)
|
||||
for i = 1,3 do s:newFrame() end
|
||||
assert(#s.frames == 4)
|
||||
|
||||
-- Layer a and b
|
||||
local a = s.layers[1]
|
||||
local b = s:newLayer()
|
||||
|
||||
local ca = { s.cels[1],
|
||||
s.cels[2],
|
||||
s.cels[3] }
|
||||
|
||||
local cb = { s:newCel(b, 1),
|
||||
s:newCel(b, 2, Image(8, 8), 4, 4),
|
||||
s:newCel(b, 3, Image(32, 10), 16, 10) }
|
||||
|
||||
assert(cb[1].bounds == Rectangle(0, 0, 32, 32))
|
||||
assert(cb[2].bounds == Rectangle(4, 4, 8, 8))
|
||||
assert(cb[3].bounds == Rectangle(16, 10, 32, 10))
|
||||
|
||||
-- Check how layer cels are updated when we delete a cel in the middle
|
||||
|
||||
assert(cb[1] == b.cels[1])
|
||||
assert(cb[2] == b.cels[2])
|
||||
assert(cb[3] == b.cels[3])
|
||||
|
||||
s:deleteCel(cb[2])
|
||||
|
||||
assert(cb[1] == b.cels[1])
|
||||
assert(cb[3] == b.cels[2])
|
||||
end
|
25
scripts/frames.lua
Normal file
25
scripts/frames.lua
Normal file
@ -0,0 +1,25 @@
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
do
|
||||
local a = Sprite(32, 32)
|
||||
assert(#a.frames == 1)
|
||||
assert(a.frames[1].frameNumber == 1)
|
||||
assert(a.frames[1].duration == 0.1)
|
||||
|
||||
local fr = a:newFrame()
|
||||
assert(#a.frames == 2)
|
||||
assert(a.frames[1].frameNumber == 1)
|
||||
assert(a.frames[2].frameNumber == 2)
|
||||
assert(a.frames[1].duration == 0.1)
|
||||
assert(a.frames[2].duration == 0.1)
|
||||
|
||||
fr.duration = 0.2
|
||||
assert(a.frames[1].duration == 0.1)
|
||||
assert(a.frames[2].duration == 0.2)
|
||||
|
||||
a:deleteFrame(1)
|
||||
assert(a.frames[1].duration == 0.2)
|
||||
end
|
18
scripts/layer.lua
Normal file
18
scripts/layer.lua
Normal file
@ -0,0 +1,18 @@
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
do
|
||||
local a = Sprite(32, 64)
|
||||
local l = a.layers[1]
|
||||
assert(l.opacity == 255)
|
||||
assert(l.blendMode == BlendMode.NORMAL)
|
||||
|
||||
l.name = "My Layer"
|
||||
l.opacity = 128
|
||||
l.blendMode = BlendMode.MULTIPLY
|
||||
assert(l.name == "My Layer")
|
||||
assert(l.opacity == 128)
|
||||
assert(l.blendMode == BlendMode.MULTIPLY)
|
||||
end
|
23
scripts/layers.lua
Normal file
23
scripts/layers.lua
Normal file
@ -0,0 +1,23 @@
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
do
|
||||
local s = Sprite(32, 32)
|
||||
assert(#s.layers == 1)
|
||||
|
||||
local a = s.layers[1]
|
||||
local b = s:newLayer()
|
||||
local c = s:newLayer()
|
||||
|
||||
assert(#s.layers == 3)
|
||||
assert(s.layers[1] == a)
|
||||
assert(s.layers[2] == b)
|
||||
assert(s.layers[3] == c)
|
||||
|
||||
s:deleteLayer(b)
|
||||
assert(#s.layers == 2)
|
||||
assert(s.layers[1] == a)
|
||||
assert(s.layers[2] == c)
|
||||
end
|
@ -3,7 +3,13 @@
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
local p = Palette(32)
|
||||
local p = Palette()
|
||||
assert(#p == 256)
|
||||
for i = 0,#p-1 do
|
||||
assert(p:getColor(i) == Color(0, 0, 0))
|
||||
end
|
||||
|
||||
p = Palette(32)
|
||||
assert(#p == 32)
|
||||
for i = 0,#p-1 do
|
||||
assert(p:getColor(i) == Color(0, 0, 0))
|
||||
|
24
scripts/slice.lua
Normal file
24
scripts/slice.lua
Normal file
@ -0,0 +1,24 @@
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
do
|
||||
local s = Sprite(32, 32)
|
||||
|
||||
local a = s:newSlice(0, 0, 32, 32)
|
||||
assert(a.bounds == Rectangle(0, 0, 32, 32))
|
||||
assert(a.sprite == s)
|
||||
|
||||
assert(a.name == "Slice")
|
||||
a.name = "Slice A"
|
||||
assert(a.name == "Slice A")
|
||||
|
||||
assert(a.center == nil)
|
||||
a.center = Rectangle(2, 3, 28, 20)
|
||||
assert(a.center == Rectangle(2, 3, 28, 20))
|
||||
|
||||
assert(a.pivot == nil)
|
||||
a.pivot = Point(16, 17)
|
||||
assert(a.pivot == Point(16, 17))
|
||||
end
|
19
scripts/slices.lua
Normal file
19
scripts/slices.lua
Normal file
@ -0,0 +1,19 @@
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
do
|
||||
local s = Sprite(32, 32)
|
||||
|
||||
local a = s:newSlice()
|
||||
local b = s:newSlice(0, 2, 8, 10)
|
||||
local c = s:newSlice{ x=0, y=0, width=32, height=32 }
|
||||
assert(a.bounds == nil)
|
||||
assert(b.bounds == Rectangle(0, 2, 8, 10))
|
||||
assert(c.bounds == Rectangle(0, 0, 32, 32))
|
||||
|
||||
s:deleteSlice(b)
|
||||
assert(a == s.slices[1])
|
||||
assert(c == s.slices[2])
|
||||
end
|
@ -3,30 +3,61 @@
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
local a = Sprite(32, 64)
|
||||
assert(a.width == 32)
|
||||
assert(a.height == 64)
|
||||
assert(a.colorMode == ColorMode.RGB) -- RGB by default
|
||||
do
|
||||
local a = Sprite(32, 64)
|
||||
assert(a.width == 32)
|
||||
assert(a.height == 64)
|
||||
assert(a.colorMode == ColorMode.RGB) -- RGB by default
|
||||
|
||||
-- Crop and resize
|
||||
a.selection:select(2, 3, 4, 5)
|
||||
a:crop()
|
||||
assert(a.width == 4)
|
||||
assert(a.height == 5)
|
||||
a:resize(6, 8)
|
||||
assert(a.width == 6)
|
||||
assert(a.height == 8)
|
||||
a:crop{x=-1, y=-1, width=20, height=30}
|
||||
assert(a.width == 20)
|
||||
assert(a.height == 30)
|
||||
-- Crop and resize
|
||||
a.selection:select(2, 3, 4, 5)
|
||||
a:crop()
|
||||
assert(a.width == 4)
|
||||
assert(a.height == 5)
|
||||
a:resize(6, 8)
|
||||
assert(a.width == 6)
|
||||
assert(a.height == 8)
|
||||
a:crop{x=-1, y=-1, width=20, height=30}
|
||||
assert(a.width == 20)
|
||||
assert(a.height == 30)
|
||||
|
||||
-- Resize sprite setting width/height
|
||||
a.width = 8
|
||||
a.height = 10
|
||||
assert(a.width == 8)
|
||||
assert(a.height == 10)
|
||||
-- Resize sprite setting width/height
|
||||
a.width = 8
|
||||
a.height = 10
|
||||
assert(a.width == 8)
|
||||
assert(a.height == 10)
|
||||
|
||||
local b = Sprite(4, 4, ColorMode.INDEXED)
|
||||
assert(b.width == 4)
|
||||
assert(b.height == 4)
|
||||
assert(b.colorMode == ColorMode.INDEXED)
|
||||
local b = Sprite(4, 4, ColorMode.INDEXED)
|
||||
assert(b.width == 4)
|
||||
assert(b.height == 4)
|
||||
assert(b.colorMode == ColorMode.INDEXED)
|
||||
end
|
||||
|
||||
-- Transparent color
|
||||
|
||||
do
|
||||
local a = Sprite(32, 32, ColorMode.INDEXED)
|
||||
assert(a.transparentColor == 0)
|
||||
a.transparentColor = 8
|
||||
assert(a.transparentColor == 8)
|
||||
end
|
||||
|
||||
-- Palette
|
||||
|
||||
do
|
||||
local a = Sprite(32, 32, ColorMode.INDEXED)
|
||||
assert(#a.palettes == 1)
|
||||
assert(#a.palettes[1] == 256)
|
||||
|
||||
local p = Palette(3)
|
||||
p:setColor(0, Color(255, 0, 0))
|
||||
p:setColor(1, Color(0, 255, 0))
|
||||
p:setColor(2, Color(0, 0, 255))
|
||||
a:setPalette(p)
|
||||
|
||||
assert(#a.palettes == 1)
|
||||
assert(#a.palettes[1] == 3)
|
||||
assert(a.palettes[1]:getColor(0) == Color(255, 0, 0))
|
||||
assert(a.palettes[1]:getColor(1) == Color(0, 255, 0))
|
||||
assert(a.palettes[1]:getColor(2) == Color(0, 0, 255))
|
||||
end
|
||||
|
33
scripts/tag.lua
Normal file
33
scripts/tag.lua
Normal file
@ -0,0 +1,33 @@
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
do
|
||||
local s = Sprite(32, 32)
|
||||
for i = 1,7 do s:newFrame() end
|
||||
assert(#s.frames == 8)
|
||||
|
||||
a = s:newTag(1, 8)
|
||||
assert(a.sprite == s)
|
||||
assert(a.fromFrame == 1)
|
||||
assert(a.toFrame == 8)
|
||||
assert(a.frames == 8)
|
||||
|
||||
a.fromFrame = 2
|
||||
a.toFrame = 5
|
||||
assert(a.fromFrame == 2)
|
||||
assert(a.toFrame == 5)
|
||||
|
||||
assert(a.name == "Tag")
|
||||
a.name = "Tag A"
|
||||
assert(a.name == "Tag A")
|
||||
|
||||
assert(a.aniDir == AniDir.FORWARD) -- Default AniDir is FORWARD
|
||||
a.aniDir = AniDir.REVERSE
|
||||
assert(a.aniDir == AniDir.REVERSE)
|
||||
a.aniDir = AniDir.PING_PONG
|
||||
assert(a.aniDir == AniDir.PING_PONG)
|
||||
a.aniDir = AniDir.FORWARD
|
||||
assert(a.aniDir == AniDir.FORWARD)
|
||||
end
|
29
scripts/tags.lua
Normal file
29
scripts/tags.lua
Normal file
@ -0,0 +1,29 @@
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
do
|
||||
local s = Sprite(32, 32)
|
||||
for i = 1,7 do s:newFrame() end
|
||||
assert(#s.frames == 8)
|
||||
|
||||
a = s:newTag(1, 2)
|
||||
b = s:newTag(3, 4)
|
||||
c = s:newTag(5, 8)
|
||||
|
||||
assert(a.frames == 2)
|
||||
assert(b.frames == 2)
|
||||
assert(c.frames == 4)
|
||||
|
||||
assert(a == s.tags[1])
|
||||
assert(b == s.tags[2])
|
||||
assert(c == s.tags[3])
|
||||
|
||||
s:deleteTag(b)
|
||||
assert(a == s.tags[1])
|
||||
assert(c == s.tags[2])
|
||||
|
||||
assert(c.fromFrame == 5)
|
||||
assert(c.toFrame == 8)
|
||||
end
|
Loading…
Reference in New Issue
Block a user