Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! Add basic input/output to fovtool
Browse files Browse the repository at this point in the history
  • Loading branch information
HexDecimal committed Oct 25, 2024
1 parent e7243ac commit 0561988
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@
"ranges": "cpp",
"span": "cpp",
"gsl": "cpp",
"pointers": "cpp"
"pointers": "cpp",
"stacktrace": "cpp",
"assert": "cpp",
"narrow": "cpp"
},
"files.trimFinalNewlines": true,
"files.insertFinalNewline": true,
Expand Down
8 changes: 4 additions & 4 deletions src/fovtool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ static auto load_map(const std::filesystem::path& path) {
auto map = MapInfo{
.data = {map_width, map_height},
};
for (int y = 0; y < lines.size(); ++y) {
for (int y = 0; y < gsl::narrow<int>(lines.size()); ++y) {
const auto& line = lines.at(y);
for (int x = 0; x < map_width; ++x) {
static constexpr auto DEFAULT_CH = '.';
const auto ch = (gsl::narrow<size_t>(x) < line.size() ? line.at(x) : DEFAULT_CH);
const auto ch = (x < gsl::narrow<int>(line.size()) ? line.at(x) : DEFAULT_CH);
const bool transparent = ch != '#';
map.data.setProperties(x, y, transparent, false);
if (ch == '@') {
Expand All @@ -59,7 +59,7 @@ static auto load_map(const std::filesystem::path& path) {
}

static auto render_map(const MapInfo& map) {
auto stream = std::basic_ostringstream<char32_t>{};
auto stream = std::ostringstream{};
for (int y = 0; y < map.data.getHeight(); ++y) {
if (y) stream << '\n';
for (int x = 0; x < map.data.getWidth(); ++x) {
Expand All @@ -72,7 +72,7 @@ static auto render_map(const MapInfo& map) {
stream << (visible ? (transparent ? '.' : '#') : (transparent ? ' ' : ' '));
}
}
return utf8::utf32to8(stream.rdbuf()->view());
return stream.rdbuf()->str();
}

int main(int argc, char** argv) {
Expand Down

0 comments on commit 0561988

Please sign in to comment.