From 4b47c2ef4c10459420a324b43fc9fa26ec9f6cdc Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Thu, 21 Jan 2016 23:15:46 +0100 Subject: [PATCH] Add nesting to `SettingsLoader::getTriangleSurface` --- src/Application/SettingsLoader.cpp | 72 ++++++++++++++++++------------ 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/src/Application/SettingsLoader.cpp b/src/Application/SettingsLoader.cpp index ba48c5c..4a0cb46 100644 --- a/src/Application/SettingsLoader.cpp +++ b/src/Application/SettingsLoader.cpp @@ -171,43 +171,57 @@ bool SettingsLoader::save(SurfaceStack & surfaces, string fileName){ BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){ vector vertices; - xmlSettings->pushTag("vertex", 0); - vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), - xmlSettings->getValue("y", 0.0f))); - xmlSettings->popTag(); - - xmlSettings->pushTag("vertex", 1); - vertices.push_back(ofVec2f(xmlSettings->getValue("x", 100.0f), - xmlSettings->getValue("y", 0.0f))); - xmlSettings->popTag(); + if(xmlSettings->tagExists("vertex", 0)){ + xmlSettings->pushTag("vertex", 0); + vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), + xmlSettings->getValue("y", 0.0f))); + xmlSettings->popTag(); + } + + if(xmlSettings->tagExists("vertex", 1)){ + xmlSettings->pushTag("vertex", 1); + vertices.push_back(ofVec2f(xmlSettings->getValue("x", 100.0f), + xmlSettings->getValue("y", 0.0f))); + xmlSettings->popTag(); + } - xmlSettings->pushTag("vertex", 2); - vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), - xmlSettings->getValue("y", 100.0f))); - xmlSettings->popTag(); + if(xmlSettings->tagExists("vertex", 2)){ + xmlSettings->pushTag("vertex", 2); + vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), + xmlSettings->getValue("y", 100.0f))); + xmlSettings->popTag(); + } xmlSettings->popTag(); // vertices - xmlSettings->pushTag("texCoords"); - vector texCoords; - xmlSettings->pushTag("texCoord", 0); - texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), - xmlSettings->getValue("y", 0.0f))); - xmlSettings->popTag(); - - xmlSettings->pushTag("texCoord", 1); - texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 1.0f), - xmlSettings->getValue("y", 0.0f))); - xmlSettings->popTag(); + if(xmlSettings->tagExists("texCoords")){ + xmlSettings->pushTag("texCoords"); + + if(xmlSettings->tagExists("texCoord", 0)){ + xmlSettings->pushTag("texCoord", 0); + texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), + xmlSettings->getValue("y", 0.0f))); + xmlSettings->popTag(); + } + + if(xmlSettings->tagExists("texCoord", 1)){ + xmlSettings->pushTag("texCoord", 1); + texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 1.0f), + xmlSettings->getValue("y", 0.0f))); + xmlSettings->popTag(); + } - xmlSettings->pushTag("texCoord", 2); - texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), - xmlSettings->getValue("y", 1.0f))); - xmlSettings->popTag(); + if(xmlSettings->tagExists("texCoord", 2)){ + xmlSettings->pushTag("texCoord", 2); + texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), + xmlSettings->getValue("y", 1.0f))); + xmlSettings->popTag(); + } - xmlSettings->popTag(); // texCoords + xmlSettings->popTag(); // texCoords + } // Create and add a triangle surface BaseSurface * triangleSurface =