QJsonObject JsonSaver::saveCity(const City& city) { QJsonObject res; res.insert("name", QString::fromStdString(city.name())); QJsonArray buildings; int i = 0; for(const auto& b : city.buildings()) buildings.insert(i++, saveBuilding(b)); res.insert("buildings", buildings); res.insert("size", saveSizeU(city.map().size())); QJsonArray roads; i = 0; for(std::size_t x = 0; x < city.map().width(); x++) for(std::size_t y = 0; y < city.map().height(); y++) if(city.map().squareType({x, y}) == Map::SquareType::Road) { roads.insert(i++, savePointU({x, y})); } res.insert("roads", roads); return res; }
// ------------------------------------ mouse/keyboard void FerryBuilding::keyPressed(int key) { if(bEnable) { if(key == ' ') { bSaved = false; bFirstPoint = false; shapes.push_back(FerryShape()); } if(key == 'c') clear(); if(key == 's') saveBuilding(); // undo the last click if(key == 'z') { if(shapes.size() > 0) { // no points left in shape then erase shape if(shapes.back().pnts.size() == 0) { int lastShape = shapes.size(); shapes.erase(shapes.begin() + lastShape); } else { int lastPnt = shapes.back().pnts.size(); shapes.back().pnts.erase(shapes.back().pnts.begin() + lastPnt); } } } /* // add a new file if(key == 'n') { fileCount ++; selectedFile = fileCount-1; string fileToSave = "building_"+ofToString(selectedFile)+".xml"; files.push_back(fileToSave); loadBuilding(files[selectedFile]); } // select the file if(key == OF_KEY_DOWN) { selectedFile ++; if(selectedFile > (files.size()-1)) { selectedFile = files.size()-1; } loadBuilding(files[selectedFile]); } if(key == OF_KEY_UP) { selectedFile --; if(selectedFile < 0) { selectedFile = 0; } loadBuilding(files[selectedFile]); } */ } // need to turn me on first if(key == 'e') bEnable = !bEnable; }