- Added a possibility to put a file "Res.txt" instead of the folder "Res". The file Res.txt is a simple 1 line text file, telling where to find the Res folder, terminated by "/". For example: "../../wagic_res".
This addresses issue 428 . This could also help us in the future, to develop mods.
This commit is contained in:
wagic.the.homebrew@gmail.com
2010-11-07 09:26:29 +00:00
parent b14e3808db
commit 5d907f5abe
31 changed files with 115 additions and 94 deletions
+7
View File
@@ -11,6 +11,9 @@
#ifndef _FILE_SYSTEM_H_ #ifndef _FILE_SYSTEM_H_
#define _FILE_SYSTEM_H_ #define _FILE_SYSTEM_H_
#define JGE_GET_RES(filename) JFileSystem::GetInstance()->GetResourceFile(filename)
#define JGE_GET_RESPATH() JFileSystem::GetInstance()->GetResourceRoot()
#include <stdio.h> #include <stdio.h>
#include <vector> #include <vector>
#include <map> #include <map>
@@ -109,6 +112,10 @@ public:
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void SetResourceRoot(const string& resourceRoot); void SetResourceRoot(const string& resourceRoot);
string GetResourceRoot();
// Returns a string prefixed with the resource path
string GetResourceFile(string filename);
protected: protected:
JFileSystem(); JFileSystem();
-1
View File
@@ -11,7 +11,6 @@
#ifndef _JGE_H_ #ifndef _JGE_H_
#define _JGE_H_ #define _JGE_H_
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
Binary file not shown.
+11
View File
@@ -257,3 +257,14 @@ void JFileSystem::SetResourceRoot(const string& resourceRoot)
{ {
mResourceRoot = resourceRoot; mResourceRoot = resourceRoot;
} }
string JFileSystem::GetResourceRoot()
{
return mResourceRoot;
}
string JFileSystem::GetResourceFile(string filename)
{
string result = mResourceRoot;
return result.append(filename);
}
+1 -5
View File
@@ -965,11 +965,7 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
JLOG("JRenderer::LoadJPG"); JLOG("JRenderer::LoadJPG");
textureInfo.mBits = NULL; textureInfo.mBits = NULL;
char filenamenew[4096]; char filenamenew[4096];
#ifdef RESPATH sprintf(filenamenew, JGE_GET_RES(filename).c_str());
sprintf(filenamenew, RESPATH"/%s", filename);
#else
sprintf(filenamenew, "Res/%s", filename);
#endif
bool useVideoRAM = (mode == TEX_TYPE_USE_VRAM); bool useVideoRAM = (mode == TEX_TYPE_USE_VRAM);
+4 -6
View File
@@ -9,6 +9,7 @@
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "../include/JSoundSystem.h" #include "../include/JSoundSystem.h"
#include "../include/JFileSystem.h"
#include "../include/JAudio.h" #include "../include/JAudio.h"
#include "../include/JMP3.h" #include "../include/JMP3.h"
#include <string> #include <string>
@@ -108,12 +109,9 @@ void JSoundSystem::DestroySoundSystem()
JMusic *JSoundSystem::LoadMusic(const char *fileName) JMusic *JSoundSystem::LoadMusic(const char *fileName)
{ {
#ifdef RESPATH
string s = RESPATH"/"; string s = JGE_GET_RES(fileName);
#else
string s = "Res/";
#endif
s.append(fileName);
JMusic *music = new JMusic(); JMusic *music = new JMusic();
if (music) if (music)
{ {
+1 -1
View File
@@ -10,7 +10,7 @@ using std::string;
#include "SimplePad.h" #include "SimplePad.h"
#include "GameApp.h" #include "GameApp.h"
#define GLOBAL_SETTINGS RESPATH"/settings/options.txt" #define GLOBAL_SETTINGS "settings/options.txt"
#define PLAYER_SAVEFILE "data.dat" #define PLAYER_SAVEFILE "data.dat"
#define PLAYER_SETTINGS "options.txt" #define PLAYER_SETTINGS "options.txt"
#define PLAYER_COLLECTION "collection.dat" #define PLAYER_COLLECTION "collection.dat"
+2 -2
View File
@@ -2,10 +2,10 @@
#define _LOGGER_H_ #define _LOGGER_H_
//TODO Remove this and use the jge logging facility (same system) //TODO Remove this and use the jge logging facility (same system)
//#define DOLOG #define DOLOG
#ifdef DOLOG #ifdef DOLOG
#define LOG_FILE RESPATH"/debug.txt" #define LOG_FILE "debug.txt"
class Logger{ class Logger{
public: public:
+1
View File
@@ -16,5 +16,6 @@
#include <assert.h> #include <assert.h>
#include "JGE.h" #include "JGE.h"
#include "JFileSystem.h"
#endif //PRECOMPILEDHEADER_H #endif //PRECOMPILEDHEADER_H
+1 -1
View File
@@ -9,7 +9,7 @@ using namespace std;
#include <JGui.h> #include <JGui.h>
class GameObserver; class GameObserver;
class MTGDeck; class MTGDeck;
#define CAMPAIGNS_FOLDER "Res/campaigns/" #define CAMPAIGNS_FOLDER "campaigns/"
class StoryDialogElement:public JGuiObject { class StoryDialogElement:public JGuiObject {
+3 -3
View File
@@ -654,7 +654,7 @@ int AIPlayer::combatDamages(){
AIStats * AIPlayer::getStats(){ AIStats * AIPlayer::getStats(){
if (!stats){ if (!stats){
char statFile[512]; char statFile[512];
sprintf(statFile, RESPATH"/ai/baka/stats/%s.stats", opponent()->deckFileSmall.c_str()); sprintf(statFile,JGE_GET_RES("ai/baka/stats/%s.stats").c_str(), opponent()->deckFileSmall.c_str());
stats = NEW AIStats(this, statFile); stats = NEW AIStats(this, statFile);
} }
return stats; return stats;
@@ -677,7 +677,7 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op
while (found){ while (found){
found = 0; found = 0;
char buffer[512]; char buffer[512];
sprintf(buffer, RESPATH"/ai/baka/deck%i.txt",nbdecks+1); sprintf(buffer, JGE_GET_RES("ai/baka/deck%i.txt").c_str(),nbdecks+1);
std::ifstream file(buffer); std::ifstream file(buffer);
if(file){ if(file){
found = 1; found = 1;
@@ -688,7 +688,7 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op
if (!nbdecks) return NULL; if (!nbdecks) return NULL;
deckid = 1 + WRand() % (nbdecks); deckid = 1 + WRand() % (nbdecks);
} }
sprintf(deckFile, RESPATH"/ai/baka/deck%i.txt",deckid); sprintf(deckFile, JGE_GET_RES("ai/baka/deck%i.txt").c_str(),deckid);
sprintf(avatarFile, "avatar%i.jpg",deckid); sprintf(avatarFile, "avatar%i.jpg",deckid);
sprintf(deckFileSmall, "ai_baka_deck%i",deckid); sprintf(deckFileSmall, "ai_baka_deck%i",deckid);
} }
+1 -1
View File
@@ -255,7 +255,7 @@ int Credits::isDifficultyUnlocked(){
found = 0; found = 0;
char buffer[512]; char buffer[512];
char aiSmallDeckName[512]; char aiSmallDeckName[512];
sprintf(buffer, RESPATH"/ai/baka/deck%i.txt",nbAIDecks+1); sprintf(buffer, JGE_GET_RES("ai/baka/deck%i.txt").c_str(),nbAIDecks+1);
if(fileExists(buffer)){ if(fileExists(buffer)){
found = 1; found = 1;
nbAIDecks++; nbAIDecks++;
+24 -10
View File
@@ -90,6 +90,21 @@ void GameApp::Create()
//_CrtSetBreakAlloc(368); //_CrtSetBreakAlloc(368);
LOG("starting Game"); LOG("starting Game");
//Find the Res folder
std::ifstream mfile("Res.txt");
string resPath;
if(mfile){
if (std::getline(mfile, resPath)) {
if (resPath[resPath.size()-1] == '\r') resPath.erase(resPath.size()-1); //Handle DOS files
//TODO ERROR Handling if file does not exist
JFileSystem::GetInstance()->SetResourceRoot(trim(resPath));
}
mfile.close();
}
LOG("Res Root:");
LOG(JFileSystem::GetInstance()->GetResourceRoot().c_str());
//Link this to our settings manager. //Link this to our settings manager.
options.theGame = this; options.theGame = this;
@@ -99,16 +114,14 @@ void GameApp::Create()
LOG("Checking for music files"); LOG("Checking for music files");
//Test for Music files presence //Test for Music files presence
string filepath = RESPATH; string filepath = JGE_GET_RES(resources.musicFile("Track0.mp3"));
filepath = filepath + "/" + resources.musicFile("Track0.mp3");
std::ifstream file(filepath.c_str()); std::ifstream file(filepath.c_str());
if (file) if (file)
file.close(); file.close();
else else
HasMusic = 0; HasMusic = 0;
filepath = RESPATH; filepath = JGE_GET_RES(resources.musicFile("Track1.mp3"));
filepath = filepath + "/" + resources.musicFile("Track1.mp3");
std::ifstream file2(filepath.c_str()); std::ifstream file2(filepath.c_str());
if (file2) if (file2)
file2.close(); file2.close();
@@ -129,7 +142,8 @@ void GameApp::Create()
manaIcons[Constants::MTG_COLOR_ARTIFACT] = resources.RetrieveQuad("menuicons.png", 2 + 6*36, 38, 32, 32, "c_artifact",RETRIEVE_MANAGE); manaIcons[Constants::MTG_COLOR_ARTIFACT] = resources.RetrieveQuad("menuicons.png", 2 + 6*36, 38, 32, 32, "c_artifact",RETRIEVE_MANAGE);
for (int i = sizeof(manaIcons)/sizeof(manaIcons[0]) - 1; i >= 0; --i) manaIcons[i]->SetHotSpot(16,16); for (int i = sizeof(manaIcons)/sizeof(manaIcons[0]) - 1; i >= 0; --i)
if (manaIcons[i]) manaIcons[i]->SetHotSpot(16,16);
LOG("--Loading back.jpg"); LOG("--Loading back.jpg");
resources.RetrieveTexture("back.jpg",RETRIEVE_MANAGE); resources.RetrieveTexture("back.jpg",RETRIEVE_MANAGE);
@@ -142,9 +156,9 @@ void GameApp::Create()
LOG("--Loading particles.png"); LOG("--Loading particles.png");
resources.RetrieveTexture("particles.png",RETRIEVE_MANAGE); resources.RetrieveTexture("particles.png",RETRIEVE_MANAGE);
jq = resources.RetrieveQuad("particles.png", 0, 0, 32, 32, "particles",RETRIEVE_MANAGE); jq = resources.RetrieveQuad("particles.png", 0, 0, 32, 32, "particles",RETRIEVE_MANAGE);
jq->SetHotSpot(16,16); if (jq) jq->SetHotSpot(16,16);
jq = resources.RetrieveQuad("particles.png", 64, 0, 32, 32, "stars",RETRIEVE_MANAGE); jq = resources.RetrieveQuad("particles.png", 64, 0, 32, 32, "stars",RETRIEVE_MANAGE);
jq->SetHotSpot(16,16); if (jq) jq->SetHotSpot(16,16);
LOG("--Loading fonts"); LOG("--Loading fonts");
string lang = options[Options::LANG].str; string lang = options[Options::LANG].str;
@@ -163,11 +177,11 @@ void GameApp::Create()
resources.RetrieveTexture("shadow.png",RETRIEVE_MANAGE); resources.RetrieveTexture("shadow.png",RETRIEVE_MANAGE);
jq = resources.RetrieveQuad("BattleIcon.png", 0, 0, 25, 25,"BattleIcon",RETRIEVE_MANAGE); jq = resources.RetrieveQuad("BattleIcon.png", 0, 0, 25, 25,"BattleIcon",RETRIEVE_MANAGE);
jq->SetHotSpot(12, 12); if (jq) jq->SetHotSpot(12, 12);
jq = resources.RetrieveQuad("DefenderIcon.png", 0, 0, 24, 23,"DefenderIcon",RETRIEVE_MANAGE); jq = resources.RetrieveQuad("DefenderIcon.png", 0, 0, 24, 23,"DefenderIcon",RETRIEVE_MANAGE);
jq->SetHotSpot(12, 12); if (jq) jq->SetHotSpot(12, 12);
jq = resources.RetrieveQuad("shadow.png", 0, 0, 16, 16,"shadow",RETRIEVE_MANAGE); jq = resources.RetrieveQuad("shadow.png", 0, 0, 16, 16,"shadow",RETRIEVE_MANAGE);
jq->SetHotSpot(8, 8); if (jq) jq->SetHotSpot(8, 8);
jq = resources.RetrieveQuad("phasebar.png",0,0,0,0,"phasebar",RETRIEVE_MANAGE); jq = resources.RetrieveQuad("phasebar.png",0,0,0,0,"phasebar",RETRIEVE_MANAGE);
LOG("Init Collection"); LOG("Init Collection");
+8 -8
View File
@@ -498,7 +498,7 @@ int GameSettings::save(){
if(profileOptions){ if(profileOptions){
//Force our directories to exist. //Force our directories to exist.
MAKEDIR(RESPATH"/profiles"); MAKEDIR(JGE_GET_RES("profiles").c_str());
string temp = profileFile("","",false,false); string temp = profileFile("","",false,false);
MAKEDIR(temp.c_str()); MAKEDIR(temp.c_str());
temp+="/stats"; temp+="/stats";
@@ -521,11 +521,11 @@ string GameSettings::profileFile(string filename, string fallback,bool sanity, b
if(!(*this)[Options::ACTIVE_PROFILE].isDefault()) { if(!(*this)[Options::ACTIVE_PROFILE].isDefault()) {
//No file, return root of profile directory //No file, return root of profile directory
if(filename == ""){ if(filename == ""){
sprintf(buf,"%sprofiles/%s",( relative ? "" : RESPATH"/" ),profile.c_str()); sprintf(buf,"%sprofiles/%s",( relative ? "" : JGE_GET_RES("").c_str() ),profile.c_str());
return buf; return buf;
} }
//Return file //Return file
sprintf(buf,RESPATH"/profiles/%s/%s",profile.c_str(),filename.c_str()); sprintf(buf,JGE_GET_RES("profiles/%s/%s").c_str(),profile.c_str(),filename.c_str());
if(fileExists(buf)){ if(fileExists(buf)){
if(relative) if(relative)
sprintf(buf,"profiles/%s/%s",profile.c_str(),filename.c_str()); sprintf(buf,"profiles/%s/%s",profile.c_str(),filename.c_str());
@@ -534,13 +534,13 @@ string GameSettings::profileFile(string filename, string fallback,bool sanity, b
} }
else{ else{
//Use the default directory. //Use the default directory.
sprintf(buf,"%splayer%s%s",(relative ? "" : RESPATH"/"),(filename == "" ? "" : "/"), filename.c_str()); sprintf(buf,"%splayer%s%s",(relative ? "" :JGE_GET_RES("").c_str()),(filename == "" ? "" : "/"), filename.c_str());
return buf; return buf;
} }
//Don't fallback if sanity checking is disabled.. //Don't fallback if sanity checking is disabled..
if(!sanity){ if(!sanity){
sprintf(buf,"%sprofiles/%s%s%s",(relative ? "" : RESPATH"/"),profile.c_str(),(filename == "" ? "" : "/"), filename.c_str()); sprintf(buf,"%sprofiles/%s%s%s",(relative ? "" : JGE_GET_RES("").c_str()),profile.c_str(),(filename == "" ? "" : "/"), filename.c_str());
return buf; return buf;
} }
@@ -548,7 +548,7 @@ string GameSettings::profileFile(string filename, string fallback,bool sanity, b
if(fallback == "") if(fallback == "")
return ""; return "";
sprintf(buf,"%s%s%s%s",(relative ? "" : RESPATH"/"),fallback.c_str(),(filename == "" ? "" : "/"), filename.c_str()); sprintf(buf,"%s%s%s%s",(relative ? "" : JGE_GET_RES("").c_str()),fallback.c_str(),(filename == "" ? "" : "/"), filename.c_str());
return buf; return buf;
} }
@@ -561,7 +561,7 @@ void GameSettings::reloadProfile(bool images){
void GameSettings::checkProfile(){ void GameSettings::checkProfile(){
if(!globalOptions) if(!globalOptions)
globalOptions = NEW GameOptions(GLOBAL_SETTINGS); globalOptions = NEW GameOptions(JGE_GET_RES(GLOBAL_SETTINGS));
//If it doesn't exist, load current profile. //If it doesn't exist, load current profile.
if(!profileOptions){ if(!profileOptions){
@@ -589,7 +589,7 @@ void GameSettings::checkProfile(){
//Make the proper directories //Make the proper directories
if(profileOptions){ if(profileOptions){
//Force our directories to exist. //Force our directories to exist.
MAKEDIR(RESPATH"/profiles"); MAKEDIR(JGE_GET_RES("profiles").c_str());
string temp = profileFile("","",false,false); string temp = profileFile("","",false,false);
MAKEDIR(temp.c_str()); MAKEDIR(temp.c_str());
temp+="/stats"; temp+="/stats";
+5 -5
View File
@@ -214,7 +214,7 @@ void GameStateDeckViewer::Start()
lastPos = 0; lastPos = 0;
lastTotal = 0; lastTotal = 0;
pricelist = NEW PriceList(RESPATH"/settings/prices.dat",mParent->collection); pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(),mParent->collection);
playerdata = NEW PlayerData(mParent->collection); playerdata = NEW PlayerData(mParent->collection);
myCollection = NEW DeckDataWrapper(playerdata->collection); myCollection = NEW DeckDataWrapper(playerdata->collection);
myCollection->Sort(WSrcCards::SORT_ALPHA); myCollection->Sort(WSrcCards::SORT_ALPHA);
@@ -306,7 +306,7 @@ void GameStateDeckViewer::saveDeck(){
void GameStateDeckViewer::saveAsAIDeck( string deckName ) void GameStateDeckViewer::saveAsAIDeck( string deckName )
{ {
DeckManager * deckManager = DeckManager::GetInstance(); DeckManager * deckManager = DeckManager::GetInstance();
vector<DeckMetaData *> aiDecks = GameState::getValidDeckMetaData( RESPATH"/ai/baka", "ai_baka", NULL); vector<DeckMetaData *> aiDecks = GameState::getValidDeckMetaData( JGE_GET_RES("ai/baka"), "ai_baka", NULL);
int nbAiDecks = aiDecks.size() + 1; int nbAiDecks = aiDecks.size() + 1;
aiDecks.clear(); aiDecks.clear();
@@ -320,8 +320,8 @@ void GameStateDeckViewer::saveAsAIDeck( string deckName )
else else
oss << myDeck->parent->meta_desc; oss << myDeck->parent->meta_desc;
string deckDesc = oss.str(); string deckDesc = oss.str();
string filepath = RESPATH; string filepath = JGE_GET_RES("ai/baka/");
filepath.append("/ai/baka/").append( defaultAiDeckName ).append( ".txt" ); filepath.append( defaultAiDeckName ).append( ".txt" );
DebugTrace("saving AI deck " << filepath); DebugTrace("saving AI deck " << filepath);
myDeck->save( filepath, true, deckName, deckDesc); myDeck->save( filepath, true, deckName, deckDesc);
} }
@@ -1503,7 +1503,7 @@ int GameStateDeckViewer::loadDeck(int deckid){
found = 0; found = 0;
char buffer[512]; char buffer[512];
char smallDeckName[512]; char smallDeckName[512];
sprintf(buffer, "%s/deck%i.txt",RESPATH"/ai/baka",nbDecks+1); sprintf(buffer, "%s/deck%i.txt",JGE_GET_RES("ai/baka").c_str(),nbDecks+1);
if(fileExists(buffer)){ if(fileExists(buffer)){
MTGDeck * mtgd = NEW MTGDeck(buffer,NULL,1); MTGDeck * mtgd = NEW MTGDeck(buffer,NULL,1);
found = 1; found = 1;
+5 -6
View File
@@ -81,7 +81,7 @@ void GameStateDuel::Start()
#ifdef TESTSUITE #ifdef TESTSUITE
SAFE_DELETE(testSuite); SAFE_DELETE(testSuite);
testSuite = NEW TestSuite(RESPATH"/test/_tests.txt",mParent->collection); testSuite = NEW TestSuite(JGE_GET_RES("test/_tests.txt").c_str(),mParent->collection);
#endif #endif
mGamePhase = DUEL_STATE_CHOOSE_DECK1; mGamePhase = DUEL_STATE_CHOOSE_DECK1;
@@ -126,7 +126,7 @@ void GameStateDuel::Start()
else else
deckmenu->Add( MENUITEM_NEW_DECK, "Create your Deck!", "Highly recommended to get\nthe full Wagic experience!"); deckmenu->Add( MENUITEM_NEW_DECK, "Create your Deck!", "Highly recommended to get\nthe full Wagic experience!");
premadeDeck = true; premadeDeck = true;
fillDeckMenu(deckmenu,RESPATH"/player/premade"); fillDeckMenu(deckmenu,JGE_GET_RES("player/premade"));
} }
deckmenu->Add( MENUITEM_NEW_DECK, "New Deck...", "Create a new deck to play with."); deckmenu->Add( MENUITEM_NEW_DECK, "New Deck...", "Create a new deck to play with.");
deckmenu->Add( MENUITEM_CANCEL, "Main Menu", "Return to Main Menu"); deckmenu->Add( MENUITEM_CANCEL, "Main Menu", "Return to Main Menu");
@@ -143,7 +143,7 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){
if (!isAI) { //Human Player if (!isAI) { //Human Player
char deckFile[255]; char deckFile[255];
if(premadeDeck) if(premadeDeck)
sprintf(deckFile, RESPATH"/player/premade/deck%i.txt",decknb); sprintf(deckFile, JGE_GET_RES("player/premade/deck%i.txt").c_str(),decknb);
else else
sprintf(deckFile, "%s/deck%i.txt",options.profileFile().c_str(), decknb); sprintf(deckFile, "%s/deck%i.txt",options.profileFile().c_str(), decknb);
char deckFileSmall[255]; char deckFileSmall[255];
@@ -226,8 +226,7 @@ void GameStateDuel::End()
//TODO Move This to utils or ResourceManager. Don't we have more generic functions that can do that? //TODO Move This to utils or ResourceManager. Don't we have more generic functions that can do that?
bool GameStateDuel::MusicExist(string FileName){ bool GameStateDuel::MusicExist(string FileName){
string filepath = RESPATH; string filepath = JGE_GET_RES(resources.musicFile(FileName));
filepath = filepath + "/" + resources.musicFile(FileName);
std::ifstream file(filepath.c_str()); std::ifstream file(filepath.c_str());
if (file) { if (file) {
file.close(); file.close();
@@ -244,7 +243,7 @@ void GameStateDuel::ensureOpponentMenu(){
if (options[Options::EVILTWIN_MODE_UNLOCKED].number) if (options[Options::EVILTWIN_MODE_UNLOCKED].number)
opponentMenu->Add( MENUITEM_EVIL_TWIN, "Evil Twin", _("Can you play against yourself?").c_str()); opponentMenu->Add( MENUITEM_EVIL_TWIN, "Evil Twin", _("Can you play against yourself?").c_str());
DeckManager * deckManager = DeckManager::GetInstance(); DeckManager * deckManager = DeckManager::GetInstance();
vector<DeckMetaData* > opponentDeckList = fillDeckMenu( opponentMenu, RESPATH"/ai/baka", "ai_baka", mPlayers[0]); vector<DeckMetaData* > opponentDeckList = fillDeckMenu( opponentMenu, JGE_GET_RES("ai/baka"), "ai_baka", mPlayers[0]);
deckManager->updateMetaDataList(&opponentDeckList, true); deckManager->updateMetaDataList(&opponentDeckList, true);
opponentMenu->Add( MENUITEM_CANCEL, "Cancel", _("Choose a different player deck").c_str()); opponentMenu->Add( MENUITEM_CANCEL, "Cancel", _("Choose a different player deck").c_str());
opponentDeckList.clear(); opponentDeckList.clear();
+9 -9
View File
@@ -103,7 +103,7 @@ void GameStateMenu::Create()
for (int j=0;j<2;j++){ for (int j=0;j<2;j++){
sprintf(buf,"menuicons%d%d",i,j); sprintf(buf,"menuicons%d%d",i,j);
mIcons[n] = resources.RetrieveQuad("menuicons.png", 2 + i * 36.0f, 2.0f + j * 36.0f, 32.0f, 32.0f, buf); mIcons[n] = resources.RetrieveQuad("menuicons.png", 2 + i * 36.0f, 2.0f + j * 36.0f, 32.0f, 32.0f, buf);
mIcons[n]->SetHotSpot(16,16); if(mIcons[n]) mIcons[n]->SetHotSpot(16,16);
n++; n++;
} }
} }
@@ -112,7 +112,7 @@ void GameStateMenu::Create()
bool langChosen = false; bool langChosen = false;
string lang = options[Options::LANG].str; string lang = options[Options::LANG].str;
if (lang.size()){ if (lang.size()){
lang = "Res/lang/" + lang + ".txt"; lang = JGE_GET_RES("lang/") + lang + ".txt";
if (fileExists(lang.c_str())) langChosen = true; if (fileExists(lang.c_str())) langChosen = true;
} }
if (!langChosen){ if (!langChosen){
@@ -155,7 +155,7 @@ void GameStateMenu::Start(){
bgTexture = resources.RetrieveTexture("menutitle.png", RETRIEVE_LOCK); bgTexture = resources.RetrieveTexture("menutitle.png", RETRIEVE_LOCK);
mBg = resources.RetrieveQuad("menutitle.png", 0, 0, 256, 166); // Create background quad for rendering. mBg = resources.RetrieveQuad("menutitle.png", 0, 0, 256, 166); // Create background quad for rendering.
mBg->SetHotSpot(128,50); if (mBg) mBg->SetHotSpot(128,50);
if (MENU_STATE_MAJOR_MAINMENU == currentState) if (MENU_STATE_MAJOR_MAINMENU == currentState)
currentState = currentState | MENU_STATE_MINOR_FADEIN; currentState = currentState | MENU_STATE_MINOR_FADEIN;
@@ -286,7 +286,7 @@ string GameStateMenu::loadRandomWallpaper() {
return wallpaper; return wallpaper;
vector<string> wallpapers; vector<string> wallpapers;
std::ifstream file("Res/graphics/wallpapers.txt"); std::ifstream file(JGE_GET_RES("graphics/wallpapers.txt").c_str());
if (!file) return wallpaper; if (!file) return wallpaper;
@@ -322,11 +322,11 @@ void GameStateMenu::loadLangMenu(){
if (!subMenuController) return; if (!subMenuController) return;
resetDirectory(); resetDirectory();
if (!mDip){ if (!mDip){
mDip = opendir("Res/lang"); mDip = opendir(JGE_GET_RES("lang").c_str());
} }
while ((mDit = readdir(mDip))){ while ((mDit = readdir(mDip))){
string filename = "Res/lang/"; string filename = JGE_GET_RES("lang/");
filename += mDit->d_name; filename += mDit->d_name;
std::ifstream file(filename.c_str()); std::ifstream file(filename.c_str());
string s; string s;
@@ -352,11 +352,11 @@ void GameStateMenu::listPrimitives(){
LOG("GameStateMenu::listPrimitives"); LOG("GameStateMenu::listPrimitives");
resetDirectory(); resetDirectory();
if (!mDip){ if (!mDip){
mDip = opendir("Res/sets/primitives/"); mDip = opendir(JGE_GET_RES("sets/primitives/").c_str());
} }
while ((mDit = readdir(mDip))){ while ((mDit = readdir(mDip))){
string filename = "Res/sets/primitives/"; string filename = JGE_GET_RES("sets/primitives/");
filename += mDit->d_name; filename += mDit->d_name;
std::ifstream file(filename.c_str()); std::ifstream file(filename.c_str());
if(!file) continue; if(!file) continue;
@@ -414,7 +414,7 @@ void GameStateMenu::Update(float dt)
}else{ }else{
mReadConf = 1; mReadConf = 1;
} }
if (!nextDirectory(RESPATH"/sets/","_cards.dat")){ if (!nextDirectory(JGE_GET_RES("sets/").c_str(),"_cards.dat")){
//Remove temporary translations //Remove temporary translations
Translator::GetInstance()->tempValues.clear(); Translator::GetInstance()->tempValues.clear();
+1 -1
View File
@@ -79,7 +79,7 @@ void GameStateShop::Start(){
MTGAllCards * ac = GameApp::collection; MTGAllCards * ac = GameApp::collection;
playerdata = NEW PlayerData(ac); playerdata = NEW PlayerData(ac);
myCollection = NEW DeckDataWrapper(playerdata->collection); myCollection = NEW DeckDataWrapper(playerdata->collection);
pricelist = NEW PriceList(RESPATH"/settings/prices.dat",ac); pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(),ac);
for(int i=0;i<SHOP_SLOTS;i++){ for(int i=0;i<SHOP_SLOTS;i++){
WGuiCardDistort * dist; WGuiCardDistort * dist;
if(i < BOOSTER_SLOTS) if(i < BOOSTER_SLOTS)
+1 -1
View File
@@ -55,7 +55,7 @@ void GameStateStory::loadStoriesMenu(const char * root){
void GameStateStory::Start() { void GameStateStory::Start() {
flow = NULL; flow = NULL;
menu = NULL; menu = NULL;
loadStoriesMenu( RESPATH"/campaigns/"); loadStoriesMenu(JGE_GET_RES("campaigns/").c_str());
} }
void GameStateStory::Update(float dt) { void GameStateStory::Update(float dt) {
+2 -2
View File
@@ -513,7 +513,7 @@ MTGDeck::MTGDeck(MTGAllCards * _allcards){
} }
int MTGDeck::totalPrice(){ int MTGDeck::totalPrice(){
int total = 0; int total = 0;
PriceList * pricelist = NEW PriceList(RESPATH"/settings/prices.dat",GameApp::collection); PriceList * pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(),GameApp::collection);
map<int,int>::iterator it; map<int,int>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){ for ( it=cards.begin() ; it != cards.end(); it++ ){
int nb = it->second; int nb = it->second;
@@ -932,7 +932,7 @@ MTGSetInfo::MTGSetInfo(string _id) {
counts[i] = 0; counts[i] = 0;
char myFilename[4096]; char myFilename[4096];
sprintf(myFilename, RESPATH"/sets/%s/booster.txt", id.c_str()); sprintf(myFilename, JGE_GET_RES("sets/%s/booster.txt").c_str(), id.c_str());
mPack = NEW MTGPack(myFilename); mPack = NEW MTGPack(myFilename);
if(!mPack->isValid()){ if(!mPack->isValid()){
SAFE_DELETE(mPack); SAFE_DELETE(mPack);
+3 -3
View File
@@ -220,13 +220,13 @@ MTGPack * MTGPacks::randomPack(int key){
return packs[key%s]; return packs[key%s];
} }
void MTGPacks::loadAll(){ void MTGPacks::loadAll(){
DIR *mDip = opendir(RESPATH"/packs/"); DIR *mDip = opendir(JGE_GET_RES("packs/").c_str());
struct dirent *mDit; struct dirent *mDit;
if(!mDip) return; if(!mDip) return;
while ((mDit = readdir(mDip))){ while ((mDit = readdir(mDip))){
char myFilename[4096]; char myFilename[4096];
sprintf(myFilename, RESPATH"/packs/%s", mDit->d_name); sprintf(myFilename, JGE_GET_RES("packs/%s").c_str(), mDit->d_name);
if(mDit->d_name[0] == '.') continue; if(mDit->d_name[0] == '.') continue;
if(!strcmp(mDit->d_name,"default_booster.txt")) continue; if(!strcmp(mDit->d_name,"default_booster.txt")) continue;
MTGPack * p = NEW MTGPack(myFilename); MTGPack * p = NEW MTGPack(myFilename);
@@ -276,7 +276,7 @@ bool MTGPack::isUnlocked(){
MTGPack * MTGPacks::getDefault(){ MTGPack * MTGPacks::getDefault(){
if(!defaultBooster.isValid()){ if(!defaultBooster.isValid()){
defaultBooster.load(RESPATH"/packs/default_booster.txt"); defaultBooster.load(JGE_GET_RES("packs/default_booster.txt"));
defaultBooster.unlockStatus = 1; defaultBooster.unlockStatus = 1;
if(!defaultBooster.isValid()){ if(!defaultBooster.isValid()){
MTGPackSlot * ps = NEW MTGPackSlot(); ps->copies = 1; MTGPackSlot * ps = NEW MTGPackSlot(); ps->copies = 1;
+6 -6
View File
@@ -94,7 +94,7 @@ void OptionSelect::addSelection(string s){
//OptionProfile //OptionProfile
const string OptionProfile::DIRTESTER = "collection.dat"; const string OptionProfile::DIRTESTER = "collection.dat";
OptionProfile::OptionProfile(GameApp * _app, JGuiListener * jgl) : OptionDirectory(RESPATH"/profiles", Options::ACTIVE_PROFILE, "Profile", DIRTESTER){ OptionProfile::OptionProfile(GameApp * _app, JGuiListener * jgl) : OptionDirectory(JGE_GET_RES("profiles"), Options::ACTIVE_PROFILE, "Profile", DIRTESTER){
app = _app; app = _app;
listener = jgl; listener = jgl;
height=60; height=60;
@@ -271,10 +271,10 @@ void OptionLanguage::Reload(){
struct dirent *mDit; struct dirent *mDit;
DIR *mDip; DIR *mDip;
mDip = opendir("Res/lang"); mDip = opendir(JGE_GET_RES("lang").c_str());
while ((mDit = readdir(mDip))){ while ((mDit = readdir(mDip))){
string filename = "Res/lang/"; string filename = JGE_GET_RES("lang/");
filename += mDit->d_name; filename += mDit->d_name;
std::ifstream file(filename.c_str()); std::ifstream file(filename.c_str());
string s; string s;
@@ -368,7 +368,7 @@ OptionDirectory::OptionDirectory(string root, int id, string displayValue, strin
} }
const string OptionTheme::DIRTESTER = "preview.png"; const string OptionTheme::DIRTESTER = "preview.png";
OptionTheme::OptionTheme(OptionThemeStyle * style) : OptionDirectory(RESPATH"/themes", Options::ACTIVE_THEME, "Current Theme", DIRTESTER){ OptionTheme::OptionTheme(OptionThemeStyle * style) : OptionDirectory(JGE_GET_RES("themes"), Options::ACTIVE_THEME, "Current Theme", DIRTESTER){
addSelection("Default"); addSelection("Default");
sort(selections.begin(),selections.end()); sort(selections.begin(),selections.end());
initSelections(); initSelections();
@@ -402,9 +402,9 @@ void OptionTheme::Render(){
author = ""; author = "";
bChecked = true; bChecked = true;
if(selections[value] == "Default") if(selections[value] == "Default")
sprintf(buf,RESPATH"/graphics/themeinfo.txt"); sprintf(buf,JGE_GET_RES("graphics/themeinfo.txt").c_str());
else else
sprintf(buf,RESPATH"/themes/%s/themeinfo.txt",selections[value].c_str()); sprintf(buf,JGE_GET_RES("themes/%s/themeinfo.txt").c_str(),selections[value].c_str());
std::ifstream file(buf); std::ifstream file(buf);
if(file){ if(file){
string temp; string temp;
+1 -1
View File
@@ -383,7 +383,7 @@ int Rules::load(string _filename){
if (fileExists(_filename.c_str())){ if (fileExists(_filename.c_str())){
sprintf(filename, "%s", _filename.c_str()); sprintf(filename, "%s", _filename.c_str());
}else{ }else{
sprintf(filename, RESPATH"/rules/%s", _filename.c_str()); sprintf(filename, JGE_GET_RES("rules/%s").c_str(), _filename.c_str());
} }
std::ifstream file(filename); std::ifstream file(filename);
std::string s; std::string s;
+1 -1
View File
@@ -269,7 +269,7 @@ void StoryDuel::init(){
Player * players[2]; Player * players[2];
char folder[255], deckFile[255],deckFileSmall[255]; char folder[255], deckFile[255],deckFileSmall[255];
sprintf(folder, CAMPAIGNS_FOLDER"%s/%s" ,mParent->folder.c_str(), pageId.c_str()); sprintf(folder, JGE_GET_RES(CAMPAIGNS_FOLDER"%s/%s").c_str() ,mParent->folder.c_str(), pageId.c_str());
sprintf(deckFile, "%s/deck.txt", folder); sprintf(deckFile, "%s/deck.txt", folder);
MTGDeck * tempDeck = NEW MTGDeck(deckFile, GameApp::collection); MTGDeck * tempDeck = NEW MTGDeck(deckFile, GameApp::collection);
+1 -1
View File
@@ -40,7 +40,7 @@ string WStyle::stylized(string filename){
void StyleManager::loadRules(){ void StyleManager::loadRules(){
killRules(); killRules();
//TODO Placeholder until XML format available. //TODO Placeholder until XML format available.
string filename = RESPATH"/" + resources.graphicsFile("style.txt"); string filename = JGE_GET_RES(resources.graphicsFile("style.txt"));
TiXmlDocument xmlfile(filename.c_str()); TiXmlDocument xmlfile(filename.c_str());
if(!xmlfile.LoadFile()) if(!xmlfile.LoadFile())
return; return;
+1 -1
View File
@@ -165,7 +165,7 @@ void Task::loadAIDeckNames() {
while (found){ while (found){
found = 0; found = 0;
char buffer[512]; char buffer[512];
sprintf(buffer, "%s/deck%i.txt",RESPATH"/ai/baka",nbDecks + 1); sprintf(buffer, "%s/deck%i.txt",JGE_GET_RES("ai/baka").c_str(),nbDecks + 1);
if(fileExists(buffer)){ if(fileExists(buffer)){
found = 1; found = 1;
+3 -3
View File
@@ -316,7 +316,7 @@ void TestSuite::initGame(){
DebugTrace("TESTUITE Init Game Done !"); DebugTrace("TESTUITE Init Game Done !");
} }
int TestSuite::Log(const char * text){ int TestSuite::Log(const char * text){
ofstream file (RESPATH"/test/results.html",ios_base::app); ofstream file (JGE_GET_RES("test/results.html").c_str(),ios_base::app);
if (file){ if (file){
file << text; file << text;
file << "\n"; file << "\n";
@@ -429,7 +429,7 @@ TestSuite::TestSuite(const char * filename,MTGAllCards* _collection){
file.close(); file.close();
} }
ofstream file2 (RESPATH"/test/results.html"); ofstream file2 (JGE_GET_RES("/test/results.html").c_str());
if (file2){ if (file2){
file2 << "<html><head>"; file2 << "<html><head>";
#ifdef WIN32 #ifdef WIN32
@@ -496,7 +496,7 @@ int TestSuite::load(const char * _filename){
forceAbility = false; forceAbility = false;
gameType = GAME_TYPE_CLASSIC; gameType = GAME_TYPE_CLASSIC;
char filename[4096]; char filename[4096];
sprintf(filename, RESPATH"/test/%s", _filename); sprintf(filename, JGE_GET_RES("/test/%s").c_str(), _filename);
std::ifstream file(filename); std::ifstream file(filename);
std::string s; std::string s;
loadRandValues(""); loadRandValues("");
+5 -5
View File
@@ -37,7 +37,7 @@ string Translator::translate(string value){
Translator::~Translator(){ Translator::~Translator(){
#if defined DEBUG_TRANSLATE #if defined DEBUG_TRANSLATE
if (!checkMisses) return; if (!checkMisses) return;
std::ofstream file("Res/lang/missing.txt"); std::ofstream file(JGE_GET_RES("lang/missing.txt").c_str());
char writer[4096]; char writer[4096];
if (file){ if (file){
map<string,int>::iterator it; map<string,int>::iterator it;
@@ -78,7 +78,7 @@ void Translator::load(string filename, map<string,string> * dictionary) {
#if defined DEBUG_TRANSLATE #if defined DEBUG_TRANSLATE
if (!checkMisses) return; if (!checkMisses) return;
std::ifstream file2("Res/lang/dontcare.txt"); std::ifstream file2(JGE_GET_RES("lang/dontcare.txt").c_str());
if(file2){ if(file2){
string s; string s;
@@ -98,14 +98,14 @@ void Translator::load(string filename, map<string,string> * dictionary) {
void Translator::initCards(){ void Translator::initCards(){
string lang = options[Options::LANG].str; string lang = options[Options::LANG].str;
if (!lang.size()) return; if (!lang.size()) return;
string cards_dict = "Res/lang/" + lang + "_cards.txt"; string cards_dict = JGE_GET_RES("lang/") + lang + "_cards.txt";
load(cards_dict,&tempValues); load(cards_dict,&tempValues);
} }
void Translator::initDecks(){ void Translator::initDecks(){
string lang = options[Options::LANG].str; string lang = options[Options::LANG].str;
if (!lang.size()) return; if (!lang.size()) return;
string decks_dict = "Res/lang/" + lang + "_decks.txt"; string decks_dict = JGE_GET_RES("lang/") + lang + "_decks.txt";
// Load file // Load file
std::ifstream file(decks_dict.c_str()); std::ifstream file(decks_dict.c_str());
@@ -136,7 +136,7 @@ void Translator::init() {
#endif #endif
string lang = options[Options::LANG].str; string lang = options[Options::LANG].str;
if (!lang.size()) return; if (!lang.size()) return;
string name = "Res/lang/" + lang + ".txt"; string name = JGE_GET_RES("lang/") + lang + ".txt";
if (fileExists(name.c_str())){ if (fileExists(name.c_str())){
// fixup for Chinese language support. // fixup for Chinese language support.
+1 -1
View File
@@ -489,7 +489,7 @@ int WSrcDeck::getCount(int count){
} }
int WSrcDeck::totalPrice(){ int WSrcDeck::totalPrice(){
int total = 0; int total = 0;
PriceList * pricelist = NEW PriceList(RESPATH"/settings/prices.dat",GameApp::collection); PriceList * pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(),GameApp::collection);
map<int,int>::iterator it; map<int,int>::iterator it;
for ( it=copies.begin() ; it != copies.end(); it++ ){ for ( it=copies.begin() ; it != copies.end(); it++ ){
int nb = it->second; int nb = it->second;
+5 -7
View File
@@ -683,7 +683,7 @@ string WResourceManager::cardFile(const string filename){
if(set.size()){ if(set.size()){
char zipname[512]; char zipname[512];
sprintf(zipname, "Res/themes/%s/sets/%s/%s.zip", theme.c_str(), set.c_str(),set.c_str()); sprintf(zipname, JGE_GET_RES("themes/%s/sets/%s/%s.zip").c_str(), theme.c_str(), set.c_str(),set.c_str());
if (fs->AttachZipFile(zipname)) if (fs->AttachZipFile(zipname))
return filename.substr(i+1); return filename.substr(i+1);
} }
@@ -718,7 +718,7 @@ string WResourceManager::cardFile(const string filename){
if(set.size()){ if(set.size()){
char zipname[512]; char zipname[512];
sprintf(zipname, "Res/sets/%s/%s.zip", set.c_str(),set.c_str()); sprintf(zipname, JGE_GET_RES("sets/%s/%s.zip").c_str(), set.c_str(),set.c_str());
if (fs->AttachZipFile(zipname)) if (fs->AttachZipFile(zipname))
return filename.substr(i+1); return filename.substr(i+1);
} }
@@ -808,13 +808,13 @@ int WResourceManager::dirOK(string dirname){
char fname[512]; char fname[512];
#if defined (WIN32) #if defined (WIN32)
sprintf(fname,RESPATH"/%s",dirname.c_str()); sprintf(fname,JGE_GET_RES(dirname).c_str());
struct _stat statBuffer; struct _stat statBuffer;
return (_stat(fname, &statBuffer) >= 0 && // make sure it exists return (_stat(fname, &statBuffer) >= 0 && // make sure it exists
statBuffer.st_mode & S_IFDIR); // and it's not a file statBuffer.st_mode & S_IFDIR); // and it's not a file
#else #else
sprintf(fname,RESPATH"/%s",dirname.c_str()); sprintf(fname,JGE_GET_RES(dirname).c_str());
struct stat st; struct stat st;
if(stat(fname,&st) == 0) if(stat(fname,&st) == 0)
return 1; return 1;
@@ -824,11 +824,9 @@ char fname[512];
int WResourceManager::fileOK(string filename, bool relative){ int WResourceManager::fileOK(string filename, bool relative){
char fname[512];
std::ifstream * fp = NULL; std::ifstream * fp = NULL;
if(relative){ if(relative){
sprintf(fname,RESPATH"/%s",filename.c_str()); fp = NEW std::ifstream(JGE_GET_RES(filename).c_str());
fp = NEW std::ifstream(fname);
} }
else else
fp = NEW std::ifstream(filename.c_str()); fp = NEW std::ifstream(filename.c_str());
+1 -3
View File
@@ -64,9 +64,7 @@ if(fichier){
return 1; return 1;
} }
char alternateFilename[512]; std::ifstream fichier2(JGE_GET_RES(filename).c_str());
sprintf(alternateFilename, RESPATH"/%s",filename);
std::ifstream fichier2(alternateFilename);
if(fichier2){ if(fichier2){
fichier2.close(); fichier2.close();
return 1; return 1;