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