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

38 lines
1.1 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> *initBody,
std::vector<std::string> *assetsBody,
struct SceneAsset *asset,
std::string tabs
) {
std::string assetType = "";
asset->usageName = "asset" + std::to_string(assetNumber++);
switch(asset->type) {
case SCENE_ASSET_TYPE_TEXTURE:
assetType = "TextureAsset";
assetMap[asset->fileName] = "&" + asset->usageName + "->texture";
break;
case SCENE_ASSET_TYPE_TRUETYPE_FONT:
assetType = "TrueTypeAsset";
assetMap[asset->fileName] = "&" + asset->usageName + "->font";
break;
default:
assertUnreachable();
}
line(initBody, "auto " + asset->usageName + " = man->get<" + assetType + ">(\"" + asset->fileName + "\");", "");
line(assetsBody, "assets.push_back(man->get<" + assetType + ">(\"" + asset->fileName + "\"));", "");
}