X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FInterpreter.cpp;h=79fe4f3de31454afcef6ae8b4508f782f56739e7;hb=215260d3f49f6bbeed7ee5f5f1da3a5ac4ecc111;hp=5d3b9fccba1dd63722aa49d1c966d71af3c8e614;hpb=b4a7dd75a2834dcf292da19a9ca44c527e163002;p=l2e.git diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index 5d3b9fc..79fe4f3 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -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::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::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);