From 4132dadf5314166d25680b7a499d337a11a0e0e7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 14 Jun 2018 11:55:07 -0300 Subject: [PATCH 001/200] First commit with README file --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 000000000..c6ed4902b --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# Aseprite Tests + +Test suite for [Aseprite](https://github.com/aseprite/aseprite) +to avoid breaking backward compatibility. + +This project is cloned by the +[.travis.yml](https://github.com/aseprite/aseprite/blob/master/.travis.yml) file +on Aseprite project to do several automated tests: + +* Save/load file formats correctly. For this we have `.aseprite`, `.png`, + `.gif`, etc. files [sprites](https://github.com/aseprite/tests/tree/master/sprites) + folder. +* Test backward compatibility with [Aseprite CLI](https://www.aseprite.org/docs/cli/) options +* Future [scripting API](https://github.com/aseprite/api) From 075966fe1874d2f0091353255ca084d88472cead Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 14 Jun 2018 11:59:07 -0300 Subject: [PATCH 002/200] Add some scripts to test the current JavaScript API --- run-tests.sh | 46 ++++++++++++++++++++++++++++++++++++++ scripts/app_pixel_color.js | 9 ++++++++ scripts/app_version.js | 4 ++++ scripts/console_assert.js | 6 +++++ scripts/console_log.js | 4 ++++ scripts/constants.js | 5 +++++ scripts/point.js | 21 +++++++++++++++++ scripts/rectangle.js | 31 +++++++++++++++++++++++++ scripts/selection.js | 29 ++++++++++++++++++++++++ scripts/size.js | 21 +++++++++++++++++ scripts/sprite.js | 31 +++++++++++++++++++++++++ 11 files changed, 207 insertions(+) create mode 100755 run-tests.sh create mode 100644 scripts/app_pixel_color.js create mode 100644 scripts/app_version.js create mode 100644 scripts/console_assert.js create mode 100644 scripts/console_log.js create mode 100644 scripts/constants.js create mode 100644 scripts/point.js create mode 100644 scripts/rectangle.js create mode 100644 scripts/selection.js create mode 100644 scripts/size.js create mode 100644 scripts/sprite.js diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 000000000..e4b157b9a --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,46 @@ +#! /bin/sh +# Copyright (C) 2018 David Capello + +if [[ "$ASEPRITE" == "" ]]; then + echo ASEPRITE env var must be pointing to the Aseprite executable + exit 1 +fi + +function fail() { + echo FAIL + echo $BASH_SOURCE:$BASH_LINENO: error: $* + exit 1 +} + +echo ---------------------------------------------------------------------- +echo $ASEPRITE --version +$ASEPRITE --version + +echo ---------------------------------------------------------------------- +echo "Testing console..." +$ASEPRITE -b --script scripts/console_assert.js > tmp +! grep -q Error tmp && fail +! grep -q "this should be in the output" tmp && fail +grep -q "this should not be in the output" tmp && fail + +$ASEPRITE -b --script scripts/console_log.js > tmp +cat >tmp_expected < tmp ; then + fail + fi +done + +echo ---------------------------------------------------------------------- +echo Done +echo ---------------------------------------------------------------------- diff --git a/scripts/app_pixel_color.js b/scripts/app_pixel_color.js new file mode 100644 index 000000000..1e7d1ecb7 --- /dev/null +++ b/scripts/app_pixel_color.js @@ -0,0 +1,9 @@ +// Copyright (C) 2018 David Capello + +var pc = app.pixelColor +console.assert(0 == pc.rgba(0, 0, 0, 0)) +console.assert(1 == pc.rgbaR(pc.rgba(1, 2, 3, 4))) +console.assert(2 == pc.rgbaG(pc.rgba(1, 2, 3, 4))) +console.assert(3 == pc.rgbaB(pc.rgba(1, 2, 3, 4))) +console.assert(4 == pc.rgbaA(pc.rgba(1, 2, 3, 4))) +console.assert(0xff104080 == pc.rgba(0x80, 0x40, 0x10, 0xff)) diff --git a/scripts/app_version.js b/scripts/app_version.js new file mode 100644 index 000000000..03c3bcb8e --- /dev/null +++ b/scripts/app_version.js @@ -0,0 +1,4 @@ +// Copyright (C) 2018 David Capello + +console.assert(app.version[0] == "1") +console.assert(app.version[1] == ".") diff --git a/scripts/console_assert.js b/scripts/console_assert.js new file mode 100644 index 000000000..cfa0729c5 --- /dev/null +++ b/scripts/console_assert.js @@ -0,0 +1,6 @@ +// Copyright (C) 2018 David Capello + +console.assert(true) +console.log("this should be in the output") +console.assert(false) +console.log("this should not be in the output") diff --git a/scripts/console_log.js b/scripts/console_log.js new file mode 100644 index 000000000..bd856a026 --- /dev/null +++ b/scripts/console_log.js @@ -0,0 +1,4 @@ +// Copyright (C) 2018 David Capello + +console.log("hello world") +console.log(1, 2, 3) diff --git a/scripts/constants.js b/scripts/constants.js new file mode 100644 index 000000000..911eef2b7 --- /dev/null +++ b/scripts/constants.js @@ -0,0 +1,5 @@ +// Copyright (C) 2018 David Capello + +console.assert(ColorMode.RGB == 0) +console.assert(ColorMode.GRAYSCALE == 1) +console.assert(ColorMode.INDEXED == 2) diff --git a/scripts/point.js b/scripts/point.js new file mode 100644 index 000000000..616a049cd --- /dev/null +++ b/scripts/point.js @@ -0,0 +1,21 @@ +// Copyright (C) 2018 David Capello + +var pt = new Point() +console.assert(pt.x == 0) +console.assert(pt.y == 0) + +pt = new Point(1, 2) +console.assert(pt.x == 1) +console.assert(pt.y == 2) + +var pt2 = new Point(pt) +console.assert(pt2.x == 1) +console.assert(pt2.y == 2) + +pt.x = 5; +pt.y = 6; +console.assert(pt.x == 5) +console.assert(pt.y == 6) + +// TODO fix this +console.log(JSON.stringify(pt)) diff --git a/scripts/rectangle.js b/scripts/rectangle.js new file mode 100644 index 000000000..ce3b650aa --- /dev/null +++ b/scripts/rectangle.js @@ -0,0 +1,31 @@ +// Copyright (C) 2018 David Capello + +var rc = new Rectangle() +console.assert(rc.x == 0) +console.assert(rc.y == 0) +console.assert(rc.width == 0) +console.assert(rc.height == 0) + +rc = new Rectangle(1, 2, 3, 4) +console.assert(rc.x == 1) +console.assert(rc.y == 2) +console.assert(rc.width == 3) +console.assert(rc.height == 4) + +var rc2 = new Rectangle(rc) +console.assert(rc2.x == 1) +console.assert(rc2.y == 2) +console.assert(rc2.width == 3) +console.assert(rc2.height == 4) + +rc.x = 5; +rc.y = 6; +rc.width = 7; +rc.height = 8; +console.assert(rc.x == 5) +console.assert(rc.y == 6) +console.assert(rc.width == 7) +console.assert(rc.height == 8) + +// TODO fix this +console.log(JSON.stringify(rc)) diff --git a/scripts/selection.js b/scripts/selection.js new file mode 100644 index 000000000..08abfd7c1 --- /dev/null +++ b/scripts/selection.js @@ -0,0 +1,29 @@ +// Copyright (C) 2018 David Capello + +// Isolated selection +var a = new Selection() +console.assert(a.bounds.x == 0) +console.assert(a.bounds.y == 0) +console.assert(a.bounds.width == 0) +console.assert(a.bounds.height == 0) + +a.select(1, 2, 3, 4); +console.assert(a.bounds.x == 1) +console.assert(a.bounds.y == 2) +console.assert(a.bounds.width == 3) +console.assert(a.bounds.height == 4) + +a.select({ 'x': 5, 'y': 6, 'width': 7, 'height': 8 }) +console.assert(a.bounds.x == 5) +console.assert(a.bounds.y == 6) +console.assert(a.bounds.width == 7) +console.assert(a.bounds.height == 8) + +a.deselect(); +console.assert(a.bounds.x == 0) +console.assert(a.bounds.y == 0) +console.assert(a.bounds.width == 0) +console.assert(a.bounds.height == 0) + +// Selection related to a sprite +// TODO diff --git a/scripts/size.js b/scripts/size.js new file mode 100644 index 000000000..8561babbb --- /dev/null +++ b/scripts/size.js @@ -0,0 +1,21 @@ +// Copyright (C) 2018 David Capello + +var sz = new Size() +console.assert(sz.width == 0) +console.assert(sz.height == 0) + +sz = new Size(3, 4) +console.assert(sz.width == 3) +console.assert(sz.height == 4) + +var sz2 = new Size(sz) +console.assert(sz2.width == 3) +console.assert(sz2.height == 4) + +sz.width = 7; +sz.height = 8; +console.assert(sz.width == 7) +console.assert(sz.height == 8) + +// TODO fix this +console.log(JSON.stringify(sz)) diff --git a/scripts/sprite.js b/scripts/sprite.js new file mode 100644 index 000000000..42a199df0 --- /dev/null +++ b/scripts/sprite.js @@ -0,0 +1,31 @@ +// Copyright (C) 2018 David Capello + +var a = new Sprite(32, 64) +console.assert(a.width == 32) +console.assert(a.height == 64) +console.assert(a.colorMode == ColorMode.RGB) // RGB by default +a.selection.select(2, 3, 4, 5) +console.assert(a.selection.bounds.x == 2) +console.assert(a.selection.bounds.y == 3) +console.assert(a.selection.bounds.width == 4) +console.assert(a.selection.bounds.height == 5) +a.crop() +console.assert(a.width == 4) +console.assert(a.height == 5) +a.resize(6, 8) +console.assert(a.width == 6) +console.assert(a.height == 8) +a.crop({ 'x': -1, 'y': -1, 'width': 20, 'height': 30 }) +console.assert(a.width == 20) +console.assert(a.height == 30) + +// resize sprite setting width/height +a.width = 8 +a.height = 10 +console.assert(a.width == 8) +console.assert(a.height == 10) + +var b = new Sprite(4, 4, ColorMode.INDEXED) +console.assert(b.width == 4) +console.assert(b.height == 4) +console.assert(b.colorMode == ColorMode.INDEXED) From d6324396a05c97e8581b1e88bd8ea12c1628cc1d Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 14 Jun 2018 12:03:03 -0300 Subject: [PATCH 003/200] Add link to scripts/ folder in README file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6ed4902b..1ea496ca8 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,4 @@ on Aseprite project to do several automated tests: `.gif`, etc. files [sprites](https://github.com/aseprite/tests/tree/master/sprites) folder. * Test backward compatibility with [Aseprite CLI](https://www.aseprite.org/docs/cli/) options -* Future [scripting API](https://github.com/aseprite/api) +* Future [scripting API](https://github.com/aseprite/api) using [JS scripts](https://github.com/aseprite/tests/tree/master/scripts) From eb387898c3c0abceb554a8ff742381464619f11d Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 20 Aug 2018 14:22:27 -0300 Subject: [PATCH 004/200] Minor change in sprite.js --- scripts/sprite.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/sprite.js b/scripts/sprite.js index 42a199df0..b64546f57 100644 --- a/scripts/sprite.js +++ b/scripts/sprite.js @@ -4,11 +4,25 @@ var a = new Sprite(32, 64) console.assert(a.width == 32) console.assert(a.height == 64) console.assert(a.colorMode == ColorMode.RGB) // RGB by default -a.selection.select(2, 3, 4, 5) -console.assert(a.selection.bounds.x == 2) -console.assert(a.selection.bounds.y == 3) -console.assert(a.selection.bounds.width == 4) -console.assert(a.selection.bounds.height == 5) + +var s = a.selection +console.assert(s.bounds.x == 0) +console.assert(s.bounds.y == 0) +console.assert(s.bounds.width == 0) +console.assert(s.bounds.height == 0) + +s.selectAll() +console.assert(s.bounds.x == 0) +console.assert(s.bounds.y == 0) +console.assert(s.bounds.width == a.width) +console.assert(s.bounds.height == a.height) + +s.select(2, 3, 4, 5) +console.assert(s.bounds.x == 2) +console.assert(s.bounds.y == 3) +console.assert(s.bounds.width == 4) +console.assert(s.bounds.height == 5) + a.crop() console.assert(a.width == 4) console.assert(a.height == 5) From 4325fdea65cf69ec50258e96df2dabb6bda39415 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 20 Aug 2018 14:22:36 -0300 Subject: [PATCH 005/200] run-tests.sh exits with error code if a script fails --- run-tests.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/run-tests.sh b/run-tests.sh index e4b157b9a..97ac9e2f6 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -32,15 +32,20 @@ EOF echo ---------------------------------------------------------------------- echo "Testing scripts..." +result=0 for jsfile in scripts/*.js ; do [[ $jsfile =~ console ]] && continue echo "Running $jsfile" if ! $ASEPRITE -b --script $jsfile > tmp ; then - fail + cat tmp + echo FAILED + result=1 fi done echo ---------------------------------------------------------------------- echo Done echo ---------------------------------------------------------------------- + +exit $result From 0dd41f69d5d48ad247ccd65463af806b81b5048d Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 20 Aug 2018 14:41:53 -0300 Subject: [PATCH 006/200] Redir stderr --- run-tests.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index 97ac9e2f6..552e1d059 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -18,12 +18,12 @@ $ASEPRITE --version echo ---------------------------------------------------------------------- echo "Testing console..." -$ASEPRITE -b --script scripts/console_assert.js > tmp +$ASEPRITE -b --script scripts/console_assert.js >tmp 2>tmp_err ! grep -q Error tmp && fail ! grep -q "this should be in the output" tmp && fail grep -q "this should not be in the output" tmp && fail -$ASEPRITE -b --script scripts/console_log.js > tmp +$ASEPRITE -b --script scripts/console_log.js >tmp 2>tmp_err cat >tmp_expected < tmp ; then - cat tmp + if ! $ASEPRITE -b --script $jsfile >tmp 2>tmp_err ; then echo FAILED + echo STDOUT && cat tmp + echo STDERR && cat tmp_err result=1 fi done From 7ed438a855de9ec28dc327672c7c1357666743ab Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 20 Aug 2018 14:50:11 -0300 Subject: [PATCH 007/200] Add license file --- LICENSE.txt | 20 ++++++++++++++++++++ scripts/app_pixel_color.js | 3 +++ scripts/app_version.js | 3 +++ scripts/console_assert.js | 3 +++ scripts/console_log.js | 3 +++ scripts/constants.js | 3 +++ scripts/point.js | 3 +++ scripts/rectangle.js | 3 +++ scripts/selection.js | 3 +++ scripts/size.js | 3 +++ scripts/sprite.js | 3 +++ 11 files changed, 50 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 000000000..72e289daa --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,20 @@ +Copyright (c) 2018 David Capello + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/scripts/app_pixel_color.js b/scripts/app_pixel_color.js index 1e7d1ecb7..63180d811 100644 --- a/scripts/app_pixel_color.js +++ b/scripts/app_pixel_color.js @@ -1,4 +1,7 @@ // Copyright (C) 2018 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. var pc = app.pixelColor console.assert(0 == pc.rgba(0, 0, 0, 0)) diff --git a/scripts/app_version.js b/scripts/app_version.js index 03c3bcb8e..b0d0d3c40 100644 --- a/scripts/app_version.js +++ b/scripts/app_version.js @@ -1,4 +1,7 @@ // Copyright (C) 2018 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. console.assert(app.version[0] == "1") console.assert(app.version[1] == ".") diff --git a/scripts/console_assert.js b/scripts/console_assert.js index cfa0729c5..46f09a464 100644 --- a/scripts/console_assert.js +++ b/scripts/console_assert.js @@ -1,4 +1,7 @@ // Copyright (C) 2018 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. console.assert(true) console.log("this should be in the output") diff --git a/scripts/console_log.js b/scripts/console_log.js index bd856a026..fbaca7658 100644 --- a/scripts/console_log.js +++ b/scripts/console_log.js @@ -1,4 +1,7 @@ // Copyright (C) 2018 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. console.log("hello world") console.log(1, 2, 3) diff --git a/scripts/constants.js b/scripts/constants.js index 911eef2b7..d70711132 100644 --- a/scripts/constants.js +++ b/scripts/constants.js @@ -1,4 +1,7 @@ // Copyright (C) 2018 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. console.assert(ColorMode.RGB == 0) console.assert(ColorMode.GRAYSCALE == 1) diff --git a/scripts/point.js b/scripts/point.js index 616a049cd..ffd745a66 100644 --- a/scripts/point.js +++ b/scripts/point.js @@ -1,4 +1,7 @@ // Copyright (C) 2018 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. var pt = new Point() console.assert(pt.x == 0) diff --git a/scripts/rectangle.js b/scripts/rectangle.js index ce3b650aa..072c4e768 100644 --- a/scripts/rectangle.js +++ b/scripts/rectangle.js @@ -1,4 +1,7 @@ // Copyright (C) 2018 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. var rc = new Rectangle() console.assert(rc.x == 0) diff --git a/scripts/selection.js b/scripts/selection.js index 08abfd7c1..9938b105e 100644 --- a/scripts/selection.js +++ b/scripts/selection.js @@ -1,4 +1,7 @@ // Copyright (C) 2018 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. // Isolated selection var a = new Selection() diff --git a/scripts/size.js b/scripts/size.js index 8561babbb..7aed31a47 100644 --- a/scripts/size.js +++ b/scripts/size.js @@ -1,4 +1,7 @@ // Copyright (C) 2018 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. var sz = new Size() console.assert(sz.width == 0) diff --git a/scripts/sprite.js b/scripts/sprite.js index b64546f57..68339bd8d 100644 --- a/scripts/sprite.js +++ b/scripts/sprite.js @@ -1,4 +1,7 @@ // Copyright (C) 2018 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. var a = new Sprite(32, 64) console.assert(a.width == 32) From 5ef31360f7cce01a2181ac28abaebbe9e1a02251 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 20 Aug 2018 14:50:21 -0300 Subject: [PATCH 008/200] Add app.transaction() test --- scripts/app_transaction.js | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/app_transaction.js diff --git a/scripts/app_transaction.js b/scripts/app_transaction.js new file mode 100644 index 000000000..79734d4dd --- /dev/null +++ b/scripts/app_transaction.js @@ -0,0 +1,40 @@ +// Copyright (C) 2018 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. + +var s = new Sprite(16, 32) +console.assert(s.width == 16) +console.assert(s.height == 32) + +s.width = 20 +console.assert(s.width == 20) +console.assert(s.height == 32) + +s.height = 40 +console.assert(s.width == 20) +console.assert(s.height == 40) + +app.undo() +console.assert(s.width == 20) +console.assert(s.height == 32) + +app.undo() +console.assert(s.width == 16) +console.assert(s.height == 32) + +app.transaction( + function() { + s.width = 20 + s.height = 40 + }) +console.assert(s.width == 20) +console.assert(s.height == 40) + +app.undo() +console.assert(s.width == 16) +console.assert(s.height == 32) + +app.redo() +console.assert(s.width == 20) +console.assert(s.height == 40) From 9bb05f7a443e206eca09f88b613d9149e1115651 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 22 Aug 2018 14:56:07 -0300 Subject: [PATCH 009/200] Convert scripts to Lua --- run-tests.sh | 23 ++++++++--------- scripts/app_pixel_color.js | 12 --------- scripts/app_pixel_color.lua | 12 +++++++++ scripts/app_transaction.js | 40 ------------------------------ scripts/app_transaction.lua | 40 ++++++++++++++++++++++++++++++ scripts/app_version.js | 7 ------ scripts/app_version.lua | 7 ++++++ scripts/console_assert.js | 9 ------- scripts/console_assert.lua | 9 +++++++ scripts/console_log.js | 7 ------ scripts/console_print.lua | 7 ++++++ scripts/constants.js | 8 ------ scripts/constants.lua | 8 ++++++ scripts/point.js | 24 ------------------ scripts/point.lua | 25 +++++++++++++++++++ scripts/rectangle.js | 34 ------------------------- scripts/rectangle.lua | 37 ++++++++++++++++++++++++++++ scripts/selection.js | 32 ------------------------ scripts/selection.lua | 29 ++++++++++++++++++++++ scripts/size.js | 24 ------------------ scripts/size.lua | 25 +++++++++++++++++++ scripts/sprite.js | 48 ------------------------------------ scripts/sprite.lua | 49 +++++++++++++++++++++++++++++++++++++ 23 files changed, 260 insertions(+), 256 deletions(-) delete mode 100644 scripts/app_pixel_color.js create mode 100644 scripts/app_pixel_color.lua delete mode 100644 scripts/app_transaction.js create mode 100644 scripts/app_transaction.lua delete mode 100644 scripts/app_version.js create mode 100644 scripts/app_version.lua delete mode 100644 scripts/console_assert.js create mode 100644 scripts/console_assert.lua delete mode 100644 scripts/console_log.js create mode 100644 scripts/console_print.lua delete mode 100644 scripts/constants.js create mode 100644 scripts/constants.lua delete mode 100644 scripts/point.js create mode 100644 scripts/point.lua delete mode 100644 scripts/rectangle.js create mode 100644 scripts/rectangle.lua delete mode 100644 scripts/selection.js create mode 100644 scripts/selection.lua delete mode 100644 scripts/size.js create mode 100644 scripts/size.lua delete mode 100644 scripts/sprite.js create mode 100644 scripts/sprite.lua diff --git a/run-tests.sh b/run-tests.sh index 552e1d059..4a959b809 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -18,26 +18,27 @@ $ASEPRITE --version echo ---------------------------------------------------------------------- echo "Testing console..." -$ASEPRITE -b --script scripts/console_assert.js >tmp 2>tmp_err -! grep -q Error tmp && fail -! grep -q "this should be in the output" tmp && fail -grep -q "this should not be in the output" tmp && fail +$ASEPRITE -b --script scripts/console_assert.lua >tmp 2>tmp_err +! grep -q "this should be in the output" tmp && fail "print() text not found in output" +! grep -q "assertion failed" tmp && fail "assert() text not found in output" +grep -q "this should not be in the output" tmp && fail "text that shouldn't be in the output is" -$ASEPRITE -b --script scripts/console_log.js >tmp 2>tmp_err +$ASEPRITE -b --script scripts/console_print.lua >tmp 2>tmp_err cat >tmp_expected <tmp 2>tmp_err ; then +result=0 +for script in scripts/*.lua ; do + [[ $script =~ console ]] && continue + + echo "Running $script" + if ! $ASEPRITE -b --script $script >tmp 2>tmp_err ; then echo FAILED echo STDOUT && cat tmp echo STDERR && cat tmp_err diff --git a/scripts/app_pixel_color.js b/scripts/app_pixel_color.js deleted file mode 100644 index 63180d811..000000000 --- a/scripts/app_pixel_color.js +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (C) 2018 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -var pc = app.pixelColor -console.assert(0 == pc.rgba(0, 0, 0, 0)) -console.assert(1 == pc.rgbaR(pc.rgba(1, 2, 3, 4))) -console.assert(2 == pc.rgbaG(pc.rgba(1, 2, 3, 4))) -console.assert(3 == pc.rgbaB(pc.rgba(1, 2, 3, 4))) -console.assert(4 == pc.rgbaA(pc.rgba(1, 2, 3, 4))) -console.assert(0xff104080 == pc.rgba(0x80, 0x40, 0x10, 0xff)) diff --git a/scripts/app_pixel_color.lua b/scripts/app_pixel_color.lua new file mode 100644 index 000000000..a86c1d3f0 --- /dev/null +++ b/scripts/app_pixel_color.lua @@ -0,0 +1,12 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local pc = app.pixelColor +assert(0 == pc.rgba(0, 0, 0, 0)) +assert(1 == pc.rgbaR(pc.rgba(1, 2, 3, 4))) +assert(2 == pc.rgbaG(pc.rgba(1, 2, 3, 4))) +assert(3 == pc.rgbaB(pc.rgba(1, 2, 3, 4))) +assert(4 == pc.rgbaA(pc.rgba(1, 2, 3, 4))) +assert(0xff104080 == pc.rgba(0x80, 0x40, 0x10, 0xff)) diff --git a/scripts/app_transaction.js b/scripts/app_transaction.js deleted file mode 100644 index 79734d4dd..000000000 --- a/scripts/app_transaction.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2018 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -var s = new Sprite(16, 32) -console.assert(s.width == 16) -console.assert(s.height == 32) - -s.width = 20 -console.assert(s.width == 20) -console.assert(s.height == 32) - -s.height = 40 -console.assert(s.width == 20) -console.assert(s.height == 40) - -app.undo() -console.assert(s.width == 20) -console.assert(s.height == 32) - -app.undo() -console.assert(s.width == 16) -console.assert(s.height == 32) - -app.transaction( - function() { - s.width = 20 - s.height = 40 - }) -console.assert(s.width == 20) -console.assert(s.height == 40) - -app.undo() -console.assert(s.width == 16) -console.assert(s.height == 32) - -app.redo() -console.assert(s.width == 20) -console.assert(s.height == 40) diff --git a/scripts/app_transaction.lua b/scripts/app_transaction.lua new file mode 100644 index 000000000..ea928b950 --- /dev/null +++ b/scripts/app_transaction.lua @@ -0,0 +1,40 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local s = Sprite(16, 32) +assert(s.width == 16) +assert(s.height == 32) + +s.width = 20 +assert(s.width == 20) +assert(s.height == 32) + +s.height = 40 +assert(s.width == 20) +assert(s.height == 40) + +app.undo() +assert(s.width == 20) +assert(s.height == 32) + +app.undo() +assert(s.width == 16) +assert(s.height == 32) + +app.transaction( + function() + s.width = 20 + s.height = 40 + end) +assert(s.width == 20) +assert(s.height == 40) + +app.undo() +assert(s.width == 16) +assert(s.height == 32) + +app.redo() +assert(s.width == 20) +assert(s.height == 40) diff --git a/scripts/app_version.js b/scripts/app_version.js deleted file mode 100644 index b0d0d3c40..000000000 --- a/scripts/app_version.js +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (C) 2018 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -console.assert(app.version[0] == "1") -console.assert(app.version[1] == ".") diff --git a/scripts/app_version.lua b/scripts/app_version.lua new file mode 100644 index 000000000..6faafd9e3 --- /dev/null +++ b/scripts/app_version.lua @@ -0,0 +1,7 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +assert(string.sub(app.version, 1, 1) == "1") +assert(string.sub(app.version, 2, 2) == ".") diff --git a/scripts/console_assert.js b/scripts/console_assert.js deleted file mode 100644 index 46f09a464..000000000 --- a/scripts/console_assert.js +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (C) 2018 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -console.assert(true) -console.log("this should be in the output") -console.assert(false) -console.log("this should not be in the output") diff --git a/scripts/console_assert.lua b/scripts/console_assert.lua new file mode 100644 index 000000000..2587e9675 --- /dev/null +++ b/scripts/console_assert.lua @@ -0,0 +1,9 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +assert(true) +print("this should be in the output") +assert(false) +print("this should not be in the output") diff --git a/scripts/console_log.js b/scripts/console_log.js deleted file mode 100644 index fbaca7658..000000000 --- a/scripts/console_log.js +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (C) 2018 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -console.log("hello world") -console.log(1, 2, 3) diff --git a/scripts/console_print.lua b/scripts/console_print.lua new file mode 100644 index 000000000..dc402169a --- /dev/null +++ b/scripts/console_print.lua @@ -0,0 +1,7 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +print("hello world") +print(1, 2, 3) diff --git a/scripts/constants.js b/scripts/constants.js deleted file mode 100644 index d70711132..000000000 --- a/scripts/constants.js +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (C) 2018 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -console.assert(ColorMode.RGB == 0) -console.assert(ColorMode.GRAYSCALE == 1) -console.assert(ColorMode.INDEXED == 2) diff --git a/scripts/constants.lua b/scripts/constants.lua new file mode 100644 index 000000000..8eb9ab970 --- /dev/null +++ b/scripts/constants.lua @@ -0,0 +1,8 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +assert(ColorMode.RGB == 0) +assert(ColorMode.GRAYSCALE == 1) +assert(ColorMode.INDEXED == 2) diff --git a/scripts/point.js b/scripts/point.js deleted file mode 100644 index ffd745a66..000000000 --- a/scripts/point.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2018 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -var pt = new Point() -console.assert(pt.x == 0) -console.assert(pt.y == 0) - -pt = new Point(1, 2) -console.assert(pt.x == 1) -console.assert(pt.y == 2) - -var pt2 = new Point(pt) -console.assert(pt2.x == 1) -console.assert(pt2.y == 2) - -pt.x = 5; -pt.y = 6; -console.assert(pt.x == 5) -console.assert(pt.y == 6) - -// TODO fix this -console.log(JSON.stringify(pt)) diff --git a/scripts/point.lua b/scripts/point.lua new file mode 100644 index 000000000..793a3aa09 --- /dev/null +++ b/scripts/point.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. + +local pt = Point() +assert(pt.x == 0) +assert(pt.y == 0) + +pt = Point(1, 2) +assert(pt.x == 1) +assert(pt.y == 2) + +local pt2 = Point(pt) +assert(pt2.x == 1) +assert(pt2.y == 2) + +pt.x = 5 +pt.y = 6 +assert(pt.x == 5) +assert(pt.y == 6) + +pt = Point{x=10, y=20} +assert(pt.x == 10) +assert(pt.y == 20) diff --git a/scripts/rectangle.js b/scripts/rectangle.js deleted file mode 100644 index 072c4e768..000000000 --- a/scripts/rectangle.js +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2018 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -var rc = new Rectangle() -console.assert(rc.x == 0) -console.assert(rc.y == 0) -console.assert(rc.width == 0) -console.assert(rc.height == 0) - -rc = new Rectangle(1, 2, 3, 4) -console.assert(rc.x == 1) -console.assert(rc.y == 2) -console.assert(rc.width == 3) -console.assert(rc.height == 4) - -var rc2 = new Rectangle(rc) -console.assert(rc2.x == 1) -console.assert(rc2.y == 2) -console.assert(rc2.width == 3) -console.assert(rc2.height == 4) - -rc.x = 5; -rc.y = 6; -rc.width = 7; -rc.height = 8; -console.assert(rc.x == 5) -console.assert(rc.y == 6) -console.assert(rc.width == 7) -console.assert(rc.height == 8) - -// TODO fix this -console.log(JSON.stringify(rc)) diff --git a/scripts/rectangle.lua b/scripts/rectangle.lua new file mode 100644 index 000000000..79e4cfd5a --- /dev/null +++ b/scripts/rectangle.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. + +local rc = Rectangle() +assert(rc.x == 0) +assert(rc.y == 0) +assert(rc.width == 0) +assert(rc.height == 0) + +rc = Rectangle(1, 2, 3, 4) +assert(rc.x == 1) +assert(rc.y == 2) +assert(rc.width == 3) +assert(rc.height == 4) + +local rc2 = Rectangle(rc) +assert(rc2.x == 1) +assert(rc2.y == 2) +assert(rc2.width == 3) +assert(rc2.height == 4) + +rc.x = 5; +rc.y = 6; +rc.width = 7; +rc.height = 8; +assert(rc.x == 5) +assert(rc.y == 6) +assert(rc.width == 7) +assert(rc.height == 8) + +rc = Rectangle{x=2, y=3, width=4, height=5} +assert(rc.x == 2) +assert(rc.y == 3) +assert(rc.width == 4) +assert(rc.height == 5) diff --git a/scripts/selection.js b/scripts/selection.js deleted file mode 100644 index 9938b105e..000000000 --- a/scripts/selection.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2018 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -// Isolated selection -var a = new Selection() -console.assert(a.bounds.x == 0) -console.assert(a.bounds.y == 0) -console.assert(a.bounds.width == 0) -console.assert(a.bounds.height == 0) - -a.select(1, 2, 3, 4); -console.assert(a.bounds.x == 1) -console.assert(a.bounds.y == 2) -console.assert(a.bounds.width == 3) -console.assert(a.bounds.height == 4) - -a.select({ 'x': 5, 'y': 6, 'width': 7, 'height': 8 }) -console.assert(a.bounds.x == 5) -console.assert(a.bounds.y == 6) -console.assert(a.bounds.width == 7) -console.assert(a.bounds.height == 8) - -a.deselect(); -console.assert(a.bounds.x == 0) -console.assert(a.bounds.y == 0) -console.assert(a.bounds.width == 0) -console.assert(a.bounds.height == 0) - -// Selection related to a sprite -// TODO diff --git a/scripts/selection.lua b/scripts/selection.lua new file mode 100644 index 000000000..91a11157a --- /dev/null +++ b/scripts/selection.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. + +-- Isolated selection +local a = Selection() +assert(a.bounds.x == 0) +assert(a.bounds.y == 0) +assert(a.bounds.width == 0) +assert(a.bounds.height == 0) + +a:select(1, 2, 3, 4) +assert(a.bounds.x == 1) +assert(a.bounds.y == 2) +assert(a.bounds.width == 3) +assert(a.bounds.height == 4) + +a:select{x=5, y=6, width=7, height=8} +assert(a.bounds.x == 5) +assert(a.bounds.y == 6) +assert(a.bounds.width == 7) +assert(a.bounds.height == 8) + +a:deselect() +assert(a.bounds.x == 0) +assert(a.bounds.y == 0) +assert(a.bounds.width == 0) +assert(a.bounds.height == 0) diff --git a/scripts/size.js b/scripts/size.js deleted file mode 100644 index 7aed31a47..000000000 --- a/scripts/size.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2018 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -var sz = new Size() -console.assert(sz.width == 0) -console.assert(sz.height == 0) - -sz = new Size(3, 4) -console.assert(sz.width == 3) -console.assert(sz.height == 4) - -var sz2 = new Size(sz) -console.assert(sz2.width == 3) -console.assert(sz2.height == 4) - -sz.width = 7; -sz.height = 8; -console.assert(sz.width == 7) -console.assert(sz.height == 8) - -// TODO fix this -console.log(JSON.stringify(sz)) diff --git a/scripts/size.lua b/scripts/size.lua new file mode 100644 index 000000000..58acb0ae7 --- /dev/null +++ b/scripts/size.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. + +local sz = Size() +assert(sz.width == 0) +assert(sz.height == 0) + +sz = Size(3, 4) +assert(sz.width == 3) +assert(sz.height == 4) + +local sz2 = Size(sz) +assert(sz2.width == 3) +assert(sz2.height == 4) + +sz.width = 7 +sz.height = 8 +assert(sz.width == 7) +assert(sz.height == 8) + +sz = Size{width=10, height=20} +assert(sz.width == 10) +assert(sz.height == 20) diff --git a/scripts/sprite.js b/scripts/sprite.js deleted file mode 100644 index 68339bd8d..000000000 --- a/scripts/sprite.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2018 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -var a = new Sprite(32, 64) -console.assert(a.width == 32) -console.assert(a.height == 64) -console.assert(a.colorMode == ColorMode.RGB) // RGB by default - -var s = a.selection -console.assert(s.bounds.x == 0) -console.assert(s.bounds.y == 0) -console.assert(s.bounds.width == 0) -console.assert(s.bounds.height == 0) - -s.selectAll() -console.assert(s.bounds.x == 0) -console.assert(s.bounds.y == 0) -console.assert(s.bounds.width == a.width) -console.assert(s.bounds.height == a.height) - -s.select(2, 3, 4, 5) -console.assert(s.bounds.x == 2) -console.assert(s.bounds.y == 3) -console.assert(s.bounds.width == 4) -console.assert(s.bounds.height == 5) - -a.crop() -console.assert(a.width == 4) -console.assert(a.height == 5) -a.resize(6, 8) -console.assert(a.width == 6) -console.assert(a.height == 8) -a.crop({ 'x': -1, 'y': -1, 'width': 20, 'height': 30 }) -console.assert(a.width == 20) -console.assert(a.height == 30) - -// resize sprite setting width/height -a.width = 8 -a.height = 10 -console.assert(a.width == 8) -console.assert(a.height == 10) - -var b = new Sprite(4, 4, ColorMode.INDEXED) -console.assert(b.width == 4) -console.assert(b.height == 4) -console.assert(b.colorMode == ColorMode.INDEXED) diff --git a/scripts/sprite.lua b/scripts/sprite.lua new file mode 100644 index 000000000..7cb56ab9c --- /dev/null +++ b/scripts/sprite.lua @@ -0,0 +1,49 @@ +-- Copyright (C) 2018 David Capello +-- +-- 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 + +-- Sprite Selection +local s = a.selection +assert(s.bounds.x == 0) +assert(s.bounds.y == 0) +assert(s.bounds.width == 0) +assert(s.bounds.height == 0) + +s:selectAll() +assert(s.bounds.x == 0) +assert(s.bounds.y == 0) +assert(s.bounds.width == a.width) +assert(s.bounds.height == a.height) + +s:select(2, 3, 4, 5) +assert(s.bounds.x == 2) +assert(s.bounds.y == 3) +assert(s.bounds.width == 4) +assert(s.bounds.height == 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) + +local b = Sprite(4, 4, ColorMode.INDEXED) +assert(b.width == 4) +assert(b.height == 4) +assert(b.colorMode == ColorMode.INDEXED) From f5a484d28a36dbab3af5f268205dca9a4cb21b49 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 30 Aug 2018 23:23:31 -0300 Subject: [PATCH 010/200] Add some tests for Image() --- scripts/image.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 scripts/image.lua diff --git a/scripts/image.lua b/scripts/image.lua new file mode 100644 index 000000000..01e58a1d3 --- /dev/null +++ b/scripts/image.lua @@ -0,0 +1,53 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local a = Image(32, 64) +assert(a.width == 32) +assert(a.height == 64) +assert(a.colorMode == ColorMode.RGB) -- RGB by default + +local b = Image(32, 64, ColorMode.INDEXED) +assert(b.width == 32) +assert(b.height == 64) +assert(b.colorMode == ColorMode.INDEXED) + +-- Get/put RGBA pixels +local pc = app.pixelColor +for y=0,a.height-1 do + for x=0,a.width-1 do + a:putPixel(x, y, pc.rgba(x, y, x+y, x-y)) + end +end + +-- Clone +local c = a:clone() +assert(c.width == 32) +assert(c.height == 64) +assert(c.colorMode == ColorMode.RGB) + +-- Get RGB pixels +for y=0,c.height-1 do + for x=0,c.width-1 do + assert(c:getPixel(x, y) == pc.rgba(x, y, x+y, x-y)) + end +end + +-- Patch +local pc = app.pixelColor +local spr = Sprite(256, 256) +local image = app.site.image +local copy = image:clone() +assert(image:getPixel(0, 0) == 0) +for y=0,copy.height-1 do + for x=0,copy.width-1 do + copy:putPixel(x, y, pc.rgba(255-x, 255-y, 0, 255)) + end +end +image:putImage(copy) +assert(image:getPixel(0, 0) == pc.rgba(255, 255, 0, 255)) +assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 255)) +app.undo() +assert(image:getPixel(0, 0) == pc.rgba(0, 0, 0, 0)) +assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 0)) From ec5a4c263f7ef665242b185c40c92cc6bcbd526d Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 31 Aug 2018 15:07:51 -0300 Subject: [PATCH 011/200] Add tests for Rectangle.isEmpty --- scripts/rectangle.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/rectangle.lua b/scripts/rectangle.lua index 79e4cfd5a..c25e9a5ce 100644 --- a/scripts/rectangle.lua +++ b/scripts/rectangle.lua @@ -8,12 +8,14 @@ assert(rc.x == 0) assert(rc.y == 0) assert(rc.width == 0) assert(rc.height == 0) +assert(rc.isEmpty) rc = Rectangle(1, 2, 3, 4) assert(rc.x == 1) assert(rc.y == 2) assert(rc.width == 3) assert(rc.height == 4) +assert(not rc.isEmpty) local rc2 = Rectangle(rc) assert(rc2.x == 1) From e7a4cce5084fd21f11a10de799a3e500e42f567b Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 31 Aug 2018 15:07:59 -0300 Subject: [PATCH 012/200] Add tests for Selection.isEmpty/contains --- scripts/selection.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/selection.lua b/scripts/selection.lua index 91a11157a..68b7cff57 100644 --- a/scripts/selection.lua +++ b/scripts/selection.lua @@ -9,12 +9,18 @@ assert(a.bounds.x == 0) assert(a.bounds.y == 0) assert(a.bounds.width == 0) assert(a.bounds.height == 0) +assert(a.isEmpty) a:select(1, 2, 3, 4) assert(a.bounds.x == 1) assert(a.bounds.y == 2) assert(a.bounds.width == 3) assert(a.bounds.height == 4) +assert(not a.isEmpty) +assert(a:contains(1, 2)) +assert(a:contains(1+3-1, 2+4-1)) +assert(not a:contains(0, 1)) +assert(not a:contains(1+3, 2+4)) a:select{x=5, y=6, width=7, height=8} assert(a.bounds.x == 5) @@ -27,3 +33,5 @@ assert(a.bounds.x == 0) assert(a.bounds.y == 0) assert(a.bounds.width == 0) assert(a.bounds.height == 0) +assert(a.isEmpty) +assert(not a:contains(0, 0)) From 017a7499d2d6dc352fa02c3f5f590d6f77247595 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 3 Sep 2018 14:28:31 -0300 Subject: [PATCH 013/200] Create blocks of tests in image.lua --- scripts/image.lua | 68 ++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/scripts/image.lua b/scripts/image.lua index 01e58a1d3..ccf7ed68f 100644 --- a/scripts/image.lua +++ b/scripts/image.lua @@ -3,51 +3,59 @@ -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. +local pc = app.pixelColor + local a = Image(32, 64) assert(a.width == 32) assert(a.height == 64) assert(a.colorMode == ColorMode.RGB) -- RGB by default -local b = Image(32, 64, ColorMode.INDEXED) -assert(b.width == 32) -assert(b.height == 64) -assert(b.colorMode == ColorMode.INDEXED) +do + local b = Image(32, 64, ColorMode.INDEXED) + assert(b.width == 32) + assert(b.height == 64) + assert(b.colorMode == ColorMode.INDEXED) +end -- Get/put RGBA pixels -local pc = app.pixelColor -for y=0,a.height-1 do - for x=0,a.width-1 do - a:putPixel(x, y, pc.rgba(x, y, x+y, x-y)) +do + for y=0,a.height-1 do + for x=0,a.width-1 do + a:putPixel(x, y, pc.rgba(x, y, x+y, x-y)) + end end end -- Clone -local c = a:clone() -assert(c.width == 32) -assert(c.height == 64) -assert(c.colorMode == ColorMode.RGB) +do + local c = a:clone() + assert(c.width == 32) + assert(c.height == 64) + assert(c.colorMode == ColorMode.RGB) --- Get RGB pixels -for y=0,c.height-1 do - for x=0,c.width-1 do - assert(c:getPixel(x, y) == pc.rgba(x, y, x+y, x-y)) + -- Get RGB pixels + for y=0,c.height-1 do + for x=0,c.width-1 do + assert(c:getPixel(x, y) == pc.rgba(x, y, x+y, x-y)) + end end end -- Patch -local pc = app.pixelColor -local spr = Sprite(256, 256) -local image = app.site.image -local copy = image:clone() -assert(image:getPixel(0, 0) == 0) -for y=0,copy.height-1 do - for x=0,copy.width-1 do - copy:putPixel(x, y, pc.rgba(255-x, 255-y, 0, 255)) +do + local spr = Sprite(256, 256) + local image = app.site.image + local copy = image:clone() + assert(image:getPixel(0, 0) == 0) + for y=0,copy.height-1 do + for x=0,copy.width-1 do + copy:putPixel(x, y, pc.rgba(255-x, 255-y, 0, 255)) + end end + image:putImage(copy) + assert(image:getPixel(0, 0) == pc.rgba(255, 255, 0, 255)) + assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 255)) + app.undo() + assert(image:getPixel(0, 0) == pc.rgba(0, 0, 0, 0)) + assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 0)) end -image:putImage(copy) -assert(image:getPixel(0, 0) == pc.rgba(255, 255, 0, 255)) -assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 255)) -app.undo() -assert(image:getPixel(0, 0) == pc.rgba(0, 0, 0, 0)) -assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 0)) From dfdadbe9c156485e570d2a06449a1a0f730885a4 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 3 Sep 2018 14:29:14 -0300 Subject: [PATCH 014/200] Add some minor tests of Lua library --- scripts/math.lua | 10 ++++++++++ scripts/os.lua | 14 ++++++++++++++ scripts/string.lua | 23 +++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 scripts/math.lua create mode 100644 scripts/os.lua create mode 100644 scripts/string.lua diff --git a/scripts/math.lua b/scripts/math.lua new file mode 100644 index 000000000..b08b2605a --- /dev/null +++ b/scripts/math.lua @@ -0,0 +1,10 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +assert(100 == math.abs(-100)) +assert(100 == math.min(100, 200, 300)) +assert(300 == math.max(100, 200, 300)) +assert(50 == math.fmod(250, 100)) +assert(3141 == math.floor(1000*math.pi)) diff --git a/scripts/os.lua b/scripts/os.lua new file mode 100644 index 000000000..f18060237 --- /dev/null +++ b/scripts/os.lua @@ -0,0 +1,14 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +assert("" ~= os.getenv("PATH")) +print("PATH", os.getenv("PATH")) + +local start_clock = os.clock() +print("Start ", start_clock) + +local end_clock = os.clock() +print("End ", end_clock, " Elapsed ", end_clock - start_clock) +assert(start_clock < end_clock) diff --git a/scripts/string.lua b/scripts/string.lua new file mode 100644 index 000000000..117fd5beb --- /dev/null +++ b/scripts/string.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. + +assert(72 == string.byte("Hello", 1)) +assert(101 == string.byte("Hello", 2)) +assert(111 == string.byte("Hello", 5)) +assert("Hello" == string.char(72, 101, 108, 108, 111)) + +local s = "Hello" +assert(111 == s:byte(5)) +assert(5 == string.len(s)) +assert("olleH" == string.reverse(s)) +assert("hello" == string.lower(s)) +assert("HELLO" == string.upper(s)) + +assert("Simple int 32" == string.format("Simple int %d", 32)) +assert("Simple int 0032" == string.format("Simple int %04d", 32)) + +assert(7 == string.find("Hello World!", "W")) + +assert("-- hi 1000 --" == string.format("-- %s %d --", "hi", 1000)) From a5c733290e7c155e344783ef8bc97ac7206ac252 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 3 Sep 2018 18:40:09 -0300 Subject: [PATCH 015/200] Add image iterator tests --- scripts/image_iterator.lua | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 scripts/image_iterator.lua diff --git a/scripts/image_iterator.lua b/scripts/image_iterator.lua new file mode 100644 index 000000000..f3456a80c --- /dev/null +++ b/scripts/image_iterator.lua @@ -0,0 +1,57 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local pc = app.pixelColor + +-- Iterate pixels +do + local spr = Sprite(2, 2) + local image = app.site.image + local colors = { pc.rgba(255, 0, 0, 255), + pc.rgba(0, 255, 0, 255), + pc.rgba(255, 0, 255, 255), + pc.rgba(255, 0, 255, 255) } + local xy = { + { x=0, y=0 }, + { x=1, y=0 }, + { x=0, y=1 }, + { x=1, y=1 } } + + local c = 1 + for y=0,image.height-1 do + for x=0,image.width-1 do + image:putPixel(x, y, colors[c]) + c = c+1 + end + end + + c = 1 + for y=0,image.height-1 do + for x=0,image.width-1 do + assert(colors[c] == image:getPixel(x, y)) + c = c+1 + end + end + + c = 1 + for it in image:pixels() do + assert(colors[c] == it()) + assert(xy[c].x == it.x) + assert(xy[c].y == it.y) + c = c+1 + end + + c = 1 + for it in image:pixels() do + it(pc.rgba(255, 32*c, 0, 255)) + c = c+1 + end + + c = 1 + for it in image:pixels() do + assert(pc.rgba(255, 32*c, 0, 255) == it()) + c = c+1 + end +end From 0e6a76e5003d87e900cd8c7a22014cd58e7010d8 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 4 Sep 2018 17:31:27 -0300 Subject: [PATCH 016/200] Add some tests for Palette, Color, and app.command --- scripts/app_command.lua | 33 +++++++++++++++++++++++++++++++++ scripts/color.lua | 40 ++++++++++++++++++++++++++++++++++++++++ scripts/palette.lua | 21 +++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 scripts/app_command.lua create mode 100644 scripts/color.lua create mode 100644 scripts/palette.lua diff --git a/scripts/app_command.lua b/scripts/app_command.lua new file mode 100644 index 000000000..f7c238bf1 --- /dev/null +++ b/scripts/app_command.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. + +local s = Sprite(32, 32) +assert(s.width == 32) +assert(s.height == 32) + +s:resize(50, 40) +assert(s.width == 50) +assert(s.height == 40) + +-- Undo/Redo + +local pc = app.command.Undo() +assert(s.width == 32) +assert(s.height == 32) + +local pc = app.command.Redo() +assert(s.width == 50) +assert(s.height == 40) + +-- NewLayer + +assert(#s.layers == 1) +app.command.NewLayer{top=true} +assert(#s.layers == 2) +assert(s.layers[2].isImage) + +app.command.NewLayer{top=true, group=true} +assert(#s.layers == 3) +assert(s.layers[3].isGroup) diff --git a/scripts/color.lua b/scripts/color.lua new file mode 100644 index 000000000..30108c788 --- /dev/null +++ b/scripts/color.lua @@ -0,0 +1,40 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local a, b + +a = Color() +assert(a.red == 0) +assert(a.green == 0) +assert(a.blue == 0) +assert(a.alpha == 0) + +a = Color{ r=100, g=50, b=10 } +b = Color(100, 50, 10) +assert(a.red == 100) +assert(a.green == 50) +assert(a.blue == 10) +assert(a.alpha == 255) +assert(a == b) + +a = Color{ red=200, green=100, blue=20, alpha=200 } +b = Color(200, 100, 20, 200) +assert(a.red == 200) +assert(a.green == 100) +assert(a.blue == 20) +assert(a.alpha == 200) +assert(a == b) + +a = Color{ h=180, s=0.4, v=0.5, a=200 } +b = Color{ hue=180, saturation=0.4, value=0.5, alpha=200 } +assert(a.hue == 180) +assert(a.saturation == 0.4) +assert(a.value == 0.5) +assert(a.alpha == 200) +assert(b.hue == 180) +assert(b.saturation == 0.4) +assert(b.value == 0.5) +assert(b.alpha == 200) +assert(a == b) diff --git a/scripts/palette.lua b/scripts/palette.lua new file mode 100644 index 000000000..f1ea43e82 --- /dev/null +++ b/scripts/palette.lua @@ -0,0 +1,21 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local p = Palette(32) +assert(#p == 32) +for i = 0,#p-1 do + assert(p:getColor(i) == Color(0, 0, 0)) +end + +p:resize(4) +assert(#p == 4) +p:setColor(0, Color(255, 8, 32)) +p:setColor(1, Color(250, 4, 30)) +p:setColor(2, Color(240, 3, 20)) +p:setColor(3, Color(210, 2, 10)) +assert(p:getColor(0) == Color(255, 8, 32)) +assert(p:getColor(1) == Color(250, 4, 30)) +assert(p:getColor(2) == Color(240, 3, 20)) +assert(p:getColor(3) == Color(210, 2, 10)) From 0ad4a3935a9fa4f69581700a88d2d46d8978967f Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 6 Sep 2018 14:21:20 -0300 Subject: [PATCH 017/200] Update app.command tests with new available commands --- scripts/app_command.lua | 107 ++++++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 21 deletions(-) diff --git a/scripts/app_command.lua b/scripts/app_command.lua index f7c238bf1..2a14d0eac 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -3,31 +3,96 @@ -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. -local s = Sprite(32, 32) -assert(s.width == 32) -assert(s.height == 32) +do -- Undo/Redo commands (like app.undo/redo()) + local s = Sprite(32, 32) + assert(s.width == 32) + assert(s.height == 32) -s:resize(50, 40) -assert(s.width == 50) -assert(s.height == 40) + s:resize(50, 40) + assert(s.width == 50) + assert(s.height == 40) --- Undo/Redo + app.command.Undo() + assert(s.width == 32) + assert(s.height == 32) -local pc = app.command.Undo() -assert(s.width == 32) -assert(s.height == 32) + app.command.Redo() + assert(s.width == 50) + assert(s.height == 40) +end -local pc = app.command.Redo() -assert(s.width == 50) -assert(s.height == 40) +do -- NewLayer/RemoveLayer + local s = Sprite(32, 32) + assert(#s.layers == 1) + local lay = s.layers[1] + app.command.NewLayer{top=true} + assert(#s.layers == 2) + assert(s.layers[2].isImage) --- NewLayer + app.command.NewLayer{top=true, group=true} + assert(#s.layers == 3) + assert(s.layers[3].isGroup) -assert(#s.layers == 1) -app.command.NewLayer{top=true} -assert(#s.layers == 2) -assert(s.layers[2].isImage) + app.command.RemoveLayer() + assert(#s.layers == 2) -app.command.NewLayer{top=true, group=true} -assert(#s.layers == 3) -assert(s.layers[3].isGroup) + app.command.RemoveLayer() + assert(#s.layers == 1) +end + +do -- Background/Transparent layers + local s = Sprite(32, 32) + assert(s.layers[1].isTransparent) + assert(s.cels[1].image:getPixel(0, 0) == app.pixelColor.rgba(0, 0, 0, 0)) + + app.bgColor = Color(32, 64, 128) + app.command.BackgroundFromLayer() -- the layer will be filled with app.bgColor + assert(s.layers[1].isBackground) + assert(s.cels[1].image:getPixel(0, 0) == app.pixelColor.rgba(32, 64, 128, 255)) + + app.command.LayerFromBackground() + assert(s.layers[1].isTransparent) + assert(s.cels[1].image:getPixel(0, 0) == app.pixelColor.rgba(32, 64, 128, 255)) +end + +do -- Crop and Trim + local s = Sprite(32, 32) + s.selection:select(4, 5, 8, 10) + assert(s.cels[1].bounds == Rectangle(0, 0, 32, 32)) + + -- Crop + + app.command.CropSprite() + assert(s.width == 8) + assert(s.height == 10) + assert(s.cels[1].bounds == Rectangle(-4, -5, 32, 32)) + + -- Autocrop (Trim) + + app.command.AutocropSprite() -- Trim does nothing when we should remove all pixels + assert(s.width == 8) + assert(s.height == 10) + + s.cels[1].image:putPixel(5, 5, Color(255, 0, 0)) + s.cels[1].image:putPixel(4, 6, Color(255, 0, 0)) + app.command.AutocropSprite() + assert(s.width == 2) + assert(s.height == 2) +end + +do -- Cel Opacity + local s = Sprite(32, 32) + local c = s.cels[1] + assert(c.opacity == 255) + + app.command.CelOpacity{opacity=128} + assert(c.opacity == 128) + + s.cels[1].opacity = 255 + assert(c.opacity == 255) + + app.undo() + assert(c.opacity == 128) + app.undo() + assert(c.opacity == 255) +end From fc2a3c81a45be706780e8773d1f3f03af329f5a5 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 6 Sep 2018 14:21:34 -0300 Subject: [PATCH 018/200] Don't run console tests on Windows --- run-tests.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index 4a959b809..706723ff0 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -23,12 +23,16 @@ $ASEPRITE -b --script scripts/console_assert.lua >tmp 2>tmp_err ! grep -q "assertion failed" tmp && fail "assert() text not found in output" grep -q "this should not be in the output" tmp && fail "text that shouldn't be in the output is" -$ASEPRITE -b --script scripts/console_print.lua >tmp 2>tmp_err -cat >tmp_expected <tmp 2>tmp_err + cat >tmp_expected < Date: Fri, 7 Sep 2018 14:05:54 -0300 Subject: [PATCH 019/200] Add cel tests --- scripts/cel.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/cel.lua diff --git a/scripts/cel.lua b/scripts/cel.lua new file mode 100644 index 000000000..cdaff30dc --- /dev/null +++ b/scripts/cel.lua @@ -0,0 +1,22 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local s = Sprite(32, 64) +assert(#s.layers == 1) +assert(#s.cels == 1) + +local c = s.cels[1] +assert(c.sprite == s) +assert(c.layer == s.layers[1]) +assert(c.frame == 1) +assert(c.image) +assert(c.bounds == Rectangle(0, 0, 32, 64)) +assert(c.color == Color()) +assert(c.data == "") + +c.color = Color{ r=255, g=100, b=20 } +c.data = "test" +assert(c.color == Color{ r=255, g=100, b=20 }) +assert(c.data == "test") From d8200651e8e2d68e613a66fec899a3faaf3cc153 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 7 Sep 2018 14:09:10 -0300 Subject: [PATCH 020/200] Move sprite selection tests to selection.lua file --- scripts/selection.lua | 80 ++++++++++++++++++++++++++++--------------- scripts/sprite.lua | 21 ++---------- 2 files changed, 54 insertions(+), 47 deletions(-) diff --git a/scripts/selection.lua b/scripts/selection.lua index 68b7cff57..778b2913f 100644 --- a/scripts/selection.lua +++ b/scripts/selection.lua @@ -4,34 +4,58 @@ -- Read LICENSE.txt for more information. -- Isolated selection -local a = Selection() -assert(a.bounds.x == 0) -assert(a.bounds.y == 0) -assert(a.bounds.width == 0) -assert(a.bounds.height == 0) -assert(a.isEmpty) +do + local a = Selection() + assert(a.bounds.x == 0) + assert(a.bounds.y == 0) + assert(a.bounds.width == 0) + assert(a.bounds.height == 0) + assert(a.isEmpty) -a:select(1, 2, 3, 4) -assert(a.bounds.x == 1) -assert(a.bounds.y == 2) -assert(a.bounds.width == 3) -assert(a.bounds.height == 4) -assert(not a.isEmpty) -assert(a:contains(1, 2)) -assert(a:contains(1+3-1, 2+4-1)) -assert(not a:contains(0, 1)) -assert(not a:contains(1+3, 2+4)) + a:select(1, 2, 3, 4) + assert(a.bounds.x == 1) + assert(a.bounds.y == 2) + assert(a.bounds.width == 3) + assert(a.bounds.height == 4) + assert(not a.isEmpty) + assert(a:contains(1, 2)) + assert(a:contains(1+3-1, 2+4-1)) + assert(not a:contains(0, 1)) + assert(not a:contains(1+3, 2+4)) -a:select{x=5, y=6, width=7, height=8} -assert(a.bounds.x == 5) -assert(a.bounds.y == 6) -assert(a.bounds.width == 7) -assert(a.bounds.height == 8) + a:select{x=5, y=6, width=7, height=8} + assert(a.bounds.x == 5) + assert(a.bounds.y == 6) + assert(a.bounds.width == 7) + assert(a.bounds.height == 8) -a:deselect() -assert(a.bounds.x == 0) -assert(a.bounds.y == 0) -assert(a.bounds.width == 0) -assert(a.bounds.height == 0) -assert(a.isEmpty) -assert(not a:contains(0, 0)) + a:deselect() + assert(a.bounds.x == 0) + assert(a.bounds.y == 0) + assert(a.bounds.width == 0) + assert(a.bounds.height == 0) + assert(a.isEmpty) + assert(not a:contains(0, 0)) +end + +-- Sprite Selection +do + local spr = Sprite(32, 32) + local sel = spr.selection + assert(sel.bounds.x == 0) + assert(sel.bounds.y == 0) + assert(sel.bounds.width == 0) + assert(sel.bounds.height == 0) + + sel:selectAll() + assert(sel.bounds.x == 0) + assert(sel.bounds.y == 0) + assert(sel.bounds.width == spr.width) + assert(sel.bounds.height == spr.height) + + sel:select(2, 3, 4, 5) + assert(sel.bounds.x == 2) + assert(sel.bounds.y == 3) + assert(sel.bounds.width == 4) + assert(sel.bounds.height == 5) +end diff --git a/scripts/sprite.lua b/scripts/sprite.lua index 7cb56ab9c..b6c4d3988 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -8,25 +8,8 @@ assert(a.width == 32) assert(a.height == 64) assert(a.colorMode == ColorMode.RGB) -- RGB by default --- Sprite Selection -local s = a.selection -assert(s.bounds.x == 0) -assert(s.bounds.y == 0) -assert(s.bounds.width == 0) -assert(s.bounds.height == 0) - -s:selectAll() -assert(s.bounds.x == 0) -assert(s.bounds.y == 0) -assert(s.bounds.width == a.width) -assert(s.bounds.height == a.height) - -s:select(2, 3, 4, 5) -assert(s.bounds.x == 2) -assert(s.bounds.y == 3) -assert(s.bounds.width == 4) -assert(s.bounds.height == 5) - +-- Crop and resize +a.selection:select(2, 3, 4, 5) a:crop() assert(a.width == 4) assert(a.height == 5) From aee07285faba937133f42df407d500ce192fc807 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 7 Sep 2018 14:38:59 -0300 Subject: [PATCH 021/200] Add some extra tests for selection operations --- scripts/selection.lua | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/scripts/selection.lua b/scripts/selection.lua index 778b2913f..529a6e6b8 100644 --- a/scripts/selection.lua +++ b/scripts/selection.lua @@ -36,6 +36,10 @@ do assert(a.bounds.height == 0) assert(a.isEmpty) assert(not a:contains(0, 0)) + + -- Constructor with rectangles + local b = Selection(1, 2, 3, 4) + assert(b.bounds == Rectangle(1, 2, 3, 4)) end -- Sprite Selection @@ -59,3 +63,50 @@ do assert(sel.bounds.width == 4) assert(sel.bounds.height == 5) end + +-- Comparison +do + local a = Selection() + local b = Selection() + assert(a == b) + + a:select(0, 0, 1, 1) + assert(a ~= b) + + b:add(a) + assert(a == b) + + a:subtract(b) + assert(a ~= b) + + b:subtract(b) + assert(a == b) +end + +-- Operations +do + local a = Selection() + a:select(2, 3, 4, 5) + assert(a.bounds == Rectangle(2, 3, 4, 5)) + + a:subtract(2, 3, 4, 1) + assert(a.bounds == Rectangle(2, 4, 4, 4)) + + assert(a:contains(3, 5)) + a:subtract(3, 5, 1, 1) + assert(not a:contains(3, 5)) + assert(a.bounds == Rectangle(2, 4, 4, 4)) + + local b = Selection() + assert(a.bounds == Rectangle(2, 4, 4, 4)) + assert(b.isEmpty) + a:subtract(b) -- This should be a no-op because b is empty + assert(a.bounds == Rectangle(2, 4, 4, 4)) + + b:select(0, 0, 32, 32) + assert(a ~= b) + b:intersect(a) + assert(a == b) + assert(b.bounds == Rectangle(2, 4, 4, 4)) + assert(b.bounds == Rectangle(2, 4, 4, 4)) +end From a8a4d1f1c42cc2aace08030238873056ad50f589 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 7 Sep 2018 14:50:25 -0300 Subject: [PATCH 022/200] Fix README We are going to use Lua instead of JavaScript --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ea496ca8..4230b2c89 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,4 @@ on Aseprite project to do several automated tests: `.gif`, etc. files [sprites](https://github.com/aseprite/tests/tree/master/sprites) folder. * Test backward compatibility with [Aseprite CLI](https://www.aseprite.org/docs/cli/) options -* Future [scripting API](https://github.com/aseprite/api) using [JS scripts](https://github.com/aseprite/tests/tree/master/scripts) +* Future [scripting API](https://github.com/aseprite/api) using [scripts](https://github.com/aseprite/tests/tree/master/scripts) From 2a9062ee997e7cb2c99d3f7724fb297d63aec8eb Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 7 Sep 2018 18:03:02 -0300 Subject: [PATCH 023/200] Add test for Image:pixels(Rectangle) --- scripts/image_iterator.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/image_iterator.lua b/scripts/image_iterator.lua index f3456a80c..8b9dcd41b 100644 --- a/scripts/image_iterator.lua +++ b/scripts/image_iterator.lua @@ -43,6 +43,21 @@ do c = c+1 end + c = 0 + for it in image:pixels{x=1, y=0, width=1, height=2} do + local i = 1 + it.y*2 + it.x + assert(colors[i] == it()) + assert(xy[i].x == it.x) + assert(xy[i].y == it.y) + c = c + 1 + end + assert(c == 2) + + -- Iterating outside + for it in image:pixels{x=2, y=0, width=2, height=2} do + assert(false) + end + c = 1 for it in image:pixels() do it(pc.rgba(255, 32*c, 0, 255)) From b6c2a43f9e411025c89d6bd6400f88e9f2d23536 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 11 Sep 2018 18:46:35 -0300 Subject: [PATCH 024/200] New tests for layers/frames/cels/tags/slices --- scripts/cels.lua | 37 +++++++++++++++++++++ scripts/frames.lua | 25 ++++++++++++++ scripts/layer.lua | 18 +++++++++++ scripts/layers.lua | 23 +++++++++++++ scripts/palette.lua | 8 ++++- scripts/slice.lua | 24 ++++++++++++++ scripts/slices.lua | 19 +++++++++++ scripts/sprite.lua | 79 +++++++++++++++++++++++++++++++-------------- scripts/tag.lua | 33 +++++++++++++++++++ scripts/tags.lua | 29 +++++++++++++++++ 10 files changed, 270 insertions(+), 25 deletions(-) create mode 100644 scripts/cels.lua create mode 100644 scripts/frames.lua create mode 100644 scripts/layer.lua create mode 100644 scripts/layers.lua create mode 100644 scripts/slice.lua create mode 100644 scripts/slices.lua create mode 100644 scripts/tag.lua create mode 100644 scripts/tags.lua 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 From 2eaf56f359d1749c69f183ff8af0b65e88f2acc6 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 11 Sep 2018 20:32:12 -0300 Subject: [PATCH 025/200] Add ImageSpec tests --- scripts/image_spec.lua | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 scripts/image_spec.lua diff --git a/scripts/image_spec.lua b/scripts/image_spec.lua new file mode 100644 index 000000000..488eb86d6 --- /dev/null +++ b/scripts/image_spec.lua @@ -0,0 +1,46 @@ +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +do + local spec = ImageSpec{colorMode=ColorMode.GRAYSCALE, width=32, height=64, transparentColor=2} + assert(spec.colorMode == ColorMode.GRAYSCALE) + assert(spec.width == 32) + assert(spec.height == 64) + assert(spec.transparentColor == 2) +end + +do + local sprite = Sprite(32, 64, ColorMode.INDEXED) + assert(sprite.width == 32) + assert(sprite.height == 64) + assert(sprite.colorMode == ColorMode.INDEXED) + + local sprite2 = Sprite(sprite.spec) + assert(sprite2.width == 32) + assert(sprite2.height == 64) + assert(sprite2.colorMode == ColorMode.INDEXED) + + local spec = sprite.spec + assert(spec.width == 32) + assert(spec.height == 64) + assert(spec.colorMode == ColorMode.INDEXED) + + spec.width = 30 + spec.height = 40 + spec.colorMode = ColorMode.RGB + assert(spec.width == 30) + assert(spec.height == 40) + assert(spec.colorMode == ColorMode.RGB) + + local image = Image(spec) + assert(image.width == 30) + assert(image.height == 40) + assert(image.colorMode == ColorMode.RGB) + + print(image.spec.width, image.spec.height, image.spec.colorMode) + assert(image.spec.width == 30) + assert(image.spec.height == 40) + assert(image.spec.colorMode == ColorMode.RGB) +end From b14c6fc8310995250fa8a8b27c72a336b60d4a08 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 12 Sep 2018 18:45:23 -0300 Subject: [PATCH 026/200] Test ipairs() --- scripts/cels.lua | 8 +++++++- scripts/frames.lua | 7 +++++++ scripts/layers.lua | 7 +++++++ scripts/slices.lua | 7 +++++++ scripts/tags.lua | 7 +++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/scripts/cels.lua b/scripts/cels.lua index dd91813a0..4fe59a7cd 100644 --- a/scripts/cels.lua +++ b/scripts/cels.lua @@ -30,8 +30,14 @@ do assert(cb[2] == b.cels[2]) assert(cb[3] == b.cels[3]) - s:deleteCel(cb[2]) + local i = 1 + for k,v in ipairs(b.cels) do + assert(i == k) + assert(v == b.cels[k]) + i = i+1 + end + 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 index 62319fac3..6a1f3ef10 100644 --- a/scripts/frames.lua +++ b/scripts/frames.lua @@ -20,6 +20,13 @@ do assert(a.frames[1].duration == 0.1) assert(a.frames[2].duration == 0.2) + local i = 1 + for k,v in ipairs(a.frames) do + assert(i == k) + assert(v == a.frames[k]) + i = i+1 + end + a:deleteFrame(1) assert(a.frames[1].duration == 0.2) end diff --git a/scripts/layers.lua b/scripts/layers.lua index 95a319c71..ca0edc9c5 100644 --- a/scripts/layers.lua +++ b/scripts/layers.lua @@ -16,6 +16,13 @@ do assert(s.layers[2] == b) assert(s.layers[3] == c) + local i = 1 + for k,v in ipairs(s.layers) do + assert(i == k) + assert(v == s.layers[k]) + i = i+1 + end + s:deleteLayer(b) assert(#s.layers == 2) assert(s.layers[1] == a) diff --git a/scripts/slices.lua b/scripts/slices.lua index 7895ae497..d9b0b522c 100644 --- a/scripts/slices.lua +++ b/scripts/slices.lua @@ -13,6 +13,13 @@ do assert(b.bounds == Rectangle(0, 2, 8, 10)) assert(c.bounds == Rectangle(0, 0, 32, 32)) + local i = 1 + for k,v in ipairs(s.slices) do + assert(i == k) + assert(v == s.slices[k]) + i = i+1 + end + s:deleteSlice(b) assert(a == s.slices[1]) assert(c == s.slices[2]) diff --git a/scripts/tags.lua b/scripts/tags.lua index 902ffff65..84d7bfed8 100644 --- a/scripts/tags.lua +++ b/scripts/tags.lua @@ -20,6 +20,13 @@ do assert(b == s.tags[2]) assert(c == s.tags[3]) + local i = 1 + for k,v in ipairs(s.tags) do + assert(i == k) + assert(v == s.tags[k]) + i = i+1 + end + s:deleteTag(b) assert(a == s.tags[1]) assert(c == s.tags[2]) From d3ae1c32c038672a6c158bcda393dbdb2f568d27 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 12 Sep 2018 18:45:35 -0300 Subject: [PATCH 027/200] Test Cel.position property --- scripts/cel.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/cel.lua b/scripts/cel.lua index cdaff30dc..1ff88a800 100644 --- a/scripts/cel.lua +++ b/scripts/cel.lua @@ -13,6 +13,7 @@ assert(c.layer == s.layers[1]) assert(c.frame == 1) assert(c.image) assert(c.bounds == Rectangle(0, 0, 32, 64)) +assert(c.position == Point(0, 0)) assert(c.color == Color()) assert(c.data == "") @@ -20,3 +21,7 @@ c.color = Color{ r=255, g=100, b=20 } c.data = "test" assert(c.color == Color{ r=255, g=100, b=20 }) assert(c.data == "test") + +c.position = Point(2, 4) +assert(c.position == Point(2, 4)) +assert(c.bounds == Rectangle(2, 4, 32, 64)) From 330da974675720700173e18395603b93d3bc44cc Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 12 Sep 2018 18:45:44 -0300 Subject: [PATCH 028/200] Test Sprite.backgroundLayer property --- scripts/app_command.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/app_command.lua b/scripts/app_command.lua index 2a14d0eac..83fcc56ec 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -48,6 +48,7 @@ do -- Background/Transparent layers app.bgColor = Color(32, 64, 128) app.command.BackgroundFromLayer() -- the layer will be filled with app.bgColor assert(s.layers[1].isBackground) + assert(s.layers[1] == s.backgroundLayer) assert(s.cels[1].image:getPixel(0, 0) == app.pixelColor.rgba(32, 64, 128, 255)) app.command.LayerFromBackground() From 4d7f3036d84a4c37bd02ee491447705fcf4a8141 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 3 Nov 2018 13:39:43 -0300 Subject: [PATCH 029/200] Add app_active.lua --- scripts/app_active.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 scripts/app_active.lua diff --git a/scripts/app_active.lua b/scripts/app_active.lua new file mode 100644 index 000000000..6a6a5bb6f --- /dev/null +++ b/scripts/app_active.lua @@ -0,0 +1,15 @@ +-- Copyright (C) 2018 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local s = Sprite(32, 64) +assert(s == app.activeSprite) +assert(s == app.activeCel.sprite) +assert(s == app.activeFrame.sprite) +assert(1 == app.activeFrame.frameNumber) +assert(0.100 == app.activeFrame.duration) -- Default frame duration + +app.command.NewFrame() +assert(2 == app.activeFrame.frameNumber) +assert(0.100 == app.activeFrame.duration) -- Default frame duration From 91e64cd436aae54b5c32b1f105d51a259450bc49 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 7 Nov 2018 16:49:31 -0300 Subject: [PATCH 030/200] Add scripts to test the CLI features I'm going to move my internals CLI tests to this repo in the near future. This is a first version to try the new --ignore-empty --save-as feature. --- cli/help.sh | 7 ++++++ cli/list-layers.sh | 10 +++++++++ cli/list-tags.sh | 5 +++++ cli/save-as.sh | 23 ++++++++++++++++++++ cli/version.sh | 7 ++++++ run-tests.sh | 45 +++++++++++++++++++++++++++++---------- sprites/1empty3.aseprite | Bin 0 -> 1048 bytes sprites/README.md | 4 ++++ sprites/abcd.aseprite | Bin 0 -> 550 bytes 9 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 cli/help.sh create mode 100644 cli/list-layers.sh create mode 100644 cli/list-tags.sh create mode 100644 cli/save-as.sh create mode 100644 cli/version.sh create mode 100644 sprites/1empty3.aseprite create mode 100644 sprites/README.md create mode 100644 sprites/abcd.aseprite diff --git a/cli/help.sh b/cli/help.sh new file mode 100644 index 000000000..0cedb5f24 --- /dev/null +++ b/cli/help.sh @@ -0,0 +1,7 @@ +#! /bin/bash +# Copyright (C) 2018 Igara Studio S.A. + +if ! $ASEPRITE --help | grep "\\-\\-help" > /dev/null ; then + echo "FAILED: --help doesn't include usage information" + exit 1 +fi diff --git a/cli/list-layers.sh b/cli/list-layers.sh new file mode 100644 index 000000000..cd81c1cc9 --- /dev/null +++ b/cli/list-layers.sh @@ -0,0 +1,10 @@ +#! /bin/bash +# Copyright (C) 2018 Igara Studio S.A. + +expect "bg +fg" "$ASEPRITE -b --list-layers sprites/1empty3.aseprite" + +expect "a +b +c +d" "$ASEPRITE -b --list-layers sprites/abcd.aseprite" diff --git a/cli/list-tags.sh b/cli/list-tags.sh new file mode 100644 index 000000000..0c3c5a2c6 --- /dev/null +++ b/cli/list-tags.sh @@ -0,0 +1,5 @@ +#! /bin/bash +# Copyright (C) 2018 Igara Studio S.A. + +expect "a +b" "$ASEPRITE -b --list-tags sprites/1empty3.aseprite" diff --git a/cli/save-as.sh b/cli/save-as.sh new file mode 100644 index 000000000..f3a7f71f8 --- /dev/null +++ b/cli/save-as.sh @@ -0,0 +1,23 @@ +#! /bin/bash +# Copyright (C) 2018 Igara Studio S.A. + +function list_files() { + oldwd=$(pwd) + cd $1 && ls -1 *.* + cd $oldwd +} + +# --save-as + +d=$t/save-as +$ASEPRITE -b sprites/1empty3.aseprite --save-as "$d/image00.png" +expect "image00.png +image01.png +image02.png" "list_files $d" + +# --ignore-empty --save-as + +d=$t/save-as-ignore-empty +$ASEPRITE -b sprites/1empty3.aseprite --ignore-empty --save-as $d/image00.png +expect "image00.png +image02.png" "list_files $d" diff --git a/cli/version.sh b/cli/version.sh new file mode 100644 index 000000000..4e64cd7a0 --- /dev/null +++ b/cli/version.sh @@ -0,0 +1,7 @@ +#! /bin/bash +# Copyright (C) 2018 Igara Studio S.A. + +if ! $ASEPRITE --version | grep "Aseprite 1\\." > /dev/null ; then + echo "FAILED: --version doesn't include 'Aseprite 1.' string" + exit 1 +fi diff --git a/run-tests.sh b/run-tests.sh index 706723ff0..f769552a3 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,4 +1,5 @@ #! /bin/sh +# Copyright (C) 2018 Igara Studio S.A. # Copyright (C) 2018 David Capello if [[ "$ASEPRITE" == "" ]]; then @@ -12,26 +13,40 @@ function fail() { exit 1 } +function expect() { + if [[ $1 != $($2) ]] ; then + echo "FAILED: $2" + echo "EXPECTED: $1" + echo "RESULT: $($2)" + exit 1 + fi +} + echo ---------------------------------------------------------------------- echo $ASEPRITE --version $ASEPRITE --version +echo ---------------------------------------------------------------------- +echo Temp dir +t=$(mktemp -d) +echo $t + echo ---------------------------------------------------------------------- echo "Testing console..." -$ASEPRITE -b --script scripts/console_assert.lua >tmp 2>tmp_err -! grep -q "this should be in the output" tmp && fail "print() text not found in output" -! grep -q "assertion failed" tmp && fail "assert() text not found in output" -grep -q "this should not be in the output" tmp && fail "text that shouldn't be in the output is" +$ASEPRITE -b --script scripts/console_assert.lua >$t/tmp 2>$t/tmp_err +! grep -q "this should be in the output" $t/tmp && fail "print() text not found in output" +! grep -q "assertion failed" $t/tmp && fail "assert() text not found in output" +grep -q "this should not be in the output" $t/tmp && fail "text that shouldn't be in the output is" if [[ "$(uname)" =~ "MINGW32" ]] || [[ "$(uname)" =~ "MSYS_NT-10.0" ]] ; then echo Ignore console tests on Windows else - $ASEPRITE -b --script scripts/console_print.lua >tmp 2>tmp_err - cat >tmp_expected <$t/tmp 2>$t/tmp_err + cat >$t/tmp_expected <tmp 2>tmp_err ; then + if ! $ASEPRITE -b --script $script >$t/tmp 2>$t/tmp_err ; then echo FAILED - echo STDOUT && cat tmp - echo STDERR && cat tmp_err + echo STDOUT && cat $t/tmp + echo STDERR && cat $t/tmp_err result=1 fi done +echo ---------------------------------------------------------------------- +echo "Testing CLI..." + +result=0 +for script in cli/*.sh ; do + echo "Running $script" + source $script +done + echo ---------------------------------------------------------------------- echo Done echo ---------------------------------------------------------------------- diff --git a/sprites/1empty3.aseprite b/sprites/1empty3.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..c28079f683328ac9640b0c7bd88486be85feaedb GIT binary patch literal 1048 zcmcJOYe-XJ7{{M&UUA?pmQ$&-3^4?qqfBW{tn6l>?1MI1G&QGAnmKDu6VozBBCSG_ zv=0d?tsAHxoQ8eK6?PRw2{UOeT|y*Y`e0K${kPDO;K!cB`JHp#b2$IsbKduac@fz< zc*M9j4iTNj?kR>iuEGCSZCoPfyq`PO4=DodzRbqRPZ$+44Ct!ue-9qAL_3(>U|Nh6 zR3|5ZrmTJ7m(pl({Jt8T9c%%Y7ZSm{)0v>=xftBrqy^K9;z4=(PEaCE22)ZlfMV4Z z@Rar|nAggJXWmbNZzonj7Dd$hq!+BKHiAVO4XDVHgZcvv;A4pd9M8@JKVIqwP0h!_ zh7vKWK^IVponai#+BWgp6j}P zF;;XrIMx_xvaB3#?6X?^&5n?W;r9CY#Kz%)sZL)V?V8WHF+QZlw^Y`p7P{j$Ygwh5 z3G7)#oPo>>meEj&@np~Wz6b@sStkE^sMnZj2-c;DSlc2`#>(wSG%eR=tL1|MtwPJM T5U$l}+_HFc(uZuX^soN_vj!&M literal 0 HcmV?d00001 diff --git a/sprites/README.md b/sprites/README.md new file mode 100644 index 000000000..43cdb1598 --- /dev/null +++ b/sprites/README.md @@ -0,0 +1,4 @@ +# Files + +* `abcd.aseprite`: Indexed, 32x32, four layers ("a", "b", "c", "d") +* `1empty3.aseprite`: RGB, 32x32, two layers ("fg", "bg"), 2nd frame completelly empty, two tags ("a", "b") diff --git a/sprites/abcd.aseprite b/sprites/abcd.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..6926af49416e042048075438af440614a5159beb GIT binary patch literal 550 zcmcJLF;2rU7=@o5n;NwPqEI!P1*j5;1qmc3gcuMjJ%N*0;R=kASXp3VV1;{B>Or_d z*DmHcHBgW;@?!h9{QUgcnMmN{O~CRq5CA;;k2FMF{5QSx^yQ-8Qv0Ng*n9Rb@|>%= z)#(;0)$bDMB5+JC#0eUNoJGY~#c0|>tKpo6%{YE3CIpHuqwF%OF2kSkL~SEmBk(t` zq|w9uYvsK6&O20gW~3eMj~})mrWl@Zm*)F-k^Ks7#!v}4F*9}T9O32Cr*+7dDnw$}n0Ex}O*hR06L?ZuIJDg`zQ+ Date: Wed, 7 Nov 2018 16:52:49 -0300 Subject: [PATCH 031/200] Disable some app.activeFrame tests that fails when there is no UI --- scripts/app_active.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/app_active.lua b/scripts/app_active.lua index 6a6a5bb6f..5c6de9ca9 100644 --- a/scripts/app_active.lua +++ b/scripts/app_active.lua @@ -10,6 +10,7 @@ assert(s == app.activeFrame.sprite) assert(1 == app.activeFrame.frameNumber) assert(0.100 == app.activeFrame.duration) -- Default frame duration -app.command.NewFrame() -assert(2 == app.activeFrame.frameNumber) -assert(0.100 == app.activeFrame.duration) -- Default frame duration +-- TODO fix these tests when there is no UI +--app.command.NewFrame() +--assert(2 == app.activeFrame.frameNumber) +--assert(0.100 == app.activeFrame.duration) -- Default frame duration From c1ca1aeda6514863762e0521aa9927932303ffa4 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 12 Nov 2018 19:32:00 -0300 Subject: [PATCH 032/200] Tests for Image:drawSprite() (previously know as Image:putSprite) --- scripts/drawing.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 scripts/drawing.lua diff --git a/scripts/drawing.lua b/scripts/drawing.lua new file mode 100644 index 000000000..21eddf327 --- /dev/null +++ b/scripts/drawing.lua @@ -0,0 +1,36 @@ +-- Copyright (C) 2018 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local pc = app.pixelColor + +-- drawSprite +do + local spr = Sprite(4, 4) + local cel = spr.cels[1] + cel.image:putPixel(0, 0, pc.rgba(255, 0, 0, 255)) + cel.image:putPixel(1, 0, pc.rgba(0, 255, 0, 255)) + cel.image:putPixel(0, 1, pc.rgba(0, 0, 255, 255)) + cel.image:putPixel(1, 1, pc.rgba(255, 255, 0, 255)) + + local r = Image(spr.spec) -- render + r:drawSprite(spr, 1, 0, 0) + + assert(r:getPixel(0, 0) == pc.rgba(255, 0, 0, 255)) + assert(r:getPixel(1, 0) == pc.rgba(0, 255, 0, 255)) + assert(r:getPixel(0, 1) == pc.rgba(0, 0, 255, 255)) + assert(r:getPixel(1, 1) == pc.rgba(255, 255, 0, 255)) + + r = Image(3, 3, spr.colorMode) + r:drawSprite(spr, 1, Point{x=1, y=1}) + assert(r:getPixel(0, 0) == pc.rgba(0, 0, 0, 0)) + assert(r:getPixel(1, 0) == pc.rgba(0, 0, 0, 0)) + assert(r:getPixel(2, 0) == pc.rgba(0, 0, 0, 0)) + assert(r:getPixel(0, 1) == pc.rgba(0, 0, 0, 0)) + assert(r:getPixel(1, 1) == pc.rgba(255, 0, 0, 255)) + assert(r:getPixel(2, 1) == pc.rgba(0, 255, 0, 255)) + assert(r:getPixel(0, 2) == pc.rgba(0, 0, 0, 0)) + assert(r:getPixel(1, 2) == pc.rgba(0, 0, 255, 255)) + assert(r:getPixel(2, 2) == pc.rgba(255, 255, 0, 255)) +end From 8e66b83319f4d359a340d33e3edd2901617f4161 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 13 Nov 2018 20:30:56 -0300 Subject: [PATCH 033/200] Add test for Image:clear() --- scripts/drawing.lua | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/scripts/drawing.lua b/scripts/drawing.lua index 21eddf327..6ab0a6514 100644 --- a/scripts/drawing.lua +++ b/scripts/drawing.lua @@ -5,7 +5,33 @@ local pc = app.pixelColor --- drawSprite +-- Image:clear +local function test_clear(colorMode) + local i = Image(2, 2, colorMode) + i:putPixel(0, 0, 1) + i:putPixel(1, 0, 2) + i:putPixel(0, 1, 3) + i:putPixel(1, 1, 4) + assert(1 == i:getPixel(0, 0)) + assert(2 == i:getPixel(1, 0)) + assert(3 == i:getPixel(0, 1)) + assert(4 == i:getPixel(1, 1)) + i:clear(5) + assert(5 == i:getPixel(0, 0)) + assert(5 == i:getPixel(1, 0)) + assert(5 == i:getPixel(0, 1)) + assert(5 == i:getPixel(1, 1)) + i:clear() -- Image:clear() clears with 0 by default + assert(0 == i:getPixel(0, 0)) + assert(0 == i:getPixel(1, 0)) + assert(0 == i:getPixel(0, 1)) + assert(0 == i:getPixel(1, 1)) +end +test_clear(ColorMode.RGB) +test_clear(ColorMode.GRAYSCALE) +test_clear(ColorMode.INDEXED) + +-- Image:drawSprite do local spr = Sprite(4, 4) local cel = spr.cels[1] From f643a939984888a25530858f0b3f94d43fa33f3d Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 13 Nov 2018 21:38:55 -0300 Subject: [PATCH 034/200] Use ColorMode.GRAY instead of ColorMode.GRAYSCALE --- scripts/image_spec.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/image_spec.lua b/scripts/image_spec.lua index 488eb86d6..0b8258187 100644 --- a/scripts/image_spec.lua +++ b/scripts/image_spec.lua @@ -1,11 +1,12 @@ +-- Copyright (C) 2018 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. do - local spec = ImageSpec{colorMode=ColorMode.GRAYSCALE, width=32, height=64, transparentColor=2} - assert(spec.colorMode == ColorMode.GRAYSCALE) + local spec = ImageSpec{colorMode=ColorMode.GRAY, width=32, height=64, transparentColor=2} + assert(spec.colorMode == ColorMode.GRAY) assert(spec.width == 32) assert(spec.height == 64) assert(spec.transparentColor == 2) From eeb2149c17a34016d8338b1c842c30c8b763fdcf Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 13 Nov 2018 21:39:10 -0300 Subject: [PATCH 035/200] Test Image:clear() without arguments (should use the transparent color) --- scripts/drawing.lua | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/drawing.lua b/scripts/drawing.lua index 6ab0a6514..44d22f8d4 100644 --- a/scripts/drawing.lua +++ b/scripts/drawing.lua @@ -6,8 +6,8 @@ local pc = app.pixelColor -- Image:clear -local function test_clear(colorMode) - local i = Image(2, 2, colorMode) +local function test_clear(colorMode, transparentColor) + local i = Image(ImageSpec{ width=2, height=2, colorMode=colorMode, transparentColor=transparentColor }) i:putPixel(0, 0, 1) i:putPixel(1, 0, 2) i:putPixel(0, 1, 3) @@ -21,15 +21,20 @@ local function test_clear(colorMode) assert(5 == i:getPixel(1, 0)) assert(5 == i:getPixel(0, 1)) assert(5 == i:getPixel(1, 1)) - i:clear() -- Image:clear() clears with 0 by default - assert(0 == i:getPixel(0, 0)) - assert(0 == i:getPixel(1, 0)) - assert(0 == i:getPixel(0, 1)) - assert(0 == i:getPixel(1, 1)) + + print("transparentColor = ", transparentColor) + assert(transparentColor == i.spec.transparentColor) + + i:clear() -- Image:clear() clears with i.spec.transparentColor by default + assert(transparentColor == i:getPixel(0, 0)) + assert(transparentColor == i:getPixel(1, 0)) + assert(transparentColor == i:getPixel(0, 1)) + assert(transparentColor == i:getPixel(1, 1)) end -test_clear(ColorMode.RGB) -test_clear(ColorMode.GRAYSCALE) -test_clear(ColorMode.INDEXED) +test_clear(ColorMode.RGB, 0) +test_clear(ColorMode.GRAYSCALE, 0) +test_clear(ColorMode.INDEXED, 0) +test_clear(ColorMode.INDEXED, 255) -- Image:drawSprite do From 01c9605a8c521727076303a2a700e6a17e0c19f6 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 14 Nov 2018 16:53:11 -0300 Subject: [PATCH 036/200] Test Sprite.bounds --- scripts/sprite.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/sprite.lua b/scripts/sprite.lua index 2474fcd48..e245cedc4 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -8,6 +8,7 @@ do assert(a.width == 32) assert(a.height == 64) assert(a.colorMode == ColorMode.RGB) -- RGB by default + assert(a.bounds == Rectangle{x=0, y=0, width=32, height=64}) -- Crop and resize a.selection:select(2, 3, 4, 5) From bd521ec45f9f4472aa1a039e61e4d167231be617 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 14 Nov 2018 16:53:24 -0300 Subject: [PATCH 037/200] Test Rectangle:contains/union/intersect(s) functions --- scripts/rectangle.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/rectangle.lua b/scripts/rectangle.lua index c25e9a5ce..e8b35bf4b 100644 --- a/scripts/rectangle.lua +++ b/scripts/rectangle.lua @@ -37,3 +37,25 @@ assert(rc.x == 2) assert(rc.y == 3) assert(rc.width == 4) assert(rc.height == 5) + +-- Rectangle:contains + +local a = Rectangle{x=2, y=3, width=4, height=5} +local b = Rectangle{x=3, y=4, width=1, height=1} +assert(a:contains(b)) +assert(not b:contains(a)) + +-- Rectangle:intersect + +assert(a:intersects(b)) +assert(b == a:intersect(b)) + +a = Rectangle{x=2, y=3, width=4, height=5} +b = Rectangle{x=3, y=4, width=4, height=5} +c = Rectangle{x=3, y=4, width=3, height=4} +assert(c == a:intersect(b)) +assert(c == b:intersect(a)) + +-- Rectangle:union + +assert(Rectangle{x=2, y=3, width=5, height=6} == a:union(b)) From 567115dbc36e5fae0061ace8fef5993256f6e444 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 22 Nov 2018 14:45:26 -0300 Subject: [PATCH 038/200] Add some app.site tests --- scripts/app_active.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/app_active.lua b/scripts/app_active.lua index 5c6de9ca9..c2ff33614 100644 --- a/scripts/app_active.lua +++ b/scripts/app_active.lua @@ -5,10 +5,15 @@ local s = Sprite(32, 64) assert(s == app.activeSprite) +assert(s == app.site.sprite) assert(s == app.activeCel.sprite) +assert(s == app.site.cel.sprite) assert(s == app.activeFrame.sprite) +assert(s == app.site.frame.sprite) assert(1 == app.activeFrame.frameNumber) +assert(1 == app.site.frame.frameNumber) assert(0.100 == app.activeFrame.duration) -- Default frame duration +assert(0.100 == app.site.frame.duration) -- TODO fix these tests when there is no UI --app.command.NewFrame() From 6d687cddab2d9e0e8a6100399b21bb93bce02a0f Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 22 Nov 2018 15:05:03 -0300 Subject: [PATCH 039/200] Add app.site.frameNumber --- scripts/app_active.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/app_active.lua b/scripts/app_active.lua index c2ff33614..174e10182 100644 --- a/scripts/app_active.lua +++ b/scripts/app_active.lua @@ -12,6 +12,7 @@ assert(s == app.activeFrame.sprite) assert(s == app.site.frame.sprite) assert(1 == app.activeFrame.frameNumber) assert(1 == app.site.frame.frameNumber) +assert(1 == app.site.frameNumber) assert(0.100 == app.activeFrame.duration) -- Default frame duration assert(0.100 == app.site.frame.duration) From 3ee484e5eb643dd0c8bf689589278e221e9e5333 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 27 Nov 2018 15:06:20 -0300 Subject: [PATCH 040/200] Test Cel.frame/frameNumber properties correctly --- scripts/cel.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/cel.lua b/scripts/cel.lua index 1ff88a800..c7ee77905 100644 --- a/scripts/cel.lua +++ b/scripts/cel.lua @@ -10,7 +10,9 @@ assert(#s.cels == 1) local c = s.cels[1] assert(c.sprite == s) assert(c.layer == s.layers[1]) -assert(c.frame == 1) +assert(c.frame == s.frames[1]) +assert(c.frame.frameNumber == 1) +assert(c.frameNumber == 1) assert(c.image) assert(c.bounds == Rectangle(0, 0, 32, 64)) assert(c.position == Point(0, 0)) From 71a02b537aaa35dac11488cd173722b3bb3be180 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 4 Dec 2018 17:58:03 -0300 Subject: [PATCH 041/200] Update tests for tags --- scripts/tag.lua | 8 ++++---- scripts/tags.lua | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/tag.lua b/scripts/tag.lua index a866166d5..465c5f52c 100644 --- a/scripts/tag.lua +++ b/scripts/tag.lua @@ -10,14 +10,14 @@ do a = s:newTag(1, 8) assert(a.sprite == s) - assert(a.fromFrame == 1) - assert(a.toFrame == 8) + assert(a.fromFrame.frameNumber == 1) + assert(a.toFrame.frameNumber == 8) assert(a.frames == 8) a.fromFrame = 2 a.toFrame = 5 - assert(a.fromFrame == 2) - assert(a.toFrame == 5) + assert(a.fromFrame.frameNumber == 2) + assert(a.toFrame.frameNumber == 5) assert(a.name == "Tag") a.name = "Tag A" diff --git a/scripts/tags.lua b/scripts/tags.lua index 84d7bfed8..edfef359c 100644 --- a/scripts/tags.lua +++ b/scripts/tags.lua @@ -31,6 +31,6 @@ do assert(a == s.tags[1]) assert(c == s.tags[2]) - assert(c.fromFrame == 5) - assert(c.toFrame == 8) + assert(c.fromFrame.frameNumber == 5) + assert(c.toFrame.frameNumber == 8) end From 812ce9320a09f1607de7bb0e01eba12ed51c01a7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 6 Dec 2018 13:00:56 -0300 Subject: [PATCH 042/200] Don't reset $result variable for CLI tests after script tests --- run-tests.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index f769552a3..6fc4d0cb5 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -67,14 +67,17 @@ done echo ---------------------------------------------------------------------- echo "Testing CLI..." -result=0 for script in cli/*.sh ; do echo "Running $script" source $script done echo ---------------------------------------------------------------------- -echo Done +if [ $result == 0 ] ; then + echo Done +else + echo FAILED +fi echo ---------------------------------------------------------------------- exit $result From 76ce890ab6dc18b597076e66a72b45ee958d8566 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 6 Dec 2018 13:01:16 -0300 Subject: [PATCH 043/200] Update tests for Sprite:new(Empty)/deleteFrame() functions --- scripts/frames.lua | 75 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/scripts/frames.lua b/scripts/frames.lua index 6a1f3ef10..b33a668d6 100644 --- a/scripts/frames.lua +++ b/scripts/frames.lua @@ -1,3 +1,4 @@ +-- Copyright (C) 2018 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -8,17 +9,37 @@ do assert(#a.frames == 1) assert(a.frames[1].frameNumber == 1) assert(a.frames[1].duration == 0.1) + a.frames[1].duration = 0.2 + assert(a.frames[1].duration == 0.2) + assert(a.layers[1]:cel(1) ~= nil) - local fr = a:newFrame() + -- Sprite:newEmptyFrame() + local fr0 = a:newEmptyFrame() + assert(fr0.frameNumber == 2) -- returned the second frame 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) + assert(a.frames[1].duration == 0.2) + assert(a.frames[2].duration == 0.2) -- the duration is copied + assert(a.layers[1]:cel(1) ~= nil) + assert(a.layers[1]:cel(fr0) == nil) -- no cel + assert(fr0 == a.frames[2]) + a:deleteFrame(fr0) + assert(#a.frames == 1) - fr.duration = 0.2 - assert(a.frames[1].duration == 0.1) + -- Sprite:newFrame() without arguments + local fr = a:newFrame() + assert(fr.frameNumber == 2) -- returned the second frame + assert(#a.frames == 2) + assert(a.frames[1].frameNumber == 1) + assert(a.frames[2].frameNumber == 2) + assert(a.frames[1].duration == 0.2) assert(a.frames[2].duration == 0.2) + assert(fr == a.frames[2]) + + fr.duration = 0.3 + assert(a.frames[1].duration == 0.2) + assert(a.frames[2].duration == 0.3) local i = 1 for k,v in ipairs(a.frames) do @@ -28,5 +49,47 @@ do end a:deleteFrame(1) - assert(a.frames[1].duration == 0.2) + assert(#a.frames == 1) + assert(a.frames[1].duration == 0.3) + + -- TODO This is a big issue, if we add/delete frames, we don't + -- update frame objects, they are still pointing to the same frame + -- number, which could lead to confusion. + assert(fr.frameNumber == 2) + fr.duration = 1 -- This is a do nothing operation + + -- Sprite:newEmptyFrame(n) + local fr2 = a:newEmptyFrame(1) + assert(#a.frames == 2) + assert(fr2.frameNumber == 1) -- returned the first frame + print(a.frames[1].duration) + assert(a.frames[1].duration == 0.3) -- the duration is copied from the frame + assert(a.frames[2].duration == 0.3) + assert(fr2 == a.frames[1]) + assert(a.layers[1]:cel(1) == nil) + assert(a.layers[1]:cel(2) ~= nil) + + -- Sprite:newFrame(n) + local fr3 = a:newFrame(2) + assert(#a.frames == 3) + assert(fr3.frameNumber == 2) -- returned the second frame + assert(a.frames[1].duration == 0.3) + assert(a.frames[2].duration == 0.3) -- copied duration from old frame 2 + assert(a.frames[3].duration == 0.3) + local cel1 = a.layers[1]:cel(1) + local cel2 = a.layers[1]:cel(2) + local cel3 = a.layers[1]:cel(3) + assert(cel1 == nil) + assert(cel2 ~= nil) + assert(cel3 ~= nil) + print(cel2.image.spec.colorMode) + print(cel2.image.spec.width) + print(cel2.image.spec.height) + print(cel3.image.spec.colorMode) + print(cel3.image.spec.width) + print(cel3.image.spec.height) + assert(cel2.image.spec == cel3.image.spec) + assert(fr3.previous == a.frames[1]) + assert(fr3 == a.frames[2]) + assert(fr3.next == a.frames[3]) end From 7e53c296e2c09a23ecf99121b024c9189f6b1a42 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 20 Dec 2018 11:30:40 -0300 Subject: [PATCH 044/200] Add more -save-as tests --- cli/save-as.sh | 139 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 137 insertions(+), 2 deletions(-) diff --git a/cli/save-as.sh b/cli/save-as.sh index f3a7f71f8..2e915a110 100644 --- a/cli/save-as.sh +++ b/cli/save-as.sh @@ -10,7 +10,7 @@ function list_files() { # --save-as d=$t/save-as -$ASEPRITE -b sprites/1empty3.aseprite --save-as "$d/image00.png" +$ASEPRITE -b sprites/1empty3.aseprite --save-as "$d/image00.png" || exit 1 expect "image00.png image01.png image02.png" "list_files $d" @@ -18,6 +18,141 @@ image02.png" "list_files $d" # --ignore-empty --save-as d=$t/save-as-ignore-empty -$ASEPRITE -b sprites/1empty3.aseprite --ignore-empty --save-as $d/image00.png +$ASEPRITE -b sprites/1empty3.aseprite --ignore-empty --save-as $d/image00.png || exit 1 expect "image00.png image02.png" "list_files $d" + +# --split-layers --save-as + +d=$t/save-as-split-layers +$ASEPRITE -b sprites/1empty3.aseprite --split-layers --save-as $d/layer.png || exit 1 +expect "layer (bg) 0.png +layer (bg) 1.png +layer (bg) 2.png +layer (fg) 0.png +layer (fg) 1.png +layer (fg) 2.png" "list_files $d" + +# --save-as {layer} + +d=$t/save-as-layer +mkdir $d # TODO why do we need this? +$ASEPRITE -b sprites/1empty3.aseprite --save-as $d/layer-{layer}.gif || exit 1 +expect "layer-bg.gif +layer-fg.gif" "list_files $d" + +# --save-as frame8-test.png + +d=$t/save-as-frame8-test +$ASEPRITE -b sprites/1empty3.aseprite --save-as "$d/frame8-test.png" || exit 1 +expect "frame8-test1.png +frame8-test2.png +frame8-test3.png" "list_files $d" + +# --save-as frame-0.png + +d=$t/save-as-frame-0 +$ASEPRITE -b sprites/1empty3.aseprite --save-as "$d/frame-0.png" || exit 1 +expect "frame-0.png +frame-1.png +frame-2.png" "list_files $d" + +# --save-as frame-00.png + +d=$t/save-as-frame-00 +$ASEPRITE -b sprites/1empty3.aseprite --save-as "$d/frame-00.png" || exit 1 +expect "frame-00.png +frame-01.png +frame-02.png" "list_files $d" + +# --save-as frame-001.png + +d=$t/save-as-frame-001 +$ASEPRITE -b sprites/1empty3.aseprite --save-as "$d/frame-001.png" || exit 1 +expect "frame-001.png +frame-002.png +frame-003.png" "list_files $d" + +# --save-as frame-0032.png + +d=$t/save-as-frame-0032 +$ASEPRITE -b sprites/1empty3.aseprite --save-as "$d/frame-0032.png" || exit 1 +expect "frame-0032.png +frame-0033.png +frame-0034.png" "list_files $d" + +# --trim --save-as + +d=$t/save-as-trim +$ASEPRITE -b --trim sprites/1empty3.aseprite --save-as "$d/trim-000.png" || exit 1 +expect "trim-000.png +trim-001.png +trim-002.png" "list_files $d" +cat >$d/compare.lua <$d/compare.lua < Date: Thu, 20 Dec 2018 13:32:31 -0300 Subject: [PATCH 045/200] Add regression test for aseprite/aseprite#591 --- cli/save-as.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cli/save-as.sh b/cli/save-as.sh index 2e915a110..82a6017a7 100644 --- a/cli/save-as.sh +++ b/cli/save-as.sh @@ -156,3 +156,21 @@ for f = 1,3 do end EOF $ASEPRITE -b -script "$d/compare.lua" || exit 1 + +# --save-as without path +# https://github.com/aseprite/aseprite/issues/591 + +d=$t/save-as-without-path +mkdir $d +open $d +oldwd=$(pwd) +cd $d +$ASEPRITE -b -split-layers $oldwd/sprites/abcd.aseprite -save-as issue591.png || exit 1 +if [[ ! -f "issue591 (a).png" || + ! -f "issue591 (b).png" || + ! -f "issue591 (c).png" || + ! -f "issue591 (d).png" ]]; then + echo "FAIL: Regression detected (issue 591)" + exit 1 +fi +cd $oldwd From 72109b99bbd16c8d17350f029a5d3ee2753b418c Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 20 Dec 2018 14:02:50 -0300 Subject: [PATCH 046/200] Remove call to open command (which was only for local testing purposes) --- cli/save-as.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/save-as.sh b/cli/save-as.sh index 82a6017a7..0393c571d 100644 --- a/cli/save-as.sh +++ b/cli/save-as.sh @@ -162,7 +162,6 @@ $ASEPRITE -b -script "$d/compare.lua" || exit 1 d=$t/save-as-without-path mkdir $d -open $d oldwd=$(pwd) cd $d $ASEPRITE -b -split-layers $oldwd/sprites/abcd.aseprite -save-as issue591.png || exit 1 From 3e23e6382444cc802ce5b222dc051769dfc16577 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 20 Dec 2018 14:23:00 -0300 Subject: [PATCH 047/200] Add support to filter tests to run in run-tests.sh --- run-tests.sh | 72 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index 6fc4d0cb5..bf1874422 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -22,54 +22,72 @@ function expect() { fi } +# General information echo ---------------------------------------------------------------------- echo $ASEPRITE --version $ASEPRITE --version -echo ---------------------------------------------------------------------- -echo Temp dir +filter="$*" +if [[ "$filter" != "" ]]; then + echo Filter: $filter +fi + t=$(mktemp -d) -echo $t +echo Temp dir: $t -echo ---------------------------------------------------------------------- -echo "Testing console..." -$ASEPRITE -b --script scripts/console_assert.lua >$t/tmp 2>$t/tmp_err -! grep -q "this should be in the output" $t/tmp && fail "print() text not found in output" -! grep -q "assertion failed" $t/tmp && fail "assert() text not found in output" -grep -q "this should not be in the output" $t/tmp && fail "text that shouldn't be in the output is" +if [[ "$filter" == "" ]] || [[ "console" =~ $filter ]]; then + echo ---------------------------------------------------------------------- + echo "Testing console..." -if [[ "$(uname)" =~ "MINGW32" ]] || [[ "$(uname)" =~ "MSYS_NT-10.0" ]] ; then - echo Ignore console tests on Windows -else - $ASEPRITE -b --script scripts/console_print.lua >$t/tmp 2>$t/tmp_err - cat >$t/tmp_expected <$t/tmp 2>$t/tmp_err + ! grep -q "this should be in the output" $t/tmp && fail "print() text not found in output" + ! grep -q "assertion failed" $t/tmp && fail "assert() text not found in output" + grep -q "this should not be in the output" $t/tmp && fail "text that shouldn't be in the output is" + + if [[ "$(uname)" =~ "MINGW32" ]] || [[ "$(uname)" =~ "MSYS_NT-10.0" ]] ; then + echo Ignore console tests on Windows + else + $ASEPRITE -b --script scripts/console_print.lua >$t/tmp 2>$t/tmp_err + cat >$t/tmp_expected <$t/tmp 2>$t/tmp_err ; then - echo FAILED - echo STDOUT && cat $t/tmp - echo STDERR && cat $t/tmp_err - result=1 + echo FAILED + echo STDOUT && cat $t/tmp + echo STDERR && cat $t/tmp_err + result=1 fi done -echo ---------------------------------------------------------------------- -echo "Testing CLI..." - +first=0 for script in cli/*.sh ; do - echo "Running $script" - source $script + if [[ "$filter" == "" ]] || [[ $script =~ $filter ]]; then + if [ $first == 0 ]; then + echo ---------------------------------------------------------------------- + echo "Testing CLI..." + first=1 + fi + echo "Running $script" + source $script + fi done echo ---------------------------------------------------------------------- From c6d3e0c9488f8b9b4e306a9c7e4f40deacc9f8c5 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 3 Jan 2019 13:51:30 -0300 Subject: [PATCH 048/200] Test default ColorSpace of new sprites --- LICENSE.txt | 1 + scripts/color_space.lua | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 scripts/color_space.lua diff --git a/LICENSE.txt b/LICENSE.txt index 72e289daa..aee5744c4 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,3 +1,4 @@ +Copyright (c) 2018-2019 Igara Studio S.A. Copyright (c) 2018 David Capello Permission is hereby granted, free of charge, to any person obtaining diff --git a/scripts/color_space.lua b/scripts/color_space.lua new file mode 100644 index 000000000..0b89d10d0 --- /dev/null +++ b/scripts/color_space.lua @@ -0,0 +1,8 @@ +-- Copyright (C) 2019 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local spr = Sprite(32, 32) +local cs = spr.spec.colorSpace +assert(cs.name == "sRGB") -- Default color profile From 3e98c69e7665cfd05d345ab0c93ff06aeb0a93f7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 3 Jan 2019 13:52:13 -0300 Subject: [PATCH 049/200] Test __eq of ColorSpace --- scripts/color_space.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/color_space.lua b/scripts/color_space.lua index 0b89d10d0..f1d5bc95c 100644 --- a/scripts/color_space.lua +++ b/scripts/color_space.lua @@ -6,3 +6,7 @@ local spr = Sprite(32, 32) local cs = spr.spec.colorSpace assert(cs.name == "sRGB") -- Default color profile + +local spr2 = Sprite(32, 32) +local cs2 = spr.spec.colorSpace +assert(cs == cs2) From 1baca9c85ec598c00663e0a14d7d848eb2acfadc Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 3 Jan 2019 15:32:45 -0300 Subject: [PATCH 050/200] Add new ColorSpace{ sRGB } --- scripts/color_space.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/color_space.lua b/scripts/color_space.lua index f1d5bc95c..a48b60bc1 100644 --- a/scripts/color_space.lua +++ b/scripts/color_space.lua @@ -3,10 +3,18 @@ -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. -local spr = Sprite(32, 32) -local cs = spr.spec.colorSpace -assert(cs.name == "sRGB") -- Default color profile +local none = ColorSpace() -- None +local srgb = ColorSpace{ sRGB } +assert(none ~= srgb) -local spr2 = Sprite(32, 32) +local spr = Sprite(32, 32) +local cs1 = spr.colorSpace local cs2 = spr.spec.colorSpace -assert(cs == cs2) +assert(cs1.name == "sRGB") -- Default color profile: sRGB +assert(cs1 == cs2) +assert(cs1 ~= none) +assert(cs1 == srgb) + +local spr3 = Sprite(32, 32) +local cs3 = spr.spec.colorSpace +assert(cs1 == cs3) From 05e6dd9b2473ea99a2e8697b4a9bbfd60790d4a8 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 3 Jan 2019 17:25:11 -0300 Subject: [PATCH 051/200] Add some examples about how to run the tests --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 4230b2c89..5f0582a0f 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,20 @@ on Aseprite project to do several automated tests: folder. * Test backward compatibility with [Aseprite CLI](https://www.aseprite.org/docs/cli/) options * Future [scripting API](https://github.com/aseprite/api) using [scripts](https://github.com/aseprite/tests/tree/master/scripts) + +## How to run tests? + +You have to set the `ASEPRITE` environment variable pointing to the +Aseprite executable and then run `run-tests.sh` from Bash: + + export ASEPRITE=$HOME/your-aseprite-build/bin/aseprite + git clone https://github.com/aseprite/tests.git + cd tests + bash run-tests.sh + +You can filter some tests with a regex giving a parameter to +`run-tests.sh`, for example: + + run-tests.sh color + +Should run all tests which have the `color` word in their name. From 6b432ea268cabc692e6d867817199f74c175f416 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 3 Jan 2019 19:37:51 -0300 Subject: [PATCH 052/200] Remove assert for the color profile name --- scripts/color_space.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/color_space.lua b/scripts/color_space.lua index a48b60bc1..9107430c6 100644 --- a/scripts/color_space.lua +++ b/scripts/color_space.lua @@ -10,10 +10,9 @@ assert(none ~= srgb) local spr = Sprite(32, 32) local cs1 = spr.colorSpace local cs2 = spr.spec.colorSpace -assert(cs1.name == "sRGB") -- Default color profile: sRGB assert(cs1 == cs2) assert(cs1 ~= none) -assert(cs1 == srgb) +assert(cs1 == srgb) -- Default color profile: sRGB local spr3 = Sprite(32, 32) local cs3 = spr.spec.colorSpace From 4b331f781ae9c5d1d22d548eb81e8fae90a82063 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 6 Jan 2019 18:24:17 -0300 Subject: [PATCH 053/200] Add app.command.PaletteSize --- scripts/app_command.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/app_command.lua b/scripts/app_command.lua index 83fcc56ec..19958711f 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -97,3 +97,12 @@ do -- Cel Opacity app.undo() assert(c.opacity == 255) end + +do -- PaletteSize + local s = Sprite(32, 32) + assert(#s.palettes[1] == 256) + app.command.PaletteSize{ size=32 } + assert(#s.palettes[1] == 32) + app.command.PaletteSize{ size=8 } + assert(#s.palettes[1] == 8) +end From 4d735ed757677abe228018af3af19b2b9fbf3571 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 6 Jan 2019 19:01:59 -0300 Subject: [PATCH 054/200] Add app.command.CanvasSize --- scripts/app_command.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/app_command.lua b/scripts/app_command.lua index 19958711f..6013f8d0f 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -106,3 +106,12 @@ do -- PaletteSize app.command.PaletteSize{ size=8 } assert(#s.palettes[1] == 8) end + +do -- CanvasSize + local s = Sprite(32, 32) + assert(s.bounds == Rectangle(0, 0, 32, 32)) + app.command.CanvasSize{ left=2 } + assert(s.bounds == Rectangle(0, 0, 34, 32)) + app.command.CanvasSize{ top=2, right=4, bottom=8 } + assert(s.bounds == Rectangle(0, 0, 38, 42)) +end From e958403e27571e4479ff180ce9524ef87ad97a84 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 9 Jan 2019 20:43:49 -0300 Subject: [PATCH 055/200] Add some tests for --sheet --- .gitmodules | 3 ++ cli/sheet.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ third_party/json | 1 + 3 files changed, 91 insertions(+) create mode 100644 .gitmodules create mode 100644 cli/sheet.sh create mode 160000 third_party/json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..c55277e57 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "third_party/json"] + path = third_party/json + url = https://github.com/rxi/json.lua diff --git a/cli/sheet.sh b/cli/sheet.sh new file mode 100644 index 000000000..37e494627 --- /dev/null +++ b/cli/sheet.sh @@ -0,0 +1,87 @@ +#! /bin/bash +# Copyright (C) 2019 Igara Studio S.A. + +# $1 = first sprite sheet json file +# $2 = second sprite sheet json file +function compare_sheet_data() { + cat $1 | grep -v "\"image\"" > $1-tmp + cat $2 | grep -v "\"image\"" > $2-tmp + diff -u $1-tmp $2-tmp +} + +# --sheet and STDOUT + +d=$t/sheet +mkdir $d # we need to create the directory because the >STDOUT redirection +if ! $ASEPRITE -b sprites/1empty3.aseprite --sheet "$d/sheet.png" > "$d/stdout.json" ; then + exit 1 +fi +cat >$d/compare.lua <$d/compare.lua <$d/create.lua <$d/compare.lua < Date: Wed, 9 Jan 2019 21:14:01 -0300 Subject: [PATCH 056/200] Add test for --sheet --data with --split-layers --- cli/sheet.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cli/sheet.sh b/cli/sheet.sh index 37e494627..3d8697b67 100644 --- a/cli/sheet.sh +++ b/cli/sheet.sh @@ -85,3 +85,39 @@ end assert(expected:isEqual(sheet.cels[1].image)) EOF $ASEPRITE -b -script "$d/compare.lua" || exit 1 + +# --split-layers --sheet --data + +d=$t/split-layers-sheet-data +$ASEPRITE -b --split-layers sprites/1empty3.aseprite \ + --filename-format "{layer}-{frame}" \ + --sheet "$d/sheet.png" \ + --data "$d/sheet.json" || exit 1 +open $d +cat >$d/compare.lua < Date: Thu, 10 Jan 2019 07:16:21 -0300 Subject: [PATCH 057/200] Remove calls to macOS open utility --- cli/sheet.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/sheet.sh b/cli/sheet.sh index 3d8697b67..33b79f77d 100644 --- a/cli/sheet.sh +++ b/cli/sheet.sh @@ -73,7 +73,6 @@ EOF $ASEPRITE -b -script "$d/create.lua" || exit 1 compare_sheet_data "$d/sheet1.json" "$d/sheet2.json" || exit 1 cmp "$d/sheet1.png" "$d/sheet2.png" || exit 1 -open $d cat >$d/compare.lua <$d/compare.lua < Date: Fri, 15 Feb 2019 17:20:18 -0300 Subject: [PATCH 058/200] Add Selection.origin setter --- scripts/selection.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/selection.lua b/scripts/selection.lua index 529a6e6b8..2b0cd8249 100644 --- a/scripts/selection.lua +++ b/scripts/selection.lua @@ -40,6 +40,12 @@ do -- Constructor with rectangles local b = Selection(1, 2, 3, 4) assert(b.bounds == Rectangle(1, 2, 3, 4)) + assert(b.origin == Point(1, 2)) + + -- Move + b.origin = Point(5, 6) + assert(b.bounds == Rectangle(5, 6, 3, 4)) + assert(b.origin == Point(5, 6)) end -- Sprite Selection @@ -62,6 +68,9 @@ do assert(sel.bounds.y == 3) assert(sel.bounds.width == 4) assert(sel.bounds.height == 5) + + sel.origin = Point(5, 6) + assert(sel.bounds == Rectangle(5, 6, 4, 5)) end -- Comparison From 0df118e4054daf495fb8c79ee0422f41d600bb09 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 15 Mar 2019 17:04:19 -0300 Subject: [PATCH 059/200] Add some app.drawWithTool() basic tests --- scripts/tools.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 scripts/tools.lua diff --git a/scripts/tools.lua b/scripts/tools.lua new file mode 100644 index 000000000..a727f1522 --- /dev/null +++ b/scripts/tools.lua @@ -0,0 +1,20 @@ +-- Copyright (C) 2019 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local spr = Sprite(4, 4) +local cel = spr.cels[1] +assert(cel.bounds == Rectangle(0, 0, 4, 4)) + +app.drawWithTool{ + tool='pencil', + color=Color{ r=0, g=0, b=0 }, + points={ Point(2, 2), + Point(3, 2) }} +assert(cel.bounds == Rectangle(2, 2, 2, 1)) + +app.drawWithTool{ + tool='eraser', + points={ Point(2, 2) }} +assert(cel.bounds == Rectangle(3, 2, 1, 1)) From 0dbe0bdffb0d4d9d8ea979b73b837f14e47b6b5e Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 16 Mar 2019 13:15:51 -0300 Subject: [PATCH 060/200] Rename app.drawWithTool() -> app.toolStroke() --- scripts/tools.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tools.lua b/scripts/tools.lua index a727f1522..a2e32c8f8 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -7,14 +7,14 @@ local spr = Sprite(4, 4) local cel = spr.cels[1] assert(cel.bounds == Rectangle(0, 0, 4, 4)) -app.drawWithTool{ +app.toolStroke{ tool='pencil', color=Color{ r=0, g=0, b=0 }, points={ Point(2, 2), Point(3, 2) }} assert(cel.bounds == Rectangle(2, 2, 2, 1)) -app.drawWithTool{ +app.toolStroke{ tool='eraser', points={ Point(2, 2) }} assert(cel.bounds == Rectangle(3, 2, 1, 1)) From 771d5f8a85d4cd0adc5d5d56f1b72044111934a6 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 18 Mar 2019 22:33:53 -0300 Subject: [PATCH 061/200] Add some extra tool tests --- scripts/tools.lua | 120 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/scripts/tools.lua b/scripts/tools.lua index a2e32c8f8..1bee81db4 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -7,6 +7,10 @@ local spr = Sprite(4, 4) local cel = spr.cels[1] assert(cel.bounds == Rectangle(0, 0, 4, 4)) +---------------------------------------------------------------------- +-- pencil and eraser +---------------------------------------------------------------------- + app.toolStroke{ tool='pencil', color=Color{ r=0, g=0, b=0 }, @@ -18,3 +22,119 @@ app.toolStroke{ tool='eraser', points={ Point(2, 2) }} assert(cel.bounds == Rectangle(3, 2, 1, 1)) + +app.toolStroke{ + tool='eraser', + points={ Point(3, 2) }} +-- This must fail because cel is pointing to an invalid cel now. +-- TODO: In a future this could change if this issue: +-- https://github.com/aseprite/aseprite/issues/1833 +-- is implemented. +assert(not pcall(function() print(cel.bounds) end)) + +---------------------------------------------------------------------- +-- line +---------------------------------------------------------------------- + +local red = Color{ r=255, g=0, b=0 } +app.toolStroke{ + tool='line', + color=red, + points={ Point(0, 0), Point(3, 3) }} +local cel = spr.cels[1] +assert(cel.bounds == Rectangle(0, 0, 4, 4)) +do + local r = app.pixelColor.rgba(red.red, red.green, red.blue) + local expected = { r, 0, 0, 0, + 0, r, 0, 0, + 0, 0, r, 0, + 0, 0, 0, r } + assert(cel.image.width == 4) + assert(cel.image.height == 4) + for v=0,3 do + for u=0,3 do + print(u, v, cel.image:getPixel(u, v), expected[1+v*4+u]) + assert(cel.image:getPixel(u, v) == expected[1+v*4+u]) + end + end +end + +---------------------------------------------------------------------- +-- paint_bucket +---------------------------------------------------------------------- + +app.toolStroke{ + tool='paint_bucket', + color=red, + points={ Point(3, 0) }} +local cel = spr.cels[1] +do + local r = app.pixelColor.rgba(red.red, red.green, red.blue) + local expected = { r, r, r, r, + 0, r, r, r, + 0, 0, r, r, + 0, 0, 0, r } + assert(cel.image.width == 4) + assert(cel.image.height == 4) + for v=0,3 do + for u=0,3 do + print(u, v, cel.image:getPixel(u, v), expected[1+v*4+u]) + assert(cel.image:getPixel(u, v) == expected[1+v*4+u]) + end + end +end + +---------------------------------------------------------------------- +-- rectangle +---------------------------------------------------------------------- + +local blue = Color{ r=0, g=0, b=255 } +app.toolStroke{ + tool='rectangle', + color=blue, + points={ Point(0, 0), Point(3, 3) }} +local cel = spr.cels[1] +do + local r = app.pixelColor.rgba(red.red, red.green, red.blue) + local b = app.pixelColor.rgba(blue.red, blue.green, blue.blue) + local expected = { b, b, b, b, + b, r, r, b, + b, 0, r, b, + b, b, b, b } + assert(cel.image.width == 4) + assert(cel.image.height == 4) + for v=0,3 do + for u=0,3 do + print(u, v, cel.image:getPixel(u, v), expected[1+v*4+u]) + assert(cel.image:getPixel(u, v) == expected[1+v*4+u]) + end + end +end + +---------------------------------------------------------------------- +-- ellipse +---------------------------------------------------------------------- + +local yellow = Color{ r=255, g=255, b=0 } +app.toolStroke{ + tool='ellipse', + color=yellow, + points={ Point(0, 0), Point(3, 3) }} +local cel = spr.cels[1] +do + local r = app.pixelColor.rgba(red.red, red.green, red.blue) + local b = app.pixelColor.rgba(blue.red, blue.green, blue.blue) + local y = app.pixelColor.rgba(yellow.red, yellow.green, yellow.blue) + local expected = { b, y, y, b, + y, r, r, y, + y, 0, r, y, + b, y, y, b } + assert(cel.image.width == 4) + assert(cel.image.height == 4) + for v=0,3 do + for u=0,3 do + print(u, v, cel.image:getPixel(u, v), expected[1+v*4+u]) + assert(cel.image:getPixel(u, v) == expected[1+v*4+u]) + end + end +end From 8e378c4e457137594874e2b678a38c4a496c5c81 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 23 Mar 2019 09:19:34 -0300 Subject: [PATCH 062/200] Add tests for app.activeTool --- scripts/tools.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/tools.lua b/scripts/tools.lua index 1bee81db4..d14b12bcc 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -3,6 +3,22 @@ -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. +---------------------------------------------------------------------- +-- activeTool +---------------------------------------------------------------------- + +local pencil = app.activeTool -- pencil is the default tool +assert(pencil ~= nil) +assert(pencil.id == 'pencil') +app.activeTool = 'line' +assert(app.activeTool.id == 'line') +app.activeTool = pencil +assert(app.activeTool.id == 'pencil') + +---------------------------------------------------------------------- +-- create sprite for testing +---------------------------------------------------------------------- + local spr = Sprite(4, 4) local cel = spr.cels[1] assert(cel.bounds == Rectangle(0, 0, 4, 4)) From aa4b9d91f3280826a5a832daaba7ffa7da2be9bb Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 23 Mar 2019 13:53:44 -0300 Subject: [PATCH 063/200] Rename app.toolStroke() -> app.useTool() --- scripts/tools.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/tools.lua b/scripts/tools.lua index d14b12bcc..642bb9b49 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -27,19 +27,19 @@ assert(cel.bounds == Rectangle(0, 0, 4, 4)) -- pencil and eraser ---------------------------------------------------------------------- -app.toolStroke{ +app.useTool{ tool='pencil', color=Color{ r=0, g=0, b=0 }, points={ Point(2, 2), Point(3, 2) }} assert(cel.bounds == Rectangle(2, 2, 2, 1)) -app.toolStroke{ +app.useTool{ tool='eraser', points={ Point(2, 2) }} assert(cel.bounds == Rectangle(3, 2, 1, 1)) -app.toolStroke{ +app.useTool{ tool='eraser', points={ Point(3, 2) }} -- This must fail because cel is pointing to an invalid cel now. @@ -53,7 +53,7 @@ assert(not pcall(function() print(cel.bounds) end)) ---------------------------------------------------------------------- local red = Color{ r=255, g=0, b=0 } -app.toolStroke{ +app.useTool{ tool='line', color=red, points={ Point(0, 0), Point(3, 3) }} @@ -79,7 +79,7 @@ end -- paint_bucket ---------------------------------------------------------------------- -app.toolStroke{ +app.useTool{ tool='paint_bucket', color=red, points={ Point(3, 0) }} @@ -105,7 +105,7 @@ end ---------------------------------------------------------------------- local blue = Color{ r=0, g=0, b=255 } -app.toolStroke{ +app.useTool{ tool='rectangle', color=blue, points={ Point(0, 0), Point(3, 3) }} @@ -132,7 +132,7 @@ end ---------------------------------------------------------------------- local yellow = Color{ r=255, g=255, b=0 } -app.toolStroke{ +app.useTool{ tool='ellipse', color=yellow, points={ Point(0, 0), Point(3, 3) }} From d16f42e1c921325966a9abbb17379cd96448ad26 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 23 Mar 2019 16:35:36 -0300 Subject: [PATCH 064/200] Use the new Color.rgbaPixel property --- scripts/color.lua | 3 +++ scripts/tools.lua | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/color.lua b/scripts/color.lua index 30108c788..f71eee379 100644 --- a/scripts/color.lua +++ b/scripts/color.lua @@ -26,6 +26,9 @@ assert(a.green == 100) assert(a.blue == 20) assert(a.alpha == 200) assert(a == b) +print(a.rgbaPixel) +print(app.pixelColor.rgba(200, 100, 20, 200)) +assert(a.rgbaPixel == app.pixelColor.rgba(200, 100, 20, 200)) a = Color{ h=180, s=0.4, v=0.5, a=200 } b = Color{ hue=180, saturation=0.4, value=0.5, alpha=200 } diff --git a/scripts/tools.lua b/scripts/tools.lua index 642bb9b49..e775ab92b 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -60,7 +60,7 @@ app.useTool{ local cel = spr.cels[1] assert(cel.bounds == Rectangle(0, 0, 4, 4)) do - local r = app.pixelColor.rgba(red.red, red.green, red.blue) + local r = red.rgbaPixel local expected = { r, 0, 0, 0, 0, r, 0, 0, 0, 0, r, 0, @@ -85,7 +85,7 @@ app.useTool{ points={ Point(3, 0) }} local cel = spr.cels[1] do - local r = app.pixelColor.rgba(red.red, red.green, red.blue) + local r = red.rgbaPixel local expected = { r, r, r, r, 0, r, r, r, 0, 0, r, r, @@ -111,8 +111,8 @@ app.useTool{ points={ Point(0, 0), Point(3, 3) }} local cel = spr.cels[1] do - local r = app.pixelColor.rgba(red.red, red.green, red.blue) - local b = app.pixelColor.rgba(blue.red, blue.green, blue.blue) + local r = red.rgbaPixel + local b = blue.rgbaPixel local expected = { b, b, b, b, b, r, r, b, b, 0, r, b, @@ -138,9 +138,9 @@ app.useTool{ points={ Point(0, 0), Point(3, 3) }} local cel = spr.cels[1] do - local r = app.pixelColor.rgba(red.red, red.green, red.blue) - local b = app.pixelColor.rgba(blue.red, blue.green, blue.blue) - local y = app.pixelColor.rgba(yellow.red, yellow.green, yellow.blue) + local r = red.rgbaPixel + local b = blue.rgbaPixel + local y = yellow.rgbaPixel local expected = { b, y, y, b, y, r, r, y, y, 0, r, y, From a32a0485c7ec8d0e95ebe6045fdc264083b13a9b Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 23 Mar 2019 16:35:56 -0300 Subject: [PATCH 065/200] Test app.useTool() with "cel" argument --- scripts/tools.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/scripts/tools.lua b/scripts/tools.lua index e775ab92b..7b4b4eef6 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -154,3 +154,41 @@ do end end end + +---------------------------------------------------------------------- +-- draw in several cels +---------------------------------------------------------------------- + +do + local spr2 = Sprite(4, 4) + spr2:newFrame() + + local bgLay = spr2.layers[1] + local fgLay = spr2:newLayer() + local bgCel1 = spr2:newCel(fgLay, 1, Image(spr2.spec)) + local fgCel1 = spr2:newCel(bgLay, 1, Image(spr2.spec)) + local bgCel2 = spr2:newCel(fgLay, 2, Image(spr2.spec)) + local fgCel2 = spr2:newCel(bgLay, 2, Image(spr2.spec)) + assert(fgCel1.bounds == Rectangle(0, 0, 4, 4)) + assert(bgCel1.bounds == Rectangle(0, 0, 4, 4)) + assert(fgCel2.bounds == Rectangle(0, 0, 4, 4)) + assert(bgCel2.bounds == Rectangle(0, 0, 4, 4)) + + -- After each useTool(), the cels will be shrunken to the minimum + -- required size. + app.activeTool = 'pencil' + app.useTool{ color=red, cel=bgCel1, points={ Point(0, 0) }} + app.useTool{ color=red, cel=bgCel2, points={ Point(1, 0) }} + app.useTool{ color=yellow, cel=fgCel1, points={ Point(1, 1) }} + app.useTool{ color=yellow, cel=fgCel2, points={ Point(2, 1) }} + + assert(bgCel1.bounds == Rectangle(0, 0, 1, 1)) + assert(bgCel2.bounds == Rectangle(1, 0, 1, 1)) + assert(fgCel1.bounds == Rectangle(1, 1, 1, 1)) + assert(fgCel2.bounds == Rectangle(2, 1, 1, 1)) + + assert(bgCel1.image:getPixel(0, 0) == red.rgbaPixel) + assert(bgCel2.image:getPixel(0, 0) == red.rgbaPixel) + assert(fgCel1.image:getPixel(0, 0) == yellow.rgbaPixel) + assert(fgCel2.image:getPixel(0, 0) == yellow.rgbaPixel) +end From 7a1cd9dad78e8b80dad92c63001a010f13565d72 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 29 Mar 2019 15:54:50 -0300 Subject: [PATCH 066/200] Test Point/Size/Rectangle tostring --- scripts/point.lua | 1 + scripts/rectangle.lua | 1 + scripts/size.lua | 1 + 3 files changed, 3 insertions(+) diff --git a/scripts/point.lua b/scripts/point.lua index 793a3aa09..1a447ab77 100644 --- a/scripts/point.lua +++ b/scripts/point.lua @@ -10,6 +10,7 @@ assert(pt.y == 0) pt = Point(1, 2) assert(pt.x == 1) assert(pt.y == 2) +assert("Point{ x=1, y=2 }" == tostring(pt)) local pt2 = Point(pt) assert(pt2.x == 1) diff --git a/scripts/rectangle.lua b/scripts/rectangle.lua index e8b35bf4b..74fcefe51 100644 --- a/scripts/rectangle.lua +++ b/scripts/rectangle.lua @@ -16,6 +16,7 @@ assert(rc.y == 2) assert(rc.width == 3) assert(rc.height == 4) assert(not rc.isEmpty) +assert("Rectangle{ x=1, y=2, width=3, height=4 }" == tostring(rc)) local rc2 = Rectangle(rc) assert(rc2.x == 1) diff --git a/scripts/size.lua b/scripts/size.lua index 58acb0ae7..f3b448ea8 100644 --- a/scripts/size.lua +++ b/scripts/size.lua @@ -10,6 +10,7 @@ assert(sz.height == 0) sz = Size(3, 4) assert(sz.width == 3) assert(sz.height == 4) +assert("Size{ width=3, height=4 }" == tostring(sz)) local sz2 = Size(sz) assert(sz2.width == 3) From b750a926472b96564cc72bdcc711a36a250d169b Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 29 Mar 2019 15:55:45 -0300 Subject: [PATCH 067/200] Test Image:isEmpty() and Image:isPlain() --- scripts/image.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/image.lua b/scripts/image.lua index ccf7ed68f..7f3d21dbc 100644 --- a/scripts/image.lua +++ b/scripts/image.lua @@ -9,6 +9,9 @@ local a = Image(32, 64) assert(a.width == 32) assert(a.height == 64) assert(a.colorMode == ColorMode.RGB) -- RGB by default +assert(a:isEmpty()) +assert(a:isPlain(pc.rgba(0, 0, 0, 0))) +assert(a:isPlain(0)) do local b = Image(32, 64, ColorMode.INDEXED) @@ -24,6 +27,7 @@ do a:putPixel(x, y, pc.rgba(x, y, x+y, x-y)) end end + assert(not a:isEmpty()) end -- Clone From bef770c2b322febf3cccb0a80d30ee26a90036f6 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 13 Apr 2019 16:30:58 -0300 Subject: [PATCH 068/200] Update some tests with the new app.activeFrame/Layer behavior --- scripts/app_active.lua | 17 ++++++++++------- scripts/app_command.lua | 6 ++++++ scripts/tools.lua | 11 +++++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/scripts/app_active.lua b/scripts/app_active.lua index 174e10182..c01eb15d9 100644 --- a/scripts/app_active.lua +++ b/scripts/app_active.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2018 Igara Studio S.A. +-- Copyright (C) 2018-2019 Igara Studio S.A. -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. @@ -6,8 +6,6 @@ local s = Sprite(32, 64) assert(s == app.activeSprite) assert(s == app.site.sprite) -assert(s == app.activeCel.sprite) -assert(s == app.site.cel.sprite) assert(s == app.activeFrame.sprite) assert(s == app.site.frame.sprite) assert(1 == app.activeFrame.frameNumber) @@ -15,8 +13,13 @@ assert(1 == app.site.frame.frameNumber) assert(1 == app.site.frameNumber) assert(0.100 == app.activeFrame.duration) -- Default frame duration assert(0.100 == app.site.frame.duration) +assert(s == app.activeLayer.sprite) +assert(s == app.site.layer.sprite) +assert(s == app.activeCel.sprite) +assert(s == app.site.cel.sprite) --- TODO fix these tests when there is no UI ---app.command.NewFrame() ---assert(2 == app.activeFrame.frameNumber) ---assert(0.100 == app.activeFrame.duration) -- Default frame duration +app.activeFrame.duration = 0.8 + +app.command.NewFrame() +assert(2 == app.activeFrame.frameNumber) +assert(0.8 == app.activeFrame.duration) -- Copy frame duration of previous frame diff --git a/scripts/app_command.lua b/scripts/app_command.lua index 6013f8d0f..3cb51064d 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -1,3 +1,4 @@ +-- Copyright (C) 2019 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -26,17 +27,22 @@ do -- NewLayer/RemoveLayer assert(#s.layers == 1) local lay = s.layers[1] app.command.NewLayer{top=true} + local lay2 = app.activeLayer assert(#s.layers == 2) assert(s.layers[2].isImage) app.command.NewLayer{top=true, group=true} + local lay3 = app.activeLayer assert(#s.layers == 3) assert(s.layers[3].isGroup) + assert(app.activeLayer == lay3) app.command.RemoveLayer() + assert(app.activeLayer == lay2) assert(#s.layers == 2) app.command.RemoveLayer() + assert(app.activeLayer == lay) assert(#s.layers == 1) end diff --git a/scripts/tools.lua b/scripts/tools.lua index 7b4b4eef6..6415909b1 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -178,8 +178,15 @@ do -- required size. app.activeTool = 'pencil' app.useTool{ color=red, cel=bgCel1, points={ Point(0, 0) }} - app.useTool{ color=red, cel=bgCel2, points={ Point(1, 0) }} - app.useTool{ color=yellow, cel=fgCel1, points={ Point(1, 1) }} + app.useTool{ color=red, layer=bgCel2.layer, frame=bgCel2.frame, points={ Point(1, 0) }} + + -- After using the tool in bgCel2, the activeFrame is the frame + -- number 2. + assert(bgCel2.frame == app.activeFrame) + assert(bgCel2.frame == fgCel2.frame) + + app.activeFrame = fgCel1.frame + app.useTool{ color=yellow, layer=fgCel1.layer, points={ Point(1, 1) }} app.useTool{ color=yellow, cel=fgCel2, points={ Point(2, 1) }} assert(bgCel1.bounds == Rectangle(0, 0, 1, 1)) From de9f8beed9b1baaf95626a7ff7aeac9257161376 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 13 Apr 2019 17:19:11 -0300 Subject: [PATCH 069/200] Add a test for https://community.aseprite.org/t/2894 --- scripts/merge_down_bugs.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scripts/merge_down_bugs.lua diff --git a/scripts/merge_down_bugs.lua b/scripts/merge_down_bugs.lua new file mode 100644 index 000000000..a98cfdb97 --- /dev/null +++ b/scripts/merge_down_bugs.lua @@ -0,0 +1,27 @@ +-- Copyright (C) 2019 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local red = Color{ r=255, g=0, b=0 } +local blue = Color{ r=0, g=0, b=255 } + +-- Reproduces the bug reported in https://community.aseprite.org/t/2894 +do + local s = Sprite(32, 32) + local a = s.layers[1] + app.useTool{ color=red, layer=a, points={ Point(2, 2) }} + + local b = s:newLayer() + app.useTool{ color=blue, layer=b, points={ Point(1, 1) }} + + a.isContinuous = true + b.isContinuous = true + + app.command.NewFrame() + app.activeLayer = b + app.command.MergeDownLayer() + + assert(#s.cels == 2) + assert(s.cels[1].image:isEqual(s.cels[2].image)) +end From ea4f6ce957101147f333753eb6b38d04cde5dc98 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 17 Apr 2019 15:04:25 -0300 Subject: [PATCH 070/200] Add Sprite:flatten() --- scripts/sprite.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/sprite.lua b/scripts/sprite.lua index e245cedc4..6b470feeb 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -62,3 +62,15 @@ do assert(a.palettes[1]:getColor(1) == Color(0, 255, 0)) assert(a.palettes[1]:getColor(2) == Color(0, 0, 255)) end + +-- Flatten + +do + local a = Sprite(32, 32) + a:newLayer() + a:newLayer() + assert(#a.layers == 3) + + a:flatten() + assert(#a.layers == 1) +end From 585ffc91a4d968066e89c3fc3299ac9f16a8d472 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 18 Apr 2019 00:16:54 -0300 Subject: [PATCH 071/200] New tests to load/save Sprite/Image/Palette --- scripts/image.lua | 103 ++++++++++++++++++++++++++++---------------- scripts/palette.lua | 60 ++++++++++++++++++-------- scripts/sprite.lua | 23 ++++++++-- 3 files changed, 127 insertions(+), 59 deletions(-) diff --git a/scripts/image.lua b/scripts/image.lua index 7f3d21dbc..bd246f5d5 100644 --- a/scripts/image.lua +++ b/scripts/image.lua @@ -1,65 +1,94 @@ +-- Copyright (C) 2019 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. -local pc = app.pixelColor +local rgba = app.pixelColor.rgba local a = Image(32, 64) assert(a.width == 32) assert(a.height == 64) assert(a.colorMode == ColorMode.RGB) -- RGB by default assert(a:isEmpty()) -assert(a:isPlain(pc.rgba(0, 0, 0, 0))) +assert(a:isPlain(rgba(0, 0, 0, 0))) assert(a:isPlain(0)) do - local b = Image(32, 64, ColorMode.INDEXED) - assert(b.width == 32) - assert(b.height == 64) - assert(b.colorMode == ColorMode.INDEXED) + local b = Image(32, 64, ColorMode.INDEXED) + assert(b.width == 32) + assert(b.height == 64) + assert(b.colorMode == ColorMode.INDEXED) + + local c = Image{ width=32, height=64, colorMode=ColorMode.INDEXED } + assert(c.width == 32) + assert(c.height == 64) + assert(c.colorMode == ColorMode.INDEXED) end -- Get/put RGBA pixels do - for y=0,a.height-1 do - for x=0,a.width-1 do - a:putPixel(x, y, pc.rgba(x, y, x+y, x-y)) - end - end - assert(not a:isEmpty()) + for y=0,a.height-1 do + for x=0,a.width-1 do + a:putPixel(x, y, rgba(x, y, x+y, x-y)) + end + end + assert(not a:isEmpty()) end -- Clone do - local c = a:clone() - assert(c.width == 32) - assert(c.height == 64) - assert(c.colorMode == ColorMode.RGB) + local c = Image(a) + local d = a:clone() + assert(c.width == 32) + assert(c.height == 64) + assert(c.colorMode == ColorMode.RGB) + assert(c.width == d.width) + assert(c.height == d.height) + assert(c.colorMode == d.colorMode) - -- Get RGB pixels - for y=0,c.height-1 do - for x=0,c.width-1 do - assert(c:getPixel(x, y) == pc.rgba(x, y, x+y, x-y)) - end - end + -- Get RGB pixels + for y=0,c.height-1 do + for x=0,c.width-1 do + local expectedColor = rgba(x, y, x+y, x-y) + assert(c:getPixel(x, y) == expectedColor) + assert(d:getPixel(x, y) == expectedColor) + end + end end -- Patch do - local spr = Sprite(256, 256) - local image = app.site.image - local copy = image:clone() - assert(image:getPixel(0, 0) == 0) - for y=0,copy.height-1 do - for x=0,copy.width-1 do - copy:putPixel(x, y, pc.rgba(255-x, 255-y, 0, 255)) - end - end - image:putImage(copy) - assert(image:getPixel(0, 0) == pc.rgba(255, 255, 0, 255)) - assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 255)) - app.undo() - assert(image:getPixel(0, 0) == pc.rgba(0, 0, 0, 0)) - assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 0)) + local spr = Sprite(256, 256) + local image = app.site.image + local copy = image:clone() + assert(image:getPixel(0, 0) == 0) + for y=0,copy.height-1 do + for x=0,copy.width-1 do + copy:putPixel(x, y, rgba(255-x, 255-y, 0, 255)) + end + end + image:putImage(copy) + assert(image:getPixel(0, 0) == rgba(255, 255, 0, 255)) + assert(image:getPixel(255, 255) == rgba(0, 0, 0, 255)) + app.undo() + assert(image:getPixel(0, 0) == rgba(0, 0, 0, 0)) + assert(image:getPixel(255, 255) == rgba(0, 0, 0, 0)) +end + +-- Load/Save +do + local a = Image{ fromFile="sprites/1empty3.aseprite" } + assert(a.width == 32) + assert(a.height == 32) + a:saveAs("_test_oneframe.png") + + local b = Image{ fromFile="_test_oneframe.png" } + assert(b.width == 32) + assert(b.height == 32) + for y=0,a.height-1 do + for x=0,a.width-1 do + assert(a:getPixel(x, y) == b:getPixel(x, y)) + end + end end diff --git a/scripts/palette.lua b/scripts/palette.lua index 1c715a9ec..51ce874b2 100644 --- a/scripts/palette.lua +++ b/scripts/palette.lua @@ -1,27 +1,51 @@ +-- Copyright (C) 2019 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. -local p = Palette() -assert(#p == 256) -for i = 0,#p-1 do - assert(p:getColor(i) == Color(0, 0, 0)) +do + local p = Palette() + assert(#p == 256) + for i = 0,#p-1 do + assert(p:getColor(i) == Color(0, 0, 0)) + end end -p = Palette(32) -assert(#p == 32) -for i = 0,#p-1 do - assert(p:getColor(i) == Color(0, 0, 0)) +do + local p = Palette(32) + assert(#p == 32) + for i = 0,#p-1 do + assert(p:getColor(i) == Color(0, 0, 0)) + end + + p:resize(4) + assert(#p == 4) + p:setColor(0, Color(255, 8, 32)) + p:setColor(1, Color(250, 4, 30)) + p:setColor(2, Color(240, 3, 20)) + p:setColor(3, Color(210, 2, 10)) + assert(p:getColor(0) == Color(255, 8, 32)) + assert(p:getColor(1) == Color(250, 4, 30)) + assert(p:getColor(2) == Color(240, 3, 20)) + assert(p:getColor(3) == Color(210, 2, 10)) end -p:resize(4) -assert(#p == 4) -p:setColor(0, Color(255, 8, 32)) -p:setColor(1, Color(250, 4, 30)) -p:setColor(2, Color(240, 3, 20)) -p:setColor(3, Color(210, 2, 10)) -assert(p:getColor(0) == Color(255, 8, 32)) -assert(p:getColor(1) == Color(250, 4, 30)) -assert(p:getColor(2) == Color(240, 3, 20)) -assert(p:getColor(3) == Color(210, 2, 10)) +-- Load/save +do + local p = Palette{ fromFile="sprites/abcd.aseprite" } + assert(#p == 5) + assert(p:getColor(0) == Color(0, 0, 0)) + assert(p:getColor(1) == Color(25, 0, 255)) + assert(p:getColor(2) == Color(255, 0, 0)) + assert(p:getColor(3) == Color(255, 255, 0)) + assert(p:getColor(4) == Color(0, 128, 0)) + + p:saveAs("_test_.gpl") + + local q = Palette{ fromFile="_test_.gpl" } + assert(#p == #q) + for i=0,#q-1 do + assert(p:getColor(i) == q:getColor(i)) + end +end diff --git a/scripts/sprite.lua b/scripts/sprite.lua index 6b470feeb..d275e511a 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -1,3 +1,4 @@ +-- Copyright (C) 2019 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -28,10 +29,22 @@ do assert(a.width == 8) assert(a.height == 10) - local b = Sprite(4, 4, ColorMode.INDEXED) + -- Test other Sprite() constructors + local b = Sprite(4, 8, ColorMode.INDEXED) assert(b.width == 4) - assert(b.height == 4) + assert(b.height == 8) assert(b.colorMode == ColorMode.INDEXED) + + local c = Sprite{ colorMode=ColorMode.INDEXED, width=10, height=20 } + assert(c.width == 10) + assert(c.height == 20) + assert(c.colorMode == ColorMode.INDEXED) + + local d = Sprite{ fromFile="sprites/abcd.aseprite" } + assert(#d.layers == 4) + assert(d.width == 32) + assert(d.height == 32) + assert(d.colorMode == ColorMode.INDEXED) end -- Transparent color @@ -63,7 +76,7 @@ do assert(a.palettes[1]:getColor(2) == Color(0, 0, 255)) end --- Flatten +-- Duplicate & Flatten do local a = Sprite(32, 32) @@ -71,6 +84,8 @@ do a:newLayer() assert(#a.layers == 3) - a:flatten() + local b = Sprite(a) -- Clone a + a:flatten() -- Flatten a assert(#a.layers == 1) + assert(#b.layers == 3) end From b16a07abc73a368513f82da2f675bcee8df6cfba Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 18 Apr 2019 22:34:27 -0300 Subject: [PATCH 072/200] Add tests for brushes --- scripts/brush.lua | 69 ++++++++++++++++++++++++++++++++++++++ scripts/test_utils.lua | 29 ++++++++++++++++ scripts/tools.lua | 75 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 scripts/brush.lua create mode 100644 scripts/test_utils.lua diff --git a/scripts/brush.lua b/scripts/brush.lua new file mode 100644 index 000000000..9f581d407 --- /dev/null +++ b/scripts/brush.lua @@ -0,0 +1,69 @@ +-- Copyright (C) 2019 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +dofile('./test_utils.lua') + +do + local b = Brush() + assert(b.type == BrushType.CIRCLE) + assert(b.size == 1) + assert(b.angle == 0) + assert(b.center == Point{ x=0, y=0 }) + assert(b.pattern == BrushPattern.NONE) + assert(b.patternOrigin == Point{ x=0, y=0 }) + + local c = Brush(4) + assert(c.type == BrushType.CIRCLE) + assert(c.size == 4) + assert(c.center == Point{ x=2, y=2 }) +end + +do + local b = Brush{ type=BrushType.SQUARE, size=4 } + assert(b.type == BrushType.SQUARE) + assert(b.size == 4) + assert(b.angle == 0) +end + +do + local b = Brush{ type=BrushType.LINE, size=5, angle=90 } + assert(b.type == BrushType.LINE) + assert(b.size == 5) + assert(b.angle == 90) +end + +do + local b = Brush{ type=BrushType.IMAGE, image=Image(4, 8) } + local c = Brush{ image=Image(4, 8) } + assert(b.type == BrushType.IMAGE) + assert(c.type == BrushType.IMAGE) + assert(b.image.width == 4) + assert(b.image.height == 8) + assert(b.pattern == BrushPattern.NONE) + assert(b.patternOrigin.x == 0) + assert(b.patternOrigin.y == 0) +end + +do + local rgba = app.pixelColor.rgba + local r = rgba(255, 0, 0) + local g = rgba(0, 128, 0) + local b = rgba(0, 0, 255) + + local img = Image(2, 2) + img:putPixel(0, 0, r) + img:putPixel(1, 0, b) + img:putPixel(0, 1, b) + img:putPixel(1, 1, r) + + local brush = Brush{ image=img } + expect_img(brush.image, { r, b, b, r }) + + brush:setFgColor(g) + expect_img(brush.image, { r, g, g, r }) + + brush:setBgColor(b) + expect_img(brush.image, { b, g, g, b }) +end diff --git a/scripts/test_utils.lua b/scripts/test_utils.lua new file mode 100644 index 000000000..6551e5165 --- /dev/null +++ b/scripts/test_utils.lua @@ -0,0 +1,29 @@ +-- Copyright (C) 2019 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +function expect_eq(a, b) + if a ~= b then + print(debug.traceback()) + print('Expected A == B but:') + print(' - Value A = ' .. tostring(a)) + print(' - Value B = ' .. tostring(b)) + assert(a == b) + end +end + +function expect_img(image, expectedPixels) + local w = image.width + local h = image.height + for y=0,h-1 do + for x=0,w-1 do + local value = image:getPixel(x, y) + local expected = expectedPixels[1+y*w+x] + if value ~= expected then + print('In pixel (' .. x .. ', ' .. y .. '):') + expect_eq(value, expected) + end + end + end +end diff --git a/scripts/tools.lua b/scripts/tools.lua index 6415909b1..4586b9895 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -3,6 +3,8 @@ -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. +dofile('./test_utils.lua') + ---------------------------------------------------------------------- -- activeTool ---------------------------------------------------------------------- @@ -15,6 +17,11 @@ assert(app.activeTool.id == 'line') app.activeTool = pencil assert(app.activeTool.id == 'pencil') +-- default brush is a circle of 1x1 when there is no UI +assert(app.activeBrush.type == BrushType.CIRCLE) +assert(app.activeBrush.size == 1) +assert(app.activeBrush.angle == 0) + ---------------------------------------------------------------------- -- create sprite for testing ---------------------------------------------------------------------- @@ -69,7 +76,6 @@ do assert(cel.image.height == 4) for v=0,3 do for u=0,3 do - print(u, v, cel.image:getPixel(u, v), expected[1+v*4+u]) assert(cel.image:getPixel(u, v) == expected[1+v*4+u]) end end @@ -94,7 +100,6 @@ do assert(cel.image.height == 4) for v=0,3 do for u=0,3 do - print(u, v, cel.image:getPixel(u, v), expected[1+v*4+u]) assert(cel.image:getPixel(u, v) == expected[1+v*4+u]) end end @@ -121,7 +126,6 @@ do assert(cel.image.height == 4) for v=0,3 do for u=0,3 do - print(u, v, cel.image:getPixel(u, v), expected[1+v*4+u]) assert(cel.image:getPixel(u, v) == expected[1+v*4+u]) end end @@ -149,7 +153,6 @@ do assert(cel.image.height == 4) for v=0,3 do for u=0,3 do - print(u, v, cel.image:getPixel(u, v), expected[1+v*4+u]) assert(cel.image:getPixel(u, v) == expected[1+v*4+u]) end end @@ -199,3 +202,67 @@ do assert(fgCel1.image:getPixel(0, 0) == yellow.rgbaPixel) assert(fgCel2.image:getPixel(0, 0) == yellow.rgbaPixel) end + +---------------------------------------------------------------------- +-- draw with brushes +---------------------------------------------------------------------- + +do + local expectedImages = { + { 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0 }, + { 0, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0 }, + { 0, 0, 0, 0, + 0, 2, 2, 0, + 0, 2, 2, 0, + 0, 0, 0, 0 }, + { 3, 3, 3, 0, + 3, 3, 3, 3, + 3, 3, 3, 3, + 0, 3, 3, 3 } + } + + local s = Sprite(4, 4, ColorMode.INDEXED) + assert(s == app.activeSprite) + assert(s.cels[1] == app.activeCel) + + function expect_cel_is_image(imageIndex) + local a = Image(s.spec) + a:drawSprite(s, 1, Point(0, 0)) + local b = expectedImages[imageIndex] + expect_img(a, b) + end + + expect_cel_is_image(1) + app.useTool{ tool='pencil', color=1, points={ Point(1, 1) } } + assert(#s.cels == 1) + expect_cel_is_image(2) + app.undo() + + expect_cel_is_image(1) + app.useTool{ tool='pencil', + brush=Brush{ size=2, type=BrushType.SQUARE }, + color=2, points={ Point(2, 2) } } + expect_cel_is_image(3) + app.undo() + + expect_cel_is_image(1) + app.useTool{ tool='pencil', + brush=Brush{ size=2, type=BrushType.SQUARE, center=Point(0, 0) }, + color=2, points={ Point(1, 1) } } + expect_cel_is_image(3) + app.undo() + + expect_cel_is_image(1) + app.useTool{ tool='line', + brush={ size=3, type=BrushType.SQUARE }, + color=3, points={ Point(1, 1), Point(2, 2) } } + expect_cel_is_image(4) + app.undo() + +end From a7bdc397615ec0c503ffcf05a773c7ae339e5321 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 21 Apr 2019 00:05:21 -0300 Subject: [PATCH 073/200] Add Version() class tests --- scripts/app_version.lua | 7 ------- scripts/version.lua | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) delete mode 100644 scripts/app_version.lua create mode 100644 scripts/version.lua diff --git a/scripts/app_version.lua b/scripts/app_version.lua deleted file mode 100644 index 6faafd9e3..000000000 --- a/scripts/app_version.lua +++ /dev/null @@ -1,7 +0,0 @@ --- Copyright (C) 2018 David Capello --- --- This file is released under the terms of the MIT license. --- Read LICENSE.txt for more information. - -assert(string.sub(app.version, 1, 1) == "1") -assert(string.sub(app.version, 2, 2) == ".") diff --git a/scripts/version.lua b/scripts/version.lua new file mode 100644 index 000000000..b9de01894 --- /dev/null +++ b/scripts/version.lua @@ -0,0 +1,37 @@ +-- Copyright (C) 2019 Igara Studio S.A. +-- Copyright (C) 2018 David Capello +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +assert(string.sub(tostring(app.version), 1, 1) == "1") +assert(string.sub(tostring(app.version), 2, 2) == ".") +assert(app.version.major == 1) +assert(app.version.minor >= 2) +assert(app.version > Version("1.2.10-beta4")) + +assert(Version("1") == Version("1")) +assert(Version("1.1") > Version("1")) +assert(Version("0.1") < Version("0.2")) +assert(Version("1.0.1") > Version("1")) +assert(Version("1.0.1") < Version("1.1")) +assert(Version("1.0.1") == Version("1.0.1")) +assert(Version("1.0.1") ~= Version("1.0.2")) +assert(Version("1.0.1") > Version("1.0.1-beta")) +assert(Version("1.0.1") > Version("1.0.1-dev")) +assert(Version("1.0.1-beta") > Version("1.0.1-alpha")) +assert(Version("1.0.1-beta50") < Version("1.0.1-beta100")) + +local v = Version() +assert(v.major == 0) +assert(v.minor == 0) +assert(v.patch == 0) +assert(v.prerelease == "") +assert(v.prereleaseDigit == 0) + +v = Version("1.2.10-beta4") +assert(v.major == 1) +assert(v.minor == 2) +assert(v.patch == 10) +assert(v.prerelease == "beta") +assert(v.prereleaseDigit == 4) From 03a74d19115c649d6decec58e6725227fa9fd169 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 21 Apr 2019 00:10:56 -0300 Subject: [PATCH 074/200] Add two minor tests for Version() <= operator --- scripts/version.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/version.lua b/scripts/version.lua index b9de01894..760c674f8 100644 --- a/scripts/version.lua +++ b/scripts/version.lua @@ -21,6 +21,8 @@ assert(Version("1.0.1") > Version("1.0.1-beta")) assert(Version("1.0.1") > Version("1.0.1-dev")) assert(Version("1.0.1-beta") > Version("1.0.1-alpha")) assert(Version("1.0.1-beta50") < Version("1.0.1-beta100")) +assert(Version("1.0.1-beta50") <= Version("1.0.1-beta100")) +assert(Version("1.0.1-beta100") <= Version("1.0.1-beta100")) local v = Version() assert(v.major == 0) From ce14e003c84965d110df84b4b121f1fab9c75fd8 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 22 Apr 2019 09:04:27 -0300 Subject: [PATCH 075/200] Update Version tests to new API --- scripts/version.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/version.lua b/scripts/version.lua index 760c674f8..b38a23cb9 100644 --- a/scripts/version.lua +++ b/scripts/version.lua @@ -28,12 +28,12 @@ local v = Version() assert(v.major == 0) assert(v.minor == 0) assert(v.patch == 0) -assert(v.prerelease == "") -assert(v.prereleaseDigit == 0) +assert(v.prereleaseLabel == "") +assert(v.prereleaseNumber == 0) v = Version("1.2.10-beta4") assert(v.major == 1) assert(v.minor == 2) assert(v.patch == 10) -assert(v.prerelease == "beta") -assert(v.prereleaseDigit == 4) +assert(v.prereleaseLabel == "beta") +assert(v.prereleaseNumber == 4) From 63ab87644121dccf67fbd17fd866e92f2c44256d Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 24 Apr 2019 19:09:21 -0300 Subject: [PATCH 076/200] Add tests for app.defaultPalette and Palette{ fromResource } --- scripts/palette.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/scripts/palette.lua b/scripts/palette.lua index 51ce874b2..9a65b451a 100644 --- a/scripts/palette.lua +++ b/scripts/palette.lua @@ -49,3 +49,33 @@ do assert(p:getColor(i) == q:getColor(i)) end end + +-- Default palette and resources +do + local db16 = Palette{ fromResource="DB16" } + local db32 = Palette{ fromResource="DB32" } + + assert(#db16 == 16) + assert(#db32 == 32) + assert(db32:getColor(0) == Color(0, 0, 0)) + assert(db32:getColor(31) == Color(138, 111, 48)) + + assert(app.defaultPalette == db32) + + app.defaultPalette = db16 + assert(app.defaultPalette == db16) + + -- Default sprite palette is completely black + -- TODO should we use the app.defaultPalette as the default palette? + local spr = Sprite(32, 32, ColorMode.INDEXED) + local sprPal = spr.palettes[1]; + assert(#sprPal == 256) + assert(sprPal ~= db16) + assert(sprPal ~= db32) + for i=0,255 do + assert(sprPal:getColor(i) == Color(0, 0,0)) + end + + spr:setPalette(db32) + assert(sprPal == db32) +end From 8c64e684f59f825c57e2277a367887581e5abe60 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 24 Apr 2019 21:15:09 -0300 Subject: [PATCH 077/200] Add app.preferences object --- scripts/app_preferences.lua | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 scripts/app_preferences.lua diff --git a/scripts/app_preferences.lua b/scripts/app_preferences.lua new file mode 100644 index 000000000..24df608ca --- /dev/null +++ b/scripts/app_preferences.lua @@ -0,0 +1,38 @@ +-- Copyright (C) 2019 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +-- Global preferences +do + assert(app.preferences.general.language == "en") + assert(app.preferences.general.screen_scale == 2) + assert(app.preferences.general.ui_scale == 1) +end + +-- Preferences for tools +do + local t = app.preferences.tool('pencil') + assert(t.opacity == 255) + assert(t.tolerance == 0) + assert(t.contiguous == true) + assert(t.brush.type == BrushType.CIRCLE) + assert(t.brush.size == 1) + t.brush.size = 2 + assert(t.brush.size == 2) + + -- Getting the tool again will give us the default configuration + -- again in batch mode + t = app.preferences.tool('pencil') + assert(t.brush.size == 1) +end + +-- Preferences for documents +do + local s = Sprite(32, 32) + local p = app.preferences.document(s) + assert(p.grid.bounds == Rectangle(0, 0, 16, 16)) + assert(p.grid.color == Color(0, 0, 255)) + p.grid.color = Color(255, 0, 0) + assert(p.grid.color == Color(255, 0, 0)) +end From 57e6fd35b4b33ad4dbd587cac7716cd22ac5abe0 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 29 Apr 2019 10:23:32 -0300 Subject: [PATCH 078/200] New useTool() tests with brushes --- scripts/test_utils.lua | 9 +++ scripts/tools.lua | 148 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 143 insertions(+), 14 deletions(-) diff --git a/scripts/test_utils.lua b/scripts/test_utils.lua index 6551e5165..b7e79ca73 100644 --- a/scripts/test_utils.lua +++ b/scripts/test_utils.lua @@ -21,6 +21,15 @@ function expect_img(image, expectedPixels) local value = image:getPixel(x, y) local expected = expectedPixels[1+y*w+x] if value ~= expected then + print('Image(' .. tostring(w) .. 'x' .. tostring(h) .. ') = {') + for v=0,h-1 do + lineStr = ' ' + for u=0,w-1 do + lineStr = lineStr .. image:getPixel(u, v) .. ',' + end + print(lineStr) + end + print('}') print('In pixel (' .. x .. ', ' .. y .. '):') expect_eq(value, expected) end diff --git a/scripts/tools.lua b/scripts/tools.lua index 4586b9895..85a0dca46 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -5,6 +5,9 @@ dofile('./test_utils.lua') +local rgba = app.pixelColor.rgba +local gray = app.pixelColor.graya + ---------------------------------------------------------------------- -- activeTool ---------------------------------------------------------------------- @@ -207,27 +210,29 @@ end -- draw with brushes ---------------------------------------------------------------------- -do +function drawing_with_simple_brushes(colorMode, a, b, c) + print("drawing_with_simple_brushes", colorMode) + local expectedImages = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, - 0, 1, 0, 0, + 0, a, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, - 0, 2, 2, 0, - 0, 2, 2, 0, + 0, b, b, 0, + 0, b, b, 0, 0, 0, 0, 0 }, - { 3, 3, 3, 0, - 3, 3, 3, 3, - 3, 3, 3, 3, - 0, 3, 3, 3 } + { c, c, c, 0, + c, c, c, c, + c, c, c, c, + 0, c, c, c } } - local s = Sprite(4, 4, ColorMode.INDEXED) + local s = Sprite(4, 4, colorMode) assert(s == app.activeSprite) assert(s.cels[1] == app.activeCel) @@ -239,7 +244,7 @@ do end expect_cel_is_image(1) - app.useTool{ tool='pencil', color=1, points={ Point(1, 1) } } + app.useTool{ tool='pencil', color=a, points={ Point(1, 1) } } assert(#s.cels == 1) expect_cel_is_image(2) app.undo() @@ -247,22 +252,137 @@ do expect_cel_is_image(1) app.useTool{ tool='pencil', brush=Brush{ size=2, type=BrushType.SQUARE }, - color=2, points={ Point(2, 2) } } + color=b, points={ Point(1, 1) } } expect_cel_is_image(3) app.undo() expect_cel_is_image(1) app.useTool{ tool='pencil', - brush=Brush{ size=2, type=BrushType.SQUARE, center=Point(0, 0) }, - color=2, points={ Point(1, 1) } } + brush=Brush{ size=2, type=BrushType.SQUARE, center=Point(1, 1) }, + color=b, points={ Point(2, 2) } } expect_cel_is_image(3) app.undo() expect_cel_is_image(1) app.useTool{ tool='line', brush={ size=3, type=BrushType.SQUARE }, - color=3, points={ Point(1, 1), Point(2, 2) } } + color=c, points={ Point(1, 1), Point(2, 2) } } expect_cel_is_image(4) app.undo() end + +do + drawing_with_simple_brushes(ColorMode.RGB, red.rgbaPixel, blue.rgbaPixel, yellow.rgbaPixel) + drawing_with_simple_brushes(ColorMode.GRAY, gray(255), gray(128), gray(32)) + drawing_with_simple_brushes(ColorMode.INDEXED, 1, 2, 3) +end + +---------------------------------------------------------------------- +-- draw with special image brushes + patterns +---------------------------------------------------------------------- + +function drawing_with_image_brushes(imageColorMode, colorInImage, + brushColorMode, colorInBrush, palette) + print("drawing_with_image_brushes", imageColorMode, brushColorMode) + local s = Sprite(4, 4, imageColorMode) + local c = colorInImage + cel = s.cels[1] + + if palette then + s:setPalette(palette) + end + + -- Brush image with BrushPattern.ORIGIN + local bi = Image(2, 2, brushColorMode) + bi:clear(0) + bi:putPixel(0, 0, colorInBrush) + bi:putPixel(1, 1, colorInBrush) + local b = Brush { image=bi, + center=Point(0, 0), + pattern=BrushPattern.ORIGIN, + patternOrigin=Point(0, 0) } + + expect_img(app.activeImage, + { 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0 }) + + app.useTool{ tool=pencil, brush=b, points={ Point(0, 0) } } + assert(cel.bounds == Rectangle(0, 0, 2, 2)) + expect_img(app.activeImage, + { c, 0, + 0, c }) + app.undo() + + app.useTool{ tool=pencil, brush=b, points={ Point(0, 0), Point(1, 1) } } + assert(cel.bounds == Rectangle(0, 0, 3, 3)) + expect_img(app.activeImage, + { c, 0, 0, + 0, c, 0, + 0, 0, c }) + app.undo() + + app.useTool{ tool=pencil, brush=b, points={ Point(0, 1) } } + assert(cel.bounds == Rectangle(0, 1, 2, 2)) + expect_img(app.activeImage, + { 0, c, + c, 0 }) + app.undo() + + app.useTool{ tool=pencil, brush=b, points={ Point(0, 0), Point(2, 0), + Point(0, 0), Point(0, 1) } } + assert(cel.bounds == Rectangle(0, 0, 4, 3)) + expect_img(app.activeImage, + { c, 0, c, 0, + 0, c, 0, c, + c, 0, 0, 0 }) + app.undo() + + app.useTool{ tool='paint_bucket', brush=b, points={ Point(0, 0) } } + assert(cel.bounds == Rectangle(0, 0, 4, 4)) + expect_img(app.activeImage, + { c, 0, c, 0, + 0, c, 0, c, + c, 0, c, 0, + 0, c, 0, c }) + app.undo() + + app.useTool{ tool=pencil, brush=b, points={ Point(1, 0) } } + assert(app.activeImage ~= nil) + assert(cel.bounds == Rectangle(1, 0, 2, 2)) + expect_img(app.activeImage, + { 0, c, + c, 0 }) + app.undo() + + app.useTool{ tool=pencil, brush=b, points={ Point(1, 0), + Point(1, 0)} } + assert(app.activeImage ~= nil) + assert(cel.bounds == Rectangle(1, 0, 2, 2)) + expect_img(app.activeImage, + { 0, c, + c, 0 }) + app.undo() + + -- Change brush pattern to BrushPattern.TARGET + + b = Brush { image=bi, + center=Point(0, 0), + pattern=BrushPattern.TARGET, + patternOrigin=Point(0, 0) } + + app.useTool{ tool=pencil, brush=b, points={ Point(1, 0) } } + assert(cel.bounds == Rectangle(1, 0, 2, 2)) + expect_img(app.activeImage, + { c, 0, + 0, c }) + app.undo() + +end + +do + drawing_with_image_brushes(ColorMode.RGB, rgba(255, 0, 0), + ColorMode.RGB, rgba(255, 0, 0)) +end From 5337328c924bf88b33f370813e29f6b5842c3ebd Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 8 May 2019 18:54:25 -0300 Subject: [PATCH 079/200] Default brush center has changed --- scripts/brush.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/brush.lua b/scripts/brush.lua index 9f581d407..a1b6e98a4 100644 --- a/scripts/brush.lua +++ b/scripts/brush.lua @@ -17,7 +17,7 @@ do local c = Brush(4) assert(c.type == BrushType.CIRCLE) assert(c.size == 4) - assert(c.center == Point{ x=2, y=2 }) + assert(c.center == Point{ x=1, y=1 }) end do From 3e2cbf4b4c8c6b827d5cfeecda14e584d1385b4d Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 8 May 2019 19:03:44 -0300 Subject: [PATCH 080/200] Remove tests for global preferences --- scripts/app_preferences.lua | 7 ------- 1 file changed, 7 deletions(-) diff --git a/scripts/app_preferences.lua b/scripts/app_preferences.lua index 24df608ca..c03b197c8 100644 --- a/scripts/app_preferences.lua +++ b/scripts/app_preferences.lua @@ -3,13 +3,6 @@ -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. --- Global preferences -do - assert(app.preferences.general.language == "en") - assert(app.preferences.general.screen_scale == 2) - assert(app.preferences.general.ui_scale == 1) -end - -- Preferences for tools do local t = app.preferences.tool('pencil') From bcc39c7bef05ebd5b1e13ea8dde8e4b7e08e6327 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 11 May 2019 18:26:58 -0300 Subject: [PATCH 081/200] Add tests for useTool+symmetry options --- scripts/tools.lua | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/scripts/tools.lua b/scripts/tools.lua index 85a0dca46..dff431e3c 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -386,3 +386,108 @@ do drawing_with_image_brushes(ColorMode.RGB, rgba(255, 0, 0), ColorMode.RGB, rgba(255, 0, 0)) end + +---------------------------------------------------------------------- +-- draw with symmetry +---------------------------------------------------------------------- + +function drawing_with_symmetry(imageColorMode, colorInImage, + brushColorMode, colorInBrush, palette) + print("drawing_with_symmetry", imageColorMode, brushColorMode) + local s = Sprite(8, 3, imageColorMode) + local c = colorInImage + cel = s.cels[1] + + if palette then + s:setPalette(palette) + end + + -- Enable symmetry + local pref = app.preferences + local docPref = pref.document(s) + pref.symmetry_mode.enabled = true + docPref.symmetry.mode = 1 -- TODO use SymmetryMode.HORIZONTAL when it's available + docPref.symmetry.x_axis = 4 + + expect_img(app.activeImage, + { 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }) + expect_eq(cel.bounds, Rectangle(0, 0, 8, 3)) + + local b = Brush { size=1 } + app.fgColor = c + app.useTool{ tool=pencil, brush=b, points={ Point(0, 0) } } + expect_img(app.activeImage, + { c, 0, 0, 0, 0, 0, 0, c }) + expect_eq(cel.bounds, Rectangle(0, 0, 8, 1)) + app.undo() + + app.useTool{ tool=pencil, brush=b, points={ Point(2, 0) } } + expect_img(app.activeImage, + { c, 0, 0, c }) + expect_eq(cel.bounds, Rectangle(2, 0, 4, 1)) + app.undo() + + -- Brush size 2x2 + b = Brush { size=2 } + app.useTool{ tool=pencil, brush=b, points={ Point(1, 0) } } + expect_eq(cel.bounds, Rectangle(1, 0, 6, 2)) + expect_img(app.activeImage, + { c, c, 0, 0, c, c, + c, c, 0, 0, c, c }) + app.undo() + + -- Brush size 3x3 + b = Brush { size=3 } + app.useTool{ tool=pencil, brush=b, points={ Point(1, 1) } } + expect_eq(cel.bounds, Rectangle(0, 0, 8, 3)) + expect_img(app.activeImage, + { 0, c, 0, 0, 0, 0, c, 0, + c, c, c, 0, 0, c, c, c, + 0, c, 0, 0, 0, 0, c, 0 }) + app.undo() + + -- Brush size 3x3 + b = Brush { size=3, center=Point(1, 1) } + app.useTool{ tool=pencil, brush=b, points={ Point(2, 1) } } + expect_eq(cel.bounds, Rectangle(1, 0, 6, 3)) + expect_img(app.activeImage, + { 0, c, 0, 0, c, 0, + c, c, c, c, c, c, + 0, c, 0, 0, c, 0 }) + app.undo() + + -- Brush size 4x4 + b = Brush { size=4 } + app.useTool{ tool=pencil, brush=b, points={ Point(1, 0) } } + expect_eq(cel.bounds, Rectangle(0, 0, 8, 3)) + expect_img(app.activeImage, + { c, c, c, c, c, c, c, c, + c, c, c, c, c, c, c, c, + 0, c, c, 0, 0, c, c, 0 }) + app.undo() + + -- Odd symmetry + docPref.symmetry.x_axis = 4.5 + + b = Brush { size=1 } + app.useTool{ tool=pencil, brush=b, points={ Point(4, 0) } } + expect_img(app.activeImage, + { c }) + expect_eq(cel.bounds, Rectangle(4, 0, 1, 1)) + app.undo() + + b = Brush { size=1 } + app.useTool{ tool=pencil, brush=b, points={ Point(3, 0) } } + expect_img(app.activeImage, + { c, 0, c }) + expect_eq(cel.bounds, Rectangle(3, 0, 3, 1)) + app.undo() + +end + +do + drawing_with_symmetry(ColorMode.RGB, rgba(255, 0, 0), + ColorMode.RGB, rgba(255, 0, 0)) +end From b5bd46a315d02fd80957cf15d824f5fe0d3f69b7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 29 May 2019 16:02:42 -0300 Subject: [PATCH 082/200] Fix tests with brushes because we reverted the default brush center --- scripts/brush.lua | 9 ++++-- scripts/tools.lua | 72 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 59 insertions(+), 22 deletions(-) diff --git a/scripts/brush.lua b/scripts/brush.lua index a1b6e98a4..2f9accdeb 100644 --- a/scripts/brush.lua +++ b/scripts/brush.lua @@ -14,10 +14,15 @@ do assert(b.pattern == BrushPattern.NONE) assert(b.patternOrigin == Point{ x=0, y=0 }) - local c = Brush(4) + local c = Brush(3) assert(c.type == BrushType.CIRCLE) - assert(c.size == 4) + assert(c.size == 3) assert(c.center == Point{ x=1, y=1 }) + + local d = Brush(4) + assert(d.type == BrushType.CIRCLE) + assert(d.size == 4) + assert(d.center == Point{ x=2, y=2 }) end do diff --git a/scripts/tools.lua b/scripts/tools.lua index dff431e3c..b4eda3a02 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -252,14 +252,14 @@ function drawing_with_simple_brushes(colorMode, a, b, c) expect_cel_is_image(1) app.useTool{ tool='pencil', brush=Brush{ size=2, type=BrushType.SQUARE }, - color=b, points={ Point(1, 1) } } + color=b, points={ Point(2, 2) } } expect_cel_is_image(3) app.undo() expect_cel_is_image(1) app.useTool{ tool='pencil', - brush=Brush{ size=2, type=BrushType.SQUARE, center=Point(1, 1) }, - color=b, points={ Point(2, 2) } } + brush=Brush{ size=2, type=BrushType.SQUARE, center=Point(0, 0) }, + color=b, points={ Point(1, 1) } } expect_cel_is_image(3) app.undo() @@ -409,31 +409,44 @@ function drawing_with_symmetry(imageColorMode, colorInImage, docPref.symmetry.mode = 1 -- TODO use SymmetryMode.HORIZONTAL when it's available docPref.symmetry.x_axis = 4 - expect_img(app.activeImage, + expect_eq(cel.bounds, Rectangle(0, 0, 8, 3)) + expect_img(cel.image, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }) - expect_eq(cel.bounds, Rectangle(0, 0, 8, 3)) local b = Brush { size=1 } app.fgColor = c app.useTool{ tool=pencil, brush=b, points={ Point(0, 0) } } - expect_img(app.activeImage, - { c, 0, 0, 0, 0, 0, 0, c }) expect_eq(cel.bounds, Rectangle(0, 0, 8, 1)) + expect_img(cel.image, + { c, 0, 0, 0, 0, 0, 0, c }) app.undo() app.useTool{ tool=pencil, brush=b, points={ Point(2, 0) } } - expect_img(app.activeImage, - { c, 0, 0, c }) expect_eq(cel.bounds, Rectangle(2, 0, 4, 1)) + expect_img(cel.image, + { c, 0, 0, c }) app.undo() - -- Brush size 2x2 + -- Brush size 2x2 center=(1,1) b = Brush { size=2 } + assert(b.center.x == 1) + assert(b.center.y == 1) + app.useTool{ tool=pencil, brush=b, points={ Point(1, 1) } } + expect_eq(cel.bounds, Rectangle(0, 0, 8, 2)) + expect_img(cel.image, + { c, c, 0, 0, 0, 0, c, c, + c, c, 0, 0, 0, 0, c, c }) + app.undo() + + -- Brush size 2x2 center=(0,0) + b = Brush { size=2, center=Point(0, 0) } + assert(b.center.x == 0) + assert(b.center.y == 0) app.useTool{ tool=pencil, brush=b, points={ Point(1, 0) } } expect_eq(cel.bounds, Rectangle(1, 0, 6, 2)) - expect_img(app.activeImage, + expect_img(cel.image, { c, c, 0, 0, c, c, c, c, 0, 0, c, c }) app.undo() @@ -442,7 +455,7 @@ function drawing_with_symmetry(imageColorMode, colorInImage, b = Brush { size=3 } app.useTool{ tool=pencil, brush=b, points={ Point(1, 1) } } expect_eq(cel.bounds, Rectangle(0, 0, 8, 3)) - expect_img(app.activeImage, + expect_img(cel.image, { 0, c, 0, 0, 0, 0, c, 0, c, c, c, 0, 0, c, c, c, 0, c, 0, 0, 0, 0, c, 0 }) @@ -452,19 +465,31 @@ function drawing_with_symmetry(imageColorMode, colorInImage, b = Brush { size=3, center=Point(1, 1) } app.useTool{ tool=pencil, brush=b, points={ Point(2, 1) } } expect_eq(cel.bounds, Rectangle(1, 0, 6, 3)) - expect_img(app.activeImage, + expect_img(cel.image, { 0, c, 0, 0, c, 0, c, c, c, c, c, c, 0, c, 0, 0, c, 0 }) app.undo() - -- Brush size 4x4 + -- Brush size 4x4 center=(2,2) b = Brush { size=4 } + assert(b.center.x == 2) + assert(b.center.y == 2) + app.useTool{ tool=pencil, brush=b, points={ Point(1, 1) } } + expect_eq(cel.bounds, Rectangle(0, 0, 8, 3)) + expect_img(cel.image, + { c, c, c, 0, 0, c, c, c, + c, c, c, 0, 0, c, c, c, + c, c, 0, 0, 0, 0, c, c }) + app.undo() + + -- Brush size 4x4 center=(1,1) + b = Brush { size=4, center=Point(1, 1) } app.useTool{ tool=pencil, brush=b, points={ Point(1, 0) } } expect_eq(cel.bounds, Rectangle(0, 0, 8, 3)) - expect_img(app.activeImage, + expect_img(cel.image, { c, c, c, c, c, c, c, c, - c, c, c, c, c, c, c, c, + c, c, c, c, c, c, c, c, 0, c, c, 0, 0, c, c, 0 }) app.undo() @@ -473,16 +498,23 @@ function drawing_with_symmetry(imageColorMode, colorInImage, b = Brush { size=1 } app.useTool{ tool=pencil, brush=b, points={ Point(4, 0) } } - expect_img(app.activeImage, - { c }) expect_eq(cel.bounds, Rectangle(4, 0, 1, 1)) + expect_img(cel.image, + { c }) app.undo() b = Brush { size=1 } app.useTool{ tool=pencil, brush=b, points={ Point(3, 0) } } - expect_img(app.activeImage, - { c, 0, c }) expect_eq(cel.bounds, Rectangle(3, 0, 3, 1)) + expect_img(cel.image, + { c, 0, c }) + app.undo() + + b = Brush { size=2 } + app.useTool{ tool=pencil, brush=b, points={ Point(2, 0) } } + expect_eq(cel.bounds, Rectangle(1, 0, 7, 1)) + expect_img(cel.image, + { c, c, 0, 0, 0, c, c }) app.undo() end From e33579fe7dc56e1d8d462752f035eaafc576eb31 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 6 Jun 2019 10:34:25 -0300 Subject: [PATCH 083/200] Change some assert() with expect_eq() --- scripts/tools.lua | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/tools.lua b/scripts/tools.lua index b4eda3a02..a227ec89d 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -31,7 +31,7 @@ assert(app.activeBrush.angle == 0) local spr = Sprite(4, 4) local cel = spr.cels[1] -assert(cel.bounds == Rectangle(0, 0, 4, 4)) +expect_eq(cel.bounds, Rectangle(0, 0, 4, 4)) ---------------------------------------------------------------------- -- pencil and eraser @@ -42,12 +42,12 @@ app.useTool{ color=Color{ r=0, g=0, b=0 }, points={ Point(2, 2), Point(3, 2) }} -assert(cel.bounds == Rectangle(2, 2, 2, 1)) +expect_eq(cel.bounds, Rectangle(2, 2, 2, 1)) app.useTool{ tool='eraser', points={ Point(2, 2) }} -assert(cel.bounds == Rectangle(3, 2, 1, 1)) +expect_eq(cel.bounds, Rectangle(3, 2, 1, 1)) app.useTool{ tool='eraser', @@ -68,7 +68,7 @@ app.useTool{ color=red, points={ Point(0, 0), Point(3, 3) }} local cel = spr.cels[1] -assert(cel.bounds == Rectangle(0, 0, 4, 4)) +expect_eq(cel.bounds, Rectangle(0, 0, 4, 4)) do local r = red.rgbaPixel local expected = { r, 0, 0, 0, @@ -175,10 +175,10 @@ do local fgCel1 = spr2:newCel(bgLay, 1, Image(spr2.spec)) local bgCel2 = spr2:newCel(fgLay, 2, Image(spr2.spec)) local fgCel2 = spr2:newCel(bgLay, 2, Image(spr2.spec)) - assert(fgCel1.bounds == Rectangle(0, 0, 4, 4)) - assert(bgCel1.bounds == Rectangle(0, 0, 4, 4)) - assert(fgCel2.bounds == Rectangle(0, 0, 4, 4)) - assert(bgCel2.bounds == Rectangle(0, 0, 4, 4)) + expect_eq(fgCel1.bounds, Rectangle(0, 0, 4, 4)) + expect_eq(bgCel1.bounds, Rectangle(0, 0, 4, 4)) + expect_eq(fgCel2.bounds, Rectangle(0, 0, 4, 4)) + expect_eq(bgCel2.bounds, Rectangle(0, 0, 4, 4)) -- After each useTool(), the cels will be shrunken to the minimum -- required size. @@ -195,10 +195,10 @@ do app.useTool{ color=yellow, layer=fgCel1.layer, points={ Point(1, 1) }} app.useTool{ color=yellow, cel=fgCel2, points={ Point(2, 1) }} - assert(bgCel1.bounds == Rectangle(0, 0, 1, 1)) - assert(bgCel2.bounds == Rectangle(1, 0, 1, 1)) - assert(fgCel1.bounds == Rectangle(1, 1, 1, 1)) - assert(fgCel2.bounds == Rectangle(2, 1, 1, 1)) + expect_eq(bgCel1.bounds, Rectangle(0, 0, 1, 1)) + expect_eq(bgCel2.bounds, Rectangle(1, 0, 1, 1)) + expect_eq(fgCel1.bounds, Rectangle(1, 1, 1, 1)) + expect_eq(fgCel2.bounds, Rectangle(2, 1, 1, 1)) assert(bgCel1.image:getPixel(0, 0) == red.rgbaPixel) assert(bgCel2.image:getPixel(0, 0) == red.rgbaPixel) @@ -310,14 +310,14 @@ function drawing_with_image_brushes(imageColorMode, colorInImage, 0, 0, 0, 0 }) app.useTool{ tool=pencil, brush=b, points={ Point(0, 0) } } - assert(cel.bounds == Rectangle(0, 0, 2, 2)) + expect_eq(cel.bounds, Rectangle(0, 0, 2, 2)) expect_img(app.activeImage, { c, 0, 0, c }) app.undo() app.useTool{ tool=pencil, brush=b, points={ Point(0, 0), Point(1, 1) } } - assert(cel.bounds == Rectangle(0, 0, 3, 3)) + expect_eq(cel.bounds, Rectangle(0, 0, 3, 3)) expect_img(app.activeImage, { c, 0, 0, 0, c, 0, @@ -325,7 +325,7 @@ function drawing_with_image_brushes(imageColorMode, colorInImage, app.undo() app.useTool{ tool=pencil, brush=b, points={ Point(0, 1) } } - assert(cel.bounds == Rectangle(0, 1, 2, 2)) + expect_eq(cel.bounds, Rectangle(0, 1, 2, 2)) expect_img(app.activeImage, { 0, c, c, 0 }) @@ -333,7 +333,7 @@ function drawing_with_image_brushes(imageColorMode, colorInImage, app.useTool{ tool=pencil, brush=b, points={ Point(0, 0), Point(2, 0), Point(0, 0), Point(0, 1) } } - assert(cel.bounds == Rectangle(0, 0, 4, 3)) + expect_eq(cel.bounds, Rectangle(0, 0, 4, 3)) expect_img(app.activeImage, { c, 0, c, 0, 0, c, 0, c, @@ -341,7 +341,7 @@ function drawing_with_image_brushes(imageColorMode, colorInImage, app.undo() app.useTool{ tool='paint_bucket', brush=b, points={ Point(0, 0) } } - assert(cel.bounds == Rectangle(0, 0, 4, 4)) + expect_eq(cel.bounds, Rectangle(0, 0, 4, 4)) expect_img(app.activeImage, { c, 0, c, 0, 0, c, 0, c, @@ -351,7 +351,7 @@ function drawing_with_image_brushes(imageColorMode, colorInImage, app.useTool{ tool=pencil, brush=b, points={ Point(1, 0) } } assert(app.activeImage ~= nil) - assert(cel.bounds == Rectangle(1, 0, 2, 2)) + expect_eq(cel.bounds, Rectangle(1, 0, 2, 2)) expect_img(app.activeImage, { 0, c, c, 0 }) @@ -360,7 +360,7 @@ function drawing_with_image_brushes(imageColorMode, colorInImage, app.useTool{ tool=pencil, brush=b, points={ Point(1, 0), Point(1, 0)} } assert(app.activeImage ~= nil) - assert(cel.bounds == Rectangle(1, 0, 2, 2)) + expect_eq(cel.bounds, Rectangle(1, 0, 2, 2)) expect_img(app.activeImage, { 0, c, c, 0 }) @@ -374,7 +374,7 @@ function drawing_with_image_brushes(imageColorMode, colorInImage, patternOrigin=Point(0, 0) } app.useTool{ tool=pencil, brush=b, points={ Point(1, 0) } } - assert(cel.bounds == Rectangle(1, 0, 2, 2)) + expect_eq(cel.bounds, Rectangle(1, 0, 2, 2)) expect_img(app.activeImage, { c, 0, 0, c }) From 15e38b6f6ae802a9834d4d2373fc76dbe56e1caf Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 28 Jun 2019 16:49:36 -0300 Subject: [PATCH 084/200] Test if two or more app.useTool() inside a app.transaction() are grouped in one undoable action --- scripts/tools.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/scripts/tools.lua b/scripts/tools.lua index a227ec89d..f52975802 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -523,3 +523,32 @@ do drawing_with_symmetry(ColorMode.RGB, rgba(255, 0, 0), ColorMode.RGB, rgba(255, 0, 0)) end + +---------------------------------------------------------------------- +-- useTool in a transaction +---------------------------------------------------------------------- + +do + local s = Sprite(2, 2) + local r = red.rgbaPixel + local y = yellow.rgbaPixel + app.fgColor = r + + local cel = s.cels[1] + expect_img(cel.image, { 0, 0, + 0, 0 }) + app.transaction( + function() + app.useTool{ tool=pencil, + color=r, brush=Brush{ size=1 }, + points={ Point(0, 0) } } + app.useTool{ tool=pencil, + color=y, brush=Brush{ size=1 }, + points={ Point(1, 1) } } + end) + expect_img(cel.image, { r, 0, + 0, y }) + app.undo() -- Undo the whole transaction (two useTool grouped in one transaction) + expect_img(cel.image, { 0, 0, + 0, 0 }) +end From b800de65a6970bdc810c51fca3dec195e2a076eb Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 28 Jun 2019 18:12:00 -0300 Subject: [PATCH 085/200] Test app.command.NewFile --- scripts/app_command.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/app_command.lua b/scripts/app_command.lua index 3cb51064d..973eed4d3 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -22,6 +22,18 @@ do -- Undo/Redo commands (like app.undo/redo()) assert(s.height == 40) end +do -- NewSprite + local s1 = app.activeSprite + app.command.NewFile{ } + assert(s1 == app.activeSprite) + app.command.NewFile{ width=256, height=128, colorMode=ColorMode.INDEXED } + local s2 = app.activeSprite + assert(s1 ~= s2) + assert(s2.width == 256) + assert(s2.height == 128) + assert(s2.colorMode == ColorMode.INDEXED) +end + do -- NewLayer/RemoveLayer local s = Sprite(32, 32) assert(#s.layers == 1) From b8affd9518f8080499ac36c594356ff1f19c47e7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 16 Jul 2019 16:13:02 -0300 Subject: [PATCH 086/200] Test ReplaceColor{} command --- scripts/app_command.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/scripts/app_command.lua b/scripts/app_command.lua index 973eed4d3..28787feba 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -4,6 +4,8 @@ -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. +dofile('./test_utils.lua') + do -- Undo/Redo commands (like app.undo/redo()) local s = Sprite(32, 32) assert(s.width == 32) @@ -133,3 +135,34 @@ do -- CanvasSize app.command.CanvasSize{ top=2, right=4, bottom=8 } assert(s.bounds == Rectangle(0, 0, 38, 42)) end + +do -- ReplaceColor + local s = Sprite(4, 4) + local cel = app.activeCel + local red = Color(255, 0, 0) + local yellow = Color(255, 255, 0) + local blue = Color(0, 0, 255) + local r = red.rgbaPixel + local y = yellow.rgbaPixel + local b = blue.rgbaPixel + + expect_eq(cel.bounds, Rectangle(0, 0, 4, 4)) + expect_img(cel.image, + { 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0 }) + + app.useTool{ brush=Brush(1), color=red, points={Point(1,1)} } + app.useTool{ brush=Brush(1), color=yellow, points={Point(2,2)} } + expect_eq(cel.bounds, Rectangle(1, 1, 2, 2)) + expect_img(cel.image, + { r, 0, + 0, y }) + + app.command.ReplaceColor{ ui=false, from=red, to=blue } + expect_eq(cel.bounds, Rectangle(1, 1, 2, 2)) + expect_img(cel.image, + { b, 0, + 0, y }) +end From a459ad6ffcd1d04134f46517ee4831a3d1f61375 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 18 Jul 2019 11:46:42 -0300 Subject: [PATCH 087/200] Add tests for BrightnessContrast, Despeckle, HueSaturation, InvertColor, Outline --- scripts/app_command.lua | 230 +++++++++++++++++++++++++++++++++++++++- scripts/test_utils.lua | 29 ++++- 2 files changed, 257 insertions(+), 2 deletions(-) diff --git a/scripts/app_command.lua b/scripts/app_command.lua index 28787feba..c67be8917 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -160,9 +160,237 @@ do -- ReplaceColor { r, 0, 0, y }) - app.command.ReplaceColor{ ui=false, from=red, to=blue } + app.command.ReplaceColor{ from=red, to=blue } expect_eq(cel.bounds, Rectangle(1, 1, 2, 2)) expect_img(cel.image, { b, 0, 0, y }) end + +do -- Invert + local s = Sprite(2, 2) + local cel = app.activeCel + local aa = Color(255, 128, 128).rgbaPixel + local na = Color(0, 127, 127).rgbaPixel + local bb = Color(128, 128, 255).rgbaPixel + local nb = Color(127, 127, 0).rgbaPixel + local i = cel.image + + i:drawPixel(0, 0, aa) + i:drawPixel(1, 0, bb) + i:drawPixel(0, 1, bb) + i:drawPixel(1, 1, aa) + expect_img(cel.image, + { aa, bb, + bb, aa }) + + app.command.InvertColor() + expect_img(cel.image, + { na, nb, + nb, na }) + + local Na = Color(0, 127, 128).rgbaPixel + local Ng = Color(127, 127, 255).rgbaPixel + app.command.InvertColor{ channels=FilterChannels.BLUE } + expect_img(cel.image, + { Na, Ng, + Ng, Na }) +end + +do -- Outline + local s = Sprite(4, 4) + local cel = app.activeCel + local red = Color(255, 0, 0) + local yellow = Color(255, 255, 0) + local blue = Color(0, 0, 255) + local r = red.rgbaPixel + local y = yellow.rgbaPixel + local b = blue.rgbaPixel + + expect_eq(cel.bounds, Rectangle(0, 0, 4, 4)) + expect_img(cel.image, + { 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0 }) + + app.useTool{ brush=Brush(1), color=red, points={Point(1,1)} } + app.useTool{ brush=Brush(1), color=yellow, points={Point(2,2)} } + expect_eq(cel.bounds, Rectangle(1, 1, 2, 2)) + expect_img(cel.image, + { r, 0, + 0, y }) + + app.command.Outline{ color=blue } + expect_eq(cel.bounds, Rectangle(0, 0, 4, 4)) + expect_img(cel.image, + { 0, b, 0, 0, + b, r, b, 0, + 0, b, y, b, + 0, 0, b, 0 }) + + -- Test "bgColor", "matrix", "place" params + + app.useTool{ tool='filled_rectangle', brush=Brush(1), color=blue, points={Point(0,0), Point(3,3)} } + app.useTool{ tool='filled_rectangle', brush=Brush(1), color=yellow, points={Point(1,1), Point(2,2)} } + expect_eq(cel.bounds, Rectangle(0, 0, 4, 4)) + expect_img(cel.image, + { b, b, b, b, + b, y, y, b, + b, y, y, b, + b, b, b, b }) + + app.command.Outline{ color=red, bgColor=blue, matrix='circle' } + expect_eq(cel.bounds, Rectangle(0, 0, 4, 4)) + expect_img(cel.image, + { b, r, r, b, + r, y, y, r, + r, y, y, r, + b, r, r, b }) + app.undo() + + app.command.Outline{ color=red, bgColor=blue, matrix='square' } + expect_eq(cel.bounds, Rectangle(0, 0, 4, 4)) + expect_img(cel.image, + { r, r, r, r, + r, y, y, r, + r, y, y, r, + r, r, r, r }) + app.undo() + + app.command.Outline{ color=red, bgColor=blue, place='inside' } + expect_eq(cel.bounds, Rectangle(0, 0, 4, 4)) + expect_img(cel.image, + { b, b, b, b, + b, r, r, b, + b, r, r, b, + b, b, b, b }) + +end + +do -- BrightnessContrast + local rgba = app.pixelColor.rgba + local rgbaR = app.pixelColor.rgbaR + local rgbaG = app.pixelColor.rgbaG + local rgbaB = app.pixelColor.rgbaB + local s = Sprite(2, 2) + local cel = app.activeCel + local c = { rgba(255, 128, 64), rgba(250, 225, 110), + rgba( 30, 60, 0), rgba(200, 100, 50), } + local i = cel.image + + i:drawPixel(0, 0, c[1]) + i:drawPixel(1, 0, c[2]) + i:drawPixel(0, 1, c[3]) + i:drawPixel(1, 1, c[4]) + expect_img(i, + { c[1], c[2], + c[3], c[4] }) + + app.command.BrightnessContrast() -- Do nothing by default + expect_img(i, + { c[1], c[2], + c[3], c[4] }) + + local d = {} + for k,v in ipairs(c) do + d[k] = rgba(math.min(255, rgbaR(v)*1.5), + math.min(255, rgbaG(v)*1.5), + math.min(255, rgbaB(v)*1.5), 255) + end + app.command.BrightnessContrast{ brightness=50 } -- Do nothing by default + expect_img(i, + { d[1], d[2], + d[3], d[4] }) +end + +do -- Despeckle + local s = Sprite(5, 5) + local white = Color(255, 255, 255) + local red = Color(255, 0, 0) + + app.bgColor = white + app.command.BackgroundFromLayer() + + local cel = app.activeCel + local i = cel.image + local b = white.rgbaPixel + local c = red.rgbaPixel + expect_img(i, + { b,b,b,b,b, + b,b,b,b,b, + b,b,b,b,b, + b,b,b,b,b, + b,b,b,b,b }) + + app.useTool{ tool='filled_rectangle', brush=Brush(1), color=red, + points={Point(1,1),Point(3,3)} } + expect_img(i, + { b,b,b,b,b, + b,c,c,c,b, + b,c,c,c,b, + b,c,c,c,b, + b,b,b,b,b }) + + app.command.Despeckle() + expect_img(i, + { b,b,b,b,b, + b,b,c,b,b, + b,c,c,c,b, + b,b,c,b,b, + b,b,b,b,b }) + + app.command.Despeckle() + expect_img(i, + { b,b,b,b,b, + b,b,b,b,b, + b,b,c,b,b, + b,b,b,b,b, + b,b,b,b,b }) +end + +do -- HueSaturation + local s = Sprite(1, 1) + local cel = app.activeCel + local i = cel.image + local b = Color(255, 0, 0).rgbaPixel + + i:drawPixel(0, 0, b) + expect_img(i, { b }) + + app.command.HueSaturation{ hue=360 } -- Do nothing (change hue to a full 360 circle) + expect_img(i, { b }) + + app.command.HueSaturation{ hue=60 } + b = Color(255, 255, 0).rgbaPixel + expect_img(i, { b }) + + app.command.HueSaturation{ hue=60 } + b = Color(0, 255, 0).rgbaPixel + expect_img(i, { b }) + + app.command.HueSaturation{ saturation=-50 } + b = Color(64, 191, 64).rgbaPixel + expect_img(i, { b }) + + app.undo() + app.command.HueSaturation{ saturation=-100 } + b = Color(128, 128, 128).rgbaPixel + expect_img(i, { b }) + + app.undo() + app.command.HueSaturation{ saturation=-50, mode='hsv' } + b = Color(128, 255, 128).rgbaPixel + expect_img(i, { b }) + + app.undo() + app.command.HueSaturation{ value=75 } + b = Color(191, 255, 191).rgbaPixel + expect_img(i, { b }) + + app.undo() + app.command.HueSaturation{ alpha=-50 } + b = Color(0, 255, 0, 127).rgbaPixel + expect_img(i, { b }) + +end diff --git a/scripts/test_utils.lua b/scripts/test_utils.lua index b7e79ca73..042d84aac 100644 --- a/scripts/test_utils.lua +++ b/scripts/test_utils.lua @@ -31,7 +31,34 @@ function expect_img(image, expectedPixels) end print('}') print('In pixel (' .. x .. ', ' .. y .. '):') - expect_eq(value, expected) + + local a = value + local b = expected + print(debug.traceback()) + print('Expected A == B but:') + if image.colorMode == ColorMode.RGB then + print(string.format(' - Value A = rgba(%d,%d,%d,%d)', + app.pixelColor.rgbaR(a), + app.pixelColor.rgbaG(a), + app.pixelColor.rgbaB(a), + app.pixelColor.rgbaA(a))) + print(string.format(' - Value B = rgba(%d,%d,%d,%d)', + app.pixelColor.rgbaR(b), + app.pixelColor.rgbaG(b), + app.pixelColor.rgbaB(b), + app.pixelColor.rgbaA(b))) + elseif image.ColorMode == ColorMode.GRAY then + print(string.format(' - Value A = gray(%d,%d)', + app.pixelColor.grayG(a), + app.pixelColor.grayA(a))) + print(string.format(' - Value B = gray(%d,%d)', + app.pixelColor.grayV(b), + app.pixelColor.grayA(b))) + else + print(' - Value A = ' .. tostring(a)) + print(' - Value B = ' .. tostring(b)) + end + assert(a == b) end end end From e70c6c5962db7f19f6b3fe60c18d9c2badc5f19a Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 19 Jul 2019 18:39:32 -0300 Subject: [PATCH 088/200] Test Point/Size/Rectangle ctor with array of integers --- scripts/point.lua | 5 +++++ scripts/rectangle.lua | 7 +++++++ scripts/size.lua | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/scripts/point.lua b/scripts/point.lua index 1a447ab77..462aa5d6c 100644 --- a/scripts/point.lua +++ b/scripts/point.lua @@ -1,3 +1,4 @@ +-- Copyright (C) 2019 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -24,3 +25,7 @@ assert(pt.y == 6) pt = Point{x=10, y=20} assert(pt.x == 10) assert(pt.y == 20) + +pt = Point{45, 25} +assert(pt.x == 45) +assert(pt.y == 25) diff --git a/scripts/rectangle.lua b/scripts/rectangle.lua index 74fcefe51..5440652a4 100644 --- a/scripts/rectangle.lua +++ b/scripts/rectangle.lua @@ -1,3 +1,4 @@ +-- Copyright (C) 2019 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -39,6 +40,12 @@ assert(rc.y == 3) assert(rc.width == 4) assert(rc.height == 5) +rc = Rectangle{6, 7, 8, 9} +assert(rc.x == 6) +assert(rc.y == 7) +assert(rc.width == 8) +assert(rc.height == 9) + -- Rectangle:contains local a = Rectangle{x=2, y=3, width=4, height=5} diff --git a/scripts/size.lua b/scripts/size.lua index f3b448ea8..70ecedd7f 100644 --- a/scripts/size.lua +++ b/scripts/size.lua @@ -1,3 +1,4 @@ +-- Copyright (C) 2019 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -24,3 +25,7 @@ assert(sz.height == 8) sz = Size{width=10, height=20} assert(sz.width == 10) assert(sz.height == 20) + +sz = Size{45, 25} +assert(sz.width == 45) +assert(sz.height == 25) From d9cde80ebb11ef27641cf393416c76a311f11585 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 1 Aug 2019 21:14:45 -0300 Subject: [PATCH 089/200] Add tests for ColorCurve and ConvolutionMatrix filters --- scripts/app_command.lua | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/scripts/app_command.lua b/scripts/app_command.lua index c67be8917..e8a4d06e4 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -394,3 +394,56 @@ do -- HueSaturation expect_img(i, { b }) end + +do -- ColorCurve + local rgba = app.pixelColor.rgba + local s = Sprite(2, 1) + local cel = app.activeCel + local i = cel.image + + i:drawPixel(0, 0, rgba(255, 128, 0)) + i:drawPixel(1, 0, rgba(64, 0, 32)) + expect_img(i, { rgba(255, 128, 0), rgba(64, 0, 32) }) + + app.command.ColorCurve() -- Do nothing + expect_img(i, { rgba(255, 128, 0), rgba(64, 0, 32) }) + + app.command.ColorCurve{ curve={{0,0},{255,128}} } + expect_img(i, { rgba(128, 64, 0), rgba(32, 0, 16) }) + + app.command.ColorCurve{ channels=FilterChannels.ALPHA, curve={{0,0},{255,128}} } + expect_img(i, { rgba(128, 64, 0, 128), rgba(32, 0, 16, 128) }) + + app.command.ColorCurve{ channels=FilterChannels.RGBA, curve={{0,255},{255,255}} } + expect_img(i, { rgba(255, 255, 255), rgba(255, 255, 255) }) + + app.command.ColorCurve{ channels=FilterChannels.GREEN, curve={{0,0},{255,0}} } + expect_img(i, { rgba(255, 0, 255), rgba(255, 0, 255) }) + + app.command.ColorCurve{ channels=FilterChannels.BLUE, curve="0,128,255,128" } + expect_img(i, { rgba(255, 0, 128), rgba(255, 0, 128) }) +end + +do -- ConvolutionMatrix + local rgba = app.pixelColor.rgba + local s = Sprite(3, 3) + local cel = app.activeCel + local i = cel.image + local b = rgba(0, 0, 0) + local w = rgba(255, 255, 255) + + app.bgColor = Color(255, 255, 255) + app.command.BackgroundFromLayer() + i:drawPixel(1, 1, b) + expect_img(i, { w, w, w, + w, b, w, + w, w, w }) + + local u = rgba(239, 239, 239) + local v = rgba(223, 223, 223) + local w = rgba(191, 191, 191) + app.command.ConvolutionMatrix{ fromResource="blur-3x3" } + expect_img(i, { u, v, u, + v, w, v, + u, v, u }) +end From 7dad69e310ef8a4fbbf634b56b5fe65b41a07b68 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 1 Aug 2019 21:15:27 -0300 Subject: [PATCH 090/200] Check loading/saving a single image in all formats --- cli/file-formats.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 cli/file-formats.sh diff --git a/cli/file-formats.sh b/cli/file-formats.sh new file mode 100644 index 000000000..cd0b28666 --- /dev/null +++ b/cli/file-formats.sh @@ -0,0 +1,61 @@ +#! /bin/bash +# Copyright (C) 2019 Igara Studio S.A. + +# Create a simple image and save it in all formats using scripts +d=$t/file-formats +mkdir $d +cat >$d/gen.lua <$d/compare.lua < Date: Sat, 10 Aug 2019 14:05:18 -0300 Subject: [PATCH 091/200] Add tests for range of colors (new API) --- scripts/app_command.lua | 35 ++++++++++++++++++++++++++ scripts/range.lua | 55 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 scripts/range.lua diff --git a/scripts/app_command.lua b/scripts/app_command.lua index e8a4d06e4..500690f8f 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -447,3 +447,38 @@ do -- ConvolutionMatrix v, w, v, u, v, u }) end + +-- MoveColors and CopyColors +do + local s = Sprite(32, 32, ColorMode.INDEXED) + local p = Palette(4) + p:setColor(0, Color(0, 0, 0)) + p:setColor(1, Color(255, 0, 0)) + p:setColor(2, Color(0, 255, 0)) + p:setColor(3, Color(0, 0, 255)) + s:setPalette(p) + assert(#app.range.colors == 0) + app.range.colors = { 0, 2 } + assert(#app.range.colors == 2) + assert(app.range.colors[1] == 0) + assert(app.range.colors[2] == 2) + app.command.MoveColors{ before=0 } + p = s.palettes[1] + p:setColor(0, Color(0, 0, 0)) + p:setColor(1, Color(0, 255, 0)) + p:setColor(2, Color(255, 0, 0)) + p:setColor(3, Color(0, 0, 255)) + + app.range.colors = { 0, 1 } + assert(#app.range.colors == 2) + assert(app.range.colors[1] == 0) + assert(app.range.colors[2] == 1) + app.command.CopyColors{ before=4 } + p = s.palettes[1] + p:setColor(0, Color(0, 0, 0)) + p:setColor(1, Color(0, 255, 0)) + p:setColor(2, Color(255, 0, 0)) + p:setColor(3, Color(0, 0, 255)) + p:setColor(4, Color(0, 0, 0)) + p:setColor(5, Color(0, 255, 0)) +end diff --git a/scripts/range.lua b/scripts/range.lua new file mode 100644 index 000000000..30d6c586e --- /dev/null +++ b/scripts/range.lua @@ -0,0 +1,55 @@ +-- Copyright (C) 2019 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +do + -- Three layers + local s = Sprite(32, 32) + assert(#s.layers == 1) + + app.activeCel = s.cels[1] + + local r = app.range + assert(#r.layers == 1) + assert(#r.frames == 1) + assert(#r.cels == 1) + assert(r.layers[1] == s.layers[1]) + assert(r.frames[1] == s.frames[1]) + assert(r.cels[1] == s.cels[1]) + + s:newLayer() + assert(#s.layers == 2) + + local r = app.range + assert(#r.layers == 1) + assert(#r.frames == 1) + assert(#r.cels == 0) + assert(r.layers[1] == s.layers[2]) + assert(r.frames[1] == s.frames[1]) +end + +do + assert(#app.range.colors == 0) + app.range.colors = { 2 } + assert(#app.range.colors == 1) + assert(app.range.colors[1] == 2) + app.range.colors = { 1, 4 } + assert(#app.range.colors == 2) + assert(app.range.colors[1] == 1) + assert(app.range.colors[2] == 4) + app.range.colors = { 5, 2, 10, 8, 0 } + assert(#app.range.colors == 5) + -- app.range.colors are always sorted by color index + assert(app.range.colors[1] == 0) + assert(app.range.colors[2] == 2) + assert(app.range.colors[3] == 5) + assert(app.range.colors[4] == 8) + assert(app.range.colors[5] == 10) + assert(app.range:containsColor(0)) + assert(not app.range:containsColor(1)) + assert(app.range:containsColor(2)) + assert(app.range:containsColor(5)) + assert(app.range:containsColor(8)) + assert(app.range:containsColor(10)) +end From 4f33bd8e142a1ea91d2447bc4e8479c254136aaf Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 13 Aug 2019 18:24:39 -0300 Subject: [PATCH 092/200] Test negation operation (unary -) for Point --- scripts/point.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/point.lua b/scripts/point.lua index 462aa5d6c..33309544f 100644 --- a/scripts/point.lua +++ b/scripts/point.lua @@ -29,3 +29,7 @@ assert(pt.y == 20) pt = Point{45, 25} assert(pt.x == 45) assert(pt.y == 25) + +pt = -pt +assert(pt.x == -45) +assert(pt.y == -25) From 6c0523f15079b21c3bc4b864f7e9bab2794fd50f Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 13 Aug 2019 18:25:37 -0300 Subject: [PATCH 093/200] Add array_to_pixels() to test_utils.lua --- scripts/test_utils.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/test_utils.lua b/scripts/test_utils.lua index 042d84aac..e3ce5f26c 100644 --- a/scripts/test_utils.lua +++ b/scripts/test_utils.lua @@ -16,6 +16,10 @@ end function expect_img(image, expectedPixels) local w = image.width local h = image.height + if w*h ~= #expectedPixels then + print(debug.traceback()) + assert(w*h == #expectedPixels) + end for y=0,h-1 do for x=0,w-1 do local value = image:getPixel(x, y) @@ -63,3 +67,16 @@ function expect_img(image, expectedPixels) end end end + +function array_to_pixels(array, image) + local w = image.width + local h = image.height + assert(w*h == #array) + local i = 1 + for y=0,h-1 do + for x=0,w-1 do + image:drawPixel(x, y, array[i]) + i = i+1 + end + end +end From f00c5e68d179a3442cd06ca6cdb911df6a33a1a5 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 13 Aug 2019 18:25:56 -0300 Subject: [PATCH 094/200] Add Image:resize() test --- scripts/image.lua | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/scripts/image.lua b/scripts/image.lua index bd246f5d5..5d6fa0642 100644 --- a/scripts/image.lua +++ b/scripts/image.lua @@ -4,6 +4,8 @@ -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. +dofile('./test_utils.lua') + local rgba = app.pixelColor.rgba local a = Image(32, 64) @@ -92,3 +94,59 @@ do end end end + +-- Resize image +do + local a = Sprite(3, 2) + local cel = a.cels[1] + assert(cel.bounds == Rectangle(0, 0, 3, 2)) + local img = cel.image + local cols = { rgba(10, 60, 1), rgba(20, 50, 2), rgba(30, 40, 3), + rgba(40, 30, 4), rgba(50, 20, 5), rgba(60, 10, 6) } + array_to_pixels(cols, img) + expect_img(img, cols) + + -- Test resize of a cel with origin=0,0 + + img:resize(img.width*2, img.height*2) + + expect_eq(cel.bounds, Rectangle(0, 0, 6, 4)) + expect_eq(img.width, 6) + expect_eq(img.height, 4) + local cols2 = { cols[1],cols[1], cols[2],cols[2], cols[3],cols[3], + cols[1],cols[1], cols[2],cols[2], cols[3],cols[3], + cols[4],cols[4], cols[5],cols[5], cols[6],cols[6], + cols[4],cols[4], cols[5],cols[5], cols[6],cols[6] } + expect_img(img, cols2) + + -- Undo + function undo() + app.undo() + img = cel.image -- TODO img shouldn't be invalidated, the resize operation should kept the image ID + end + undo() + + -- Test a resize when cel origin > 0,0 + cel.position = Point(2, 1) + expect_eq(cel.bounds, Rectangle(2, 1, 3, 2)) + expect_img(img, cols) + img:resize{ width=6, height=4 } + expect_eq(cel.bounds, Rectangle(2, 1, 6, 4)) -- Position is not modified + expect_eq(img.width, 6) + expect_eq(img.height, 4) + + undo() + img:resize{ size=Size(6, 4), pivot=Point(1, 1) } + expect_eq(cel.bounds, Rectangle(1, 0, 6, 4)) + + undo() + img:resize{ size=Size(6, 4), pivot=Point(3, 2) } + expect_eq(cel.bounds, Rectangle(-1, -1, 6, 4)) + + -- Test resize without cel + + local img2 = Image(img) + expect_img(img2, cols2) + img2:resize(3, 2) + expect_img(img2, cols) +end From c81a7937e9e882d0fee7b4cb1af98e18123fc64d Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 13 Aug 2019 18:26:15 -0300 Subject: [PATCH 095/200] Extra checks for Sprite:resize() --- scripts/sprite.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/sprite.lua b/scripts/sprite.lua index d275e511a..01823ed0a 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -16,14 +16,18 @@ do a:crop() assert(a.width == 4) assert(a.height == 5) + assert(a.cels[1].image.width == 32) + assert(a.cels[1].image.height == 64) a:resize(6, 8) assert(a.width == 6) assert(a.height == 8) + assert(a.cels[1].image.width == 32 * 6 / 4) -- Check that the image was resized (not only the canvas) + assert(a.cels[1].image.height == 64 * 8 / 5) a:crop{x=-1, y=-1, width=20, height=30} assert(a.width == 20) assert(a.height == 30) - -- Resize sprite setting width/height + -- Resize sprite setting width/height (just changing canvas size) a.width = 8 a.height = 10 assert(a.width == 8) From bb89bfbb7ea0299d16e08ccc53be2d0d498c164a Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 28 Aug 2019 09:18:46 -0300 Subject: [PATCH 096/200] Add some test sprites with groups --- sprites/README.md | 10 +++++++++- sprites/groups2.aseprite | Bin 0 -> 820 bytes sprites/groups3abc.aseprite | Bin 0 -> 1202 bytes 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 sprites/groups2.aseprite create mode 100644 sprites/groups3abc.aseprite diff --git a/sprites/README.md b/sprites/README.md index 43cdb1598..1c2f0c205 100644 --- a/sprites/README.md +++ b/sprites/README.md @@ -1,4 +1,12 @@ # Files * `abcd.aseprite`: Indexed, 32x32, four layers ("a", "b", "c", "d") -* `1empty3.aseprite`: RGB, 32x32, two layers ("fg", "bg"), 2nd frame completelly empty, two tags ("a", "b") +* `1empty3.aseprite`: RGB, 32x32, two layers ("fg", "bg"), 2nd frame + completelly empty, two tags ("a", "b") +* `groups2.aseprite`: Indexed, 8x8, two groups ("items", "player"), + two layers per group ("items/gun", "items/sword", "player/head", + "player/body"), with one layer hidden ("items/gun"). +* `groups3abc.aseprite`: RGB, 9x11, three groups ("a", "b", "c"), with + three layers each one (called "a", "b", "c" too). There is a + combination of visibilities ("b/b", "c", "c/a", and "c/b" are + hidden). diff --git a/sprites/groups2.aseprite b/sprites/groups2.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..4310c50f4c5d273aafa254440447c7fc92f735e6 GIT binary patch literal 820 zcmcJMJxE(o7>3`QkopIA{1O) z3iWSrannr@916uzIv3kPg?262u`OJmduxpm9R0$5a&x}#ocB4TIVzp)Sb7+KEJ+Se zzKpD3@!o1bBK^K73R88H{F>iNJ25Ms{Pbp7y3nIKI<|=@xK@5LqDVODI5DYMc0)MDd%;wcU7VM2 d2NQ0hwA7ZhCa*RewH2p%^FWKy5@yt)hD#KBrIG*u literal 0 HcmV?d00001 diff --git a/sprites/groups3abc.aseprite b/sprites/groups3abc.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..baced93490dbfcc9c191db909510af39d73e26ef GIT binary patch literal 1202 zcmcJNUr19?9LIlme_ZQs8AP#>;2|V>iLGrEmM{x~$R5Inl|*DNR*rB45rZH^7Lg%? z2+C&UOKt}_A$QBiY`?s~g zRPzp)Pwat{=eEM};S~J({5D*e+X)9}4#V`*Fx+*c2ex&GV0&8=jI=bvc>FvJclNWwMQAWY3J*qL?$Q<5ole7!L_55&uOHrzMBw<5Bz$-AG0fjQ2>UZ( zBh4*b=Krpka0zaJKJJKPjWWK-Vu~h?2x5mCUPxhtj_G0;SfD^Y;Up7FCV`|86*QBS zv+|CaR);1hmkP36!i{;&LRYOF$)&=d?@yDOJE|FuN}#1=h1c9s&2TKsTDvq^F4VZk zzhrFZP`9#fVVD~$!zoV54lVq8`NhaIy%N`_v-0HQ#@R4Mw{lSAb6C|}D91|1A(fK8 z!J}i!C&vdi3|WUerS32NqZ6mU#dUAARVxN0mRjFsHM?nb*$$81z5a8u!5bBA_hyM? z>#v3?CUuzDn}57{Ys~sz_*zQ?m;KLVX3QV5&h{W;Z`bD%<;GktI4m7LnU4APTFqV( z*4Rag4;M2u_sSi=OnLNcmdIK}?9GoxLgh?7BAt0t Date: Wed, 28 Aug 2019 09:19:11 -0300 Subject: [PATCH 097/200] Minor change in layer.lua --- scripts/layer.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/layer.lua b/scripts/layer.lua index c0494dc54..9f4372497 100644 --- a/scripts/layer.lua +++ b/scripts/layer.lua @@ -1,11 +1,12 @@ --- Copyright (C) 2018 David Capello +-- Copyright (C) 2019 Igara Studio S.A. -- -- 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] + local s = Sprite(32, 64) + local l = s.layers[1] + assert(l.parent == s) assert(l.opacity == 255) assert(l.blendMode == BlendMode.NORMAL) From af2adf99f996d934072d417f0741d4adcd841e7b Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 28 Aug 2019 09:19:23 -0300 Subject: [PATCH 098/200] Some tests for layer groups --- scripts/layers.lua | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/scripts/layers.lua b/scripts/layers.lua index ca0edc9c5..344fe8f7f 100644 --- a/scripts/layers.lua +++ b/scripts/layers.lua @@ -1,3 +1,4 @@ +-- Copyright (C) 2019 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -28,3 +29,80 @@ do assert(s.layers[1] == a) assert(s.layers[2] == c) end + +-- Test groups + +do + local s = Sprite(32, 64) + local l = s.layers[1] + assert(#s.layers == 1) + local g = s:newGroup() + assert(#s.layers == 2) + assert(l.parent == s) + assert(g.parent == s) + assert(s.layers[1] == l) + assert(s.layers[2] == g) + + l.parent = g + assert(g.parent == s) + assert(l.parent == g) + + assert(#s.layers == 1) + assert(s.layers[1] == g) + assert(#s.layers[1].layers == 1) + assert(s.layers[1].layers[1] == l) +end + +do + local s = Sprite(4, 4) + -- 4 layers + local a = s.layers[1] a.name = "a" + local b = s:newLayer() b.name = "b" + local c = s:newLayer() c.name = "c" + local d = s:newLayer() d.name = "d" + -- 3 groups + local e = s:newGroup() e.name = "e" + local f = s:newGroup() f.name = "f" + local g = s:newGroup() g.name = "g" + + e.parent = f + a.parent = f + b.parent = f + c.parent = g + d.parent = g + + assert(#s.layers == 2) + assert(s.layers[1] == f) + assert(s.layers[2] == g) + assert(s.layers["f"] == f) + assert(s.layers["g"] == g) + assert(f.stackIndex == 1) + assert(g.stackIndex == 2) + + assert(#f.layers == 3) + assert(f.layers[1] == e) + assert(f.layers[2] == a) + assert(f.layers[3] == b) + assert(f.layers["e"] == e) + assert(f.layers["a"] == a) + assert(f.layers["b"] == b) + assert(e.stackIndex == 1) + assert(a.stackIndex == 2) + assert(b.stackIndex == 3) + + assert(#g.layers == 2) + assert(g.layers[1] == c) + assert(g.layers[2] == d) + assert(g.layers["c"] == c) + assert(g.layers["d"] == d) + assert(c.stackIndex == 1) + assert(d.stackIndex == 2) + + d.stackIndex = 1 + assert(d.stackIndex == 1) + assert(c.stackIndex == 2) + + d.stackIndex = 3 + assert(c.stackIndex == 1) + assert(d.stackIndex == 2) +end From b450229caa0dd85a3e161bfff37d0f132ff4c7f6 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 29 Aug 2019 17:07:49 -0300 Subject: [PATCH 099/200] Add several CLI tests for -save-as with -layer and -ignore-layer --- cli/save-as.sh | 78 +++++++++++++++++++++++++++++++++++++++++- scripts/test_utils.lua | 35 +++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/cli/save-as.sh b/cli/save-as.sh index 0393c571d..b0645ea12 100644 --- a/cli/save-as.sh +++ b/cli/save-as.sh @@ -1,5 +1,5 @@ #! /bin/bash -# Copyright (C) 2018 Igara Studio S.A. +# Copyright (C) 2018-2019 Igara Studio S.A. function list_files() { oldwd=$(pwd) @@ -173,3 +173,79 @@ if [[ ! -f "issue591 (a).png" || exit 1 fi cd $oldwd + +# --save-as group without showing hidden children +# https://github.com/aseprite/aseprite/issues/2084#issuecomment-525835889 + +d=$t/save-as-groups-and-hidden +mkdir $d +$ASEPRITE -b sprites/groups2.aseprite -layer '*' -save-as "$d/g2-all.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer items -save-as "$d/g2-all-without-items.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer gun -save-as "$d/g2-all-without-gun1.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer sword -save-as "$d/g2-all-without-sword1.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer items/gun -save-as "$d/g2-all-without-gun2.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer items/sword -save-as "$d/g2-all-without-sword2.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer player -save-as "$d/g2-all-without-player.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer player -save-as "$d/g2-player.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer items -save-as "$d/g2-items.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer 'items/*' -save-as "$d/g2-items-all.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer sword -save-as "$d/g2-sword.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer gun -save-as "$d/g2-gun.png" || exit 1 + +$ASEPRITE -b sprites/groups3abc.aseprite -layer a -save-as "$d/g3-a.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer b -save-as "$d/g3-b.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer c -save-as "$d/g3-c.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer 'a/*' -save-as "$d/g3-a-all.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer 'b/*' -save-as "$d/g3-b-all.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer 'c/*' -save-as "$d/g3-c-all.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer a/a -save-as "$d/g3-aa.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer b/a -save-as "$d/g3-ba.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer c/a -save-as "$d/g3-ca.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer a/b -save-as "$d/g3-ab.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer b/b -save-as "$d/g3-bb.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer c/b -save-as "$d/g3-cb.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer a/c -save-as "$d/g3-ac.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer b/c -save-as "$d/g3-bc.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer c/c -save-as "$d/g3-cc.png" || exit 1 + +cat >$d/compare.lua < Date: Wed, 11 Sep 2019 19:19:10 -0300 Subject: [PATCH 100/200] Test resizing non-active sprite --- scripts/sprite.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/sprite.lua b/scripts/sprite.lua index 01823ed0a..52fd8b730 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -93,3 +93,23 @@ do assert(#a.layers == 1) assert(#b.layers == 3) end + +-- Resize non-active sprite +do + local a = Sprite(32, 32) + local b = Sprite(64, 64) + app.activeSprite = a + a:resize(10, 10) + b:resize(20, 20) + assert(a.width == 10) + assert(a.height == 10) + assert(b.width == 20) + assert(b.height == 20) + app.undo() + assert(a.width == 32) + assert(a.height == 32) + app.activeSprite = b + app.undo() + assert(b.width == 64) + assert(b.height == 64) +end From 7ded5ec710322e969ab32db8470370d3b905cf14 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 23 Sep 2019 10:22:33 -0300 Subject: [PATCH 101/200] Add some operations (add,sub,mul,etc.) to points/size/rectangles --- scripts/point.lua | 40 +++++++++++++++++++++++++++++++++++++++ scripts/rectangle.lua | 5 ++++- scripts/size.lua | 44 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/scripts/point.lua b/scripts/point.lua index 33309544f..88add18ae 100644 --- a/scripts/point.lua +++ b/scripts/point.lua @@ -33,3 +33,43 @@ assert(pt.y == 25) pt = -pt assert(pt.x == -45) assert(pt.y == -25) + +-- add/sub/mul/div/mod/pow/idiv + +pt = Point(1, 2) + 4 +pt2 = 4 + Point(1, 2) +assert(pt.x == 5) +assert(pt.y == 6) +assert(pt == pt2) + +pt = Point(1, 2) + Point(3, 4) +assert(pt.x == 4) +assert(pt.y == 6) + +pt = Point(3, 4) - 1 +assert(pt.x == 2) +assert(pt.y == 3) + +pt = Point(1, 5) - Point(3, 2) +assert(pt.x == -2) +assert(pt.y == 3) + +pt = Point(6, 10) * 2 +assert(pt.x == 12) +assert(pt.y == 20) + +pt = Point(6, 10) / 2 +assert(pt.x == 3) +assert(pt.y == 5) + +pt = Point(10, 5) % 2 +assert(pt.x == 0) +assert(pt.y == 1) + +pt = Point(2, 5) ^ 2 +assert(pt.x == 4) +assert(pt.y == 25) + +pt = Point(31, 10) // 3 +assert(pt.x == 10) +assert(pt.y == 3) diff --git a/scripts/rectangle.lua b/scripts/rectangle.lua index 5440652a4..a1c2f2c20 100644 --- a/scripts/rectangle.lua +++ b/scripts/rectangle.lua @@ -63,7 +63,10 @@ b = Rectangle{x=3, y=4, width=4, height=5} c = Rectangle{x=3, y=4, width=3, height=4} assert(c == a:intersect(b)) assert(c == b:intersect(a)) +assert((a & b) == c) -- Rectangle:union -assert(Rectangle{x=2, y=3, width=5, height=6} == a:union(b)) +c = Rectangle{x=2, y=3, width=5, height=6} +assert(c == a:union(b)) +assert(c == (a | b)) diff --git a/scripts/size.lua b/scripts/size.lua index 70ecedd7f..1cd6d661a 100644 --- a/scripts/size.lua +++ b/scripts/size.lua @@ -29,3 +29,47 @@ assert(sz.height == 20) sz = Size{45, 25} assert(sz.width == 45) assert(sz.height == 25) + +sz = -sz +assert(sz.width == -45) +assert(sz.height == -25) + +-- add/sub/mul/div/mod/pow/idiv + +sz = Size(1, 2) + 4 +sz2 = 4 + Size(1, 2) +assert(sz.width == 5) +assert(sz.height == 6) +assert(sz == sz2) + +sz = Size(1, 2) + Size(3, 4) +assert(sz.width == 4) +assert(sz.height == 6) + +sz = Size(3, 4) - 1 +assert(sz.width == 2) +assert(sz.height == 3) + +sz = Size(8, 5) - Size(3, 2) +assert(sz.width == 5) +assert(sz.height == 3) + +sz = Size(6, 10) * 2 +assert(sz.width == 12) +assert(sz.height == 20) + +sz = Size(6, 10) / 2 +assert(sz.width == 3) +assert(sz.height == 5) + +sz = Size(10, 5) % 2 +assert(sz.width == 0) +assert(sz.height == 1) + +sz = Size(2, 5) ^ 2 +assert(sz.width == 4) +assert(sz.height == 25) + +sz = Size(31, 10) // 3 +assert(sz.width == 10) +assert(sz.height == 3) From 3c336cb9972f6190a9c66beee60cdbfdcb3cf17b Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 1 Oct 2019 09:37:39 -0300 Subject: [PATCH 102/200] Add test for AddColor command --- scripts/app_command.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/app_command.lua b/scripts/app_command.lua index 500690f8f..1a1fd8f14 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -482,3 +482,28 @@ do p:setColor(4, Color(0, 0, 0)) p:setColor(5, Color(0, 255, 0)) end + +-- AddColor +do + local s = Sprite(32, 32) + local p = s.palettes[1] + + function testAddColor(color) + assert(p:getColor(#p-1) ~= color) + app.command.AddColor{ color=color } + assert(p:getColor(#p-1) == color) + end + testAddColor(Color(255, 0, 0)) + testAddColor(Color(0, 255, 0)) + testAddColor(Color(0, 0, 255)) + + local color = Color(128, 0, 0) + app.preferences.color_bar.fg_color = color + app.command.AddColor{ source="fg" } + assert(p:getColor(#p-1) == color) + + local color = Color(0, 0, 128) + app.preferences.color_bar.bg_color = color + app.command.AddColor{ source="bg" } + assert(p:getColor(#p-1) == color) +end From 4fb4c30ecb30ee2e47e9dec1786bc147ead01d71 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 1 Oct 2019 10:12:22 -0300 Subject: [PATCH 103/200] Check that -sheet keeps the transparent color index of the source --- cli/sheet.sh | 14 ++++++++++++++ sprites/README.md | 2 ++ sprites/bg-index-3.aseprite | Bin 0 -> 367 bytes 3 files changed, 16 insertions(+) create mode 100644 sprites/bg-index-3.aseprite diff --git a/cli/sheet.sh b/cli/sheet.sh index 33b79f77d..6719c299e 100644 --- a/cli/sheet.sh +++ b/cli/sheet.sh @@ -119,3 +119,17 @@ end assert(expected:isEqual(sheet.cels[1].image)) EOF $ASEPRITE -b -script "$d/compare.lua" || exit 1 + +# Test that the transparent color persists in the output sheet + +d=$t/sheet-custom-transparent-index +if ! $ASEPRITE -b sprites/bg-index-3.aseprite -sheet "$d/sheet.aseprite" -data "$d/sheet.json" ; then + exit 1 +fi +cat >$d/compare.lua <bALM|QBS>_D~{5VI?wTWJIo zl~iB>k{|$b7Xr-Q!~dUwp?eL8G)OW4lKd9@|3T&e-3}yx@<2(T3{Y4KB&vX{AE=yx zi6JQ+mrPo^Do_Qh0s}Z~{xbnNV88@4y<$#sLIaQo3^xrR#R_&dBLhMa3(#nwqNJph M6s9Bw1}6qy0KZQj>;M1& literal 0 HcmV?d00001 From 6117e064cb03013e4d11079aca17278f042335cb Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 1 Oct 2019 20:45:18 -0300 Subject: [PATCH 104/200] Add test for https://github.com/aseprite/aseprite/issues/2116 --- cli/sheet.sh | 36 +++++++++++++++++++++++++++++++++++- sprites/README.md | 3 +++ sprites/tags3.aseprite | Bin 0 -> 1648 bytes 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 sprites/tags3.aseprite diff --git a/cli/sheet.sh b/cli/sheet.sh index 6719c299e..19a13b7f3 100644 --- a/cli/sheet.sh +++ b/cli/sheet.sh @@ -20,7 +20,7 @@ cat >$d/compare.lua <$d/check.lua <Y)mHsUXDTR$afDB%6)UqzgJ>zwEx5_x}IQOld&m)1zUr z_}LN?kwu=)Af|%|z|*lQn4LHd z*XJhT*0nLX`7jH=zkUFBew>8&zn+KrmvK0Lw*Y5y$KdSDQJ9#TfXU^#3KfAhc$d*3P;#cUR)O!SU?|fl#xXfLDY~MRZ6xA z+XD+IFYGpPWw(j+Jc-e+QvR|`h9z4pUtcIMTD*20W?0IZN~XM=8I%LU*>}dElyZfo zQn9cUC%Dg6Glsa{8jG)LJ)KIWV$0i3Cl)%p(ma!d9* z=C7DuWoSE{sw$^i{}y@rdn@urMz*bFg>_ED)HhPK71en_RrmGMRyFpds@mwKdX9Og zVQ5vgw!f;`Rj<3(pw&Y1FRMw Date: Wed, 2 Oct 2019 09:13:55 -0300 Subject: [PATCH 105/200] Remove call to aseprite -help --- cli/sheet.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/sheet.sh b/cli/sheet.sh index 19a13b7f3..be7d79094 100644 --- a/cli/sheet.sh +++ b/cli/sheet.sh @@ -139,7 +139,6 @@ $ASEPRITE -b -script "$d/compare.lua" || exit 1 # -layer -trim -ignore-empty -list-tags -sheet -data d=$t/sheet-trim-without-ignore-empty -$ASEPRITE -help $ASEPRITE -b \ -list-tags \ -layer "c" \ From 4ddb08203aa3ab0bb5456ecb3e4334bc8b6ad25d Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 1 Nov 2019 15:06:11 -0300 Subject: [PATCH 106/200] Test that Sprite.gridBounds property is saved inside .aseprite files --- scripts/sprite.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/sprite.lua b/scripts/sprite.lua index 52fd8b730..e9846bdb1 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -113,3 +113,15 @@ do assert(b.width == 64) assert(b.height == 64) end + +-- Grid bounds +do + local s = Sprite(32, 32) + assert(s.gridBounds == Rectangle{0, 0, 16, 16}) + s.gridBounds = Rectangle{2, 3, 8, 4} + assert(s.gridBounds == Rectangle{2, 3, 8, 4}) + s:saveAs("_test_sprite_gridbounds.png") + + local s2 = Sprite{ fromFile="_test_sprite_gridbounds.png" } + assert(s.gridBounds == Rectangle{2, 3, 8, 4}) +end From fdf8adc947d52074f00918aadde26141090cde56 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 1 Nov 2019 15:21:26 -0300 Subject: [PATCH 107/200] Add tests to compare -sheet-type columns vs. rows and -trim vs -trim-sprite --- cli/sheet.sh | 39 ++++++++++++++++++++ scripts/compare_sprite_sheets.lua | 60 +++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 scripts/compare_sprite_sheets.lua diff --git a/cli/sheet.sh b/cli/sheet.sh index be7d79094..8fa574d62 100644 --- a/cli/sheet.sh +++ b/cli/sheet.sh @@ -166,3 +166,42 @@ assert(#sheet1.frames == 12) assert(#sheet2.frames == 4) EOF $ASEPRITE -b -script "$d/check.lua" || exit 1 + +# -sheet -sheet-columns vs -sheet-rows + +d=$t/sheet-columns-and-rows +$ASEPRITE -b -split-layers sprites/1empty3.aseprite \ + -filename-format "{layer}{frame}" \ + -sheet "$d/sheet1.png" \ + -sheet-type rows \ + -sheet-columns 3 \ + -data "$d/sheet1.json" || exit $? +$ASEPRITE -b -split-layers sprites/1empty3.aseprite \ + -filename-format "{layer}{frame}" \ + -sheet "$d/sheet2.png" \ + -sheet-type columns \ + -sheet-rows 3 \ + -data "$d/sheet2.json" || exit $? +$ASEPRITE -b \ + -script-param file1=$d/sheet1.json \ + -script-param file2=$d/sheet2.json \ + -script scripts/compare_sprite_sheets.lua || exit $? + +# -sheet -trim vs -trim-sprite + +d=$t/sheet-columns-and-rows +$ASEPRITE -b -split-layers sprites/1empty3.aseprite \ + -trim \ + -filename-format "{layer}{frame}" \ + -sheet "$d/sheet1.png" \ + -data "$d/sheet1.json" || exit $? + +$ASEPRITE -b -split-layers sprites/1empty3.aseprite \ + -trim-sprite \ + -filename-format "{layer}{frame}" \ + -sheet "$d/sheet2.png" \ + -data "$d/sheet2.json" || exit $? +$ASEPRITE -b \ + -script-param file1=$d/sheet1.json \ + -script-param file2=$d/sheet2.json \ + -script scripts/compare_sprite_sheets.lua || exit $? diff --git a/scripts/compare_sprite_sheets.lua b/scripts/compare_sprite_sheets.lua new file mode 100644 index 000000000..d786ceb7b --- /dev/null +++ b/scripts/compare_sprite_sheets.lua @@ -0,0 +1,60 @@ +-- Copyright (C) 2019 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local file1 = app.params["file1"] +local file2 = app.params["file2"] +if file1 == nil or file2 == nil then + return 0 +end + +local json = dofile('../third_party/json/json.lua') +local data1 = json.decode(io.open(file1):read('a')) +local data2 = json.decode(io.open(file2):read('a')) + +if data1 == nil then + print('Cannot read file ' .. file1) + return 1 +elseif data2 == nil then + print('Cannot read file ' .. file2) + return 1 +end + +local function replace_filename(fn, newfn) + return string.gsub(fn, "(.*)[/\\]([^/\\]+)", "%1/"..newfn) +end + +local sheet1 = app.open(replace_filename(file1, data1.meta.image)) +local sheet2 = app.open(replace_filename(file2, data2.meta.image)) + +for k,v in pairs(data1.frames) do + local fr1 = data1.frames[k] + local fr2 = data2.frames[k] + if fr1.duration ~= fr2.duration then + print('Frame '..k..' doesn\'t match duration') + return 1 + end + if fr1.sourceSize.w ~= fr2.sourceSize.w or + fr1.sourceSize.h ~= fr2.sourceSize.h then + print('Frame '..k..' doesn\'t match sourceSize') + return 1 + end + + local celImage1 = Image(fr1.frame.w, fr1.frame.h, sheet1.colorMode) + local celImage2 = Image(fr2.frame.w, fr2.frame.h, sheet2.colorMode) + celImage1:drawSprite(sheet1, 1, -fr1.frame.x, -fr1.frame.y) + celImage2:drawSprite(sheet2, 1, -fr2.frame.x, -fr2.frame.y) + + local frImage1 = Image(fr1.sourceSize.w, fr1.sourceSize.h, sheet1.colorMode) + local frImage2 = Image(fr2.sourceSize.w, fr2.sourceSize.h, sheet2.colorMode) + frImage1:drawImage(celImage1, fr1.spriteSourceSize.x, fr1.spriteSourceSize.y) + frImage2:drawImage(celImage2, fr2.spriteSourceSize.x, fr2.spriteSourceSize.y) + + -- To debug this function + --frImage1:saveAs(replace_filename(file1, k .. "-fr1.png")) + --frImage2:saveAs(replace_filename(file2, k .. "-fr2.png")) + --print(k, "fr1", fr1.frame.x, fr1.frame.y, "fr2", fr2.frame.x, fr2.frame.y) + + assert(frImage1:isEqual(frImage2)) +end From a14a0a321d962c90a28586360af24ff018af5716 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 1 Nov 2019 15:53:15 -0300 Subject: [PATCH 108/200] Test all -sheet-types --- cli/sheet.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/cli/sheet.sh b/cli/sheet.sh index 8fa574d62..373bfe517 100644 --- a/cli/sheet.sh +++ b/cli/sheet.sh @@ -205,3 +205,41 @@ $ASEPRITE -b \ -script-param file1=$d/sheet1.json \ -script-param file2=$d/sheet2.json \ -script scripts/compare_sprite_sheets.lua || exit $? + +# Test all sprite sheet types +# -sheet horizontal/vertical/rows/columns/packed +d=$t/sheet-all-types +for type in horizontal vertical rows columns packed ; do + $ASEPRITE -b "sprites/tags3.aseprite" \ + -sheet-type $type -sheet "$d/$type.png" \ + -format json-array -data "$d/$type.json" || exit $? + + $ASEPRITE -b -split-layers "sprites/tags3.aseprite" \ + -sheet-type $type -sheet "$d/$type-layers.png" \ + -format json-array -data "$d/$type-layers.json" || exit $? + + $ASEPRITE -b -split-layers -merge-duplicates "sprites/tags3.aseprite" \ + -sheet-type $type -sheet "$d/$type-layers-merge-duplicates.png" \ + -format json-array -data "$d/$type-layers-merge-duplicates.json" || exit $? + + $ASEPRITE -b -split-tags "sprites/tags3.aseprite" \ + -sheet-type $type -sheet "$d/$type-tags.png" \ + -format json-array -data "$d/$type-tags.json" || exit $? + + $ASEPRITE -b -split-tags -trim "sprites/tags3.aseprite" \ + -sheet-type $type -sheet "$d/$type-tags-trim.png" \ + -format json-array -data "$d/$type-tags-trim.json" || exit $? + + $ASEPRITE -b -split-layers -split-tags "sprites/tags3.aseprite" \ + -sheet-type $type -sheet "$d/$type-layer-tags.png" \ + -format json-array -data "$d/$type-layer-tags.json" || exit $? +done + +for type in horizontal vertical rows columns ; do + for subtype in "" "-layers" "-layers-merge-duplicates" "-tags" "-tags-trim" "-layer-tags" ; do + $ASEPRITE -b \ + -script-param file1=$d/packed$subtype.json \ + -script-param file2=$d/$type$subtype.json \ + -script scripts/compare_sprite_sheets.lua || exit $? + done +done From 7ebaaf485ac32398936e5f9bcbd96893e3db0afd Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 29 Nov 2019 11:06:52 -0300 Subject: [PATCH 109/200] Add more tests for Layer.stackIndex setter --- scripts/layers.lua | 48 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/scripts/layers.lua b/scripts/layers.lua index 344fe8f7f..3519eeaa8 100644 --- a/scripts/layers.lua +++ b/scripts/layers.lua @@ -102,7 +102,53 @@ do assert(d.stackIndex == 1) assert(c.stackIndex == 2) - d.stackIndex = 3 + d.stackIndex = 2 assert(c.stackIndex == 1) assert(d.stackIndex == 2) + + c.stackIndex = 2 + assert(d.stackIndex == 1) + assert(c.stackIndex == 2) +end + +-- Test possible bugs with stackIndex +do + local s = Sprite(4, 4) + local a = s.layers[1] a.name = "a" + local b = s:newLayer() b.name = "b" + local c = s:newLayer() c.name = "c" + local d = s:newLayer() d.name = "d" + assert(d.stackIndex == 4) + assert(s.layers[4].name == "d") + + d.stackIndex = d.stackIndex+1 + assert(d.stackIndex == 4) + assert(s.layers[4].name == "d") + + -- Go down in the stack + d.stackIndex = d.stackIndex-1 + assert(s.layers[3].name == "d") + + d.stackIndex = d.stackIndex-1 + assert(s.layers[2].name == "d") + + -- Without change + d.stackIndex = d.stackIndex + assert(s.layers[2].name == "d") + + -- Go up + d.stackIndex = d.stackIndex+1 + assert(d.stackIndex == 3) + assert(s.layers[3].name == "d") + + d.stackIndex = d.stackIndex+1 + assert(d.stackIndex == 4) + assert(s.layers[4].name == "d") + + -- Go specific stack indexes + for i=1,4 do + d.stackIndex = i + assert(d.stackIndex == i) + assert(s.layers[i].name == "d") + end end From 47b3098c8b0aa124b2255fa04b58e5b593577f0d Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 2 Dec 2019 19:27:04 -0300 Subject: [PATCH 110/200] Add tests for default vs specific document preferences --- run-tests.sh | 1 + scripts/app_preferences.lua | 88 +++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index bf1874422..bd52f6100 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -34,6 +34,7 @@ fi t=$(mktemp -d) echo Temp dir: $t +export ASEPRITE_USER_FOLDER=$t if [[ "$filter" == "" ]] || [[ "console" =~ $filter ]]; then echo ---------------------------------------------------------------------- diff --git a/scripts/app_preferences.lua b/scripts/app_preferences.lua index c03b197c8..5737c86aa 100644 --- a/scripts/app_preferences.lua +++ b/scripts/app_preferences.lua @@ -22,10 +22,98 @@ end -- Preferences for documents do + local defPref = app.preferences.document(nil) + defPref.grid.bounds = Rectangle(0, 0, 16, 16) + local s = Sprite(32, 32) local p = app.preferences.document(s) + assert(s.gridBounds == Rectangle(0, 0, 16, 16)) assert(p.grid.bounds == Rectangle(0, 0, 16, 16)) assert(p.grid.color == Color(0, 0, 255)) p.grid.color = Color(255, 0, 0) assert(p.grid.color == Color(255, 0, 0)) end + +-- Default & doc preferences combinations (related to https://community.aseprite.org/t/4305) +do + -- Set default preferences + local defPref = app.preferences.document(nil) + defPref.grid.bounds = Rectangle(0, 0, 10, 10) + defPref.grid.color = Color(255, 255, 0) -- White + assert(defPref.grid.bounds == Rectangle(0, 0, 10, 10)) + assert(defPref.grid.color == Color(255, 255, 0)) + + do -- File with default preferences + local doc = Sprite(32, 32) + local docPref = app.preferences.document(doc) + assert(doc.gridBounds == Rectangle(0, 0, 10, 10)) + assert(docPref.grid.bounds == Rectangle(0, 0, 10, 10)) + assert(docPref.grid.color == Color(255, 255, 0)) + doc:saveAs('_test_pref.png') + doc:close() + end + + do -- File with specific preferences + local doc = Sprite(32, 32) + local docPref = app.preferences.document(doc) + docPref.grid.color = Color(0, 128, 0) + assert(docPref.grid.bounds == Rectangle(0, 0, 10, 10)) + assert(docPref.grid.color == Color(0, 128, 0)) + doc:saveAs('_test_pref2.png') + doc:close() + end + + -- Now we change default preferences + defPref.grid.bounds = Rectangle(0, 0, 64, 64) + defPref.grid.color = Color(255, 0, 0) -- Red + assert(defPref.grid.bounds == Rectangle(0, 0, 64, 64)) + assert(defPref.grid.color == Color(255, 0, 0)) + do -- A new document should have the new default preferences + local doc = Sprite(32, 32) + local docPref = app.preferences.document(doc) + assert(docPref.grid.bounds == Rectangle(0, 0, 64, 64)) + assert(docPref.grid.color == Color(255, 0, 0)) + doc:close() + end + do -- The first document should have the new default preferences (because it was saved with the defaults) + + -- TODO maybe related to https://community.aseprite.org/t/grid-for-new-documents/3303 + -- should we get the new defaults or the values when we saved the document? + -- (e.g. even if we didn't change the grid values, it looks + -- like if the user changed something about the grid or the + -- background colors, the expected behavior would be to + -- restore the exact same colors, no the new defaults) + + local doc = Sprite{ fromFile="_test_pref.png" } + local docPref = app.preferences.document(doc) + assert(docPref.grid.bounds == Rectangle(0, 0, 64, 64)) + assert(docPref.grid.color == Color(255, 0, 0)) + doc:close() + end + do -- The second document should have the new specific preferences for the grid color + local doc = Sprite{ fromFile="_test_pref2.png" } + local docPref = app.preferences.document(doc) + assert(docPref.grid.bounds == Rectangle(0, 0, 64, 64)) + assert(docPref.grid.color == Color(0, 128, 0)) + doc:close() + end +end + +do -- Test symmetry preferences + do -- File with default preferences + local doc = Sprite(200, 100) + local docPref = app.preferences.document(doc) + assert(docPref.symmetry.x_axis == 100) + assert(docPref.symmetry.y_axis == 50) + docPref.symmetry.x_axis = 25 + doc:saveAs('_test_symmetry.png') + doc:close() + end + do -- File with default preferences + local doc = Sprite{ fromFile='_test_symmetry.png' } + local docPref = app.preferences.document(doc) + assert(docPref.symmetry.x_axis == 25) + assert(docPref.symmetry.y_axis == 50) + doc:close() + end +end From e857b0e3e56ac0a3d00476624af8ad8c33473751 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 11 Dec 2019 14:44:29 -0300 Subject: [PATCH 111/200] Fix running Lua scripts that use temp dir ($t) on Windows --- cli/save-as.sh | 4 ++-- run-tests.sh | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/save-as.sh b/cli/save-as.sh index b0645ea12..a5f6ad8fe 100644 --- a/cli/save-as.sh +++ b/cli/save-as.sh @@ -2,7 +2,7 @@ # Copyright (C) 2018-2019 Igara Studio S.A. function list_files() { - oldwd=$(pwd) + oldwd=$(pwd $PWDARG) cd $1 && ls -1 *.* cd $oldwd } @@ -162,7 +162,7 @@ $ASEPRITE -b -script "$d/compare.lua" || exit 1 d=$t/save-as-without-path mkdir $d -oldwd=$(pwd) +oldwd=$(pwd $PWDARG) cd $d $ASEPRITE -b -split-layers $oldwd/sprites/abcd.aseprite -save-as issue591.png || exit 1 if [[ ! -f "issue591 (a).png" || diff --git a/run-tests.sh b/run-tests.sh index bd52f6100..c04686469 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -33,6 +33,12 @@ if [[ "$filter" != "" ]]; then fi t=$(mktemp -d) +if [[ "$(uname)" =~ "MINGW32" ]] || [[ "$(uname)" =~ "MSYS_NT-10.0" ]] ; then + PWDARG=-W + t=$(cd "$t" && pwd $PWDARG) +else + PWDARG= +fi echo Temp dir: $t export ASEPRITE_USER_FOLDER=$t From 2380719a3fe09282f5717f1dbb8a82a09fbd0ee1 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 11 Dec 2019 14:45:03 -0300 Subject: [PATCH 112/200] Fix some comments in app_preferences.lua --- scripts/app_preferences.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/app_preferences.lua b/scripts/app_preferences.lua index 5737c86aa..9c2a96c4f 100644 --- a/scripts/app_preferences.lua +++ b/scripts/app_preferences.lua @@ -39,7 +39,7 @@ do -- Set default preferences local defPref = app.preferences.document(nil) defPref.grid.bounds = Rectangle(0, 0, 10, 10) - defPref.grid.color = Color(255, 255, 0) -- White + defPref.grid.color = Color(255, 255, 0) -- Yellow assert(defPref.grid.bounds == Rectangle(0, 0, 10, 10)) assert(defPref.grid.color == Color(255, 255, 0)) @@ -56,7 +56,7 @@ do do -- File with specific preferences local doc = Sprite(32, 32) local docPref = app.preferences.document(doc) - docPref.grid.color = Color(0, 128, 0) + docPref.grid.color = Color(0, 128, 0) -- Green assert(docPref.grid.bounds == Rectangle(0, 0, 10, 10)) assert(docPref.grid.color == Color(0, 128, 0)) doc:saveAs('_test_pref2.png') From 0fd04fd57f8834c29c832bdab675cd1a509f27f3 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 11 Dec 2019 15:44:03 -0300 Subject: [PATCH 113/200] Add app.fs tests --- scripts/app_fs.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 scripts/app_fs.lua diff --git a/scripts/app_fs.lua b/scripts/app_fs.lua new file mode 100644 index 000000000..e34c9e803 --- /dev/null +++ b/scripts/app_fs.lua @@ -0,0 +1,52 @@ +-- Copyright (C) 2019 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local fs = app.fs +local sep = fs.pathSeparator + +assert('' == fs.filePath('first.png')) +assert('path' == fs.filePath('path/second.png')) +assert('C:\\path' == fs.filePath('C:\\path\\third.png')) + +assert('first.png' == fs.fileName('first.png')) +assert('second.png' == fs.fileName('path/second.png')) +assert('third.png' == fs.fileName('C:\\path\\third.png')) + +assert('first' == fs.fileTitle('first.png')) +assert('second' == fs.fileTitle('path/second.png')) +assert('third' == fs.fileTitle('C:\\path\\third.png')) + +assert('first' == fs.filePathAndTitle('first.png')) +assert('path/second' == fs.filePathAndTitle('path/second.png')) +assert('C:\\path\\third' == fs.filePathAndTitle('C:\\path\\third.png')) + +assert('hi/bye' == fs.joinPath('hi/', 'bye')) +assert('hi/bye' .. sep .. 'smth.png' == fs.joinPath('hi/', 'bye', 'smth.png')) + +local pwd = fs.currentPath +assert(pwd ~= nil) +assert(fs.isDirectory(pwd)) +assert(not fs.isFile(pwd)) +assert(fs.isFile(fs.joinPath(pwd, 'run-tests.sh'))) + +do + local runTestsFound = false + local readmeFound = false + local files = fs.listFiles(pwd) + for i in pairs(files) do + if files[i] == 'run-tests.sh' then + runTestsFound = true + elseif files[i] == 'README.md' then + readmeFound = true + end + + local fullFs = fs.joinPath(pwd, files[i]) + if fs.isFile(fullFs) then + assert(fs.fileSize(fullFs) > 0) + end + end + assert(runTestsFound) + assert(readmeFound) +end From 1db7233496a66a0e30707204c988c752423e2969 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 11 Dec 2019 23:50:37 -0300 Subject: [PATCH 114/200] Test that the crash when we called print() on a __gc at exit is fixed --- scripts/print_on_gc.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 scripts/print_on_gc.lua diff --git a/scripts/print_on_gc.lua b/scripts/print_on_gc.lua new file mode 100644 index 000000000..f39c50fce --- /dev/null +++ b/scripts/print_on_gc.lua @@ -0,0 +1,10 @@ +-- Copyright (C) 2019 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +-- Create global variable which will be GC'd on lua_close() +a = { } + +-- Call print() on __gc, in previous version this produced a crash at exit +setmetatable(a, { __gc=function() print('gc') end }) From ade7285ff68ec1cdf06a5a92ce22416e8376813f Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 13 Jan 2020 11:19:15 -0300 Subject: [PATCH 115/200] Add test for app.fs.fileExtension --- scripts/app_fs.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/app_fs.lua b/scripts/app_fs.lua index e34c9e803..ab2fa6235 100644 --- a/scripts/app_fs.lua +++ b/scripts/app_fs.lua @@ -14,6 +14,8 @@ assert('first.png' == fs.fileName('first.png')) assert('second.png' == fs.fileName('path/second.png')) assert('third.png' == fs.fileName('C:\\path\\third.png')) +assert('png' == fs.fileExtension('path/file.png')) + assert('first' == fs.fileTitle('first.png')) assert('second' == fs.fileTitle('path/second.png')) assert('third' == fs.fileTitle('C:\\path\\third.png')) From b43e21baba0062076534063f57169ad26dce2225 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 13 Jan 2020 11:22:42 -0300 Subject: [PATCH 116/200] Test fix for Palette:setEntry() when alpha channel is involved --- scripts/palette.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/palette.lua b/scripts/palette.lua index 9a65b451a..6a22abfc1 100644 --- a/scripts/palette.lua +++ b/scripts/palette.lua @@ -29,6 +29,12 @@ do assert(p:getColor(1) == Color(250, 4, 30)) assert(p:getColor(2) == Color(240, 3, 20)) assert(p:getColor(3) == Color(210, 2, 10)) + + -- Check alpha + local c = Color{red=100, green=50, blue=10, alpha=128} + p:setColor(3, c) + assert(p:getColor(3) == c) + assert(p:getColor(3).alpha == 128) end -- Load/save From adc97fffb731bf891be4ff47ce6d59689d7e2d3e Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 13 Jan 2020 12:29:37 -0300 Subject: [PATCH 117/200] Test new function to save images with a specific palette --- LICENSE.txt | 2 +- scripts/image.lua | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index aee5744c4..73cdac56d 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2018-2019 Igara Studio S.A. +Copyright (c) 2018-2020 Igara Studio S.A. Copyright (c) 2018 David Capello Permission is hereby granted, free of charge, to any person obtaining diff --git a/scripts/image.lua b/scripts/image.lua index 5d6fa0642..5f542afb5 100644 --- a/scripts/image.lua +++ b/scripts/image.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019 Igara Studio S.A. +-- Copyright (C) 2019-2020 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -95,6 +95,47 @@ do end end +-- Save indexed image and load and check that the palette is the same +do + local spr = Sprite{ fromFile="sprites/abcd.aseprite" } + local img = Image{ fromFile="sprites/abcd.aseprite" } + spr.cels[1].image:saveAs("_test_palette_a.png") + img:saveAs("_test_palette_b.png") -- This file will contain a black palette + img:saveAs{ filename="_test_palette_c.png", palette=spr.palettes[1] } + + local a = Sprite{ fromFile="_test_palette_a.png" } + local b = Sprite{ fromFile="_test_palette_b.png" } + local c = Sprite{ fromFile="_test_palette_c.png" } + + assert(a.width == 5) + assert(a.height == 7) + assert(b.width == 32) + assert(b.height == 32) + assert(c.width == 32) + assert(c.height == 32) + local bimg = b.cels[1].image + local cimg = c.cels[1].image + for y=0,31 do + for x=0,31 do + assert(bimg:getPixel(x, y) == cimg:getPixel(x, y)) + end + end + + local apal = a.palettes[1] + local bpal = b.palettes[1] + local cpal = c.palettes[1] + -- Same palette in a and c + assert(#apal == #cpal) + for i=0,#apal-1 do + assert(apal:getColor(i) == cpal:getColor(i)) + end + -- b should contain a complete black palette + assert(bpal:getColor(0) == Color(0, 0, 0, 0)) + for i=1,#bpal-1 do + assert(bpal:getColor(i) == Color(0, 0, 0, 255)) + end +end + -- Resize image do local a = Sprite(3, 2) From b69023038765d9a64eae149e6a576ccf482b7fae Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 6 Feb 2020 11:54:55 -0300 Subject: [PATCH 118/200] Test that "spriteSourceSize" are generated correctly when -trim -merge-duplicates are used together --- cli/sheet.sh | 31 ++++++++++++++++++++++++++++++- sprites/README.md | 4 ++++ sprites/point4frames.aseprite | Bin 0 -> 591 bytes 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 sprites/point4frames.aseprite diff --git a/cli/sheet.sh b/cli/sheet.sh index 373bfe517..d633fefcd 100644 --- a/cli/sheet.sh +++ b/cli/sheet.sh @@ -1,5 +1,5 @@ #! /bin/bash -# Copyright (C) 2019 Igara Studio S.A. +# Copyright (C) 2019-2020 Igara Studio S.A. # $1 = first sprite sheet json file # $2 = second sprite sheet json file @@ -243,3 +243,32 @@ for type in horizontal vertical rows columns ; do -script scripts/compare_sprite_sheets.lua || exit $? done done + +# "Trim Cels" (-trim) with -merge-duplicates didn't generate the +# correct "spriteSourceSize" for each frame. +# https://igarastudio.zendesk.com/agent/tickets/407 +d=$t/ticket-407 +for layer in a b ; do + $ASEPRITE -b -layer "$layer" "sprites/point4frames.aseprite" \ + -trim \ + -data "$d/data1-$layer.json" \ + -format json-array -sheet "$d/sheet1-$layer.png" || exit 1 + $ASEPRITE -b -layer "$layer" "sprites/point4frames.aseprite" \ + -trim -merge-duplicates \ + -data "$d/data2-$layer.json" \ + -format json-array -sheet "$d/sheet2-$layer.png" || exit 1 + cat >$d/compare.lua <z{*fDCpjS{B_+XyRlyDzI9d#189+6^J~Dy508$Fm%K~%;A-xc_ yj6jvx)Fve*B{+fYVX|h>#$^vX13S_7U{{N3j}6#Aj9~wOA_C?gZU%0G_5c9Lvpe4a literal 0 HcmV?d00001 From 0b0fbecc26032bc1717c4c7d95150e0c8e41ad79 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 6 Feb 2020 14:40:55 -0300 Subject: [PATCH 119/200] Test that "sourceSize" fields are generated correctly When two similar cels from two different sprites with different canvas size are merged together we have to keep the "sourceSize" of each original sprite. --- cli/sheet.sh | 31 ++++++++++++++++++++++++++++++- sprites/README.md | 4 ++++ sprites/point2frames.aseprite | Bin 0 -> 358 bytes 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 sprites/point2frames.aseprite diff --git a/cli/sheet.sh b/cli/sheet.sh index d633fefcd..6aa801142 100644 --- a/cli/sheet.sh +++ b/cli/sheet.sh @@ -261,7 +261,8 @@ for layer in a b ; do local json = dofile('third_party/json/json.lua') local data1 = json.decode(io.open('$d/data1-$layer.json'):read('a')) local data2 = json.decode(io.open('$d/data2-$layer.json'):read('a')) -for i = 1,4 do +assert(#data1.frames == #data2.frames) +for i = 1,#data1.frames do local a = data1.frames[i].spriteSourceSize local b = data2.frames[i].spriteSourceSize assert(a.x == b.x) @@ -272,3 +273,31 @@ end EOF $ASEPRITE -b -script "$d/compare.lua" || exit 1 done + +# Same problem as in ticket 407 but with "sourceSize" field and +# different sprites in the same texture atlas. +d=$t/ticket-407-w-atlas +$ASEPRITE -b \ + -layer a "sprites/point4frames.aseprite" \ + "sprites/point2frames.aseprite" \ + -data "$d/data1.json" \ + -format json-array -sheet "$d/sheet1.png" || exit 1 +$ASEPRITE -b \ + -layer a "sprites/point4frames.aseprite" \ + "sprites/point2frames.aseprite" \ + -trim \ + -data "$d/data2.json" \ + -format json-array -sheet-pack -sheet "$d/sheet2.png" || exit 1 +cat >$d/compare.lua <mw`JR#qTe42ankz*Ztz zrvqe5DlkJun2=<^%>N7wt{OH#@;}3d|H42a7LZRs%E7`LBtb%O?I0~cwLm3_Aahw2 yKui{f|8Qej8CV%A<|HSiq@*OcuqxOA!$6Bc%m%3T*GERMOF`~~=>^$ENG|}BB^{Ii literal 0 HcmV?d00001 From 22c5c2d5475110f16438e3db1bde70df1516a158 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 11 Feb 2020 09:36:48 -0300 Subject: [PATCH 120/200] Test bugs using image brush + tiled mode --- scripts/test_utils.lua | 29 +++++++++++------- scripts/tools.lua | 69 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 12 deletions(-) diff --git a/scripts/test_utils.lua b/scripts/test_utils.lua index bea00fe13..e6344bb5d 100644 --- a/scripts/test_utils.lua +++ b/scripts/test_utils.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019 Igara Studio S.A. +-- Copyright (C) 2019-2020 Igara Studio S.A. -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. @@ -13,11 +13,26 @@ function expect_eq(a, b) end end +local function dump_img(image) + local w = image.width + local h = image.height + print('Image(' .. tostring(w) .. 'x' .. tostring(h) .. ') = {') + for v=0,h-1 do + local lineStr = ' ' + for u=0,w-1 do + lineStr = lineStr .. image:getPixel(u, v) .. ',' + end + print(lineStr) + end + print('}') +end + function expect_img(image, expectedPixels) local w = image.width local h = image.height if w*h ~= #expectedPixels then print(debug.traceback()) + dump_img(image) assert(w*h == #expectedPixels) end for y=0,h-1 do @@ -25,15 +40,7 @@ function expect_img(image, expectedPixels) local value = image:getPixel(x, y) local expected = expectedPixels[1+y*w+x] if value ~= expected then - print('Image(' .. tostring(w) .. 'x' .. tostring(h) .. ') = {') - for v=0,h-1 do - lineStr = ' ' - for u=0,w-1 do - lineStr = lineStr .. image:getPixel(u, v) .. ',' - end - print(lineStr) - end - print('}') + dump_img(image) print('In pixel (' .. x .. ', ' .. y .. '):') local a = value @@ -51,7 +58,7 @@ function expect_img(image, expectedPixels) app.pixelColor.rgbaG(b), app.pixelColor.rgbaB(b), app.pixelColor.rgbaA(b))) - elseif image.ColorMode == ColorMode.GRAY then + elseif image.colorMode == ColorMode.GRAY then print(string.format(' - Value A = gray(%d,%d)', app.pixelColor.grayG(a), app.pixelColor.grayA(a))) diff --git a/scripts/tools.lua b/scripts/tools.lua index f52975802..aa4e51559 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019 Igara Studio S.A. +-- Copyright (C) 2019-2020 Igara Studio S.A. -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. @@ -552,3 +552,70 @@ do expect_img(cel.image, { 0, 0, 0, 0 }) end + +---------------------------------------------------------------------- +-- draw with tiled mode + image brush +-- test for: https://community.aseprite.org/t/tile-mode-glitch/1183 +---------------------------------------------------------------------- + +function drawing_with_tiled_mode_and_image_brush() + print("drawing_with_tiled_mode_and_image_brush") + local spr = Sprite(8, 3, ColorMode.INDEXED) + local cel = spr.cels[1] + + -- enable tiled mode + local pref = app.preferences + local docPref = pref.document(spr) + docPref.tiled.mode = 3 -- both + + expect_img(cel.image, + { 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }) + + -- Create brush + local brushImg = Image(5, 2, ColorMode.INDEXED) + array_to_pixels({ 1, 2, 3, 2, 1, + 0, 1, 2, 1, 0 }, brushImg) + local bru = Brush { image=brushImg } + + -- Without overflow + app.useTool{ tool=pencil, brush=bru, points={ Point(2, 1) } } + expect_img(cel.image, + { 1, 2, 3, 2, 1, + 0, 1, 2, 1, 0 }) + app.undo() + + -- Overflow at the left-side + app.useTool{ tool=pencil, brush=bru, points={ Point(1, 1) } } + expect_img(cel.image, + { 2, 3, 2, 1, 0, 0, 0, 1, + 1, 2, 1, 0, 0, 0, 0, 0 }) + app.undo() + + -- Overflow at the right-side + app.useTool{ tool=pencil, brush=bru, points={ Point(9, 1) } } + expect_img(cel.image, + { 2, 3, 2, 1, 0, 0, 0, 1, + 1, 2, 1, 0, 0, 0, 0, 0 }) + app.undo() + + -- Overflow at the top + app.useTool{ tool=pencil, brush=bru, points={ Point(0, 0) } } + expect_img(cel.image, + { 2, 1, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, + 3, 2, 1, 0, 0, 0, 1, 2 }) + app.undo() + + -- Overflow at the bottom + app.useTool{ tool=pencil, brush=bru, points={ Point(1, 3) } } + expect_img(cel.image, + { 1, 2, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 2, 3, 2, 1, 0, 0, 0, 1 }) + app.undo() + + docPref.tiled.mode = 0 -- none (disable tiled mode) +end +drawing_with_tiled_mode_and_image_brush() From e3d67e9765be969e0f320083a0e79712cbe86bc8 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 19 Mar 2020 08:57:53 -0300 Subject: [PATCH 121/200] Add Tag.color (related to https://github.com/aseprite/api/issues/24) --- scripts/tag.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/tag.lua b/scripts/tag.lua index 465c5f52c..67b9bd1a0 100644 --- a/scripts/tag.lua +++ b/scripts/tag.lua @@ -1,3 +1,4 @@ +-- Copyright (C) 2020 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -30,4 +31,8 @@ do assert(a.aniDir == AniDir.PING_PONG) a.aniDir = AniDir.FORWARD assert(a.aniDir == AniDir.FORWARD) + + assert(a.color == Color(0, 0, 0)) + a.color = Color(255, 0, 0) + assert(a.color == Color(255, 0, 0)) end From d890906f1aa7ac00fc1fd46dd8ba85d89bd8d6b3 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 25 Mar 2020 23:17:48 -0300 Subject: [PATCH 122/200] Fix version tests now that the master branch is v1.x-dev --- scripts/version.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/version.lua b/scripts/version.lua index b38a23cb9..9137835c1 100644 --- a/scripts/version.lua +++ b/scripts/version.lua @@ -7,8 +7,10 @@ assert(string.sub(tostring(app.version), 1, 1) == "1") assert(string.sub(tostring(app.version), 2, 2) == ".") assert(app.version.major == 1) -assert(app.version.minor >= 2) -assert(app.version > Version("1.2.10-beta4")) + +-- We cannot test the specific app.version from the master branch +-- because it's "1.x-dev" (which is converted to "1.0-dev" as Version object) +--assert(app.version > Version("1.2.10-beta4")) assert(Version("1") == Version("1")) assert(Version("1.1") > Version("1")) From 7df01d80d8ea0b54d448dd1000df8056f6f6ab10 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 28 Mar 2020 13:25:17 -0300 Subject: [PATCH 123/200] Test some crashes of Image() constructor --- scripts/image.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/image.lua b/scripts/image.lua index 5f542afb5..af67baaf0 100644 --- a/scripts/image.lua +++ b/scripts/image.lua @@ -191,3 +191,23 @@ do img2:resize(3, 2) expect_img(img2, cols) end + +-- Test v1.2.17 crashes +do + local defSpec = ImageSpec{ width=1, height=1, colorMode=ColorMode.RGB } + + local img = Image() -- we create a 1x1 RGB image + assert(img ~= nil) + assert(img.spec == defSpec) + + img = Image(nil) + assert(img ~= nil) + assert(img.spec == defSpec) + + local spr = Sprite(32, 32, ColorMode.INDEXED) + spr.cels[1].image:putPixel(15, 15, 129) + img = Image(spr) -- we create a sprite render of the first frame + assert(img ~= nil) + assert(img.spec == spr.spec) + assert(img:getPixel(15, 15) == 129) +end From 58dccdaff20b5b6de63588ec7256929561ee6c3f Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 16 Apr 2020 19:20:01 -0300 Subject: [PATCH 124/200] Add Range.layers/frames setters and Range:clear() --- scripts/range.lua | 58 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/scripts/range.lua b/scripts/range.lua index 30d6c586e..54b62d2dc 100644 --- a/scripts/range.lua +++ b/scripts/range.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019 Igara Studio S.A. +-- Copyright (C) 2019-2020 Igara Studio S.A. -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. @@ -29,6 +29,7 @@ do assert(r.frames[1] == s.frames[1]) end +-- Test app.range.colors do assert(#app.range.colors == 0) app.range.colors = { 2 } @@ -53,3 +54,58 @@ do assert(app.range:containsColor(8)) assert(app.range:containsColor(10)) end + +-- Test setters +do + local spr = Sprite(32, 32) + local lay1 = spr.layers[1] + local r = app.range + assert(r.type == RangeType.EMPTY) + assert(#r.layers == 1) + assert(#r.frames == 1) + assert(r.layers[1] == lay1) + assert(r.frames[1].frameNumber == 1) + + local lay2 = spr:newLayer() + r = app.range + assert(r.type == RangeType.EMPTY) + assert(#r.layers == 1) + assert(#r.frames == 1) + assert(r.layers[1] == lay2) + assert(r.frames[1].frameNumber == 1) + + r.layers = { lay1, lay2 } + assert(r.type == RangeType.LAYERS) + assert(#r.layers == 2) + assert(#r.frames == 1) + assert(r.layers[1] == lay1) + assert(r.layers[2] == lay2) + assert(r.frames[1].frameNumber == 1) + + spr:newFrame() + spr:newFrame() + r.frames = { 1, 3 } + assert(r.type == RangeType.FRAMES) + assert(#r.layers == 2) + assert(#r.frames == 2) + assert(r.layers[1] == lay1) + assert(r.layers[2] == lay2) + assert(r.frames[1].frameNumber == 1) + assert(r.frames[2].frameNumber == 3) + + r.layers = { lay2 } + assert(r.type == RangeType.LAYERS) + assert(#r.layers == 1) + assert(#r.frames == 2) + assert(r.layers[1] == lay2) + assert(r.frames[1].frameNumber == 1) + assert(r.frames[2].frameNumber == 3) + + -- Clear range + r:clear() + assert(r.type == RangeType.EMPTY) + assert(#r.layers == 1) + assert(#r.frames == 1) + assert(r.layers[1] == app.activeLayer) + assert(r.frames[1] == app.activeFrame) +end From 52a3fe55aeac872d97a8c7a7f49441251393d167 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 16 Apr 2020 21:36:50 -0300 Subject: [PATCH 125/200] Check that app.range:clear() reset the selected colors --- scripts/range.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/range.lua b/scripts/range.lua index 54b62d2dc..3128e8e3c 100644 --- a/scripts/range.lua +++ b/scripts/range.lua @@ -108,4 +108,11 @@ do assert(#r.frames == 1) assert(r.layers[1] == app.activeLayer) assert(r.frames[1] == app.activeFrame) + + -- Check that Range:clear() reset the selected colors + r.colors = { 2 } + assert(#r.colors == 1) + assert(r.colors[1] == 2) + r:clear() + assert(#r.colors == 0) end From f358262ad55ba8305a7d46bf6e0d5e9dddafa4d7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 17 Apr 2020 12:26:29 -0300 Subject: [PATCH 126/200] Test app.command.Flip() --- scripts/app_command.lua | 50 +++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/scripts/app_command.lua b/scripts/app_command.lua index 1a1fd8f14..50c3b30a4 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019 Igara Studio S.A. +-- Copyright (C) 2019-2020 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -6,6 +6,11 @@ dofile('./test_utils.lua') +local rgba = app.pixelColor.rgba +local rgbaR = app.pixelColor.rgbaR +local rgbaG = app.pixelColor.rgbaG +local rgbaB = app.pixelColor.rgbaB + do -- Undo/Redo commands (like app.undo/redo()) local s = Sprite(32, 32) assert(s.width == 32) @@ -269,10 +274,6 @@ do -- Outline end do -- BrightnessContrast - local rgba = app.pixelColor.rgba - local rgbaR = app.pixelColor.rgbaR - local rgbaG = app.pixelColor.rgbaG - local rgbaB = app.pixelColor.rgbaB local s = Sprite(2, 2) local cel = app.activeCel local c = { rgba(255, 128, 64), rgba(250, 225, 110), @@ -396,7 +397,6 @@ do -- HueSaturation end do -- ColorCurve - local rgba = app.pixelColor.rgba local s = Sprite(2, 1) local cel = app.activeCel local i = cel.image @@ -425,7 +425,6 @@ do -- ColorCurve end do -- ConvolutionMatrix - local rgba = app.pixelColor.rgba local s = Sprite(3, 3) local cel = app.activeCel local i = cel.image @@ -507,3 +506,40 @@ do app.command.AddColor{ source="bg" } assert(p:getColor(#p-1) == color) end + +-- Flip +do + local s = Sprite(4, 2, ColorMode.INDEXED) + local i = s.cels[1].image + array_to_pixels({ 0, 1, 2, 3, + 4, 5, 6, 7 }, i) + app.command.Flip{ orientation="horizontal" } + expect_img(i, { 3, 2, 1, 0, + 7, 6, 5, 4 }) + + app.command.Flip{ orientation="vertical" } + expect_img(i, { 7, 6, 5, 4, + 3, 2, 1, 0 }) + + s.selection:select{ 1, 0, 2, 2 } + app.command.Flip{ orientation="horizontal", target="mask" } + expect_img(i, { 7, 5, 6, 4, + 3, 1, 2, 0 }) + + s:newFrame() + + assert(app.activeCel.frameNumber == 2) + local j = app.activeImage + app.command.Flip{ orientation="vertical", target="mask" } + expect_img(i, { 7, 5, 6, 4, + 3, 1, 2, 0 }) + expect_img(j, { 7, 1, 2, 4, + 3, 5, 6, 0 }) + + app.range.frames = { 1, 2 } + app.command.Flip{ orientation="horizontal", target="mask" } + expect_img(i, { 7, 6, 5, 4, + 3, 2, 1, 0 }) + expect_img(j, { 7, 2, 1, 4, + 3, 6, 5, 0 }) +end From 6497147845a5566121cdfc9b2f99c6124f64c4ba Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 20 May 2020 18:17:17 -0300 Subject: [PATCH 127/200] Add some tests for Simple and Alpha Compositing inks --- scripts/inks.lua | 87 ++++++++++++++++++++++++++++++++++++++++++ scripts/test_utils.lua | 8 ++-- 2 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 scripts/inks.lua diff --git a/scripts/inks.lua b/scripts/inks.lua new file mode 100644 index 000000000..28b7437bd --- /dev/null +++ b/scripts/inks.lua @@ -0,0 +1,87 @@ +-- Copyright (C) 2020 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +dofile('./test_utils.lua') + +local pencil = "pencil" + +function test_inks(colorMode) + -- Test ink over a transparent sprite + local s = Sprite(3, 3, colorMode) + local p, a, b, c, d + if colorMode == ColorMode.GRAY then + local function gray(g) + return app.pixelColor.graya(g, 255) + end + p = s.palettes[1] + a, b, c, d = gray(0), gray(64), gray(128), gray(255) + else + p = Palette() + p:resize(4) + p:setColor(0, Color(0, 0, 0)) + p:setColor(1, Color(64, 64, 64)) + p:setColor(2, Color(128, 128, 128)) + p:setColor(3, Color(255, 255, 255)) + s:setPalette(p) + + a, b, c, d = 0, 1, 2, 3 + if colorMode == ColorMode.RGB then + a = p:getColor(a).rgbaPixel + b = p:getColor(b).rgbaPixel + c = p:getColor(c).rgbaPixel + d = p:getColor(d).rgbaPixel + end + end + + -- With simple ink opacity doesn't have affect (always the color) + local opacities = { 0, 128, 255 } + for i = 1,#opacities do + print(opacities[i]) + expect_img(app.activeImage, + { 0, 0, 0, + 0, 0, 0, + 0, 0, 0 }) + app.useTool{ tool=pencil, color=d, points={ Point(0, 0), Point(2, 2) }, + ink=Ink.SIMPLE, opacity=opacities[i] } + expect_img(app.activeImage, + { d, 0, 0, + 0, d, 0, + 0, 0, d }) + if i < #opacities then app.undo() end + end + + -- Check that painting with transparent index (color) on a + -- transparent layer (using any value of opacity) with alpha + -- compositing doesn't modify pixels + for i = 1,#opacities do + app.useTool{ tool=pencil, color=0, points={ Point(1, 1) }, + ink=Ink.ALPHA_COMPOSITING, opacity=opacities[i] } + expect_img(app.activeImage, + { d, 0, 0, + 0, d, 0, + 0, 0, d }) + end + + -- Convert to background layer + app.command.BackgroundFromLayer() + + app.useTool{ tool=pencil, color=d, points={ Point(0, 1), Point(2, 1) }, + ink=Ink.ALPHA_COMPOSITING, opacity=64 } + expect_img(app.activeImage, + { d, a, a, + b, d, b, + a, a, d }) + + app.useTool{ tool=pencil, color=d, points={ Point(0, 1) }, + ink=Ink.ALPHA_COMPOSITING, opacity=86 } + expect_img(app.activeImage, + { d, a, a, + c, d, b, + a, a, d }) +end + +test_inks(ColorMode.RGB) +test_inks(ColorMode.GRAY) +test_inks(ColorMode.INDEXED) diff --git a/scripts/test_utils.lua b/scripts/test_utils.lua index e6344bb5d..0f8029109 100644 --- a/scripts/test_utils.lua +++ b/scripts/test_utils.lua @@ -60,11 +60,11 @@ function expect_img(image, expectedPixels) app.pixelColor.rgbaA(b))) elseif image.colorMode == ColorMode.GRAY then print(string.format(' - Value A = gray(%d,%d)', - app.pixelColor.grayG(a), - app.pixelColor.grayA(a))) + app.pixelColor.grayaV(a), + app.pixelColor.grayaA(a))) print(string.format(' - Value B = gray(%d,%d)', - app.pixelColor.grayV(b), - app.pixelColor.grayA(b))) + app.pixelColor.grayaV(b), + app.pixelColor.grayaA(b))) else print(' - Value A = ' .. tostring(a)) print(' - Value B = ' .. tostring(b)) From 76c2fff045d9c1f310e43d5d4b0895d02215d4cb Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 21 May 2020 18:33:02 -0300 Subject: [PATCH 128/200] Test that alpha compositing ink w/opacity=255 behaves like simple ink --- scripts/inks.lua | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/scripts/inks.lua b/scripts/inks.lua index 28b7437bd..1bda9217a 100644 --- a/scripts/inks.lua +++ b/scripts/inks.lua @@ -38,7 +38,6 @@ function test_inks(colorMode) -- With simple ink opacity doesn't have affect (always the color) local opacities = { 0, 128, 255 } for i = 1,#opacities do - print(opacities[i]) expect_img(app.activeImage, { 0, 0, 0, 0, 0, 0, @@ -82,6 +81,32 @@ function test_inks(colorMode) a, a, d }) end +function test_alpha_compositing_on_indexed_with_full_opacity_and_repeated_colors_in_palette() + local s = Sprite(1, 1, ColorMode.INDEXED) + local p = Palette() + p:resize(5) + p:setColor(0, Color(0, 0, 0)) + p:setColor(1, Color(64, 64, 64)) + p:setColor(2, Color(128, 128, 128)) + p:setColor(3, Color(128, 128, 128)) + p:setColor(4, Color(255, 255, 255)) + s:setPalette(p) + + app.command.BackgroundFromLayer() + + local inks = { Ink.SIMPLE, Ink.ALPHA_COMPOSITING } + for i = 1,2 do + for c = 0,4 do + expect_img(app.activeImage, { 0 }) + app.useTool{ tool="pencil", color=c, points={ Point(0, 0) }, + ink=inks[i], opacity=255 } + expect_img(app.activeImage, { c }) + app.undo() + end + end +end + test_inks(ColorMode.RGB) test_inks(ColorMode.GRAY) test_inks(ColorMode.INDEXED) +test_alpha_compositing_on_indexed_with_full_opacity_and_repeated_colors_in_palette() From b81c6152117b460d821842874b3c118bbaf85a28 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 21 May 2020 20:52:16 -0300 Subject: [PATCH 129/200] Test transparent/background layer in special indexed case for alpha compositing ink --- scripts/inks.lua | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/scripts/inks.lua b/scripts/inks.lua index 1bda9217a..2bd14700e 100644 --- a/scripts/inks.lua +++ b/scripts/inks.lua @@ -92,16 +92,23 @@ function test_alpha_compositing_on_indexed_with_full_opacity_and_repeated_colors p:setColor(4, Color(255, 255, 255)) s:setPalette(p) - app.command.BackgroundFromLayer() - local inks = { Ink.SIMPLE, Ink.ALPHA_COMPOSITING } - for i = 1,2 do - for c = 0,4 do - expect_img(app.activeImage, { 0 }) - app.useTool{ tool="pencil", color=c, points={ Point(0, 0) }, - ink=inks[i], opacity=255 } - expect_img(app.activeImage, { c }) - app.undo() + + -- k=1 -> transparent layer + -- k=2 -> background layer + for k=1,2 do + if k == 2 then app.command.BackgroundFromLayer() end + -- i=1 -> simple ink + -- i=2 -> alpha compositing ink + for i = 1,2 do + -- j=color index + for j = 0,4 do + expect_img(app.activeImage, { 0 }) + app.useTool{ tool="pencil", color=j, points={ Point(0, 0) }, + ink=inks[i], opacity=255 } + expect_img(app.activeImage, { j }) + app.undo() + end end end end From 86841217b26f287724d71f62cfe77aa452f81d4f Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 25 May 2020 17:34:28 -0300 Subject: [PATCH 130/200] Add more tests for simple and alpha compositing inks w/brushes --- scripts/inks.lua | 117 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 111 insertions(+), 6 deletions(-) diff --git a/scripts/inks.lua b/scripts/inks.lua index 2bd14700e..5d86d1794 100644 --- a/scripts/inks.lua +++ b/scripts/inks.lua @@ -5,16 +5,22 @@ dofile('./test_utils.lua') +local colorModes = { ColorMode.RGB, + ColorMode.GRAY, + ColorMode.INDEXED } + local pencil = "pencil" +local pc = app.pixelColor + +local function gray(g) + return pc.graya(g, 255) +end function test_inks(colorMode) -- Test ink over a transparent sprite local s = Sprite(3, 3, colorMode) local p, a, b, c, d if colorMode == ColorMode.GRAY then - local function gray(g) - return app.pixelColor.graya(g, 255) - end p = s.palettes[1] a, b, c, d = gray(0), gray(64), gray(128), gray(255) else @@ -79,6 +85,105 @@ function test_inks(colorMode) { d, a, a, c, d, b, a, a, d }) + + ---------------------------------------------------------------------- + -- Inks with custom brushes + + function test_custom_brush_inks(brushColorMode) + -- Colors in the brush image (ba, bb, bc, bd) + local ba, bb, bc, bd + if brushColorMode == ColorMode.RGB then + ba = Color(0, 0, 0) + bb = Color(64, 64, 64) + bc = Color(128, 128, 128) + bd = Color(255, 255, 255) + elseif brushColorMode == ColorMode.GRAY then + ba, bb, bc, bd = gray(0), gray(64), gray(128), gray(255) + else + ba, bb, bc, bd = 0, 1, 2, 3 + end + + local brushImage = Image(2, 2, brushColorMode) + array_to_pixels({ 0, bd, + bc, 0 }, brushImage) + local brush = Brush(brushImage) + + -- da, db, dc, dd are the final result after painting the custom + -- brush in the sprite + local ra, rb, rc, rd + if s.colorMode ~= ColorMode.INDEXED and + brushColorMode == ColorMode.INDEXED then + -- For indexed images we take the index of the brush and use the + -- sprite palette, we are not sure if this in the future might + -- change, e.g. having the original palette that was used to + -- create the brush integrated to the brush itself, in that case + -- we should convert the brush index using the same brush + -- palette (instead of the sprite palette). + -- + -- TODO check BrushInkProcessingBase comment for more information + if s.colorMode == ColorMode.RGB then + ra, rb, rc, rd = + p:getColor(ba).rgbaPixel, + p:getColor(bb).rgbaPixel, + p:getColor(bc).rgbaPixel, + p:getColor(bd).rgbaPixel + else + ra, rb, rc, rd = + p:getColor(ba).grayPixel, + p:getColor(bb).grayPixel, + p:getColor(bc).grayPixel, + p:getColor(bd).grayPixel + end + else + ra, rb, rc, rd = a, b, c, d + end + + array_to_pixels({ a, a, a, + a, a, a, + a, a, a }, app.activeImage) + + -- Simple + expect_img(app.activeImage, + { a, a, a, + a, a, a, + a, a, a }) + app.useTool{ tool=pencil, brush=brush, points={ Point(2, 2) }, + ink=Ink.SIMPLE } + expect_img(app.activeImage, + { a, a, a, + a, a, rd, + a, rc, a }) + + -- Alpha Compositing + app.useTool{ tool=pencil, brush=brush, points={ Point(1, 1) }, + ink=Ink.ALPHA_COMPOSITING, opacity=255 } + expect_img(app.activeImage, + { a, rd, a, + rc, a, rd, + a, rc, a }) + + local qc, qd + if s.colorMode == ColorMode.GRAY and + brushColorMode == ColorMode.INDEXED then + qc = gray(pc.grayaV(rc)/2) + qd = gray(pc.grayaV(rd)/2) + else + qc, qd = rb, rc + end + + app.useTool{ tool=pencil, brush=brush, points={ Point(1, 2) }, + ink=Ink.ALPHA_COMPOSITING, opacity=128 } + expect_img(app.activeImage, + { a, rd, a, + rc, qd, rd, + qc, rc, a }) + + -- TODO test Lock Alpha, Copy Color+Alpha, Shading... + end + + for j = 1,#colorModes do + test_custom_brush_inks(colorModes[j]) + end end function test_alpha_compositing_on_indexed_with_full_opacity_and_repeated_colors_in_palette() @@ -113,7 +218,7 @@ function test_alpha_compositing_on_indexed_with_full_opacity_and_repeated_colors end end -test_inks(ColorMode.RGB) -test_inks(ColorMode.GRAY) -test_inks(ColorMode.INDEXED) +for i = 1,#colorModes do + test_inks(colorModes[i]) +end test_alpha_compositing_on_indexed_with_full_opacity_and_repeated_colors_in_palette() From 2df9614ac6fd2a31fdfe0f4ec5f300beb4deb5e9 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 28 May 2020 12:25:28 -0300 Subject: [PATCH 131/200] [lua] Test crash undoing removed layers/groups --- scripts/layers.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/scripts/layers.lua b/scripts/layers.lua index 3519eeaa8..361ef4a58 100644 --- a/scripts/layers.lua +++ b/scripts/layers.lua @@ -152,3 +152,36 @@ do assert(s.layers[i].name == "d") end end + +-- Test crash because ActiveSiteHandler::onBeforeRemoveLayer() didn't +-- update the selected range of layers correctly (i.e. removing +-- deleted layer from the selected layers in the active range). +do + local s = Sprite(4, 4) + local a = s:newGroup() a.name = "a" + local b = s:newGroup() b.name = "b" + local c = s:newGroup() c.name = "c" + local ca = s:newGroup() ca.name = "ca" + local cb = s:newGroup() cb.name = "cb" + local d = s:newGroup() d.name = "d" + + d.parent = ca + ca.parent = c + cb.parent = c + c.parent = b + b.parent = a + + assert(#a.layers == 1) + assert(#c.layers == 2) + + app.range.layers = { b } + app.command.RemoveLayer() + assert(#a.layers == 0) + app.undo() + assert(#a.layers == 1) + assert(#c.layers == 2) + + -- Crash selecting a layer that was removed and then brought back to + -- life with "undo" + app.range.layers = { b } +end From e73a30057b0741ab1ca6b738ecd939b625fa273c Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 10 Jun 2020 12:03:53 -0300 Subject: [PATCH 132/200] Add test for https://github.com/aseprite/aseprite/issues/2380 --- cli/sheet.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cli/sheet.sh b/cli/sheet.sh index 6aa801142..09ed5561d 100644 --- a/cli/sheet.sh +++ b/cli/sheet.sh @@ -301,3 +301,18 @@ for i = 1,#data1.frames do end EOF $ASEPRITE -b -script "$d/compare.lua" || exit 1 + +# https://github.com/aseprite/aseprite/issues/2380 +# Check that -split-layers and -list-layers include group information +d=$t/issue-2380 +$ASEPRITE -b -trim -all-layers "sprites/groups3abc.aseprite" -data "$d/sheet1.json" -format json-array -sheet "$d/sheet1.png" -list-layers +$ASEPRITE -b -trim -all-layers -split-layers "sprites/groups3abc.aseprite" -data "$d/sheet2.json" -format json-array -sheet "$d/sheet2.png" -list-layers +cat >$d/check.lua < Date: Wed, 10 Jun 2020 12:58:26 -0300 Subject: [PATCH 133/200] Add test for https://github.com/aseprite/aseprite/issues/2432 --- cli/sheet.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cli/sheet.sh b/cli/sheet.sh index 09ed5561d..f6e2c2be0 100644 --- a/cli/sheet.sh +++ b/cli/sheet.sh @@ -316,3 +316,18 @@ assert(#sheet2.meta.layers == 12) assert(json.encode(sheet1.meta.layers) == json.encode(sheet2.meta.layers)) EOF $ASEPRITE -b -script "$d/check.lua" || exit 1 + +# https://github.com/aseprite/aseprite/issues/2432 +# -ignore-layer is ignoring extra layers when -split-layers is used +d=$t/issue-2432 +$ASEPRITE -b -trim -ignore-layer "c" -all-layers "sprites/groups3abc.aseprite" -data "$d/sheet1.json" -format json-array -sheet "$d/sheet1.png" -list-layers +$ASEPRITE -b -trim -ignore-layer "c" -all-layers -split-layers "sprites/groups3abc.aseprite" -data "$d/sheet2.json" -format json-array -sheet "$d/sheet2.png" -list-layers +cat >$d/check.lua < Date: Tue, 30 Jun 2020 18:52:23 -0300 Subject: [PATCH 134/200] Add tilemap tests --- scripts/tilemap.lua | 266 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 scripts/tilemap.lua diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua new file mode 100644 index 000000000..0c2c37615 --- /dev/null +++ b/scripts/tilemap.lua @@ -0,0 +1,266 @@ +-- Copyright (C) 2019-2020 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +-- This version of Aseprite doesn't support tilemaps +if TilesetMode == nil then return end + +dofile('./test_utils.lua') + +local rgba = app.pixelColor.rgba + +-- Check constants +assert(TilemapMode.PIXELS == 0) +assert(TilemapMode.TILES == 1) +assert(TilesetMode.STACK == 2) +assert(TilesetMode.MANUAL == 0) +assert(TilesetMode.AUTO == 1) +assert(TilesetMode.STACK == 2) + +---------------------------------------------------------------------- +-- Tests drawing in the tilemap +---------------------------------------------------------------------- + +do + local spr = Sprite(32, 32) + assert(spr.layers[1].isImage) + assert(not spr.layers[1].isTilemap) + + ---------------------------------------------------------------------- + -- Create a tilemap + ---------------------------------------------------------------------- + + app.command.NewLayer{ tilemap=true } + assert(#spr.layers == 2) + local tilemapLay = spr.layers[2] + assert(tilemapLay.isImage) + assert(tilemapLay.isTilemap) + assert(#tilemapLay.cels == 0) + + ---------------------------------------------------------------------- + -- Draw the first pixel on the tilemap so a new tile is created + ---------------------------------------------------------------------- + + app.useTool{ + tool='pencil', + color=Color{ r=0, g=0, b=0 }, + layer=tilemapLay, + tilesetMode=TilesetMode.STACK, + points={ Point(2, 2), Point(3, 2) }} + assert(#tilemapLay.cels == 1) + assert(tilemapLay:cel(1).image.colorMode == ColorMode.TILEMAP) + local tilemapCel = tilemapLay:cel(1) + assert(tilemapCel.bounds == Rectangle(0, 0, 16, 16)) + + assert(#spr.tilesets == 1) -- one tileset + assert(spr.tilesets[1] == tilemapLay.tileset) + + local tileset = tilemapLay.tileset + assert(#tileset == 1) -- one tile + + tilemapCel.position = Point(2, 2) + assert(tilemapCel.bounds == Rectangle(2, 2, 16, 16)) + assert(#tileset == 1) + + assert(tilemapCel.image.width == 1) + assert(tilemapCel.image.height == 1) + assert(tilemapCel.image:getPixel(0, 0) == 0) + + ---------------------------------------------------------------------- + -- Draw a second pixel with locked mode (new tiles are not generated) + ---------------------------------------------------------------------- + + app.useTool{ + tool='pencil', + color=Color{ r=0, g=0, b=0 }, + cel=tilemapCel, + tilesetMode=TilesetMode.MANUAL, + points={ Point(0, 0) }} + + assert(tilemapCel.bounds == Rectangle(2, 2, 16, 16)) + assert(#tileset == 1) + + ---------------------------------------------------------------------- + -- Draw pixels generating new tiles + ---------------------------------------------------------------------- + + app.useTool{ + tool='pencil', + color=Color{ r=0, g=0, b=0 }, + cel=tilemapCel, + tilesetMode=TilesetMode.STACK, + points={ Point(0, 0) }} + + assert(tilemapCel.bounds == Rectangle(-14, -14, 32, 32)) + assert(#tileset == 3) + assert(not tileset:getTile(0):isEmpty()) + assert(not tileset:getTile(1):isEmpty()) + assert(tileset:getTile(2):isEmpty()) + assert(tilemapCel.image.width == 2) + assert(tilemapCel.image.height == 2) + assert(tilemapCel.image:getPixel(0, 0) == 1) + assert(tilemapCel.image:getPixel(1, 0) == 2) + assert(tilemapCel.image:getPixel(0, 1) == 2) + assert(tilemapCel.image:getPixel(1, 1) == 0) + + app.useTool{ + tool='pencil', + color=Color{ r=0, g=0, b=0 }, + cel=tilemapCel, + tilesetMode=TilesetMode.STACK, + points={ Point(19, 19) }} + + assert(tilemapCel.bounds == Rectangle(-14, -14, 48, 48)) + assert(#tilemapLay.tileset == 4) + assert(not tileset:getTile(3):isEmpty()) + assert(tilemapCel.image.width == 3) + assert(tilemapCel.image.height == 3) + assert(tilemapCel.image:getPixel(0, 0) == 1) + assert(tilemapCel.image:getPixel(1, 0) == 2) + assert(tilemapCel.image:getPixel(2, 0) == 2) + assert(tilemapCel.image:getPixel(0, 1) == 2) + assert(tilemapCel.image:getPixel(1, 1) == 0) + assert(tilemapCel.image:getPixel(2, 1) == 2) + assert(tilemapCel.image:getPixel(0, 2) == 2) + assert(tilemapCel.image:getPixel(1, 2) == 2) + assert(tilemapCel.image:getPixel(2, 2) == 3) +end + +---------------------------------------------------------------------- +-- Tests drawing when the grid origin is in a negative position +---------------------------------------------------------------------- + +do + local spr = Sprite(32, 32) + app.command.NewLayer{ tilemap=true } + local tilemapLay = spr.layers[2] + + app.useTool{ + tool='pencil', + color=Color{ r=0, g=255, b=0 }, + layer=tilemapLay, + tilesetMode=TilesetMode.STACK, + points={ Point(0, 0) }} + local tilemapCel = tilemapLay:cel(1) + assert(tilemapCel.bounds == Rectangle(0, 0, 16, 16)) + + local tileset = tilemapLay.tileset + assert(#tileset == 1) -- one tile + + tilemapCel.position = Point(-1, -1) + assert(tilemapCel.bounds == Rectangle(-1, -1, 16, 16)) + + app.useTool{ + tool='pencil', + color=Color{ r=255, g=0, b=0 }, + cel=tilemapCel, + tilesetMode=TilesetMode.STACK, + points={ Point(0, 0) }} + + assert(tilemapCel.bounds == Rectangle(-1, -1, 16, 16)) + assert(#tileset == 2) + + local img = tileset:getTile(1) + + assert(img:getPixel(0, 0) == rgba(0, 255, 0, 255)) + assert(img:getPixel(1, 0) == rgba(0, 0, 0, 0)) + assert(img:getPixel(2, 0) == rgba(0, 0, 0, 0)) + + assert(img:getPixel(0, 1) == rgba(0, 0, 0, 0)) + assert(img:getPixel(1, 1) == rgba(255, 0, 0, 255)) + assert(img:getPixel(2, 1) == rgba(0, 0, 0, 0)) + + assert(img:getPixel(0, 2) == rgba(0, 0, 0, 0)) + assert(img:getPixel(1, 2) == rgba(0, 0, 0, 0)) + assert(img:getPixel(2, 2) == rgba(0, 0, 0, 0)) +end + +---------------------------------------------------------------------- +-- Tests that extra tiles are not created +---------------------------------------------------------------------- + +do + local spr = Sprite(32, 32) + app.command.NewLayer{ tilemap=true } + local tilemapLay = spr.layers[2] + + app.useTool{ + tool='pencil', + color=Color{ r=0, g=255, b=0 }, + layer=tilemapLay, + tilesetMode=TilesetMode.STACK, + points={ Point(0, 0) }} + local tilemapCel = tilemapLay:cel(1) + tilemapCel.position = Point(-1, -1) + + app.useTool{ + tool='pencil', + color=Color{ r=255, g=0, b=0 }, + cel=tilemapCel, + tilesetMode=TilesetMode.STACK, + points={ Point(30, 30) }} + + assert(tilemapCel.bounds == Rectangle(-1, -1, 32, 32)) +end + +---------------------------------------------------------------------- +-- Tests moving tiles +---------------------------------------------------------------------- + +do + local spr = Sprite(32, 32) + app.command.NewLayer{ tilemap=true } + local tilemapLay = spr.layers[2] + + app.useTool{ + tool='ellipse', + color=Color{ r=0, g=0, b=0 }, + layer=tilemapLay, + tilesetMode=TilesetMode.STACK, + points={ Point(0, 0), Point(31, 31) }} + + local ts = tilemapLay.tileset + assert(#ts == 4) + + local imgs = { ts:getTile(0), + ts:getTile(1), + ts:getTile(2), + ts:getTile(3) } + + -- No op = move tile 0 before the tile 0, result=0,1,2,3 + app.range.tiles = { 0 } + app.command.MoveTiles{ before=0 } + expect_eq(imgs[0+1], ts:getTile(0)) + expect_eq(imgs[1+1], ts:getTile(1)) + expect_eq(imgs[2+1], ts:getTile(2)) + expect_eq(imgs[3+1], ts:getTile(3)) + + -- Move tile 1 before tile 0, result=1,0,2,3 + app.range.tiles = { 1 } + app.command.MoveTiles{ before=0 } + expect_eq(imgs[1+1], ts:getTile(0)) + expect_eq(imgs[0+1], ts:getTile(1)) + expect_eq(imgs[2+1], ts:getTile(2)) + expect_eq(imgs[3+1], ts:getTile(3)) + app.undo() + + -- Move tiles 0 and 1 before 3, result=2,0,1,3 + app.range.tiles = { 0, 1 } + app.command.MoveTiles({ before=3 }) + expect_eq(imgs[2+1], ts:getTile(0)) + expect_eq(imgs[0+1], ts:getTile(1)) + expect_eq(imgs[1+1], ts:getTile(2)) + expect_eq(imgs[3+1], ts:getTile(3)) + app.undo() + + -- Move tiles 0 and 2 before 2, result=1,0,2,3 + app.range.tiles = { 0, 2 } + app.command.MoveTiles({ before=2 }) + expect_eq(imgs[1+1], ts:getTile(0)) + expect_eq(imgs[0+1], ts:getTile(1)) + expect_eq(imgs[2+1], ts:getTile(2)) + expect_eq(imgs[3+1], ts:getTile(3)) + app.undo() + +end From 59592bea2eae8374963b09a4d5d82803c911aa7a Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 14 Jul 2020 18:03:58 -0300 Subject: [PATCH 135/200] Test TilemapMode.TILES mode --- scripts/tilemap.lua | 108 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 90 insertions(+), 18 deletions(-) diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua index 0c2c37615..731e83ea5 100644 --- a/scripts/tilemap.lua +++ b/scripts/tilemap.lua @@ -13,7 +13,6 @@ local rgba = app.pixelColor.rgba -- Check constants assert(TilemapMode.PIXELS == 0) assert(TilemapMode.TILES == 1) -assert(TilesetMode.STACK == 2) assert(TilesetMode.MANUAL == 0) assert(TilesetMode.AUTO == 1) assert(TilesetMode.STACK == 2) @@ -97,12 +96,8 @@ do assert(not tileset:getTile(0):isEmpty()) assert(not tileset:getTile(1):isEmpty()) assert(tileset:getTile(2):isEmpty()) - assert(tilemapCel.image.width == 2) - assert(tilemapCel.image.height == 2) - assert(tilemapCel.image:getPixel(0, 0) == 1) - assert(tilemapCel.image:getPixel(1, 0) == 2) - assert(tilemapCel.image:getPixel(0, 1) == 2) - assert(tilemapCel.image:getPixel(1, 1) == 0) + expect_img(tilemapCel.image, { 1, 2, + 2, 0 }) app.useTool{ tool='pencil', @@ -114,17 +109,94 @@ do assert(tilemapCel.bounds == Rectangle(-14, -14, 48, 48)) assert(#tilemapLay.tileset == 4) assert(not tileset:getTile(3):isEmpty()) - assert(tilemapCel.image.width == 3) - assert(tilemapCel.image.height == 3) - assert(tilemapCel.image:getPixel(0, 0) == 1) - assert(tilemapCel.image:getPixel(1, 0) == 2) - assert(tilemapCel.image:getPixel(2, 0) == 2) - assert(tilemapCel.image:getPixel(0, 1) == 2) - assert(tilemapCel.image:getPixel(1, 1) == 0) - assert(tilemapCel.image:getPixel(2, 1) == 2) - assert(tilemapCel.image:getPixel(0, 2) == 2) - assert(tilemapCel.image:getPixel(1, 2) == 2) - assert(tilemapCel.image:getPixel(2, 2) == 3) + expect_img(tilemapCel.image, { 1, 2, 2, + 2, 0, 2, + 2, 2, 3 }) +end + +---------------------------------------------------------------------- +-- Tests drawing in the tilemap with tiles +---------------------------------------------------------------------- + +do + local spr = Sprite(32, 32) + spr.gridBounds = Rectangle(0, 0, 8, 8) + app.command.NewLayer{ tilemap=true } + + local tm = app.activeLayer + local ts = tm.tileset + assert(ts ~= nil) + expect_eq(0, ts.grid.origin.x) + expect_eq(0, ts.grid.origin.y) + expect_eq(8, ts.grid.tileSize.width) + expect_eq(8, ts.grid.tileSize.height) + + app.useTool{ + tool='pencil', + color=Color{ r=0, g=0, b=0 }, + tilemapMode=TilesetMode.PIXELS, + tilesetMode=TilesetMode.STACK, + points={ Point(0, 0), Point(31, 31) }} + + local cel = tm.cels[1]; + expect_eq(2, #ts) + expect_img(cel.image, { 0,1,1,1, + 1,0,1,1, + 1,1,0,1, + 1,1,1,0 }) + + app.useTool{ + tool='pencil', + color=Color(0), + tilemapMode=TilemapMode.TILES, + tilesetMode=TilesetMode.STACK, + points={ Point(0, 16) }} -- y=16 is the first pixel of 3rd row of tiles + cel = tm.cels[1]; + expect_img(cel.image, { 0,1,1,1, + 1,0,1,1, + 0,1,0,1, + 1,1,1,0 }) + + app.useTool{ + tool='pencil', + color=Color(0), + tilemapMode=TilemapMode.TILES, + tilesetMode=TilesetMode.STACK, + points={ Point(0, 0), Point(16, 0) }} -- x=16 is the first pixel of 3rd column of tiles + cel = tm.cels[1]; + expect_img(cel.image, { 0,0,0,1, + 1,0,1,1, + 0,1,0,1, + 1,1,1,0 }) + + -- Move layer origin to 10, 8 + cel.position = { 10, 8 } + expect_eq(Point{ 10, 8 }, cel.position) + app.useTool{ + tool='pencil', + color=Color(1), + tilemapMode=TilemapMode.TILES, + tilesetMode=TilesetMode.STACK, + points={ Point(10, 8) }} -- {10,8} is the first existent tile in the tilemap + cel = tm.cels[1]; + expect_img(cel.image, { 1,0,0,1, + 1,0,1,1, + 0,1,0,1, + 1,1,1,0 }) + + app.useTool{ + tool='pencil', + color=Color(0), + tilemapMode=TilemapMode.TILES, + tilesetMode=TilesetMode.STACK, + points={ Point(0, 0), Point(8, 8) }} -- Tile 0,0 and 1,1 + cel = tm.cels[1]; + expect_img(cel.image, { 0,1, 1,1,1,1, + 1,0, 1,0,0,1, + 1,1, 1,0,1,1, + 1,1, 0,1,0,1, + 1,1, 1,1,1,0 }) + end ---------------------------------------------------------------------- From e4e8568dae66ca10236bda5ea28282c07f8242b7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 16 Jul 2020 19:00:02 -0300 Subject: [PATCH 136/200] New tests for app.command.CopyTiles() --- scripts/tilemap.lua | 98 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua index 731e83ea5..97c9f6300 100644 --- a/scripts/tilemap.lua +++ b/scripts/tilemap.lua @@ -277,7 +277,7 @@ do end ---------------------------------------------------------------------- --- Tests moving tiles +-- Tests moving & copying tiles ---------------------------------------------------------------------- do @@ -307,6 +307,8 @@ do expect_eq(imgs[1+1], ts:getTile(1)) expect_eq(imgs[2+1], ts:getTile(2)) expect_eq(imgs[3+1], ts:getTile(3)) + expect_eq(1, #app.range.tiles) + expect_eq(0, app.range.tiles[1]) -- Move tile 1 before tile 0, result=1,0,2,3 app.range.tiles = { 1 } @@ -315,6 +317,8 @@ do expect_eq(imgs[0+1], ts:getTile(1)) expect_eq(imgs[2+1], ts:getTile(2)) expect_eq(imgs[3+1], ts:getTile(3)) + expect_eq(1, #app.range.tiles) + expect_eq(0, app.range.tiles[1]) app.undo() -- Move tiles 0 and 1 before 3, result=2,0,1,3 @@ -324,6 +328,9 @@ do expect_eq(imgs[0+1], ts:getTile(1)) expect_eq(imgs[1+1], ts:getTile(2)) expect_eq(imgs[3+1], ts:getTile(3)) + expect_eq(2, #app.range.tiles) + expect_eq(1, app.range.tiles[1]) + expect_eq(2, app.range.tiles[2]) app.undo() -- Move tiles 0 and 2 before 2, result=1,0,2,3 @@ -333,6 +340,95 @@ do expect_eq(imgs[0+1], ts:getTile(1)) expect_eq(imgs[2+1], ts:getTile(2)) expect_eq(imgs[3+1], ts:getTile(3)) + expect_eq(2, #app.range.tiles) + expect_eq(1, app.range.tiles[1]) + expect_eq(2, app.range.tiles[2]) + app.undo() + + -- Copy tiles 0 before 0, result=0,0,1,2,3 + app.range.tiles = { 0 } + app.command.CopyTiles({ before=0 }) + expect_eq(1, #app.range.tiles) + expect_eq(0, app.range.tiles[1]) + expect_eq(5, #ts) + assert(ts:getTile(0):isEqual(imgs[0+1])) + assert(ts:getTile(1):isEqual(imgs[0+1])) + assert(ts:getTile(2):isEqual(imgs[1+1])) + assert(ts:getTile(3):isEqual(imgs[2+1])) + assert(ts:getTile(4):isEqual(imgs[3+1])) + app.undo() + + -- Copy tiles 0 before 3, result=0,1,2,0,3 + app.range.tiles = { 0 } + app.command.CopyTiles({ before=3 }) + expect_eq(1, #app.range.tiles) + expect_eq(3, app.range.tiles[1]) + expect_eq(5, #ts) + assert(ts:getTile(0):isEqual(imgs[0+1])) + assert(ts:getTile(1):isEqual(imgs[1+1])) + assert(ts:getTile(2):isEqual(imgs[2+1])) + assert(ts:getTile(3):isEqual(imgs[0+1])) + assert(ts:getTile(4):isEqual(imgs[3+1])) + app.undo() + + -- Copy tiles 0, 1, and 3, before 4, result=0,1,2,3,0,1,3 + app.range.tiles = { 0, 1, 3 } + app.command.CopyTiles({ before=4 }) + assert(ts:getTile(0):isEqual(imgs[0+1])) + assert(ts:getTile(1):isEqual(imgs[1+1])) + assert(ts:getTile(2):isEqual(imgs[2+1])) + assert(ts:getTile(3):isEqual(imgs[3+1])) + assert(ts:getTile(4):isEqual(imgs[0+1])) + assert(ts:getTile(5):isEqual(imgs[1+1])) + assert(ts:getTile(6):isEqual(imgs[3+1])) + app.undo() + + -- Copy tiles 1, and 3, before 0, result=1,3,0,1,2,3 + app.range.tiles = { 1, 3 } + app.command.CopyTiles({ before=0 }) + assert(ts:getTile(0):isEqual(imgs[1+1])) + assert(ts:getTile(1):isEqual(imgs[3+1])) + assert(ts:getTile(2):isEqual(imgs[0+1])) + assert(ts:getTile(3):isEqual(imgs[1+1])) + assert(ts:getTile(4):isEqual(imgs[2+1])) + assert(ts:getTile(5):isEqual(imgs[3+1])) + app.undo() + + -- Copy tiles 0, and 3, before 7, result=0,1,2,3,0,3 + app.range.tiles = { 0, 3 } + app.command.CopyTiles({ before=4 }) + assert(ts:getTile(0):isEqual(imgs[0+1])) + assert(ts:getTile(1):isEqual(imgs[1+1])) + assert(ts:getTile(2):isEqual(imgs[2+1])) + assert(ts:getTile(3):isEqual(imgs[3+1])) + assert(ts:getTile(4):isEqual(imgs[0+1])) + assert(ts:getTile(5):isEqual(imgs[3+1])) + app.undo() + + -- Copy tiles 0, and 3, before 7, result=0,1,2,3,-,0,3 + app.range.tiles = { 0, 3 } + app.command.CopyTiles({ before=5 }) + assert(ts:getTile(0):isEqual(imgs[0+1])) + assert(ts:getTile(1):isEqual(imgs[1+1])) + assert(ts:getTile(2):isEqual(imgs[2+1])) + assert(ts:getTile(3):isEqual(imgs[3+1])) + assert(ts:getTile(4):isPlain()) + assert(ts:getTile(5):isEqual(imgs[0+1])) + assert(ts:getTile(6):isEqual(imgs[3+1])) + app.undo() + + -- Copy tiles 2, and 3, before 7, result=0,1,2,3,-,-,-,2,3 + app.range.tiles = { 2, 3 } + app.command.CopyTiles({ before=7 }) + assert(ts:getTile(0):isEqual(imgs[0+1])) + assert(ts:getTile(1):isEqual(imgs[1+1])) + assert(ts:getTile(2):isEqual(imgs[2+1])) + assert(ts:getTile(3):isEqual(imgs[3+1])) + assert(ts:getTile(4):isPlain()) + assert(ts:getTile(5):isPlain()) + assert(ts:getTile(6):isPlain()) + assert(ts:getTile(7):isEqual(imgs[2+1])) + assert(ts:getTile(8):isEqual(imgs[3+1])) app.undo() end From 9e22d2513686ecd5b5fa5378ec130fdb7ec75466 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 22 Jul 2020 14:17:46 -0300 Subject: [PATCH 137/200] Test crash undoing Sprite:newCel() in background layers --- scripts/cels.lua | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/scripts/cels.lua b/scripts/cels.lua index 4fe59a7cd..2c68aeab6 100644 --- a/scripts/cels.lua +++ b/scripts/cels.lua @@ -1,8 +1,11 @@ +-- Copyright (C) 2020 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. +dofile('./test_utils.lua') + do local s = Sprite(32, 32) for i = 1,3 do s:newFrame() end @@ -41,3 +44,43 @@ do assert(cb[1] == b.cels[1]) assert(cb[3] == b.cels[2]) end + +-- Some extra tests of newCel() and deleteCel() +do + local s = Sprite(4, 4, ColorMode.INDEXED) + local layer = app.activeLayer + app.bgColor = 0 + app.command.BackgroundFromLayer() + expect_img(s.cels[1].image, { 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0 }) + + -- Crash in old versions undoing newCel() in a background layer + s:newCel(layer, 1) + app.undo() + + -- Check that newCel clears with bgColor in background layer + local img = Image(ImageSpec{ width=2, height=2, + colorMode=ColorMode.INDEXED }) + array_to_pixels({ 0, 1, + 2, 3 }, img) + + app.bgColor = Color(1) -- bgColor used to clear the background cel + s:newCel(layer, 1, img, Point(1, 1)) + expect_img(s.cels[1].image, { 1, 1, 1, 1, + 1, 0, 1, 1, + 1, 2, 3, 1, + 1, 1, 1, 1 }) + app.undo() + + -- Check deleteCel() + app.bgColor = Color(2) + s:deleteCel(layer, 1) + expect_img(s.cels[1].image, { 2, 2, 2, 2, + 2, 2, 2, 2, + 2, 2, 2, 2, + 2, 2, 2, 2 }) + app.undo() + +end From 233c56a8806778bd5c804210cd22fe60565cba1f Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 28 Jul 2020 17:44:31 -0300 Subject: [PATCH 138/200] Check ColorSpace{} constructor --- scripts/color_space.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/color_space.lua b/scripts/color_space.lua index 9107430c6..103c89209 100644 --- a/scripts/color_space.lua +++ b/scripts/color_space.lua @@ -4,8 +4,10 @@ -- Read LICENSE.txt for more information. local none = ColorSpace() -- None -local srgb = ColorSpace{ sRGB } +local srgb = ColorSpace{ sRGB=true } +local none2 = ColorSpace{ sRGB=false } assert(none ~= srgb) +assert(none == none2) local spr = Sprite(32, 32) local cs1 = spr.colorSpace From 34789673a42e521b49cf527329805645aed3494d Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 28 Jul 2020 17:44:43 -0300 Subject: [PATCH 139/200] Test new Sprite{ fromFile="...", oneFrame=true } API --- scripts/sprite.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/sprite.lua b/scripts/sprite.lua index e9846bdb1..a08d6f801 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -125,3 +125,21 @@ do local s2 = Sprite{ fromFile="_test_sprite_gridbounds.png" } assert(s.gridBounds == Rectangle{2, 3, 8, 4}) end + +-- Sprite{ fromFile, oneFrame } +do + local s = Sprite(32, 32) + s:newFrame() + s:saveAs("_test1.png") + assert(#s.frames == 2) + + s = Sprite{ fromFile="_test1.png" } + print(#s.frames) + assert(#s.frames == 2) + + s = Sprite{ fromFile="_test1.png", oneFrame=true } + assert(#s.frames == 1) + + s = Sprite{ fromFile="_test1.png", oneFrame=false } + assert(#s.frames == 2) +end From e08f4f582778637edde953b0dda01d0f34697ea6 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 7 Aug 2020 13:12:08 -0300 Subject: [PATCH 140/200] Merge stdout/stderr in the same output In this way we can print() lines from Lua + debug use TRACE() lines from code to test/debug. --- run-tests.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index c04686469..a1459334e 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -46,7 +46,7 @@ if [[ "$filter" == "" ]] || [[ "console" =~ $filter ]]; then echo ---------------------------------------------------------------------- echo "Testing console..." - $ASEPRITE -b --script scripts/console_assert.lua >$t/tmp 2>$t/tmp_err + $ASEPRITE -b --script scripts/console_assert.lua >$t/tmp 2>&1 ! grep -q "this should be in the output" $t/tmp && fail "print() text not found in output" ! grep -q "assertion failed" $t/tmp && fail "assert() text not found in output" grep -q "this should not be in the output" $t/tmp && fail "text that shouldn't be in the output is" @@ -54,7 +54,7 @@ if [[ "$filter" == "" ]] || [[ "console" =~ $filter ]]; then if [[ "$(uname)" =~ "MINGW32" ]] || [[ "$(uname)" =~ "MSYS_NT-10.0" ]] ; then echo Ignore console tests on Windows else - $ASEPRITE -b --script scripts/console_print.lua >$t/tmp 2>$t/tmp_err + $ASEPRITE -b --script scripts/console_print.lua >$t/tmp 2>&1 cat >$t/tmp_expected <$t/tmp 2>$t/tmp_err ; then - echo FAILED - echo STDOUT && cat $t/tmp - echo STDERR && cat $t/tmp_err + if ! $ASEPRITE -b --script $script >$t/tmp 2>&1 ; then + echo FAILED && cat $t/tmp result=1 fi done From 72a10c6ca1758d39ee6f090981c96eb4b5e228a1 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 21 Aug 2020 21:31:23 -0300 Subject: [PATCH 141/200] Some adjustments to tilemap tests --- scripts/tilemap.lua | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua index 97c9f6300..352edad6a 100644 --- a/scripts/tilemap.lua +++ b/scripts/tilemap.lua @@ -138,7 +138,7 @@ do tilesetMode=TilesetMode.STACK, points={ Point(0, 0), Point(31, 31) }} - local cel = tm.cels[1]; + local cel = tm.cels[1] expect_eq(2, #ts) expect_img(cel.image, { 0,1,1,1, 1,0,1,1, @@ -147,11 +147,11 @@ do app.useTool{ tool='pencil', - color=Color(0), + color=Color{ index=0 }, tilemapMode=TilemapMode.TILES, tilesetMode=TilesetMode.STACK, points={ Point(0, 16) }} -- y=16 is the first pixel of 3rd row of tiles - cel = tm.cels[1]; + cel = tm.cels[1] expect_img(cel.image, { 0,1,1,1, 1,0,1,1, 0,1,0,1, @@ -159,11 +159,11 @@ do app.useTool{ tool='pencil', - color=Color(0), + color=Color{ index=0 }, tilemapMode=TilemapMode.TILES, tilesetMode=TilesetMode.STACK, points={ Point(0, 0), Point(16, 0) }} -- x=16 is the first pixel of 3rd column of tiles - cel = tm.cels[1]; + cel = tm.cels[1] expect_img(cel.image, { 0,0,0,1, 1,0,1,1, 0,1,0,1, @@ -174,28 +174,33 @@ do expect_eq(Point{ 10, 8 }, cel.position) app.useTool{ tool='pencil', - color=Color(1), + color=Color{ index=1 }, tilemapMode=TilemapMode.TILES, tilesetMode=TilesetMode.STACK, - points={ Point(10, 8) }} -- {10,8} is the first existent tile in the tilemap - cel = tm.cels[1]; + points={ { 10, 8 }, { 18, 16 } }} -- {10,8} is the first existent tile in the tilemap + -- these are tiles 2,1 and 3,2 + cel = tm.cels[1] expect_img(cel.image, { 1,0,0,1, - 1,0,1,1, + 1,1,1,1, 0,1,0,1, 1,1,1,0 }) app.useTool{ tool='pencil', - color=Color(0), + color=Color{ index=0 }, tilemapMode=TilemapMode.TILES, tilesetMode=TilesetMode.STACK, - points={ Point(0, 0), Point(8, 8) }} -- Tile 0,0 and 1,1 - cel = tm.cels[1]; - expect_img(cel.image, { 0,1, 1,1,1,1, - 1,0, 1,0,0,1, - 1,1, 1,0,1,1, - 1,1, 0,1,0,1, - 1,1, 1,1,1,0 }) + points={ Point(1, 7), Point(2, 8) }} -- Tile 0,0 and 1,1 + + -- TODO add a constant for the empty tile + local e = 4294967295 -- empty tile (0xffffffff) + + cel = tm.cels[1] + expect_img(cel.image, { 0,e, e,e,e,e, + e,0, 1,0,0,1, + e,e, 1,1,1,1, + e,e, 0,1,0,1, + e,e, 1,1,1,0 }) end From 32b1348a977eecb4cbde1c32c7bacd90006d2d1d Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 13 Oct 2020 11:52:35 -0300 Subject: [PATCH 142/200] Some extra tests for user data text --- scripts/layer.lua | 3 +++ scripts/slice.lua | 3 +++ scripts/tag.lua | 3 +++ 3 files changed, 9 insertions(+) diff --git a/scripts/layer.lua b/scripts/layer.lua index 9f4372497..6eb6ec083 100644 --- a/scripts/layer.lua +++ b/scripts/layer.lua @@ -16,4 +16,7 @@ do assert(l.name == "My Layer") assert(l.opacity == 128) assert(l.blendMode == BlendMode.MULTIPLY) + + l.data = "Data" + assert(l.data == "Data") end diff --git a/scripts/slice.lua b/scripts/slice.lua index 85e62147e..3794e4a3e 100644 --- a/scripts/slice.lua +++ b/scripts/slice.lua @@ -21,4 +21,7 @@ do assert(a.pivot == nil) a.pivot = Point(16, 17) assert(a.pivot == Point(16, 17)) + + a.data = "Data" + assert(a.data == "Data") end diff --git a/scripts/tag.lua b/scripts/tag.lua index 67b9bd1a0..d49604ac6 100644 --- a/scripts/tag.lua +++ b/scripts/tag.lua @@ -35,4 +35,7 @@ do assert(a.color == Color(0, 0, 0)) a.color = Color(255, 0, 0) assert(a.color == Color(255, 0, 0)) + + a.data = "Data" + assert(a.data == "Data") end From 6f65211803fec8d166cff76ca2188527d8fdbd15 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 13 Oct 2020 16:52:53 -0300 Subject: [PATCH 143/200] Minor change in tilemap.lua to identify empty tiles --- scripts/tilemap.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua index 352edad6a..1df9df0c2 100644 --- a/scripts/tilemap.lua +++ b/scripts/tilemap.lua @@ -193,7 +193,7 @@ do points={ Point(1, 7), Point(2, 8) }} -- Tile 0,0 and 1,1 -- TODO add a constant for the empty tile - local e = 4294967295 -- empty tile (0xffffffff) + local e = tonumber("ffffffff", 16) -- empty tile (0xffffffff) cel = tm.cels[1] expect_img(cel.image, { 0,e, e,e,e,e, From 475b81b78cd33a76895b3ee78a6a7646a7b4e304 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 13 Oct 2020 16:55:44 -0300 Subject: [PATCH 144/200] Add some tests for app.command.Fill() --- scripts/app_command.lua | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/scripts/app_command.lua b/scripts/app_command.lua index 50c3b30a4..8a2f9602b 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -543,3 +543,49 @@ do expect_img(j, { 7, 2, 1, 4, 3, 6, 5, 0 }) end + +-- Fill +do + local s = Sprite(4, 2, ColorMode.INDEXED) + local c = s.cels[1] + local i = c.image + i:clear(1) + array_to_pixels({ 1, 1, 1, 1, + 1, 1, 1, 1 }, i) + app.fgColor = Color{ index=0 } + s.selection = Selection(Rectangle(1, 1, 2, 1)) + app.command.Fill() + expect_eq(Rectangle(0, 0, 4, 2), c.bounds) + expect_img(i, { 1, 1, 1, 1, + 1, 0, 0, 1 }) + + c.position = { x=0, y=1 } + app.fgColor = Color{ index=2 } + s.selection = Selection(Rectangle(1, 0, 2, 2)) + app.command.Fill() + expect_eq(Rectangle(0, 0, 4, 3), c.bounds) + expect_img(i, { 0, 2, 2, 0, + 1, 2, 2, 1, + 1, 0, 0, 1 }) + + app.fgColor = Color{ index=0 } + s.selection = Selection(Rectangle(0, 0, 3, 3)) + app.command.Fill() + expect_eq(Rectangle(3, 1, 1, 2), c.bounds) + expect_img(i, { 1, + 1 }) + + app.undo() -- undo Fill + expect_eq(Rectangle(0, 0, 4, 3), c.bounds) + expect_img(i, { 0, 2, 2, 0, + 1, 2, 2, 1, + 1, 0, 0, 1 }) + + expect_eq(Rectangle(0, 0, 3, 3), s.selection.bounds) + app.undo() -- undo selection change + expect_eq(Rectangle(1, 0, 2, 2), s.selection.bounds) + app.undo() -- undo Fill + expect_eq(Rectangle(0, 1, 4, 2), c.bounds) + expect_img(i, { 1, 1, 1, 1, + 1, 0, 0, 1 }) +end From c4252301bf0272433d9c22d8922b536e963f602c Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 22 Oct 2020 11:38:51 -0300 Subject: [PATCH 145/200] New tests for functions to manipulate directories --- scripts/app_fs.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/app_fs.lua b/scripts/app_fs.lua index ab2fa6235..e3e38949c 100644 --- a/scripts/app_fs.lua +++ b/scripts/app_fs.lua @@ -52,3 +52,26 @@ do assert(runTestsFound) assert(readmeFound) end + +-- Create directories +do + assert(fs.makeDirectory("_tmp")) + assert(fs.isDirectory("_tmp")) + + assert(fs.makeAllDirectories("_tmp/a/b")) + assert(fs.isDirectory("_tmp/a")) + assert(fs.isDirectory("_tmp/a/b")) + + assert(fs.removeDirectory("_tmp/a/b")) + assert(not fs.isDirectory("_tmp/a/b")) + assert(fs.isDirectory("_tmp/a")) + + assert(not fs.removeDirectory("_tmp")) -- Should fail + assert(fs.isDirectory("_tmp/a")) + assert(fs.isDirectory("_tmp")) + + assert(fs.removeDirectory("_tmp/a")) + assert(fs.removeDirectory("_tmp")) + assert(not fs.isDirectory("_tmp/a")) + assert(not fs.isDirectory("_tmp")) +end From e3a24035019b52ec4352af26f9680b89cd0b7b79 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 30 Oct 2020 16:36:49 -0300 Subject: [PATCH 146/200] Update tilemap tests with recent changes in the impl --- scripts/tilemap.lua | 318 ++++++++++++++++++++++---------------------- 1 file changed, 161 insertions(+), 157 deletions(-) diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua index 1df9df0c2..4b4d63174 100644 --- a/scripts/tilemap.lua +++ b/scripts/tilemap.lua @@ -13,8 +13,8 @@ local rgba = app.pixelColor.rgba -- Check constants assert(TilemapMode.PIXELS == 0) assert(TilemapMode.TILES == 1) -assert(TilesetMode.MANUAL == 0) -assert(TilesetMode.AUTO == 1) +assert(TilesetMode.AUTO == 0) +assert(TilesetMode.MANUAL == 1) assert(TilesetMode.STACK == 2) ---------------------------------------------------------------------- @@ -56,15 +56,15 @@ do assert(spr.tilesets[1] == tilemapLay.tileset) local tileset = tilemapLay.tileset - assert(#tileset == 1) -- one tile + assert(#tileset == 2) -- empty tile + our tile tilemapCel.position = Point(2, 2) assert(tilemapCel.bounds == Rectangle(2, 2, 16, 16)) - assert(#tileset == 1) + assert(#tileset == 2) assert(tilemapCel.image.width == 1) assert(tilemapCel.image.height == 1) - assert(tilemapCel.image:getPixel(0, 0) == 0) + assert(tilemapCel.image:getPixel(0, 0) == 1) ---------------------------------------------------------------------- -- Draw a second pixel with locked mode (new tiles are not generated) @@ -78,7 +78,7 @@ do points={ Point(0, 0) }} assert(tilemapCel.bounds == Rectangle(2, 2, 16, 16)) - assert(#tileset == 1) + assert(#tileset == 2) ---------------------------------------------------------------------- -- Draw pixels generating new tiles @@ -93,11 +93,11 @@ do assert(tilemapCel.bounds == Rectangle(-14, -14, 32, 32)) assert(#tileset == 3) - assert(not tileset:getTile(0):isEmpty()) + assert(tileset:getTile(0):isEmpty()) assert(not tileset:getTile(1):isEmpty()) - assert(tileset:getTile(2):isEmpty()) - expect_img(tilemapCel.image, { 1, 2, - 2, 0 }) + assert(not tileset:getTile(2):isEmpty()) + expect_img(tilemapCel.image, { 2, 0, + 0, 1 }) app.useTool{ tool='pencil', @@ -109,9 +109,9 @@ do assert(tilemapCel.bounds == Rectangle(-14, -14, 48, 48)) assert(#tilemapLay.tileset == 4) assert(not tileset:getTile(3):isEmpty()) - expect_img(tilemapCel.image, { 1, 2, 2, - 2, 0, 2, - 2, 2, 3 }) + expect_img(tilemapCel.image, { 2, 0, 0, + 0, 1, 0, + 0, 0, 3 }) end ---------------------------------------------------------------------- @@ -140,67 +140,64 @@ do local cel = tm.cels[1] expect_eq(2, #ts) - expect_img(cel.image, { 0,1,1,1, - 1,0,1,1, - 1,1,0,1, - 1,1,1,0 }) + expect_img(cel.image, { 1,0,0,0, + 0,1,0,0, + 0,0,1,0, + 0,0,0,1 }) app.useTool{ tool='pencil', - color=Color{ index=0 }, + color=Color{ index=1 }, tilemapMode=TilemapMode.TILES, tilesetMode=TilesetMode.STACK, points={ Point(0, 16) }} -- y=16 is the first pixel of 3rd row of tiles cel = tm.cels[1] - expect_img(cel.image, { 0,1,1,1, - 1,0,1,1, - 0,1,0,1, - 1,1,1,0 }) + expect_img(cel.image, { 1,0,0,0, + 0,1,0,0, + 1,0,1,0, + 0,0,0,1 }) app.useTool{ tool='pencil', - color=Color{ index=0 }, + color=Color{ index=1 }, tilemapMode=TilemapMode.TILES, tilesetMode=TilesetMode.STACK, points={ Point(0, 0), Point(16, 0) }} -- x=16 is the first pixel of 3rd column of tiles cel = tm.cels[1] - expect_img(cel.image, { 0,0,0,1, - 1,0,1,1, - 0,1,0,1, - 1,1,1,0 }) + expect_img(cel.image, { 1,1,1,0, + 0,1,0,0, + 1,0,1,0, + 0,0,0,1 }) -- Move layer origin to 10, 8 cel.position = { 10, 8 } expect_eq(Point{ 10, 8 }, cel.position) app.useTool{ tool='pencil', - color=Color{ index=1 }, + color=Color{ index=0 }, tilemapMode=TilemapMode.TILES, tilesetMode=TilesetMode.STACK, points={ { 10, 8 }, { 18, 16 } }} -- {10,8} is the first existent tile in the tilemap -- these are tiles 2,1 and 3,2 cel = tm.cels[1] - expect_img(cel.image, { 1,0,0,1, - 1,1,1,1, - 0,1,0,1, - 1,1,1,0 }) + expect_img(cel.image, { 0,1,1,0, + 0,0,0,0, + 1,0,1,0, + 0,0,0,1 }) app.useTool{ tool='pencil', - color=Color{ index=0 }, + color=Color{ index=1 }, tilemapMode=TilemapMode.TILES, tilesetMode=TilesetMode.STACK, points={ Point(1, 7), Point(2, 8) }} -- Tile 0,0 and 1,1 - -- TODO add a constant for the empty tile - local e = tonumber("ffffffff", 16) -- empty tile (0xffffffff) - cel = tm.cels[1] - expect_img(cel.image, { 0,e, e,e,e,e, - e,0, 1,0,0,1, - e,e, 1,1,1,1, - e,e, 0,1,0,1, - e,e, 1,1,1,0 }) + expect_img(cel.image, { 1,0, 0,0,0,0, + 0,1, 0,1,1,0, + 0,0, 0,0,0,0, + 0,0, 1,0,1,0, + 0,0, 0,0,0,1 }) end @@ -223,7 +220,7 @@ do assert(tilemapCel.bounds == Rectangle(0, 0, 16, 16)) local tileset = tilemapLay.tileset - assert(#tileset == 1) -- one tile + assert(#tileset == 2) -- empty tile + our tile tilemapCel.position = Point(-1, -1) assert(tilemapCel.bounds == Rectangle(-1, -1, 16, 16)) @@ -236,9 +233,9 @@ do points={ Point(0, 0) }} assert(tilemapCel.bounds == Rectangle(-1, -1, 16, 16)) - assert(#tileset == 2) + assert(#tileset == 3) - local img = tileset:getTile(1) + local img = tileset:getTile(2) assert(img:getPixel(0, 0) == rgba(0, 255, 0, 255)) assert(img:getPixel(1, 0) == rgba(0, 0, 0, 0)) @@ -298,142 +295,149 @@ do points={ Point(0, 0), Point(31, 31) }} local ts = tilemapLay.tileset - assert(#ts == 4) + assert(#ts == 5) - local imgs = { ts:getTile(0), - ts:getTile(1), + local imgs = { ts:getTile(1), ts:getTile(2), - ts:getTile(3) } + ts:getTile(3), + ts:getTile(4) } - -- No op = move tile 0 before the tile 0, result=0,1,2,3 - app.range.tiles = { 0 } - app.command.MoveTiles{ before=0 } - expect_eq(imgs[0+1], ts:getTile(0)) - expect_eq(imgs[1+1], ts:getTile(1)) - expect_eq(imgs[2+1], ts:getTile(2)) - expect_eq(imgs[3+1], ts:getTile(3)) - expect_eq(1, #app.range.tiles) - expect_eq(0, app.range.tiles[1]) - - -- Move tile 1 before tile 0, result=1,0,2,3 + -- No op = move tile 1 before the tile 1, result=0,1,2,3,4 app.range.tiles = { 1 } - app.command.MoveTiles{ before=0 } - expect_eq(imgs[1+1], ts:getTile(0)) - expect_eq(imgs[0+1], ts:getTile(1)) - expect_eq(imgs[2+1], ts:getTile(2)) - expect_eq(imgs[3+1], ts:getTile(3)) + app.command.MoveTiles{ before=1 } + expect_eq(imgs[1], ts:getTile(1)) + expect_eq(imgs[2], ts:getTile(2)) + expect_eq(imgs[3], ts:getTile(3)) + expect_eq(imgs[4], ts:getTile(4)) expect_eq(1, #app.range.tiles) - expect_eq(0, app.range.tiles[1]) - app.undo() - - -- Move tiles 0 and 1 before 3, result=2,0,1,3 - app.range.tiles = { 0, 1 } - app.command.MoveTiles({ before=3 }) - expect_eq(imgs[2+1], ts:getTile(0)) - expect_eq(imgs[0+1], ts:getTile(1)) - expect_eq(imgs[1+1], ts:getTile(2)) - expect_eq(imgs[3+1], ts:getTile(3)) - expect_eq(2, #app.range.tiles) expect_eq(1, app.range.tiles[1]) - expect_eq(2, app.range.tiles[2]) - app.undo() - -- Move tiles 0 and 2 before 2, result=1,0,2,3 - app.range.tiles = { 0, 2 } - app.command.MoveTiles({ before=2 }) - expect_eq(imgs[1+1], ts:getTile(0)) - expect_eq(imgs[0+1], ts:getTile(1)) - expect_eq(imgs[2+1], ts:getTile(2)) - expect_eq(imgs[3+1], ts:getTile(3)) - expect_eq(2, #app.range.tiles) + -- Move tile 2 before tile 1, result=0,2,1,3,4 + app.range.tiles = { 2 } + app.command.MoveTiles{ before=1 } + expect_eq(imgs[2], ts:getTile(1)) + expect_eq(imgs[1], ts:getTile(2)) + expect_eq(imgs[3], ts:getTile(3)) + expect_eq(imgs[4], ts:getTile(4)) + expect_eq(1, #app.range.tiles) expect_eq(1, app.range.tiles[1]) - expect_eq(2, app.range.tiles[2]) app.undo() - -- Copy tiles 0 before 0, result=0,0,1,2,3 - app.range.tiles = { 0 } - app.command.CopyTiles({ before=0 }) - expect_eq(1, #app.range.tiles) - expect_eq(0, app.range.tiles[1]) - expect_eq(5, #ts) - assert(ts:getTile(0):isEqual(imgs[0+1])) - assert(ts:getTile(1):isEqual(imgs[0+1])) - assert(ts:getTile(2):isEqual(imgs[1+1])) - assert(ts:getTile(3):isEqual(imgs[2+1])) - assert(ts:getTile(4):isEqual(imgs[3+1])) + -- Move tiles 1 and 2 before 4, result=0,3,1,2,4 + app.range.tiles = { 1, 2 } + app.command.MoveTiles({ before=4 }) + expect_eq(imgs[3], ts:getTile(1)) + expect_eq(imgs[1], ts:getTile(2)) + expect_eq(imgs[2], ts:getTile(3)) + expect_eq(imgs[4], ts:getTile(4)) + expect_eq(2, #app.range.tiles) + expect_eq(2, app.range.tiles[1]) + expect_eq(3, app.range.tiles[2]) app.undo() - -- Copy tiles 0 before 3, result=0,1,2,0,3 - app.range.tiles = { 0 } - app.command.CopyTiles({ before=3 }) - expect_eq(1, #app.range.tiles) - expect_eq(3, app.range.tiles[1]) - expect_eq(5, #ts) - assert(ts:getTile(0):isEqual(imgs[0+1])) - assert(ts:getTile(1):isEqual(imgs[1+1])) - assert(ts:getTile(2):isEqual(imgs[2+1])) - assert(ts:getTile(3):isEqual(imgs[0+1])) - assert(ts:getTile(4):isEqual(imgs[3+1])) - app.undo() - - -- Copy tiles 0, 1, and 3, before 4, result=0,1,2,3,0,1,3 - app.range.tiles = { 0, 1, 3 } - app.command.CopyTiles({ before=4 }) - assert(ts:getTile(0):isEqual(imgs[0+1])) - assert(ts:getTile(1):isEqual(imgs[1+1])) - assert(ts:getTile(2):isEqual(imgs[2+1])) - assert(ts:getTile(3):isEqual(imgs[3+1])) - assert(ts:getTile(4):isEqual(imgs[0+1])) - assert(ts:getTile(5):isEqual(imgs[1+1])) - assert(ts:getTile(6):isEqual(imgs[3+1])) - app.undo() - - -- Copy tiles 1, and 3, before 0, result=1,3,0,1,2,3 + -- Move tiles 1 and 3 before 3, result=0,2,1,3,4 app.range.tiles = { 1, 3 } - app.command.CopyTiles({ before=0 }) - assert(ts:getTile(0):isEqual(imgs[1+1])) - assert(ts:getTile(1):isEqual(imgs[3+1])) - assert(ts:getTile(2):isEqual(imgs[0+1])) - assert(ts:getTile(3):isEqual(imgs[1+1])) - assert(ts:getTile(4):isEqual(imgs[2+1])) - assert(ts:getTile(5):isEqual(imgs[3+1])) + app.command.MoveTiles({ before=3 }) + expect_eq(imgs[2], ts:getTile(1)) + expect_eq(imgs[1], ts:getTile(2)) + expect_eq(imgs[3], ts:getTile(3)) + expect_eq(imgs[4], ts:getTile(4)) + expect_eq(2, #app.range.tiles) + expect_eq(2, app.range.tiles[1]) + expect_eq(3, app.range.tiles[2]) app.undo() - -- Copy tiles 0, and 3, before 7, result=0,1,2,3,0,3 - app.range.tiles = { 0, 3 } + -- Copy tiles 1 before 1, result=0,1,1,2,3,4 + app.range.tiles = { 1 } + app.command.CopyTiles({ before=1 }) + expect_eq(1, #app.range.tiles) + expect_eq(1, app.range.tiles[1]) + expect_eq(6, #ts) + assert(ts:getTile(0):isEmpty()) + assert(ts:getTile(1):isEqual(imgs[1])) + assert(ts:getTile(2):isEqual(imgs[1])) + assert(ts:getTile(3):isEqual(imgs[2])) + assert(ts:getTile(4):isEqual(imgs[3])) + assert(ts:getTile(5):isEqual(imgs[4])) + app.undo() + + -- Copy tiles 1 before 4, result=0,1,2,3,1,4 + app.range.tiles = { 1 } app.command.CopyTiles({ before=4 }) - assert(ts:getTile(0):isEqual(imgs[0+1])) - assert(ts:getTile(1):isEqual(imgs[1+1])) - assert(ts:getTile(2):isEqual(imgs[2+1])) - assert(ts:getTile(3):isEqual(imgs[3+1])) - assert(ts:getTile(4):isEqual(imgs[0+1])) - assert(ts:getTile(5):isEqual(imgs[3+1])) + expect_eq(1, #app.range.tiles) + expect_eq(4, app.range.tiles[1]) + expect_eq(6, #ts) + assert(ts:getTile(0):isEmpty()) + assert(ts:getTile(1):isEqual(imgs[1])) + assert(ts:getTile(2):isEqual(imgs[2])) + assert(ts:getTile(3):isEqual(imgs[3])) + assert(ts:getTile(4):isEqual(imgs[1])) + assert(ts:getTile(5):isEqual(imgs[4])) app.undo() - -- Copy tiles 0, and 3, before 7, result=0,1,2,3,-,0,3 - app.range.tiles = { 0, 3 } + -- Copy tiles 1, 2, and 4, before 5, result=0,1,2,3,4,1,2,4 + app.range.tiles = { 1, 2, 4 } app.command.CopyTiles({ before=5 }) - assert(ts:getTile(0):isEqual(imgs[0+1])) - assert(ts:getTile(1):isEqual(imgs[1+1])) - assert(ts:getTile(2):isEqual(imgs[2+1])) - assert(ts:getTile(3):isEqual(imgs[3+1])) - assert(ts:getTile(4):isPlain()) - assert(ts:getTile(5):isEqual(imgs[0+1])) - assert(ts:getTile(6):isEqual(imgs[3+1])) + assert(ts:getTile(0):isEmpty()) + assert(ts:getTile(1):isEqual(imgs[1])) + assert(ts:getTile(2):isEqual(imgs[2])) + assert(ts:getTile(3):isEqual(imgs[3])) + assert(ts:getTile(4):isEqual(imgs[4])) + assert(ts:getTile(5):isEqual(imgs[1])) + assert(ts:getTile(6):isEqual(imgs[2])) + assert(ts:getTile(7):isEqual(imgs[4])) app.undo() - -- Copy tiles 2, and 3, before 7, result=0,1,2,3,-,-,-,2,3 - app.range.tiles = { 2, 3 } - app.command.CopyTiles({ before=7 }) - assert(ts:getTile(0):isEqual(imgs[0+1])) - assert(ts:getTile(1):isEqual(imgs[1+1])) - assert(ts:getTile(2):isEqual(imgs[2+1])) - assert(ts:getTile(3):isEqual(imgs[3+1])) - assert(ts:getTile(4):isPlain()) + -- Copy tiles 2, and 4, before 1, result=0,2,4,1,2,3,4 + app.range.tiles = { 2, 4 } + app.command.CopyTiles({ before=1 }) + assert(ts:getTile(0):isEmpty()) + assert(ts:getTile(1):isEqual(imgs[2])) + assert(ts:getTile(2):isEqual(imgs[4])) + assert(ts:getTile(3):isEqual(imgs[1])) + assert(ts:getTile(4):isEqual(imgs[2])) + assert(ts:getTile(5):isEqual(imgs[3])) + assert(ts:getTile(6):isEqual(imgs[4])) + app.undo() + + -- Copy tiles 1, and 4, before 5, result=0,1,2,3,4,1,4 + app.range.tiles = { 1, 4 } + app.command.CopyTiles({ before=5 }) + assert(ts:getTile(0):isEmpty()) + assert(ts:getTile(1):isEqual(imgs[1])) + assert(ts:getTile(2):isEqual(imgs[2])) + assert(ts:getTile(3):isEqual(imgs[3])) + assert(ts:getTile(4):isEqual(imgs[4])) + assert(ts:getTile(5):isEqual(imgs[1])) + assert(ts:getTile(6):isEqual(imgs[4])) + app.undo() + + -- Copy tiles 1, and 4, before 6, result=0,1,2,3,4,-,1,4 + app.range.tiles = { 1, 4 } + app.command.CopyTiles({ before=6 }) + assert(ts:getTile(0):isEmpty()) + assert(ts:getTile(1):isEqual(imgs[1])) + assert(ts:getTile(2):isEqual(imgs[2])) + assert(ts:getTile(3):isEqual(imgs[3])) + assert(ts:getTile(4):isEqual(imgs[4])) + assert(ts:getTile(5):isEmpty()) + assert(ts:getTile(6):isEqual(imgs[1])) + assert(ts:getTile(7):isEqual(imgs[4])) + app.undo() + + -- Copy tiles 3, and 4, before 8, result=0,1,2,3,4,-,-,-,3,4 + app.range.tiles = { 3, 4 } + app.command.CopyTiles({ before=8 }) + assert(ts:getTile(0):isEmpty()) + assert(ts:getTile(1):isEqual(imgs[1])) + assert(ts:getTile(2):isEqual(imgs[2])) + assert(ts:getTile(3):isEqual(imgs[3])) + assert(ts:getTile(4):isEqual(imgs[4])) assert(ts:getTile(5):isPlain()) assert(ts:getTile(6):isPlain()) - assert(ts:getTile(7):isEqual(imgs[2+1])) - assert(ts:getTile(8):isEqual(imgs[3+1])) + assert(ts:getTile(7):isPlain()) + assert(ts:getTile(8):isEqual(imgs[3])) + assert(ts:getTile(9):isEqual(imgs[4])) app.undo() end From d1ebec4006a85866ad9473b0a8fc548985c9381e Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 4 Nov 2020 16:57:33 -0300 Subject: [PATCH 147/200] Update tilemap tests to check the manual mode a little more --- scripts/tilemap.lua | 111 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 96 insertions(+), 15 deletions(-) diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua index 4b4d63174..71b08b243 100644 --- a/scripts/tilemap.lua +++ b/scripts/tilemap.lua @@ -13,8 +13,8 @@ local rgba = app.pixelColor.rgba -- Check constants assert(TilemapMode.PIXELS == 0) assert(TilemapMode.TILES == 1) -assert(TilesetMode.AUTO == 0) -assert(TilesetMode.MANUAL == 1) +assert(TilesetMode.MANUAL == 0) +assert(TilesetMode.AUTO == 1) assert(TilesetMode.STACK == 2) ---------------------------------------------------------------------- @@ -22,7 +22,8 @@ assert(TilesetMode.STACK == 2) ---------------------------------------------------------------------- do - local spr = Sprite(32, 32) + local spr = Sprite(32, 32, ColorMode.INDEXED) + spr.gridBounds = Rectangle{ 0, 0, 4, 4 } assert(spr.layers[1].isImage) assert(not spr.layers[1].isTilemap) @@ -43,23 +44,29 @@ do app.useTool{ tool='pencil', - color=Color{ r=0, g=0, b=0 }, + color=1, layer=tilemapLay, tilesetMode=TilesetMode.STACK, - points={ Point(2, 2), Point(3, 2) }} + points={ Point(1, 2), Point(2, 2) }} assert(#tilemapLay.cels == 1) assert(tilemapLay:cel(1).image.colorMode == ColorMode.TILEMAP) local tilemapCel = tilemapLay:cel(1) - assert(tilemapCel.bounds == Rectangle(0, 0, 16, 16)) + assert(tilemapCel.bounds == Rectangle(0, 0, 4, 4)) assert(#spr.tilesets == 1) -- one tileset assert(spr.tilesets[1] == tilemapLay.tileset) local tileset = tilemapLay.tileset assert(#tileset == 2) -- empty tile + our tile + assert(tileset:getTile(0):isEmpty()) + assert(not tileset:getTile(1):isEmpty()) + expect_img(tileset:getTile(1), { 0,0,0,0, + 0,0,0,0, + 0,1,1,0, + 0,0,0,0 }) tilemapCel.position = Point(2, 2) - assert(tilemapCel.bounds == Rectangle(2, 2, 16, 16)) + assert(tilemapCel.bounds == Rectangle(2, 2, 4, 4)) assert(#tileset == 2) assert(tilemapCel.image.width == 1) @@ -72,12 +79,12 @@ do app.useTool{ tool='pencil', - color=Color{ r=0, g=0, b=0 }, + color=1, cel=tilemapCel, tilesetMode=TilesetMode.MANUAL, points={ Point(0, 0) }} - assert(tilemapCel.bounds == Rectangle(2, 2, 16, 16)) + assert(tilemapCel.bounds == Rectangle(2, 2, 4, 4)) assert(#tileset == 2) ---------------------------------------------------------------------- @@ -86,12 +93,12 @@ do app.useTool{ tool='pencil', - color=Color{ r=0, g=0, b=0 }, + color=1, cel=tilemapCel, tilesetMode=TilesetMode.STACK, points={ Point(0, 0) }} - assert(tilemapCel.bounds == Rectangle(-14, -14, 32, 32)) + assert(tilemapCel.bounds == Rectangle(-2, -2, 8, 8)) assert(#tileset == 3) assert(tileset:getTile(0):isEmpty()) assert(not tileset:getTile(1):isEmpty()) @@ -101,17 +108,91 @@ do app.useTool{ tool='pencil', - color=Color{ r=0, g=0, b=0 }, + color=1, cel=tilemapCel, tilesetMode=TilesetMode.STACK, - points={ Point(19, 19) }} + points={ Point(6, 6) }} - assert(tilemapCel.bounds == Rectangle(-14, -14, 48, 48)) - assert(#tilemapLay.tileset == 4) + assert(tilemapCel.bounds == Rectangle(-2, -2, 12, 12)) + assert(#tileset == 4) assert(not tileset:getTile(3):isEmpty()) expect_img(tilemapCel.image, { 2, 0, 0, 0, 1, 0, 0, 0, 3 }) + + ---------------------------------------------------------------------- + -- Draw in manual mode to modify existent tiles + ---------------------------------------------------------------------- + + assert(tilemapCel.bounds == Rectangle(-2, -2, 12, 12)) + assert(#tileset == 4) + expect_img(tileset:getTile(1), { 0,0,0,0, + 0,0,0,0, + 0,1,1,0, + 0,0,0,0 }) + expect_img(tileset:getTile(2), { 0,0,0,0, + 0,0,0,0, + 0,0,1,0, + 0,0,0,0 }) + expect_img(tileset:getTile(3), { 1,0,0,0, + 0,0,0,0, + 0,0,0,0, + 0,0,0,0 }) + expect_img(tilemapCel.image, { 2, 0, 0, + 0, 1, 0, + 0, 0, 3 }) + + app.useTool{ + tool='rectangle', + color=2, + cel=tilemapCel, + tilesetMode=TilesetMode.MANUAL, + points={ Point(0, 0), Point(9, 9) }} + + assert(tilemapCel.bounds == Rectangle(-2, -2, 12, 12)) + assert(#tileset == 4) + expect_img(tileset:getTile(1), { 0,0,0,0, + 0,0,0,0, + 0,1,1,0, + 0,0,0,0 }) + expect_img(tileset:getTile(2), { 0,0,0,0, + 0,0,0,0, + 0,0,2,2, + 0,0,2,0 }) + expect_img(tileset:getTile(3), { 1,0,0,2, + 0,0,0,2, + 0,0,0,2, + 2,2,2,2 }) + expect_img(tilemapCel.image, { 2, 0, 0, + 0, 1, 0, + 0, 0, 3 }) + + tilemapCel.position = Point(1, 1) + app.useTool{ + tool='line', + color=3, + cel=tilemapCel, + tilesetMode=TilesetMode.MANUAL, + points={ Point(1, 1), Point(12, 12) }} + + assert(tilemapCel.bounds == Rectangle(1, 1, 12, 12)) + assert(#tileset == 4) + expect_img(tileset:getTile(1), { 3,0,0,0, + 0,3,0,0, + 0,1,3,0, + 0,0,0,3 }) + expect_img(tileset:getTile(2), { 3,0,0,0, + 0,3,0,0, + 0,0,3,2, + 0,0,2,3 }) + expect_img(tileset:getTile(3), { 3,0,0,2, + 0,3,0,2, + 0,0,3,2, + 2,2,2,3 }) + expect_img(tilemapCel.image, { 2, 0, 0, + 0, 1, 0, + 0, 0, 3 }) + end ---------------------------------------------------------------------- From b7b4fd1f9763584606589254d307eebae9518a18 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 8 Mar 2021 16:06:35 -0300 Subject: [PATCH 148/200] Update json.lua submodule --- .gitmodules | 2 +- third_party/json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index c55277e57..cbba74050 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "third_party/json"] path = third_party/json - url = https://github.com/rxi/json.lua + url = https://github.com/aseprite/json.lua diff --git a/third_party/json b/third_party/json index bee7ee343..dbf4b2dd2 160000 --- a/third_party/json +++ b/third_party/json @@ -1 +1 @@ -Subproject commit bee7ee3431133009a97257bde73da8a34e53c15c +Subproject commit dbf4b2dd2eb7c23be2773c89eb059dadd6436f94 From 513d57a6b4db880f0cc1f908a24b0004c15e2e10 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 8 Mar 2021 16:07:35 -0300 Subject: [PATCH 149/200] Include uname output in run-tests.sh --- run-tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/run-tests.sh b/run-tests.sh index c04686469..4ad540d18 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -45,6 +45,7 @@ export ASEPRITE_USER_FOLDER=$t if [[ "$filter" == "" ]] || [[ "console" =~ $filter ]]; then echo ---------------------------------------------------------------------- echo "Testing console..." + echo "uname=$(uname)" $ASEPRITE -b --script scripts/console_assert.lua >$t/tmp 2>$t/tmp_err ! grep -q "this should be in the output" $t/tmp && fail "print() text not found in output" From 293f9170b6a1902939e2b3a7bda84f903174fbe8 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 8 Mar 2021 16:28:55 -0300 Subject: [PATCH 150/200] Ignore MINGW64 uname --- run-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index 4ad540d18..ca535ba20 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -33,7 +33,7 @@ if [[ "$filter" != "" ]]; then fi t=$(mktemp -d) -if [[ "$(uname)" =~ "MINGW32" ]] || [[ "$(uname)" =~ "MSYS_NT-10.0" ]] ; then +if [[ "$(uname)" =~ "MINGW" ]] || [[ "$(uname)" =~ "MSYS" ]] ; then PWDARG=-W t=$(cd "$t" && pwd $PWDARG) else @@ -52,7 +52,7 @@ if [[ "$filter" == "" ]] || [[ "console" =~ $filter ]]; then ! grep -q "assertion failed" $t/tmp && fail "assert() text not found in output" grep -q "this should not be in the output" $t/tmp && fail "text that shouldn't be in the output is" - if [[ "$(uname)" =~ "MINGW32" ]] || [[ "$(uname)" =~ "MSYS_NT-10.0" ]] ; then + if [[ "$(uname)" =~ "MINGW" ]] || [[ "$(uname)" =~ "MSYS" ]] ; then echo Ignore console tests on Windows else $ASEPRITE -b --script scripts/console_print.lua >$t/tmp 2>$t/tmp_err From 58235ac14dfd39b8879498049a7a84c9129de22e Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 8 Mar 2021 19:27:07 -0300 Subject: [PATCH 151/200] Try to fix comparing text lines on Windows --- run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-tests.sh b/run-tests.sh index ca535ba20..c7f630de9 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -14,7 +14,7 @@ function fail() { } function expect() { - if [[ $1 != $($2) ]] ; then + if [[ $1 != "$($2 | tr -d "\r")" ]] ; then echo "FAILED: $2" echo "EXPECTED: $1" echo "RESULT: $($2)" From cb674e0bf25ca0b123f5bf4d20b9ffa10c0a3b49 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 9 Mar 2021 09:20:28 -0300 Subject: [PATCH 152/200] Try to fix passing * as an argument in MINGW64 bash It looks like '*' is being converted as a wildcard to list files in the current dir, which doesn't happen in other platforms (?). --- cli/save-as.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cli/save-as.sh b/cli/save-as.sh index a5f6ad8fe..3f54d99fd 100644 --- a/cli/save-as.sh +++ b/cli/save-as.sh @@ -1,5 +1,5 @@ #! /bin/bash -# Copyright (C) 2018-2019 Igara Studio S.A. +# Copyright (C) 2018-2021 Igara Studio S.A. function list_files() { oldwd=$(pwd $PWDARG) @@ -179,25 +179,25 @@ cd $oldwd d=$t/save-as-groups-and-hidden mkdir $d -$ASEPRITE -b sprites/groups2.aseprite -layer '*' -save-as "$d/g2-all.png" || exit 1 -$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer items -save-as "$d/g2-all-without-items.png" || exit 1 -$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer gun -save-as "$d/g2-all-without-gun1.png" || exit 1 -$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer sword -save-as "$d/g2-all-without-sword1.png" || exit 1 -$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer items/gun -save-as "$d/g2-all-without-gun2.png" || exit 1 -$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer items/sword -save-as "$d/g2-all-without-sword2.png" || exit 1 -$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer player -save-as "$d/g2-all-without-player.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer \* -save-as "$d/g2-all.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer items -save-as "$d/g2-all-without-items.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer gun -save-as "$d/g2-all-without-gun1.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer sword -save-as "$d/g2-all-without-sword1.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer items/gun -save-as "$d/g2-all-without-gun2.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer items/sword -save-as "$d/g2-all-without-sword2.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer player -save-as "$d/g2-all-without-player.png" || exit 1 $ASEPRITE -b sprites/groups2.aseprite -layer player -save-as "$d/g2-player.png" || exit 1 $ASEPRITE -b sprites/groups2.aseprite -layer items -save-as "$d/g2-items.png" || exit 1 -$ASEPRITE -b sprites/groups2.aseprite -layer 'items/*' -save-as "$d/g2-items-all.png" || exit 1 +$ASEPRITE -b sprites/groups2.aseprite -layer items/\* -save-as "$d/g2-items-all.png" || exit 1 $ASEPRITE -b sprites/groups2.aseprite -layer sword -save-as "$d/g2-sword.png" || exit 1 $ASEPRITE -b sprites/groups2.aseprite -layer gun -save-as "$d/g2-gun.png" || exit 1 $ASEPRITE -b sprites/groups3abc.aseprite -layer a -save-as "$d/g3-a.png" || exit 1 $ASEPRITE -b sprites/groups3abc.aseprite -layer b -save-as "$d/g3-b.png" || exit 1 $ASEPRITE -b sprites/groups3abc.aseprite -layer c -save-as "$d/g3-c.png" || exit 1 -$ASEPRITE -b sprites/groups3abc.aseprite -layer 'a/*' -save-as "$d/g3-a-all.png" || exit 1 -$ASEPRITE -b sprites/groups3abc.aseprite -layer 'b/*' -save-as "$d/g3-b-all.png" || exit 1 -$ASEPRITE -b sprites/groups3abc.aseprite -layer 'c/*' -save-as "$d/g3-c-all.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer a/\* -save-as "$d/g3-a-all.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer b/\* -save-as "$d/g3-b-all.png" || exit 1 +$ASEPRITE -b sprites/groups3abc.aseprite -layer c/\* -save-as "$d/g3-c-all.png" || exit 1 $ASEPRITE -b sprites/groups3abc.aseprite -layer a/a -save-as "$d/g3-aa.png" || exit 1 $ASEPRITE -b sprites/groups3abc.aseprite -layer b/a -save-as "$d/g3-ba.png" || exit 1 $ASEPRITE -b sprites/groups3abc.aseprite -layer c/a -save-as "$d/g3-ca.png" || exit 1 From eb8e12c94a9b1a9d2f70a8be630deb9bc729c3f3 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 9 Mar 2021 09:59:02 -0300 Subject: [PATCH 153/200] Ignore failing test from save-as.sh on Windows --- cli/save-as.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cli/save-as.sh b/cli/save-as.sh index 3f54d99fd..0063d13e0 100644 --- a/cli/save-as.sh +++ b/cli/save-as.sh @@ -177,6 +177,9 @@ cd $oldwd # --save-as group without showing hidden children # https://github.com/aseprite/aseprite/issues/2084#issuecomment-525835889 +if [[ "$(uname)" =~ "MINGW" ]] || [[ "$(uname)" =~ "MSYS" ]] ; then + # Ignore this test on Windows because we cannot give * as a parameter (?) +else d=$t/save-as-groups-and-hidden mkdir $d $ASEPRITE -b sprites/groups2.aseprite -layer \* -save-as "$d/g2-all.png" || exit 1 @@ -249,3 +252,4 @@ expect_rendered_layers(img("g3-cb"), g3, { "c/b" }) expect_rendered_layers(img("g3-cc"), g3, { "c/c" }) EOF $ASEPRITE -b -script "$d/compare.lua" || exit 1 +fi From 5018d156bdc87ec283494cdf2a1305cbe6cdc577 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 9 Mar 2021 16:38:40 -0300 Subject: [PATCH 154/200] Fix syntax error in save-as.sh --- cli/save-as.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/save-as.sh b/cli/save-as.sh index 0063d13e0..c8791ed36 100644 --- a/cli/save-as.sh +++ b/cli/save-as.sh @@ -179,6 +179,7 @@ cd $oldwd if [[ "$(uname)" =~ "MINGW" ]] || [[ "$(uname)" =~ "MSYS" ]] ; then # Ignore this test on Windows because we cannot give * as a parameter (?) + echo Do nothing else d=$t/save-as-groups-and-hidden mkdir $d From 4bd7d8eb2168a0d8863f34773d0197fcacf5284f Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 7 Apr 2021 11:29:31 -0300 Subject: [PATCH 155/200] Update branch name of aseprite/aseprite repo --- README.md | 6 +++--- scripts/version.lua | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5f0582a0f..0035a1783 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ Test suite for [Aseprite](https://github.com/aseprite/aseprite) to avoid breaking backward compatibility. This project is cloned by the -[.travis.yml](https://github.com/aseprite/aseprite/blob/master/.travis.yml) file +[build.yml](https://github.com/aseprite/aseprite/blob/main/.github/workflows/build.yml) file on Aseprite project to do several automated tests: * Save/load file formats correctly. For this we have `.aseprite`, `.png`, - `.gif`, etc. files [sprites](https://github.com/aseprite/tests/tree/master/sprites) + `.gif`, etc. files [sprites](https://github.com/aseprite/tests/tree/main/sprites) folder. * Test backward compatibility with [Aseprite CLI](https://www.aseprite.org/docs/cli/) options -* Future [scripting API](https://github.com/aseprite/api) using [scripts](https://github.com/aseprite/tests/tree/master/scripts) +* Future [scripting API](https://github.com/aseprite/api) using [scripts](https://github.com/aseprite/tests/tree/main/scripts) ## How to run tests? diff --git a/scripts/version.lua b/scripts/version.lua index 9137835c1..024b43b4b 100644 --- a/scripts/version.lua +++ b/scripts/version.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019 Igara Studio S.A. +-- Copyright (C) 2019-2021 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -8,7 +8,7 @@ assert(string.sub(tostring(app.version), 1, 1) == "1") assert(string.sub(tostring(app.version), 2, 2) == ".") assert(app.version.major == 1) --- We cannot test the specific app.version from the master branch +-- We cannot test the specific app.version from the "main" branch -- because it's "1.x-dev" (which is converted to "1.0-dev" as Version object) --assert(app.version > Version("1.2.10-beta4")) From ffb4397238344bd3d4844c11ce520b98e95d4ed9 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 7 Apr 2021 12:57:24 -0300 Subject: [PATCH 156/200] Reset tool preferences just once when running from CLI --- LICENSE.txt | 2 +- scripts/app_preferences.lua | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 73cdac56d..a1db71aea 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2018-2020 Igara Studio S.A. +Copyright (c) 2018-2021 Igara Studio S.A. Copyright (c) 2018 David Capello Permission is hereby granted, free of charge, to any person obtaining diff --git a/scripts/app_preferences.lua b/scripts/app_preferences.lua index 9c2a96c4f..82cbe4286 100644 --- a/scripts/app_preferences.lua +++ b/scripts/app_preferences.lua @@ -1,10 +1,13 @@ --- Copyright (C) 2019 Igara Studio S.A. +-- Copyright (C) 2019-2021 Igara Studio S.A. -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. -- Preferences for tools do + -- The first time we get the tool preferences in CLI mode, we get + -- the default options for this tool (in GUI, we get the current + -- user-defined options). local t = app.preferences.tool('pencil') assert(t.opacity == 255) assert(t.tolerance == 0) @@ -14,10 +17,10 @@ do t.brush.size = 2 assert(t.brush.size == 2) - -- Getting the tool again will give us the default configuration - -- again in batch mode + -- Getting the tool again must give us the configuration that was + -- set inside the script t = app.preferences.tool('pencil') - assert(t.brush.size == 1) + assert(t.brush.size == 2) end -- Preferences for documents From 3a63ec4cf013bca6f883e40f103039e967f4ba73 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 7 Apr 2021 13:02:27 -0300 Subject: [PATCH 157/200] Add tests for paint_bucket tool --- scripts/paint_bucket.lua | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 scripts/paint_bucket.lua diff --git a/scripts/paint_bucket.lua b/scripts/paint_bucket.lua new file mode 100644 index 000000000..52276f617 --- /dev/null +++ b/scripts/paint_bucket.lua @@ -0,0 +1,55 @@ +-- Copyright (C) 2020-2021 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +dofile('./test_utils.lua') + +app.activeTool = 'paint_bucket' +assert(app.activeTool.id == 'paint_bucket') +assert(app.activeBrush.type == BrushType.CIRCLE) +assert(app.activeBrush.size == 1) +assert(app.activeBrush.angle == 0) +assert(app.preferences.tool('paint_bucket').floodfill.pixel_connectivity == 0) + +local function test_paint_bucket(colorMode, a, b, c) + local spr = Sprite(4, 4, colorMode) + local img = app.activeImage + + array_to_pixels({ a, a, a, a, + a, b, b, a, + a, a, b, a, + a, a, a, b, }, img) + + app.useTool{ points={Point(0, 0)}, color=b } + expect_img(img, { b, b, b, b, + b, b, b, b, + b, b, b, b, + b, b, b, b, }) + + app.undo() + -- FOUR_CONNECTED=0 + app.preferences.tool('paint_bucket').floodfill.pixel_connectivity = 0 + assert(app.preferences.tool('paint_bucket').floodfill.pixel_connectivity == 0) + app.useTool{ points={Point(1, 1)}, color=c } + expect_img(img, { a, a, a, a, + a, c, c, a, + a, a, c, a, + a, a, a, b, }) + + app.undo() + -- EIGHT_CONNECTED=1 + app.preferences.tool('paint_bucket').floodfill.pixel_connectivity = 1 + assert(app.preferences.tool('paint_bucket').floodfill.pixel_connectivity == 1) + app.useTool{ points={Point(1, 1)}, color=c } + expect_img(img, { a, a, a, a, + a, c, c, a, + a, a, c, a, + a, a, a, c, }) +end + +local rgba = app.pixelColor.rgba +local gray = app.pixelColor.graya +test_paint_bucket(ColorMode.RGB, rgba(0, 0, 0), rgba(128, 128, 128), rgba(255, 255, 255)) +test_paint_bucket(ColorMode.GRAYSCALE, gray(0), gray(128), gray(255)) +test_paint_bucket(ColorMode.INDEXED, 1, 2, 3) From 691bc0ace1bc0bfc2ad897fa6b2e1125912acc37 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 9 Apr 2021 16:19:58 -0300 Subject: [PATCH 158/200] Test new Sprite.pixelRatio property --- scripts/sprite.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/sprite.lua b/scripts/sprite.lua index a08d6f801..27d07a126 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019 Igara Studio S.A. +-- Copyright (C) 2019-2021 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -120,10 +120,22 @@ do assert(s.gridBounds == Rectangle{0, 0, 16, 16}) s.gridBounds = Rectangle{2, 3, 8, 4} assert(s.gridBounds == Rectangle{2, 3, 8, 4}) - s:saveAs("_test_sprite_gridbounds.png") + s:saveAs("_test_sprite_gridbounds.aseprite") - local s2 = Sprite{ fromFile="_test_sprite_gridbounds.png" } - assert(s.gridBounds == Rectangle{2, 3, 8, 4}) + local s2 = Sprite{ fromFile="_test_sprite_gridbounds.aseprite" } + assert(s2.gridBounds == Rectangle{2, 3, 8, 4}) +end + +-- Pixel ratio +do + local s = Sprite(32, 32) + assert(s.pixelRatio == Size{1, 1}) + s.pixelRatio = Size{3, 2} + assert(s.pixelRatio == Size{3, 2}) + s:saveAs("_test_sprite_pixelratio.aseprite") + + local s2 = Sprite{ fromFile="_test_sprite_pixelratio.aseprite" } + assert(s2.pixelRatio == Size{3, 2}) end -- Sprite{ fromFile, oneFrame } From 3d07526618d48d0ccd487b01d9eea3837809160d Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 9 Apr 2021 17:14:58 -0300 Subject: [PATCH 159/200] Now app.command.ImportSpriteSheet() can be used from CLI --- scripts/import_sprite_sheet_command.lua | 75 +++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 scripts/import_sprite_sheet_command.lua diff --git a/scripts/import_sprite_sheet_command.lua b/scripts/import_sprite_sheet_command.lua new file mode 100644 index 000000000..741d3d5fe --- /dev/null +++ b/scripts/import_sprite_sheet_command.lua @@ -0,0 +1,75 @@ +-- Copyright (C) 2021 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +dofile('./test_utils.lua') + +do + local s = Sprite(8, 4, ColorMode.INDEXED) + assert(#s.cels == 1) + + local i = s.cels[1].image + array_to_pixels({ 0, 1, 2, 3, 3, 2, 1, 0, + 1, 2, 3, 4, 4, 3, 2, 1, + 1, 2, 3, 4, 4, 3, 2, 1, + 0, 1, 2, 3, 3, 2, 1, 0 }, i) + + app.command.ImportSpriteSheet{ + ui=false, + type=SpriteSheetType.ROWS, + frameBounds=Rectangle(0, 0, 4, 4) + } + assert(#s.cels == 2) + expect_img(s.cels[1].image, + { 0, 1, 2, 3, + 1, 2, 3, 4, + 1, 2, 3, 4, + 0, 1, 2, 3 }) + expect_img(s.cels[2].image, + { 3, 2, 1, 0, + 4, 3, 2, 1, + 4, 3, 2, 1, + 3, 2, 1, 0 }) + + app.undo(); + app.command.ImportSpriteSheet{ + ui=false, + type=SpriteSheetType.ROWS, + frameBounds=Rectangle(0, 0, 2, 3) + } + assert(#s.cels == 4) + expect_img(s.cels[1].image, + { 0, 1, + 1, 2, + 1, 2 }) + expect_img(s.cels[2].image, + { 2, 3, + 3, 4, + 3, 4 }) + expect_img(s.cels[3].image, + { 3, 2, + 4, 3, + 4, 3 }) + expect_img(s.cels[4].image, + { 1, 0, + 2, 1, + 2, 1 }) + + + app.undo(); + app.command.ImportSpriteSheet{ + ui=false, + type=SpriteSheetType.ROWS, + frameBounds=Rectangle(1, 1, 2, 2), + padding=Size(2, 0) + } + assert(#s.cels == 2) + expect_img(s.cels[1].image, + { 2, 3, + 2, 3 }) + expect_img(s.cels[2].image, + { 3, 2, + 3, 2 }) + +end From f588477f4f5bea9697fca811ac3bf69d854208ef Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 19 Apr 2021 16:52:51 -0300 Subject: [PATCH 160/200] Add test case to avoid duplicated tiles when A=0 and RGB is different --- scripts/tilemap.lua | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua index 71b08b243..d450ccfaf 100644 --- a/scripts/tilemap.lua +++ b/scripts/tilemap.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019-2020 Igara Studio S.A. +-- Copyright (C) 2019-2021 Igara Studio S.A. -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. @@ -522,3 +522,39 @@ do app.undo() end + +---------------------------------------------------------------------- +-- Tests bug with alpha=0 and different RGB values +---------------------------------------------------------------------- + +do + local spr = Sprite(32, 32) + spr.gridBounds = Rectangle(0, 0, 2, 2) + app.command.NewLayer{ tilemap=true } + + local tm = app.activeLayer + local ts = tm.tileset + expect_eq(1, #ts) + + app.useTool{ + tool='pencil', + color=Color{ r=0, g=0, b=0, a=255 }, + tilemapMode=TilesetMode.PIXELS, + tilesetMode=TilesetMode.STACK, + points={ Point(0, 0), Point(3, 0) }} + + expect_eq(2, #ts) + + app.useTool{ + tool='pencil', + color=Color{ r=255, g=0, b=0, a=0 }, + tilemapMode=TilesetMode.PIXELS, + tilesetMode=TilesetMode.STACK, + points={ Point(0, 0), Point(1, 0) }} + + -- If #ts is == 3, it means that the last useTool() with a r=255 a=0 + -- created a new tile, that shouldn't be the case (because a=0 + -- should ignore RGB values to compare tiles) + expect_eq(2, #ts) + +end From 8b104313fa7e1bec8488f2e63c06023ce6de1909 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 22 Apr 2021 12:59:04 -0300 Subject: [PATCH 161/200] Test magic wand in a fully opaque transparent layer --- scripts/selection_tools.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 scripts/selection_tools.lua diff --git a/scripts/selection_tools.lua b/scripts/selection_tools.lua new file mode 100644 index 000000000..24fa8791b --- /dev/null +++ b/scripts/selection_tools.lua @@ -0,0 +1,28 @@ +-- Copyright (C) 2021 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +dofile('./test_utils.lua') + +---------------------------------------------------------------------- +-- Test magic wand in transparent layer +-- Note: A regression in the beta was found in this case. + +do + local s = Sprite(4, 4, ColorMode.INDEXED) + app.command.LayerFromBackground() + + local i = s.cels[1].image + i:clear(0) + i:putPixel(0, 0, 1) + expect_eq(4, i.width) + expect_eq(4, i.height) + + app.useTool{ tool='magic_wand', points={Point(0, 0)} } + expect_eq(Rectangle(0, 0, 1, 1), s.selection.bounds) + + app.useTool{ tool='magic_wand', points={Point(1, 0)} } + expect_eq(Rectangle(0, 0, 4, 4), s.selection.bounds) + assert(not s.selection:contains(0, 0)) +end From dba0ddac853e8067cf5df32f05a91d146978c07e Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 28 Apr 2021 17:21:31 -0300 Subject: [PATCH 162/200] Add test to avoid removing used tiles in Auto mode --- scripts/tilemap.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua index d450ccfaf..94489a6b9 100644 --- a/scripts/tilemap.lua +++ b/scripts/tilemap.lua @@ -558,3 +558,23 @@ do expect_eq(2, #ts) end + +---------------------------------------------------------------------- +-- Tests tiles dissapearing in AUTO mode +---------------------------------------------------------------------- + +do + local spr = Sprite(32, 16, ColorMode.INDEXED) + spr.gridBounds = Rectangle(0, 0, 2, 2) + app.command.ConvertLayer{ to="tilemap" } + app.useTool{ points={ Point(0, 0), Point(31, 31) }, color=1, tool="filled_ellipse", tilesetMode=TilesetMode.AUTO } + app.useTool{ points={ Point(4, 4), Point(27, 27) }, color=2, tool="filled_ellipse", tilesetMode=TilesetMode.AUTO } + app.useTool{ points={ Point(0, 0), Point(32, 16) }, color=3, tool="line", tilesetMode=TilesetMode.AUTO } + app.useTool{ points={ Point(0, 0), Point(31, 8), + Point(0, 8), Point(31, 16) }, + brush=4, color=3, tool="pencil", tilesetMode=TilesetMode.AUTO } + + local i = spr.cels[1].image + assert(i:getPixel(4, 6) ~= 0) + assert(i:getPixel(8, 7) ~= 0) +end From 66e09857ac22edd092ebe35c839a0a6f047b5dad Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 9 May 2021 17:22:07 -0300 Subject: [PATCH 163/200] Add some tests for ColorQuantization and ChangePixelFormat --- scripts/color_quantization.lua | 136 +++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 scripts/color_quantization.lua diff --git a/scripts/color_quantization.lua b/scripts/color_quantization.lua new file mode 100644 index 000000000..c905f7f2c --- /dev/null +++ b/scripts/color_quantization.lua @@ -0,0 +1,136 @@ +-- Copyright (C) 2019-2021 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +dofile("./test_utils.lua") + +local rgba = app.pixelColor.rgba + +---------------------------------------------------------------------- +-- app.command.ColorQuantization + +do + -- One sprite with a background layer + local s = Sprite(2, 2) + app.command.BackgroundFromLayer() + + local i = s.cels[1].image + local p = s.palettes[1] + assert(#p == 256) + assert(s.colorMode == ColorMode.RGB) + app.command.ColorQuantization() + assert(#p == 1) + + array_to_pixels({ rgba(255, 255, 0), rgba(255, 255, 0), + rgba(255, 255, 0), rgba(255, 255, 0) }, i) + app.command.ColorQuantization() + assert(#p == 1) + assert(p:getColor(0) == Color(255, 255, 0)) + + array_to_pixels({ rgba(255, 0, 0), rgba(255, 0, 0), + rgba(255, 255, 0), rgba(255, 255, 0) }, i) + app.command.ColorQuantization() + assert(#p == 2) + assert(p:getColor(0) == Color(255, 0, 0)) + assert(p:getColor(1) == Color(255, 255, 0)) + + array_to_pixels({ rgba(255, 0, 0), rgba(255, 0, 0), + rgba(255, 255, 0), rgba(0, 0, 255) }, i) + app.command.ColorQuantization() + assert(#p == 3) + assert(p:getColor(0) == Color(255, 0, 0)) + assert(p:getColor(1) == Color(255, 255, 0)) + assert(p:getColor(2) == Color(0, 0, 255)) + + -- Convert the background layer to a transparent layer + + app.command.LayerFromBackground() + app.command.ColorQuantization{ withAlpha=false } + assert(#p == 4) -- One extra color for transparent layer + assert(p:getColor(0) == Color(0, 0, 0)) + assert(p:getColor(1) == Color(255, 0, 0)) + assert(p:getColor(2) == Color(255, 255, 0)) + assert(p:getColor(3) == Color(0, 0, 255)) + + app.command.ColorQuantization() + assert(#p == 4) + assert(p:getColor(0) == Color(0, 0, 0, 0)) + assert(p:getColor(1) == Color(255, 0, 0)) + assert(p:getColor(2) == Color(255, 255, 0)) + assert(p:getColor(3) == Color(0, 0, 255)) + + array_to_pixels({ rgba(0, 0, 0), rgba(255, 0, 0), + rgba(255, 0, 0), rgba(0, 0, 255) }, i) + app.command.ColorQuantization{ withAlpha=false } + assert(#p == 4) + assert(p:getColor(0) == Color(0, 0, 0)) + assert(p:getColor(1) == Color(0, 0, 0)) + assert(p:getColor(2) == Color(255, 0, 0)) + assert(p:getColor(3) == Color(0, 0, 255)) + + app.command.ColorQuantization() + assert(#p == 4) + assert(p:getColor(0) == Color(0, 0, 0, 0)) + assert(p:getColor(1) == Color(0, 0, 0)) + assert(p:getColor(2) == Color(255, 0, 0)) + assert(p:getColor(3) == Color(0, 0, 255)) +end + +do + -- One sprite with a transparent layer + a background layer + local s = Sprite(2, 2) + local p = s.palettes[1] + app.command.BackgroundFromLayer() + local bg = s.cels[1].image + local fg = s:newCel(s:newLayer(), 1).image + + assert(#s.frames == 1) + assert(#s.layers == 2) + assert(#s.cels == 2) + + array_to_pixels({ rgba(0, 0, 0, 0), rgba(0, 255, 0), + rgba(255, 0, 0), rgba(0, 0, 0, 0) }, fg) + array_to_pixels({ rgba(0, 0, 0), rgba(0, 0, 0), + rgba(0, 0, 0), rgba(0, 0, 255) }, bg) + + app.command.ColorQuantization() + assert(#p == 5) + assert(p:getColor(0) == Color(0, 0, 0, 0)) + assert(p:getColor(1) == Color(0, 0, 0)) + assert(p:getColor(2) == Color(0, 255, 0)) + assert(p:getColor(3) == Color(255, 0, 0)) + assert(p:getColor(4) == Color(0, 0, 255)) +end + +---------------------------------------------------------------------- +-- app.command.ChangePixelFormat + +do + local s = Sprite(2, 2, ColorMode.RGB) + local p = Palette(4) + p:setColor(0, Color(0, 0, 0)) + p:setColor(1, Color(101, 90, 200)) + p:setColor(2, Color(102, 91, 201)) + p:setColor(3, Color(103, 92, 203)) + s:setPalette(p) + + app.command.BackgroundFromLayer() + + local bg = s.cels[1].image + array_to_pixels({ rgba(0, 0, 0), rgba(101, 90, 200), + rgba(102, 91, 201), rgba(103, 92, 203) }, bg) + + app.command.ChangePixelFormat{ format="indexed", rgbmap="rgb5a3" } + local bg = s.cels[1].image + -- Using the 5-bit precision of RGB5A3 will match everything with + -- the first palette entry. + expect_img(bg, { 0, 1, + 1, 1 }) + app.undo() + + app.command.ChangePixelFormat{ format="indexed", rgbmap="octree" } + local bg = s.cels[1].image + expect_img(bg, { 0, 1, + 2, 3 }) +end From 1dce35245c36eb80bf89d069a45c018f93de175c Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 1 Jun 2021 08:55:01 -0300 Subject: [PATCH 164/200] New changes to ColorQuantization() to select the correct algorithm --- scripts/color_quantization.lua | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/scripts/color_quantization.lua b/scripts/color_quantization.lua index c905f7f2c..649eab6d4 100644 --- a/scripts/color_quantization.lua +++ b/scripts/color_quantization.lua @@ -19,25 +19,25 @@ do local p = s.palettes[1] assert(#p == 256) assert(s.colorMode == ColorMode.RGB) - app.command.ColorQuantization() + app.command.ColorQuantization{ algorithm="rgb5a3" } assert(#p == 1) array_to_pixels({ rgba(255, 255, 0), rgba(255, 255, 0), rgba(255, 255, 0), rgba(255, 255, 0) }, i) - app.command.ColorQuantization() + app.command.ColorQuantization{ algorithm="rgb5a3" } assert(#p == 1) assert(p:getColor(0) == Color(255, 255, 0)) array_to_pixels({ rgba(255, 0, 0), rgba(255, 0, 0), rgba(255, 255, 0), rgba(255, 255, 0) }, i) - app.command.ColorQuantization() + app.command.ColorQuantization{ algorithm="rgb5a3" } assert(#p == 2) assert(p:getColor(0) == Color(255, 0, 0)) assert(p:getColor(1) == Color(255, 255, 0)) array_to_pixels({ rgba(255, 0, 0), rgba(255, 0, 0), rgba(255, 255, 0), rgba(0, 0, 255) }, i) - app.command.ColorQuantization() + app.command.ColorQuantization{ algorithm="rgb5a3" } assert(#p == 3) assert(p:getColor(0) == Color(255, 0, 0)) assert(p:getColor(1) == Color(255, 255, 0)) @@ -46,7 +46,7 @@ do -- Convert the background layer to a transparent layer app.command.LayerFromBackground() - app.command.ColorQuantization{ withAlpha=false } + app.command.ColorQuantization{ algorithm="rgb5a3", withAlpha=false } assert(#p == 4) -- One extra color for transparent layer assert(p:getColor(0) == Color(0, 0, 0)) assert(p:getColor(1) == Color(255, 0, 0)) @@ -62,14 +62,14 @@ do array_to_pixels({ rgba(0, 0, 0), rgba(255, 0, 0), rgba(255, 0, 0), rgba(0, 0, 255) }, i) - app.command.ColorQuantization{ withAlpha=false } + app.command.ColorQuantization{ algorithm="rgb5a3", withAlpha=false } assert(#p == 4) assert(p:getColor(0) == Color(0, 0, 0)) assert(p:getColor(1) == Color(0, 0, 0)) assert(p:getColor(2) == Color(255, 0, 0)) assert(p:getColor(3) == Color(0, 0, 255)) - app.command.ColorQuantization() + app.command.ColorQuantization{ algorithm="rgb5a3" } assert(#p == 4) assert(p:getColor(0) == Color(0, 0, 0, 0)) assert(p:getColor(1) == Color(0, 0, 0)) @@ -94,7 +94,7 @@ do array_to_pixels({ rgba(0, 0, 0), rgba(0, 0, 0), rgba(0, 0, 0), rgba(0, 0, 255) }, bg) - app.command.ColorQuantization() + app.command.ColorQuantization{ algorithm="rgb5a3" } assert(#p == 5) assert(p:getColor(0) == Color(0, 0, 0, 0)) assert(p:getColor(1) == Color(0, 0, 0)) @@ -122,15 +122,26 @@ do rgba(102, 91, 201), rgba(103, 92, 203) }, bg) app.command.ChangePixelFormat{ format="indexed", rgbmap="rgb5a3" } - local bg = s.cels[1].image -- Using the 5-bit precision of RGB5A3 will match everything with -- the first palette entry. + bg = s.cels[1].image expect_img(bg, { 0, 1, 1, 1 }) app.undo() app.command.ChangePixelFormat{ format="indexed", rgbmap="octree" } - local bg = s.cels[1].image + bg = s.cels[1].image expect_img(bg, { 0, 1, 2, 3 }) + app.undo() + + p:setColor(0, Color(0, 0, 0, 0)) + bg = s.cels[1].image + array_to_pixels({ rgba(101, 90, 200, 0), rgba(101, 90, 200), + rgba(102, 91, 201), rgba(103, 92, 203, 0) }, bg) + app.command.ChangePixelFormat{ format="indexed", rgbmap="octree" } + bg = s.cels[1].image + expect_img(bg, { 0, 1, + 2, 0 }) + end From d73ba86f73c9f794057393a0cafdc020d6a4a16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Capello?= Date: Thu, 20 May 2021 16:37:33 -0300 Subject: [PATCH 165/200] Add pixel perfect tests --- scripts/pixel_perfect.lua | 361 ++++++++++++++++++++++++++++++++++++++ scripts/test_utils.lua | 10 ++ 2 files changed, 371 insertions(+) create mode 100644 scripts/pixel_perfect.lua diff --git a/scripts/pixel_perfect.lua b/scripts/pixel_perfect.lua new file mode 100644 index 000000000..391dd8644 --- /dev/null +++ b/scripts/pixel_perfect.lua @@ -0,0 +1,361 @@ +-- Copyright (C) 2019-2021 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +dofile('./test_utils.lua') + +local spr = Sprite(6, 6) +local cel = spr.cels[1] + +-- Point size 1px, solid color, no symmetry, no tiled mode +do + local title = '1px, solid, no symmetry, no tiled' + local red = Color{ r=255, g=0, b=0 } + local r = red.rgbaPixel + local pixel=Brush{ size=1, type=BrushType.CIRCLE } + local testData = { + { + id='1 - ' .. title .. ': right then down', + points={ Point(2, 2), Point(3, 2), Point(3, 3) }, + expected={ r, 0, + 0, r } + }, + { + id='2 - ' .. title .. ': down then right', + points={ Point(2, 2), Point(2, 3), Point(3, 3) }, + expected={ r, 0, + 0, r } + }, + { + id='3 - ' .. title .. ': left then up', + points={ Point(2, 2), Point(1, 2), Point(1, 1) }, + expected={ r, 0, + 0, r } + }, + { + id='4 - ' .. title .. ': up then left', + points={ Point(2, 2), Point(2, 1), Point(1, 1) }, + expected={ r, 0, + 0, r } + } + } + + for i,v in ipairs(testData) do + app.useTool{ + tool='pencil', + freehandAlgorithm=1, + brush=pixel, + color=red, + points=v.points} + expect_img_msg(cel.image, v.expected, '\nTest \'' .. v.id .. '\' failed') + cel.image:clear(0) + end +end + +-- Point size 2px, translucent color, no symmetry, no tiled mode +do + local title = '2px, translucent, no symmetry, no tiled' + local red = Color{ r=255, g=0, b=0, a=127 } + local r = red.rgbaPixel + local square=Brush{ size=2, type=BrushType.SQUARE } + local testData = { + { + id='1 - ' .. title .. ': right then down', + points={ Point(2, 2), Point(3, 2), Point(3, 3) }, + expected={ r, r, 0, + r, r, r, + 0, r, r } + }, + { + id='2 - ' .. title .. ': down then right', + points={ Point(2, 2), Point(2, 3), Point(3, 3) }, + expected={ r, r, 0, + r, r, r, + 0, r, r } + }, + { + id='3 - ' .. title .. ': left then up', + points={ Point(2, 2), Point(1, 2), Point(1, 1) }, + expected={ r, r, 0, + r, r, r, + 0, r, r } + }, + { + id='4 - ' .. title .. ': up then left', + points={ Point(2, 2), Point(2, 1), Point(1, 1) }, + expected={ r, r, 0, + r, r, r, + 0, r, r } + } + } + + for i,v in ipairs(testData) do + app.useTool{ + tool='pencil', + freehandAlgorithm=1, + brush=square, + color=red, + points=v.points} + expect_img_msg(cel.image, v.expected, '\nTest \'' .. v.id .. '\' failed') + cel.image:clear(0) + end +end + +-- Point size 2px, translucent color, symmetry, no tiled mode +do + local pref = app.preferences + local docPref = pref.document(spr) + pref.symmetry_mode.enabled = true + docPref.symmetry.mode = 3 + docPref.symmetry.x_axis = 3 + docPref.symmetry.y_axis = 3 + + local title = '2px, translucent, symmetry on, no tiled' + local red = Color{ r=255, g=0, b=0, a=127 } + local r = red.rgbaPixel + local square=Brush{ size=2, type=BrushType.SQUARE } + local testData = { + { + id='1 - ' .. title .. ': right then down', + points={ Point(1, 1), Point(2, 1), Point(2, 2) }, + expected={ r, r, 0, 0, r, r, + r, r, r, r, r, r, + 0, r, r, r, r, 0, + 0, r, r, r, r, 0, + r, r, r, r, r, r, + r, r, 0, 0, r, r } + }, + { + id='2 - ' .. title .. ': down then right', + points={ Point(1, 1), Point(1, 2), Point(2, 2) }, + expected={ r, r, 0, 0, r, r, + r, r, r, r, r, r, + 0, r, r, r, r, 0, + 0, r, r, r, r, 0, + r, r, r, r, r, r, + r, r, 0, 0, r, r } + }, + { + id='3 - ' .. title .. ': left then up', + points={ Point(2, 2), Point(1, 2), Point(1, 1) }, + expected={ r, r, 0, 0, r, r, + r, r, r, r, r, r, + 0, r, r, r, r, 0, + 0, r, r, r, r, 0, + r, r, r, r, r, r, + r, r, 0, 0, r, r } + }, + { + id='4 - ' .. title .. ': up then left', + points={ Point(2, 2), Point(2, 1), Point(1, 1) }, + expected={ r, r, 0, 0, r, r, + r, r, r, r, r, r, + 0, r, r, r, r, 0, + 0, r, r, r, r, 0, + r, r, r, r, r, r, + r, r, 0, 0, r, r } + } + } + + for i,v in ipairs(testData) do + app.useTool{ + tool='pencil', + freehandAlgorithm=1, + brush=square, + color=red, + points=v.points} + expect_img_msg(cel.image, v.expected, '\nTest \'' .. v.id .. '\' failed') + cel.image:clear(0) + end +end + +-- Point size 2px, translucent color, no symmetry, tiled mode on +do + local pref = app.preferences + local docPref = pref.document(spr) + pref.symmetry_mode.enabled = false + docPref.tiled.mode = 3 + + local title = '2px, translucent, no symmetry, tiled' + local red = Color{ r=255, g=0, b=0, a=127 } + local r = red.rgbaPixel + local square=Brush{ size=2, type=BrushType.SQUARE } + local testData = { + -- Top left corner + { + id='1 - ' .. title .. ': on top left corner, right then down', + points={ Point(0, 0), Point(1, 0), Point(1, 1) }, + expected={ r, r, 0, 0, 0, r, + r, r, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + r, 0, 0, 0, 0, r } + }, + { + id='2 - ' .. title .. ': on top left corner, down then right', + points={ Point(0, 0), Point(0, 1), Point(1, 1) }, + expected={ r, r, 0, 0, 0, r, + r, r, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + r, 0, 0, 0, 0, r } + }, + { + id='3 - ' .. title .. ': on top left corner, left then up', + points={ Point(0, 0), Point(-1, 0), Point(-1, -1) }, + expected={ r, 0, 0, 0, 0, r, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, r, r, + r, 0, 0, 0, r, r } + }, + { + id='4 - ' .. title .. ': on top left corner, up then left', + points={ Point(0, 0), Point(0, -1), Point(-1, -1) }, + expected={ r, 0, 0, 0, 0, r, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, r, r, + r, 0, 0, 0, r, r } + }, + -- Top right corner + { + id='5 - ' .. title .. ': on top right corner, right then down', + points={ Point(6, 0), Point(7, 0), Point(7, 1) }, + expected={ r, r, 0, 0, 0, r, + r, r, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + r, 0, 0, 0, 0, r } + }, + { + id='6 - ' .. title .. ': on top right corner, down then right', + points={ Point(6, 0), Point(6, 1), Point(7, 1) }, + expected={ r, r, 0, 0, 0, r, + r, r, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + r, 0, 0, 0, 0, r } + }, + { + id='7 - ' .. title .. ': on top right corner, left then up', + points={ Point(6, 0), Point(5, 0), Point(5, -1) }, + expected={ r, 0, 0, 0, 0, r, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, r, r, + r, 0, 0, 0, r, r } + }, + { + id='8 - ' .. title .. ': on top right corner, up then left', + points={ Point(6, 0), Point(5, 0), Point(5, -1) }, + expected={ r, 0, 0, 0, 0, r, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, r, r, + r, 0, 0, 0, r, r } + }, + -- Bottom left corner + { + id='9 - ' .. title .. ': on bottom left corner, right then down', + points={ Point(0, 6), Point(1, 6), Point(1, 7) }, + expected={ r, r, 0, 0, 0, r, + r, r, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + r, 0, 0, 0, 0, r } + }, + { + id='10 - ' .. title .. ': on bottom left corner, down then right', + points={ Point(0, 6), Point(0, 7), Point(1, 7) }, + expected={ r, r, 0, 0, 0, r, + r, r, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + r, 0, 0, 0, 0, r } + }, + { + id='11 - ' .. title .. ': on bottom left corner, left then up', + points={ Point(0, 6), Point(-1, 6), Point(-1, 5) }, + expected={ r, 0, 0, 0, 0, r, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, r, r, + r, 0, 0, 0, r, r } + }, + { + id='12 - ' .. title .. ': on bottom left corner, up then left', + points={ Point(0, 6), Point(0, 5), Point(-1, 5) }, + expected={ r, 0, 0, 0, 0, r, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, r, r, + r, 0, 0, 0, r, r } + }, + -- Botomm right corner + { + id='13 - ' .. title .. ': on bottom right corner, right then down', + points={ Point(6, 6), Point(7, 6), Point(7, 7) }, + expected={ r, r, 0, 0, 0, r, + r, r, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + r, 0, 0, 0, 0, r } + }, + { + id='14 - ' .. title .. ': on bottom right corner, down then right', + points={ Point(6, 6), Point(6, 7), Point(7, 7) }, + expected={ r, r, 0, 0, 0, r, + r, r, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + r, 0, 0, 0, 0, r } + }, + { + id='15 - ' .. title .. ': on bottom right corner, left then up', + points={ Point(6, 6), Point(5, 6), Point(5, 5) }, + expected={ r, 0, 0, 0, 0, r, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, r, r, + r, 0, 0, 0, r, r } + }, + { + id='16 - ' .. title .. ': on bottom right corner, up then left', + points={ Point(6, 6), Point(6, 5), Point(5, 5) }, + expected={ r, 0, 0, 0, 0, r, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, r, r, + r, 0, 0, 0, r, r } + }, + } + + for i,v in ipairs(testData) do + app.useTool{ + tool='pencil', + freehandAlgorithm=1, + brush=square, + color=red, + points=v.points} + expect_img_msg(cel.image, v.expected, '\nTest \'' .. v.id .. '\' failed') + cel.image:clear(0) + end +end diff --git a/scripts/test_utils.lua b/scripts/test_utils.lua index 0f8029109..28e208fad 100644 --- a/scripts/test_utils.lua +++ b/scripts/test_utils.lua @@ -32,6 +32,8 @@ function expect_img(image, expectedPixels) local h = image.height if w*h ~= #expectedPixels then print(debug.traceback()) + print('Expected pixels: #=' .. #expectedPixels) + print('Image size: w=' .. w .. ' h=' .. h .. ' #=' .. w*h) dump_img(image) assert(w*h == #expectedPixels) end @@ -75,6 +77,14 @@ function expect_img(image, expectedPixels) end end +function expect_img_msg(image, expectedPixels, msg) + local status, err = pcall(expect_img, image, expectedPixels) + if not status then + print(msg) + error(err) + end +end + function array_to_pixels(array, image) local w = image.width local h = image.height From 691ea0b5f8e38a3b8622e0c89eeaa6c2b8163844 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 30 Aug 2021 10:51:24 -0300 Subject: [PATCH 166/200] Test undoing sprite.gridBounds changes Test for https://github.com/aseprite/aseprite/issues/2872 --- scripts/app_preferences.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/app_preferences.lua b/scripts/app_preferences.lua index 82cbe4286..5c11bc82d 100644 --- a/scripts/app_preferences.lua +++ b/scripts/app_preferences.lua @@ -102,6 +102,24 @@ do end end +do -- Test that undoing grid bounds, updates the grid in the preferences correctly + local doc = Sprite(32, 32) + assert(doc.gridBounds == Rectangle(0, 0, 64, 64)) + assert(app.preferences.document(doc).grid.bounds == Rectangle(0, 0, 64, 64)) + + doc.gridBounds = Rectangle(0, 0, 4, 4) + assert(doc.gridBounds == Rectangle(0, 0, 4, 4)) + assert(app.preferences.document(doc).grid.bounds == Rectangle(0, 0, 4, 4)) + + app.undo() + assert(doc.gridBounds == Rectangle(0, 0, 64, 64)) + assert(app.preferences.document(doc).grid.bounds == Rectangle(0, 0, 64, 64)) + + app.redo() + assert(doc.gridBounds == Rectangle(0, 0, 4, 4)) + assert(app.preferences.document(doc).grid.bounds == Rectangle(0, 0, 4, 4)) +end + do -- Test symmetry preferences do -- File with default preferences local doc = Sprite(200, 100) From 36ee80aaca585fc00baf63c58612e1d64f4df60b Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 2 Sep 2021 17:48:06 -0300 Subject: [PATCH 167/200] Test crash saving palette to .jpg file Test for the following patch: https://github.com/aseprite/aseprite/commit/341408e9024edd2651e61844a9457f1d3ccf92b6 --- scripts/palette.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/palette.lua b/scripts/palette.lua index 6a22abfc1..12d92408f 100644 --- a/scripts/palette.lua +++ b/scripts/palette.lua @@ -85,3 +85,15 @@ do spr:setPalette(db32) assert(sprPal == db32) end + +-- Test crash +do + local p = Palette{ fromResource="DB32" } + p:saveAs("_test_.jpg") + + local q = Palette{ fromFile="_test_.gpl" } + assert(#p == #q) + for i=0,#q-1 do + assert(p:getColor(i) == q:getColor(i)) + end +end From 997501e6be092316b5168bea8c1a3fbabcc97e11 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 2 Sep 2021 17:48:39 -0300 Subject: [PATCH 168/200] Remove print() which was used for debugging purposes --- scripts/sprite.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/sprite.lua b/scripts/sprite.lua index 27d07a126..b7d101249 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -146,7 +146,6 @@ do assert(#s.frames == 2) s = Sprite{ fromFile="_test1.png" } - print(#s.frames) assert(#s.frames == 2) s = Sprite{ fromFile="_test1.png", oneFrame=true } From 0ac10ee18d295d144480286426140339604519d2 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 2 Sep 2021 17:48:58 -0300 Subject: [PATCH 169/200] Add some tests for issues with indexes out of the valid range Related to: https://github.com/aseprite/aseprite/pull/2934 --- scripts/sprite.lua | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/scripts/sprite.lua b/scripts/sprite.lua index b7d101249..347509b82 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -154,3 +154,46 @@ do s = Sprite{ fromFile="_test1.png", oneFrame=false } assert(#s.frames == 2) end + +-- Issues with sprites having pixel with indexes out of palette bounds: +-- Saving png failed (https://github.com/aseprite/aseprite/issues/2842) +do + local s = Sprite(2, 2, ColorMode.INDEXED) + assert(#s.palettes == 1) + + s.transparentColor = 1 + s.palettes[1]:resize(8) + assert(#s.palettes[1] == 8) + s.cels[1].image:clear(2) + s.cels[1].image:putPixel(0, 0, 7) + s:saveAs("_test1_.png") -- OK + + s.palettes[1]:resize(4) + assert(#s.palettes[1] == 4) + local result = s:saveAs("_test2_palerr_.png") -- Used to fail + + -- If result=false we got a "libpng: Wrote palette index exceeding num_palette" + assert(result) + + local s2 = app.open("_test2_palerr_.png") + assert(s2 ~= nil) + print(s2.cels[1].image:getPixel(0, 0)) + assert(s2.cels[1].image:getPixel(0, 0) == 1) +end +-- Flatten visible layers uses indices outside the palette range as opaque colors instead of transparent color (https://github.com/aseprite/aseprite/issues/2912) +do + local s = Sprite(2, 2, ColorMode.INDEXED) + + s.transparentColor = 0 + s.palettes[1]:resize(4) + + s.cels[1].image:clear(1) + local l = s:newLayer() + s:newCel(l) + s.cels[2].image:putPixel(0, 0, 2) + s.cels[2].image:putPixel(1, 0, 7) + s:flatten() + + assert(s.cels[1].image:getPixel(0, 0) == 2) + assert(s.cels[1].image:getPixel(1, 0) == 1) -- Get the color of the first layer +end From 2c950360e8f55163b30b7f26af792265e7d25a97 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 2 Sep 2021 18:12:33 -0300 Subject: [PATCH 170/200] Revert "Test crash saving palette to .jpg file" This reverts commit 36ee80aaca585fc00baf63c58612e1d64f4df60b. Saving the .jpg palette will make the script fail anyway. --- scripts/palette.lua | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/scripts/palette.lua b/scripts/palette.lua index 12d92408f..6a22abfc1 100644 --- a/scripts/palette.lua +++ b/scripts/palette.lua @@ -85,15 +85,3 @@ do spr:setPalette(db32) assert(sprPal == db32) end - --- Test crash -do - local p = Palette{ fromResource="DB32" } - p:saveAs("_test_.jpg") - - local q = Palette{ fromFile="_test_.gpl" } - assert(#p == #q) - for i=0,#q-1 do - assert(p:getColor(i) == q:getColor(i)) - end -end From ae2be843f8fb7daee96da9cca57eac24d6f8dc25 Mon Sep 17 00:00:00 2001 From: Joshua Ogunyinka Date: Mon, 20 Sep 2021 17:10:02 +0400 Subject: [PATCH 171/200] Added tests for cropping canvas --- scripts/tilemap.lua | 156 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua index 94489a6b9..0e2477361 100644 --- a/scripts/tilemap.lua +++ b/scripts/tilemap.lua @@ -578,3 +578,159 @@ do assert(i:getPixel(4, 6) ~= 0) assert(i:getPixel(8, 7) ~= 0) end + +----------------------------------------------------------------------- +-- Test CanvasSize with tilemaps when we trim out content +----------------------------------------------------------------------- + +do + local sprite = Sprite(32, 32) + sprite.gridBounds = Rectangle(0, 0, 16, 16) + + -- Create a 2x2 tilemap with 4 tiles drawing an ellipse + app.command.NewLayer{ tilemap=true } + app.useTool{ + tool='filled_ellipse', + color=Color{ r=255, g=255, b=0 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(0, 0), Point(31, 31) } + } + assert(#sprite.layers == 2) + -- remove the unused layer image + sprite:deleteLayer("Layer 1") + assert(#sprite.layers == 1) + + local celMap = app.activeLayer.cels[1] + assert(celMap.bounds == Rectangle(0, 0, 32, 32)) + + -- resize the canvas to 16x16 starting point(4,9) + -- covering a large part of the tile in 0,0 + app.command.CanvasSize{ + bounds=Rectangle(4,9,16,16), + trimOutside=true + } + + assert(#app.activeLayer.cels == 1) + + expect_eq(celMap.bounds.width, 32) + expect_eq(celMap.bounds.height, 32) + expect_eq(sprite.bounds.width, 16) + expect_eq(sprite.bounds.height, 16) + + -- the expected visible part of the image is the part + -- specified in the bounds + expect_eq(celMap.bounds.x, -4) + expect_eq(celMap.bounds.y, -9) + + -- grid is 16x16, so expected image width/height is 2 + expect_eq(celMap.image.width, 2) + expect_eq(celMap.image.height, 2) + expect_eq(celMap.image:getPixel(0,0), 1) + expect_eq(celMap.image:getPixel(1,0), 2) + expect_eq(celMap.image:getPixel(0,1), 3) + expect_eq(celMap.image:getPixel(1,1), 4) + + -- undo the last canvas resize + app.command.Undo() + + -- reposition the cel in the sprite + celMap.position = Point(0,16) + expect_eq(celMap.bounds, Rectangle(0, 16, 32, 32)) + + -- deleting the whole tilemap cel when it's outside the bounds + app.command.CanvasSize { + bounds=Rectangle(0,0,8,8), + trimOutside=true + } + + expect_eq(#app.activeLayer.cels, 0) + expect_eq(sprite.bounds.width, 8) + expect_eq(sprite.bounds.height, 8) + + -- undo canvas resize + app.command.Undo() + + -- undo set position + app.command.Undo() + expect_eq(celMap.bounds, Rectangle(0, 0, 32, 32)) + + app.command.CanvasSize{ + bounds=Rectangle(16,16,16,16), + trimOutside=true + } + + assert(celMap ~= nil) + expect_eq(celMap.bounds.x, 0) + expect_eq(celMap.bounds.y, 0) + expect_eq(celMap.image.width, 1) + expect_eq(celMap.image.height, 1) + expect_eq(celMap.position, Point(0,0)) + expect_eq(celMap.image:getPixel(0,0), 4) +end + +----------------------------------------------------------------------- +-- Test CanvasSize when the bounds of an image is shrunken +----------------------------------------------------------------------- + +do + local sprite = Sprite(32, 32) + sprite.gridBounds = Rectangle(0, 0, 8, 8) + + app.command.NewLayer{ tilemap=true } + local tilemapLayer = sprite.layers[2] + + -- tile 1 + app.useTool { + tool='pencil', color=Color{r=255, b=0, g=255}, + layer=tilemapLayer, + points={ Point(7,8), Point(0, 15) }, + tilesetMode=TilesetMode.AUTO + } + + local celMap = tilemapLayer.cels[1] + + -- tile 2 + app.useTool { + tool='pencil', color=Color{r=0, b=255, g=255}, + cel=celMap, + points={ Point(24,16), Point(31, 23) }, + tilesetMode=TilesetMode.AUTO + } + + -- tile 3 + app.useTool { + tool='pencil', color=Color{r=0, b=0, g=255}, + cel=celMap, + points={ Point(30,24), Point(24, 31) }, + tilesetMode=TilesetMode.AUTO + } + + -- tile 4 + app.useTool { + tool='pencil', color=Color{r=0, b=255, g=0}, + cel=celMap, + points={ Point(17,24), Point(23, 31) }, + tilesetMode=TilesetMode.AUTO + } + + -- crop this sprite a little below pixel(0,0) + app.command.CanvasSize { + bounds=Rectangle(8,16,20,16), + trimOutside=true, ui=false + } + + expect_eq(sprite.bounds.width, 20) + expect_eq(sprite.bounds.height, 16) + + -- ideally, we expect a 3x2 image, however, some parts of top and left + -- of the image are empty/notile, so it's optimized by shrunking it + -- we got paddings instead. + + expect_eq(celMap.image.width, 2) + expect_eq(celMap.image.height, 2) + expect_eq(celMap.image:getPixel(0, 0), 0) + expect_eq(celMap.image:getPixel(1, 0), 2) + expect_eq(celMap.image:getPixel(1, 1), 3) + expect_eq(celMap.image:getPixel(0, 1), 4) + +end From 88f53dd96760f8e8cfaa7e6e616e61ff20db9510 Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Mon, 27 Sep 2021 10:26:09 -0300 Subject: [PATCH 172/200] Added tilemap tests for canvas cropping --- scripts/tilemap.lua | 356 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 355 insertions(+), 1 deletion(-) diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua index 0e2477361..42b7fdfb6 100644 --- a/scripts/tilemap.lua +++ b/scripts/tilemap.lua @@ -732,5 +732,359 @@ do expect_eq(celMap.image:getPixel(1, 0), 2) expect_eq(celMap.image:getPixel(1, 1), 3) expect_eq(celMap.image:getPixel(0, 1), 4) - +end + +---------------------------------------------------------------------- +-- Tests canvas resizing in the tilemap with tiles 1x1 +---------------------------------------------------------------------- + +do + local sprite1 = Sprite(4, 4) + -- Create a tilemap layer which grid size is 1x1 + sprite1.gridBounds = Rectangle(1, 1, 1, 1) + app.command.NewLayer{ tilemap=true } + -- Create a tilemap of 2x2 tiles: + -- ______ + -- | ∏∏ | + -- | ∏∏ | + -- | | + -- |______| + app.useTool{ + tool='pencil', + color=Color{ r=255, g=0, b=0 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(1, 0) } + } + app.useTool{ + tool='pencil', + color=Color{ r=0, g=255, b=0 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(2, 0) } + } + app.useTool{ + tool='pencil', + color=Color{ r=0, g=0, b=255 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(1, 1) } + } + app.useTool{ + tool='pencil', + color=Color{ r=255, g=255, b=255 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(2, 1) } + } + + app.command.CanvasSize{ + ui=false, + bounds=Rectangle(0,0,2,2), + trimOutside=true + } + + expect_eq(app.activeLayer.cels[1].image.width, 1) + expect_eq(app.activeLayer.cels[1].image.height, 2) + + app.command.CanvasSize{ + ui=false, + bounds=Rectangle(0,0,2,1), + trimOutside=true + } + + expect_eq(app.activeLayer.cels[1].image.width, 1) + expect_eq(app.activeLayer.cels[1].image.height, 1) +end + +---------------------------------------------------------------------- +-- Tests canvas resizing in the tilemap with tiles 2x2, origin 2,1 +---------------------------------------------------------------------- + +do + local sprite2 = Sprite(8, 8) + -- Create a tilemap layer which grid size is 2x2 + sprite2.gridBounds = Rectangle(0, 0, 2, 2) + app.command.NewLayer{ tilemap=true } + -- Create a tilemap of 4x4 tiles: + -- + -- ,--------- x = 2 + -- | + -- ____v______ + -- | | + -- | ∏∏XX |<-- y = 1 + -- | ∏∏XX | + -- | OO∏∏ | + -- | OO∏∏ | + -- | | + -- | | + -- |___________| + + -- Making a pixel to make a Cel + app.useTool{ + tool='pencil', + color=Color{ r=255, g=0, b=0 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(0, 0) } + } + + -- Moving the Cel to de desired position + app.activeLayer.cels[1].position = Point(2, 1) + + -- Filling with squares of 2x2 + app.useTool{ + tool='pencil', + color=Color{ r=255, g=0, b=0 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(3, 1), Point(3, 2), Point(2, 2) } + } + + app.useTool{ + tool='pencil', + color=Color{ r=0, g=255, b=0 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(4, 1), Point(5, 1), Point(5, 2), Point(4, 2) } + } + + app.useTool{ + tool='pencil', + color=Color{ r=0, g=0, b=255 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(2, 3), Point(3, 3), Point(3, 4), Point(2, 4) } + } + + app.useTool{ + tool='pencil', + color=Color{ r=255, g=255, b=255 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(4, 3), Point(5, 3), Point(5, 4), Point(4, 4) } + } + -- ====================================================================== + -- Cutting the canvas from the bottom + -- ,--------- x = 2 + -- | + -- ____v______ + -- | | + -- | ∏∏XX |<-- y = 1 + -- | ∏∏XX | + app.command.CanvasSize{ + ui=false, + bounds=Rectangle(0,0,8,3), + trimOutside=true + } + + expect_eq(app.activeLayer.cels[1].position, Point(2,1)) + expect_eq(app.activeLayer.cels[1].image.width, 2) -- width in tilemap terms + expect_eq(app.activeLayer.cels[1].image.height, 1) -- height in tilemap terms + -- ====================================================================== + -- Cutting the canvas from the right + -- ,--------- x = 2 + -- | + -- ____v_ + -- | | + -- | ∏∏|<-- y = 1 + -- | ∏∏| + app.command.CanvasSize{ + ui=false, + bounds=Rectangle(0,0,4,3), + trimOutside=true + } + + expect_eq(app.activeLayer.cels[1].position, Point(2,1)) + expect_eq(app.activeLayer.cels[1].image.width, 1) -- width in tilemap terms + expect_eq(app.activeLayer.cels[1].image.height, 1) -- height in tilemap terms + -- ====================================================================== + + app.command.Undo() + app.command.Undo() + + -- ====================================================================== + -- Cutting the canvas from the left, partial tile: + -- + -- ,--------- x = -1 + -- | + -- v ______ + -- | | | + -- | ∏|∏XX |<-- y = 1 + -- | ∏|∏XX | + -- | O|O∏∏ | + -- | O|O∏∏ | + -- | | | + -- | | | + -- | |______| + app.command.CanvasSize{ + ui=false, + bounds=Rectangle(3,0,5,8), + trimOutside=true + } + + expect_eq(app.activeLayer.cels[1].position, Point(-1, 1)) + expect_eq(app.activeLayer.cels[1].image.width, 2) -- width in tilemap terms + expect_eq(app.activeLayer.cels[1].image.height, 2) -- height in tilemap terms + -- ====================================================================== + + app.command.Undo() + + -- ====================================================================== + -- Cutting the canvas from the top, partial tile: + -- + -- ,--------- x = 2 + -- | + -- ____|______ + -- v + -- ____∏∏XX___ <-- y = -1 + -- | ∏∏XX | + -- | OO∏∏ | + -- | OO∏∏ | + -- | | + -- | | + -- |___________| + app.command.CanvasSize{ + ui=false, + bounds=Rectangle(0,2,8,6), + trimOutside=true + } + + expect_eq(app.activeLayer.cels[1].position, Point(2, -1)) + expect_eq(app.activeLayer.cels[1].image.width, 2) -- width in tilemap terms + expect_eq(app.activeLayer.cels[1].image.height, 2) -- height in tilemap terms + + -- ====================================================================== + + app.command.Undo() + + -- ====================================================================== + -- Cutting the canvas from the left, cutting first tile column: + -- + -- ,--------- x = 0 + -- | + -- v____ + -- | | | + -- | |XX |<-- y = 1 + -- | |XX | + -- | |∏∏ | + -- | |∏∏ | + -- | | | + -- | | | + -- | |_____| + app.command.CanvasSize{ + ui=false, + bounds=Rectangle(4,0,4,8), + trimOutside=true + } + + expect_eq(app.activeLayer.cels[1].position, Point(0, 1)) + expect_eq(app.activeLayer.cels[1].image.width, 1) -- width in tilemap terms + expect_eq(app.activeLayer.cels[1].image.height, 2) -- height in tilemap terms + -- ====================================================================== + + app.command.Undo() + + -- ====================================================================== + -- Cutting the canvas from the top, cutting the top tile row: + -- + -- ,--------- x = 2 + -- | + -- ____|______ + -- | + -- | + -- ____v______ + -- | OO∏∏ | <-- y = 0 + -- | OO∏∏ | + -- | | + -- | | + -- |___________| + app.command.CanvasSize{ + ui=false, + bounds=Rectangle(0,3,8,5), + trimOutside=true + } + + expect_eq(app.activeLayer.cels[1].position, Point(2, 0)) + expect_eq(app.activeLayer.cels[1].image.width, 2) -- width in tilemap terms + expect_eq(app.activeLayer.cels[1].image.height, 1) -- height in tilemap terms +end + +---------------------------------------------------------------------- +-- Tests canvas resizing in the tilemap with tiles 2x2 with shrink action +---------------------------------------------------------------------- + +do + local sprite3 = Sprite(8, 8) + -- Create a tilemap layer which grid size is 2x2 + sprite3.gridBounds = Rectangle(0, 0, 2, 2) + app.command.NewLayer{ tilemap=true } + -- Create a tilemap of 4x4 tiles: + -- + -- ,--------- x = 0 + -- | + -- v__________ + -- | | + -- |∏∏ |<-- y = 1 + -- |∏∏ | + -- |OO XX| + -- |OO XX| + -- | ∏∏| + -- | ∏∏| + -- |___________| + + -- Making a pixel to make a Cel + app.useTool{ + tool='pencil', + color=Color{ r=255, g=0, b=0 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(0, 0) } + } + + -- Moving the Cel to de desired position + app.activeLayer.cels[1].position = Point(0, 1) + + -- Filling with squares of 2x2 + app.useTool{ + tool='pencil', + color=Color{ r=255, g=0, b=0 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(1, 1), Point(1, 2), Point(0, 2) } + } + + app.useTool{ + tool='pencil', + color=Color{ r=0, g=255, b=0 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(0, 3), Point(1, 3), Point(1, 4), Point(0, 4) } + } + + app.useTool{ + tool='pencil', + color=Color{ r=0, g=0, b=255 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(6, 3), Point(7, 3), Point(6, 4), Point(7, 4) } + } + + app.useTool{ + tool='pencil', + color=Color{ r=255, g=255, b=255 }, + tilesetMode=TilesetMode.AUTO, + points={ Point(6, 5), Point(7, 5), Point(6, 6), Point(7, 6) } + } + + -- ====================================================================== + -- Cutting the canvas from the left, cutting the most left tile column: + -- + -- ,--------- x = 4 + -- | + -- ______v_ + -- | | | + -- | | | + -- | | | + -- | | XX| <-- y = 3 + -- | | XX| + -- | | ∏∏| + -- | | ∏∏| + -- | |________| + app.command.CanvasSize{ + ui=false, + bounds=Rectangle(2,0,6,8), + trimOutside=true + } + + expect_eq(app.activeLayer.cels[1].position, Point(4, 3)) + expect_eq(app.activeLayer.cels[1].image.width, 1) -- width in tilemap terms + expect_eq(app.activeLayer.cels[1].image.height, 2) -- height in tilemap terms end From 4dde10a8d1711c1107742aed5041b9c5506e45c1 Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Mon, 27 Sep 2021 13:24:56 -0300 Subject: [PATCH 173/200] Add new tilemap test --- scripts/tilemap.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua index 42b7fdfb6..f90db3efe 100644 --- a/scripts/tilemap.lua +++ b/scripts/tilemap.lua @@ -855,6 +855,36 @@ do tilesetMode=TilesetMode.AUTO, points={ Point(4, 3), Point(5, 3), Point(5, 4), Point(4, 4) } } + + -- ====================================================================== + -- Cutting the canvas in the midle of the tilemap: + -- + -- ,--------- x = -1 + -- | + -- ___v _______ + -- | | | | + -- ∏|∏X|X <-- y = -1 + -- |----|--|----| + -- ∏|∏X|X + -- O|O∏|∏ + -- |----|--|----| + -- O|O∏|∏ + -- | | + -- | | + -- |____|__|____| + app.command.CanvasSize{ + ui=false, + bounds=Rectangle(3,2,2,2), + trimOutside=true + } + + expect_eq(app.activeLayer.cels[1].position, Point(-1,-1)) + expect_eq(app.activeLayer.cels[1].image.width, 2) -- width in tilemap terms + expect_eq(app.activeLayer.cels[1].image.height, 2) -- height in tilemap terms + -- ====================================================================== + + app.command.Undo() + -- ====================================================================== -- Cutting the canvas from the bottom -- ,--------- x = 2 From 9d2531da915488f932731ae47eabb58e1e0e2ced Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 27 Sep 2021 17:00:26 -0300 Subject: [PATCH 174/200] Add some minor extra checks in some CanvasSize tests for tilemaps --- scripts/tilemap.lua | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/scripts/tilemap.lua b/scripts/tilemap.lua index f90db3efe..2eb38560d 100644 --- a/scripts/tilemap.lua +++ b/scripts/tilemap.lua @@ -612,16 +612,10 @@ do assert(#app.activeLayer.cels == 1) - expect_eq(celMap.bounds.width, 32) - expect_eq(celMap.bounds.height, 32) + expect_eq(celMap.bounds, Rectangle(-4, -9, 32, 32)) expect_eq(sprite.bounds.width, 16) expect_eq(sprite.bounds.height, 16) - -- the expected visible part of the image is the part - -- specified in the bounds - expect_eq(celMap.bounds.x, -4) - expect_eq(celMap.bounds.y, -9) - -- grid is 16x16, so expected image width/height is 2 expect_eq(celMap.image.width, 2) expect_eq(celMap.image.height, 2) @@ -726,6 +720,7 @@ do -- of the image are empty/notile, so it's optimized by shrunking it -- we got paddings instead. + expect_eq(celMap.position, Point(8, 0)) expect_eq(celMap.image.width, 2) expect_eq(celMap.image.height, 2) expect_eq(celMap.image:getPixel(0, 0), 0) @@ -780,8 +775,10 @@ do trimOutside=true } - expect_eq(app.activeLayer.cels[1].image.width, 1) - expect_eq(app.activeLayer.cels[1].image.height, 2) + local cel = app.activeLayer.cels[1] + expect_eq(cel.image.width, 1) + expect_eq(cel.image.height, 2) + expect_eq(cel.bounds, Rectangle(1, 0, 1, 2)) app.command.CanvasSize{ ui=false, @@ -789,8 +786,10 @@ do trimOutside=true } - expect_eq(app.activeLayer.cels[1].image.width, 1) - expect_eq(app.activeLayer.cels[1].image.height, 1) + cel = app.activeLayer.cels[1] + expect_eq(cel.image.width, 1) + expect_eq(cel.image.height, 1) + expect_eq(cel.bounds, Rectangle(1, 0, 1, 1)) end ---------------------------------------------------------------------- From b007185bdf2cfe5fb0a380d6ffd4b6fb9380f445 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 7 Oct 2021 19:39:13 -0300 Subject: [PATCH 175/200] New tests for App.events & Sprite.events --- scripts/events.lua | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 scripts/events.lua diff --git a/scripts/events.lua b/scripts/events.lua new file mode 100644 index 000000000..fcdcf3193 --- /dev/null +++ b/scripts/events.lua @@ -0,0 +1,89 @@ +-- Copyright (C) 2021 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +dofile('./test_utils.lua') + +if false then +-- Test app.events +do + local i = 0 + local listener = app.events:on('sitechange', + function() i = i + 1 end) + assert(i == 0) + local a = Sprite(32, 32) + expect_eq(a, app.activeSprite) + expect_eq(1, i) + local b = Sprite(32, 32) + expect_eq(b, app.activeSprite) + expect_eq(2, i) + app.activeSprite = a + expect_eq(3, i) + app.events:off(listener) + app.activeSprite = b + expect_eq(3, i) +end + +-- Test Sprite.events +do + local spr = Sprite(32, 64) + local changes = 0 + function incChanges() changes = changes + 1 end + spr.events:on('change', incChanges) + expect_eq(0, changes) + spr.width = 64 + expect_eq(1, changes) + app.undo() + expect_eq(2, changes) + app.redo() + expect_eq(3, changes) + spr.events:off(incChanges) + app.undo() + expect_eq(3, changes) +end + +end + +-- Multiple listeners +do + local spr = Sprite(2, 2) + local ai, bi = 0, 0 + function a() ai = ai + 1 end + function b() bi = bi + 1 end + + spr.events:on('change', a) + spr.events:on('change', b) + spr.width = 4 + expect_eq(1, ai) + expect_eq(1, bi) + + spr.events:off(a) + spr.width = 8 + expect_eq(1, ai) + expect_eq(2, bi) + + spr.events:off(b) + spr.width = 16 + expect_eq(1, ai) + expect_eq(2, bi) +end + +-- Avoid removing invalid listener when we use Events:off(function) +do + local spr = Sprite(2, 2) + + local i = 0 + function inc() i = i + 1 end + spr.events:on('change', inc) + + spr.width = 4 + expect_eq(1, i) + + app.events:off(inc) + spr.width = 8 + + -- If this fails is because app.events:off(inc) removed the sprite + -- listener instead of doing nothing. + expect_eq(2, i) +end From 452f07cde31a30239564f1a8a8cd5d510c6825ce Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 7 Oct 2021 19:39:27 -0300 Subject: [PATCH 176/200] Add tests for Image.rowStride --- scripts/image.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/image.lua b/scripts/image.lua index af67baaf0..b0d08df9c 100644 --- a/scripts/image.lua +++ b/scripts/image.lua @@ -12,6 +12,7 @@ local a = Image(32, 64) assert(a.width == 32) assert(a.height == 64) assert(a.colorMode == ColorMode.RGB) -- RGB by default +assert(a.rowStride == 32*4) assert(a:isEmpty()) assert(a:isPlain(rgba(0, 0, 0, 0))) assert(a:isPlain(0)) @@ -21,6 +22,7 @@ do assert(b.width == 32) assert(b.height == 64) assert(b.colorMode == ColorMode.INDEXED) + assert(b.rowStride == 32*1) local c = Image{ width=32, height=64, colorMode=ColorMode.INDEXED } assert(c.width == 32) From 261ab6e79540b552abfd9a210613479961c8222d Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 12 Oct 2021 19:57:33 -0300 Subject: [PATCH 177/200] Enable all tests for events --- scripts/events.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/events.lua b/scripts/events.lua index fcdcf3193..3740058b3 100644 --- a/scripts/events.lua +++ b/scripts/events.lua @@ -5,7 +5,6 @@ dofile('./test_utils.lua') -if false then -- Test app.events do local i = 0 @@ -43,8 +42,6 @@ do expect_eq(3, changes) end -end - -- Multiple listeners do local spr = Sprite(2, 2) From 2b122616eb64287b71b316ffbaa293536b9b4cb9 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 19 Oct 2021 15:20:24 -0300 Subject: [PATCH 178/200] Add "fgcolorchange" and "bgcolorchange" events --- scripts/events.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/events.lua b/scripts/events.lua index 3740058b3..78b8fe7d2 100644 --- a/scripts/events.lua +++ b/scripts/events.lua @@ -24,6 +24,31 @@ do expect_eq(3, i) end +do + local pref = app.preferences + pref.color_bar.fg_color = Color(0, 0, 0) + pref.color_bar.bg_color = Color(0, 0, 0) + + local fg, bg = 0, 0 + local a = app.events:on('fgcolorchange', function() fg = fg + 1 end) + local b = app.events:on('bgcolorchange', function() bg = bg + 1 end) + assert(fg == 0) + assert(bg == 0) + + pref.color_bar.fg_color = Color(255, 0, 0) + pref.color_bar.bg_color = Color(255, 0, 0) + assert(fg == 1) + assert(bg == 1) + pref.color_bar.fg_color = Color(255, 0, 0) -- No change (same color) + assert(fg == 1) + pref.color_bar.fg_color = Color(0, 0, 0) + assert(fg == 2) + app.events:off(a) + app.events:off(b) + pref.color_bar.fg_color = Color(255, 0, 0) + assert(fg == 2) +end + -- Test Sprite.events do local spr = Sprite(32, 64) From 6ca19d33a0f30ac390630b55d29b001dd51ec905 Mon Sep 17 00:00:00 2001 From: Joshua Ogunyinka Date: Fri, 12 Nov 2021 13:43:07 +0400 Subject: [PATCH 179/200] Test correct layers iteration when layer names are numbers Related to: https://github.com/aseprite/aseprite/issues/3045 --- scripts/layers.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/layers.lua b/scripts/layers.lua index 361ef4a58..6fec6899f 100644 --- a/scripts/layers.lua +++ b/scripts/layers.lua @@ -185,3 +185,22 @@ do -- life with "undo" app.range.layers = { b } end + +-- Test layer name bug when iterating over layers where names given to +-- some layers are integers and also are valid ranges/indexes in the +-- list of layers +do + local layerNames = { "2", "4", "Non-integer", "1" } + local s = Sprite(4, 4) + local layer1 = s.layers[1] layer1.name = layerNames[1] + local layer2 = s:newLayer() layer2.name = layerNames[2] + local layer3 = s:newLayer() layer3.name = layerNames[3] + local layer4 = s:newLayer() layer4.name = layerNames[4] + + local i = 1 + for index, layer in ipairs(app.activeSprite.layers) do + assert(index == i) + assert(layer.name == layerNames[i]) + i = i + 1 + end +end From 9a387a16e045a01446ba84e5cf8366d98b36bd09 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 15 Nov 2021 15:11:36 -0300 Subject: [PATCH 180/200] Test correct clipping drawing an image in a cel image Reported here https://github.com/aseprite/aseprite/issues/3054 --- scripts/image.lua | 53 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/scripts/image.lua b/scripts/image.lua index b0d08df9c..b6af4ba7f 100644 --- a/scripts/image.lua +++ b/scripts/image.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019-2020 Igara Studio S.A. +-- Copyright (C) 2019-2021 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -213,3 +213,54 @@ do assert(img.spec == spr.spec) assert(img:getPixel(15, 15) == 129) end + +-- Fix drawImage() when drawing in a cel image +do + local a = Image(3, 2, ColorMode.INDEXED) + array_to_pixels({ 0, 1, 2, + 2, 3, 4 }, a) + + local function test(b) + expect_img(b, { 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0 }) + + b:drawImage(a, Point(2, 1)) + expect_img(b, { 0, 0, 0, 0, 0, + 0, 0, 0, 1, 2, + 0, 0, 2, 3, 4, + 0, 0, 0, 0, 0 }) + + b:drawImage(a, Point(0, 1)) + expect_img(b, { 0, 0, 0, 0, 0, + 0, 1, 2, 1, 2, + 2, 3, 4, 3, 4, + 0, 0, 0, 0, 0 }) + + b:drawImage(a, Point(-1, 2)) + expect_img(b, { 0, 0, 0, 0, 0, + 0, 1, 2, 1, 2, + 1, 2, 4, 3, 4, + 3, 4, 0, 0, 0 }) + + b:drawImage(a, Point(0, 3)) + expect_img(b, { 0, 0, 0, 0, 0, + 0, 1, 2, 1, 2, + 1, 2, 4, 3, 4, + 0, 1, 2, 0, 0 }) + + b:drawImage(a, Point(0, 3)) -- Do nothing + expect_img(b, { 0, 0, 0, 0, 0, + 0, 1, 2, 1, 2, + 1, 2, 4, 3, 4, + 0, 1, 2, 0, 0 }) + end + + local b = Image(5, 4, ColorMode.INDEXED) + test(b) + + local s = Sprite(5, 4, ColorMode.INDEXED) + test(app.activeCel.image) + +end From 522825129820a2b0822980509540e1830fd76bea Mon Sep 17 00:00:00 2001 From: Joshua Ogunyinka Date: Wed, 15 Dec 2021 19:05:11 +0400 Subject: [PATCH 181/200] Add color conversion tests --- scripts/color_convert.lua | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 scripts/color_convert.lua diff --git a/scripts/color_convert.lua b/scripts/color_convert.lua new file mode 100644 index 000000000..955d81500 --- /dev/null +++ b/scripts/color_convert.lua @@ -0,0 +1,50 @@ +-- Copyright (C) 2019-2021 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +dofile('./test_utils.lua') + +-- this tests and ensures that the alpha-ness of a background +-- layer is maintained when sprite conversion takes place from +-- Indexed to RGB + +do + local sprite = Sprite(2, 2, ColorMode.INDEXED) + local pal = sprite.palettes[1] + + assert(sprite.layers[1].isTransparent) + assert(sprite.colorMode == ColorMode.INDEXED) + assert(#pal == 256) + + local color = pal:getColor(3) + color.alpha = 200 + pal:setColor(3, color) + + local image = sprite.cels[1].image + image:drawPixel(0, 0, pal:getColor(2)) + image:drawPixel(0, 1, pal:getColor(3)) + image:drawPixel(1, 0, pal:getColor(4)) + image:drawPixel(1, 1, pal:getColor(5)) + + app.command.BackgroundFromLayer() + + local layer = sprite.layers[1] + assert(layer.isTransparent == false) + assert(layer.name == "Background") + + -- change color mode from Indexed to RGB + app.command.ChangePixelFormat { + format="rgb" + } + + assert(sprite.colorMode == ColorMode.RGB) + image = sprite.cels[1].image + + for x=0, 1, 1 do + for y=0, 1, 1 do + local pixel = image:getPixel(x, y) + assert(app.pixelColor.rgbaA(pixel) == 255) + end + end +end From 2da98f2837fd04fa7a4edeef4e3bc14de7930568 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 4 Feb 2022 11:43:34 -0300 Subject: [PATCH 182/200] Add some tests to use Color() with Image:drawPixel() in indexed mode Related to: https://github.com/aseprite/aseprite/issues/3159 --- scripts/drawing.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/drawing.lua b/scripts/drawing.lua index 44d22f8d4..a4b40332a 100644 --- a/scripts/drawing.lua +++ b/scripts/drawing.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2018 Igara Studio S.A. +-- Copyright (C) 2018-2022 Igara Studio S.A. -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. @@ -65,3 +65,19 @@ do assert(r:getPixel(1, 2) == pc.rgba(0, 0, 255, 255)) assert(r:getPixel(2, 2) == pc.rgba(255, 255, 0, 255)) end + + +-- Image:drawPixel with indexed color +do + local a = Sprite(32, 32, ColorMode.INDEXED) + local i = a.cels[1].image + assert(i:getPixel(0, 0) == 0) + assert(i:getPixel(1, 0) == 0) + assert(i:getPixel(2, 0) == 0) + i:drawPixel(0, 0, Color{ index=2 }) + i:drawPixel(1, 0, Color{ index=3 }.index) + i:drawPixel(2, 0, Color(4)) + assert(i:getPixel(0, 0) == 2) + assert(i:getPixel(1, 0) == 3) + assert(i:getPixel(2, 0) == 4) +end From 3b88d4d62e6ece038c2a13a8b4d186464073eac9 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 25 Feb 2022 15:04:56 -0300 Subject: [PATCH 183/200] Add some tests for contour + pixel perfect Related to https://community.aseprite.org/t/13149 --- scripts/tools.lua | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/scripts/tools.lua b/scripts/tools.lua index aa4e51559..ee64aa3b2 100644 --- a/scripts/tools.lua +++ b/scripts/tools.lua @@ -619,3 +619,66 @@ function drawing_with_tiled_mode_and_image_brush() docPref.tiled.mode = 0 -- none (disable tiled mode) end drawing_with_tiled_mode_and_image_brush() + +---------------------------------------------------------------------- +-- countour with pixel perfect +---------------------------------------------------------------------- + +do + local s = Sprite(3, 3, ColorMode.INDEXED) + local i = app.activeImage + i:clear(1) + expect_img(i, + { 1, 1, 1, + 1, 1, 1, + 1, 1, 1 }) + app.useTool{ + tool='contour', + brush=Brush(1), + color=2, + freehandAlgorithm=1, -- 1=FreehandAlgorithm.PIXEL_PERFECT + points={ { 1, 1 }, { 2, 1 }, { 2, 2 } + } + } + expect_img(app.activeImage, + { 1, 1, 1, + 1, 2, 1, + 1, 1, 2 }) + + app.undo() + + -- Test one pixel when using one point + app.useTool{ + tool='contour', + brush=Brush(1), + color=2, + freehandAlgorithm=1, -- 1=FreehandAlgorithm.PIXEL_PERFECT + points={ { 1, 1 } } + } + expect_img(app.activeImage, + { 1, 1, 1, + 1, 2, 1, + 1, 1, 1 }) + app.undo() + + -- Test bug where one click doesn't draw with the contour tool with + -- pixel perfect algorith. + -- Report: https://community.aseprite.org/t/13149 + expect_img(app.activeImage, + { 1, 1, 1, + 1, 1, 1, + 1, 1, 1 }) + app.useTool{ + tool='contour', + brush=Brush(1), + color=2, + freehandAlgorithm=1, -- 1=FreehandAlgorithm.PIXEL_PERFECT + -- Two points in the same spot, this happens in the UI, one + -- created in mouse down, other in mouse up. + points={ { 1, 1 }, { 1, 1 } } + } + expect_img(app.activeImage, + { 1, 1, 1, + 1, 2, 1, + 1, 1, 1 }) +end From 99950d7b4c199431ca40aded15aa01cf6945401b Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 2 Mar 2022 16:09:59 -0300 Subject: [PATCH 184/200] Add some tests for indexed mode + alpha compositing ink Mainly to test: https://github.com/aseprite/aseprite/issues/3047 --- scripts/inks.lua | 59 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/scripts/inks.lua b/scripts/inks.lua index 5d86d1794..6ec229d1d 100644 --- a/scripts/inks.lua +++ b/scripts/inks.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2020 Igara Studio S.A. +-- Copyright (C) 2020-2022 Igara Studio S.A. -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. @@ -222,3 +222,60 @@ for i = 1,#colorModes do test_inks(colorModes[i]) end test_alpha_compositing_on_indexed_with_full_opacity_and_repeated_colors_in_palette() + +---------------------------------------------------------------------- +-- Test painting with transparent color on indexed +---------------------------------------------------------------------- + +do + local s = Sprite(2, 2, ColorMode.INDEXED) + s.transparentColor = 0 + app.bgColor = 0 + app.command:BackgroundFromLayer() + expect_img(app.activeImage, { 0, 0, + 0, 0 }) + + app.useTool{ tool="pencil", color=Color{r=0,g=0,b=0}, + points={ Point(0, 0) }, + ink=Ink.SIMPLE } + expect_img(app.activeImage, { 0, 0, + 0, 0 }) + + -- Test that painting in the background layer with transparent color + -- with alpha compositing and all opacity=255, will use the transparent + -- index anyway. Reported here: https://github.com/aseprite/aseprite/issues/3047 + app.useTool{ tool="pencil", color=0, + points={ Point(0, 0) }, + ink=Ink.ALPHA_COMPOSITING, + opacity=255 } + expect_img(app.activeImage, { 0, 0, + 0, 0 }) + + -- Other cases should keep working + local p = s.palettes[1] + + -- palette with only 3 colors: white, gray (50%), black + p:setColor(0, Color{ r=255, g=255, b=255 }) + p:setColor(1, Color{ r=128, g=128, b=128 }) + p:setColor(2, Color{ r=0, g=0, b=0 }) + app.useTool{ tool="paint_bucket", color=2, + points={ Point(0, 0) }, + ink=Ink.SIMPLE } + + -- White over black w/opacity=50% => gray + app.useTool{ tool="pencil", color=0, + points={ Point(0, 0) }, + ink=Ink.ALPHA_COMPOSITING, + opacity=128 } + expect_img(app.activeImage, { 1, 2, + 2, 2 }) + + -- White over gray w/opacity=51% => white + app.useTool{ tool="pencil", color=0, + points={ Point(0, 0) }, + ink=Ink.ALPHA_COMPOSITING, + opacity=129 } + expect_img(app.activeImage, { 0, 2, + 2, 2 }) + +end From 64045a67105ea8e33898c6b6d9852df65f944373 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 2 Mar 2022 21:37:30 -0300 Subject: [PATCH 185/200] Some minor changes/asserts in inks.lua --- scripts/inks.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/inks.lua b/scripts/inks.lua index 6ec229d1d..21c9d5d74 100644 --- a/scripts/inks.lua +++ b/scripts/inks.lua @@ -231,7 +231,8 @@ do local s = Sprite(2, 2, ColorMode.INDEXED) s.transparentColor = 0 app.bgColor = 0 - app.command:BackgroundFromLayer() + app.command.BackgroundFromLayer() + assert(app.activeLayer.isBackground) expect_img(app.activeImage, { 0, 0, 0, 0 }) @@ -261,6 +262,8 @@ do app.useTool{ tool="paint_bucket", color=2, points={ Point(0, 0) }, ink=Ink.SIMPLE } + expect_img(app.activeImage, { 2, 2, + 2, 2 }) -- White over black w/opacity=50% => gray app.useTool{ tool="pencil", color=0, From 2a96d2d1c0a6c191697200c609a8b288d01364bd Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 3 Mar 2022 11:29:36 -0300 Subject: [PATCH 186/200] Fix some tests failing when calling BackgroundFromLayer and the user has some special app.bgColor values in the preferences --- scripts/color_convert.lua | 3 ++- scripts/inks.lua | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/color_convert.lua b/scripts/color_convert.lua index 955d81500..3babcef41 100644 --- a/scripts/color_convert.lua +++ b/scripts/color_convert.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019-2021 Igara Studio S.A. +-- Copyright (C) 2019-2022 Igara Studio S.A. -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. @@ -27,6 +27,7 @@ do image:drawPixel(1, 0, pal:getColor(4)) image:drawPixel(1, 1, pal:getColor(5)) + app.bgColor = Color{ index=0 } app.command.BackgroundFromLayer() local layer = sprite.layers[1] diff --git a/scripts/inks.lua b/scripts/inks.lua index 21c9d5d74..91dbfd4f2 100644 --- a/scripts/inks.lua +++ b/scripts/inks.lua @@ -70,6 +70,7 @@ function test_inks(colorMode) end -- Convert to background layer + app.bgColor = Color{ index=0 } app.command.BackgroundFromLayer() app.useTool{ tool=pencil, color=d, points={ Point(0, 1), Point(2, 1) }, From 09958449c39bad222c66252a23aac9f3a5eacd3a Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Thu, 3 Mar 2022 11:29:36 -0300 Subject: [PATCH 187/200] Add export sprite sheet test when some cels are linked + TrimmedCels + Merge Duplicates + SplitLayers checked https://github.com/aseprite/aseprite/issues/2600 --- cli/sheet.sh | 71 +++++++++++++++++++++++++++++++++++++++++- sprites/link.aseprite | Bin 0 -> 845 bytes 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 sprites/link.aseprite diff --git a/cli/sheet.sh b/cli/sheet.sh index f6e2c2be0..27c46b4aa 100644 --- a/cli/sheet.sh +++ b/cli/sheet.sh @@ -1,5 +1,5 @@ #! /bin/bash -# Copyright (C) 2019-2020 Igara Studio S.A. +# Copyright (C) 2019-2022 Igara Studio S.A. # $1 = first sprite sheet json file # $2 = second sprite sheet json file @@ -331,3 +331,72 @@ assert(#sheet2.meta.layers == 8) assert(json.encode(sheet1.meta.layers) == json.encode(sheet2.meta.layers)) EOF $ASEPRITE -b -script "$d/check.lua" || exit 1 + +# https://github.com/aseprite/aseprite/issues/2600 +# -merge-duplicates -split-layers -trim give incorrect 'frame' coordinates on linked cels +d=$t/issue-2600 +$ASEPRITE -b -list-layers -format json-array -trim -merge-duplicates -split-layers -all-layers "sprites/link.aseprite" -data "$d/sheet.json" -sheet "$d/sheet.png" +cat >$d/check.lua < #sheet.meta.layers) + +app.activeSprite = restoredSprite +app.activeLayer = restoredSprite.layers[#restoredSprite.layers] +for i=1,#restoredSprite.layers-1 do + app.command.MergeDownLayer() +end + +local orig = app.open("sprites/link.aseprite") +app.activeSprite = orig +app.activeLayer = orig.layers[#orig.layers] +for i=1,#orig.layers-1 do + app.command.MergeDownLayer() +end + +assert(orig.width == restoredSprite.width) +assert(orig.height == restoredSprite.height) +assert(#orig.frames == #restoredSprite.frames) +for fr=1,#restoredSprite.frames do + for celIndex1=1,#restoredSprite.cels do + if restoredSprite.cels[celIndex1].frameNumber == fr then + for celIndex2=1,#orig.cels do + if orig.cels[celIndex2].frameNumber == fr then + assert(orig.cels[celIndex2].position == restoredSprite.cels[celIndex1].position) + if orig.cels[celIndex2].image ~= nil and restoredSprite.cels[celIndex1].image ~= nil then + assert(orig.cels[celIndex2].image:isEqual(restoredSprite.cels[celIndex1].image)) + end + end + end + end + end +end +EOF +$ASEPRITE -b -script "$d/check.lua" || exit 1 diff --git a/sprites/link.aseprite b/sprites/link.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..461eba73e91e4b5e084337189943ebe88c1a4c26 GIT binary patch literal 845 zcmcJNPe>F|9LImoIvQS-4z?BSK18I%Xm^ZcaZwSyWPvQQQ63!Iu$+TSB)JfDh(OrO zUV^CIgBMTg!BgNNf*=s_yqE_S)`L)qp2AI@pP5~96g>7G^WpLS%=hz~HxB|L+w+E8 zqARHpk*7STjX8Hxn&|(dJvKy+4jR1F1_GLS>XjGii~GU&s#4XNuy4g1YLOOo2M*qd z!--fF=91lT>qQ&fn45sVzkPz`!@Ka~?l5$|L}1tZDL6EF8zzQYp%st8-ri{#vERbc zsU4WgYdE%Ef@_<9p{9xCmp;RHZ)V}7g^QL2Hy);7@%0MKeYgj+>4xoGKH(%2OD2J&5p~T?Qe5}H zhJqM!KYHPcb>T{98)t)O?&;i}1!QFW*)4XN%1tpubJLYpOU0Q&%C_x4jRPfnE?Fnp zt?RotSv9>^n!e2ej%Etwuq08%Twy6v;`EI9gt!~ueZjtu#mA#kjIywk= zf0kQyr*}#?<9Dg6y7ZaFg_+~}@#&uBC(pk}MZWHb(n0TtTNp;Z`YQ8P0pI)y5tFo! literal 0 HcmV?d00001 From dd30981e8ba4e33d70b7fc8706a4e795677003d7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 23 May 2022 17:23:16 -0300 Subject: [PATCH 188/200] Add tests to compare different sprites (Sprite vs Layer mainly) Related to: https://github.com/aseprite/aseprite/issues/3218 --- LICENSE.txt | 2 +- scripts/color.lua | 2 ++ scripts/layers.lua | 11 ++++++++++- scripts/sprite.lua | 11 ++++++++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index a1db71aea..7d9e58083 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2018-2021 Igara Studio S.A. +Copyright (c) 2018-2022 Igara Studio S.A. Copyright (c) 2018 David Capello Permission is hereby granted, free of charge, to any person obtaining diff --git a/scripts/color.lua b/scripts/color.lua index f71eee379..ab2751837 100644 --- a/scripts/color.lua +++ b/scripts/color.lua @@ -1,3 +1,4 @@ +-- Copyright (C) 2022 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -41,3 +42,4 @@ assert(b.saturation == 0.4) assert(b.value == 0.5) assert(b.alpha == 200) assert(a == b) +assert(a ~= 1) -- Comparing with other type fails diff --git a/scripts/layers.lua b/scripts/layers.lua index 6fec6899f..a8e16dffc 100644 --- a/scripts/layers.lua +++ b/scripts/layers.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019 Igara Studio S.A. +-- Copyright (C) 2019-2022 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -204,3 +204,12 @@ do i = i + 1 end end + +-- Compare layers vs sprites (just return false) + +do + local s = Sprite(2, 2) + assert(s.layers[1].parent == s) + assert(s.layers[1] ~= s) -- Uses Layer_eq() to compare + assert(s ~= s.layers[1]) -- Uses Sprite_eq() to compare +end diff --git a/scripts/sprite.lua b/scripts/sprite.lua index 347509b82..16f52be5d 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019-2021 Igara Studio S.A. +-- Copyright (C) 2019-2022 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -197,3 +197,12 @@ do assert(s.cels[1].image:getPixel(0, 0) == 2) assert(s.cels[1].image:getPixel(1, 0) == 1) -- Get the color of the first layer end + +-- Compare sprite IDs + +do + local a = Sprite(1, 1) + local b = Sprite(1, 1) + assert(a == a) + assert(a ~= b) -- Compares IDs, not sprite size +end From b8854d34062a8786ae47306908d09c49db2835f4 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 13 Jun 2022 19:17:05 -0300 Subject: [PATCH 189/200] Add simple tests for SaveFile-commands --- scripts/save_file_command.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 scripts/save_file_command.lua diff --git a/scripts/save_file_command.lua b/scripts/save_file_command.lua new file mode 100644 index 000000000..a8b50efb8 --- /dev/null +++ b/scripts/save_file_command.lua @@ -0,0 +1,17 @@ +-- Copyright (C) 2022 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +do + local spr = Sprite(32, 32) + spr.filename = "_test_a.png" + app.command.SaveFile() + assert(spr.filename == "_test_a.png") + + app.command.SaveFileAs{ filename="_test_b.png" } + assert(spr.filename == "_test_b.png") + + app.command.SaveFileCopyAs{ filename="_test_c.png" } + assert(spr.filename == "_test_b.png") +end From 96c4f703d0e1fe643d4363b3b228ef1d286a7c93 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 14 Jun 2022 10:04:29 -0300 Subject: [PATCH 190/200] Test for new Image(Image, Rectangle) ctor --- scripts/image.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/image.lua b/scripts/image.lua index b6af4ba7f..3bbe430af 100644 --- a/scripts/image.lua +++ b/scripts/image.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019-2021 Igara Studio S.A. +-- Copyright (C) 2019-2022 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -59,6 +59,16 @@ do assert(d:getPixel(x, y) == expectedColor) end end + + -- Clone a rectangle + local e = Image(c, Rectangle(1, 1, 4, 5)) + print(e.width) + print(e.height) + assert(e.width == 4) + assert(e.height == 5) + + -- Empty clone + assert(nil == Image(c, Rectangle(1, 1, 0, 0))) end -- Patch From 1caeee9aceaac470db75b62b2385804f061b7f6d Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 14 Jun 2022 10:58:14 -0300 Subject: [PATCH 191/200] Test SaveFile with slice parameter --- scripts/save_file_command.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/save_file_command.lua b/scripts/save_file_command.lua index a8b50efb8..04529e937 100644 --- a/scripts/save_file_command.lua +++ b/scripts/save_file_command.lua @@ -5,13 +5,23 @@ do local spr = Sprite(32, 32) - spr.filename = "_test_a.png" + app.useTool{ color=Color(255, 255, 255), brush=Brush(1), + tool="filled_ellipse", points={{0,0},{31,31}} } + spr.filename = "_test_a.aseprite" app.command.SaveFile() - assert(spr.filename == "_test_a.png") + assert(spr.filename == "_test_a.aseprite") app.command.SaveFileAs{ filename="_test_b.png" } assert(spr.filename == "_test_b.png") app.command.SaveFileCopyAs{ filename="_test_c.png" } assert(spr.filename == "_test_b.png") + + -- Slices + local slice = spr:newSlice(Rectangle(1, 2, 8, 15)) + slice.name = "small_slice" + app.command.SaveFileCopyAs{ filename="_test_c_small_slice.png", slice="small_slice" } + local c = app.open("_test_c_small_slice.png") + assert(c.width == 8) + assert(c.height == 15) end From ee696ede163354b3ed5e81b9c543ac53dc21f334 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 14 Jun 2022 21:51:13 -0300 Subject: [PATCH 192/200] Test SaveFile command with scale and slice parameters --- scripts/save_file_command.lua | 55 ++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/scripts/save_file_command.lua b/scripts/save_file_command.lua index 04529e937..891c633b1 100644 --- a/scripts/save_file_command.lua +++ b/scripts/save_file_command.lua @@ -4,9 +4,16 @@ -- Read LICENSE.txt for more information. do - local spr = Sprite(32, 32) - app.useTool{ color=Color(255, 255, 255), brush=Brush(1), + local spr = Sprite(32, 32, ColorMode.INDEXED) + spr.palettes[1]:resize(3) + spr.palettes[1]:setColor(0, Color(0, 0, 0, 0)) + spr.palettes[1]:setColor(1, Color(0, 0, 0, 255)) + spr.palettes[1]:setColor(2, Color(255, 0, 0, 255)) + + app.useTool{ color=1, brush=Brush(1), tool="filled_ellipse", points={{0,0},{31,31}} } + app.useTool{ color=2, brush=Brush(1), + tool="filled_ellipse", points={{4,4},{27,27}} } spr.filename = "_test_a.aseprite" app.command.SaveFile() assert(spr.filename == "_test_a.aseprite") @@ -17,11 +24,45 @@ do app.command.SaveFileCopyAs{ filename="_test_c.png" } assert(spr.filename == "_test_b.png") - -- Slices + -- Scale + for _,fn in ipairs({ "_test_c_scaled.png", + "_test_c_scaled.gif", + "_test_c_scaled.fli", + "_test_c_scaled.tga", + "_test_c_scaled.bmp" }) do + for _,scale in ipairs({ 1, 2, 4 }) do + app.activeSprite = spr + app.command.SaveFileCopyAs{ filename=fn, scale=scale } + local c = app.open(fn) + assert(c.width == spr.width*scale) + assert(c.height == spr.height*scale) + + local testImg = Image(spr.cels[1].image) + testImg:resize(testImg.width*scale, testImg.height*scale) + assert(c.cels[1].image:isEqual(testImg)) + end + end + + -- Scale + Slices local slice = spr:newSlice(Rectangle(1, 2, 8, 15)) slice.name = "small_slice" - app.command.SaveFileCopyAs{ filename="_test_c_small_slice.png", slice="small_slice" } - local c = app.open("_test_c_small_slice.png") - assert(c.width == 8) - assert(c.height == 15) + for _,fn in ipairs({ "_test_c_small_slice.png", + -- Slices aren't supported in gif/fli yet + --"_test_c_small_slice.gif", + --"_test_c_small_slice.fli", + "_test_c_small_slice.tga", + "_test_c_small_slice.bmp" }) do + for _,scale in ipairs({ 1, 2, 4 }) do + app.activeSprite = spr + app.command.SaveFileCopyAs{ filename=fn, slice="small_slice", scale=scale } + local c = app.open(fn) + assert(c.width == 8*scale) + assert(c.height == 15*scale) + + local testImg = Image(spr.cels[1].image, spr.slices[1].bounds) + testImg:resize(testImg.width*scale, testImg.height*scale) + assert(c.cels[1].image:isEqual(testImg)) + end + end + end From 2c601bee776961cdafdaf40092a1455f4b4b51cc Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 15 Jun 2022 10:20:13 -0300 Subject: [PATCH 193/200] Test SaveFile with different color modes --- scripts/save_file_command.lua | 143 ++++++++++++++++++++++++++-------- 1 file changed, 109 insertions(+), 34 deletions(-) diff --git a/scripts/save_file_command.lua b/scripts/save_file_command.lua index 891c633b1..dd800ec0d 100644 --- a/scripts/save_file_command.lua +++ b/scripts/save_file_command.lua @@ -3,18 +3,53 @@ -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. -do - local spr = Sprite(32, 32, ColorMode.INDEXED) +function fix_test_img(testImg, scale, fileExt, cm, c1) + -- With file formats that don't support alpha channel, we + -- compare totally transparent pixels (alpha=0) with black. + if fileExt == "bmp" or (fileExt == "tga" and + cm == ColorMode.GRAYSCALE) then + local pixel + if cm == ColorMode.RGB then + pixel = c1.rgbaPixel + elseif cm == ColorMode.GRAYSCALE then + pixel = c1.grayPixel + else + pixel = 0 -- Do nothing in indexed + end + for p in testImg:pixels() do + if p() == 0 then p(pixel) end + end + end + testImg:resize(testImg.width*scale, testImg.height*scale) +end + +for _,cm in ipairs{ ColorMode.RGB, + ColorMode.GRAYSCALE, + ColorMode.INDEXED } do + local spr = Sprite(32, 32, cm) spr.palettes[1]:resize(3) spr.palettes[1]:setColor(0, Color(0, 0, 0, 0)) spr.palettes[1]:setColor(1, Color(0, 0, 0, 255)) spr.palettes[1]:setColor(2, Color(255, 0, 0, 255)) - app.useTool{ color=1, brush=Brush(1), - tool="filled_ellipse", points={{0,0},{31,31}} } - app.useTool{ color=2, brush=Brush(1), - tool="filled_ellipse", points={{4,4},{27,27}} } + local c1, c2 + if cm == ColorMode.RGB then + c1 = Color(0, 0, 0) + c2 = Color(255, 0, 0) + elseif cm == ColorMode.GRAYSCALE then + c1 = Color{ gray=0 } + c2 = Color{ gray=255 } + elseif cm == ColorMode.INDEXED then + c1 = 1 + c2 = 2 + end + + app.useTool{ color=c1, brush=Brush(1), + tool="filled_ellipse", points={{0,0},{31,31}} } + app.useTool{ color=c2, brush=Brush(1), + tool="filled_ellipse", points={{4,4},{27,27}} } spr.filename = "_test_a.aseprite" + app.command.SaveFile() assert(spr.filename == "_test_a.aseprite") @@ -25,21 +60,51 @@ do assert(spr.filename == "_test_b.png") -- Scale - for _,fn in ipairs({ "_test_c_scaled.png", - "_test_c_scaled.gif", - "_test_c_scaled.fli", - "_test_c_scaled.tga", - "_test_c_scaled.bmp" }) do - for _,scale in ipairs({ 1, 2, 4 }) do - app.activeSprite = spr - app.command.SaveFileCopyAs{ filename=fn, scale=scale } - local c = app.open(fn) - assert(c.width == spr.width*scale) - assert(c.height == spr.height*scale) + for _,fn in ipairs{ "_test_c_scaled.png", + "_test_c_scaled.gif", + "_test_c_scaled.fli", + "_test_c_scaled.tga", + "_test_c_scaled.bmp" } do + local fileExt = app.fs.fileExtension(fn) - local testImg = Image(spr.cels[1].image) - testImg:resize(testImg.width*scale, testImg.height*scale) - assert(c.cels[1].image:isEqual(testImg)) + -- TODO support saving any color mode to FLI files on the fly + if (fileExt ~= "fli" or cm == ColorMode.INDEXED) and + -- TODO Review grayscale support in bmp files + (fileExt ~= "bmp" or cm ~= ColorMode.GRAYSCALE) then + for _,scale in ipairs({ 1, 2, 3, 4 }) do + print(fn, scale, cm) + + app.activeSprite = spr + app.command.SaveFileCopyAs{ filename=fn, scale=scale } + local c = app.open(fn) + assert(c.width == spr.width*scale) + assert(c.height == spr.height*scale) + + -- GIF file is loaded as indexed, so we have to convert from + -- indexed to the ColorMode + if c.colorMode ~= cm then + assert(fileExt == "gif" or fileExt == "bmp") + + if cm == ColorMode.RGB then + app.activeSprite = c + app.command.ChangePixelFormat{ format="rgb" } + elseif cm == ColorMode.GRAYSCALE then + app.activeSprite = c + app.command.ChangePixelFormat{ format="grayscale" } + else + assert(false) + end + end + + local testImg = Image(spr.cels[1].image) + fix_test_img(testImg, scale, fileExt, cm, c1) + if not c.cels[1].image:isEqual(testImg) then + c.cels[1].image:saveAs("_testA.png") + testImg:saveAs("_testB.png") + end + assert(c.cels[1].image.colorMode == testImg.colorMode) + assert(c.cels[1].image:isEqual(testImg)) + end end end @@ -47,21 +112,31 @@ do local slice = spr:newSlice(Rectangle(1, 2, 8, 15)) slice.name = "small_slice" for _,fn in ipairs({ "_test_c_small_slice.png", - -- Slices aren't supported in gif/fli yet - --"_test_c_small_slice.gif", - --"_test_c_small_slice.fli", - "_test_c_small_slice.tga", - "_test_c_small_slice.bmp" }) do - for _,scale in ipairs({ 1, 2, 4 }) do - app.activeSprite = spr - app.command.SaveFileCopyAs{ filename=fn, slice="small_slice", scale=scale } - local c = app.open(fn) - assert(c.width == 8*scale) - assert(c.height == 15*scale) + -- TODO slices aren't supported in gif/fli yet + --"_test_c_small_slice.gif", + --"_test_c_small_slice.fli", + "_test_c_small_slice.tga", + "_test_c_small_slice.bmp" }) do + local fileExt = app.fs.fileExtension(fn) - local testImg = Image(spr.cels[1].image, spr.slices[1].bounds) - testImg:resize(testImg.width*scale, testImg.height*scale) - assert(c.cels[1].image:isEqual(testImg)) + if (fileExt ~= "bmp" or cm ~= ColorMode.GRAYSCALE) then + for _,scale in ipairs({ 1, 2, 3, 4 }) do + print(fn, scale, cm) + + app.activeSprite = spr + app.command.SaveFileCopyAs{ filename=fn, slice="small_slice", scale=scale } + local c = app.open(fn) + assert(c.width == slice.bounds.width*scale) + assert(c.height == slice.bounds.height*scale) + + local testImg = Image(spr.cels[1].image, spr.slices[1].bounds) + fix_test_img(testImg, scale, fileExt, cm, c1) + if not c.cels[1].image:isEqual(testImg) then + c.cels[1].image:saveAs("_testA.png") + testImg:saveAs("_testB.png") + end + assert(c.cels[1].image:isEqual(testImg)) + end end end From f2312f85feca34465909dbb4ce39c9b2317b4e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Capello?= Date: Mon, 27 Jun 2022 16:48:29 -0300 Subject: [PATCH 194/200] Test that exporting a sprite sheet uses the correct mask color index when spacing > 0 (test https://github.com/aseprite/aseprite/issues/3391) --- scripts/app_command.lua | 15 +++++++++++++++ sprites/2f-index-3x3.aseprite | Bin 0 -> 616 bytes sprites/README.md | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 sprites/2f-index-3x3.aseprite diff --git a/scripts/app_command.lua b/scripts/app_command.lua index 50c3b30a4..a96a8b420 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -41,6 +41,21 @@ do -- NewSprite assert(s2.colorMode == ColorMode.INDEXED) end +do -- ExportSpriteSheet + local s = Sprite{ fromFile="sprites/2f-index-3x3.aseprite" } + app.command.ExportSpriteSheet { + type="horizontal", + textureFilename="_test_export_spritesheet1.png", + shapePadding=1 + } + local i = Image{ fromFile="_test_export_spritesheet1.png" } + expect_img(i, { + 11,8,11,21,8,11,11, + 11,8,11,21,11,8,11, + 11,8,11,21,11,11,8, + }) +end + do -- NewLayer/RemoveLayer local s = Sprite(32, 32) assert(#s.layers == 1) diff --git a/sprites/2f-index-3x3.aseprite b/sprites/2f-index-3x3.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..55d2ce4101e9a7a2150337e935f059fe78208dc1 GIT binary patch literal 616 zcmcJNF-QVY9Ebm>T{gB9H2J6~w^X8%1R-e2hHx;#p~RBB!6+h%pdo_5#U+Tcp{1>$ zEof+Il;*I8jOxa~Mhjlw-4(br_J6$Z-o4}Q_q}^>*(Xvz^NF9CtN?d-#XWx=_03T{l4;CVC(YqL3czkLnMhf}b$64n+AXmkF%V!$F;0s6Qjjy1~o zB8w@SI3kE0YIq@q5ju{G)>xoGKH(%2OD2J&5fyZjlpp>U3KEd%?AFqniVSjND({iz oP Date: Wed, 29 Jun 2022 19:44:02 -0300 Subject: [PATCH 195/200] Test undo of Sprite:newSlice() Related to https://github.com/aseprite/aseprite/issues/3393 --- scripts/slices.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/slices.lua b/scripts/slices.lua index d9b0b522c..42e3d2589 100644 --- a/scripts/slices.lua +++ b/scripts/slices.lua @@ -1,3 +1,4 @@ +-- Copyright (C) 2022 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -13,14 +14,27 @@ do assert(b.bounds == Rectangle(0, 2, 8, 10)) assert(c.bounds == Rectangle(0, 0, 32, 32)) + local bounds = { nil, Rectangle(0, 2, 8, 10), Rectangle(0, 0, 32, 32) } + local i = 1 for k,v in ipairs(s.slices) do assert(i == k) assert(v == s.slices[k]) + assert(bounds[i] == s.slices[k].bounds) i = i+1 end s:deleteSlice(b) assert(a == s.slices[1]) assert(c == s.slices[2]) + + assert(2 == #s.slices) + app.undo() + assert(3 == #s.slices) + app.undo() + assert(2 == #s.slices) + app.undo() + assert(1 == #s.slices) + app.undo() + assert(0 == #s.slices) end From 1f5d89a4277db340de0ebedfb41edd1fdabdb811 Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Wed, 6 Jul 2022 09:02:48 -0300 Subject: [PATCH 196/200] Tests for issue aseprite/aseprite#3207 Before the fix the conversion from RGB to INDEXED color mode, in transparent layers, always picked index 0 as transparent color, even if the mask color was present in the palette. --- scripts/color_quantization.lua | 56 +++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/scripts/color_quantization.lua b/scripts/color_quantization.lua index 649eab6d4..b37a9c13a 100644 --- a/scripts/color_quantization.lua +++ b/scripts/color_quantization.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019-2021 Igara Studio S.A. +-- Copyright (C) 2019-2022 Igara Studio S.A. -- -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. @@ -145,3 +145,57 @@ do 2, 0 }) end + +---------------------------------------------------------------------- +-- Tests for issue aseprite/aseprite#3207 +-- Conversion RGB to INDEXED color mode, in transparent layers, always +-- picks index 0 as transparent color, even if the mask color is present +-- in the palette. + +do + local s = Sprite(2, 3, ColorMode.RGB) + local p = Palette(4) + p:setColor(0, Color(0, 0, 0)) + p:setColor(1, Color(255, 0, 0)) + p:setColor(2, Color(0, 0, 0, 0)) + p:setColor(3, Color(0, 255, 0)) + s:setPalette(p) + + local bg = s.cels[1].image + array_to_pixels({ rgba(0, 0, 0),rgba(255, 0, 0), + rgba(255, 0, 0), rgba(0, 0, 0, 0), + rgba(0, 0, 0, 0), rgba(0, 0, 0, 0), }, bg) + + app.command.ChangePixelFormat{ format="indexed", rgbmap="rgb5a3" } + -- Using the 5-bit precision of RGB5A3 will match everything with + -- the first palette entry. + bg = s.cels[1].image + expect_img(bg, { 0, 1, + 1, 2, + 2, 2 }) + app.undo() + + app.command.ChangePixelFormat{ format="indexed", rgbmap="octree" } + bg = s.cels[1].image + expect_img(bg, { 0, 1, + 1, 2, + 2, 2 }) + app.undo() + + p:setColor(2, Color(0, 0, 255)) + s:setPalette(p) + bg = s.cels[1].image + + app.command.ChangePixelFormat{ format="indexed", rgbmap="rgb5a3" } + bg = s.cels[1].image + expect_img(bg, { 2, 1, + 1, 0, + 0, 0 }) + app.undo() + + app.command.ChangePixelFormat{ format="indexed", rgbmap="octree" } + bg = s.cels[1].image + expect_img(bg, { 2, 1, + 1, 0, + 0, 0 }) +end From 02a2f1f933e2b8d830cc8c6d91eba399ebe62498 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 16 Jul 2022 13:11:05 -0300 Subject: [PATCH 197/200] Test when Sprite.events are created just when the sprite is being closed As app 'sitechange' event is generated when we close a sprite, accessing Sprite.events on that event will re-create the app::script::SpriteEvents instance associated with the sprite. --- scripts/events.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/events.lua b/scripts/events.lua index 78b8fe7d2..0a523bb45 100644 --- a/scripts/events.lua +++ b/scripts/events.lua @@ -109,3 +109,28 @@ do -- listener instead of doing nothing. expect_eq(2, i) end + +-- Accessing Sprite.events when closing the same sprite will call +-- push_sprite_events() creating a new app::script::SpriteEvents +-- instance again even when we've just destroyed the old one (because +-- we're just closing the sprite). +do + local s = Sprite(32, 32) + function onSpriteChange() + -- Do nothing + end + -- Here we access s.events for first time, creating the + -- app::script::SpriteEvents for this sprite. + s.events:on('change', onSpriteChange) + function onSiteChange() + -- Accessing s.events again on 'sitechange' when we're just + -- closing the sprite, re-generating its SpriteEvents instance. + -- We've to have special care of this case. + s.events:off(onSpriteChange) + end + app.events:on('sitechange', onSiteChange) + -- Closing the sprite will create a 'sitechange' event calling + -- onSiteChange() function. + s:close() + app.events:off(onSiteChange) +end From 29af6174bd5410a90bda158a8fc2a45796eeb032 Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Wed, 24 Aug 2022 19:09:18 -0300 Subject: [PATCH 198/200] Fix fix_test_img() because BMP supports alpha channel --- scripts/save_file_command.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/save_file_command.lua b/scripts/save_file_command.lua index dd800ec0d..b2963681c 100644 --- a/scripts/save_file_command.lua +++ b/scripts/save_file_command.lua @@ -6,8 +6,7 @@ function fix_test_img(testImg, scale, fileExt, cm, c1) -- With file formats that don't support alpha channel, we -- compare totally transparent pixels (alpha=0) with black. - if fileExt == "bmp" or (fileExt == "tga" and - cm == ColorMode.GRAYSCALE) then + if fileExt == "tga" and cm == ColorMode.GRAYSCALE then local pixel if cm == ColorMode.RGB then pixel = c1.rgbaPixel From 82bd4e61dd4e48dc0a7a27756d7972e0e631fc3d Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 24 Oct 2022 14:03:54 -0300 Subject: [PATCH 199/200] Add Tag.repeats field --- scripts/tag.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/tag.lua b/scripts/tag.lua index d49604ac6..2d38fd881 100644 --- a/scripts/tag.lua +++ b/scripts/tag.lua @@ -36,6 +36,10 @@ do a.color = Color(255, 0, 0) assert(a.color == Color(255, 0, 0)) + assert(a.repeats == 0) + a.repeats = 1 + assert(a.repeats == 1) + a.data = "Data" assert(a.data == "Data") end From 9959dc5d757de4fd202fc96cde31b2241a6d57ce Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 25 Oct 2022 14:56:41 -0300 Subject: [PATCH 200/200] run-tests.sh requires /bin/bash, not /bin/sh (reported in #9) --- run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-tests.sh b/run-tests.sh index cd428ed5c..f94e90136 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash # Copyright (C) 2018 Igara Studio S.A. # Copyright (C) 2018 David Capello