From a0d3fd9afdc82ac83aeeec011139a590d5ce7673 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 20 Mar 2024 10:09:29 +0300 Subject: [PATCH] xml 2d, 3d, 4d vectors shortcuts --- src/coders/xml.cpp | 8 ++++---- src/graphics/ui/gui_util.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coders/xml.cpp b/src/coders/xml.cpp index 2bd656de..34579835 100644 --- a/src/coders/xml.cpp +++ b/src/coders/xml.cpp @@ -36,7 +36,7 @@ bool Attribute::asBool() const { glm::vec2 Attribute::asVec2() const { size_t pos = text.find(','); if (pos == std::string::npos) { - throw std::runtime_error("invalid vec2 value "+escape_string(text)); + return glm::vec2(util::parse_double(text, 0, text.length())); } return glm::vec2( util::parse_double(text, 0, pos), @@ -48,7 +48,7 @@ glm::vec2 Attribute::asVec2() const { glm::vec3 Attribute::asVec3() const { size_t pos1 = text.find(','); if (pos1 == std::string::npos) { - throw std::runtime_error("invalid vec3 value "+escape_string(text)); + return glm::vec3(util::parse_double(text, 0, text.length())); } size_t pos2 = text.find(',', pos1+1); if (pos2 == std::string::npos) { @@ -65,7 +65,7 @@ glm::vec3 Attribute::asVec3() const { glm::vec4 Attribute::asVec4() const { size_t pos1 = text.find(','); if (pos1 == std::string::npos) { - throw std::runtime_error("invalid vec4 value "+escape_string(text)); + return glm::vec4(util::parse_double(text, 0, text.length())); } size_t pos2 = text.find(',', pos1+1); if (pos2 == std::string::npos) { @@ -99,7 +99,7 @@ glm::vec4 Attribute::asColor() const { } return glm::vec4(r / 255.f, g / 255.f, b / 255.f, a / 255.f); } else { - throw std::runtime_error("hex colors are only supported"); + return asVec4() / 255.f; } } diff --git a/src/graphics/ui/gui_util.cpp b/src/graphics/ui/gui_util.cpp index 5f10b8db..84f704a9 100644 --- a/src/graphics/ui/gui_util.cpp +++ b/src/graphics/ui/gui_util.cpp @@ -27,7 +27,7 @@ std::shared_ptr" ));