/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: ... */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD #include "resource.h" #include "new_resource_manager.h" #include "debug.h" ObjectListDefinition(NewResource); /** * standard constructor */ NewResource::NewResource (Resources::Type* type) : _pointer(NULL), _type(type) { this->registerObject(this, NewResource::_objectList); } /** * standard deconstructor */ NewResource::~NewResource () { // delete what has to be deleted here } std::string NewResource::locateFile(const std::string& fileName) const { if (File(fileName).exists()) return fileName; else if ((NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).exists() ) return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name(); printf("LOCATED %s\n", locateFileInSubDir(Directory("/home/bensch/svn/orxonox/data/"), fileName).c_str()); return std::string("/home/bensch/svn/orxonox/data/") + fileName; } /** * @brief tests in all the SubDirectories defined in Resource under Directory if the fileName exists. * @param directory the directory to in what to search for all subdirectories for. * @param fileName the Name of the File to query for * @return true on success. */ std::string NewResource::locateFileInSubDir(const Directory& directory, const std::string& fileName) const { std::vector::const_iterator it; for (it = this->_type->resourceSubPaths().begin(); it != this->_type->resourceSubPaths().end(); ++it) { Directory dir = directory + (*it); File file = dir + File(fileName); printf("Testing %s (from %s in directory %s)\n", file.name().c_str(), fileName.c_str(), dir.name().c_str()); if ((dir+ File(fileName)).exists()) return (dir+File(fileName)).name(); } return ""; } Resources::StorePointer* NewResource::acquireResource(const std::string& loadString) { //const Resources::Type* const type = Resources::_resourceTypes[this->_type->id()]; for (unsigned int i = 0; i < _type->storedResources().size(); ++i) { if (_type->storedResources()[i]->loadString() == loadString) return _type->storedResources()[i]; } return NULL; } void NewResource::addResource(Resources::StorePointer* pointer) { this->_type->addResource(pointer); } /////////////////// //// KEEPLEVEL //// /////////////////// std::vector Resources::KeepLevel::_keepLevelNames; void Resources::KeepLevel::defineKeepLevelName(unsigned int level, const std::string& name) { if (_keepLevelNames.size() <= level) _keepLevelNames.resize(level+1); _keepLevelNames[level] = name; } /////////////////////// //// STORE POINTER //// /////////////////////// Resources::StorePointer::StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel) : _loadString(loadString), _keepLevel(keeplevel) {} ////////////// //// TYPE //// ////////////// Resources::Type::Type(const std::string& typeName) : _id(-1), _typeName(typeName) { NewResourceManager::getInstance()->registerType(this); } void Resources::Type::addResource(Resources::StorePointer* resource) { this->_storedResources.push_back(resource); } bool Resources::Type::addResourcePath(const std::string& path) { std::vector::const_iterator it; for (it = this->_resourcePaths.begin(); it != this->_resourcePaths.end(); ++it) if ((*it) == path) return false; this->_resourcePaths.push_back(path); return true; } bool Resources::Type::addResourceSubPath(const std::string& subPath) { std::vector::const_iterator it; for (it = this->_resourceSubPaths.begin(); it != this->_resourceSubPaths.end(); ++it) if ((*it) == subPath) return false; this->_resourceSubPaths.push_back(subPath); return true; } void Resources::Type::setID(int id) { this->_id = id; }