Dawn/src/dawntools/util/generator/SceneAssetGenerator.cpp

53 lines
1.7 KiB
C++

// 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 + "->font";
assetMap[asset->usageName] = "&" + asset->usageName + "->font";
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 + "\"));", "");
}