Commits

Anonymous committed 1d10c49

start of TCODConsole implementation

  • Participants
  • Parent commits b70e045

Comments (0)

Files changed (1)

File src/main/java/net/fishbulb/jcod/Console.java

 package net.fishbulb.jcod;
 
+import com.badlogic.gdx.graphics.Color;
 import lombok.Getter;
 import lombok.Setter;
+import net.fishbulb.jcod.display.Tile;
+import net.fishbulb.jcod.display.Tileset;
 
-/** ==Incompatibilities==
- *
+/**
+ * ==Incompatibilities==
+ * <p/>
  * Methods not supported:
  * <ul>
  * <li>initRoot (create and set root directly)</li>
  * <li></li>
  * <li></li>
  * </ul>
- * */
+ */
 
 public class Console {
 
+    public class Cell {
+        public char c;
+        public int fg;
+        public int bg;
+
+        Tile tile = null;  // generated from above
+
+        public Cell(char c, int fg, int bg) {
+            this.c = c;
+            this.fg = fg;
+            this.bg = bg;
+        }
+
+        public Cell(char c, Color fg, Color bg) {
+            this(c, fg.toIntBits(), bg.toIntBits());
+        }
+
+        public Cell(char c, Color fg) {
+            this(c, fg, defaultBackground);
+        }
+
+        public Cell(char c) {
+            this(c, defaultForeground, defaultBackground);
+        }
+
+        public Cell(Cell that) {
+            this(that.c, that.fg, that.bg);
+        }
+
+        public void setFg(Color c) {
+            fg = c.toIntBits();
+        }
+
+        public void setBg(Color c) {
+            bg = c.toIntBits();
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+
+            Cell cell = (Cell) o;
+
+            if (bg != cell.bg) return false;
+            if (c != cell.c) return false;
+            if (fg != cell.fg) return false;
+
+            return true;
+        }
+
+        @Override
+        public int hashCode() {
+            int result = (int) c;
+            result = 31 * result + fg;
+            result = 31 * result + bg;
+            return result;
+        }
+    }
+
+
     @Getter @Setter
-    private Console root = null;
+    private static Console root = null;
 
+    @Getter @Setter
+    private Tileset tileSet;
+
+    @Getter @Setter
+    private Color defaultBackground = Color.CLEAR;
+
+    @Getter @Setter
+    private Color defaultForeground = Color.WHITE;
+
+    public static void mapAsciiCodeToFont(char asciiCode, int fontCharX, int fontCharY) {
+        if (root != null) root.mapCharToFont(asciiCode, fontCharX, fontCharY);
+    }
+
+    public static void mapAsciiCodesToFont(char firstAsciiCode, int nbCodes, int fontCharX, int fontCharY) {
+        if (root != null) root.mapCharRangeToFont(firstAsciiCode, nbCodes, fontCharX, fontCharY);
+    }
+
+    public static void mapStringToFont(CharSequence s, int fontCharX, int fontCharY) {
+        if (root != null) root.mapCharsToFont(s, fontCharX, fontCharY);
+    }
+
+    // Nonstatic implementations can't have the same name, unfortunately
+    public void mapCharToFont(char asciiCode, int fontCharX, int fontCharY) {
+        if (tileSet == null) return;
+        tileSet.mapChar(asciiCode, tileSet.get(fontCharX, fontCharY));
+    }
+
+    public void mapCharRangeToFont(char firstAsciiCode, int nbCodes, int fontCharX, int fontCharY) {
+        if (tileSet == null) return;
+        for (char c = firstAsciiCode; c < firstAsciiCode + nbCodes; c++) {
+            mapCharToFont(c, fontCharX, fontCharY);
+            fontCharX++;
+            if (fontCharX == tileSet.columns()) {
+                fontCharX = 0;
+                fontCharY++;
+            }
+        }
+    }
+
+    public void mapCharsToFont(CharSequence s, int fontCharX, int fontCharY) {
+        if (tileSet == null) return;
+        for (int i = 0; i < s.length(); i++) {
+            mapCharToFont(s.charAt(i), fontCharX, fontCharY);
+            fontCharX++;
+            if (fontCharX == tileSet.columns()) {
+                fontCharX = 0;
+                fontCharY++;
+            }
+        }
+    }
 
 
 
 }
 
-//static void mapAsciiCodeToFont(int asciiCode, int fontCharX, int fontCharY);
-//static void mapAsciiCodesToFont(int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY);
-//static void mapStringToFont(String s, int fontCharX, int fontCharY);
-//static boolean isFullscreen();
-//static void setFullscreen(boolean fullscreen);
-//static void setWindowTitle(String title);
-//static boolean isWindowClosed();
-//static void credits();
-//static boolean renderCredits(int x, int y, boolean alpha);
-//static void resetCredits();
-//void setDefaultBackground(TCODColor back);
-//void setDefaultForeground(TCODColor fore);
 //void clear();
 //void setCharBackground(int x, int y, const TCODColor &col, TCOD_bkgnd_flag_t flag = TCOD_BKGND_SET);
 //void setCharForeground(int x, int y, const TCODColor &col);
 //TCODConsole(TCOD_console_t con) : data(con) {}
 //static String getColorControlString( TCOD_colctrl_t ctrl );
 //static String getRGBColorControlString( TCOD_colctrl_t ctrl, const TCODColor & col );
+
+
+//static void credits();
+//static boolean renderCredits(int x, int y, boolean alpha);
+//static void resetCredits();