]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/Interpreter.cpp
added interpretation of colors
[l2e.git] / src / loader / Interpreter.cpp
index 5d3b9fccba1dd63722aa49d1c966d71af3c8e614..79fe4f3de31454afcef6ae8b4508f782f56739e7 100644 (file)
@@ -35,6 +35,7 @@ using common::Item;
 using common::Spell;
 using common::TargetingMode;
 using graphics::Animation;
+using graphics::Color;
 using graphics::Font;
 using graphics::Frame;
 using graphics::Gauge;
@@ -127,6 +128,19 @@ bool Interpreter::GetBoolean(const std::string &name) const {
        }
 }
 
+const Color &Interpreter::GetColor(const std::string &name) const {
+       map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+       if (i != parsedDefinitions.end()) {
+               if (i->second.type == COLOR) {
+                       return colors[i->second.index];
+               } else {
+                       throw Error("cannot cast " + i->second.dfn->TypeName() + " to Color");
+               }
+       } else {
+               throw Error("access to undefined Color " + name);
+       }
+}
+
 Font *Interpreter::GetFont(const std::string &name) {
        map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
        if (i != parsedDefinitions.end()) {
@@ -356,7 +370,8 @@ void Interpreter::ReadLiteral(const Definition &dfn) {
                        parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, BOOLEAN, booleans.size() - 1)));
                        break;
                case Literal::COLOR:
-                       throw Error("unhandled literal: color");
+                       colors.push_back(Color(dfn.GetLiteral()->GetRed(), dfn.GetLiteral()->GetGreen(), dfn.GetLiteral()->GetBlue(), dfn.GetLiteral()->GetAlpha()));
+                       parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, COLOR, colors.size() - 1)));
                        break;
                case Literal::NUMBER:
                        numbers.push_back(dfn.GetLiteral()->GetNumber());
@@ -418,6 +433,15 @@ bool Interpreter::GetBoolean(const Value &v) {
        }
 }
 
+Color Interpreter::GetColor(const Value &v) {
+       if (v.IsLiteral()) {
+               return Color(v.GetLiteral().GetRed(), v.GetLiteral().GetGreen(), v.GetLiteral().GetBlue(), v.GetLiteral().GetAlpha());
+       } else {
+               ReadDefinition(source.GetDefinition(v.GetIdentifier()));
+               return GetColor(v.GetIdentifier());
+       }
+}
+
 Font *Interpreter::GetFont(const Value &v) {
        if (v.IsLiteral()) {
                Font *f(new Font);