Blocks atlas is auto-assembling now
This commit is contained in:
+15
-14
@@ -2,6 +2,7 @@
|
||||
#include "Assets.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
|
||||
#include "../constants.h"
|
||||
@@ -42,6 +43,7 @@ bool AssetsLoader::loadNext() {
|
||||
#include "../graphics/Shader.h"
|
||||
#include "../graphics/ImageData.h"
|
||||
#include "../graphics/Texture.h"
|
||||
#include "../graphics/Atlas.h"
|
||||
#include "../graphics/Font.h"
|
||||
|
||||
bool _load_shader(Assets* assets, const std::string& filename, const std::string& name) {
|
||||
@@ -65,18 +67,19 @@ bool _load_texture(Assets* assets, const std::string& filename, const std::strin
|
||||
}
|
||||
|
||||
bool _load_atlas(Assets* assets, const std::string& filename, const std::string& name) {
|
||||
unique_ptr<ImageData> image (png::load_image(filename));
|
||||
if (image == nullptr) {
|
||||
std::cerr << "failed to load image '" << name << "'" << std::endl;
|
||||
return false;
|
||||
AtlasBuilder builder;
|
||||
for (const auto& entry : std::filesystem::directory_iterator(filename)) {
|
||||
std::filesystem::path file = entry.path();
|
||||
if (file.extension() == ".png") {
|
||||
std::string name = file.stem().string();
|
||||
std::unique_ptr<ImageData> image (png::load_image(file.string()));
|
||||
//image->flipY();
|
||||
image->fixAlphaColor();
|
||||
builder.add(name, image.release());
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < ATLAS_MARGIN_SIZE; i++) {
|
||||
ImageData* newimage = add_atlas_margins(image.get(), 16);
|
||||
image.reset(newimage);
|
||||
}
|
||||
|
||||
Texture* texture = Texture::from(image.get());
|
||||
assets->store(texture, name);
|
||||
Atlas* atlas = builder.build(2);
|
||||
assets->store(atlas, name);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -107,9 +110,7 @@ void AssetsLoader::addDefaults(AssetsLoader& loader) {
|
||||
loader.add(ASSET_SHADER, SHADERS_FOLDER"/lines", "lines");
|
||||
loader.add(ASSET_SHADER, SHADERS_FOLDER"/ui", "ui");
|
||||
|
||||
loader.add(ASSET_ATLAS, TEXTURES_FOLDER"/block.png", "block");
|
||||
loader.add(ASSET_TEXTURE, TEXTURES_FOLDER"/block.png", "block_tex");
|
||||
loader.add(ASSET_TEXTURE, TEXTURES_FOLDER"/slot.png", "slot");
|
||||
loader.add(ASSET_ATLAS, TEXTURES_FOLDER"/blocks", "blocks");
|
||||
loader.add(ASSET_TEXTURE, TEXTURES_FOLDER"/menubg.png", "menubg");
|
||||
|
||||
loader.add(ASSET_FONT, FONTS_FOLDER"/font", "normal");
|
||||
|
||||
Reference in New Issue
Block a user