Tried out using the actual textures from the game but they don't really have the feel I want. I'll have to think about it.
This commit is contained in:
parent
5e01eb29a9
commit
5db3d1a306
7 changed files with 49 additions and 6 deletions
Binary file not shown.
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 9.6 KiB |
|
@ -22,8 +22,8 @@
|
||||||
"collision": true,
|
"collision": true,
|
||||||
"display": 9256,
|
"display": 9256,
|
||||||
"light": 20,
|
"light": 20,
|
||||||
"foreground": [100, 100, 180],
|
"background": [100, 100, 180],
|
||||||
"background": [100, 150, 100],
|
"foreground": [100, 150, 100],
|
||||||
"id": 2
|
"id": 2
|
||||||
},
|
},
|
||||||
"ceiling_black": {
|
"ceiling_black": {
|
||||||
|
|
|
@ -170,7 +170,7 @@ executable('zedcaster',
|
||||||
dependencies: dependencies)
|
dependencies: dependencies)
|
||||||
|
|
||||||
executable('icongen',
|
executable('icongen',
|
||||||
[ 'config.cpp', 'dbc.cpp', 'tools/icongen.cpp' ],
|
[ 'textures.cpp', 'config.cpp', 'dbc.cpp', 'tools/icongen.cpp' ],
|
||||||
cpp_args: cpp_args,
|
cpp_args: cpp_args,
|
||||||
link_args: link_args,
|
link_args: link_args,
|
||||||
override_options: exe_defaults,
|
override_options: exe_defaults,
|
||||||
|
|
|
@ -132,7 +132,6 @@ TEST_CASE("map image test", "[map-sprite]") {
|
||||||
|
|
||||||
auto sprite = render_sprite(sprite_coord, size, display, map_sprites);
|
auto sprite = render_sprite(sprite_coord, size, display, map_sprites);
|
||||||
sprite.setPosition({float(it.x * size.x), float(it.y * size.y)});
|
sprite.setPosition({float(it.x * size.x), float(it.y * size.y)});
|
||||||
sprite.setColor({255, 255, 255, 200});
|
|
||||||
render.draw(sprite);
|
render.draw(sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,10 @@ namespace textures {
|
||||||
return (const uint32_t *)TMGR.surfaces[num].getPixelsPtr();
|
return (const uint32_t *)TMGR.surfaces[num].getPixelsPtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sf::Image& get_surface_img(size_t num) {
|
||||||
|
return TMGR.surfaces[num];
|
||||||
|
}
|
||||||
|
|
||||||
const uint32_t* get_ceiling(size_t num) {
|
const uint32_t* get_ceiling(size_t num) {
|
||||||
size_t ceiling_num = TMGR.ceilings[num];
|
size_t ceiling_num = TMGR.ceilings[num];
|
||||||
return (const uint32_t *)TMGR.surfaces[ceiling_num].getPixelsPtr();
|
return (const uint32_t *)TMGR.surfaces[ceiling_num].getPixelsPtr();
|
||||||
|
|
|
@ -36,6 +36,8 @@ namespace textures {
|
||||||
|
|
||||||
const uint32_t* get_surface(size_t num);
|
const uint32_t* get_surface(size_t num);
|
||||||
|
|
||||||
|
sf::Image& get_surface_img(size_t num);
|
||||||
|
|
||||||
const uint32_t* get_ceiling(size_t num);
|
const uint32_t* get_ceiling(size_t num);
|
||||||
|
|
||||||
size_t get_id(const std::string& name);
|
size_t get_id(const std::string& name);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "shiterator.hpp"
|
#include "shiterator.hpp"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "textures.hpp"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
constexpr const int TILE_COUNT=10;
|
constexpr const int TILE_COUNT=10;
|
||||||
|
@ -28,6 +29,7 @@ struct MapConfig {
|
||||||
BoolGrid centered = make<bool>(TILE_COUNT, TILE_COUNT);
|
BoolGrid centered = make<bool>(TILE_COUNT, TILE_COUNT);
|
||||||
std::unordered_map<wchar_t, sf::Color> colors;
|
std::unordered_map<wchar_t, sf::Color> colors;
|
||||||
std::unordered_map<wchar_t, sf::Color> backgrounds;
|
std::unordered_map<wchar_t, sf::Color> backgrounds;
|
||||||
|
std::unordered_map<wchar_t, std::string> names;
|
||||||
each_row_t<MapGrid> it{map};
|
each_row_t<MapGrid> it{map};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -81,8 +83,43 @@ struct MapTileBuilder {
|
||||||
dbc::check(worked, "Failed to write screenshot.png");
|
dbc::check(worked, "Failed to write screenshot.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void run_real_textures(MapConfig &config) {
|
||||||
|
sf::Vector2u crop{$size.x * (unsigned int)config.it.width, ($size.y) * ((unsigned int)config.it.y + 1)};
|
||||||
|
fmt::println("TEXTURE CROP: {},{}; size: {},{}", $size.x, $size.y, crop.x, crop.y);
|
||||||
|
$render = std::make_shared<sf::RenderTexture>(crop);
|
||||||
|
$render->clear({0,0,0,0});
|
||||||
|
|
||||||
|
$render->setSmooth(false);
|
||||||
|
sf::Vector2f cell_pos{0.0f,0.0f};
|
||||||
|
|
||||||
|
for(each_row_t<MapGrid> it{config.map}; it.next();) {
|
||||||
|
wchar_t display_char = config.map[it.y][it.x];
|
||||||
|
// stop when there's no more cells set
|
||||||
|
if(display_char == 0) break;
|
||||||
|
|
||||||
|
cell_pos.x = it.x * $size.x;
|
||||||
|
cell_pos.y = it.y * $size.y;
|
||||||
|
|
||||||
|
auto& name = config.names.at(display_char);
|
||||||
|
auto id = textures::get_id(name);
|
||||||
|
auto& img = textures::get_surface_img(id);
|
||||||
|
auto img_size = img.getSize();
|
||||||
|
|
||||||
|
sf::Texture surface{img};
|
||||||
|
|
||||||
|
sf::Vector2f scale{float($size.x) / float(img_size.x),
|
||||||
|
float($size.y) / float(img_size.y)};
|
||||||
|
|
||||||
|
sf::Sprite sprite{surface};
|
||||||
|
sprite.setScale(scale);
|
||||||
|
sprite.setPosition(cell_pos);
|
||||||
|
$render->draw(sprite);
|
||||||
|
$render->display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void run(MapConfig& config) {
|
void run(MapConfig& config) {
|
||||||
sf::Vector2u crop{$size.x * (unsigned int)config.it.width, $size.y * (unsigned int)config.it.y};
|
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});
|
||||||
|
|
||||||
|
@ -107,7 +144,6 @@ struct MapTileBuilder {
|
||||||
|
|
||||||
sf::Text icon{$font, content, $font_size};
|
sf::Text icon{$font, content, $font_size};
|
||||||
icon.setFillColor({255, 255, 255, 255});
|
icon.setFillColor({255, 255, 255, 255});
|
||||||
|
|
||||||
$temp_render.draw(icon);
|
$temp_render.draw(icon);
|
||||||
$temp_render.clear({0,0,0,0});
|
$temp_render.clear({0,0,0,0});
|
||||||
|
|
||||||
|
@ -178,6 +214,7 @@ void load_config(MapConfig& config, bool is_centered, std::string path, std::fun
|
||||||
wchar_t display = data["display"];
|
wchar_t display = data["display"];
|
||||||
config.map[config.it.y][config.it.x] = display;
|
config.map[config.it.y][config.it.x] = display;
|
||||||
config.centered[config.it.y][config.it.x] = is_centered;
|
config.centered[config.it.y][config.it.x] = is_centered;
|
||||||
|
config.names.insert_or_assign(display, key);
|
||||||
|
|
||||||
dbc::check(!config.colors.contains(display),
|
dbc::check(!config.colors.contains(display),
|
||||||
fmt::format("duplicate color for display={} key={}",
|
fmt::format("duplicate color for display={} key={}",
|
||||||
|
@ -220,6 +257,7 @@ 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…
Add table
Add a link
Reference in a new issue