content-pack resources support

This commit is contained in:
MihailRis
2023-12-14 02:30:39 +03:00
parent c6d2266026
commit 396ee31bcc
43 changed files with 170 additions and 90 deletions
+22 -13
View File
@@ -1,8 +1,10 @@
#include "asset_loaders.h"
#include <iostream>
#include <filesystem>
#include "Assets.h"
#include "../files/files.h"
#include "../files/engine_paths.h"
#include "../coders/png.h"
#include "../graphics/Shader.h"
#include "../graphics/Texture.h"
@@ -18,9 +20,10 @@ using std::filesystem::path;
namespace fs = std::filesystem;
bool assetload::texture(Assets* assets,
const path filename,
const ResPaths* paths,
const string filename,
const string name) {
Texture* texture = png::load_texture(filename.string());
Texture* texture = png::load_texture(paths->find(filename).string());
if (texture == nullptr) {
std::cerr << "failed to load texture '" << name << "'" << std::endl;
return false;
@@ -30,10 +33,11 @@ bool assetload::texture(Assets* assets,
}
bool assetload::shader(Assets* assets,
const path filename,
const string name) {
path vertexFile = path(filename.string()+".glslv");
path fragmentFile = path(filename.string()+".glslf");
const ResPaths* paths,
const string filename,
const string name) {
path vertexFile = paths->find(filename+".glslv");
path fragmentFile = paths->find(filename+".glslf");
string vertexSource = files::read_string(vertexFile);
string fragmentSource = files::read_string(fragmentFile);
@@ -49,13 +53,16 @@ bool assetload::shader(Assets* assets,
}
bool assetload::atlas(Assets* assets,
const path directory,
const string name) {
const ResPaths* paths,
const string directory,
const string name) {
AtlasBuilder builder;
for (const auto& entry : fs::directory_iterator(directory)) {
path file = entry.path();
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()));
image->fixAlphaColor();
builder.add(name, image.release());
@@ -67,11 +74,13 @@ bool assetload::atlas(Assets* assets,
}
bool assetload::font(Assets* assets,
const path filename,
const string name) {
const ResPaths* paths,
const string filename,
const string name) {
vector<Texture*> pages;
for (size_t i = 0; i <= 4; i++) {
string name = filename.string() + "_" + std::to_string(i) + ".png";
string name = filename + "_" + std::to_string(i) + ".png";
name = paths->find(name).string();
Texture* texture = png::load_texture(name);
if (texture == nullptr) {
std::cerr << "failed to load bitmap font '" << name;