Minor fixes to make initializing the terminal more consistent and to remove a magic number for wall limits.
This commit is contained in:
parent
2d5490131d
commit
ae43dad499
12 changed files with 47 additions and 42 deletions
|
@ -109,10 +109,6 @@ ANSIParser::ANSIParser(sf::Color default_fg, sf::Color default_bg) :
|
||||||
$default_fg(default_fg),
|
$default_fg(default_fg),
|
||||||
$default_bg(default_bg)
|
$default_bg(default_bg)
|
||||||
{
|
{
|
||||||
// the parser only handles full color so force it
|
|
||||||
if(ftxui::Terminal::ColorSupport() != ftxui::Terminal::Color::TrueColor) {
|
|
||||||
ftxui::Terminal::SetColorSupport(ftxui::Terminal::Color::TrueColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_cb) {
|
bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_cb) {
|
||||||
|
@ -127,14 +123,14 @@ bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_
|
||||||
sf::Color* target = &color;
|
sf::Color* target = &color;
|
||||||
|
|
||||||
|
|
||||||
#line 122 "ansi_parser.cpp"
|
#line 118 "ansi_parser.cpp"
|
||||||
{
|
{
|
||||||
cs = ansi_parser_start;
|
cs = ansi_parser_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 149 "ansi_parser.rl"
|
#line 145 "ansi_parser.rl"
|
||||||
|
|
||||||
#line 125 "ansi_parser.cpp"
|
#line 121 "ansi_parser.cpp"
|
||||||
{
|
{
|
||||||
int _klen;
|
int _klen;
|
||||||
unsigned int _trans;
|
unsigned int _trans;
|
||||||
|
@ -325,7 +321,7 @@ _match:
|
||||||
#line 85 "ansi_parser.rl"
|
#line 85 "ansi_parser.rl"
|
||||||
{}
|
{}
|
||||||
break;
|
break;
|
||||||
#line 298 "ansi_parser.cpp"
|
#line 294 "ansi_parser.cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,7 +341,7 @@ _again:
|
||||||
#line 85 "ansi_parser.rl"
|
#line 85 "ansi_parser.rl"
|
||||||
{}
|
{}
|
||||||
break;
|
break;
|
||||||
#line 316 "ansi_parser.cpp"
|
#line 312 "ansi_parser.cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,7 +349,7 @@ _again:
|
||||||
_out: {}
|
_out: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 150 "ansi_parser.rl"
|
#line 146 "ansi_parser.rl"
|
||||||
|
|
||||||
bool good = pe - p == 0;
|
bool good = pe - p == 0;
|
||||||
|
|
||||||
|
|
|
@ -128,10 +128,6 @@ ANSIParser::ANSIParser(sf::Color default_fg, sf::Color default_bg) :
|
||||||
$default_fg(default_fg),
|
$default_fg(default_fg),
|
||||||
$default_bg(default_bg)
|
$default_bg(default_bg)
|
||||||
{
|
{
|
||||||
// the parser only handles full color so force it
|
|
||||||
if(ftxui::Terminal::ColorSupport() != ftxui::Terminal::Color::TrueColor) {
|
|
||||||
ftxui::Terminal::SetColorSupport(ftxui::Terminal::Color::TrueColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_cb) {
|
bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_cb) {
|
||||||
|
|
2
gui.cpp
2
gui.cpp
|
@ -63,7 +63,7 @@ void GUI::save_world() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::create_renderer() {
|
void GUI::create_renderer() {
|
||||||
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
$renderer.init_terminal();
|
||||||
auto player = $world.get_the<Player>();
|
auto player = $world.get_the<Player>();
|
||||||
|
|
||||||
$map_view.set_renderer(Renderer([&] {
|
$map_view.set_renderer(Renderer([&] {
|
||||||
|
|
7
main.cpp
7
main.cpp
|
@ -13,10 +13,6 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#if defined(_WIN64) || defined(_WIN32)
|
|
||||||
#include <io.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace ftxui;
|
using namespace ftxui;
|
||||||
using namespace components;
|
using namespace components;
|
||||||
using lighting::LightSource;
|
using lighting::LightSource;
|
||||||
|
@ -68,9 +64,6 @@ const int GAME_MAP_X = 40;
|
||||||
const int GAME_MAP_Y = 40;
|
const int GAME_MAP_Y = 40;
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
#if defined(_WIN64) || defined(_WIN32)
|
|
||||||
_setmode(_fileno(stdout), _O_U16TEXT);
|
|
||||||
#endif
|
|
||||||
DinkyECS::World world;
|
DinkyECS::World world;
|
||||||
Map game_map(GAME_MAP_X, GAME_MAP_Y);
|
Map game_map(GAME_MAP_X, GAME_MAP_Y);
|
||||||
save::load_configs(world);
|
save::load_configs(world);
|
||||||
|
|
6
map.cpp
6
map.cpp
|
@ -17,7 +17,7 @@ void dump_map(const std::string &msg, Matrix &map, int show_x, int show_y) {
|
||||||
|
|
||||||
if(int(x) == show_x && int(y) == show_y) {
|
if(int(x) == show_x && int(y) == show_y) {
|
||||||
print("{:x}<", col);
|
print("{:x}<", col);
|
||||||
} else if(col == 1000) {
|
} else if(col == WALL_PATH_LIMIT) {
|
||||||
print("# ");
|
print("# ");
|
||||||
} else if(col > 15) {
|
} else if(col > 15) {
|
||||||
print("* ");
|
print("* ");
|
||||||
|
@ -30,11 +30,11 @@ void dump_map(const std::string &msg, Matrix &map, int show_x, int show_y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Map::Map(size_t width, size_t height) :
|
Map::Map(size_t width, size_t height) :
|
||||||
$limit(1000),
|
$limit(WALL_PATH_LIMIT),
|
||||||
$width(width),
|
$width(width),
|
||||||
$height(height),
|
$height(height),
|
||||||
$walls(height, MatrixRow(width, INV_WALL)),
|
$walls(height, MatrixRow(width, INV_WALL)),
|
||||||
$paths(height, width, 1000)
|
$paths(height, width, WALL_PATH_LIMIT)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Map::Map(Matrix &walls, Pathing &paths, int limit) :
|
Map::Map(Matrix &walls, Pathing &paths, int limit) :
|
||||||
|
|
9
map.hpp
9
map.hpp
|
@ -11,10 +11,11 @@
|
||||||
#include "pathing.hpp"
|
#include "pathing.hpp"
|
||||||
#include "matrix.hpp"
|
#include "matrix.hpp"
|
||||||
|
|
||||||
#define INV_WALL 0
|
const int INV_WALL = 0;
|
||||||
#define INV_SPACE 1
|
const int INV_SPACE = 1;
|
||||||
#define WALL_VALUE 1
|
const int WALL_VALUE = 1;
|
||||||
#define SPACE_VALUE 0
|
const int SPACE_VALUE = 0;
|
||||||
|
const int WALL_PATH_LIMIT = 1000;
|
||||||
|
|
||||||
using lighting::LightSource;
|
using lighting::LightSource;
|
||||||
|
|
||||||
|
|
15
render.cpp
15
render.cpp
|
@ -6,6 +6,12 @@
|
||||||
#include "map.hpp"
|
#include "map.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "color.hpp"
|
#include "color.hpp"
|
||||||
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <io.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
|
|
||||||
|
@ -220,3 +226,12 @@ void SFMLRender::draw(Panel &panel, float x_offset, float y_offset) {
|
||||||
render_text(panelout, panel.default_fg, panel.default_bg, panel.x + x_offset, panel.y + y_offset);
|
render_text(panelout, panel.default_fg, panel.default_bg, panel.x + x_offset, panel.y + y_offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SFMLRender::init_terminal() {
|
||||||
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
|
_setmode(_fileno(stdout), _O_U16TEXT);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// the parser only handles full color so force it
|
||||||
|
ftxui::Terminal::SetColorSupport(ftxui::Terminal::Color::TrueColor);
|
||||||
|
}
|
||||||
|
|
|
@ -67,4 +67,5 @@ struct SFMLRender {
|
||||||
int font_size() { return $map_font_size; }
|
int font_size() { return $map_font_size; }
|
||||||
void clear() { $window.clear(); }
|
void clear() { $window.clear(); }
|
||||||
void display() { $window.display(); }
|
void display() { $window.display(); }
|
||||||
|
static void init_terminal();
|
||||||
};
|
};
|
||||||
|
|
12
status.txt
12
status.txt
|
@ -1,16 +1,14 @@
|
||||||
TODAY'S GOAL:
|
TODAY'S GOAL:
|
||||||
* Neighbors needs a rewrite
|
|
||||||
* Neighbors algo isn't using greater parameter
|
|
||||||
* Clean up and document as much code as possible.
|
|
||||||
* Add a method to render.cpp that sets terminal true color.
|
|
||||||
* limit as 1000 should be a constant
|
|
||||||
* Big Code Review
|
* Big Code Review
|
||||||
|
* Clean up and document as much code as possible.
|
||||||
|
* color namespace is too ambiguous
|
||||||
|
|
||||||
|
* Lua integration
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
* I can do headless windows in renderer for testing.
|
* I can do headless windows in renderer for testing.
|
||||||
- renderer.$window.setVisible(false);
|
- renderer.$window.setVisible(false);
|
||||||
* Think up an enemy system.
|
* Think up an enemy system.
|
||||||
* Revisit map generation.
|
|
||||||
* Write a method for renderer that can translate coordinates.
|
* Write a method for renderer that can translate coordinates.
|
||||||
* Can std::any be defaulted to a noop in the events?
|
* Can std::any be defaulted to a noop in the events?
|
||||||
* Save file isn't saving gold.
|
* Save file isn't saving gold.
|
||||||
|
@ -19,9 +17,7 @@ TODO:
|
||||||
* Devise a more complete map/world generator that can use the loot and enemies better.
|
* Devise a more complete map/world generator that can use the loot and enemies better.
|
||||||
* Maybe an LOS system, but the hearing version works pretty well so far.
|
* Maybe an LOS system, but the hearing version works pretty well so far.
|
||||||
* Probably a system for mapping collision types to sound effects, rather than having the GUI do it.
|
* Probably a system for mapping collision types to sound effects, rather than having the GUI do it.
|
||||||
|
|
||||||
* Write a test that generates a ton of maps then confirms there's a path from one room to every other room?
|
* Write a test that generates a ton of maps then confirms there's a path from one room to every other room?
|
||||||
* Lua integration
|
|
||||||
|
|
||||||
* check out SoLoud.
|
* check out SoLoud.
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,16 @@
|
||||||
#include "ftxui/screen/color.hpp" // for Color, Color::Black, Color::Blue, Color::BlueLight, Color::Cyan, Color::CyanLight, Color::Default, Color::GrayDark, Color::GrayLight, Color::Green, Color::GreenLight, Color::Magenta, Color::MagentaLight, Color::Red, Color::RedLight, Color::White, Color::Yellow, Color::YellowLight, Color::Palette256, ftxui
|
#include "ftxui/screen/color.hpp" // for Color, Color::Black, Color::Blue, Color::BlueLight, Color::Cyan, Color::CyanLight, Color::Default, Color::GrayDark, Color::GrayLight, Color::Green, Color::GreenLight, Color::Magenta, Color::MagentaLight, Color::Red, Color::RedLight, Color::White, Color::Yellow, Color::YellowLight, Color::Palette256, ftxui
|
||||||
#include <ftxui/screen/color_info.hpp> // for ColorInfo
|
#include <ftxui/screen/color_info.hpp> // for ColorInfo
|
||||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||||
|
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||||
#include <ftxui/screen/terminal.hpp> // for ColorSupport, Color, Palette16, Palette256, TrueColor
|
#include <ftxui/screen/terminal.hpp> // for ColorSupport, Color, Palette16, Palette256, TrueColor
|
||||||
|
#include "render.hpp"
|
||||||
|
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
using namespace ftxui;
|
using namespace ftxui;
|
||||||
|
|
||||||
std::string generate_colors() {
|
std::string generate_colors() {
|
||||||
|
SFMLRender::init_terminal();
|
||||||
|
|
||||||
REQUIRE(ftxui::Terminal::ColorSupport() == ftxui::Terminal::Color::TrueColor);
|
REQUIRE(ftxui::Terminal::ColorSupport() == ftxui::Terminal::Color::TrueColor);
|
||||||
|
|
||||||
const int max_value = 255;
|
const int max_value = 255;
|
||||||
|
@ -30,8 +34,8 @@ std::string generate_colors() {
|
||||||
for (int hue = 0; hue < max_value; hue += hue_increment) {
|
for (int hue = 0; hue < max_value; hue += hue_increment) {
|
||||||
line.push_back(
|
line.push_back(
|
||||||
text("#") //
|
text("#") //
|
||||||
| color(Color::HSV(hue, saturation, value)) //
|
| ftxui::color(Color::HSV(hue, saturation, value)) //
|
||||||
| bgcolor(Color::HSV(hue, saturation, value + value_increment)));
|
| ftxui::bgcolor(Color::HSV(hue, saturation, value + value_increment)));
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
array.push_back(hbox(std::move(line)));
|
array.push_back(hbox(std::move(line)));
|
||||||
|
@ -51,6 +55,7 @@ std::string generate_colors() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("test out ragel parser", "[gui]") {
|
TEST_CASE("test out ragel parser", "[gui]") {
|
||||||
|
SFMLRender::init_terminal();
|
||||||
sf::Color default_fg(0,0,0);
|
sf::Color default_fg(0,0,0);
|
||||||
sf::Color default_bg(100,100,100);
|
sf::Color default_bg(100,100,100);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <ftxui/dom/elements.hpp> // for hflow, paragraph, separator, hbox, vbox, filler, operator|, border, Element
|
#include <ftxui/dom/elements.hpp> // for hflow, paragraph, separator, hbox, vbox, filler, operator|, border, Element
|
||||||
#include "panel.hpp"
|
#include "panel.hpp"
|
||||||
#include "ansi_parser.hpp"
|
#include "ansi_parser.hpp"
|
||||||
|
#include "render.hpp"
|
||||||
|
|
||||||
using namespace ftxui;
|
using namespace ftxui;
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
|
@ -27,8 +28,7 @@ void test_ansi_parsing(Panel &panel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("can render a simple text panel", "[panel]") {
|
TEST_CASE("can render a simple text panel", "[panel]") {
|
||||||
ftxui::Terminal::SetColorSupport(ftxui::Terminal::Color::TrueColor);
|
SFMLRender::init_terminal();
|
||||||
|
|
||||||
Panel text_panel(0, 0, 20, 5);
|
Panel text_panel(0, 0, 20, 5);
|
||||||
|
|
||||||
bool show_modal = false;
|
bool show_modal = false;
|
||||||
|
@ -59,7 +59,7 @@ TEST_CASE("can render a simple text panel", "[panel]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("can render a simple grid panel", "[panel]") {
|
TEST_CASE("can render a simple grid panel", "[panel]") {
|
||||||
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
SFMLRender::init_terminal();
|
||||||
|
|
||||||
Panel grid_panel(20, 20, 20, 5, true);
|
Panel grid_panel(20, 20, 20, 5, true);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ void run_renderer(SFMLRender &renderer, Panel &panel) {
|
||||||
|
|
||||||
TEST_CASE("can render a text panel", "[render]") {
|
TEST_CASE("can render a text panel", "[render]") {
|
||||||
SFMLRender renderer;
|
SFMLRender renderer;
|
||||||
|
renderer.init_terminal();
|
||||||
|
|
||||||
Panel panel(0, 0, 20, 5);
|
Panel panel(0, 0, 20, 5);
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ TEST_CASE("can render a text panel", "[render]") {
|
||||||
|
|
||||||
TEST_CASE("can render a text", "[render]") {
|
TEST_CASE("can render a text", "[render]") {
|
||||||
SFMLRender renderer;
|
SFMLRender renderer;
|
||||||
|
renderer.init_terminal();
|
||||||
DinkyECS::World world;
|
DinkyECS::World world;
|
||||||
|
|
||||||
save::load_configs(world);
|
save::load_configs(world);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue