summaryrefslogtreecommitdiff
path: root/tools/src/asset_processor/assets/asset.h
blob: 1b29c03c5046204bbd169917ad18f2b2cab7f415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef ASSET_H
#define ASSET_H

#include "util.h"
#include <filesystem>
#include <nlohmann/json_fwd.hpp>
#include <string>
#include <iostream>
#include <utility>

class BaseAsset {
  public:
    BaseAsset(std::filesystem::path path_, int start_, int size_, const nlohmann::json& asset_)
        : path(std::move(path_)), start(start_), size(size_), asset(asset_) {
    }

    virtual ~BaseAsset() = default;

    void setup() {
        // Cannot call virtual functions in constructor, so another function call is necessary
        assetPath = generateAssetPath();
        buildPath = generateBuildPath();
    }

    // Extract the binary segment for this asset from the baserom and store it in a separate file.
    virtual void extractBinary(const std::vector<char>& baserom);

    // Convert the binary data for this asset to a human readable form.
    virtual void convertToHumanReadable([[maybe_unused]] const std::vector<char>& baserom) {
    }

    // Build the asset from the human readable form back to the binary.
    virtual void buildToBinary() {
    }

    // Returns the path to the binary file extracted from the baserom.
    [[nodiscard]] std::filesystem::path getPath() const {
        return path;
    }

    // Returns the path to the human readable asset file.
    [[nodiscard]] std::filesystem::path getAssetPath() const {
        return assetPath;
    }

    // Returns the path to the resulting file after building.
    [[nodiscard]] std::filesystem::path getBuildPath() const {
        return buildPath;
    }

    // Returns the base of the filename of the asset.
    [[nodiscard]] virtual std::string getSymbol() const {
        // Need to get the stem twice to remove both of the .4bpp.lz extensions.
        return (path.stem()).stem();
    }

    // Returns the start address of this asset.
    [[nodiscard]] int getStart() const {
        return start;
    }

  protected:
    std::filesystem::path path;
    std::filesystem::path assetPath;
    std::filesystem::path buildPath;
    int start;
    int size;
    const nlohmann::json& asset;

  private:
    virtual std::filesystem::path generateAssetPath() {
        return path;
    }
    virtual std::filesystem::path generateBuildPath() {
        return path;
    }
};

#endif