#include "levelextinputdata.h" using namespace ArduinoJson ; #include using std::ifstream; using std::ofstream; LevelExtInputData::LevelExtInputData() { _seed = 1234567 ; _hasMovement = 0; _firstMoveType = ""; // A1, B1,B2,B3, C1,C2... _firstMoveLyrCnt = 0 ; _firstMoveDirection = 0 ; //0-fromRight2Left 1-fromLeft2Right _secondMoveType = "" ; _secondMoveLyrCnt = 0 ; _secondMoveDirection =0 ; _bigPlatePercent = 50; //不移动盘子中大盘子百分比 _midPlatePercent = 50; //不移动盘子中中盘子百分比 _lyr1Percent = 0 ; //不移动盘子中有一层的盘子百分比 _lyr2Percent = 100; //不移动盘子中有两层的盘子百分比 _lyr3Percent = 0 ; //不移动盘子中有三层的盘子百分比 _matchLyr1 = 70; //第一层可配百分比,第一层是点击层、第二层是可见层、第三层为隐藏层 _matchLyr2 = 70; //第二层可配百分比 _matchLyr3 = 70; //第三层可配百分比 } bool LevelExtInputData::readFromFile(string filename) { *this = LevelExtInputData() ; ifstream ifs( filename.c_str() ) ; if( ifs.good() == false ) return false ; DynamicJsonBuffer buffer ; JsonObject& root = buffer.parse(ifs) ; _seed = root["seed"].as() ; _hasMovement = root["HasMovement"].as() ; if( _hasMovement ) { _firstMoveType = root["movement"]["firstType"].as() ; // A1, B1,B2,B3, C1,C2... _firstMoveLyrCnt = root["movement"]["firstLyrCnt"].as() ; _firstMoveDirection =root["movement"]["firstDirection"].as() ; //0-fromRight2Left 1-fromLeft2Right _secondMoveType = root["movement"]["secondType"].as() ; _secondMoveLyrCnt = root["movement"]["secondLyrCnt"].as() ; _secondMoveDirection =root["movement"]["secondDirection"].as() ; } _bigPlatePercent = root["BigPlatePercent"].as() ; //不移动盘子中大盘子百分比 _midPlatePercent = root["MidPlatePercent"].as() ; //不移动盘子中中盘子百分比 _lyr1Percent = root["Lyr1Percent"].as() ; //不移动盘子中有一层的盘子百分比 _lyr2Percent = root["Lyr2Percent"].as() ; //不移动盘子中有两层的盘子百分比 _lyr3Percent = root["Lyr3Percent"].as() ; //不移动盘子中有三层的盘子百分比 _matchLyr1 = root["MatchLyr1"].as() ; //第一层可配百分比,第一层是点击层、第二层是可见层、第三层为隐藏层 _matchLyr2 = root["MatchLyr2"].as() ; //第二层可配百分比 _matchLyr3 = root["MatchLyr3"].as() ; //第三层可配百分比 ifs.close(); return true; } bool LevelExtInputData::writeToFile(string filename) { DynamicJsonBuffer buffer ; JsonObject& root = buffer.createObject() ; root["seed"] = _seed ; root["HasMovement"] = _hasMovement ; JsonObject& movement = root.createNestedObject("movement") ; movement["firstType"] = _firstMoveType ; movement["firstLyrCnt"] = _firstMoveLyrCnt ; movement["firstDirection"] = _firstMoveDirection ; movement["secondType"] = _secondMoveType ; movement["secondLyrCnt"] = _secondMoveLyrCnt ; movement["secondDirection"] = _secondMoveDirection ; root["BigPlatePercent"] = _bigPlatePercent ; //不移动盘子中大盘子百分比 root["MidPlatePercent"] = _midPlatePercent ; //不移动盘子中中盘子百分比 root["Lyr1Percent"] = _lyr1Percent ; //不移动盘子中有一层的盘子百分比 root["Lyr2Percent"] = _lyr2Percent; //不移动盘子中有两层的盘子百分比 root["Lyr3Percent"] = _lyr3Percent; //不移动盘子中有三层的盘子百分比 root["MatchLyr1"] = _matchLyr1 ; //第一层可配百分比,第一层是点击层、第二层是可见层、第三层为隐藏层 root["MatchLyr2"] = _matchLyr2 ; //第二层可配百分比 root["MatchLyr3"] = _matchLyr3 ; //第三层可配百分比 string jsontext ; root.printTo(jsontext) ; ofstream ofs( filename.c_str() ) ; if( ofs.good() == false ) return false ; ofs<