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) {
writer.writeLn(logLine("SILY",pos,msg), LightGrey);
writer.writeLn(logLine("SILY",pos,msg), LightGray);
#if webconsole
Debug.printWeb(logLine("SILY",pos,msg));
#end

View File

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

View File

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

View File

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

View File

@ -31,12 +31,12 @@ interface TermWriteable {
public function clear():Void;
public function clearLine():Void;
public function getTextColor():Color;
public function setTextColor(colour:Color):Void;
public function setTextColor(color:Color):Void;
public function getBackgroundColor():Color;
public function setBackgroundColor(color:Color):Void;
public function isColor():Bool;
// 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.

View File

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

View File

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

View File

@ -1,111 +1,20 @@
package util;
import haxe.Exception;
import cc.Colors;
enum Color {
White;
Orange;
Magenta;
LightBlue;
Yellow;
Lime;
Pink;
Gray;
Grey;
LightGray;
LightGrey;
Cyan;
Purple;
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");
}
}
enum abstract Color(Int) from cc.Colors.Color to cc.Colors.Color {
var White = 0x1;
var Orange = 0x2;
var Magenta = 0x4;
var LightBlue = 0x8;
var Yellow = 0x10;
var Lime = 0x20;
var Pink = 0x40;
var Gray = 0x80;
var LightGray = 0x100;
var Cyan = 0x200;
var Purple = 0x400;
var Blue = 0x800;
var Brown = 0x1000;
var Green = 0x2000;
var Red = 0x4000;
var Black = 0x8000;
}