added tileset fonts back in

This commit is contained in:
Squishy Bloob 2024-03-31 01:56:47 +00:00
parent 55204a5d0a
commit 4f584174a6
5 changed files with 65 additions and 29 deletions

View File

@ -3,11 +3,16 @@
#include <string>
#include <vector>
#include "image.h"
#include "resource_manager.h"
#include "vec2.h"
struct tileset {
struct font;
struct tileset : resource {
friend struct font;
tileset(image const* image, vec2i tile_size);
//tileset(std::string path, vec2i tile_size);
tileset(resource_manager& rm, ini_category const* ini, std::string const& path, std::vector<uint8_t> const& data);
image& operator[](int index);

View File

@ -1,14 +1,12 @@
#include "font.h"
#include "image.h"
#include "tileset.h"
font::font(resource_manager& rm, ini_category const* ini, std::string const& path, std::vector<uint8_t> const& data) {
if(!ini)
throw std::runtime_error("font needs assets.ini");
if(!ini->get<bool>("proportional"))
throw std::runtime_error("not yet implemented");
if(ini->get<bool>("proportional")) {
auto image = rm.get<::image>(path);
auto x = 0;
std::vector<int> slices;
@ -29,7 +27,15 @@ font::font(resource_manager& rm, ini_category const* ini, std::string const& pat
_glyphs.at(ch).clear(0);
_glyphs.at(ch).draw(image, vec2i::zero, r);
}
} else {
int width = ini->get<int>("width");
int height = ini->get<int>("height");
auto ts = rm.get<tileset>(path);
_lineheight = ts->_tile_size.y;
for(int i = 0; i < 256; ++i) {
_glyphs.insert({ i, ts->_tiles[i] });
}
}
}
image const* font::get(char ch) const {

View File

@ -1,4 +1,5 @@
#include "tileset.h"
#include "image.h"
tileset::tileset(image const* image, vec2i tile_size) {
auto tile_count = image->size() / tile_size;
@ -11,6 +12,21 @@ tileset::tileset(image const* image, vec2i tile_size) {
}
}
}
tileset::tileset(resource_manager& rm, ini_category const* ini, std::string const& path, std::vector<uint8_t> const& data) {
auto tile_size = vec2i(ini->get<int>("tile_width"), ini->get<int>("tile_height"));
_tile_size = tile_size;
auto image = rm.get<::image>(path);
auto tile_count = image->size() / tile_size;
for(int y = 0; y < tile_count.y; ++y) {
for(int x = 0; x < tile_count.x; ++x) {
auto tile = ::image(tile_size);
tile.clear(0);
tile.draw(image, vec2i::zero, recti(tile_size * vec2i(x, y), tile_size));
_tiles.push_back(tile);
}
}
}
/*
tileset::tileset(std::string path, vec2i tile_size) :
tileset(new image(path), tile_size)

View File

@ -1,3 +1,7 @@
[habbo.png]
proportional = true
[font.png]
proportional = false
tile_width = 8
tile_height = 14

View File

@ -12,22 +12,24 @@ struct my_game : game {
//tileset tileset;
font const* font;
font const* font1;
font const* font2;
double time;
};
void my_game::init(settings& settings) {
settings.target_fps = 6000;
time = 0.0;
settings.scale = 3;
settings.size = vec2i(1920/3, 1080/3);
settings.scale = 1;
settings.size = vec2i(1920, 1080);
//img = get<image>("test.png");
//slime = get<image>("slime.png");
//slime = slime->upscale_2x();
//slime = slime->upscale_2x();
//slime = slime->upscale_2x();
//ini = get<::ini>("test.ini");
font = get<::font>("_/default-font-prop.png");
font1 = get<::font>("_/default-font-prop.png");
font2 = get<::font>("font.png");
//cursor(&font['\\']);
}
@ -47,7 +49,10 @@ void my_game::render(image& target) {
//target.draw(tileset[0xda], vec2i(320, 180) + pos, 0xff00ff);
auto str = "Can only be played if\nthere are no card in\nyour draw pile.\nDeal 50 damage to ALL\nenemies.";
//target.draw(str, vec2i(100, 100) + pos, font, 0xffffff, 0);
target.draw(std::format("FPS: {}", fps()), vec2i(10, 10), font, 0xffffff, 0);
target.draw(std::format("FPS: {}", fps()), vec2i(10, 10), font1, 0xffffff, 0);
for(int i = 0; i < 64; ++i)
target.draw("C-4", vec2i(100, i * 14), font2, 0xffffff, 0);
//target.draw("\\", mouse_pos(), font, 0xffffff, 0);
}