mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-07-14 15:47:39 +00:00
Move PGN export to the right place
This commit is contained in:
parent
9cba705e66
commit
cb4f5ada5c
6 changed files with 61 additions and 54 deletions
|
@ -81,7 +81,7 @@ void PGNGameBase::Save(std::vector<std::uint32_t> to_ignore,
|
|||
several = true;
|
||||
}
|
||||
std::shared_ptr<Game> g = GetCurrentGame();
|
||||
new_pgn.Write(g->GetPGN());
|
||||
new_pgn.Write(GetPGN(g));
|
||||
}
|
||||
id++;
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ void PGNGameBase::Save(std::vector<std::uint32_t> to_ignore,
|
|||
several = true;
|
||||
}
|
||||
std::shared_ptr<Game> g = current->GetCurrentGame();
|
||||
new_pgn.Write(g->GetPGN());
|
||||
new_pgn.Write(GetPGN(g));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ void PGNGameBase::Save(std::vector<std::uint32_t> to_ignore,
|
|||
} else {
|
||||
several = true;
|
||||
}
|
||||
new_pgn.Write(g->GetPGN());
|
||||
new_pgn.Write(GetPGN(g));
|
||||
}
|
||||
|
||||
new_pgn.Close();
|
||||
|
@ -126,8 +126,56 @@ void PGNGameBase::Export(std::shared_ptr<GameBase> base) {
|
|||
several = true;
|
||||
}
|
||||
std::shared_ptr<Game> g = base->GetCurrentGame();
|
||||
new_pgn.Write(g->GetPGN());
|
||||
new_pgn.Write(GetPGN(g));
|
||||
}
|
||||
|
||||
new_pgn.Close();
|
||||
}
|
||||
|
||||
std::string PGNGameBase::GetPGN(std::shared_ptr<Game> g) {
|
||||
std::string pgn;
|
||||
HalfMove *m=g->GetMoves();
|
||||
|
||||
for (auto const &element : g->ListTags()) {
|
||||
pgn += '[' + element + " \"" + g->GetTag(element) + "\"]\n";
|
||||
}
|
||||
pgn += GetMovesPGN(m,m->IsABlackMove());
|
||||
|
||||
pgn += " " + g->GetResult();
|
||||
return (pgn);
|
||||
}
|
||||
|
||||
std::string PGNGameBase::GetMovesPGN(HalfMove *m, bool needDots) {
|
||||
std::string part;
|
||||
bool newNeedDots = false;
|
||||
|
||||
if (!m->IsABlackMove() || needDots) {
|
||||
part += std::to_string(m->Number) + ".";
|
||||
if (needDots) {
|
||||
part += "..";
|
||||
}
|
||||
}
|
||||
part += m->move;
|
||||
|
||||
if (m->GetNbLineComment() > 0) {
|
||||
part += " {";
|
||||
part += m->GetComment();
|
||||
part += "}";
|
||||
newNeedDots = true;
|
||||
}
|
||||
|
||||
if (m->GetVariations().size() > 0) {
|
||||
newNeedDots = true;
|
||||
for (HalfMove *v : m->GetVariations()) {
|
||||
part += " (";
|
||||
part += GetMovesPGN(v, m->IsABlackMove());
|
||||
part += ")";
|
||||
}
|
||||
}
|
||||
|
||||
if (m->GetMainline() != NULL) {
|
||||
part += " " + GetMovesPGN(m->GetMainline(), !m->IsABlackMove() && newNeedDots);
|
||||
}
|
||||
|
||||
return (part);
|
||||
}
|
|
@ -18,4 +18,6 @@ public:
|
|||
std::vector<std::shared_ptr<Game>> new_games);
|
||||
void Reset();
|
||||
void Export(std::shared_ptr<GameBase> base);
|
||||
static std::string GetMovesPGN(HalfMove *m, bool needDots);
|
||||
static std::string GetPGN(std::shared_ptr<Game> g);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue