X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fcatalogue.cpp;h=7a780116664a5c27ae1f86d073fb1f64b2523d32;hb=508ee4bfcc0f8fb1373fb7af251c59c873ef896f;hp=cfd5d6425f29d971bc116d96c72cfe0307eb4468;hpb=81ee4fbd16b472892b67b35ea85956423a2247ed;p=r2c2.git diff --git a/source/libr2c2/catalogue.cpp b/source/libr2c2/catalogue.cpp index cfd5d64..7a78011 100644 --- a/source/libr2c2/catalogue.cpp +++ b/source/libr2c2/catalogue.cpp @@ -1,9 +1,13 @@ -#include -#include +#include +#include #include +#include +#include +#include #include "catalogue.h" #include "signaltype.h" #include "terraintype.h" +#include "trackappearance.h" #include "tracktype.h" #include "vehicletype.h" @@ -16,10 +20,75 @@ Catalogue::Catalogue(): scale(1), layout(*this) { - add_type(); - add_type(); - add_type(); - add_type(); + add_type().keyword("track"); + add_type().keyword("signal"); + add_type().suffix(".veh").keyword("vehicle"); + add_type().suffix(".terr").keyword("terrain"); + add_type().suffix("trkapp").keyword("track_appearance"); + + add_source("data/r2c2"); +} + +void Catalogue::add_source(const FS::Path &path) +{ + string ext = FS::extpart(path.str()); + DataFile::CollectionSource *source = 0; + IO::Seekable *init_file = 0; + if(ext==".mdt") + { + DataFile::PackSource *pack_source = new DataFile::PackSource; + pack_source->add_pack_file(path.str()); + source = pack_source; + + list files = pack_source->list_files(); + for(list::const_iterator i=files.begin(); i!=files.end(); ++i) + { + string fext = FS::extpart(i->name); + if(fext==".cat" && !init_file) + init_file = pack_source->open(i->name); + } + } + else if(FS::is_dir(path)) + { + DataFile::DirectorySource *dir_source = new DataFile::DirectorySource; + dir_source->add_directory(path); + + list queue; + queue.push_back(path); + while(!queue.empty()) + { + FS::Path dir = queue.front(); + queue.pop_front(); + list files = FS::list_files(dir); + for(list::const_iterator i=files.begin(); i!=files.end(); ++i) + { + FS::Path full = dir/ *i; + if(FS::is_dir(full)) + { + dir_source->add_directory(full); + queue.push_back(full); + } + + string fext = FS::extpart(*i); + if(fext==".cat" && !init_file) + init_file = new IO::BufferedFile(full.str()); + } + } + + source = dir_source; + } + + sources.push_back(source); + Collection::add_source(*source); + signal_source_added.emit(*source); + + if(init_file) + { + DataFile::Parser parser(*init_file, path.str()); + Loader ldr(*this); + ldr.load(parser); + } + delete init_file; } @@ -29,11 +98,6 @@ Catalogue::Loader::Loader(Catalogue &c): { add("layout", &Loader::layout); add("scale", &Loader::scale); - add("signal", &Loader::signal); - add("terrain", &Loader::terrain); - add("track", &Loader::track); - add("track_appearance", &Loader::track_appearance); - add("vehicle", &Loader::vehicle); } void Catalogue::Loader::layout() @@ -46,41 +110,4 @@ void Catalogue::Loader::scale(float n, float d) cat.scale = n/d; } -void Catalogue::Loader::signal(const string &n) -{ - RefPtr sig = new SignalType(n); - load_sub(*sig); - cat.add(n, sig.get()); - sig.release(); -} - -void Catalogue::Loader::terrain(const string &n) -{ - RefPtr ter = new TerrainType(n); - load_sub(*ter); - cat.add(n, ter.get()); - ter.release(); -} - -void Catalogue::Loader::track(const string &n) -{ - RefPtr trk = new TrackType(n, &cat.appearance); - load_sub(*trk); - cat.add(n, trk.get()); - trk.release(); -} - -void Catalogue::Loader::track_appearance() -{ - load_sub(cat.appearance); -} - -void Catalogue::Loader::vehicle(const string &n) -{ - RefPtr veh = new VehicleType(n); - load_sub(*veh); - cat.add(n, veh.get()); - veh.release(); -} - } // namespace R2C2