Module AM37

Class PrintableObject

java.lang.Object
it.polimi.ingsw.view.cli.console.graphics.components.PrintableObject

public class PrintableObject
extends java.lang.Object
Allows the use of graphics via ANSI arts, loading the corresponding files from the resources folder
  • Constructor Summary

    Constructors 
    Constructor Description
    PrintableObject​(java.io.InputStream file, int width, int height)
    Loads the object from a text file
  • Method Summary

    Modifier and Type Method Description
    int getHeight()
    height getter
    java.lang.String[][] getObject()  
    int getWidth()
    width getter
    static PrintableObject load​(java.lang.Object caller, java.lang.String filename, int width, int height)  
    static PrintableObject load​(java.lang.String filePath, int width, int height)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PrintableObject

      public PrintableObject​(java.io.InputStream file, int width, int height) throws java.io.IOException
      Loads the object from a text file

      To work properly, each object has to be divided in a String matrix; each element of the matrix contains a printable char and a special sequence (\033), followed by some parameters to color the char; the file must not contain '\' characters other than the ones used for the escape code: when parsing the file, all the backslashes are transcribed as '\003', and the "003" in the file is dumped, because it is not possible to read an escape code; 'm' characters are also forbidden, as they mark that the end of the color sequence. Note that the reset sequence is also stored in the matrix, so the caller has to take this into account.
      In case those conditions are not satisfied, the method will not behave properly, but could end without throwing exceptions: in case the object size is bigger than the provided size, all chars outside the matrix will be ignored; if smaller, the elements of the matrix will be left to null.
      For further information see ANSI colors

      Parameters:
      file - the object file path
      height - the expected matrix height
      width - the expected matrix width
      Throws:
      java.io.IOException - if an I/O error occurs
  • Method Details

    • load

      public static PrintableObject load​(java.lang.Object caller, java.lang.String filename, int width, int height) throws java.io.IOException
      Throws:
      java.io.IOException
    • load

      public static PrintableObject load​(java.lang.String filePath, int width, int height) throws java.io.IOException
      Throws:
      java.io.IOException
    • getWidth

      public int getWidth()
      width getter

      Takes in account the ANSI reset code

      Returns:
      the number of columns in the matrix
    • getHeight

      public int getHeight()
      height getter
      Returns:
      the object height
    • getObject

      public java.lang.String[][] getObject()
      Returns:
      the object, as a string matrix