Commit ac998769 authored by sm's avatar sm

Improve option conditional parsing

parent 29e4c0e3
......@@ -237,10 +237,6 @@ const NamedRgbColor& getSvgColor(int32_t nPal)
}
assert((nPal >= 0) && (nPal < getTotSvgColors()));
return s_aNamedRgbColors[nPal];
// sName = s_aNamedRgbColors[nPal].m_sName;
// nR = s_aNamedRgbColors[nPal].m_nR;
// nG = s_aNamedRgbColors[nPal].m_nG;
// nB = s_aNamedRgbColors[nPal].m_nB;
}
} // namespace CommonTheme
......
......@@ -418,6 +418,7 @@ private:
bool evalCondition(ConditionalCtx& oCtx, const xmlpp::Element* p0Element) const;
//
static std::runtime_error errorElementCannotDetermineTeamFromContext(ParserCtx& oCtx, const xmlpp::Element* p0Element);
static std::runtime_error errorElementCannotDeterminePlayerFromContext(ParserCtx& oCtx, const xmlpp::Element* p0Element);
private:
XmlConditionalParser(const XmlConditionalParser& oSource) = delete;
XmlConditionalParser& operator=(const XmlConditionalParser& oSource) = delete;
......
......@@ -19,7 +19,7 @@
#include "xmlconditionalparser.h"
#include "util.h"
#include <stmm-games/util.h>
#include <vector>
#include <cassert>
......@@ -118,6 +118,10 @@ std::runtime_error XmlConditionalParser::errorElementCannotDetermineTeamFromCont
{
return XmlCommonErrors::error(oCtx, p0Element, Util::s_sEmptyString, "Cannot determine team from context");
}
std::runtime_error XmlConditionalParser::errorElementCannotDeterminePlayerFromContext(ParserCtx& oCtx, const xmlpp::Element* p0Element)
{
return XmlCommonErrors::error(oCtx, p0Element, Util::s_sEmptyString, "Cannot determine player from context");
}
bool XmlConditionalParser::parseIntSetAttributes(ConditionalCtx& oCtx, const xmlpp::Element* p0Element
, const std::string& sMultiAttr, const std::string& sSeparatorAttr
, IntSet& oIntSet
......@@ -318,22 +322,37 @@ bool XmlConditionalParser::evalCondition(ConditionalCtx& oCtx, const xmlpp::Elem
if (!oPairOptionName.first) {
throw XmlCommonErrors::errorAttrNotFound(oCtx, p0Condition, s_sConditionalConditionOptionNameAttr);
}
const auto oPairOwnerType = parseOwnerType(oCtx, p0Condition, Util::s_sEmptyString);
OwnerType eOwnerType;
if (nTeam < 0) {
eOwnerType = OwnerType::GAME;
if (oPairOwnerType.first) {
eOwnerType = oPairOwnerType.second;
if (eOwnerType == OwnerType::TEAM) {
if (nTeam < 0) {
throw errorElementCannotDetermineTeamFromContext(oCtx, p0Condition);
}
} else if (eOwnerType == OwnerType::PLAYER) {
if (nMate < 0) {
throw errorElementCannotDeterminePlayerFromContext(oCtx, p0Condition);
}
}
} else {
if (nMate < 0) {
eOwnerType = OwnerType::TEAM;
if (nTeam < 0) {
eOwnerType = OwnerType::GAME;
} else {
eOwnerType = OwnerType::PLAYER;
if (nMate < 0) {
eOwnerType = OwnerType::TEAM;
} else {
eOwnerType = OwnerType::PLAYER;
}
}
}
const auto& refOption = p0AppPreferences->getAppConfig()->getOption(eOwnerType, sOptionName);
Variant oValue;
if (!refOption) {
throw XmlCommonErrors::error(oCtx, p0Condition, s_sConditionalConditionOptionNameAttr
, Util::stringCompose("Attribute '%1': %3 option with name '%2' not found", s_sConditionalConditionComplementAttr, sOptionName
, ( (eOwnerType == OwnerType::GAME) ? "game" : ( (eOwnerType == OwnerType::TEAM) ? "team" : "player" ) ) ));
, Util::stringCompose("Attribute '%1': %3 option with name '%2' not found", s_sConditionalConditionOptionNameAttr
, sOptionName
, ( (eOwnerType == OwnerType::GAME) ? "game" : ( (eOwnerType == OwnerType::TEAM) ? "team" : "player" ) ) ));
}
if (eOwnerType == OwnerType::GAME) {
oValue = p0AppPreferences->getOptionValue(sOptionName);
......
......@@ -130,7 +130,7 @@ set(STMMI_HEADERS
set(STMMI_SOURCES_DIR "${PROJECT_SOURCE_DIR}/src")
# Source files (and headers only used for building)
set(STMMI_SOURCES
#${STMMI_SOURCES_DIR}/level.cc
#${STMMI_SOURCES_DIR}/util.cc
${STMMI_SOURCES_DIR}/animations/backgroundanimation.cc
${STMMI_SOURCES_DIR}/animations/explosionanimation.cc
......
......@@ -20,20 +20,16 @@
#ifndef STMG_UTIL_H
#define STMG_UTIL_H
#include <stdint.h>
#include <stdexcept>
#include <list>
#include <set>
#include <vector>
#include <string>
#include <locale>
#include <sstream>
#include <initializer_list>
#include <type_traits>
#include <cassert>
#include <iostream>
#include <stdint.h>
namespace stmg
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment