diff --git a/scripts/cels.lua b/scripts/cels.lua new file mode 100644 index 000000000..dd91813a0 --- /dev/null +++ b/scripts/cels.lua @@ -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 diff --git a/scripts/frames.lua b/scripts/frames.lua new file mode 100644 index 000000000..62319fac3 --- /dev/null +++ b/scripts/frames.lua @@ -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 diff --git a/scripts/layer.lua b/scripts/layer.lua new file mode 100644 index 000000000..c0494dc54 --- /dev/null +++ b/scripts/layer.lua @@ -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 diff --git a/scripts/layers.lua b/scripts/layers.lua new file mode 100644 index 000000000..95a319c71 --- /dev/null +++ b/scripts/layers.lua @@ -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 diff --git a/scripts/palette.lua b/scripts/palette.lua index f1ea43e82..1c715a9ec 100644 --- a/scripts/palette.lua +++ b/scripts/palette.lua @@ -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)) diff --git a/scripts/slice.lua b/scripts/slice.lua new file mode 100644 index 000000000..85e62147e --- /dev/null +++ b/scripts/slice.lua @@ -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 diff --git a/scripts/slices.lua b/scripts/slices.lua new file mode 100644 index 000000000..7895ae497 --- /dev/null +++ b/scripts/slices.lua @@ -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 diff --git a/scripts/sprite.lua b/scripts/sprite.lua index b6c4d3988..2474fcd48 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -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 diff --git a/scripts/tag.lua b/scripts/tag.lua new file mode 100644 index 000000000..a866166d5 --- /dev/null +++ b/scripts/tag.lua @@ -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 diff --git a/scripts/tags.lua b/scripts/tags.lua new file mode 100644 index 000000000..902ffff65 --- /dev/null +++ b/scripts/tags.lua @@ -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