// Copyright (c) 2023 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "SceneItemComponentGenerator.hpp" using namespace Dawn; void SceneItemComponentGenerator::generate( std::map &assetMap, int32_t &componentNumber, std::vector &includes, std::string itemRef, std::vector *publicProperties, std::vector *initBody, struct SceneItemComponent *component, std::string tabs ) { auto componentName = "cmp" + std::to_string(componentNumber++); bool_t componentInit = true; if(component->ref.size() > 0) { componentInit = false; componentName = component->ref; line(publicProperties, component->type + " *" + component->ref + " = nullptr;", ""); } // Initialize line(initBody, (componentInit ? "auto " : "") + componentName + " = " + itemRef + "->addComponent<" + component->type + ">();", ""); // Now set each property auto itValues = component->values.begin(); while(itValues != component->values.end()) { auto value = itValues->second; if(assetMap.find(value) != assetMap.end()) { value = assetMap[value]; } line(initBody, componentName + "->" + itValues->first + " = " + value + ";", ""); ++itValues; } includes.push_back(component->include); }