Merge pull request #195 from devZoGok/ft-142-music

Ft 142 music
This commit is contained in:
devZoGok
2025-06-23 05:21:50 +00:00
committed by GitHub
25 changed files with 138 additions and 36 deletions
+4
View File
@@ -65,3 +65,7 @@ mappings = {
graphics = {
resolution = {x = 1920, y = 1080}
}
audio = {
sfxVolume = 100,
musicVolume = 100,
}
+23
View File
@@ -3,6 +3,29 @@ 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 = true,
delay = 2000,
tracks = factionTracks
}
end
eyeIcon = 'eye.png'
refIcon = 'refineds.png'
minimapSize = {x = 200, y = 200}
+7 -1
View File
@@ -1,5 +1,11 @@
Size = {x = 150, y = 40}
music = {
loop = true,
shuffle = false,
delay = 2000,
tracks = {'defeat.ogg'}
}
gui = {
{
guiType = GuiType.TEXT,
@@ -25,6 +31,6 @@ gui = {
name = 'Leave',
buttonType = ButtonType.STATISTICS,
trigger = -1,
imagePath = ''
--imagePath = ''
}
}
+6
View File
@@ -1,6 +1,12 @@
Size = {x = 150, y = 40}
numGui = 4
music = {
loop = true,
shuffle = false,
delay = 2000,
tracks = {'intro.ogg'}
}
gui = {
{
pos = {x = 110, y = 40, z = 0},
+1
View File
@@ -1,3 +1,4 @@
music = {tracks = {}}
numGui = 6
Size = {x = 140, y = 20}
+6
View File
@@ -1,4 +1,10 @@
Size = {x = 100, y = 20}
music = {
loop = true,
shuffle = false,
delay = 2000,
tracks = {'intro.ogg'}
}
gui = {
{
-7
View File
@@ -95,13 +95,6 @@ gui = {
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
},
{
guiType = GuiType.GUI_RECTANGLE,
pos = {x = 100, y = 200, z = 0},
zIndex = 1,
size = {x = 600, y = 600},
color = {x = 0, y = 0, z = 1, w = 1}
},
{
pos = {x = 1700, y = 1000, z = 0},
size = Size,
+11 -5
View File
@@ -1,11 +1,17 @@
Size = {x = 150, y = 40}
music = {
loop = true,
shuffle = false,
delay = 2000,
tracks = {'victory.ogg'}
}
gui = {
{
guiType = GuiType.TEXT,
text = 'VICTORY!!!',
name = 'V',
pos = {x = 100, y = 100},
pos = {x = 100, y = 100, z = 0},
zIndex = 0,
scale = 1,
font = 'batang.ttf',
@@ -15,25 +21,25 @@ gui = {
},
{
guiType = GuiType.GUI_RECTANGLE,
pos = {x = 100, y = 200},
pos = {x = 100, y = 200, z = 0},
zIndex = 1,
size = {x = 600, y = 600},
color = {x = 0, y = 0, z = 0, w = 0.1}
},
{
pos = {x = 100, y = 350},
pos = {x = 100, y = 350, z = 0},
size = Size,
guiType = GuiType.BUTTON,
name = 'Resume',
buttonType = ButtonType.RESUME
},
{
pos = {x = 110, y = 400},
pos = {x = 110, y = 400, z = 0},
size = Size,
guiType = GuiType.BUTTON,
name = 'Leave',
buttonType = ButtonType.STATISTICS,
trigger = -1,
imagePath = ''
--imagePath = ''
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4 -8
View File
@@ -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)
+11 -1
View File
@@ -120,7 +120,17 @@ namespace battleship{
void ActiveGameState::onAttached() {
AbstractAppState::onAttached();
ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua");
ConcreteGuiManager::getSingleton()->readLuaScreenScript(
"activeGameState.lua",
vector<Button*>{},
vector<Listbox*>{},
vector<Checkbox*>{},
vector<Slider*>{},
vector<Textbox*>{},
vector<Node*>{},
vector<Text*>{},
"music = generateFactionMusic(" + to_string(mainPlayer->getFaction()) + ")"
);
if(!cursorNode) initCursor();
}
+52 -5
View File
@@ -1,4 +1,5 @@
#include <solUtil.h>
#include <soundManager.h>
#include <quad.h>
@@ -497,7 +498,6 @@ namespace battleship{
sol::state_view SOL_LUA_STATE = generateView();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
sol::table posTable = guiTable["pos"];
sol::table scaleTable = guiTable["scale"];
Root *root = Root::getSingleton();
@@ -512,7 +512,20 @@ namespace battleship{
text->setMaterial(mat);
Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]);
Vector3 scale = Vector3(scaleTable["x"], scaleTable["y"], 1);
SOL_LUA_STATE.script("tp = type(gui[" + to_string(guiId + 1) + "].scale)");
string st = SOL_LUA_STATE["tp"];
Vector3 scale;
if(st == "table"){
sol::table scaleTable = guiTable["scale"];
scale = Vector3(scaleTable["x"], scaleTable["y"], 1);
}
else if(st == "number"){
float sc = guiTable["scale"];
scale = Vector3(sc, sc, 1);
}
Node *node = new Node(pos, Quaternion::QUAT_W, scale, guiTable["name"]);
node->addText(text);
root->getGuiNode()->attachChild(node);
@@ -523,6 +536,34 @@ namespace battleship{
return text;
}
void ConcreteGuiManager::parseMusic(){
sol::state_view SOL_STATE_VIEW = generateView();
sol::optional<sol::table> musicTblOpt = SOL_STATE_VIEW["music"];
if(musicTblOpt == sol::nullopt) return;
sol::table musicTbl = SOL_STATE_VIEW["music"], tracksTbl = musicTbl["tracks"];
SoundManager *sm = SoundManager::getSingleton();
if(tracksTbl.size() == 0){
sm->clearPlaylist();
return;
}
bool loop = musicTbl["loop"], shuffle = musicTbl["shuffle"];
int delay = musicTbl["delay"].get_or(0);
int numTracks = tracksTbl.size();
vector<string> trackPaths;
for(int i = 0; i < numTracks; i++){
string track = tracksTbl[i + 1];
trackPaths.push_back(GameManager::getSingleton()->getPath() + "Sounds/Music/" + track);
}
sm->play(trackPaths, 100, delay, loop, shuffle);
}
void ConcreteGuiManager::readLuaScreenScript(
string script,
vector<Button*> buttonExceptions,
@@ -531,10 +572,11 @@ namespace battleship{
vector<Slider*> sliderExceptions,
vector<Textbox*> textboxExceptions,
vector<Node*> guiRectboxExceptions,
vector<Text*> textExceptions
vector<Text*> textExceptions,
string luaCode
){
removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions, guiRectboxExceptions, textExceptions);
parseLuaScript(script);
parseLuaScript(script, luaCode);
}
void ConcreteGuiManager::readLuaScreenScriptDel(
@@ -558,13 +600,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 +640,7 @@ namespace battleship{
break;
}
}
parseMusic();
}
}
+5 -3
View File
@@ -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<vb01Gui::Slider*> = std::vector<vb01Gui::Slider*>{},
std::vector<vb01Gui::Textbox*> = std::vector<vb01Gui::Textbox*>{},
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
std::vector<vb01::Text*> = std::vector<vb01::Text*>{},
std::string = ""
);
void readLuaScreenScriptDel(
std::string,
@@ -94,7 +95,7 @@ namespace battleship{
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
);
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<std::pair<int*, void*>> guiElements;
std::string texBasePath, fontBasePath;
+1 -1
View File
@@ -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;
+2
View File
@@ -2,6 +2,7 @@
#include <stateManager.h>
#include <inputManager.h>
#include <soundManager.h>
#include <assetManager.h>
#include <root.h>
@@ -170,6 +171,7 @@ namespace battleship{
void GameManager::update() {
Root::getSingleton()->update();
SoundManager::getSingleton()->update();
inputManager->update();
stateManager->update();
}
+4 -4
View File
@@ -624,13 +624,13 @@ namespace battleship{
void Map::unload(){
Minimap::getSingleton()->unload();
unloadSkybox();
unloadLights();
unloadPlayerObjects();
unloadCells();
unloadTerrainObjects();
unloadPlayerObjects();
spawnPoints.clear();
destroyScene();
unloadLights();
unloadSkybox();
spawnPoints.clear();
}
vector<RayCaster::CollisionResult> Map::raycastTerrain(Vector3 rayPos, Vector3 rayDir, bool bothTerrTypes){