63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
#include "clusters.hpp"
|
|
#include "rules.hpp"
|
|
#include "data.hpp"
|
|
|
|
#include <boost/archive/text_oarchive.hpp>
|
|
#include <boost/program_options.hpp>
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include <iostream>
|
|
#include <fstream>
|
|
|
|
int main(int argc, char** argv){
|
|
namespace po = boost::program_options;
|
|
namespace fs = boost::filesystem;
|
|
|
|
// Describe program options
|
|
po::options_description opts;
|
|
opts.add_options()
|
|
("input,i", "input directory")
|
|
("output,o", po::value<std::string>(), "output file")
|
|
("add-unsolvables,u", po::bool_switch(), "also adds the unsolvable levels to the pack")
|
|
("help", po::bool_switch(), "show this help");
|
|
|
|
po::positional_options_description file_opts;
|
|
file_opts.add("input", 1);
|
|
|
|
// Parse and store them in a vm
|
|
po::variables_map vm;
|
|
po::store(po::command_line_parser(argc, argv).options(opts).positional(file_opts).run(), vm);
|
|
po::notify(vm);
|
|
|
|
if(vm["help"].as<bool>()){
|
|
std::cout << "Puzzle Wuzzle Level Packer, version " << __DATE__ << std::endl;
|
|
std::cout << "pack [-u] [-o <outputfile>] <directory>\n";
|
|
std::cout << opts << std::endl;
|
|
return 0;
|
|
}
|
|
|
|
fs::path directory = vm["input"].as<std::string>();
|
|
fs::path output_file = directory.parent_path().string() + ".pck";
|
|
if(vm.count("output")) output_file = vm["output"].as<std::string>();
|
|
|
|
std::vector<AnalyzedGrid<DynamicGridBase>> pack;
|
|
std::cout << "Packing " << directory << " into " << output_file << std::endl;
|
|
bool unsolvables = vm["add-unsolvables"].as<bool>();
|
|
|
|
fs::directory_iterator eod;
|
|
for(fs::directory_iterator it(directory); it != eod; ++it){
|
|
auto && path = it->path();
|
|
if(path.extension() != ".lvl") continue;
|
|
|
|
auto level = grid_from_file(path.string());
|
|
if(!unsolvables && level.solutions.traces.empty()) continue;
|
|
|
|
pack.emplace_back(std::move(level));
|
|
}
|
|
|
|
std::ofstream file(output_file.string());
|
|
boost::archive::text_oarchive ar(file);
|
|
ar << pack;
|
|
|
|
std::cout << "Packed " << pack.size() << " levels" << std::endl;
|
|
}
|