Map now displays and works, just need to refine the colors and the compass directions.

master
Zed A. Shaw 1 day ago
parent dca38397e7
commit 75646619b3
  1. 58
      assets/map_tiles.json
  2. BIN
      assets/map_tiles.png
  3. 4
      constants.hpp
  4. 2
      gui/fsm.cpp
  5. 45
      gui/map_view.cpp
  6. 11
      gui/map_view.hpp
  7. 1
      tests/map.cpp
  8. 2
      tools/icongen.cpp

@ -8,121 +8,121 @@
{ {
"centered": false, "centered": false,
"display": 8284, "display": 8284,
"x": 32, "x": 64,
"y": 0 "y": 0
}, },
{ {
"centered": false, "centered": false,
"display": 11590, "display": 11590,
"x": 64, "x": 128,
"y": 0 "y": 0
}, },
{ {
"centered": false, "centered": false,
"display": 10899, "display": 10899,
"x": 96, "x": 192,
"y": 0 "y": 0
}, },
{ {
"centered": false, "centered": false,
"display": 9256, "display": 9256,
"x": 128, "x": 256,
"y": 0 "y": 0
}, },
{ {
"centered": false, "centered": false,
"display": 9608, "display": 9608,
"x": 160, "x": 320,
"y": 0 "y": 0
}, },
{ {
"centered": false, "centered": false,
"display": 10747, "display": 10747,
"x": 192, "x": 384,
"y": 0 "y": 0
}, },
{ {
"centered": false, "centered": false,
"display": 8285, "display": 8285,
"x": 224, "x": 448,
"y": 0 "y": 0
}, },
{ {
"centered": true, "centered": true,
"display": 1003, "display": 1003,
"x": 256, "x": 512,
"y": 0 "y": 0
}, },
{ {
"centered": true, "centered": true,
"display": 3848, "display": 3848,
"x": 288, "x": 576,
"y": 0 "y": 0
}, },
{ {
"centered": true, "centered": true,
"display": 85, "display": 85,
"x": 0, "x": 0,
"y": 32 "y": 64
}, },
{ {
"centered": true, "centered": true,
"display": 8687, "display": 8687,
"x": 32, "x": 64,
"y": 32 "y": 64
}, },
{ {
"centered": true, "centered": true,
"display": 10949, "display": 10949,
"x": 64, "x": 128,
"y": 32 "y": 64
}, },
{ {
"centered": true, "centered": true,
"display": 8793, "display": 8793,
"x": 96, "x": 192,
"y": 32 "y": 64
}, },
{ {
"centered": true, "centered": true,
"display": 95, "display": 95,
"x": 128, "x": 256,
"y": 32 "y": 64
}, },
{ {
"centered": true, "centered": true,
"display": 1898, "display": 1898,
"x": 160, "x": 320,
"y": 32 "y": 64
}, },
{ {
"centered": true, "centered": true,
"display": 42586, "display": 42586,
"x": 192, "x": 384,
"y": 32 "y": 64
}, },
{ {
"centered": true, "centered": true,
"display": 2189, "display": 2189,
"x": 224, "x": 448,
"y": 32 "y": 64
}, },
{ {
"centered": true, "centered": true,
"display": 41981, "display": 41981,
"x": 256, "x": 512,
"y": 32 "y": 64
}, },
{ {
"centered": true, "centered": true,
"display": 2220, "display": 2220,
"x": 288, "x": 576,
"y": 32 "y": 64
}, },
{ {
"centered": true, "centered": true,
"display": 1218, "display": 1218,
"x": 0, "x": 0,
"y": 64 "y": 128
} }
] ]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

@ -15,8 +15,8 @@ constexpr const int RAY_VIEW_Y=0;
constexpr const int GLOW_LIMIT=220; constexpr const int GLOW_LIMIT=220;
constexpr const int LIGHT_MULTIPLIER=2.5; constexpr const int LIGHT_MULTIPLIER=2.5;
constexpr const float AIMED_AT_BRIGHTNESS=0.2f; constexpr const float AIMED_AT_BRIGHTNESS=0.2f;
constexpr const int MAP_TILE_DIM=32; constexpr const int MAP_TILE_DIM=64;
constexpr const int ICONGEN_MAP_TILE_DIM=32; constexpr const int ICONGEN_MAP_TILE_DIM=64;
constexpr const int BOSS_VIEW_WIDTH=1080; constexpr const int BOSS_VIEW_WIDTH=1080;
constexpr const int BOSS_VIEW_HEIGHT=SCREEN_HEIGHT; constexpr const int BOSS_VIEW_HEIGHT=SCREEN_HEIGHT;

