| 
									
										
										
										
											2018-09-05 04:31:27 +08:00
										 |  |  | -- Copyright (C) 2018  David Capello | 
					
						
							|  |  |  | -- | 
					
						
							|  |  |  | -- This file is released under the terms of the MIT license. | 
					
						
							|  |  |  | -- Read LICENSE.txt for more information. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 01:21:20 +08:00
										 |  |  | do -- Undo/Redo commands (like app.undo/redo()) | 
					
						
							|  |  |  |   local s = Sprite(32, 32) | 
					
						
							|  |  |  |   assert(s.width == 32) | 
					
						
							|  |  |  |   assert(s.height == 32) | 
					
						
							| 
									
										
										
										
											2018-09-05 04:31:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 01:21:20 +08:00
										 |  |  |   s:resize(50, 40) | 
					
						
							|  |  |  |   assert(s.width == 50) | 
					
						
							|  |  |  |   assert(s.height == 40) | 
					
						
							| 
									
										
										
										
											2018-09-05 04:31:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 01:21:20 +08:00
										 |  |  |   app.command.Undo() | 
					
						
							|  |  |  |   assert(s.width == 32) | 
					
						
							|  |  |  |   assert(s.height == 32) | 
					
						
							| 
									
										
										
										
											2018-09-05 04:31:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 01:21:20 +08:00
										 |  |  |   app.command.Redo() | 
					
						
							|  |  |  |   assert(s.width == 50) | 
					
						
							|  |  |  |   assert(s.height == 40) | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2018-09-05 04:31:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 01:21:20 +08:00
										 |  |  | 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) | 
					
						
							| 
									
										
										
										
											2018-09-05 04:31:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 01:21:20 +08:00
										 |  |  |   app.command.NewLayer{top=true, group=true} | 
					
						
							|  |  |  |   assert(#s.layers == 3) | 
					
						
							|  |  |  |   assert(s.layers[3].isGroup) | 
					
						
							| 
									
										
										
										
											2018-09-05 04:31:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 01:21:20 +08:00
										 |  |  |   app.command.RemoveLayer() | 
					
						
							|  |  |  |   assert(#s.layers == 2) | 
					
						
							| 
									
										
										
										
											2018-09-05 04:31:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 01:21:20 +08:00
										 |  |  |   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) | 
					
						
							| 
									
										
										
										
											2018-09-13 05:45:44 +08:00
										 |  |  |   assert(s.layers[1] == s.backgroundLayer) | 
					
						
							| 
									
										
										
										
											2018-09-07 01:21:20 +08:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2019-01-07 05:24:17 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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 |