From 41aa789b1ef3de660d38c0815dea1e863be6d139 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Mon, 25 Jul 2022 11:44:19 +0300 Subject: [PATCH] using base path value from Lua script --- activeGameState.cpp | 2 +- build.sh | 5 +++++ defConfigs.h | 4 ++-- exitButton.cpp | 2 +- explosion.cpp | 6 +++--- gameManager.cpp | 8 ++++++-- gameManager.h | 2 ++ guiAppState.cpp | 2 +- inGameAppState.cpp | 18 +++++++++--------- map.cpp | 8 ++++---- optionsButton.cpp | 24 +++++++++++++----------- projectile.cpp | 4 ++-- projectileData.h | 16 ++++++++-------- unit.cpp | 2 +- unitData.h | 12 ++++++------ unitDataManager.cpp | 3 ++- util.cpp | 17 ++++++++--------- vessel.h | 2 +- 18 files changed, 75 insertions(+), 62 deletions(-) diff --git a/activeGameState.cpp b/activeGameState.cpp index efb3613..9d9e9d4 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -37,7 +37,7 @@ namespace battleship{ AppStateType::ACTIVE_STATE, configData::calcSumBinds(AppStateType::ACTIVE_STATE, true), configData::calcSumBinds(AppStateType::ACTIVE_STATE, false), - PATH + "Scripts/options.lua"){ + GameManager::getSingleton()->getPath() + "Scripts/options.lua"){ this->guiState = guiState; this->map = map; this->players = players; diff --git a/build.sh b/build.sh index 6f33384..9dd19af 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,8 @@ +basePath=$(pwd) +file="Assets/Scripts/defPaths.lua" +touch $file +echo "PATH = \"$basePath/Assets/\"" > $file + cd external git submodule update --init --recursive diff --git a/defConfigs.h b/defConfigs.h index d2a19ca..3297afb 100755 --- a/defConfigs.h +++ b/defConfigs.h @@ -7,13 +7,13 @@ #include #include "binds.h" +#include "gameManager.h" namespace battleship{ namespace configData{ using namespace gameBase; - const std::string PATH = "/home/dominykas/c++/Battleship/Assets/"; - const std::string DEFAULT_TEXTURE = PATH + "Textures/defaultTexture.jpg"; + const std::string DEFAULT_TEXTURE = GameManager::getSingleton()->getPath() + "Textures/defaultTexture.jpg"; const double camPanSpeed = .1; const static int numAppStates = 3; diff --git a/exitButton.cpp b/exitButton.cpp index a9db5e7..729b106 100755 --- a/exitButton.cpp +++ b/exitButton.cpp @@ -7,7 +7,7 @@ using namespace std; using namespace vb01; namespace battleship{ - ExitButton::ExitButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, configData::PATH + "Fonts/batang.ttf", -1, separate) { + ExitButton::ExitButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) { } void ExitButton::onClick() { diff --git a/explosion.cpp b/explosion.cpp index 7f159f8..5f4fa31 100644 --- a/explosion.cpp +++ b/explosion.cpp @@ -13,7 +13,7 @@ namespace battleship{ void detonate(InGameAppState *inGameState, Vector3 pos, Vector3 dir){ sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer(); sf::Sound *sfx = nullptr; - string p = PATH + "Sounds/Explosions/explosion0" + to_string(rand() % 4) + ".ogg"; + string p = GameManager::getSingleton()->getPath() + "Sounds/Explosions/explosion0" + to_string(rand() % 4) + ".ogg"; if(sfxBuffer->loadFromFile(p.c_str())){ sfx = new sf::Sound(*sfxBuffer); @@ -30,7 +30,7 @@ namespace battleship{ void detonateDepthCharge(InGameAppState *inGameState, Vector3){ sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer(); sf::Sound *sfx = nullptr; - string p = PATH + "Sounds/Destroyers/depthCharge.ogg"; + string p = GameManager::getSingleton()->getPath() + "Sounds/Destroyers/depthCharge.ogg"; if(sfxBuffer->loadFromFile(p.c_str())){ sfx = new sf::Sound(*sfxBuffer); @@ -47,7 +47,7 @@ namespace battleship{ void detonateTorpedo(InGameAppState *inGameState, Vector3){ sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer(); sf::Sound *sfx = nullptr; - string p = PATH + "Sounds/Submarines/torpedo.ogg"; + string p = GameManager::getSingleton()->getPath() + "Sounds/Submarines/torpedo.ogg"; if(sfxBuffer->loadFromFile(p.c_str())){ sfx = new sf::Sound(*sfxBuffer); diff --git a/gameManager.cpp b/gameManager.cpp index ee274c8..35c1faa 100755 --- a/gameManager.cpp +++ b/gameManager.cpp @@ -1,11 +1,12 @@ #include -#include - #include #include #include +#include + +#include #include "gameManager.h" #include "guiAppState.h" @@ -25,6 +26,9 @@ namespace battleship{ } GameManager::GameManager() { + LuaManager *luaManager = LuaManager::getSingleton(); + luaManager->buildScript(vector{"../Assets/Scripts/defPaths.lua"}); + path = luaManager->getString("PATH"); } GameManager::~GameManager() {} diff --git a/gameManager.h b/gameManager.h index bada3dc..6241564 100755 --- a/gameManager.h +++ b/gameManager.h @@ -23,6 +23,7 @@ namespace battleship{ void update(); inline int getWidth(){return width;} inline int getHeight(){return height;} + inline std::string getPath(){return path;} inline gameBase::InputManager* getInputManager(){return inputManager;} inline bool isServerSide(){return serverSide;} inline gameBase::StateManager* getStateManager(){return stateManager;} @@ -33,6 +34,7 @@ namespace battleship{ gameBase::StateManager *stateManager = nullptr; gameBase::InputManager *inputManager = nullptr; int width, height; + std::string path = ""; bool serverSide; }; diff --git a/guiAppState.cpp b/guiAppState.cpp index fd8266e..5799a07 100755 --- a/guiAppState.cpp +++ b/guiAppState.cpp @@ -19,7 +19,7 @@ namespace battleship{ AppStateType::GUI_STATE, configData::calcSumBinds(AppStateType::GUI_STATE, true), configData::calcSumBinds(AppStateType::GUI_STATE, false), - PATH + "Scripts/options.lua"){ + GameManager::getSingleton()->getPath() + "Scripts/options.lua"){ } GuiAppState::~GuiAppState() {} diff --git a/inGameAppState.cpp b/inGameAppState.cpp index e24e32f..6e698ad 100755 --- a/inGameAppState.cpp +++ b/inGameAppState.cpp @@ -19,7 +19,7 @@ using namespace std; namespace battleship{ using namespace configData; - InGameAppState::ResumeButton::ResumeButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) { + InGameAppState::ResumeButton::ResumeButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) { this->guiState = guiState; this->inGameState = inGameState; } @@ -32,7 +32,7 @@ namespace battleship{ return guiState; } - InGameAppState::ConsoleButton::ConsoleButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) { + InGameAppState::ConsoleButton::ConsoleButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) { this->guiState = guiState; this->inGameState = inGameState; } @@ -42,7 +42,7 @@ namespace battleship{ class ConsoleCommandEntryButton : public Button { public: - ConsoleCommandEntryButton(InGameAppState *inGameState, Textbox *t, Listbox *l, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) { + ConsoleCommandEntryButton(InGameAppState *inGameState, Textbox *t, Listbox *l, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) { this->inGameState = inGameState; textbox = t; listbox = l; @@ -64,16 +64,16 @@ namespace battleship{ list.push_back(""); Vector2 pos = Vector2(300, 100); - Listbox *consoleListbox = new Listbox(Vector2(pos.x, pos.y), Vector2(420, 20), list, 20, PATH + "Fonts/batang.ttf"); + Listbox *consoleListbox = new Listbox(Vector2(pos.x, pos.y), Vector2(420, 20), list, 20, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"); consoleListbox->openUp(); guiState->addListbox(consoleListbox); - Textbox *consoleTextbox = new Textbox(Vector2(pos.x, pos.y + 20 * (emptyEntries + 1)), Vector2(300, 20), PATH + "Fonts/batang.ttf"); + Textbox *consoleTextbox = new Textbox(Vector2(pos.x, pos.y + 20 * (emptyEntries + 1)), Vector2(300, 20), GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"); guiState->addTextbox(consoleTextbox); ConsoleCommandEntryButton *entryButton = new ConsoleCommandEntryButton(inGameState, consoleTextbox, consoleListbox, Vector2(pos.x + 320, pos.y + 20 * (emptyEntries + 1)), Vector2(100, 20), "Enter", true); guiState->addButton(entryButton); } - InGameAppState::InGameOptionsButton::ReturnButton::ReturnButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) { + InGameAppState::InGameOptionsButton::ReturnButton::ReturnButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) { this->guiState = guiState; this->inGameState = inGameState; } @@ -122,7 +122,7 @@ namespace battleship{ OptionsButton::onClick(); } - InGameAppState::MainMenuButton::MainMenuButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) { + InGameAppState::MainMenuButton::MainMenuButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) { this->guiState = guiState; this->inGameState = inGameState; } @@ -131,7 +131,7 @@ namespace battleship{ } - InGameAppState::UnitCreationButton::UnitCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) {} + InGameAppState::UnitCreationButton::UnitCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {} void InGameAppState::UnitCreationButton::onClick() { } @@ -179,7 +179,7 @@ namespace battleship{ AppStateType::IN_GAME_STATE, configData::calcSumBinds(AppStateType::IN_GAME_STATE, true), configData::calcSumBinds(AppStateType::IN_GAME_STATE, false), - PATH + "Scripts/options.lua"){ + GameManager::getSingleton()->getPath() + "Scripts/options.lua"){ this->playerId = 0; this->difficultyLevels = difficultyLevels; this->factions = factions; diff --git a/map.cpp b/map.cpp index af6dbcc..d8c9b4c 100755 --- a/map.cpp +++ b/map.cpp @@ -29,7 +29,7 @@ namespace battleship{ void Map::loadSkybox(LuaManager *luaManager){ int numPaths = 6; - string table = "skybox", basePath = configData::PATH + "Models/Maps/" + mapName + "/"; + string table = "skybox", basePath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/"; string path[] = { basePath + luaManager->getStringFromTable(table, vector{Index("left", true)}), basePath + luaManager->getStringFromTable(table, vector{Index("right", true)}), @@ -50,7 +50,7 @@ namespace battleship{ string albedoFile = luaManager->getString("albedoMap"); AssetManager *assetManager = AssetManager::getSingleton(); - string basePath = configData::PATH + "Models/Maps/" + mapName + "/"; + string basePath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/"; assetManager->load(basePath + terrainFile); assetManager->load(basePath + albedoFile); @@ -82,7 +82,7 @@ namespace battleship{ mat->addBoolUniform("texturingEnabled", true); mat->addBoolUniform("lightingEnabled", false); - string fr[]{PATH + "Models/Maps/" + mapName + "/" + luaManager->getStringFromTable(table, vector{Index("albedoMap", true)})}; + string fr[]{GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + luaManager->getStringFromTable(table, vector{Index("albedoMap", true)})}; AssetManager::getSingleton()->load(fr[0]); Texture *t = new Texture(fr, 1, false); @@ -102,7 +102,7 @@ namespace battleship{ void Map::load() { LuaManager *luaManager = LuaManager::getSingleton(); - luaManager->buildScript(vector{configData::PATH + "Models/Maps/" + mapName + "/" + mapName + ".lua"}); + luaManager->buildScript(vector{GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + mapName + ".lua"}); loadSkybox(luaManager); loadTerrain(luaManager); diff --git a/optionsButton.cpp b/optionsButton.cpp index 7a8dc65..1243c5e 100755 --- a/optionsButton.cpp +++ b/optionsButton.cpp @@ -1,6 +1,7 @@ #include "optionsButton.h" #include "util.h" #include "defConfigs.h" +#include "gameManager.h" #include @@ -11,21 +12,21 @@ using namespace std; namespace battleship{ using namespace configData; - OptionsButton::OkButton::OkButton() : Button(Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Ok", PATH + "Fonts/batang.ttf", -1, true) { + OptionsButton::OkButton::OkButton() : Button(Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::GUI_STATE)); } void OptionsButton::OkButton::onClick() { } - OptionsButton::DefaultsButton::DefaultsButton() : Button(Vector2(200, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Restore defaults", PATH + "Fonts/batang.ttf", -1, true) { + OptionsButton::DefaultsButton::DefaultsButton() : Button(Vector2(200, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Restore defaults", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::GUI_STATE)); } void OptionsButton::DefaultsButton::onClick() { } - OptionsButton::BackButton::BackButton() : Button(Vector2(350, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Back", PATH + "Fonts/batang.ttf", -1, true) { + OptionsButton::BackButton::BackButton() : Button(Vector2(350, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Back", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::GUI_STATE)); } void OptionsButton::BackButton::onClick() { @@ -41,7 +42,7 @@ namespace battleship{ state->removeButton("Back"); } - OptionsButton::TabButton::TabButton(Vector2 pos, Vector2 size, string name) :Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, true) { + OptionsButton::TabButton::TabButton(Vector2 pos, Vector2 size, string name) :Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::GUI_STATE)); } void OptionsButton::TabButton::onClick() { @@ -63,10 +64,11 @@ namespace battleship{ void OptionsButton::ControlsTab::onClick() { TabButton::onClick(); std::vector lines; - readFile(PATH + "../options.cfg", lines); + string path = GameManager::getSingleton()->getPath(); + readFile(path + "../options.cfg", lines); GameManager *gm = GameManager::getSingleton(); - Listbox *listbox = new Listbox(Vector2(gm->getWidth() / 4, gm->getHeight() / 10), Vector2(360, 20), lines, lines.size() < 5 ? lines.size() : 5, PATH + "Fonts/batang.ttf"); + Listbox *listbox = new Listbox(Vector2(gm->getWidth() / 4, gm->getHeight() / 10), Vector2(360, 20), lines, lines.size() < 5 ? lines.size() : 5, path + "Fonts/batang.ttf"); state->addListbox(listbox); state->removeButton("Mouse"); @@ -88,7 +90,7 @@ namespace battleship{ GameManager *gm = GameManager::getSingleton(); Vector2 pos = Vector2(gm->getWidth() / 3, gm->getHeight() / 4); - string font = PATH + "Fonts/batang.ttf"; + string font = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"; Slider *mouseSensitivitySlider = new Slider(Vector2(pos.x, pos.y), Vector2(300, 10), .1, 3.); Textbox *mouseSensitivityTextbox = new Textbox(Vector2(pos.x + 320, pos.y - 10), Vector2(100, 20), font); Checkbox *reverseMouseCheckbox = new Checkbox(Vector2(pos.x, pos.y + 50), font); @@ -115,7 +117,7 @@ namespace battleship{ } GameManager *gm = GameManager::getSingleton(); - string font = PATH + "Fonts/batang.ttf"; + string font = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"; Vector2 pos = Vector2(gm->getWidth() / 3, gm->getHeight() / 8); Listbox *resolutionsListbox = new Listbox(Vector2(pos.x, pos.y), Vector2(100, 20), lines, 5, font); @@ -145,7 +147,7 @@ namespace battleship{ GameManager *gm = GameManager::getSingleton(); Vector2 pos(gm->getWidth() / 3, gm->getHeight() / 8); Slider *volumeSlider = new Slider(Vector2(pos.x, pos.y), Vector2(300, 10), 0., 2.); - Textbox *volumeTextbox = new Textbox(Vector2(pos.x + 320, pos.y), Vector2(100, 20), PATH + "Fonts/batang.ttf"); + Textbox *volumeTextbox = new Textbox(Vector2(pos.x + 320, pos.y), Vector2(100, 20), GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"); volumeSlider->setTextbox(volumeTextbox); volumeTextbox->setSlider(volumeSlider); state->addTextbox(volumeTextbox); @@ -161,7 +163,7 @@ namespace battleship{ void OptionsButton::MultiplayerTab::onClick() { TabButton::onClick(); GameManager *gm = GameManager::getSingleton(); - string font = PATH + "Fonts/batang.ttf"; + string font = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"; Vector2 pos = Vector2(gm->getWidth() / 3, gm->getHeight() / 6); Textbox *tcpTextbox = new Textbox(Vector2(pos.x, pos.y), Vector2(100, 20), font); Textbox *udpTextbox = new Textbox(Vector2(pos.x, pos.y + 30), Vector2(100, 20), font); @@ -177,7 +179,7 @@ namespace battleship{ state->removeButton("Multiplayer"); } - OptionsButton::OptionsButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) { + OptionsButton::OptionsButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) { this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::GUI_STATE)); } void OptionsButton::onClick() { diff --git a/projectile.cpp b/projectile.cpp index cee5620..fc39d61 100755 --- a/projectile.cpp +++ b/projectile.cpp @@ -52,8 +52,8 @@ namespace battleship{ float angle = dirVec.getAngleBetween(Vector3(0, 0, -1)); angle = Quaternion(angle, upVec) * Vector3(0, 0, -1) == dirVec ? angle : -angle; - string p1 = PATH + "Sounds/" + unitData::name[id] + "s/" + projectileData::name[id][weaponTypeId] + ".ogg"; - string p2 = PATH + "Sounds/Explosions/explosion03" + to_string(rand() % 4) + ".ogg"; + string p1 = gm->getPath() + "Sounds/" + unitData::name[id] + "s/" + projectileData::name[id][weaponTypeId] + ".ogg"; + string p2 = gm->getPath() + "Sounds/Explosions/explosion03" + to_string(rand() % 4) + ".ogg"; this->shotSfxBuffer = new sf::SoundBuffer(); this->explosionSfxBuffer=new sf::SoundBuffer(); diff --git a/projectileData.h b/projectileData.h index 07a9a24..e8f6153 100755 --- a/projectileData.h +++ b/projectileData.h @@ -229,16 +229,16 @@ namespace battleship{ {"missile","missile"}, }; const std::string meshPath[unitData::numberOfUnits][numberOfTypesOfWeapons]{ - {PATH + "Models/Shell/shell.x"}, - {PATH + "Models/Shell/shell.x"}, - {PATH + "Models/Shell/shell.x", PATH + "Models/Depth charge/depthCharge.x"}, - {PATH + "Models/Shell/shell.x", PATH + "Models/Depth charge/depthCharge.x"}, - {PATH + "Models/Shell/shell.x", PATH + "Models/Guided missile/guidedMissile.x"}, - {PATH + "Models/Shell/shell.x", PATH + "Models/Guided missile/guidedMissile.x"}, + {GameManager::getSingleton()->getPath() + "Models/Shell/shell.x"}, + {GameManager::getSingleton()->getPath() + "Models/Shell/shell.x"}, + {GameManager::getSingleton()->getPath() + "Models/Shell/shell.x", GameManager::getSingleton()->getPath() + "Models/Depth charge/depthCharge.x"}, + {GameManager::getSingleton()->getPath() + "Models/Shell/shell.x", GameManager::getSingleton()->getPath() + "Models/Depth charge/depthCharge.x"}, + {GameManager::getSingleton()->getPath() + "Models/Shell/shell.x", GameManager::getSingleton()->getPath() + "Models/Guided missile/guidedMissile.x"}, + {GameManager::getSingleton()->getPath() + "Models/Shell/shell.x", GameManager::getSingleton()->getPath() + "Models/Guided missile/guidedMissile.x"}, {}, {}, - {PATH + "Models/Torpedo/torpedo.x"}, - {PATH + "Models/Jets/aam.x", PATH + "Models/Jets/awm.x"}, + {GameManager::getSingleton()->getPath() + "Models/Torpedo/torpedo.x"}, + {GameManager::getSingleton()->getPath() + "Models/Jets/aam.x", GameManager::getSingleton()->getPath() + "Models/Jets/awm.x"}, }; const std::string diffuseMapTextPath[unitData::numberOfUnits][numberOfTypesOfWeapons]{ {}, diff --git a/unit.cpp b/unit.cpp index 89f104c..3e7d3b5 100755 --- a/unit.cpp +++ b/unit.cpp @@ -50,7 +50,7 @@ namespace battleship{ placeUnit(pos); selectionSfxBuffer = new sf::SoundBuffer(); - string p = PATH + "Sounds/" + unitData::name[id] + "s/selection.ogg"; + string p = GameManager::getSingleton()->getPath() + "Sounds/" + unitData::name[id] + "s/selection.ogg"; if(selectionSfxBuffer->loadFromFile(p.c_str())) selectionSfx = new sf::Sound(*selectionSfxBuffer); diff --git a/unitData.h b/unitData.h index e901bea..37e2d1d 100755 --- a/unitData.h +++ b/unitData.h @@ -280,12 +280,12 @@ namespace battleship { "jet00.x", "jet01.x" }; const std::string basePath[numberOfUnits]{ - PATH + "Models/Battleships/", PATH + "Models/Battleships/", - PATH + "Models/Destroyers/", PATH + "Models/Destroyers/", - PATH + "Models/Cruisers/", PATH + "Models/Cruisers/", - PATH + "Models/Aircraft carriers/", PATH + "Models/Aircraft carriers/", - PATH + "Models/Submarines/", - PATH + "Models/Jets/", PATH + "Models/Jets/"}; + GameManager::getSingleton()->getPath() + "Models/Battleships/", GameManager::getSingleton()->getPath() + "Models/Battleships/", + GameManager::getSingleton()->getPath() + "Models/Destroyers/", GameManager::getSingleton()->getPath() + "Models/Destroyers/", + GameManager::getSingleton()->getPath() + "Models/Cruisers/", GameManager::getSingleton()->getPath() + "Models/Cruisers/", + GameManager::getSingleton()->getPath() + "Models/Aircraft carriers/", GameManager::getSingleton()->getPath() + "Models/Aircraft carriers/", + GameManager::getSingleton()->getPath() + "Models/Submarines/", + GameManager::getSingleton()->getPath() + "Models/Jets/", GameManager::getSingleton()->getPath() + "Models/Jets/"}; } } diff --git a/unitDataManager.cpp b/unitDataManager.cpp index d0e0a00..07425e5 100644 --- a/unitDataManager.cpp +++ b/unitDataManager.cpp @@ -22,7 +22,8 @@ namespace battleship{ UnitDataManager::UnitDataManager(){ LuaManager *luaManager = LuaManager::getSingleton(); - luaManager->buildScript(vector{configData::PATH + "Scripts/defPaths.lua", configData::PATH + "Scripts/unitData.lua"}); + string path = GameManager::getSingleton()->getPath(); + luaManager->buildScript(vector{path + "Scripts/defPaths.lua", path + "Scripts/unitData.lua"}); numUnits = luaManager->getInt("numUnits"); diff --git a/util.cpp b/util.cpp index 801f2d7..702bdc8 100755 --- a/util.cpp +++ b/util.cpp @@ -30,7 +30,7 @@ namespace battleship{ class SpButton : public Button { public: - SpButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", GLFW_KEY_S, separate) { + SpButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_S, separate) { this->state = state; } @@ -47,7 +47,7 @@ namespace battleship{ class PlayButton : public Button { public: - PlayButton(Listbox **difficulties, Listbox **factions, Listbox *mapListbox, int lengths[2], Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", GLFW_KEY_P, separate) { + PlayButton(Listbox **difficulties, Listbox **factions, Listbox *mapListbox, int lengths[2], Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_P, separate) { this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::GUI_STATE)); this->lengths[0] = lengths[0]; this->lengths[1] = lengths[1]; @@ -88,7 +88,7 @@ namespace battleship{ class ReturnButton : public Button { public: - ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", GLFW_KEY_B, separate) { + ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_B, separate) { this->state = state; } @@ -114,11 +114,10 @@ namespace battleship{ factions.push_back("1"); tinydir_dir dir; - int i; - tinydir_open_sorted(&dir, (PATH + "Models/Maps").c_str()); + tinydir_open_sorted(&dir, (gm->getPath() + "Models/Maps").c_str()); vector folders; - for (i = 0; i < dir.n_files; i++) { + for (int i = 0; i < dir.n_files; i++) { tinydir_file file; tinydir_readfile_n(&dir, &file, i); @@ -128,7 +127,7 @@ namespace battleship{ tinydir_close(&dir); - string font = PATH + "Fonts/batang.ttf"; + string font = gm->getPath() + "Fonts/batang.ttf"; Listbox *cpuDifficulty = new Listbox(Vector2(pos.x, pos.y + 30), Vector2(100, 20), difficulties, 3, font); Listbox *cpuFaction = new Listbox(Vector2(pos.x + 110, pos.y + 30), Vector2(100, 20), factions, 2, font); Listbox *playerFaction = new Listbox(Vector2(pos.x + 110, pos.y), Vector2(100, 20), factions, 2, font); @@ -188,7 +187,7 @@ namespace battleship{ class ReturnButton : public Button { public: - ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) { + ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) { this->state = state; } @@ -217,7 +216,7 @@ namespace battleship{ }; GameManager *gm = GameManager::getSingleton(); - string font = PATH + "Fonts/batang.ttf"; + string font = gm->getPath() + "Fonts/batang.ttf"; AssetManager::getSingleton()->load(font); SpButton *spButton = new SpButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12), Vector2(150, 40), "Singleplayer", true); MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 2), Vector2(150, 40), "Options", true); diff --git a/vessel.h b/vessel.h index 13876a9..90a6255 100755 --- a/vessel.h +++ b/vessel.h @@ -41,7 +41,7 @@ namespace battleship { inline bool canFire(){return vb01::getTime() - lastShotTime > rateOfFire;} inline vb01::Node* getNode(){return node;} private: - inline std::string getExplosionSfxPath(){return configData::PATH + "Sounds/Explosions/explosion0" + std::to_string(rand() % 4) + ".ogg";} + inline std::string getExplosionSfxPath(){return GameManager::getSingleton()->getPath() + "Sounds/Explosions/explosion0" + std::to_string(rand() % 4) + ".ogg";} vb01::Node *fxNode; vb01::ParticleEmitter *emitter;