@ -347,7 +347,7 @@ namespace gui {
if(!sound::playing("ambient_1")) sound::play("ambient_1", true); if(!sound::playing("ambient_1")) sound::play("ambient_1", true);
$debug_ui.debug(); $debug_ui.debug();
shaders::reload(); shaders::reload();
$map_ui.save_map("map.txt", $main_ui.$compass_dir); $map_ui.save_map($main_ui.$compass_dir);
break; break;
case KEY::O: case KEY::O:
autowalking = true; autowalking = true;

@ -18,6 +18,9 @@ namespace gui {
MapViewUI::MapViewUI(GameLevel &level) : MapViewUI::MapViewUI(GameLevel &level) :
$level(level), $level(level),
$map_render(std::make_shared<sf::RenderTexture>()),
$map_sprite($map_render->getTexture()),
$map_tiles(matrix::make(12,11)),
$paper(textures::get("full_screen_paper")) $paper(textures::get("full_screen_paper"))
{ {
} }
@ -27,47 +30,43 @@ namespace gui {
} }
void MapViewUI::init() { void MapViewUI::init() {
//auto top_right = overlay.entity("top_right");
//auto cell = overlay.cell_for(top_right);
$gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); $gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
$gui.layout( $gui.layout(
"[log_view| *%(200)map_grid | _ ]" "[log_view| *%(200)map_grid | _ ]"
); );
auto grid = $gui.entity("map_grid");
$gui.set<Textual>(grid,
{L"Loading...", 65, {27, 26, 23, 150}, 10});
$log_to = $gui.entity("log_view"); $log_to = $gui.entity("log_view");
$gui.set<Textual>($log_to, {L"Welcome to the Game!", 25, {37, 36, 33}, 25}); $gui.set<Textual>($log_to, {L"Welcome to the Game!", 25, {37, 36, 33}, 25});
$paper.sprite->setPosition({0, 0}); $paper.sprite->setPosition({0, 0});
auto map_cell = $gui.cell_for("map_grid");
$map_sprite.setPosition({(float)map_cell.x, (float)map_cell.y + 30});
$gui.init(); $gui.init();
} }
void MapViewUI::render(sf::RenderWindow &window, int compass_dir) { void MapViewUI::save_map(int compass_dir) {
(void)compass_dir; (void)compass_dir;
window.draw(*$paper.sprite); // confirm we get two different maps
auto out_img = $map_render->getTexture().copyToImage();
bool worked = out_img.saveToFile("tmp/map_render.png");
dbc::check(worked, "failed to render map");
}
auto grid = $gui.entity("map_grid");
// System::draw_map
auto& map_text = $gui.get<Textual>(grid);
map_text.update(L"MAP BROKEN");
$gui.render(window); void MapViewUI::render(sf::RenderWindow &window, int compass_dir) {
// $gui.debug_layout(window); window.draw(*$paper.sprite);
}
void MapViewUI::save_map(const std::string& outfile, int compass_dir) { System::draw_map($level, $map_tiles, $entity_map, compass_dir);
(void)compass_dir;
std::wstring map_out = L"I'M BROKEN";
std::wofstream out(outfile, std::ios::binary); System::render_map($map_tiles, $entity_map, *$map_render);
std::locale loc(std::locale::classic(), new std::codecvt_utf8<wchar_t>);
out.imbue(loc);
out << map_out; $map_sprite.setTexture($map_render->getTexture(), true);
dbc::check(out.good(), "failed to write map file"); window.draw($map_sprite);
$gui.render(window);
// $gui.debug_layout(window);
} }
void MapViewUI::update() { void MapViewUI::update() {

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "levelmanager.hpp" #include "levelmanager.hpp"
#include "textures.hpp" #include "textures.hpp"
#include "matrix.hpp"
#include <guecs/ui.hpp> #include <guecs/ui.hpp>
#include <string> #include <string>
@ -8,10 +9,14 @@ namespace gui {
class MapViewUI { class MapViewUI {
public: public:
guecs::UI $gui; guecs::UI $gui;
GameLevel $level;
DinkyECS::Entity $log_to; DinkyECS::Entity $log_to;
textures::SpriteTexture $paper; EntityGrid $entity_map;
std::deque<std::wstring> $messages; std::deque<std::wstring> $messages;
GameLevel $level;
std::shared_ptr<sf::RenderTexture> $map_render;
sf::Sprite $map_sprite;
matrix::Matrix $map_tiles;
textures::SpriteTexture $paper;
MapViewUI(GameLevel &level); MapViewUI(GameLevel &level);
void init(); void init();
@ -19,6 +24,6 @@ namespace gui {
void update_level(GameLevel &level); void update_level(GameLevel &level);
void log(std::wstring msg); void log(std::wstring msg);
void update(); void update();
void save_map(const std::string& outfile, int compass_dir); void save_map(int compass_dir);
}; };
} }

@ -101,7 +101,6 @@ TEST_CASE("map image test", "[map-sprite]") {
player_pos.location.y = it.y; player_pos.location.y = it.y;
System::draw_map(level, map_tiles, entity_map, 2); System::draw_map(level, map_tiles, entity_map, 2);
// on level start make one render texture with the base map
System::render_map(map_tiles, entity_map, *render); System::render_map(map_tiles, entity_map, *render);
#ifdef TEST_RENDER #ifdef TEST_RENDER

@ -83,6 +83,7 @@ struct MapTileBuilder {
} }
void run_real_textures(MapConfig &config) { void run_real_textures(MapConfig &config) {
textures::init();
sf::Vector2u crop{$size.x * (unsigned int)config.it.width, ($size.y) * ((unsigned int)config.it.y + 1)}; sf::Vector2u crop{$size.x * (unsigned int)config.it.width, ($size.y) * ((unsigned int)config.it.y + 1)};
$render = std::make_shared<sf::RenderTexture>(crop); $render = std::make_shared<sf::RenderTexture>(crop);
$render->clear({0,0,0,0}); $render->clear({0,0,0,0});
@ -248,7 +249,6 @@ json& component_display(json& val) {
} }
int main() { int main() {
textures::init();
MapConfig config; MapConfig config;
load_config(config, false, "./assets/tiles.json", [](json& val) -> json& { load_config(config, false, "./assets/tiles.json", [](json& val) -> json& {

Loading…
Cancel
Save