diff --git a/src/level/parser/parserparam.cpp b/src/level/parser/parserparam.cpp index 37773efa..3ccd7f9c 100644 --- a/src/level/parser/parserparam.cpp +++ b/src/level/parser/parserparam.cpp @@ -28,6 +28,7 @@ #include "common/resources/resourcemanager.h" #include "level/robotmain.h" +#include "level/scoreboard.h" #include "level/parser/parser.h" @@ -916,6 +917,26 @@ int CLevelParserParam::AsResearchFlag(int def) return AsResearchFlag(); } +int CLevelParserParam::ToSortType(std::string value) +{ + if (value == "Points" ) return SORT_POINTS; + if (value == "Name" ) return SORT_ID; + return Cast(value, "sorttype"); +} + +int CLevelParserParam::AsSortType() +{ + if (m_empty) + throw CLevelParserExceptionMissingParam(this); + return ToSortType(m_value); +} + +int CLevelParserParam::AsSortType(int def) +{ + if (m_empty) + return def; + return AsSortType(); +} Gfx::PyroType CLevelParserParam::ToPyroType(std::string value) { diff --git a/src/level/parser/parserparam.h b/src/level/parser/parserparam.h index c72be4f0..1261bb65 100644 --- a/src/level/parser/parserparam.h +++ b/src/level/parser/parserparam.h @@ -85,6 +85,7 @@ public: Gfx::EngineObjectType AsTerrainType(); int AsBuildFlag(); int AsResearchFlag(); + int AsSortType(); Gfx::PyroType AsPyroType(); Gfx::CameraType AsCameraType(); MissionType AsMissionType(); @@ -108,6 +109,7 @@ public: Gfx::EngineObjectType AsTerrainType(Gfx::EngineObjectType def); int AsBuildFlag(int def); int AsResearchFlag(int def); + int AsSortType(int def); Gfx::PyroType AsPyroType(Gfx::PyroType def); Gfx::CameraType AsCameraType(Gfx::CameraType def); MissionType AsMissionType(MissionType def); @@ -139,6 +141,7 @@ private: Gfx::EngineObjectType ToTerrainType(std::string value); int ToBuildFlag(std::string value); int ToResearchFlag(std::string value); + int ToSortType(std::string value); Gfx::PyroType ToPyroType(std::string value); Gfx::CameraType ToCameraType(std::string value); MissionType ToMissionType(std::string value); diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index d12d8af5..eed48aae 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -3566,16 +3566,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetCommand() == "ScoreboardSortType" && !resetObject) { - if (line->GetParam("SortBy")->AsString() == "Points") - { - // Sort teams by points - m_scoreboard->SetSortType(SORT_POINTS); - } - else if (line->GetParam("SortBy")->AsString() == "Name") - { - // Sort teams alphabetically - m_scoreboard->SetSortType(SORT_ID); - } + m_scoreboard->SetSortType(static_cast(line->GetParam("sort")->AsSortType() ) ); continue; } diff --git a/src/level/scoreboard.h b/src/level/scoreboard.h index f691e176..cd964de3 100644 --- a/src/level/scoreboard.h +++ b/src/level/scoreboard.h @@ -61,7 +61,7 @@ enum SortType * \section example Usage example * \code{.scene} * Scoreboard enable=true // enable the scoreboard - * ScoreboardSortType SortBy="Name" // sort teams alphabetically, another option is SortBy="Points", sorting teams in order of points + * ScoreboardSortType sort=Name // sort teams alphabetically, another option is sort=Points, sorting teams in order of points * ScoreboardKillRule type=WheeledShooter team=1 score=500 // destruction of team 1's WheeledShooter gives 100 points to the team that destroyed it * ScoreboardKillRule type=TargetBot score=100 // destruction of TargetBot (any team) gives 100 points * ScoreboardEndTakeRule score=1000 // completion of EndMissionTake objectives for any team results in 1000 points for that team