mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Convert scripts to Lua
This commit is contained in:
parent
5ef31360f7
commit
9bb05f7a44
21
run-tests.sh
21
run-tests.sh
@ -18,12 +18,12 @@ $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 <<EOF
|
||||
hello world
|
||||
1 2 3
|
||||
@ -32,12 +32,13 @@ 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 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
|
||||
|
@ -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))
|
12
scripts/app_pixel_color.lua
Normal file
12
scripts/app_pixel_color.lua
Normal file
@ -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))
|
@ -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)
|
40
scripts/app_transaction.lua
Normal file
40
scripts/app_transaction.lua
Normal file
@ -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)
|
@ -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] == ".")
|
7
scripts/app_version.lua
Normal file
7
scripts/app_version.lua
Normal file
@ -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) == ".")
|
@ -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")
|
9
scripts/console_assert.lua
Normal file
9
scripts/console_assert.lua
Normal file
@ -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")
|
@ -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)
|
7
scripts/console_print.lua
Normal file
7
scripts/console_print.lua
Normal file
@ -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)
|
@ -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)
|
8
scripts/constants.lua
Normal file
8
scripts/constants.lua
Normal file
@ -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)
|
@ -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))
|
25
scripts/point.lua
Normal file
25
scripts/point.lua
Normal file
@ -0,0 +1,25 @@
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
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)
|
@ -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))
|
37
scripts/rectangle.lua
Normal file
37
scripts/rectangle.lua
Normal file
@ -0,0 +1,37 @@
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
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)
|
@ -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
|
29
scripts/selection.lua
Normal file
29
scripts/selection.lua
Normal file
@ -0,0 +1,29 @@
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
-- 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)
|
@ -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))
|
25
scripts/size.lua
Normal file
25
scripts/size.lua
Normal file
@ -0,0 +1,25 @@
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
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)
|
@ -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)
|
49
scripts/sprite.lua
Normal file
49
scripts/sprite.lua
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user