Permalink
Browse files

Added a compatibility method to merge json scores

  • Loading branch information...
1 parent 8f600ff commit b4007e51822881fc2e3af2c34e9aa8f83d1ce3cb @SuperV1234 committed Apr 2, 2013
@@ -14,6 +14,7 @@ namespace hg
std::string get181Validator(const std::string& mPackPath, const std::string& mLevelId, const std::string& mJsonRootPath, const std::string& mLuaScriptPath, float mDifficultyMultiplier);
void convert181to183Hashes(const std::string& mSourceJsonPath, const std::string& mTargetJsonPath);
void convert182to183Hashes(const std::string& mSourceJsonPath, const std::string& mTargetJsonPath);
+ void merge19Scores(const std::string& mSourceJsonPathA, const std::string& mSourceJsonPathB, const std::string& mTargetJsonPath);
}
}
@@ -154,5 +154,51 @@ namespace hg
ofstream o; o.open(mTargetJsonPath); o << scores; o.flush(); o.close();
}
+ void merge19Scores(const string& mSourceJsonPathA, const string& mSourceJsonPathB, const string& mTargetJsonPath)
+ {
+ string aStr{get184FileContents(mSourceJsonPathA)};
+ string bStr{get184FileContents(mSourceJsonPathB)};
+ Json::Value a{getRootFromString(aStr)};
+ Json::Value b{getRootFromString(bStr)};
+
+ Json::Value result{a};
+
+ for(auto itr = b.begin(); itr != b.end(); ++itr)
+ {
+ string validator = itr.key().asString();
+ log("Dealing with validator <" + validator + ">", "Merge");
+
+ if(result.isMember(validator))
+ {
+ log("Result has alerady validator <" + validator + ">", "Merge");
+ Json::Value& lvl = result[validator];
+
+ for(auto nsPairItr = (*itr).begin(); nsPairItr != (*itr).end(); ++nsPairItr)
+ {
+ Json::Value& nsPair = (*nsPairItr);
+
+ bool found{false};
+ for(auto lvlPairItr = lvl.begin(); lvlPairItr != lvl.end(); ++lvlPairItr)
+ {
+ Json::Value& lvlPair = (*lvlPairItr);
+ if(lvlPair["n"] == nsPair["n"] && nsPair["s"].asFloat() > lvlPair["s"].asFloat())
+ {
+ lvlPair["s"] = nsPair["s"].asFloat();
+ found = true;
+ break;
+ }
+ }
+
+ if(!found) lvl.append(nsPair);
+ }
+ }
+ else log("Result has not validator <" + validator + ">, creating", "Merge");
+ }
+
+ string resString{""};
+ Json::FastWriter fw;
+ resString = fw.write(result);
+ ofstream o; o.open(mTargetJsonPath); o << resString; o.flush(); o.close();
+ }
}
}
@@ -24,7 +24,7 @@ using namespace ssvu::FileSystem;
using namespace hg;
int main(int argc, char* argv[])
-{
+{
vector<string> overrideIds; for(int i{0}; i < argc; i++) overrideIds.push_back(string{argv[i]});
if(!exists("Profiles/"))

0 comments on commit b4007e5

Please sign in to comment.