// Copyright (c) 2023 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "SceneGenerator.hpp" using namespace Dawn; void SceneGenerator::generate( struct Scene *scene, struct ClassGenInfo &classInfo, struct MethodGenInfo &methodAssets, struct MethodGenInfo &methodInit ) { classInfo.clazz = scene->name; classInfo.constructorArgs = "DawnGame *game"; classInfo.extendArgs = "game"; std::string baseClassName = "Scene"; // Determine extends if(scene->extend.empty()) { classInfo.includes.push_back("scene/Scene.hpp"); } else { classInfo.includes.push_back(scene->extend + ".hpp"); // Get last slash of scene->extend auto lastSlash = scene->extend.find_last_of('/'); baseClassName = scene->extend; if(lastSlash != std::string::npos) { baseClassName = scene->extend.substr(lastSlash + 1); } } classInfo.extend = baseClassName; methodAssets.name = "getRequiredAssets"; methodAssets.isOverride = true; methodAssets.type = "std::vector"; line(&methodAssets.body, "auto assMan = &this->game->assetManager;", ""); methodInit.name = "stage"; methodInit.isOverride = true; if(scene->extend.empty()) { line(&methodAssets.body, "std::vector assets;", ""); } else { line(&methodAssets.body, "std::vector assets = " + baseClassName + "::getRequiredAssets();", ""); line(&methodInit.body, baseClassName + "::stage();", ""); } // Generate int32_t assetNumber = 0; int32_t childNumber = 0; int32_t componentNumber = 0; std::map assetMap; auto sceneItems = scene->items.begin(); while(sceneItems != scene->items.end()) { SceneItemGenerator::generate( assetNumber, componentNumber, childNumber, assetMap, classInfo.includes, &classInfo.publicProperties, &methodInit.body, &methodAssets.body, "", "this", &(*sceneItems), "" ); ++sceneItems; } // Seal methods line(&methodAssets.body, "return assets;", ""); }