yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
custom_object.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_DUNGEON_CUSTOM_OBJECT_H_
2#define YAZE_ZELDA3_DUNGEON_CUSTOM_OBJECT_H_
3
4#include <cstdint>
5#include <string>
6#include <vector>
7#include <memory>
8#include <unordered_map>
9
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
13
14namespace yaze {
15namespace zelda3 {
16
33 struct TileMapEntry {
34 int rel_x;
35 int rel_y;
36 uint16_t tile_data; // vhopppcc cccccccc
37 };
38
39 std::vector<TileMapEntry> tiles;
40
41 bool IsEmpty() const { return tiles.empty(); }
42};
43
48 public:
49 static CustomObjectManager& Get();
50
51 // Initialize with the full path to the custom objects folder
52 // e.g., "/path/to/project/Dungeons/Objects/Data"
53 void Initialize(const std::string& custom_objects_folder);
54
55 // Load a custom object from a binary file
56 absl::StatusOr<std::shared_ptr<CustomObject>> LoadObject(const std::string& filename);
57
58 // Get an object by ID/Subtype mapping (0x31 or 0x32)
59 // Subtype index maps to the .ObjOffset table
60 absl::StatusOr<std::shared_ptr<CustomObject>> GetObjectInternal(int object_id, int subtype);
61
62 // Get number of subtypes for a custom object ID
63 int GetSubtypeCount(int object_id) const;
64
65 // Reload all cached objects (useful for editor)
66 void ReloadAll();
67
68 private:
70
71 absl::StatusOr<CustomObject> ParseBinaryData(const std::vector<uint8_t>& data);
72
73 std::string base_path_;
74 std::unordered_map<std::string, std::shared_ptr<CustomObject>> cache_;
75
76 // Mapping from subtype index to filename for ID 0x31
77 static const std::vector<std::string> kSubtype1Filenames;
78 // Mapping from subtype index to filename for ID 0x32
79 static const std::vector<std::string> kSubtype2Filenames;
80};
81
82} // namespace zelda3
83} // namespace yaze
84
85#endif // YAZE_ZELDA3_DUNGEON_CUSTOM_OBJECT_H_
Manages loading and caching of custom object binary files.
int GetSubtypeCount(int object_id) const
absl::StatusOr< CustomObject > ParseBinaryData(const std::vector< uint8_t > &data)
static CustomObjectManager & Get()
absl::StatusOr< std::shared_ptr< CustomObject > > LoadObject(const std::string &filename)
absl::StatusOr< std::shared_ptr< CustomObject > > GetObjectInternal(int object_id, int subtype)
static const std::vector< std::string > kSubtype2Filenames
void Initialize(const std::string &custom_objects_folder)
std::unordered_map< std::string, std::shared_ptr< CustomObject > > cache_
static const std::vector< std::string > kSubtype1Filenames
Represents a decoded custom object (from binary format)
std::vector< TileMapEntry > tiles