LEL is working at a basic grid level, able to render boxes where I want.
This commit is contained in:
parent
846b7aaf16
commit
872cedc8e1
8 changed files with 127 additions and 99 deletions
|
@ -4,11 +4,31 @@
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
CombatUI::CombatUI(GameLevel level) :
|
CombatUI::CombatUI(GameLevel level) :
|
||||||
|
$layout(RAY_VIEW_X, RAY_VIEW_HEIGHT,
|
||||||
|
RAY_VIEW_WIDTH, SCREEN_HEIGHT - RAY_VIEW_HEIGHT),
|
||||||
$level(level)
|
$level(level)
|
||||||
{
|
{
|
||||||
|
bool good = $layout.parse(
|
||||||
|
"[attack1 | attack2 | attack3 | heal]"
|
||||||
|
"[move1 | move2 | move3 | move4]"
|
||||||
|
);
|
||||||
|
|
||||||
|
dbc::check(good, "failed to parse combat layout");
|
||||||
|
|
||||||
|
for(auto& [name, cell] : $layout.cells) {
|
||||||
|
sf::RectangleShape button;
|
||||||
|
button.setPosition({float(cell.x + 10), float(cell.y + 10)});
|
||||||
|
button.setSize({float(cell.w - 20), float(cell.h - 20)});
|
||||||
|
button.setFillColor({uint8_t(cell.col * 75), 100, 100});
|
||||||
|
button.setOutlineColor({200, 200, 200});
|
||||||
|
button.setOutlineThickness(5);
|
||||||
|
$shapes[name] = button;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatUI::draw(sf::RenderWindow& window) {
|
void CombatUI::draw(sf::RenderWindow& window) {
|
||||||
(void)window;
|
for(auto& [name, shape] : $shapes) {
|
||||||
|
window.draw(shape);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,15 @@
|
||||||
#include "panel.hpp"
|
#include "panel.hpp"
|
||||||
#include "levelmanager.hpp"
|
#include "levelmanager.hpp"
|
||||||
#include <SFML/Graphics/RenderWindow.hpp>
|
#include <SFML/Graphics/RenderWindow.hpp>
|
||||||
|
#include <SFML/Graphics/RectangleShape.hpp>
|
||||||
|
#include "lel.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class CombatUI {
|
class CombatUI {
|
||||||
public:
|
public:
|
||||||
|
LELParser $layout;
|
||||||
GameLevel $level;
|
GameLevel $level;
|
||||||
|
std::unordered_map<std::string, sf::RectangleShape> $shapes;
|
||||||
CombatUI(GameLevel level);
|
CombatUI(GameLevel level);
|
||||||
|
|
||||||
void draw(sf::RenderWindow& window);
|
void draw(sf::RenderWindow& window);
|
||||||
|
|
5
gui.cpp
5
gui.cpp
|
@ -316,11 +316,6 @@ namespace gui {
|
||||||
left_gui->setPosition({0,0});
|
left_gui->setPosition({0,0});
|
||||||
$window.draw(*left_gui);
|
$window.draw(*left_gui);
|
||||||
|
|
||||||
sf::RectangleShape lower({RAY_VIEW_WIDTH, SCREEN_HEIGHT - RAY_VIEW_HEIGHT});
|
|
||||||
lower.setPosition({RAY_VIEW_X,RAY_VIEW_HEIGHT});
|
|
||||||
lower.setFillColor({30, 30, 30});
|
|
||||||
$window.draw(lower);
|
|
||||||
|
|
||||||
$status_view.render();
|
$status_view.render();
|
||||||
$renderer.draw($status_view);
|
$renderer.draw($status_view);
|
||||||
|
|
||||||
|
|
54
lel.cpp
54
lel.cpp
|
@ -1,6 +1,6 @@
|
||||||
#include "lel.hpp"
|
#include "lel.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
#include "dbc.hpp"
|
||||||
#include "lel_parser.cpp"
|
#include "lel_parser.cpp"
|
||||||
|
|
||||||
LELParser::LELParser(int x, int y, int width, int height) :
|
LELParser::LELParser(int x, int y, int width, int height) :
|
||||||
|
@ -10,12 +10,10 @@ LELParser::LELParser(int x, int y, int width, int height) :
|
||||||
grid_h(height),
|
grid_h(height),
|
||||||
cur(0, 0)
|
cur(0, 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LELParser::ltab() {
|
void LELParser::ltab() {
|
||||||
cur.row = row_count;
|
cur.row = rows;
|
||||||
fmt::println("ltab: rows {}", row_count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LELParser::col() {
|
void LELParser::col() {
|
||||||
|
@ -23,60 +21,62 @@ void LELParser::col() {
|
||||||
|
|
||||||
void LELParser::valign(char dir) {
|
void LELParser::valign(char dir) {
|
||||||
cur.top = dir == '^';
|
cur.top = dir == '^';
|
||||||
fmt::println("valign: {}", dir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LELParser::align(char dir) {
|
void LELParser::align(char dir) {
|
||||||
cur.left = dir == '<';
|
cur.left = dir == '<';
|
||||||
fmt::println("align {}", dir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LELParser::id(std::string name) {
|
void LELParser::id(std::string name) {
|
||||||
fmt::println("id: {}", name);
|
dbc::check(!cells.contains(name),
|
||||||
|
fmt::format("duplicate cell name {}", name));
|
||||||
|
|
||||||
cells.insert_or_assign(name, cur);
|
cells.insert_or_assign(name, cur);
|
||||||
cur = {cur.col + 1, cur.row};
|
cur = {cur.col + 1, cur.row};
|
||||||
}
|
}
|
||||||
|
|
||||||
void LELParser::row() {
|
void LELParser::row() {
|
||||||
row_count++;
|
rows++;
|
||||||
max_columns = std::max(max_columns, cur.col);
|
columns = std::max(columns, cur.col);
|
||||||
cur.col = 0;
|
cur.col = 0;
|
||||||
fmt::println("row end: cols {}", cur.col);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LELParser::setwidth(int width) {
|
void LELParser::setwidth(int width) {
|
||||||
fmt::println("setwidth: {}", width);
|
cur.max_w = width;
|
||||||
cur.w = width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LELParser::setheight(int height) {
|
void LELParser::setheight(int height) {
|
||||||
fmt::println("setheight: {}", height);
|
cur.max_h = height;
|
||||||
cur.h = height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LELParser::expand() {
|
void LELParser::expand() {
|
||||||
fmt::println("expand");
|
|
||||||
cur.expand = true;
|
cur.expand = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LELParser::finalize() {
|
void LELParser::finalize() {
|
||||||
int cell_width = grid_w / max_columns;
|
dbc::check(columns > 0, "columns are 0");
|
||||||
int cell_height = grid_h / row_count;
|
dbc::check(rows > 0, "rows are 0");
|
||||||
fmt::println("FINALIZE: cell w/h: {},{}", cell_width, cell_height);
|
int cell_width = grid_w / columns;
|
||||||
|
int cell_height = grid_h / rows;
|
||||||
|
dbc::check(cell_width > 0, "invalid cell width calc");
|
||||||
|
dbc::check(cell_height > 0, "invalid cell height calc");
|
||||||
|
|
||||||
for(auto [name, cell] : cells) {
|
for(auto& [name, cell] : cells) {
|
||||||
cell.x = cell.col * cell_width;
|
cell.x = grid_x + (cell.col * cell_width);
|
||||||
cell.y = cell.row * cell_height;
|
cell.y = grid_y + (cell.row * cell_height);
|
||||||
if(cell.w == 0) cell.w = cell_width;
|
cell.max_w = cell.max_w == 0 ? cell_width : cell.max_w;
|
||||||
if(cell.x == 0) cell.h = cell_height;
|
cell.max_h = cell.max_h == 0 ? cell_height : cell.max_h;
|
||||||
|
|
||||||
fmt::println("name={}; col/row={},{}; x/y={},{} w/h={},{}; left={}, top={}, expand={}",
|
cell.w = cell.expand ? cell.max_w : std::min(cell_width, cell.max_w);
|
||||||
name, cell.col, cell.row, cell.x, cell.y, cell.w, cell.h, cell.left, cell.top, cell.expand);
|
cell.h = cell.expand ? cell.max_h : std::min(cell_height, cell.max_h);
|
||||||
|
|
||||||
|
dbc::check(cell.h > 0, fmt::format("invalid height cell {}", name));
|
||||||
|
dbc::check(cell.w > 0, fmt::format("invalid width cell {}", name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LELParser::reset() {
|
void LELParser::reset() {
|
||||||
row_count = 0;
|
rows = 0;
|
||||||
max_columns = 0;
|
columns = 0;
|
||||||
cur = {0, 0};
|
cur = {0, 0};
|
||||||
}
|
}
|
||||||
|
|
6
lel.hpp
6
lel.hpp
|
@ -7,6 +7,8 @@ struct Cell {
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int w = 0;
|
int w = 0;
|
||||||
int h = 0;
|
int h = 0;
|
||||||
|
int max_w = 0;
|
||||||
|
int max_h = 0;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
int row = 0;
|
int row = 0;
|
||||||
bool left = true;
|
bool left = true;
|
||||||
|
@ -21,8 +23,8 @@ struct LELParser {
|
||||||
int grid_y = 0;
|
int grid_y = 0;
|
||||||
int grid_w = 0;
|
int grid_w = 0;
|
||||||
int grid_h = 0;
|
int grid_h = 0;
|
||||||
int row_count = 0;
|
int rows = 0;
|
||||||
int max_columns = 0;
|
int columns = 0;
|
||||||
Cell cur;
|
Cell cur;
|
||||||
std::unordered_map<std::string, Cell> cells;
|
std::unordered_map<std::string, Cell> cells;
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
#line 1 "lel_parser.rl"
|
#line 1 "lel_parser.rl"
|
||||||
#include "lel.hpp"
|
#include "lel.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
#line 33 "lel_parser.rl"
|
#line 34 "lel_parser.rl"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#line 7 "lel_parser.cpp"
|
#line 8 "lel_parser.cpp"
|
||||||
static const char _LELParser_actions[] = {
|
static const char _LELParser_actions[] = {
|
||||||
0, 1, 1, 1, 2, 1, 3, 1,
|
0, 1, 1, 1, 2, 1, 3, 1,
|
||||||
4, 1, 5, 1, 6, 1, 9, 1,
|
4, 1, 5, 1, 6, 1, 9, 1,
|
||||||
|
@ -18,8 +19,7 @@ static const char _LELParser_actions[] = {
|
||||||
|
|
||||||
static const char _LELParser_key_offsets[] = {
|
static const char _LELParser_key_offsets[] = {
|
||||||
0, 0, 4, 18, 20, 24, 35, 47,
|
0, 0, 4, 18, 20, 24, 35, 47,
|
||||||
52, 66, 68, 72, 83, 95, 99, 101,
|
52, 54, 57
|
||||||
104, 106, 109
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char _LELParser_trans_keys[] = {
|
static const char _LELParser_trans_keys[] = {
|
||||||
|
@ -29,33 +29,23 @@ static const char _LELParser_trans_keys[] = {
|
||||||
40, 42, 46, 60, 62, 94, 95, 65,
|
40, 42, 46, 60, 62, 94, 95, 65,
|
||||||
90, 97, 122, 32, 93, 95, 124, 9,
|
90, 97, 122, 32, 93, 95, 124, 9,
|
||||||
13, 48, 57, 65, 90, 97, 122, 32,
|
13, 48, 57, 65, 90, 97, 122, 32,
|
||||||
93, 124, 9, 13, 32, 40, 42, 46,
|
93, 124, 9, 13, 48, 57, 41, 48,
|
||||||
60, 62, 94, 95, 9, 13, 65, 90,
|
57, 32, 91, 9, 13, 0
|
||||||
97, 122, 48, 57, 41, 44, 48, 57,
|
|
||||||
40, 42, 46, 60, 62, 94, 95, 65,
|
|
||||||
90, 97, 122, 32, 93, 95, 124, 9,
|
|
||||||
13, 48, 57, 65, 90, 97, 122, 32,
|
|
||||||
93, 9, 13, 48, 57, 41, 48, 57,
|
|
||||||
48, 57, 41, 48, 57, 32, 91, 9,
|
|
||||||
13, 0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char _LELParser_single_lengths[] = {
|
static const char _LELParser_single_lengths[] = {
|
||||||
0, 2, 8, 0, 2, 7, 4, 3,
|
0, 2, 8, 0, 2, 7, 4, 3,
|
||||||
8, 0, 2, 7, 4, 2, 0, 1,
|
|
||||||
0, 1, 2
|
0, 1, 2
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char _LELParser_range_lengths[] = {
|
static const char _LELParser_range_lengths[] = {
|
||||||
0, 1, 3, 1, 1, 2, 4, 1,
|
0, 1, 3, 1, 1, 2, 4, 1,
|
||||||
3, 1, 1, 2, 4, 1, 1, 1,
|
|
||||||
1, 1, 1
|
1, 1, 1
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char _LELParser_index_offsets[] = {
|
static const char _LELParser_index_offsets[] = {
|
||||||
0, 0, 4, 16, 18, 22, 32, 41,
|
0, 0, 4, 16, 18, 22, 32, 41,
|
||||||
46, 58, 60, 64, 74, 83, 87, 89,
|
46, 48, 51
|
||||||
92, 94, 97
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char _LELParser_indicies[] = {
|
static const char _LELParser_indicies[] = {
|
||||||
|
@ -64,40 +54,30 @@ static const char _LELParser_indicies[] = {
|
||||||
9, 1, 10, 11, 12, 1, 4, 5,
|
9, 1, 10, 11, 12, 1, 4, 5,
|
||||||
6, 7, 7, 6, 8, 8, 8, 1,
|
6, 7, 7, 6, 8, 8, 8, 1,
|
||||||
13, 15, 14, 16, 13, 14, 14, 14,
|
13, 15, 14, 16, 13, 14, 14, 14,
|
||||||
1, 17, 18, 19, 17, 1, 20, 21,
|
1, 17, 18, 19, 17, 1, 20, 1,
|
||||||
22, 23, 24, 24, 23, 25, 20, 25,
|
21, 22, 1, 23, 2, 23, 1, 0
|
||||||
25, 1, 26, 1, 27, 28, 29, 1,
|
|
||||||
21, 22, 23, 24, 24, 23, 25, 25,
|
|
||||||
25, 1, 30, 15, 31, 16, 30, 31,
|
|
||||||
31, 31, 1, 32, 18, 32, 1, 33,
|
|
||||||
1, 34, 35, 1, 36, 1, 37, 38,
|
|
||||||
1, 39, 2, 39, 1, 0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char _LELParser_trans_targs[] = {
|
static const char _LELParser_trans_targs[] = {
|
||||||
1, 0, 2, 2, 3, 5, 5, 5,
|
1, 0, 2, 2, 3, 5, 5, 5,
|
||||||
6, 4, 5, 16, 4, 7, 6, 18,
|
6, 4, 5, 8, 4, 7, 6, 10,
|
||||||
8, 7, 18, 8, 8, 9, 11, 11,
|
2, 7, 10, 2, 9, 5, 9, 10
|
||||||
11, 12, 10, 11, 14, 10, 13, 12,
|
|
||||||
13, 15, 11, 15, 17, 5, 17, 18
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char _LELParser_trans_actions[] = {
|
static const char _LELParser_trans_actions[] = {
|
||||||
0, 0, 3, 0, 0, 13, 5, 11,
|
0, 0, 3, 0, 0, 13, 5, 11,
|
||||||
17, 15, 19, 19, 0, 7, 0, 28,
|
17, 15, 19, 19, 0, 7, 0, 28,
|
||||||
25, 0, 9, 1, 0, 0, 13, 5,
|
25, 0, 9, 1, 15, 22, 0, 0
|
||||||
11, 17, 15, 19, 19, 0, 7, 0,
|
|
||||||
0, 15, 22, 0, 15, 22, 0, 0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int LELParser_start = 1;
|
static const int LELParser_start = 1;
|
||||||
static const int LELParser_first_final = 18;
|
static const int LELParser_first_final = 10;
|
||||||
static const int LELParser_error = 0;
|
static const int LELParser_error = 0;
|
||||||
|
|
||||||
static const int LELParser_en_main = 1;
|
static const int LELParser_en_main = 1;
|
||||||
|
|
||||||
|
|
||||||
#line 36 "lel_parser.rl"
|
#line 37 "lel_parser.rl"
|
||||||
|
|
||||||
bool LELParser::parse(std::string input) {
|
bool LELParser::parse(std::string input) {
|
||||||
reset();
|
reset();
|
||||||
|
@ -109,14 +89,14 @@ bool LELParser::parse(std::string input) {
|
||||||
std::string tk;
|
std::string tk;
|
||||||
|
|
||||||
|
|
||||||
#line 104 "lel_parser.cpp"
|
#line 84 "lel_parser.cpp"
|
||||||
{
|
{
|
||||||
cs = LELParser_start;
|
cs = LELParser_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 47 "lel_parser.rl"
|
#line 48 "lel_parser.rl"
|
||||||
|
|
||||||
#line 107 "lel_parser.cpp"
|
#line 87 "lel_parser.cpp"
|
||||||
{
|
{
|
||||||
int _klen;
|
int _klen;
|
||||||
unsigned int _trans;
|
unsigned int _trans;
|
||||||
|
@ -191,54 +171,54 @@ _match:
|
||||||
switch ( *_acts++ )
|
switch ( *_acts++ )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
#line 8 "lel_parser.rl"
|
#line 9 "lel_parser.rl"
|
||||||
{tk = input.substr(start - begin, p - start); }
|
{tk = input.substr(start - begin, p - start); }
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
#line 10 "lel_parser.rl"
|
#line 11 "lel_parser.rl"
|
||||||
{ col(); }
|
{ col(); }
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
#line 11 "lel_parser.rl"
|
#line 12 "lel_parser.rl"
|
||||||
{ ltab(); }
|
{ ltab(); }
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
#line 12 "lel_parser.rl"
|
#line 13 "lel_parser.rl"
|
||||||
{ valign((*p)); }
|
{ valign((*p)); }
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
#line 13 "lel_parser.rl"
|
#line 14 "lel_parser.rl"
|
||||||
{ id(input.substr(start - begin, p - start)); }
|
{ id(input.substr(start - begin, p - start)); }
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
#line 14 "lel_parser.rl"
|
#line 15 "lel_parser.rl"
|
||||||
{ row(); }
|
{ row(); }
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
#line 15 "lel_parser.rl"
|
#line 16 "lel_parser.rl"
|
||||||
{ align((*p)); }
|
{ align((*p)); }
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
#line 16 "lel_parser.rl"
|
#line 17 "lel_parser.rl"
|
||||||
{ setwidth(std::stoi(tk)); }
|
{ setwidth(std::stoi(tk)); }
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
#line 17 "lel_parser.rl"
|
#line 18 "lel_parser.rl"
|
||||||
{ setheight(std::stoi(tk)); }
|
{ setheight(std::stoi(tk)); }
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
#line 18 "lel_parser.rl"
|
#line 19 "lel_parser.rl"
|
||||||
{ expand(); }
|
{ expand(); }
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
#line 26 "lel_parser.rl"
|
#line 27 "lel_parser.rl"
|
||||||
{ start = p; }
|
{ start = p; }
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
#line 29 "lel_parser.rl"
|
#line 30 "lel_parser.rl"
|
||||||
{start = p;}
|
{start = p;}
|
||||||
break;
|
break;
|
||||||
#line 216 "lel_parser.cpp"
|
#line 196 "lel_parser.cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,10 +231,14 @@ _again:
|
||||||
_out: {}
|
_out: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 48 "lel_parser.rl"
|
#line 49 "lel_parser.rl"
|
||||||
|
|
||||||
bool good = pe - p == 0;
|
bool good = pe - p == 0;
|
||||||
finalize();
|
if(good) {
|
||||||
|
finalize();
|
||||||
|
} else {
|
||||||
|
fmt::println("error at");
|
||||||
|
std::cout << p;
|
||||||
|
}
|
||||||
return good;
|
return good;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "lel.hpp"
|
#include "lel.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
%%{
|
%%{
|
||||||
machine LELParser;
|
machine LELParser;
|
||||||
|
@ -27,7 +28,7 @@
|
||||||
setw = ("(" number %setwidth ("," number %setheight)? ")") ;
|
setw = ("(" number %setwidth ("," number %setheight)? ")") ;
|
||||||
modifiers = (expand | valign | halign | setw);
|
modifiers = (expand | valign | halign | setw);
|
||||||
id = modifiers* ((alpha | '_')+ :>> (alnum | '_')*) >{start = fpc;} %id;
|
id = modifiers* ((alpha | '_')+ :>> (alnum | '_')*) >{start = fpc;} %id;
|
||||||
row = space* ltab space* id space* (col space* id)* space* rtab space*;
|
row = space* ltab space* id space* (col space* id space*)* space* rtab space*;
|
||||||
|
|
||||||
main := row+;
|
main := row+;
|
||||||
}%%
|
}%%
|
||||||
|
@ -47,7 +48,11 @@ bool LELParser::parse(std::string input) {
|
||||||
%% write exec;
|
%% write exec;
|
||||||
|
|
||||||
bool good = pe - p == 0;
|
bool good = pe - p == 0;
|
||||||
finalize();
|
if(good) {
|
||||||
|
finalize();
|
||||||
|
} else {
|
||||||
|
fmt::println("error at");
|
||||||
|
std::cout << p;
|
||||||
|
}
|
||||||
return good;
|
return good;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,23 +5,41 @@
|
||||||
#include "ansi_parser.hpp"
|
#include "ansi_parser.hpp"
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
TEST_CASE("test basic ops", "[lel]") {
|
TEST_CASE("test basic ops", "[lel]") {
|
||||||
LELParser parser(0, 0, 500, 500);
|
LELParser parser(0, 0, 500, 500);
|
||||||
|
std::vector<std::string> labels{
|
||||||
|
"label_1", "label3", "text1", "people",
|
||||||
|
"label2", "_", "message", "buttons"};
|
||||||
|
|
||||||
bool good = parser.parse(
|
bool good = parser.parse(
|
||||||
"[ label_1 | *label3 ]"
|
"[ label_1 | label3 | test1]"
|
||||||
"[ (300,300)text1 | (150)people ]"
|
"[ *(300,300)text1 | (150)people | test2]"
|
||||||
"[ >label2 | _ ]"
|
"[ >label2 | _ | test3]"
|
||||||
"[ message | buttons ]");
|
"[ message | buttons | test4]");
|
||||||
|
|
||||||
REQUIRE(good);
|
REQUIRE(good);
|
||||||
|
|
||||||
REQUIRE(parser.row_count == 4);
|
REQUIRE(parser.rows == 4);
|
||||||
REQUIRE(parser.max_columns == 2);
|
REQUIRE(parser.columns == 3);
|
||||||
REQUIRE(parser.cells.size() == 8);
|
REQUIRE(parser.cells.size() == 12);
|
||||||
REQUIRE(parser.cells.at("label2").left == false);
|
REQUIRE(parser.cells.at("label2").left == false);
|
||||||
REQUIRE(parser.cells.at("label3").expand == true);
|
REQUIRE(parser.cells.at("text1").expand == true);
|
||||||
|
REQUIRE(parser.cells.at("text1").w == 300);
|
||||||
|
REQUIRE(parser.cells.at("text1").h == 300);
|
||||||
REQUIRE(parser.cells.at("people").expand == false);
|
REQUIRE(parser.cells.at("people").expand == false);
|
||||||
REQUIRE(parser.cells.at("message").expand == false);
|
REQUIRE(parser.cells.at("message").expand == false);
|
||||||
|
|
||||||
|
for(auto name : labels) {
|
||||||
|
auto& cell = parser.cells.at(name);
|
||||||
|
|
||||||
|
fmt::println("name={}; col/row={},{}; x/y={},{} w/h={},{}; left={}, top={}, expand={}",
|
||||||
|
name, cell.col, cell.row, cell.x, cell.y, cell.w, cell.h, cell.left, cell.top, cell.expand);
|
||||||
|
|
||||||
|
REQUIRE(cell.w > 0);
|
||||||
|
REQUIRE(cell.h > 0);
|
||||||
|
REQUIRE(cell.row < parser.rows);
|
||||||
|
REQUIRE(cell.col < parser.columns);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue