summaryrefslogtreecommitdiff
path: root/tools/src
diff options
context:
space:
mode:
authoroctorock <79596758+octorock@users.noreply.github.com>2022-12-06 17:00:46 +0100
committeroctorock <79596758+octorock@users.noreply.github.com>2022-12-06 17:00:46 +0100
commit80b66166f57ddca9dec06fbec6e621b1771e3cca (patch)
tree5b75135ff8034f0e08a37275f9bba368882798d4 /tools/src
parent03408debcd86ef85aa02a85680b4ebc26e53efb9 (diff)
Decompress map assets
Diffstat (limited to 'tools/src')
-rw-r--r--tools/src/asset_processor/assets/gfx.cpp35
-rw-r--r--tools/src/asset_processor/assets/gfx.h1
-rw-r--r--tools/src/asset_processor/assets/map.cpp44
-rw-r--r--tools/src/asset_processor/assets/map.h17
-rw-r--r--tools/src/asset_processor/assets/tileset.cpp35
-rw-r--r--tools/src/asset_processor/assets/tileset.h1
-rw-r--r--tools/src/asset_processor/main.cpp5
7 files changed, 133 insertions, 5 deletions
diff --git a/tools/src/asset_processor/assets/gfx.cpp b/tools/src/asset_processor/assets/gfx.cpp
index 39a11e3c..ef656e25 100644
--- a/tools/src/asset_processor/assets/gfx.cpp
+++ b/tools/src/asset_processor/assets/gfx.cpp
@@ -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";
} \ No newline at end of file
diff --git a/tools/src/asset_processor/assets/gfx.h b/tools/src/asset_processor/assets/gfx.h
index 394961ea..2e9db49c 100644
--- a/tools/src/asset_processor/assets/gfx.h
+++ b/tools/src/asset_processor/assets/gfx.h
@@ -8,4 +8,5 @@ class GfxAsset : public BaseAsset {
private:
virtual std::filesystem::path generateAssetPath();
+ bool isCompressed();
}; \ No newline at end of file
diff --git a/tools/src/asset_processor/assets/map.cpp b/tools/src/asset_processor/assets/map.cpp
new file mode 100644
index 00000000..2d5a0bca
--- /dev/null
+++ b/tools/src/asset_processor/assets/map.cpp
@@ -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";
+} \ No newline at end of file
diff --git a/tools/src/asset_processor/assets/map.h b/tools/src/asset_processor/assets/map.h
new file mode 100644
index 00000000..075af0bf
--- /dev/null
+++ b/tools/src/asset_processor/assets/map.h
@@ -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
diff --git a/tools/src/asset_processor/assets/tileset.cpp b/tools/src/asset_processor/assets/tileset.cpp
index cd564f33..cf921653 100644
--- a/tools/src/asset_processor/assets/tileset.cpp
+++ b/tools/src/asset_processor/assets/tileset.cpp
@@ -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";
} \ No newline at end of file
diff --git a/tools/src/asset_processor/assets/tileset.h b/tools/src/asset_processor/assets/tileset.h
index 0affdf4d..f2d6fb9a 100644
--- a/tools/src/asset_processor/assets/tileset.h
+++ b/tools/src/asset_processor/assets/tileset.h
@@ -8,4 +8,5 @@ class TilesetAsset : public BaseAsset {
private:
virtual std::filesystem::path generateAssetPath();
+ bool isCompressed();
}; \ No newline at end of file
diff --git a/tools/src/asset_processor/main.cpp b/tools/src/asset_processor/main.cpp
index c1bb66cf..db472e6e 100644
--- a/tools/src/asset_processor/main.cpp
+++ b/tools/src/asset_processor/main.cpp
@@ -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()) {