From 354cd9ff21e878c9a34866b0c3916e42e226d105 Mon Sep 17 00:00:00 2001 From: Reimar Date: Sat, 12 Dec 2015 16:20:42 +0100 Subject: Now taking env variable RCADE_DATA and RCADE_SAVE. Default: data/ and save/ . also old saves are not compatible --- main.cpp | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 738743d..305c67f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,11 @@ #include "main.h" + + +string get_data_path() +{ + return DATA_PATH; +} + AbstractInteractive* getWeaponInfo(Weapon* w, SDL_Rect target, int textSize) { SDL_Rect tRect = target; @@ -62,7 +69,7 @@ Shop::Shop(Account** nuser, int ngameMenu) gameMenu = ngameMenu; currentWeapon = 0; currentShip = 0; - SDL_Surface* BG = loadBMP("data/images/bg_stars.bmp"); + SDL_Surface* BG = loadBMP(get_data_path() + "images/bg_stars.bmp"); SDL_Surface* mbg = SDL_CreateRGBSurface(0,400,400,32,0,0,0,0); SDL_FillRect(mbg,NULL,0x000102); SDL_SetColorKey(mbg,SDL_SRCCOLORKEY,0x000102); @@ -88,7 +95,7 @@ Shop::Shop(Account** nuser, int ngameMenu) //reading available weapons ifstream ins; - string path = "data/weapons/"; + string path = get_data_path() + "weapons/"; ins.open((path+"weapons.txt").c_str()); char workaround; ins >> workaround; @@ -126,11 +133,11 @@ Shop::Shop(Account** nuser, int ngameMenu) subRect.h = height; Scrollable* temps = new Scrollable(targetRect, tempm, subRect, false, true); submenues.push_back(temps); - path = "data/ships/user/"; + path = get_data_path() + "ships/user/"; ins.open((path+"userships.txt").c_str()); ins >> workaround; vector shipPics; - Weapon empty = Weapon("data/weapons/empty.txt"); + Weapon empty = Weapon(get_data_path() + "weapons/empty.txt"); while(ins.good()) { string filepath; @@ -270,7 +277,7 @@ void Shop::draw(SDL_Surface* screen) textColor.r = 255; textColor.g = 255; textColor.b = 255; - TTF_Font *font = TTF_OpenFont("data/fonts/OpenSans-Semibold.ttf", 30); + TTF_Font *font = TTF_OpenFont((get_data_path() + "fonts/OpenSans-Semibold.ttf").c_str(), 30); SDL_Surface* headline = NULL; headline = TTF_RenderText_Solid(font, "Shop",textColor); if(headline == NULL) @@ -320,7 +327,7 @@ InventoryMenu::InventoryMenu(Account** nuser, int ngameMenu) MY = 0; user = nuser; gameMenu = ngameMenu; - BG = new SlidingBackground(loadBMP("data/images/bg_stars.bmp"), 0, 100); + BG = new SlidingBackground(loadBMP(get_data_path() + "images/bg_stars.bmp"), 0, 100); SDL_Rect backPos; backPos.x = 0; backPos.y = 460; @@ -462,8 +469,8 @@ int InventoryMenu::handleEvents(SDL_Event event) { SDL_FreeSurface(cursor); cursor = NULL; - int x = event.button.x; - int y = event.button.y; +// int x = event.button.x; +// int y = event.button.y; } } @@ -523,12 +530,12 @@ bool init(SDL_Surface*& screen) Menu* makeLoadGameMenu(SDL_Surface *screen) { - string bfile = "data/images/bg_stars.bmp"; + string bfile = get_data_path() + "images/bg_stars.bmp"; SDL_Surface *bg = loadBMP(bfile); vector ts; vector ti; ifstream ins; - ins.open("save/saves.txt"); + ins.open((SAVE_PATH + "saves.txt").c_str()); char workaround; ins >> workaround; int counter = 0; @@ -551,7 +558,7 @@ Menu* makeLoadGameMenu(SDL_Surface *screen) Menu* makeMainMenu(SDL_Surface *screen) { - string bfile = "data/images/bg_stars.bmp"; + string bfile = get_data_path() + "images/bg_stars.bmp"; SDL_Surface *bg = loadBMP(bfile); vector ts; ts.push_back("New Game"); @@ -568,7 +575,7 @@ Menu* makeMainMenu(SDL_Surface *screen) Menu* makeGameMenu(SDL_Surface *screen) { - string bfile = "data/images/bg_stars.bmp"; + string bfile = get_data_path() + "images/bg_stars.bmp"; SDL_Surface *bg = loadBMP(bfile); vector ts; ts.push_back("Missions"); @@ -591,7 +598,7 @@ Menu* makeGameMenu(SDL_Surface *screen) Menu* makeLevelMenu(vector levels, SDL_Surface *screen) { - string bfile = "data/images/bg_stars.bmp"; + string bfile = get_data_path() + "images/bg_stars.bmp"; SDL_Surface *bg = loadBMP(bfile); vector ts; vector ti; @@ -619,7 +626,7 @@ GameHandler::GameHandler() isGood = false; //reading available levels ifstream ins; - string path = "data/levels/"; + string path = get_data_path() + "levels/"; ins.open((path+"levels.txt").c_str()); char workaround; ins >> workaround; @@ -638,7 +645,7 @@ GameHandler::GameHandler() menus.push_back(makeLevelMenu(levelpaths,screen)); menus.push_back(new Shop(&user, MENU | 1)); menus.push_back(makeLoadGameMenu(screen)); - SDL_Surface* bg = loadBMP("data/images/bg_stars.bmp"); + SDL_Surface* bg = loadBMP(get_data_path() + "images/bg_stars.bmp"); GetStringMenu* mt = new GetStringMenu("Enter your Nickname:", MENU | 0, LEVEL | 0, bg, screen); acname = &mt->s; menus.push_back(mt); @@ -691,7 +698,7 @@ int GameHandler::game() if(*acname != "") { delete user; - user = new Account("data/default/account.txt"); + user = new Account(get_data_path() + "default/account.txt"); user->name = *acname; menus[5]->refresh(); menus[3]->refresh(); @@ -710,7 +717,7 @@ int GameHandler::game() if(state & LOAD) { ifstream ins; - ins.open("save/saves.txt"); + ins.open((SAVE_PATH + "saves.txt").c_str()); char workaround; ins >> workaround; int counter = 0; @@ -722,7 +729,7 @@ int GameHandler::game() { account = workaround + account; delete user; - user = new Account("save/" + account + ".txt"); + user = new Account(SAVE_PATH + account + ".txt"); menus[3]->refresh(); menus[6]->refresh(); user->resetShips(); @@ -802,6 +809,11 @@ int GameHandler::game() int main(int argc, char* args[]) { + if(getenv("RCADE_DATA") != NULL) + DATA_PATH = getenv("RCADE_DATA"); + + if(getenv("RCADE_SAVE") != NULL) + SAVE_PATH = getenv("RCADE_DATA"); GameHandler* GH = new GameHandler(); // Account a = Account(); -- cgit v1.2.3