5 * Created by Alyssa Milburn on Mon Jan 16 2006.
6 * Copyright (c) 2006 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library 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 GNU
16 * Lesser General Public License for more details.
20 #include "prayManager.h"
21 #include "exceptions.h"
22 #include "World.h" // data_directories
23 #include "Catalogue.h"
24 #include <boost/filesystem/convenience.hpp>
26 prayManager::~prayManager() {
27 while (files
.size() != 0) {
28 prayFile
*f
= files
[0];
33 assert(blocks
.size() == 0);
36 void prayManager::addFile(prayFile
*f
) {
37 std::vector
<prayFile
*>::iterator p
= std::find(files
.begin(), files
.end(), f
);
38 assert(p
== files
.end());
41 for (std::vector
<prayBlock
*>::iterator i
= f
->blocks
.begin(); i
!= f
->blocks
.end(); i
++) {
42 if (blocks
.find((*i
)->name
) != blocks
.end()) // garr, block conflict
44 //assert(blocks.find((*i)->name) == blocks.end());
45 blocks
[(*i
)->name
] = *i
;
49 void prayManager::removeFile(prayFile
*f
) {
50 std::vector
<prayFile
*>::iterator p
= std::find(files
.begin(), files
.end(), f
);
51 assert(p
!= files
.end());
54 for (std::vector
<prayBlock
*>::iterator i
= f
->blocks
.begin(); i
!= f
->blocks
.end(); i
++) {
55 if (blocks
.find((*i
)->name
) == blocks
.end()) // garr, block conflict
57 /*assert(blocks.find((*i)->name) != blocks.end());
58 assert(blocks[(*i)->name] == *i); */
59 blocks
.erase(blocks
.find((*i
)->name
));
63 void prayManager::update() {
64 if (files
.size() != 0) return; // TODO: Handle actual update cases, rather than just the initial init.
66 if (!catalogue
.hasTag("Pray System File Extensions")) {
67 std::cout
<< "Warning: Catalogue tag \"Pray System File Extensions\" wasn't found, so no PRAY files will be loaded." << std::endl
;
71 const std::vector
<std::string
> &extensions
= catalogue
.getTag("Pray System File Extensions");
73 for (std::vector
<fs::path
>::iterator i
= world
.data_directories
.begin(); i
!= world
.data_directories
.end(); i
++) {
74 assert(fs::exists(*i
));
75 assert(fs::is_directory(*i
));
77 fs::path
praydir(*i
/ fs::path("/My Agents/", fs::native
));
79 if (fs::exists(praydir
) && fs::is_directory(praydir
)) {
80 fs::directory_iterator fsend
;
81 for (fs::directory_iterator
d(praydir
); d
!= fsend
; ++d
) {
82 std::string x
= fs::extension(*d
);
83 if (!x
.empty()) x
.erase(x
.begin());
84 if (std::find(extensions
.begin(), extensions
.end(), x
) != extensions
.end()) {
85 // TODO: language checking!
86 //std::cout << "scanning PRAY file " << d->path().native_directory_string() << std::endl;
88 prayFile
*p
= new prayFile(*d
);
90 } catch (creaturesException
&e
) {
91 std::cerr
<< "PRAY file \"" << d
->path().native_directory_string() << "\" failed to load: " << e
.what() << std::endl
;
99 std::string
prayManager::getResourceDir(unsigned int type
) {
101 case 0: return "/"; // main
102 case 1: return "/Sounds/"; // sounds
103 case 2: return "/Images/"; // images
104 case 3: return "/Genetics/"; // genetics
105 case 4: return "/Body Data/"; // body data
106 case 5: return "/Overlay Data/"; // overlay data
107 case 6: return "/Backgrounds/";// backgrounds
108 case 7: return "/Catalogue/"; // catalogue
109 //case 8: return "/Bootstrap/"; // bootstrap
110 //case 9: return "/My Worlds/"; // my worlds
111 case 10: return "/My Creatures/";// my creatures
112 case 11: return "/My Agents/"; // my agents