Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
MetaFile.hpp
1#pragma once
2
3#include <filesystem>
4
5#include <Common/Editor/Importer.hpp>
6#include <Common/ResourcePipeline/AssetType.hpp>
7#include <Editor/AssetRegistry.hpp>
8
9#include "ImporterSettings.hpp"
10#include "Uuid.hpp"
11
12namespace Grindstone::Editor {
13 class MetaFile {
14 public:
15 struct Subasset {
16 std::string displayName;
17 std::string subassetIdentifier;
18 std::string address;
19 AssetType assetType = AssetType::Undefined;
20 Uuid uuid;
21
22 Subasset() = default;
23 Subasset(
24 std::string_view subassetIdentifier,
25 std::string_view displayName,
26 std::string_view address,
27 Uuid uuid,
28 AssetType type
29 ) : subassetIdentifier(subassetIdentifier),
30 displayName(displayName),
31 address(address),
32 uuid(uuid),
33 assetType(type) {}
34 };
35
36 public:
37 MetaFile() = default;
38 MetaFile(AssetRegistry& assetRegistry, const std::filesystem::path&);
39
40 void Load(AssetRegistry& assetRegistry, const std::filesystem::path&);
41 MetaFile(const MetaFile& other) = delete;
42 MetaFile(MetaFile&& other) noexcept = default;
43
44 MetaFile& operator=(const MetaFile& other) = delete;
45 MetaFile& operator=(MetaFile&& other) noexcept = default;
46
47 void Save(uint32_t currentImporterVersion);
48 void SaveWithoutImporterVersionChange();
49 bool TryGetDefaultSubasset(Subasset& subasset) const;
50 Uuid GetOrCreateDefaultSubassetUuid(const std::string& subassetName, AssetType assetType);
51 Uuid GetOrCreateSubassetUuid(const std::string& subassetName, AssetType assetType);
52 size_t GetSubassetCount() const;
53 bool TryGetSubasset(const std::string& subassetName, Subasset*& outSubasset);
54 bool TryGetSubasset(Uuid uuid, Subasset*& outSubasset);
55 bool TryGetDefaultSubassetUuid(Uuid& outUuid) const;
56 bool TryGetSubassetUuid(const std::string& subassetName, Uuid& outUuid) const;
57 bool IsValid() const;
58 bool IsOutdatedImporterVersion(Grindstone::Editor::ImporterVersion currentImporterVersion) const;
59 bool IsOutdatedMetaVersion() const;
60
61 Grindstone::Editor::ImporterSettings& GetImporterSettings() {
62 return importerSettings;
63 }
64 public:
65 using Iterator = std::vector<Subasset>::iterator;
66 using ConstIterator = std::vector<Subasset>::const_iterator;
67
68 Iterator begin() noexcept;
69 ConstIterator begin() const noexcept;
70
71 Iterator end() noexcept;
72 ConstIterator end() const noexcept;
73 private:
74 std::string MakeDefaultAddress(std::string_view subassetName) const;
75
76 bool isDirty = false;
77 bool isValid = true;
78 uint32_t importerVersion = 0;
79 uint32_t metaVersion = 0;
80 AssetRegistry* assetRegistry = nullptr;
81 Subasset defaultSubasset;
82 std::vector<Subasset> subassets;
83 std::filesystem::path metaFilePath;
84 std::filesystem::path baseAssetPath;
85 std::filesystem::path mountedAssetPath;
86
87 Grindstone::Editor::ImporterSettings importerSettings;
88 };
89}
Definition AssetRegistry.hpp:15
Definition Uuid.hpp:7
Definition ImporterSettings.hpp:8
Definition MetaFile.hpp:15