Skip to content

Commit

Permalink
allow 3.95 importing again, need to figure this out more but this is …
Browse files Browse the repository at this point in the history
…for eze's profile atm
  • Loading branch information
MinaciousGrace committed Jun 2, 2017
1 parent 853a9c1 commit ad58aa3
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 18 deletions.
50 changes: 50 additions & 0 deletions src/HighScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ struct HighScoreImpl
RString NoteRowsToString(vector<int> v) const;
vector<int> NoteRowsToVector(RString s);

bool is39import = false;

bool operator==( const HighScoreImpl& other ) const;
bool operator!=( const HighScoreImpl& other ) const { return !(*this == other); }
};
Expand Down Expand Up @@ -468,6 +470,52 @@ void HighScoreImpl::LoadFromNode(const XNode *pNode)
UnloadReplayData();
}
// Validate input.

// 3.9 conversion stuff (wtf is this code??) -mina
if (pTapNoteScores)
FOREACH_ENUM(TapNoteScore, tns) {
pTapNoteScores->GetChildValue(TapNoteScoreToString(tns), iTapNoteScores[tns]);
if (tns == TNS_W1 && iTapNoteScores[tns] == 0) {
int old = iTapNoteScores[tns];
pTapNoteScores->GetChildValue("Marvelous", iTapNoteScores[tns]);

// only mark as import if loading the other tag changes the values
if(old != iTapNoteScores[tns])
is39import = true;
}
else if (tns == TNS_W2 && iTapNoteScores[tns] == 0)
pTapNoteScores->GetChildValue("Perfect", iTapNoteScores[tns]);
else if (tns == TNS_W3 && iTapNoteScores[tns] == 0)
pTapNoteScores->GetChildValue("Great", iTapNoteScores[tns]);
else if (tns == TNS_W4 && iTapNoteScores[tns] == 0)
pTapNoteScores->GetChildValue("Good", iTapNoteScores[tns]);
else if (tns == TNS_W5 && iTapNoteScores[tns] == 0)
pTapNoteScores->GetChildValue("Boo", iTapNoteScores[tns]);
}

if (pHoldNoteScores)
FOREACH_ENUM(HoldNoteScore, hns) {
pHoldNoteScores->GetChildValue(HoldNoteScoreToString(hns), iHoldNoteScores[hns]);
if (hns == HNS_Held && iHoldNoteScores[hns] == 0)
pHoldNoteScores->GetChildValue("OK", iHoldNoteScores[hns]);
else if (hns == HNS_LetGo && iHoldNoteScores[hns] == 0)
pHoldNoteScores->GetChildValue("NG", iHoldNoteScores[hns]);
}

int basecmod = 0;

// 3.9 doesnt save rates lol....
if (is39import && basecmod > 0) {
string cmod = sModifiers.substr(0, sModifiers.find_first_of(","));
if (cmod.substr(0, 1) == "C") {
int playedcmod = StringToInt(cmod.substr(1, cmod.size()));
float estrate = static_cast<float>(basecmod) / static_cast<float>(playedcmod);
int herp = lround(estrate * 10);
estrate = herp / 10.f;
fMusicRate = estrate;
}
}

grade = clamp( grade, Grade_Tier01, Grade_Failed );
}

Expand Down Expand Up @@ -593,6 +641,8 @@ bool HighScore::IsEmpty() const
return true;
}

bool HighScore::Is39import() const { return m_Impl->is39import; }

string HighScore::GetName() const { return m_Impl->sName; }
string HighScore::GetChartKey() const { return m_Impl->ChartKey; }
int HighScore::GetSSRCalcVersion() const { return m_Impl->SSRCalcVersion; }
Expand Down
2 changes: 2 additions & 0 deletions src/HighScore.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ struct HighScore
void UnloadReplayData();
void ResetSkillsets();

bool Is39import() const;

string GetDisplayName() const;

