Interface to create and save new assets that are internal: Prefabs, Scenes, Materials
This commit is contained in:
parent
cd62dbbb25
commit
0182c90a21
|
@ -0,0 +1,23 @@
|
|||
/******************************************************************************
|
||||
* \file SHMaterialAsset.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date 29 October 2022
|
||||
* \brief
|
||||
*
|
||||
* \copyright Copyright (c) 2021 Digipen Institute of Technology. Reproduction
|
||||
* or disclosure of this file or its contents without the prior
|
||||
* written consent of Digipen Institute of Technology is prohibited.
|
||||
******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Assets/Asset Types/SHAssetData.h"
|
||||
#include <string>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
struct SHMaterialAsset : SHAssetData
|
||||
{
|
||||
std::string name;
|
||||
std::string data;
|
||||
};
|
||||
}
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "Assets/Asset Types/SHSceneAsset.h"
|
||||
#include "Assets/Asset Types/SHPrefabAsset.h"
|
||||
#include "Assets/Asset Types/SHMaterialAsset.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
@ -52,7 +53,10 @@ namespace SHADE
|
|||
}
|
||||
else if (path.extension().string() == MATERIAL_EXTENSION)
|
||||
{
|
||||
auto data = //TODO make material class
|
||||
auto data = new SHMaterialAsset();
|
||||
data->name = path.stem().string();
|
||||
data->data = std::move(content);
|
||||
result = data;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
@ -82,7 +86,8 @@ namespace SHADE
|
|||
}
|
||||
else if (path.extension().string() == MATERIAL_EXTENSION)
|
||||
{
|
||||
auto material = //todo
|
||||
auto material = dynamic_cast<SHMaterialAsset const*>(data);
|
||||
file << material->data;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
|
|
@ -61,6 +61,11 @@ constexpr std::string_view ASSET_ROOT {"Assets"};
|
|||
constexpr std::string_view ASSET_ROOT {"../../Assets"};
|
||||
#endif
|
||||
|
||||
// INTERNAL ASSET PATHS
|
||||
constexpr std::string_view SCENE_FOLDER{ "/Scenes/" };
|
||||
constexpr std::string_view PREFAB_FOLDER{ "/Prefabs/" };
|
||||
constexpr std::string_view MATERIAL_FOLDER{ "/Materials/" };
|
||||
|
||||
|
||||
// ASSET EXTENSIONS
|
||||
constexpr std::string_view META_EXTENSION {".shmeta"};
|
||||
|
|
|
@ -148,40 +148,74 @@ namespace SHADE
|
|||
****************************************************************************/
|
||||
AssetID SHAssetManager::CreateNewAsset(AssetType type, AssetName name) noexcept
|
||||
{
|
||||
AssetID id{ GenerateAssetID(type) };
|
||||
SHAsset meta;
|
||||
meta.id = id;
|
||||
meta.type = type;
|
||||
std::string newPath{ ASSET_ROOT };
|
||||
switch (type)
|
||||
{
|
||||
case AssetType::PREFAB:
|
||||
newPath += PREFAB_FOLDER;
|
||||
break;
|
||||
|
||||
std::string folder;
|
||||
//TODO implement folder choosing
|
||||
//switch (type)
|
||||
//{
|
||||
//default:
|
||||
// folder = "";
|
||||
// break;
|
||||
//}
|
||||
AssetPath path{ std::string{ASSET_ROOT} + folder + name + SHAssetMetaHandler::GetExtensionFromType(type) };
|
||||
case AssetType::SCENE:
|
||||
newPath += SCENE_FOLDER;
|
||||
break;
|
||||
|
||||
SHAssetMetaHandler::WriteMetaData(meta);
|
||||
case AssetType::MATERIAL:
|
||||
newPath += MATERIAL_FOLDER;
|
||||
break;
|
||||
|
||||
assetCollection.push_back(meta);
|
||||
default:
|
||||
SHLOG_ERROR("Asset type of {} not an internal asset type, cannot be created", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto id = GenerateAssetID(type);
|
||||
|
||||
assetCollection.emplace_back(
|
||||
name,
|
||||
id,
|
||||
type,
|
||||
newPath
|
||||
);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
AssetID SHAssetManager::CreateAsset(AssetName name, AssetType type) noexcept
|
||||
{
|
||||
AssetID id = GenerateAssetID(type);
|
||||
void SHAssetManager::SaveAsset(AssetID id) noexcept
|
||||
{
|
||||
for (auto const& asset : assetCollection)
|
||||
{
|
||||
if (asset.id == id)
|
||||
{
|
||||
if (
|
||||
asset.type == AssetType::SCENE ||
|
||||
asset.type == AssetType::PREFAB ||
|
||||
asset.type == AssetType::MATERIAL
|
||||
)
|
||||
{
|
||||
auto const data = assetData[id];
|
||||
loaders[static_cast<size_t>(asset.type)]->Write(data, asset.path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SHLOG_WARNING("Asset id: {} not an internal asset type, save cannot be triggered", id);
|
||||
}
|
||||
|
||||
//AssetID SHAssetManager::CreateAsset(AssetName name, AssetType type) noexcept
|
||||
//{
|
||||
// AssetID id = GenerateAssetID(type);
|
||||
|
||||
// assetCollection.emplace_back(
|
||||
// name,
|
||||
// id,
|
||||
// type,
|
||||
// GenerateNewPath(name, type)
|
||||
// );
|
||||
// return id;
|
||||
//}
|
||||
|
||||
|
||||
assetCollection.emplace_back(
|
||||
name,
|
||||
id,
|
||||
type,
|
||||
GenerateNewPath(name, type)
|
||||
);
|
||||
return id;
|
||||
}
|
||||
/****************************************************************************
|
||||
* \brief Import new asset from outside editor window.
|
||||
*
|
||||
|
|
|
@ -59,8 +59,8 @@ namespace SHADE
|
|||
* \param name of resource
|
||||
* \return resource id generated for new asset
|
||||
****************************************************************************/
|
||||
static AssetID CreateNewAsset(AssetType, AssetName) noexcept;
|
||||
static AssetID CreateAsset(AssetName name, AssetType type) noexcept;
|
||||
static AssetID CreateNewAsset(AssetType type, AssetName name) noexcept;
|
||||
static void SaveAsset(AssetID id) noexcept;
|
||||
|
||||
/****************************************************************************
|
||||
* \brief Import new resource from outside editor window.
|
||||
|
@ -101,6 +101,9 @@ namespace SHADE
|
|||
|
||||
static void CompileAll() noexcept;
|
||||
|
||||
//TODO use this function to create asset data internall at all calls to generate id
|
||||
//static AssetID CreateAsset(AssetName name, AssetType type) noexcept;
|
||||
|
||||
static FMOD::System* audioSystem;
|
||||
static std::unordered_map<AssetID,SHSound>* audioSoundList;
|
||||
|
||||
|
|
Loading…
Reference in New Issue