Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: load sounds with protobuf #1074

Merged
merged 11 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions data/sounds/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!README.md
9 changes: 9 additions & 0 deletions data/sounds/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Adding client versions

Create a version folder and drop your soundbank in it.

For the list of supported client versions see `modules/gamelib/game.lua`

# Example configuration

`data/sounds/1340/ (catalog-sound.json and all sound files)`
1 change: 1 addition & 0 deletions data/things/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*
!.gitignore
!README.md
13 changes: 13 additions & 0 deletions data/things/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Adding client versions

Create a version folder and drop your sprite files or assets in it.

For the list of supported client versions see `modules/gamelib/game.lua`

# Example configurations

spr/dat:
`data/things/860/ (spr and dat files there)`

assets:
`data/things/1340/ (catalog-content.json and all asset files)`
12 changes: 8 additions & 4 deletions meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ function g_things.loadAppearances(file) end
---@return boolean
function g_things.loadStaticData(file) end

---@param file string
---@return boolean
function g_things.loadSounds(file) end

---@param file string
---@return boolean
function g_things.loadDat(file) end
Expand Down Expand Up @@ -5835,6 +5831,14 @@ function g_sounds.createSoundEffect() end
---@return boolean
function g_sounds.isEaxEnabled() end

---@param file string
---@return boolean
function g_sounds.loadClientFiles(directory) end

---@param audioFileId string
---@return string
function g_sounds.getAudioFileNameById(audioFileId) end

--------------------------------
--------- SoundSource ----------
--------------------------------
Expand Down
24 changes: 11 additions & 13 deletions mods/game_bot/default_configs/vBot_4.8/vBot/alarms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,16 @@ addAlarm("creatureDetected", "Creature Detected", false, 1, 1)
addAlarm("playerDetected", "Player Detected", false, 1, 1)
addAlarm("creatureName", "Creature Name:", "", 3, 1, "You can add a name or part of it, that if found in any visible creature name will trigger alert.\nYou can add many, just separate them by comma.")


local lastCall = now
local function alarm(file, windowText)
if now - lastCall < 2000 then return end -- 2s delay
lastCall = now

if not g_resources.fileExists(file) then
file = "/sounds/alarm.ogg"
file = "sounds/alarm.ogg"
lastCall = now + 4000 -- alarm.ogg length is 6s
end


