aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/Template/Template.hpp
blob: 061cc07f524d0048d99531de5c62f77ba4456002 (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
#pragma once

#include "Model/Assets.hpp"
#include "cplt_fwd.hpp"

#include <filesystem>
#include <iosfwd>
#include <memory>
#include <string>

class Template : public Asset
{
public:
	enum Kind
	{
		KD_Table,

		InvalidKind,
		KindCount = InvalidKind,
	};

	using CategoryType = TemplateAssetList;

private:
	Kind mKind;

public:
	static const char* FormatKind(Kind kind);
	static std::unique_ptr<Template> CreateByKind(Kind kind);

	static bool IsInstance(const Template* tmpl);

	Template(Kind kind);
	~Template() override = default;

	Kind GetKind() const;

	virtual void ReadFromDataStream(InputDataStream& stream) = 0;
	virtual void WriteToDataStream(OutputDataStream& stream) const = 0;
};

class TemplateAssetList final : public AssetListTyped<Template>
{
private:
	// AC = Asset Creator
	std::string mACNewName;
	NameSelectionError mACNewNameError = NameSelectionError::Empty;
	Template::Kind mACNewKind = Template::InvalidKind;

public:
	// Inherit constructors
	using AssetListTyped::AssetListTyped;

protected:
	void DiscoverFiles(const std::function<void(SavedAsset)>& callback) const override;

	std::string RetrieveNameFromFile(const std::filesystem::path& file) const override;
	uuids::uuid RetrieveUuidFromFile(const std::filesystem::path& file) const override;
	std::filesystem::path RetrievePathFromAsset(const SavedAsset& asset) const override;

	bool SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const override;
	Template* LoadInstance(const SavedAsset& assetInfo) const override;
	Template* CreateInstance(const SavedAsset& assetInfo) const override;
	bool RenameInstanceOnDisk(const SavedAsset& assetInfo, std::string_view oldName) const override;

	void DisplayAssetCreator(ListState& state) override;
	void DisplayDetailsTable(ListState& state) const override;
};