diff --git a/ansi_parser.cpp b/ansi_parser.cpp index d0443f6..c23479e 100644 --- a/ansi_parser.cpp +++ b/ansi_parser.cpp @@ -10,7 +10,7 @@ using namespace fmt; -#line 115 "ansi_parser.rl" +#line 121 "ansi_parser.rl" @@ -101,7 +101,7 @@ static const int ansi_parser_error = 0; static const int ansi_parser_en_main = 26; -#line 118 "ansi_parser.rl" +#line 124 "ansi_parser.rl" #include @@ -124,7 +124,7 @@ bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_ const wchar_t *eof = pe; sf::Color bgcolor($default_bg); sf::Color color($default_fg); - sf::Color &target = color; + sf::Color* target = &color; #line 122 "ansi_parser.cpp" @@ -132,7 +132,7 @@ bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_ cs = ansi_parser_start; } -#line 143 "ansi_parser.rl" +#line 149 "ansi_parser.rl" #line 125 "ansi_parser.cpp" { @@ -246,13 +246,13 @@ _match: case 3: #line 43 "ansi_parser.rl" { - target = color; + target = &color; } break; case 4: #line 46 "ansi_parser.rl" { - target = bgcolor; + target = &bgcolor; } break; case 5: @@ -263,14 +263,20 @@ _match: break; case 6: #line 54 "ansi_parser.rl" - { color = $default_fg; } + { + color = $default_fg; + color_cb(color, bgcolor); + } break; case 7: -#line 55 "ansi_parser.rl" - { bgcolor = $default_bg; } +#line 58 "ansi_parser.rl" + { + bgcolor = $default_bg; + color_cb(color, bgcolor); + } break; case 8: -#line 56 "ansi_parser.rl" +#line 62 "ansi_parser.rl" { color = $default_bg; bgcolor = $default_fg; @@ -278,7 +284,7 @@ _match: } break; case 9: -#line 61 "ansi_parser.rl" +#line 67 "ansi_parser.rl" { color = $default_fg; bgcolor = $default_bg; @@ -286,40 +292,40 @@ _match: } break; case 10: -#line 66 "ansi_parser.rl" +#line 72 "ansi_parser.rl" { color = sf::Color(100,100,100); color_cb(color, bgcolor); } break; case 11: -#line 70 "ansi_parser.rl" +#line 76 "ansi_parser.rl" { color = sf::Color::Red; color_cb(color, bgcolor); } break; case 12: -#line 75 "ansi_parser.rl" - { target.r = value; } +#line 81 "ansi_parser.rl" + { target->r = value; } break; case 13: -#line 76 "ansi_parser.rl" - { target.g = value; } +#line 82 "ansi_parser.rl" + { target->g = value; } break; case 14: -#line 77 "ansi_parser.rl" - { target.b = value; } +#line 83 "ansi_parser.rl" + { target->b = value; } break; case 15: -#line 78 "ansi_parser.rl" +#line 84 "ansi_parser.rl" { value = 0; } break; case 16: -#line 79 "ansi_parser.rl" +#line 85 "ansi_parser.rl" {} break; -#line 292 "ansi_parser.cpp" +#line 298 "ansi_parser.cpp" } } @@ -336,10 +342,10 @@ _again: while ( __nacts-- > 0 ) { switch ( *__acts++ ) { case 16: -#line 79 "ansi_parser.rl" +#line 85 "ansi_parser.rl" {} break; -#line 310 "ansi_parser.cpp" +#line 316 "ansi_parser.cpp" } } } @@ -347,12 +353,11 @@ _again: _out: {} } -#line 144 "ansi_parser.rl" +#line 150 "ansi_parser.rl" bool good = pe - p == 0; if(!good) { - println("FAIL AT {}", pe - p); p -= 10; // dear cthuhlu, save me from the pain that is wstring for(int i = 0; i < 100; i++) { diff --git a/ansi_parser.rl b/ansi_parser.rl index 595caec..e73b679 100644 --- a/ansi_parser.rl +++ b/ansi_parser.rl @@ -41,18 +41,24 @@ using namespace fmt; color_cb(color, bgcolor); } action is_fg { - target = color; + target = &color; } action is_bg { - target = bgcolor; + target = &bgcolor; } action out { write_cb(fc); } - action reset_fg { color = $default_fg; } - action reset_bg { bgcolor = $default_bg; } + action reset_fg { + color = $default_fg; + color_cb(color, bgcolor); + } + action reset_bg { + bgcolor = $default_bg; + color_cb(color, bgcolor); + } action invert { color = $default_bg; bgcolor = $default_fg; @@ -72,9 +78,9 @@ using namespace fmt; color_cb(color, bgcolor); } - action red { target.r = value; } - action blue { target.g = value; } - action green { target.b = value; } + action red { target->r = value; } + action blue { target->g = value; } + action green { target->b = value; } action start { value = 0; } action end {} action log { println("command {}", (char)fc); } @@ -137,7 +143,7 @@ bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_ const wchar_t *eof = pe; sf::Color bgcolor($default_bg); sf::Color color($default_fg); - sf::Color &target = color; + sf::Color* target = &color; %% write init; %% write exec; @@ -145,7 +151,6 @@ bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_ bool good = pe - p == 0; if(!good) { - println("FAIL AT {}", pe - p); p -= 10; // dear cthuhlu, save me from the pain that is wstring for(int i = 0; i < 100; i++) { diff --git a/assets/config.json b/assets/config.json index e1f0d3f..6328805 100644 --- a/assets/config.json +++ b/assets/config.json @@ -1,8 +1,8 @@ { "map": { - "WALL_TILE": "█", + "WALL_TILE": "\ua5b8", "FLOOR_TILE": "\u2849", - "PLAYER_TILE": "♣", + "PLAYER_TILE": "\ua66b", "ENEMY_TILE": "Ω", "BG_TILE": "█" }, diff --git a/systems.cpp b/systems.cpp index 9b17ba9..9e6116b 100644 --- a/systems.cpp +++ b/systems.cpp @@ -159,27 +159,34 @@ void System::draw_map(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canv // LIGHT: if tile is in light then color ++ otherwise -- // LIGHT: is put into the/a collision map and if a cell is a light's neighbor // it gets brighter. - const int LIGHT_MIN = 30; - const int LIGHT_MAX = 180; + const int LIGHT_MIN = 10; + const int LIGHT_MAX = 110; + int light_strength = 100; // lower is stronger Point light_at{start.x+x, start.y+y}; int dnum = paths[light_at.y][light_at.x]; - int light_value = std::clamp(255 - (dnum * 75), LIGHT_MIN, LIGHT_MAX); + int light_value = std::clamp(255 - (dnum * light_strength), LIGHT_MIN, LIGHT_MAX); + // "WALL_TILE": "\u2591", + // "WALL_TILE": "\ua5b8", if(tile == config.WALL_TILE) { - canvas.DrawText(x * 2, y * 4, tile, Color::HSV(230, 20, 20)); + canvas.DrawText(x * 2, y * 4, config.WALL_TILE, [](auto &pixel) { + pixel.foreground_color = Color::HSV(230, 20, 10); + pixel.background_color = Color::HSV(230, 20, 30); + }); } else if(DEBUG_MAP) { string num = format("{:x}", dnum); num = num.size() > 2 ? "*" : num; - canvas.DrawText(x * 2, y * 4, num, Color::HSV(dnum * 20, 150, light_value)); + canvas.DrawText(x * 2, y * 4, num, [dnum, light_value](auto &pixel) { + pixel.foreground_color = Color::HSV(dnum * 20, 150, 200); + pixel.background_color = Color::HSV(30, 20, light_value / 5); + }); } else { - // floor tile or similar - // BUG: no idea why this works but this actually implements decent light - canvas.DrawText(x * 2, y * 4, tile, [&, light_value](auto &pixel) { - pixel.foreground_color = Color::HSV(30, light_value / 2, light_value); - pixel.background_color = Color::HSV(30, 20, light_value); - }); + canvas.DrawText(x * 2, y * 4, tile, [light_value](auto &pixel) { + pixel.foreground_color = Color::HSV(30, 40, light_value); + pixel.background_color = Color::HSV(30, 20, light_value / 5); + }); } } }