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