Skip to content

Commit dfe1c61

Browse files
Matt JohnsonMatt Johnson
Matt Johnson
authored and
Matt Johnson
committed
CharAttr getters/setters added to prevent bugs when setting colors.
1 parent 97d3425 commit dfe1c61

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

luxe_ascii/CharAttr.hx

+38-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,48 @@ import snow.api.buffers.*;
55

66
class CharAttr {
77
public var char:Int;
8-
public var fg:Color;
9-
public var bg:Uint8Array;
8+
9+
public var fg(get, set):Color;
10+
private var _fg:Color;
11+
12+
public var bg(get, set):Uint8Array;
13+
private var _bg:Uint8Array;
14+
1015
public var attr:Int;
1116

1217
public function new() {
1318
char = 0;
14-
fg = new Color();
15-
bg = new Uint8Array(3);
19+
_fg = new Color();
20+
_bg = new Uint8Array(3);
1621
attr = 0;
1722
}
23+
24+
public inline function get_fg():Color {
25+
return _fg;
26+
}
27+
28+
public inline function set_fg(color:Color):Color {
29+
_fg.r = color.r;
30+
_fg.g = color.g;
31+
_fg.b = color.b;
32+
return _fg;
33+
}
34+
35+
public inline function set_bg_color(color:Color):Uint8Array {
36+
_bg[0] = Std.int(color.r * 255);
37+
_bg[1] = Std.int(color.g * 255);
38+
_bg[2] = Std.int(color.b * 255);
39+
return _bg;
40+
}
41+
42+
public inline function set_bg(color:Uint8Array):Uint8Array {
43+
_bg[0] = color[0];
44+
_bg[1] = color[1];
45+
_bg[2] = color[2];
46+
return _bg;
47+
}
48+
49+
public inline function get_bg():Uint8Array {
50+
return _bg;
51+
}
1852
}

luxe_ascii/TextBuffer.hx

+3-12
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,14 @@ class TextBuffer {
4343
if(x < 0 || y < 0 || x >= width || y >= height)
4444
return;
4545

46-
var c:Color = data[y * width + x].fg;
47-
c.r = color.r;
48-
c.g = color.g;
49-
c.b = color.b;
46+
data[y * width + x].fg = color;
5047
}
5148

5249
public function set_bg_color(x:Int, y:Int, color:Color) {
5350
if(x < 0 || y < 0 || x >= width || y >= height)
5451
return;
5552

56-
var bg = data[y * width + x].bg;
57-
58-
bg[0] = Std.int(color.r * 255);
59-
bg[1] = Std.int(color.g * 255);
60-
bg[2] = Std.int(color.b * 255);
53+
data[y * width + x].set_bg_color(color);
6154
}
6255

6356
// Draw a TextBuffer onto this one at (xPos, yPos), taking into account transparency.
@@ -87,9 +80,7 @@ class TextBuffer {
8780
if(src_data.attr & 0x02 != 0)
8881
continue;
8982

90-
dst_data.fg.r = src_data.fg.r;
91-
dst_data.fg.g = src_data.fg.g;
92-
dst_data.fg.b = src_data.fg.b;
83+
dst_data.fg = src_data.fg;
9384

9485
dst_data.char = src_data.char;
9586
dst_data.bg[0] = src_data.bg[0];

0 commit comments

Comments
 (0)