これはopenFrameworksC ++コードです。ゲームで行われた各動きに関する情報を保存しますが、新しいゲームごとに<MOVE> <PLAYER/> <MOVE/>
、以前の<GAME><GAME/>
タグの内部のすべての値が消去されます。
bool My_xml::setup() {
XML.loadFile(ofxiPhoneGetDocumentsDirectory() + "scoresAndSettings.xml")
//read the settings from XML
//if the settings file doesn't exist we assign default values
globalsettings.user_id = XML.getValue("GLOBALSETTINGS:USERID", ofRandom(std::numeric_limits<float>::max() - 1));
if (globalsettings.user_id == 0) { // for first game only
XML.setValue("GLOBALSETTINGS:USERID", globalsettings.user_id);
}
globalsettings.playing_big_board = XML.getValue("GLOBALSETTINGS:BIGBOARD", false);
globalsettings.drawCrossHairs = XML.getValue("GLOBALSETTINGS:DRAWCROSSHAIRS", false);
globalsettings.graphFFT = XML.getValue("GLOBALSETTINGS:GRAPHFFT", true); //
globalsettings.showDebugText = XML.getValue("GLOBALSETTINGS:SHOWDEBUGTEXT", false);
gameNumber = XML.addTag("GAME");
XML.setAttribute("GAME", "number", gameNumber+1, gameNumber);
XML.setAttribute("GAME", "start", makeTimeStamp(), gameNumber);
XML.pushTag("GAME", gameNumber);
return true;
}
void My_xml::saveMoveInfo() {
int moveNumber = XML.addTag("MOVE");
if( XML.pushTag("MOVE", moveNumber) ){
// put in data from this move
int player = ((testApp*)ofGetAppPtr())->gameplay->whoseTurnIsIt;
string playerTag = "PLAYER " + ofToString(player);
int tagNum = XML.addTag(playerTag);
XML.addAttribute(playerTag, "move", moveNumber++, tagNum);
XML.addAttribute(playerTag, "duration", lastMoveDuration, tagNum);
XML.addAttribute(playerTag, "wait", waitBeforeThisMove, tagNum);
XML.addAttribute(playerTag, "timestamp", makeTimeStamp(), tagNum);
XML.popTag();
}
XML.saveFile( ofxiPhoneGetDocumentsDirectory() + "scoresAndSettings.xml" );
}
void My_xml::winGame() {
writeToFile();
}
void My_xml::writeToFile() {
XML.popTag();
XML.setAttribute("GAME", "lat", ofToString(coreLocation->getLatitude(), 10), gameNumber);
XML.setAttribute("GAME", "long", ofToString(coreLocation->getLongitude(), 10), gameNumber);
XML.setAttribute("GAME", "end", makeTimeStamp(), gameNumber);
XML.saveFile( ofxiPhoneGetDocumentsDirectory() + "scoresAndSettings.xml" );
}
編集/追加:キャリブレーションデータを保存するこのコードは、各ゲームで上書き/クリア/食べられません。
if (animations->training != NOT_TRAINING) {
int numGameTags = XML.XML.getNumTags("GAME");
XML.XML.pushTag("GAME", numGameTags-1);
int moveNumber = XML.XML.addTag("CALIBRATION");
if (gameplay->whoseTurnIsIt < 2) { // PLAYER 1
switch (animations->training) {
case TRAINING_UP:
XML.player1settings.pitch_high = gameplay->high_pitch_thresh;
XML.XML.setAttribute("CALIBRATION", "player", gameplay->whoseTurnIsIt, moveNumber);
XML.XML.setAttribute("CALIBRATION", "type", "pitch", moveNumber);
XML.XML.setAttribute("CALIBRATION", "level", "high", moveNumber);
XML.XML.setValue("CALIBRATION", gameplay->high_pitch_thresh, moveNumber);
break;
// etc.
default:
break;
}
} else { // PLAYER 2
switch (animations->training) {
case TRAINING_UP:
XML.player2settings.pitch_high = gameplay->high_pitch_thresh;
XML.XML.setAttribute("CALIBRATION", "player", gameplay->whoseTurnIsIt, moveNumber);
XML.XML.setAttribute("CALIBRATION", "type", "pitch", moveNumber);
XML.XML.setAttribute("CALIBRATION", "level", "high", moveNumber);
XML.XML.setValue("CALIBRATION", gameplay->high_pitch_thresh, moveNumber);
break;
// etc.
default:
break;
} // end switch
} // end else
XML.XML.popTag();
}
編集2:
コンテンツが削除されただけでなく、XMLタグが実際に変更されていることに気づきました。タグは<PLAYER 1>
または<PLAYER 2>
最新のゲームにありますが<PLAYER />
、すべての古いデータにあることに注意してください...
<GAME number="3" start="2011-08-19|16:00:59|2.7" lat="51.38325077" long="-2.36163312" end="2011-08-19|16:01:29|32.8">
<PLAYER />
</GAME>
<GAME number="4" start="2011-08-19|16:14:12|2.6">
<PLAYER />
</GAME>
<GAME number="5" start="2011-08-19|16:16:10|2.9">
<PLAYER 1 col="0" row="2" err="0" move="1" duration="0.012999" wait="19.784000" timestamp="2011-08-19|16:16:30|22.8"></PLAYER 1>
<PLAYER 2 col="0" row="2" err="-2" move="1" duration="0.219000" wait="1.605001" timestamp="2011-08-19|16:16:32|24.6"></PLAYER 2>
<PLAYER 2 col="0" row="2" err="-2" move="2" duration="0.226000" wait="1.500000" timestamp="2011-08-19|16:16:34|26.4"></PLAYER 2>
</GAME>
EDIT3:ああ、それだけです。タグ名にスペースはありません。シーシュ。