Moved C++ tools out
This commit is contained in:
53
archive/dawntools/util/generator/SceneAssetGenerator.cpp
Normal file
53
archive/dawntools/util/generator/SceneAssetGenerator.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SceneAssetGenerator.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void SceneAssetGenerator::generate(
|
||||
std::map<std::string, std::string> &assetMap,
|
||||
int32_t &assetNumber,
|
||||
std::vector<std::string> *publicProperties,
|
||||
std::vector<std::string> *initBody,
|
||||
std::vector<std::string> *assetsBody,
|
||||
struct SceneAsset *asset,
|
||||
std::string tabs
|
||||
) {
|
||||
std::string assetType = "";
|
||||
|
||||
bool_t componentInit = true;
|
||||
if(asset->ref.empty()) {
|
||||
asset->usageName = "asset" + std::to_string(assetNumber++);
|
||||
} else {
|
||||
asset->usageName = asset->ref;
|
||||
}
|
||||
|
||||
switch(asset->type) {
|
||||
case SCENE_ASSET_TYPE_TEXTURE:
|
||||
assetType = "TextureAsset";
|
||||
assetMap[asset->fileName] = "&" + asset->usageName + "->texture";
|
||||
assetMap[asset->usageName] = "&" + asset->usageName + "->texture";
|
||||
break;
|
||||
|
||||
case SCENE_ASSET_TYPE_TRUETYPE_FONT:
|
||||
assetType = "TrueTypeAsset";
|
||||
assetMap[asset->fileName] = asset->usageName;
|
||||
assetMap[asset->usageName] = asset->usageName;
|
||||
break;
|
||||
|
||||
default:
|
||||
assertUnreachable("SceneAssetGenerator::generate: Unknown asset type");
|
||||
}
|
||||
|
||||
if(!asset->ref.empty()) {
|
||||
line(publicProperties, assetType + " *" + asset->usageName + " = nullptr;", "");
|
||||
line(initBody, asset->usageName + " = man->get<" + assetType + ">(\"" + asset->fileName + "\");", "");
|
||||
} else {
|
||||
line(initBody, "auto " + asset->usageName + " = man->get<" + assetType + ">(\"" + asset->fileName + "\");", "");
|
||||
}
|
||||
|
||||
line(assetsBody, "assets.push_back(man->get<" + assetType + ">(\"" + asset->fileName + "\"));", "");
|
||||
}
|
Reference in New Issue
Block a user