Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/src/libraries/tools/ResourceCollection.cc @ 12204

Last change on this file since 12204 was 12177, checked in by siramesh, 6 years ago

Super Orxo Bros Final (Sidharth Ramesh, Nisa Balta, Jeff Ren)

File size: 3.0 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "ResourceCollection.h"
30
31#include "util/Exception.h"
32#include "core/CoreIncludes.h"
33#include "core/Resource.h"
34#include "core/XMLPort.h"
35#include "ResourceLocation.h"
36
37namespace orxonox
38{
39    RegisterClass(ResourceCollection);
40
41    ResourceCollection::ResourceCollection(Context* context)
42        : BaseObject(context)
43    {
44        RegisterObject(ResourceCollection);
45
46        // Default group is "General"
47        this->setResourceGroup(Resource::getDefaultResourceGroup());
48    }
49
50    void ResourceCollection::XMLPort(Element& xmlelement, XMLPort::Mode mode)
51    {
52        XMLPortParam(ResourceCollection, "resourceGroup", setResourceGroup, getResourceGroup, xmlelement, mode);
53        XMLPortObject(ResourceCollection, ResourceLocation, "", addResourceLocation, getResourceLocation, xmlelement, mode);
54    }
55
56    void ResourceCollection::setResourceGroup(const std::string& resourceGroup)
57    {
58        if (resourceGroup.empty())
59        {
60            orxout(internal_warning) << "\"\" is not a valid resource group." << endl;
61            return;
62        }
63        if (!resourceLocations_.empty())
64            ThrowException(InitialisationFailed, "ResourceGroup: Group change not allowed with locations already added!");
65        resourceGroup_ = resourceGroup;
66    }
67
68    void ResourceCollection::addResourceLocation(ResourceLocation* location)
69    {
70        location->load(resourceGroup_);
71        this->resourceLocations_.push_back(location);
72    }
73
74    void ResourceCollection::removeResourceLocation(ResourceLocation* location)
75    {
76        for (std::vector<ResourceLocation*>::iterator it = resourceLocations_.begin(); it != resourceLocations_.end(); )
77        {
78            if (*it == location)
79            {
80                it = resourceLocations_.erase(it);
81                location->unload(); // doesn't throw
82            }
83            else
84                ++it;
85        }
86    }
87
88    ResourceLocation* ResourceCollection::getResourceLocation(unsigned int index) const
89    {
90        if (index >= resourceLocations_.size())
91            return nullptr;
92        else
93            return resourceLocations_[index];
94    }
95}
Note: See TracBrowser for help on using the repository browser.