1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING |
---|
17 | |
---|
18 | #include "resource.h" |
---|
19 | #include "filesys/file.h" |
---|
20 | |
---|
21 | ObjectListDefinition(NewResource); |
---|
22 | |
---|
23 | |
---|
24 | std::vector<NewResource::Type*> NewResource::_resourceTypes; |
---|
25 | |
---|
26 | //! GLOBALS |
---|
27 | Directory NewResource::_mainGlobalPath; |
---|
28 | std::vector<Directory> NewResource::_globalPaths; |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | * standard constructor |
---|
33 | */ |
---|
34 | NewResource::NewResource (NewResource::Type* type) |
---|
35 | : _pointer(NULL), _type(type) |
---|
36 | { |
---|
37 | this->registerObject(this, NewResource::_objectList); |
---|
38 | |
---|
39 | if(this->_type->id() == -1) |
---|
40 | { |
---|
41 | NewResource::_resourceTypes.push_back(this->_type); |
---|
42 | this->_type->setID(NewResource::_resourceTypes.size()-1); |
---|
43 | } |
---|
44 | |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | * standard deconstructor |
---|
49 | */ |
---|
50 | NewResource::~NewResource () |
---|
51 | { |
---|
52 | // delete what has to be deleted here |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | std::string NewResource::locateFile(const std::string& fileName) |
---|
57 | { |
---|
58 | if (File(fileName).exists()) |
---|
59 | return fileName; |
---|
60 | else if ((NewResource::_mainGlobalPath+File(fileName)) . exists() ) |
---|
61 | return (NewResource::_mainGlobalPath + File(fileName)).name(); |
---|
62 | |
---|
63 | return std::string("/home/bensch/svn/orxonox/data/") + fileName; |
---|
64 | |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | NewResource::Pointer* NewResource::acquireResource(const std::string& loadString) |
---|
69 | { |
---|
70 | //const NewResource::Type* const type = NewResource::_resourceTypes[this->_type->id()]; |
---|
71 | |
---|
72 | for (unsigned int i = 0; i < _type->storedResources().size(); ++i) |
---|
73 | { |
---|
74 | if (_type->storedResources()[i]->loadString() == loadString) |
---|
75 | return _type->storedResources()[i]; |
---|
76 | } |
---|
77 | |
---|
78 | return NULL; |
---|
79 | } |
---|
80 | |
---|
81 | void NewResource::setMainGlobalPath(const Directory& directory) |
---|
82 | { |
---|
83 | NewResource::_mainGlobalPath = directory; |
---|
84 | NewResource::_mainGlobalPath.open(); |
---|
85 | } |
---|
86 | |
---|
87 | void NewResource::addGlobalPath(const Directory& directory) |
---|
88 | { |
---|
89 | std::vector<Directory>::const_iterator it = std::find(NewResource::_globalPaths.begin(), NewResource::_globalPaths.end(), directory); |
---|
90 | if (it == NewResource::_globalPaths.end()) |
---|
91 | NewResource::_globalPaths.push_back(directory); |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | void NewResource::addResource(NewResource::Pointer* pointer) |
---|
97 | { |
---|
98 | this->_type->addResource(pointer); |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | void NewResource::KeepLevel::setKeepLevelName(unsigned int level, const std::string& name) |
---|
111 | { |
---|
112 | if (_keepLevelName.size() <= level) |
---|
113 | _keepLevelName.resize(level+1); |
---|
114 | _keepLevelName[level] = name; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | void NewResource::Type::addResource(NewResource::Pointer* resource) |
---|
120 | { |
---|
121 | this->_storedResources.push_back(resource); |
---|
122 | |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | NewResource::Pointer::Pointer(const std::string& loadString, const NewResource::KeepLevel& keeplevel) |
---|
127 | : _loadString(loadString), _keepLevel(keeplevel) |
---|
128 | {} |
---|
129 | |
---|
130 | |
---|
131 | void NewResource::Type::setID(int id) |
---|
132 | { |
---|
133 | this->_id = id; |
---|
134 | } |
---|