Els objectes de Text es precarreguen al inici
This commit is contained in:
@@ -42,6 +42,7 @@ Resource::Resource()
|
||||
loadAnimations();
|
||||
loadDemoData();
|
||||
addPalettes();
|
||||
createText();
|
||||
createTextures();
|
||||
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
||||
}
|
||||
@@ -106,6 +107,21 @@ std::shared_ptr<TextFile> Resource::getTextFile(const std::string &name)
|
||||
throw std::runtime_error("TextFile no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene el objeto de texto a partir de un nombre
|
||||
std::shared_ptr<Text> Resource::getText(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(texts_.begin(), texts_.end(), [&name](const auto &t)
|
||||
{ return t.name == name; });
|
||||
|
||||
if (it != texts_.end())
|
||||
{
|
||||
return it->text;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Text no encontrado " << name << std::endl;
|
||||
throw std::runtime_error("Text no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
AnimationsFileBuffer &Resource::getAnimation(const std::string &name)
|
||||
{
|
||||
@@ -239,7 +255,7 @@ void Resource::createTextures()
|
||||
};
|
||||
|
||||
std::cout << "\n>> CREATING TEXTURES" << std::endl;
|
||||
auto text = std::make_unique<Text>(getTexture("04b_25.png"), getTextFile("04b_25.txt"));
|
||||
auto text = getText("04b_25");
|
||||
|
||||
// Tamaño normal
|
||||
std::vector<NameAndText> strings = {
|
||||
@@ -270,3 +286,21 @@ void Resource::createTextures()
|
||||
printWithDots("Texture : ", s.name, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
|
||||
// Crea los objetos de texto
|
||||
void Resource::createText()
|
||||
{
|
||||
std::cout << "\n>> CREATING TEXT_OBJECTS" << std::endl;
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> resources = {
|
||||
{"04b_25", "04b_25.png"},
|
||||
{"8bithud", "8bithud.png"},
|
||||
{"nokia", "nokia.png"},
|
||||
{"smb2", "smb2.gif"}};
|
||||
|
||||
for (const auto &resource : resources)
|
||||
{
|
||||
texts_.emplace_back(ResourceText(resource.first, std::make_shared<Text>(getTexture(resource.second), getTextFile(resource.first + ".txt"))));
|
||||
printWithDots("Text : ", resource.first, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user