if modules.game_bot.g_app.getOs() == "windows" and config.flashClient.enabled then
g_window.flash()
end
Expand All @@ -137,7 +135,7 @@ end
onTextMessage(function(mode, text)
if not config.enabled then return end
if mode == 22 and config.damageTaken.enabled then
return alarm('/sounds/magnum.ogg', "Damage Received!")
return alarm('sounds/magnum.ogg', "Damage Received!")
end

if config.customMessage.enabled then
Expand All @@ -152,7 +150,7 @@ onTextMessage(function(mode, text)
part = part:lower()

if text:find(part) then
return alarm('/sounds/magnum.ogg', "Special Message!")
return alarm('sounds/magnum.ogg', "Special Message!")
end
end
end
Expand All @@ -166,11 +164,11 @@ onTalk(function(name, level, mode, text, channelId, pos)
if config.ignoreFriends.enabled and isFriend(name) then return end -- ignore friends if enabled

if mode == 1 and config.defaultMsg.enabled then
return alarm("/sounds/magnum.ogg", "Default Message!")
return alarm("sounds/magnum.ogg", "Default Message!")
end

if mode == 4 and config.privateMsg.enabled then
return alarm("/sounds/Private_Message.ogg", "Private Message!")
return alarm("sounds/Private_Message.ogg", "Private Message!")
end
end)

Expand All @@ -179,29 +177,29 @@ macro(100, function()
if not config.enabled then return end
if config.lowHealth.enabled then
if hppercent() < config.lowHealth.value then
return alarm("/sounds/Low_Health.ogg", "Low Health!")
return alarm("sounds/Low_Health.ogg", "Low Health!")
end
end

if config.lowMana.enabled then
if hppercent() < config.lowMana.value then
return alarm("/sounds/Low_Mana.ogg", "Low Mana!")
return alarm("sounds/Low_Mana.ogg", "Low Mana!")
end
end

for i, spec in ipairs(getSpectators()) do
if not spec:isLocalPlayer() and not (config.ignoreFriends.enabled and isFriend(spec)) then

if config.creatureDetected.enabled then
return alarm("/sounds/magnum.ogg", "Creature Detected!")
return alarm("sounds/magnum.ogg", "Creature Detected!")
end

if spec:isPlayer() then
if spec:isTimedSquareVisible() and config.playerAttack.enabled then
return alarm("/sounds/Player_Attack.ogg", "Player Attack!")
return alarm("sounds/Player_Attack.ogg", "Player Attack!")
end
if config.playerDetected.enabled then
return alarm("/sounds/Player_Detected.ogg", "Player Detected!")
return alarm("sounds/Player_Detected.ogg", "Player Detected!")
end
end

Expand All @@ -213,7 +211,7 @@ macro(100, function()
local frag = fragments[i]:trim():lower()

if name:lower():find(frag) then
return alarm("/sounds/alarm.ogg", "Special Creature Detected!")
return alarm("sounds/alarm.ogg", "Special Creature Detected!")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion mods/game_bot/functions/sound.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ context.stopSound = function()
end

context.playAlarm = function()
return context.playSound("/sounds/alarm.ogg")
return context.playSound("sounds/alarm.ogg")
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions modules/client/client.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local musicFilename = '/sounds/startup'
local musicFilename = 'sounds/startup'
local musicChannel = nil
if g_sounds then
musicChannel = g_sounds.getChannel(SoundChannels.Music)
Expand All @@ -14,7 +14,6 @@ function setMusic(filename)
end

function startup()
-- Play startup music (The Silver Tree, by Mattias Westlund)
if musicChannel then
musicChannel:enqueue(musicFilename, 3)
connect(g_game, {
Expand Down
File renamed without changes.
36 changes: 21 additions & 15 deletions modules/game_things/things.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,27 @@ function load(version)
end

loaded = #errorList == 0
if loaded then
-- loading client files was successful, try to load sounds now
-- sound files are optional, this means that failing to load them
-- will not block logging into game
g_sounds.loadClientFiles(resolvepath(string.format('/sounds/%d/', version)))
return
end

if not loaded then
local messageBox = displayErrorBox(tr('Error'), table.concat(errorList, "\n"))
addEvent(function()
messageBox:raise()
messageBox:focus()
end)
-- loading client files failed, show an error
local messageBox = displayErrorBox(tr('Error'), table.concat(errorList, "\n"))
addEvent(function()
messageBox:raise()
messageBox:focus()
end)

disconnect(g_game, {
onClientVersionChange = load
})
g_game.setClientVersion(0)
g_game.setProtocolVersion(0)
connect(g_game, {
onClientVersionChange = load
})
end
disconnect(g_game, {
onClientVersionChange = load
})
g_game.setClientVersion(0)
g_game.setProtocolVersion(0)
connect(g_game, {
onClientVersionChange = load
})
end
1 change: 0 additions & 1 deletion src/client/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ void Client::registerLuaFunctions()
g_lua.registerSingletonClass("g_things");
g_lua.bindSingletonFunction("g_things", "loadAppearances", &ThingTypeManager::loadAppearances, &g_things);
g_lua.bindSingletonFunction("g_things", "loadStaticData", &ThingTypeManager::loadStaticData, &g_things);
g_lua.bindSingletonFunction("g_things", "loadSounds", &ThingTypeManager::loadSounds, &g_things);
g_lua.bindSingletonFunction("g_things", "loadDat", &ThingTypeManager::loadDat, &g_things);
g_lua.bindSingletonFunction("g_things", "loadOtml", &ThingTypeManager::loadOtml, &g_things);
g_lua.bindSingletonFunction("g_things", "isDatLoaded", &ThingTypeManager::isDatLoaded, &g_things);
Expand Down
8 changes: 0 additions & 8 deletions src/client/thingtypemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#include <appearances.pb.h>
#include <staticdata.pb.h>
#include <sounds.pb.h>

#include <nlohmann/json.hpp>

Expand Down Expand Up @@ -288,13 +287,6 @@ bool ThingTypeManager::loadStaticData(const std::string& file)
return false;
}

bool ThingTypeManager::loadSounds(const std::string& /* file */)
{
// to be implemented
// to be moved to g_sounds
return false;
}

const ThingTypeList& ThingTypeManager::getThingTypes(const ThingCategory category)
{
if (category < ThingLastCategory)
Expand Down
1 change: 0 additions & 1 deletion src/client/thingtypemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class ThingTypeManager
bool loadOtml(std::string file);
bool loadAppearances(const std::string& file);
bool loadStaticData(const std::string& file);
bool loadSounds(const std::string& file);

#ifdef FRAMEWORK_EDITOR
void parseItemType(uint16_t id, pugi::xml_node node);
Expand Down
2 changes: 2 additions & 0 deletions src/framework/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,8 @@ void Application::registerLuaFunctions()
g_lua.bindSingletonFunction("g_sounds", "setPosition", &SoundManager::setPosition, &g_sounds);
g_lua.bindSingletonFunction("g_sounds", "createSoundEffect", &SoundManager::createSoundEffect, &g_sounds);
g_lua.bindSingletonFunction("g_sounds", "isEaxEnabled", &SoundManager::isEaxEnabled, &g_sounds);
g_lua.bindSingletonFunction("g_sounds", "loadClientFiles", &SoundManager::loadClientFiles, &g_sounds);
g_lua.bindSingletonFunction("g_sounds", "getAudioFileNameById", &SoundManager::getAudioFileNameById, &g_sounds);

g_lua.registerClass<SoundSource>();
g_lua.bindClassStaticFunction<SoundSource>("create", [] { return std::make_shared<SoundSource>(); });
Expand Down
Loading
Loading