mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 23:30:04 +00:00
Parse title from placefile
This commit is contained in:
parent
4ee7731023
commit
ae1bca3602
2 changed files with 22 additions and 8 deletions
|
|
@ -84,11 +84,13 @@ public:
|
||||||
*/
|
*/
|
||||||
std::vector<std::shared_ptr<DrawItem>> GetDrawItems();
|
std::vector<std::shared_ptr<DrawItem>> GetDrawItems();
|
||||||
|
|
||||||
|
std::string title() const;
|
||||||
std::unordered_map<std::size_t, std::shared_ptr<Font>> fonts();
|
std::unordered_map<std::size_t, std::shared_ptr<Font>> fonts();
|
||||||
std::shared_ptr<Font> font(std::size_t i);
|
std::shared_ptr<Font> font(std::size_t i);
|
||||||
|
|
||||||
static std::shared_ptr<Placefile> Load(const std::string& filename);
|
static std::shared_ptr<Placefile> Load(const std::string& filename);
|
||||||
static std::shared_ptr<Placefile> Load(std::istream& is);
|
static std::shared_ptr<Placefile> Load(const std::string& name,
|
||||||
|
std::istream& is);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Impl;
|
class Impl;
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ public:
|
||||||
static void ProcessEscapeCharacters(std::string& s);
|
static void ProcessEscapeCharacters(std::string& s);
|
||||||
static void TrimQuotes(std::string& s);
|
static void TrimQuotes(std::string& s);
|
||||||
|
|
||||||
|
std::string title_ {};
|
||||||
std::chrono::seconds refresh_ {-1};
|
std::chrono::seconds refresh_ {-1};
|
||||||
|
|
||||||
// Parsing state
|
// Parsing state
|
||||||
|
|
@ -84,6 +85,11 @@ std::vector<std::shared_ptr<Placefile::DrawItem>> Placefile::GetDrawItems()
|
||||||
return p->drawItems_;
|
return p->drawItems_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Placefile::title() const
|
||||||
|
{
|
||||||
|
return p->title_;
|
||||||
|
}
|
||||||
|
|
||||||
std::unordered_map<std::size_t, std::shared_ptr<Placefile::Font>>
|
std::unordered_map<std::size_t, std::shared_ptr<Placefile::Font>>
|
||||||
Placefile::fonts()
|
Placefile::fonts()
|
||||||
{
|
{
|
||||||
|
|
@ -104,13 +110,16 @@ std::shared_ptr<Placefile> Placefile::Load(const std::string& filename)
|
||||||
{
|
{
|
||||||
logger_->debug("Loading placefile: {}", filename);
|
logger_->debug("Loading placefile: {}", filename);
|
||||||
std::ifstream f(filename, std::ios_base::in);
|
std::ifstream f(filename, std::ios_base::in);
|
||||||
return Load(f);
|
return Load(filename, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Placefile> Placefile::Load(std::istream& is)
|
std::shared_ptr<Placefile> Placefile::Load(const std::string& name,
|
||||||
|
std::istream& is)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Placefile> placefile = std::make_shared<Placefile>();
|
std::shared_ptr<Placefile> placefile = std::make_shared<Placefile>();
|
||||||
|
|
||||||
|
placefile->p->title_ = name;
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (scwx::util::getline(is, line))
|
while (scwx::util::getline(is, line))
|
||||||
{
|
{
|
||||||
|
|
@ -167,6 +176,7 @@ std::shared_ptr<Placefile> Placefile::Load(std::istream& is)
|
||||||
|
|
||||||
void Placefile::Impl::ProcessLine(const std::string& line)
|
void Placefile::Impl::ProcessLine(const std::string& line)
|
||||||
{
|
{
|
||||||
|
static const std::string titleKey_ {"Title:"};
|
||||||
static const std::string thresholdKey_ {"Threshold:"};
|
static const std::string thresholdKey_ {"Threshold:"};
|
||||||
static const std::string hsluvKey_ {"HSLuv:"};
|
static const std::string hsluvKey_ {"HSLuv:"};
|
||||||
static const std::string colorKey_ {"Color:"};
|
static const std::string colorKey_ {"Color:"};
|
||||||
|
|
@ -189,7 +199,13 @@ void Placefile::Impl::ProcessLine(const std::string& line)
|
||||||
// When tokenizing, add one additional delimiter to discard unexpected
|
// When tokenizing, add one additional delimiter to discard unexpected
|
||||||
// parameters (where appropriate)
|
// parameters (where appropriate)
|
||||||
|
|
||||||
if (boost::istarts_with(line, thresholdKey_))
|
if (boost::istarts_with(line, titleKey_))
|
||||||
|
{
|
||||||
|
// Title: title
|
||||||
|
title_ = line.substr(titleKey_.size());
|
||||||
|
boost::trim(title_);
|
||||||
|
}
|
||||||
|
else if (boost::istarts_with(line, thresholdKey_))
|
||||||
{
|
{
|
||||||
// Threshold: nautical_miles
|
// Threshold: nautical_miles
|
||||||
std::vector<std::string> tokenList =
|
std::vector<std::string> tokenList =
|
||||||
|
|
@ -394,10 +410,6 @@ void Placefile::Impl::ProcessLine(const std::string& line)
|
||||||
{
|
{
|
||||||
objectStack_.pop_back();
|
objectStack_.pop_back();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
logger_->warn("End found without Object");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (boost::istarts_with(line, lineKey_))
|
else if (boost::istarts_with(line, lineKey_))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue