diff --git a/Assets/Scripts/Core/options.lua b/Assets/Scripts/Core/options.lua index 8c95ea4..5c0be6d 100644 --- a/Assets/Scripts/Core/options.lua +++ b/Assets/Scripts/Core/options.lua @@ -65,3 +65,7 @@ mappings = { graphics = { resolution = {x = 1920, y = 1080} } +audio = { + sfxVolume = 100, + musicVolume = 100, +} diff --git a/Assets/Scripts/Gui/activeGameState.lua b/Assets/Scripts/Gui/activeGameState.lua index 83a4dcc..db9ad36 100644 --- a/Assets/Scripts/Gui/activeGameState.lua +++ b/Assets/Scripts/Gui/activeGameState.lua @@ -3,6 +3,28 @@ Size = {x = 70, y = 70} sz = 210 s = 40 +function generateFactionMusic(factionId) + asianTracks = {'ACS/asian_theme_1.ogg', 'ACS/asian_theme_2.ogg'} + americanTracks = {'AInc/american_theme_1.ogg', 'AInc/american_theme_2.ogg'} + europeanTracks = {'ER/european_theme_1.ogg', 'ER/european_theme_2.ogg'} + + factionTracks = {} + + if factionId == 0 then + factionTracks = americanTracks + elseif factionId == 1 then + factionTracks = europeanTracks + elseif factionId == 2 then + factionTracks = asianTracks + end + + return { + loop = true, + shuffle = false, + tracks = factionTracks + } +end + eyeIcon = 'eye.png' refIcon = 'refineds.png' minimapSize = {x = 200, y = 200} diff --git a/Assets/Scripts/Gui/mainMenu.lua b/Assets/Scripts/Gui/mainMenu.lua index 85edd47..5ea8728 100644 --- a/Assets/Scripts/Gui/mainMenu.lua +++ b/Assets/Scripts/Gui/mainMenu.lua @@ -1,6 +1,11 @@ Size = {x = 150, y = 40} numGui = 4 +music = { + loop = true, + shuffle = false, + tracks = {'intro.ogg'} +} gui = { { pos = {x = 110, y = 40, z = 0}, diff --git a/Assets/Sounds/Music/ACS/asian_theme_1.ogg b/Assets/Sounds/Music/ACS/asian_theme_1.ogg new file mode 100644 index 0000000..f7c39db Binary files /dev/null and b/Assets/Sounds/Music/ACS/asian_theme_1.ogg differ diff --git a/Assets/Sounds/Music/ACS/asian_theme_2.ogg b/Assets/Sounds/Music/ACS/asian_theme_2.ogg new file mode 100644 index 0000000..96d83ca Binary files /dev/null and b/Assets/Sounds/Music/ACS/asian_theme_2.ogg differ diff --git a/Assets/Sounds/Music/AInc/american_theme_1.ogg b/Assets/Sounds/Music/AInc/american_theme_1.ogg new file mode 100644 index 0000000..c21a768 Binary files /dev/null and b/Assets/Sounds/Music/AInc/american_theme_1.ogg differ diff --git a/Assets/Sounds/Music/AInc/american_theme_2.ogg b/Assets/Sounds/Music/AInc/american_theme_2.ogg new file mode 100644 index 0000000..059f287 Binary files /dev/null and b/Assets/Sounds/Music/AInc/american_theme_2.ogg differ diff --git a/Assets/Sounds/Music/ER/european_theme_1.ogg b/Assets/Sounds/Music/ER/european_theme_1.ogg new file mode 100644 index 0000000..5e00f7a Binary files /dev/null and b/Assets/Sounds/Music/ER/european_theme_1.ogg differ diff --git a/Assets/Sounds/Music/ER/european_theme_2.ogg b/Assets/Sounds/Music/ER/european_theme_2.ogg new file mode 100644 index 0000000..87d09af Binary files /dev/null and b/Assets/Sounds/Music/ER/european_theme_2.ogg differ diff --git a/Assets/Sounds/Music/defeat.ogg b/Assets/Sounds/Music/defeat.ogg new file mode 100644 index 0000000..f9490b6 Binary files /dev/null and b/Assets/Sounds/Music/defeat.ogg differ diff --git a/Assets/Sounds/Music/intro.ogg b/Assets/Sounds/Music/intro.ogg new file mode 100644 index 0000000..1fdded6 Binary files /dev/null and b/Assets/Sounds/Music/intro.ogg differ diff --git a/Assets/Sounds/Music/victory.ogg b/Assets/Sounds/Music/victory.ogg new file mode 100644 index 0000000..63b6634 Binary files /dev/null and b/Assets/Sounds/Music/victory.ogg differ diff --git a/CMakeLists.txt b/CMakeLists.txt index 49156cb..c89e3e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ endif() set(CMAKE_CXX_STANDART 17) set(CMAKE_POLICY_VERSION_MINIMUM 3.5) set(CMAKE_BUILD_TYPE Debug) -set(BUILD_TESTS ON) +set(BUILD_TESTS OFF) set(BUILD_SHARED_LIBS OFF CACHE BOOL FORCED) cmake_policy(SET CMP0015 NEW) @@ -41,7 +41,7 @@ set(UTIL util.cpp binds.h) set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL}) -set(SFML_DIR external/SFML) +set(SFML_DIR external/gameBase/external/SFML) set(VB01_DIR external/vb01) set(VB01_GUI_DIR external/vb01Gui) set(GAME_BASE_DIR external/gameBase) @@ -51,6 +51,7 @@ add_executable(${GAME_NAME} main.cpp ${GAME_SRC}) include_directories(external/tinydir) include_directories(external/vb01/external/glm) include_directories(external/vb01/external/glm/glm) +include_directories(external/gameBase/external/SFML/include) add_subdirectory(${VB01_DIR}) set(VB01_LIB_DIR ${VB01_DIR}/build) @@ -62,12 +63,7 @@ set(GAME_BASE_LIB_DIR build/${GAME_BASE_DIR}/src) target_include_directories(${GAME_NAME} PUBLIC ${GAME_BASE_DIR}) target_link_directories(${GAME_NAME} PUBLIC ${GAME_BASE_LIB_DIR}) -add_subdirectory(${SFML_DIR}) -set(SFML_LIB_DIR build/${SFML_DIR}/src) -target_include_directories(${GAME_NAME} PUBLIC ${SFML_DIR}/include) -target_link_directories(${GAME_NAME} PUBLIC ${SFML_LIB_DIR}) - -set(DEPS vb01 gameBase sfml-system sfml-audio) +set(DEPS vb01 gameBase) target_link_libraries(${GAME_NAME} ${DEPS}) if(BUILD_TESTS) diff --git a/activeGameState.cpp b/activeGameState.cpp index a0d3d81..536e188 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -120,7 +120,17 @@ namespace battleship{ void ActiveGameState::onAttached() { AbstractAppState::onAttached(); - ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua"); + ConcreteGuiManager::getSingleton()->readLuaScreenScript( + "activeGameState.lua", + vector{}, + vector{}, + vector{}, + vector{}, + vector{}, + vector{}, + vector{}, + "music = generateFactionMusic(" + to_string(mainPlayer->getFaction()) + ")" + ); if(!cursorNode) initCursor(); } diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index a5a05bb..4536c68 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -523,6 +524,26 @@ namespace battleship{ return text; } + void ConcreteGuiManager::parseMusic(){ + sol::state_view SOL_STATE_VIEW = generateView(); + sol::optional musicTblOpt = SOL_STATE_VIEW["music"]; + + if(musicTblOpt == sol::nullopt) return; + + sol::table musicTbl = SOL_STATE_VIEW["music"], tracksTbl = musicTbl["tracks"]; + bool loop = musicTbl["loop"], shuffle = musicTbl["shuffle"]; + int numTracks = tracksTbl.size(); + + vector trackPaths; + + for(int i = 0; i < numTracks; i++){ + string track = tracksTbl[i + 1]; + trackPaths.push_back(GameManager::getSingleton()->getPath() + "Sounds/Music/" + track); + } + + SoundManager::getSingleton()->play(trackPaths, 100, loop, shuffle); + } + void ConcreteGuiManager::readLuaScreenScript( string script, vector buttonExceptions, @@ -531,10 +552,11 @@ namespace battleship{ vector sliderExceptions, vector textboxExceptions, vector guiRectboxExceptions, - vector textExceptions + vector textExceptions, + string luaCode ){ removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions, guiRectboxExceptions, textExceptions); - parseLuaScript(script); + parseLuaScript(script, luaCode); } void ConcreteGuiManager::readLuaScreenScriptDel( @@ -558,13 +580,16 @@ namespace battleship{ parseLuaScript(script); } - void ConcreteGuiManager::parseLuaScript(string script){ + void ConcreteGuiManager::parseLuaScript(string script, string luaCode){ guiElements.clear(); string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/"; sol::state_view SOL_LUA_VIEW = generateView(); + SOL_LUA_VIEW.script("music = nil"); SOL_LUA_VIEW.script_file(basePath + script); + if(luaCode != "") SOL_LUA_VIEW.script(luaCode); + SOL_LUA_VIEW.script("numGui = #gui"); int numGuiElements = SOL_LUA_VIEW["numGui"]; @@ -595,5 +620,7 @@ namespace battleship{ break; } } + + parseMusic(); } } diff --git a/concreteGuiManager.h b/concreteGuiManager.h index 326e1d3..47035fb 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -13,7 +13,7 @@ namespace vb01{ } namespace battleship{ - enum GuiElementType {BUTTON, LISTBOX, CHECKBOX, SLIDER, TEXTBOX, GUI_RECTANGLE, TEXT}; + enum GuiElementType {BUTTON, LISTBOX, CHECKBOX, SLIDER, TEXTBOX, GUI_RECTANGLE, TEXT, MUSIC}; enum ButtonType { SINGLE_PLAYER, EDITOR, @@ -82,7 +82,8 @@ namespace battleship{ std::vector = std::vector{}, std::vector = std::vector{}, std::vector = std::vector{}, - std::vector = std::vector{} + std::vector = std::vector{}, + std::string = "" ); void readLuaScreenScriptDel( std::string, @@ -94,7 +95,7 @@ namespace battleship{ std::vector = std::vector{}, std::vector = std::vector{} ); - void parseLuaScript(std::string); + void parseLuaScript(std::string, std::string = ""); private: ConcreteGuiManager(); vb01Gui::Button* parseButton(int); @@ -105,6 +106,7 @@ namespace battleship{ vb01Gui::Textbox* parseTextbox(int); vb01::Node* parseGuiRectangle(int); vb01::Text* parseText(int); + void parseMusic(); std::vector> guiElements; std::string texBasePath, fontBasePath; diff --git a/fxManager.cpp b/fxManager.cpp index 3273cab..859d297 100644 --- a/fxManager.cpp +++ b/fxManager.cpp @@ -204,7 +204,7 @@ namespace battleship{ } else{ sf::Sound *sfx = (sf::Sound*)fx->components[cid].comp; - const sf::SoundBuffer *buffer = sfx->getBuffer(); + const sf::SoundBuffer *buffer = &sfx->getBuffer(); sfx->stop(); delete sfx; diff --git a/gameManager.cpp b/gameManager.cpp index 1a01d32..5d9cc8b 100755 --- a/gameManager.cpp +++ b/gameManager.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -170,6 +171,7 @@ namespace battleship{ void GameManager::update() { Root::getSingleton()->update(); + SoundManager::getSingleton()->update(); inputManager->update(); stateManager->update(); }