#include #include #include #include "RecipieLoader.h" RecipieLoader::RecipieLoader() : Framework::ReferenceCounter() {} void RecipieLoader::loadRecipies( const char* path ) { std::cout << "loading recipies from '" << path << "'" << std::endl; Framework::Datei d; d.setDatei( path ); if( d.istOrdner() ) { Framework::RCArray* files = d.getDateiListe(); for( Framework::Text* f : *files ) loadRecipies( Framework::Text( path ) + "/" + *f ); files->release(); } else { Framework::JSON::JSONValue* json = Framework::JSON::loadJSONFromFile( path ); if( json->getType() == Framework::JSON::JSONType::ARRAY ) { // TODO: parse the json recipies } else std::cout << "could not load recipie file '" << path << "' because it does not contain a valid json array of recipies" << std::endl; json->release(); } } RecipieList* RecipieLoader::zRecipieList( const char* name ) { for( RecipieList* l : lists ) { if( l->getName().istGleich( name ) ) return l; } return 0; } ShapedRecipieList* RecipieLoader::zShapedRecipieList( const char* name ) { for( ShapedRecipieList* l : shapedLists ) { if( l->getName().istGleich( name ) ) return l; } return 0; } void RecipieLoader::registerRecipieList( const char* name ) { if( zRecipieList( name ) ) throw new std::invalid_argument( "the recipie list already exists" ); lists.add( new RecipieList( name ) ); } void RecipieLoader::registerShapedRecipieList( const char* name ) { if( zShapedRecipieList( name ) ) throw new std::invalid_argument( "the recipie list already exists" ); shapedLists.add( new ShapedRecipieList( name ) ); }