From e15bfac60f930877c940cac5662ceacc7e0f4826 Mon Sep 17 00:00:00 2001 From: LBPHacker Date: Fri, 5 May 2017 17:42:01 +0200 Subject: [PATCH] Moving conditional branches around --- src/gui/game/PropertyTool.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/gui/game/PropertyTool.cpp b/src/gui/game/PropertyTool.cpp index d261fde58..f1166e9ab 100644 --- a/src/gui/game/PropertyTool.cpp +++ b/src/gui/game/PropertyTool.cpp @@ -122,27 +122,14 @@ void PropertyWindow::SetProperty() } else { - if(properties[property->GetOption().second].Type == StructProperty::ParticleType) + int type; + if (properties[property->GetOption().second].Type == StructProperty::ParticleType && (type = sim->GetParticleType(value)) != -1) { - int type = sim->GetParticleType(value); - if(type != -1) - { + v = type; + #ifdef DEBUG - std::cout << "Got type from particle name" << std::endl; + std::cout << "Got type from particle name" << std::endl; #endif - v = type; - } - else - { - std::stringstream buffer(value); - buffer.exceptions(std::stringstream::failbit | std::stringstream::badbit); - buffer >> v; - } - if (property->GetOption().first == "type" && (v < 0 || v >= PT_NUM || !sim->elements[v].Enabled)) - { - new ErrorMessage("Could not set property", "Invalid particle type"); - return; - } } else { @@ -151,9 +138,17 @@ void PropertyWindow::SetProperty() buffer >> v; } } + + if (properties[property->GetOption().second].Type == StructProperty::ParticleType && (v < 0 || v >= PT_NUM || !sim->elements[v].Enabled)) + { + new ErrorMessage("Could not set property", "Invalid particle type"); + return; + } + #ifdef DEBUG std::cout << "Got int value " << v << std::endl; #endif + tool->propValue.Integer = v; break; }