Skip to content

Commit

Permalink
Moved music out of GMCP listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Volte6 committed Feb 25, 2025
1 parent 2fb8067 commit a1dbb1e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
13 changes: 0 additions & 13 deletions internal/hooks/RoomChange_LocationGMCPUpdates_Listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,5 @@ func LocationGMCPUpdates_Listener(e events.Event) bool {
})
}

// If this zone has music, play it.
// Room music takes priority.
if newRoom.MusicFile != `` {
user.PlayMusic(newRoom.MusicFile)
} else {
zoneInfo := rooms.GetZoneConfig(newRoom.Zone)
if zoneInfo.MusicFile != `` {
user.PlayMusic(zoneInfo.MusicFile)
} else if oldRoom.MusicFile != `` {
user.PlayMusic(`Off`)
}
}

return true
}
55 changes: 55 additions & 0 deletions internal/hooks/RoomChange_LocationMusicChange_Listener.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package hooks

import (
"github.com/volte6/gomud/internal/events"
"github.com/volte6/gomud/internal/rooms"
"github.com/volte6/gomud/internal/users"
)

//
// RoomChangeHandler waits for RoomChange events
// It then sends out GMCP data updates
// Also sends music changes out
//

func LocationMusicChange_Listener(e events.Event) bool {
evt := e.(events.RoomChange)

// If this isn't a user changing rooms, just pass it along.
if evt.UserId == 0 {
return true
}

// Get user... Make sure they still exist too.
user := users.GetByUserId(evt.UserId)
if user == nil {
return false
}

// Get the new room data... abort if doesn't exist.
newRoom := rooms.LoadRoom(evt.ToRoomId)
if newRoom == nil {
return false
}

// Get the old room data... abort if doesn't exist.
oldRoom := rooms.LoadRoom(evt.FromRoomId)
if oldRoom == nil {
return false
}

// If this zone has music, play it.
// Room music takes priority.
if newRoom.MusicFile != `` {
user.PlayMusic(newRoom.MusicFile)
} else {
zoneInfo := rooms.GetZoneConfig(newRoom.Zone)
if zoneInfo.MusicFile != `` {
user.PlayMusic(zoneInfo.MusicFile)
} else if oldRoom.MusicFile != `` {
user.PlayMusic(`Off`)
}
}

return true
}
1 change: 1 addition & 0 deletions internal/hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ func RegisterListeners() {

// RoomChange Listeners
events.RegisterListener(events.RoomChange{}, LocationGMCPUpdates_Listener)
events.RegisterListener(events.RoomChange{}, LocationMusicChange_Listener)

// NewRound Listeners
events.RegisterListener(events.NewRound{}, PruneVMs_Listener)
Expand Down

0 comments on commit a1dbb1e

Please sign in to comment.