You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.7 KiB
82 lines
1.7 KiB
#include "lel.hpp"
|
|
#include <fmt/core.h>
|
|
|
|
#include "lel_parser.cpp"
|
|
|
|
LELParser::LELParser(int x, int y, int width, int height) :
|
|
grid_x(x),
|
|
grid_y(y),
|
|
grid_w(width),
|
|
grid_h(height),
|
|
cur(0, 0)
|
|
{
|
|
|
|
}
|
|
|
|
void LELParser::ltab() {
|
|
cur.row = row_count;
|
|
fmt::println("ltab: rows {}", row_count);
|
|
}
|
|
|
|
void LELParser::col() {
|
|
}
|
|
|
|
void LELParser::valign(char dir) {
|
|
cur.top = dir == '^';
|
|
fmt::println("valign: {}", dir);
|
|
}
|
|
|
|
void LELParser::align(char dir) {
|
|
cur.left = dir == '<';
|
|
fmt::println("align {}", dir);
|
|
}
|
|
|
|
void LELParser::id(std::string name) {
|
|
fmt::println("id: {}", name);
|
|
cells.insert_or_assign(name, cur);
|
|
cur = {cur.col + 1, cur.row};
|
|
}
|
|
|
|
void LELParser::row() {
|
|
row_count++;
|
|
max_columns = std::max(max_columns, cur.col);
|
|
cur.col = 0;
|
|
fmt::println("row end: cols {}", cur.col);
|
|
}
|
|
|
|
void LELParser::setwidth(int width) {
|
|
fmt::println("setwidth: {}", width);
|
|
cur.w = width;
|
|
}
|
|
|
|
void LELParser::setheight(int height) {
|
|
fmt::println("setheight: {}", height);
|
|
cur.h = height;
|
|
}
|
|
|
|
void LELParser::expand() {
|
|
fmt::println("expand");
|
|
cur.expand = true;
|
|
}
|
|
|
|
void LELParser::finalize() {
|
|
int cell_width = grid_w / max_columns;
|
|
int cell_height = grid_h / row_count;
|
|
fmt::println("FINALIZE: cell w/h: {},{}", cell_width, cell_height);
|
|
|
|
for(auto [name, cell] : cells) {
|
|
cell.x = cell.col * cell_width;
|
|
cell.y = cell.row * cell_height;
|
|
if(cell.w == 0) cell.w = cell_width;
|
|
if(cell.x == 0) cell.h = cell_height;
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
void LELParser::reset() {
|
|
row_count = 0;
|
|
max_columns = 0;
|
|
cur = {0, 0};
|
|
}
|
|
|