Additional check + refactor
This commit is contained in:
parent
3c89b9c083
commit
13b204f28d
@ -12,17 +12,13 @@
|
||||
#include "../graphics/Atlas.h"
|
||||
#include "../graphics/Font.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::unique_ptr;
|
||||
using std::filesystem::path;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
bool assetload::texture(Assets* assets,
|
||||
const ResPaths* paths,
|
||||
const string filename,
|
||||
const string name) {
|
||||
const std::string filename,
|
||||
const std::string name) {
|
||||
Texture* texture = png::load_texture(paths->find(filename).string());
|
||||
if (texture == nullptr) {
|
||||
std::cerr << "failed to load texture '" << name << "'" << std::endl;
|
||||
@ -34,16 +30,19 @@ bool assetload::texture(Assets* assets,
|
||||
|
||||
bool assetload::shader(Assets* assets,
|
||||
const ResPaths* paths,
|
||||
const string filename,
|
||||
const string name) {
|
||||
path vertexFile = paths->find(filename+".glslv");
|
||||
path fragmentFile = paths->find(filename+".glslf");
|
||||
const std::string filename,
|
||||
const std::string name) {
|
||||
fs::path vertexFile = paths->find(filename+".glslv");
|
||||
fs::path fragmentFile = paths->find(filename+".glslf");
|
||||
|
||||
string vertexSource = files::read_string(vertexFile);
|
||||
string fragmentSource = files::read_string(fragmentFile);
|
||||
std::string vertexSource = files::read_string(vertexFile);
|
||||
std::string fragmentSource = files::read_string(fragmentFile);
|
||||
|
||||
Shader* shader = Shader::loadShader(vertexFile.string(), fragmentFile.string(),
|
||||
vertexSource, fragmentSource);
|
||||
Shader* shader = Shader::loadShader(
|
||||
vertexFile.string(),
|
||||
fragmentFile.string(),
|
||||
vertexSource, fragmentSource);
|
||||
|
||||
if (shader == nullptr) {
|
||||
std::cerr << "failed to load shader '" << name << "'" << std::endl;
|
||||
return false;
|
||||
@ -54,19 +53,25 @@ bool assetload::shader(Assets* assets,
|
||||
|
||||
bool assetload::atlas(Assets* assets,
|
||||
const ResPaths* paths,
|
||||
const string directory,
|
||||
const string name) {
|
||||
const std::string directory,
|
||||
const std::string name) {
|
||||
AtlasBuilder builder;
|
||||
for (const auto& file : paths->listdir(directory)) {
|
||||
if (file.extension() == ".png") {
|
||||
string name = file.stem().string();
|
||||
if (builder.has(name)) {
|
||||
continue; // skip duplicates
|
||||
}
|
||||
std::unique_ptr<ImageData> image (png::load_image(file.string()));//but what if load_image return nullptr?
|
||||
image->fixAlphaColor();
|
||||
builder.add(name, image.release());
|
||||
// png is only supported format
|
||||
if (file.extension() != ".png")
|
||||
continue;
|
||||
std::string name = file.stem().string();
|
||||
// skip duplicates
|
||||
if (builder.has(name)) {
|
||||
continue;
|
||||
}
|
||||
std::unique_ptr<ImageData> image (png::load_image(file.string()));
|
||||
if (image == nullptr) {
|
||||
std::cerr << "could not to load " << file.string() << std::endl;
|
||||
continue;
|
||||
}
|
||||
image->fixAlphaColor();
|
||||
builder.add(name, image.release());
|
||||
}
|
||||
Atlas* atlas = builder.build(2);
|
||||
assets->store(atlas, name);
|
||||
@ -75,11 +80,11 @@ bool assetload::atlas(Assets* assets,
|
||||
|
||||
bool assetload::font(Assets* assets,
|
||||
const ResPaths* paths,
|
||||
const string filename,
|
||||
const string name) {
|
||||
vector<Texture*> pages;
|
||||
const std::string filename,
|
||||
const std::string name) {
|
||||
std::vector<Texture*> pages;
|
||||
for (size_t i = 0; i <= 4; i++) {
|
||||
string name = filename + "_" + std::to_string(i) + ".png";
|
||||
std::string name = filename + "_" + std::to_string(i) + ".png";
|
||||
name = paths->find(name).string();
|
||||
Texture* texture = png::load_texture(name);
|
||||
if (texture == nullptr) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user