Implement map view music, add tracks

master
WKFO 2020-12-25 19:24:01 +03:00 committed by Webster Sheets
parent e7bebe9b56
commit bdfe6ef873
10 changed files with 59 additions and 11 deletions

View File

@ -11,6 +11,8 @@ local MusicPlayer = {}
local music = {}
local inMapView = false
function MusicPlayer.getCategoryForSong(name)
if not name then return "" end
local _, _, category = string.find(name, "^music/core/([%l-]+)/")
@ -99,7 +101,7 @@ local playAmbient = function ()
-- switch to the specific music. if the music doesn't start (ie we don't
-- have any specific music) then fall back to normal space music
MusicPlayer.playRandomSongFromCategory(category)
if not Music.IsPlaying() then
if not Music.IsPlaying() or current_category == "map-core" or current_category == "map-unexplored" then
if Game.system then
if Game.system:DistanceTo(sol) > unexplored_distance then
MusicPlayer.playRandomSongFromCategory("unexplored")
@ -132,8 +134,27 @@ Event.Register("onGameStart", function ()
end)
-- if a song finishes fall back to ambient music
-- unless the player is in a map view, in which case
-- we start map music instead
Event.Register("onSongFinished", function ()
playAmbient()
if Game.CurrentView() == "sector" or Game.CurrentView() == "system_info" or Game.CurrentView() == "system" then
if Game.system:DistanceTo(SystemPath.New(0, 0, 0, 0, 0)) < 1000 then -- farther than where ambient music switches
if music["map-core"] then
MusicPlayer.playRandomSongFromCategory("map-core")
else -- fall back to ambient if category is empty
playAmbient()
end
else
if music["map-unexplored"] then
MusicPlayer.playRandomSongFromCategory("map-unexplored")
else -- fall back to ambient if category is empty
playAmbient()
end
end
inMapView = true
else
playAmbient()
end
end)
-- play discovery music if player enters an interesting system
@ -165,8 +186,8 @@ end)
Event.Register("onShipDestroyed", function (ship, attacker)
if ship:IsPlayer() then
MusicPlayer.playRandomSongFromCategory("player-destroyed")
elseif attacker:isa("Ship") and attacker:IsPlayer() then
MusicPlayer.playRandomSongFromCategory("ship-destroyed")
--elseif attacker:isa("Ship") and attacker:IsPlayer() then
-- MusicPlayer.playRandomSongFromCategory("ship-destroyed")
end
end)
@ -188,16 +209,29 @@ Event.Register("onShipAlertChanged", function (ship, alert)
if alert == "SHIP_NEARBY" and not ship:IsDocked() then
MusicPlayer.playRandomSongFromCategory("ship-nearby")
elseif alert == "SHIP_FIRING" then
MusicPlayer.playRandomSongFromCategory("ship-firing")
MusicPlayer.playRandomSongFromCategory("ship-firing", true)
else
playAmbient()
end
end)
-- player changed frame and might be near a planet or orbital station
Event.Register("onFrameChanged", function (body)
if Game.player:GetAlertState() == 'ship-firing' or Game.player:GetAlertState() == 'ship-nearby' then return end
if not body:isa("Ship") then return end
if not body:IsPlayer() then return end
playAmbient()
if not inMapView then
playAmbient()
end
end)
-- view has changed, so player might have left the map view
Event.Register("onViewChanged", function()
if inMapView and Game.CurrentView() == "world" then
playAmbient()
inMapView = false
end
end)
return MusicPlayer

View File

@ -8,10 +8,22 @@ Music in core/ is selected based on game events. When a particular game event
occurs a song is chosen at random from the appropriate subdir. The subdirs are
as follows:
- space: ambient music, played while flying in space. When music for a
specific event finishes the player will start a song from this category.
This is also the fallback category if any category subdir has no songs in
it.
- space: ambient music, played while flying in space around the populated
regions of the galaxy. When music for a specific event finishes the player
will start a song from this category. This is also the fallback category if
any category subdir has no songs in it.
- unexplored: ambient music, played while flying in space far away from
the populated regions of the galaxy. This is also the fallback category if
current music ends while player is in hyperspace.
- menu: main menu theme.
- discovery: plays if the player jumps to a rare unexplored stellar object.
- map-core, map-unexplored: plays if the ambient music ends while the player
is in sector or system map. map-core if player is in the populated regions
of the galaxy, map-unexplored if far away from civilization.
- near-planet, near-spacestation: ambient music specific to planets and
orbital stations. The player will play something from one of these
@ -27,7 +39,8 @@ as follows:
presence of a ship (even a firing ship) does not necessarily mean the ship
is hostile and the player is (about to be) in combat.
- ship-destroyed: played with the player destroys a ship
- ship-destroyed: played with the player destroys a ship. Disabled with
https://github.com/pioneerspacesim/pioneer/pull/5093.
- player-destroyed: played when the player is destroyed. Will continue to
play over the "tombstone" screen.

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.

View File

@ -1191,6 +1191,7 @@ void Pi::SetView(View *v)
if (currentView) currentView->Detach();
currentView = v;
if (currentView) currentView->Attach();
LuaEvent::Queue("onViewChanged");
}
void Pi::OnChangeDetailLevel()