Mercurial > hg > tweakathon2ios
diff presetManager.mm @ 5:213df0baed47
presets file is updated when one is saved.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Thu, 16 Oct 2014 15:52:53 +0100 |
parents | 60b54ba87f6a |
children | 92850a2b099c |
line wrap: on
line diff
--- a/presetManager.mm Thu Oct 16 14:34:14 2014 +0100 +++ b/presetManager.mm Thu Oct 16 15:52:53 2014 +0100 @@ -23,13 +23,15 @@ Json::Value presetVal; - presetVal["creatorUserName"] = creatorUserName; - presetVal["creatorDeviceID"] = creatorDeviceID; + presetVal["creatorUserName"] = creatorUserName; + presetVal["creatorDeviceID"] = creatorDeviceID; presetVal["creationTime"] = creationTime; presetVal["name"] = name; - - for(vector<int>::iterator i; i < CCValues.end(); i++){ - presetVal["CCValues"].append(*i); + presetVal["imageFileName"] = imageFileName; + + for(vector<int>::iterator i = CCValues.begin(); i < CCValues.end(); i++){ + int c = *i; + presetVal["CCValues"].append(c); } return presetVal; @@ -62,7 +64,7 @@ return root; } //--------------------------------------------------------------------------- -void PresetManager::readJsonToPresets(const string &jsonFile){ +void PresetManager::loadPresetsFromJsonFile(const string &jsonFile){ Json::Value root; Json::Reader reader; @@ -100,7 +102,7 @@ for ( int index = 0; index < jpresets.size(); ++index ) thePresets.push_back(new Preset(jpresets[index])); - //printAll(); + printAll(); } //--------------------------------------------------------------------------- @@ -119,7 +121,7 @@ } //--------------------------------------------------------------------------- // when save button pressed -int PresetManager::savePreset(const string name, vector<int> values){ +void PresetManager::savePreset(const string name, vector<int> values){ presetAlertShowing = false; // check for same name @@ -130,6 +132,9 @@ cout << "WARNING Preset by that name exists, overwriting\n"; // overwrite it (*iter)->CCValues = values; + updatePresetFile(); + eventLogger.logEvent(SAVE_PRESET); // TODO need to log details? + return; } } @@ -138,43 +143,47 @@ } - thePresets.push_back(new Preset(values, name, nextID, eventLogger.userName, eventLogger.deviceID)); eventLogger.logEvent(SAVE_PRESET); // TODO need to log details? + updatePresetFile(); - return nextID++; } - +//----------------------------------------------cu----------------------------- vector<int> PresetManager::recallPreset(string name){ vector<Preset *>::iterator p; - for(p = thePresets.begin(); p < thePresets.end(); p++){ - if ( (*p)->getName() == name){ - return (*p)->getValues(); - } + for(p = thePresets.begin(); p < thePresets.end(); p++){ + if ( (*p)->getName() == name){ + return (*p)->getValues(); + } } - + vector<int> empty; + return empty; } //----------------------------------------------cu----------------------------- void PresetManager::startLoadAll(){ - // get stuff from file - // load file - string fname = ofxiPhoneGetDocumentsDirectory() + PRESET_FILENAME; + presetFileName = ofxiPhoneGetDocumentsDirectory() + PRESET_FILENAME; - readJsonToPresets(fname); + loadPresetsFromJsonFile(presetFileName); timesOpened++; } +//--------------------------------------------------------------------------- +void PresetManager::updatePresetFile(){ + + // TODO really inefficient + + ofFile presetFile(presetFileName,ofFile::WriteOnly); -//--------------------------------------------------------------------------- -void PresetManager::exitAndSaveAll(){ - ofFile presetFile(ofxiPhoneGetDocumentsDirectory() +PRESET_FILENAME,ofFile::WriteOnly); - // stick all the stuff in a json value Json::Value root = allPresetsToJson(); cout << root; presetFile << root; +} +//--------------------------------------------------------------------------- +void PresetManager::exitAndSaveAll(){ + updatePresetFile(); }