Skip to content

Commit

Permalink
rework the chart entry save/load in playlists and include rates
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed May 13, 2017
1 parent 1909f38 commit 6bffed9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
52 changes: 28 additions & 24 deletions src/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,47 @@ void Chart::FromKey(const string& ck) {
Song* song = SONGMAN->GetSongByChartkey(ck);
if (song) {
Steps* steps = SONGMAN->GetStepsByChartkey(ck);
key = ck;

lastpack = song->GetSongDir();
lastsong = song->GetDisplayMainTitle();
lastdiff = steps->GetDifficulty();
loaded = true;
songptr = song;
stepsptr = steps;
key = ck;
LOG->Trace(songptr->GetDisplayMainTitle());
}
loaded = false;
}

XNode* Chart::CreateNode() const {
XNode* ch = new XNode("Chart");
ch->AppendAttr("Key", key);
ch->AppendAttr("Pack", lastpack);
ch->AppendAttr("Song", lastsong);
ch->AppendAttr("Steps", DifficultyToString(lastdiff));
ch->AppendAttr("Rate", ssprintf("%.3f",rate));
return ch;
}

void Chart::LoadFromNode(const XNode* node) {
ASSERT(node->GetName() == "Chart");
RString s;
node->GetAttrValue("Pack", lastpack);
node->GetAttrValue("Song", lastsong);
//node->GetAttrValue("Steps", s); lastdiff = StringToDifficulty(s);
node->GetAttrValue("Rate", s); rate = StringToFloat(s);
node->GetAttrValue("Key", s); key = s;

// check if this chart is loaded and overwrite any last-seen values with updated ones
FromKey(key);
}

XNode* Playlist::CreateNode() const {
XNode* pl = new XNode("Playlist");
pl->AppendAttr("Name", name);
FOREACH_CONST(Chart, chartlist, ch) {
XNode* chart = new XNode(ch->key);
Song* song = SONGMAN->GetSongByChartkey(ch->key);
if (song) {
chart->AppendAttr("Pack", song->m_sGroupName);
chart->AppendAttr("Song", song->GetDisplayMainTitle());

}
else {
chart->AppendAttr("Pack", ch->lastpack);
chart->AppendAttr("Song", ch->lastsong);
}
pl->AppendChild(chart);
}
FOREACH_CONST(Chart, chartlist, ch)
pl->AppendChild(ch->CreateNode());

return pl;
}
Expand All @@ -184,15 +196,7 @@ void Playlist::LoadFromNode(const XNode* node) {
node->GetAttrValue("Name", name);
FOREACH_CONST_Child(node, chart) {
Chart ch;
ch.key = chart->GetName();
chart->GetAttrValue("Pack", ch.lastpack);
chart->GetAttrValue("Song", ch.lastsong);

Song* song = SONGMAN->GetSongByChartkey(ch.key);
if (song) {
ch.lastpack = song->m_sGroupName;
ch.lastsong = song->GetDisplayMainTitle();
}
ch.LoadFromNode(chart);
chartlist.emplace_back(ch);
}

Expand Down
8 changes: 5 additions & 3 deletions src/SongManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ struct Chart {
string key;
RString lastsong;
RString lastpack;
Difficulty lastdiff;

Difficulty lastdiff = Difficulty_Invalid;
float rate = 1.f;
Song* songptr;
Steps* stepsptr;

bool loaded;
bool loaded = false;
void FromKey(const string& ck);
XNode * CreateNode() const;
void LoadFromNode(const XNode * node);
};

struct Playlist {
Expand Down

0 comments on commit 6bffed9

Please sign in to comment.