changed how we handle colors

This commit is contained in:
Djeeberjr 2022-03-12 21:48:09 +01:00
parent aee8c0fd3c
commit 35be02dbe2
8 changed files with 37 additions and 128 deletions

View File

@ -60,7 +60,7 @@ class Log {
} }
public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) { public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) {
writer.writeLn(logLine("SILY",pos,msg), LightGrey); writer.writeLn(logLine("SILY",pos,msg), LightGray);
#if webconsole #if webconsole
Debug.printWeb(logLine("SILY",pos,msg)); Debug.printWeb(logLine("SILY",pos,msg));
#end #end

View File

@ -77,19 +77,19 @@ class MainTerm implements TermWriteable {
} }
public function getTextColor():Color { public function getTextColor():Color {
return ColorConvert.ccToColor(Term.getTextColor()); return Term.getTextColor();
} }
public function setTextColor(colour:Color) { public function setTextColor(color:Color) {
Term.setTextColor(ColorConvert.colorToCC(colour)); Term.setTextColor(color);
} }
public function getBackgroundColor():Color { public function getBackgroundColor():Color {
return ColorConvert.ccToColor(Term.getBackgroundColor()); return Term.getBackgroundColor();
} }
public function setBackgroundColor(color:Color) { public function setBackgroundColor(color:Color) {
Term.setBackgroundColor(ColorConvert.colorToCC(color)); Term.setBackgroundColor(color);
} }
public function isColor():Bool { public function isColor():Bool {

View File

@ -90,19 +90,19 @@ class Screen implements TermWriteable implements IPeripheral {
} }
public function getTextColor():Color { public function getTextColor():Color {
return ColorConvert.ccToColor(nativ.getTextColor()); return nativ.getTextColor();
} }
public function setTextColor(colour:Color) { public function setTextColor(color:Color) {
nativ.setTextColor(ColorConvert.colorToCC(colour)); nativ.setTextColor(color);
} }
public function getBackgroundColor():Color { public function getBackgroundColor():Color {
return ColorConvert.ccToColor(nativ.getBackgroundColor()); return nativ.getBackgroundColor();
} }
public function setBackgroundColor(color:Color) { public function setBackgroundColor(color:Color) {
nativ.setBackgroundColor(ColorConvert.colorToCC(color)); nativ.setBackgroundColor(color);
} }
public function isColor():Bool { public function isColor():Bool {

View File

@ -158,8 +158,8 @@ class TermBuffer implements TermWriteable {
return currentTextColor; return currentTextColor;
} }
public function setTextColor(colour:Color) { public function setTextColor(color:Color) {
currentTextColor = colour; currentTextColor = color;
} }
public function getBackgroundColor():Color { public function getBackgroundColor():Color {

View File

@ -31,12 +31,12 @@ interface TermWriteable {
public function clear():Void; public function clear():Void;
public function clearLine():Void; public function clearLine():Void;
public function getTextColor():Color; public function getTextColor():Color;
public function setTextColor(colour:Color):Void; public function setTextColor(color:Color):Void;
public function getBackgroundColor():Color; public function getBackgroundColor():Color;
public function setBackgroundColor(color:Color):Void; public function setBackgroundColor(color:Color):Void;
public function isColor():Bool; public function isColor():Bool;
// public function setPaletteColor(...); // public function setPaletteColor(...);
// public function getPaletteColor(colour); // public function getPaletteColor(color);
/** /**
Clears the screen, resetes the courser to (0,0) and resetes the color to Black and White. Clears the screen, resetes the courser to (0,0) and resetes the color to Black and White.

View File

@ -150,12 +150,12 @@ class VirtualTermWriter implements TermWriteable extends TermBuffer {
return super.getTextColor(); return super.getTextColor();
} }
public override function setTextColor(colour:Color) { public override function setTextColor(color:Color) {
if (isEnabled()) { if (isEnabled()) {
target.setTextColor(colour); target.setTextColor(color);
} }
super.setTextColor(colour); super.setTextColor(color);
} }
public override function getBackgroundColor():Color { public override function getBackgroundColor():Color {

View File

@ -114,8 +114,8 @@ class WindowContext implements TermWriteable {
return writer.getTextColor(); return writer.getTextColor();
} }
public function setTextColor(colour:Color) { public function setTextColor(color:Color) {
writer.setTextColor(colour); writer.setTextColor(color);
} }
public function getBackgroundColor():Color { public function getBackgroundColor():Color {

View File

@ -1,111 +1,20 @@
package util; package util;
import haxe.Exception; enum abstract Color(Int) from cc.Colors.Color to cc.Colors.Color {
import cc.Colors; var White = 0x1;
var Orange = 0x2;
enum Color { var Magenta = 0x4;
White; var LightBlue = 0x8;
Orange; var Yellow = 0x10;
Magenta; var Lime = 0x20;
LightBlue; var Pink = 0x40;
Yellow; var Gray = 0x80;
Lime; var LightGray = 0x100;
Pink; var Cyan = 0x200;
Gray; var Purple = 0x400;
Grey; var Blue = 0x800;
LightGray; var Brown = 0x1000;
LightGrey; var Green = 0x2000;
Cyan; var Red = 0x4000;
Purple; var Black = 0x8000;
Blue;
Brown;
Green;
Red;
Black;
}
class ColorConvert {
public static function colorToCC(color:Color):cc.Colors.Color {
switch color {
case White:
return Colors.white;
case Orange:
return Colors.orange;
case Magenta:
return Colors.magenta;
case LightBlue:
return Colors.lightBlue;
case Yellow:
return Colors.yellow;
case Lime:
return Colors.lime;
case Pink:
return Colors.pink;
case Gray:
return Colors.gray;
case Grey:
return Colors.grey;
case LightGray:
return Colors.lightGray;
case LightGrey:
return Colors.lightGrey;
case Cyan:
return Colors.cyan;
case Purple:
return Colors.purple;
case Blue:
return Colors.blue;
case Brown:
return Colors.brown;
case Green:
return Colors.green;
case Red:
return Colors.red;
case Black:
return Colors.black;
};
}
public static function ccToColor(color:cc.Colors.Color):Color {
switch color {
case 0:
return White;
case 1:
return Orange;
case 2:
return Magenta;
case 3:
return LightBlue;
case 4:
return Yellow;
case 5:
return Lime;
case 6:
return Pink;
case 7:
return Gray;
case 8:
return Grey;
case 9:
return LightGray;
case 10:
return LightGrey;
case 11:
return Cyan;
case 12:
return Purple;
case 13:
return Blue;
case 14:
return Brown;
case 15:
return Green;
case 16:
return Red;
case 17:
return Black;
case _:
throw new Exception("Invalid input");
}
}
} }