1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
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 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef WIN32
#include <unistd.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif /* WIN32 */
#include <string>
#include <iostream>
#include "Theme.h"
using namespace std;
Theme *CurrentTheme;
string ThemeDir;
void errorOn(string file) {
throw Theme:: ThemeErrorException("Error accessing file " + file);
}
bool Theme::_checkTheme() {
bool r;
_hasConfFile = true;
#ifndef WIN32
cerr << "Verifying Theme `" << _name << "' [" << ThemeDir << "/" << _name << "/]:\n";
if ( access(_CCS(_background), R_OK) ) {
if (!_bigBackground)
_background = TD + TH_BACKGROUND_JPG;
else
_background = TD + TH_BACKGROUND_BIG_JPG;
if ( access(_CCS(_background), R_OK) ) errorOn("background.{jpg,png}");
}
if ( access(_CCS(_font), R_OK) ) errorOn(TH_FONT);
if ( access(_CCS(_fontinv), R_OK) ) errorOn(TH_FONTINV);
if ( access(_CCS(_leftmale), R_OK) ) errorOn(TH_LEFTMALE);
if ( access(_CCS(_rightmale), R_OK) ) errorOn(TH_RIGHTMALE);
if ( access(_CCS(_leftfemale), R_OK) ) errorOn(TH_LEFTFEMALE);
if ( access(_CCS(_rightfemale), R_OK) ) errorOn(TH_RIGHTFEMALE);
if ( access(_CCS(_ball), R_OK) ) errorOn(TH_BALL);
if ( access(_CCS(_confFile), R_OK) ) _hasConfFile = false;
r = (access(_CCS(_net), R_OK) == 0);
#else
struct _stat sStat ;
cerr << "Verifying Theme `" << _name << "' [" << ThemeDir << "\\" << _name << "\\]:\n";
if (_stat (_background.c_str(), &sStat)) {
if (!_bigBackground)
_background = TD + TH_BACKGROUND_JPG;
else
_background = TD + TH_BACKGROUND_BIG_JPG;
if (_stat (_background.c_str(), &sStat)) errorOn("background.{jpg,png}");
}
if (_stat (_font.c_str(), &sStat)) errorOn (TH_FONT) ;
if (_stat (_fontinv.c_str(), &sStat)) errorOn (TH_FONTINV) ;
if (_stat (_leftmale.c_str(), &sStat)) errorOn (TH_LEFTMALE) ;
if (_stat (_rightmale.c_str(), &sStat)) errorOn (TH_RIGHTMALE) ;
if (_stat (_leftfemale.c_str(), &sStat)) errorOn (TH_LEFTFEMALE) ;
if (_stat (_rightfemale.c_str(), &sStat)) errorOn (TH_RIGHTFEMALE) ;
if (_stat (_ball.c_str(), &sStat)) errorOn (TH_BALL) ;
if ( _stat(_confFile.c_str(), &sStat) ) _hasConfFile = false;
r = (_stat (_net.c_str(), &sStat) == 0) ;
#endif /* WIN32 */
if ( !r ) cerr << "Warning: No net for this theme!\n";
cerr << "OK!\n";
configuration.setDefaultFrameConf();
if ( _hasConfFile ) {
cerr << "Using configuration file theme.conf\n";
loadConf();
} else {
cerr << "No theme.conf\n";
}
return(r);
}
void Theme::loadConf()
{
Aargh myAargh; /* I want a new one, 'cause the global one is used by
configuration */
myAargh.loadConf(_confFile.c_str());
/* now set things up in configuration */
string value;
if ( myAargh.getArg("NPlayerFrames", value) )
configuration.playerFrameConf.nPlayerFrames = atoi(value.c_str());
if ( myAargh.getArg("PlayerStillB", value) )
configuration.playerFrameConf.playerStillB = atoi(value.c_str());
if ( myAargh.getArg("PlayerStillE", value) )
configuration.playerFrameConf.playerStillE = atoi(value.c_str());
if ( myAargh.getArg("PlayerStillP", value) )
configuration.playerFrameConf.playerStillP = atoi(value.c_str());
if ( myAargh.getArg("PlayerRunB", value) )
configuration.playerFrameConf.playerRunB = atoi(value.c_str());
if ( myAargh.getArg("PlayerRunE", value) )
configuration.playerFrameConf.playerRunE = atoi(value.c_str());
if ( myAargh.getArg("PlayerRunP", value) )
configuration.playerFrameConf.playerRunP = atoi(value.c_str());
if ( myAargh.getArg("PlayerJumpB", value) )
configuration.playerFrameConf.playerJmpB = atoi(value.c_str());
if ( myAargh.getArg("PlayerJumpE", value) )
configuration.playerFrameConf.playerJmpE = atoi(value.c_str());
if ( myAargh.getArg("PlayerJumpP", value) )
configuration.playerFrameConf.playerJmpP = atoi(value.c_str());
if ( myAargh.getArg("NBallFrames", value) )
configuration.ballFrameConf.nBallFrames = atoi(value.c_str());
if ( myAargh.getArg("BallPeriod", value) )
configuration.ballFrameConf.ballPeriod = atoi(value.c_str());
}
|