added tileset fonts back in
This commit is contained in:
parent
55204a5d0a
commit
4f584174a6
|
@ -3,11 +3,16 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
#include "resource_manager.h"
|
||||||
#include "vec2.h"
|
#include "vec2.h"
|
||||||
|
|
||||||
struct tileset {
|
struct font;
|
||||||
|
|
||||||
|
struct tileset : resource {
|
||||||
|
friend struct font;
|
||||||
tileset(image const* image, vec2i tile_size);
|
tileset(image const* image, vec2i tile_size);
|
||||||
//tileset(std::string path, 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);
|
image& operator[](int index);
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
|
|
||||||
#include "image.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) {
|
font::font(resource_manager& rm, ini_category const* ini, std::string const& path, std::vector<uint8_t> const& data) {
|
||||||
if(!ini)
|
if(!ini)
|
||||||
throw std::runtime_error("font needs assets.ini");
|
throw std::runtime_error("font needs assets.ini");
|
||||||
if(!ini->get<bool>("proportional"))
|
if(ini->get<bool>("proportional")) {
|
||||||
throw std::runtime_error("not yet implemented");
|
|
||||||
|
|
||||||
|
|
||||||
auto image = rm.get<::image>(path);
|
auto image = rm.get<::image>(path);
|
||||||
auto x = 0;
|
auto x = 0;
|
||||||
std::vector<int> slices;
|
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).clear(0);
|
||||||
_glyphs.at(ch).draw(image, vec2i::zero, r);
|
_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 {
|
image const* font::get(char ch) const {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "tileset.h"
|
#include "tileset.h"
|
||||||
|
#include "image.h"
|
||||||
|
|
||||||
tileset::tileset(image const* image, vec2i tile_size) {
|
tileset::tileset(image const* image, vec2i tile_size) {
|
||||||
auto tile_count = image->size() / 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::tileset(std::string path, vec2i tile_size) :
|
||||||
tileset(new image(path), tile_size)
|
tileset(new image(path), tile_size)
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
[habbo.png]
|
[habbo.png]
|
||||||
proportional = true
|
proportional = true
|
||||||
|
|
||||||
|
[font.png]
|
||||||
|
proportional = false
|
||||||
|
tile_width = 8
|
||||||
|
tile_height = 14
|
|
@ -12,22 +12,24 @@ struct my_game : game {
|
||||||
|
|
||||||
|
|
||||||
//tileset tileset;
|
//tileset tileset;
|
||||||
font const* font;
|
font const* font1;
|
||||||
|
font const* font2;
|
||||||
double time;
|
double time;
|
||||||
};
|
};
|
||||||
|
|
||||||
void my_game::init(settings& settings) {
|
void my_game::init(settings& settings) {
|
||||||
settings.target_fps = 6000;
|
settings.target_fps = 6000;
|
||||||
time = 0.0;
|
time = 0.0;
|
||||||
settings.scale = 3;
|
settings.scale = 1;
|
||||||
settings.size = vec2i(1920/3, 1080/3);
|
settings.size = vec2i(1920, 1080);
|
||||||
//img = get<image>("test.png");
|
//img = get<image>("test.png");
|
||||||
//slime = get<image>("slime.png");
|
//slime = get<image>("slime.png");
|
||||||
//slime = slime->upscale_2x();
|
//slime = slime->upscale_2x();
|
||||||
//slime = slime->upscale_2x();
|
//slime = slime->upscale_2x();
|
||||||
//slime = slime->upscale_2x();
|
//slime = slime->upscale_2x();
|
||||||
//ini = get<::ini>("test.ini");
|
//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['\\']);
|
//cursor(&font['\\']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +49,10 @@ void my_game::render(image& target) {
|
||||||
//target.draw(tileset[0xda], vec2i(320, 180) + pos, 0xff00ff);
|
//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.";
|
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(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);
|
//target.draw("\\", mouse_pos(), font, 0xffffff, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue