|
| 1 | +import java.awt.image.BufferedImage; |
| 2 | +import java.nio.Buffer; |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +/** |
| 7 | + * Created by Andreas on 13.12.2015. |
| 8 | + */ |
| 9 | +public class SGModel { |
| 10 | + |
| 11 | + private SpritesheetGenerator controller = null; |
| 12 | + |
| 13 | + private List<BufferedImage> sprites = null; |
| 14 | + |
| 15 | + |
| 16 | + private List<Integer> heights = null; |
| 17 | + private List<Integer> widths = null; |
| 18 | + |
| 19 | + public SGModel( SpritesheetGenerator controller ) { |
| 20 | + this.controller = controller; |
| 21 | + sprites = new ArrayList<BufferedImage>(); |
| 22 | + heights = new ArrayList<>(); |
| 23 | + widths = new ArrayList<>(); |
| 24 | + } |
| 25 | + |
| 26 | + public void reset() { |
| 27 | + sprites = new ArrayList<BufferedImage>(); |
| 28 | + heights = new ArrayList<>(); |
| 29 | + widths = new ArrayList<>(); |
| 30 | + } |
| 31 | + |
| 32 | + public List<BufferedImage> getSprites() { |
| 33 | + return sprites; |
| 34 | + } |
| 35 | + |
| 36 | + public void setSprites( List<BufferedImage> sprites ) { |
| 37 | + this.sprites = sprites; |
| 38 | + } |
| 39 | + |
| 40 | + public void addSprite( BufferedImage sprite ) { |
| 41 | + if( sprite!= null ) sprites.add( sprite ); |
| 42 | + } |
| 43 | + |
| 44 | + public void addHeight( int height ) { |
| 45 | + heights.add( height ); |
| 46 | + } |
| 47 | + |
| 48 | + public void addWidth( int width ) { |
| 49 | + widths.add( width ); |
| 50 | + } |
| 51 | + |
| 52 | + public boolean heightsAreEqual() { |
| 53 | + if( heights!=null && !heights.isEmpty() ) { |
| 54 | + int mHeight = heights.get(0); |
| 55 | + for (int height : heights) { |
| 56 | + if( mHeight!=height ) return false; |
| 57 | + } |
| 58 | + return true; |
| 59 | + } |
| 60 | + return false; |
| 61 | + } |
| 62 | + |
| 63 | + public boolean widthsAreEqual() { |
| 64 | + if( widths != null && !widths.isEmpty() ) { |
| 65 | + int mWidth = widths.get(0); |
| 66 | + for( int width : widths ) { |
| 67 | + if( mWidth != width ) return false; |
| 68 | + } |
| 69 | + return true; |
| 70 | + } |
| 71 | + return false; |
| 72 | + } |
| 73 | + |
| 74 | + public boolean hasSprites() { |
| 75 | + if( sprites!=null && !sprites.isEmpty() ) { |
| 76 | + return true; |
| 77 | + } |
| 78 | + return false; |
| 79 | + } |
| 80 | + |
| 81 | + public int getTotalWidth() { |
| 82 | + if( sprites != null && !sprites.isEmpty() ) { |
| 83 | + return sprites.size() * sprites.get(0).getWidth(); |
| 84 | + } |
| 85 | + return -1; |
| 86 | + } |
| 87 | + |
| 88 | + public int getHeight() { |
| 89 | + if( sprites != null && !sprites.isEmpty() ) { |
| 90 | + return sprites.get(0).getHeight(); |
| 91 | + } |
| 92 | + return -1; |
| 93 | + } |
| 94 | + |
| 95 | + public int getType() { |
| 96 | + if( sprites != null && !sprites.isEmpty() ) { |
| 97 | + return sprites.get(0).getType(); |
| 98 | + } |
| 99 | + return -1; |
| 100 | + } |
| 101 | + |
| 102 | + public int getWidth() { |
| 103 | + if( sprites != null && !sprites.isEmpty() ) { |
| 104 | + return sprites.get(0).getWidth(); |
| 105 | + } |
| 106 | + return -1; |
| 107 | + } |
| 108 | +} |
0 commit comments