Decompress map assets

This commit is contained in:
octorock
2022-12-06 17:00:46 +01:00
parent 03408debcd
commit 80b66166f5
11 changed files with 2849 additions and 2720 deletions
+33 -2
View File
@@ -16,8 +16,21 @@ void GfxAsset::convertToHumanReadable(const std::vector<char>& baserom) {
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
std::filesystem::path decompressedPath = path;
if (isCompressed()) {
// First decompress.
decompressedPath.replace_extension("");
cmd.push_back(toolsPath / "bin" / "gbagfx");
cmd.push_back(path);
cmd.push_back(decompressedPath);
check_call(cmd);
cmd.clear();
}
cmd.push_back(toolsPath / "bin" / "gbagfx");
cmd.push_back(path);
cmd.push_back(decompressedPath);
cmd.push_back(assetPath);
if (asset.contains("options")) {
for (const auto& it : asset["options"].items()) {
@@ -31,8 +44,26 @@ void GfxAsset::convertToHumanReadable(const std::vector<char>& baserom) {
void GfxAsset::buildToBinary() {
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
std::filesystem::path decompressedPath = path;
if (isCompressed()) {
decompressedPath.replace_extension("");
}
cmd.push_back(toolsPath / "bin" / "gbagfx");
cmd.push_back(assetPath);
cmd.push_back(path);
cmd.push_back(decompressedPath);
check_call(cmd);
if (isCompressed()) {
// Compress.
cmd.push_back(toolsPath / "bin" / "gbagfx");
cmd.push_back(decompressedPath);
cmd.push_back(path);
check_call(cmd);
}
}
bool GfxAsset::isCompressed() {
return path.extension() == ".lz";
}
+1
View File
@@ -8,4 +8,5 @@ class GfxAsset : public BaseAsset {
private:
virtual std::filesystem::path generateAssetPath();
bool isCompressed();
};
+44
View File
@@ -0,0 +1,44 @@
#include "map.h"
#include "util.h"
#include <nlohmann/json.hpp>
std::filesystem::path MapAsset::generateAssetPath() {
std::filesystem::path decompressedPath = path;
if (isCompressed()) {
if (decompressedPath.extension() == ".lz") {
decompressedPath.replace_extension("");
}
}
return decompressedPath;
}
void MapAsset::convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
if (isCompressed()) {
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
// Decompress.
cmd.push_back(toolsPath / "bin" / "gbagfx");
cmd.push_back(path);
cmd.push_back(assetPath);
check_call(cmd);
}
}
void MapAsset::buildToBinary() {
if (isCompressed()) {
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
// Compress.
cmd.push_back(toolsPath / "bin" / "gbagfx");
cmd.push_back(assetPath);
cmd.push_back(path);
check_call(cmd);
}
}
bool MapAsset::isCompressed() {
return path.extension() == ".lz";
}
+17
View File
@@ -0,0 +1,17 @@
#ifndef MAP_H
#define MAP_H
#include "asset.h"
class MapAsset : public BaseAsset {
public:
using BaseAsset::BaseAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
virtual void buildToBinary();
private:
virtual std::filesystem::path generateAssetPath();
bool isCompressed();
};
#endif // MAP_H
+33 -2
View File
@@ -15,8 +15,21 @@ void TilesetAsset::convertToHumanReadable(const std::vector<char>& baserom) {
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
std::filesystem::path decompressedPath = path;
if (isCompressed()) {
// First decompress.
decompressedPath.replace_extension("");
cmd.push_back(toolsPath / "bin" / "gbagfx");
cmd.push_back(path);
cmd.push_back(decompressedPath);
check_call(cmd);
cmd.clear();
}
cmd.push_back(toolsPath / "bin" / "gbagfx");
cmd.push_back(path);
cmd.push_back(decompressedPath);
cmd.push_back(assetPath);
cmd.push_back("-mwidth");
cmd.push_back("32");
@@ -26,8 +39,26 @@ void TilesetAsset::convertToHumanReadable(const std::vector<char>& baserom) {
void TilesetAsset::buildToBinary() {
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
std::filesystem::path decompressedPath = path;
if (isCompressed()) {
decompressedPath.replace_extension("");
}
cmd.push_back(toolsPath / "bin" / "gbagfx");
cmd.push_back(assetPath);
cmd.push_back(path);
cmd.push_back(decompressedPath);
check_call(cmd);
if (isCompressed()) {
// Compress.
cmd.push_back(toolsPath / "bin" / "gbagfx");
cmd.push_back(decompressedPath);
cmd.push_back(path);
check_call(cmd);
}
}
bool TilesetAsset::isCompressed() {
return path.extension() == ".lz";
}
+1
View File
@@ -8,4 +8,5 @@ class TilesetAsset : public BaseAsset {
private:
virtual std::filesystem::path generateAssetPath();
bool isCompressed();
};
+4 -1
View File
@@ -3,6 +3,7 @@
#include "assets/animation.h"
#include "assets/frameobjlists.h"
#include "assets/gfx.h"
#include "assets/map.h"
#include "assets/midi.h"
#include "assets/palette.h"
#include "assets/spriteframe.h"
@@ -281,7 +282,9 @@ std::unique_ptr<BaseAsset> getAssetHandlerByType(const std::filesystem::path& pa
} else if (type == "map_gfx" || type == "map_layer1" || type == "map_layer2" || type == "metatiles_tile_types1" ||
type == "metatiles_tile_types2" || type == "metatiles_tileset1" || type == "metatiles_tileset2" ||
type == "map_mapping1" || type == "map_mapping2" || type == "tileset_mapping3" ||
type == "map_collision" || type == "unknown") {
type == "map_collision") {
assetHandler = std::make_unique<MapAsset>(path, start, size, asset);
} else if (type == "unknown") {
// TODO implement conversions
assetHandler = std::make_unique<BaseAsset>(path, start, size, asset);
} else if (type.empty()) {