001package squidpony.squidgrid.gui.gdx;
002
003import com.badlogic.gdx.graphics.Color;
004
005import java.io.Serializable;
006
007/**
008 * A basic interface for any kind of object that has a symbolic representation and a color, here represented by a char
009 * and a packed float color. This is useful for generic classes that don't force user code to extend a specific class to
010 * be shown in some way.
011 * <br>
012 * Created by Tommy Ettinger on 10/17/2019.
013 */
014public interface ICellVisible {
015    /**
016     * @return a char that can be used to represent this ICellVisible on a grid
017     */
018    char getSymbol();
019
020    /**
021     * @return a packed float color as produced by {@link Color#toFloatBits()} that this ICellVisible will be shown with
022     */
023    float getPackedColor();
024
025    /**
026     * A bare-bones implementation of ICellVisible that always allows its symbol and color to be changed.
027     */
028    class Basic implements ICellVisible, Serializable {
029        private static final long serialVersionUID = 1L;
030        public char symbol;
031        public float packedColor;
032
033        public Basic()
034        {
035            this('.', -0x1.0p125f); // float is equal to SColor.FLOAT_BLACK
036        }
037        public Basic(char symbol, Color color)
038        {
039            this.symbol = symbol;
040            this.packedColor = color.toFloatBits();
041        }
042
043        public Basic(char symbol, float color)
044        {
045            this.symbol = symbol;
046            this.packedColor = color;
047        }
048
049        @Override
050        public char getSymbol() {
051            return symbol;
052        }
053
054        public void setSymbol(char symbol) {
055            this.symbol = symbol;
056        }
057
058        @Override
059        public float getPackedColor() {
060            return packedColor;
061        }
062
063        public void setPackedColor(float packedColor) {
064            this.packedColor = packedColor;
065        }
066    }
067
068    /**
069     * A implementation of ICellVisible that extends {@link ICellVisible.Basic} to also carry a String name.
070     */
071    class Named extends Basic implements ICellVisible, Serializable {
072        private static final long serialVersionUID = 1L;
073        public String name;
074
075        public Named()
076        {
077            this('.', -0x1.0p125f, "floor"); // float is equal to SColor.FLOAT_BLACK
078        }
079        public Named(char symbol, Color color, String name)
080        {
081            super(symbol, color);
082            this.name = name;
083        }
084
085        public Named(char symbol, float color, String name)
086        {
087            super(symbol, color);
088            this.name = name;
089        }
090
091        @Override
092        public char getSymbol() {
093            return symbol;
094        }
095
096        public void setSymbol(char symbol) {
097            this.symbol = symbol;
098        }
099
100        @Override
101        public float getPackedColor() {
102            return packedColor;
103        }
104
105        public void setPackedColor(float packedColor) {
106            this.packedColor = packedColor;
107        }
108
109        public String getName() {
110            return name;
111        }
112
113        public void setName(String name) {
114            this.name = name;
115        }
116    }
117}