// Mina stuff - Mina
Expand Down
69 changes: 51 additions & 18 deletions src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,8 @@ void Profile::ImportScoresToEtterna() {
int notloaded = 0;
LOG->Trace("Beginning import of stats.xml scores");

const vector<Song*>& songs = SONGMAN->GetAllSongs();

string ck;
FOREACHM(SongID, HighScoresForASong, m_SongHighScores, i) {
SongID id = i->first;
Expand Down Expand Up @@ -1978,22 +1980,47 @@ void Profile::ImportScoresToEtterna() {
for (size_t i = 0; i < hsv.size(); ++i) {
HighScore hs = hsv[i];
// ignore historic key and just load from here since the hashing function was changed anyway
hs.SetChartKey(ck);
hs.SetChartKey(ck);
SCOREMAN->AddScore(hs);
++loaded;
}
continue;
}

// if we still haven't correlated a score to a key, match by song title and number of notes
// score import is meant to be a qol and pre-existing scores need not undergo strict filtering
// edit: this is mostly broken since the idea is to catch renamed packs, if the pack was renamed
// the id won't be valid. Need to strip group names from all loaded songdirs and match the latter
// half and then load any matched songs and attempt matches -mina
if (id.IsValid()) {
vector<HighScore>& hsv = j->second.hsl.vHighScores;
// score import is meant to be a qol and pre-existing scores need not undergo strict filtering -mina
if (!id.IsValid()) {
string unloaded = id.ToString();
unloaded = unloaded.substr(0, unloaded.size() - 1);
int jjq = unloaded.find_last_of("/");
unloaded = unloaded.substr(jjq + 1, unloaded.size() - jjq);

LOG->Trace("Unloaded to be matched %s", id.ToString());

for (size_t i = 0; i < songs.size(); ++i) {
SongID matchid;
matchid.FromSong(songs[i]);

string matchstring = matchid.ToString();
matchstring = matchstring.substr(0, matchstring.size() - 1);
jjq = matchstring.find_last_of("/");
matchstring = matchstring.substr(jjq + 1, matchstring.size() - jjq);

if (unloaded == matchstring) {
LOG->Trace("Match at %s", matchid.ToString());
id = matchid;
break;
}
}

Song* song = id.ToSong();
const vector<Song*>& songs = SONGMAN->GetAllSongs();

if (!song) {
LOG->Trace("no match found");
continue;
}

vector<HighScore>& hsv = j->second.hsl.vHighScores;
string title = song->GetDisplayMainTitle();

for (size_t i = 0; i < hsv.size(); ++i) {
Expand All @@ -2004,12 +2031,7 @@ void Profile::ImportScoresToEtterna() {
bool matched = false;
for (size_t j = 0; j < demsteps.size(); ++j) {
Steps* steps = demsteps[j];
if (!steps) {
LOG->Warn("What????");
continue;
}

int notes = steps->GetRadarValues()[RadarCategory_Notes];
int notes = steps->GetRadarValues()[RadarCategory_TapsAndHolds];
int snotes = 0;

snotes += tmp.GetTapNoteScore(TNS_Miss);
Expand All @@ -2020,13 +2042,24 @@ void Profile::ImportScoresToEtterna() {
snotes += tmp.GetTapNoteScore(TNS_W5);

if (notes == snotes) {
LOG->Warn("Matched based on note count");
ck = steps->GetChartKey();
LOG->Trace("Matched based on taps count");
matched = true;
break;
}

notes = steps->GetRadarValues()[RadarCategory_Notes];

if (notes == snotes) {
LOG->Trace("Matched based on notes count");
matched = true;
SCOREMAN->AddScore(tmp);
loaded++;
break;
}

if (matched) {
ck = steps->GetChartKey();
loaded++;
SCOREMAN->AddScore(tmp);
}
}
}
}
Expand Down

0 comments on commit ad58aa3

Please sign in to comment.