2022-07-25 23:42:36 +00:00
|
|
|
|
// SoundLoop Stardew Valley Mod
|
|
|
|
|
// Copyright (C) 2022 strelkasaur
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using StardewModdingAPI;
|
|
|
|
|
using StardewModdingAPI.Events;
|
|
|
|
|
using StardewModdingAPI.Utilities;
|
|
|
|
|
using StardewValley;
|
|
|
|
|
using StardewValley.Locations;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace SoundLoopMod
|
|
|
|
|
{
|
|
|
|
|
public class ModEntry : Mod
|
|
|
|
|
{
|
|
|
|
|
public override void Entry(IModHelper helper)
|
|
|
|
|
{
|
|
|
|
|
helper.Events.GameLoop.OneSecondUpdateTicking += this.CheckMusicNeedsRestarting;
|
2022-07-27 01:29:49 +00:00
|
|
|
|
helper.Events.Player.Warped += this.ResetMusicSecretWoods;
|
2022-07-25 23:42:36 +00:00
|
|
|
|
}
|
2022-07-27 01:29:49 +00:00
|
|
|
|
|
|
|
|
|
private const string WoodsName = "Woods";
|
|
|
|
|
|
2022-07-25 23:42:36 +00:00
|
|
|
|
private void CheckMusicNeedsRestarting(object? sender, OneSecondUpdateTickingEventArgs e)
|
|
|
|
|
{
|
2022-07-26 20:26:26 +00:00
|
|
|
|
// Don't do anything if we're at the title screen
|
2022-07-25 23:42:36 +00:00
|
|
|
|
if (!Context.IsWorldReady)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-07-26 20:26:26 +00:00
|
|
|
|
// Music won't play again in the mines if this timestamp is lower than 150000. Set to some arbitrary large value.
|
|
|
|
|
// The skull cavern is considered an extension of the mines, so this should affect that as well.
|
2022-07-25 23:42:36 +00:00
|
|
|
|
MineShaft.timeSinceLastMusic = 999999;
|
|
|
|
|
|
|
|
|
|
// Avoid playing morning song in the mines etc.
|
|
|
|
|
if (!Game1.currentLocation.IsOutdoors)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// The game keeps trying to stop the music if it's dark. We won't fight it for now
|
|
|
|
|
if (Game1.isDarkOut())
|
|
|
|
|
return;
|
2022-07-26 20:26:26 +00:00
|
|
|
|
|
|
|
|
|
// Don't start music while on the bus
|
|
|
|
|
// shouldHideCharacters seems to only be used for the bus, seems to be the nicest way to get this info
|
|
|
|
|
if (Game1.currentLocation.shouldHideCharacters())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Be extra-safe about not doing anything during an event (to protect the special cases below)
|
|
|
|
|
if (Game1.eventUp)
|
|
|
|
|
return;
|
2022-07-25 23:42:36 +00:00
|
|
|
|
|
2022-07-26 20:26:26 +00:00
|
|
|
|
// Seems to be safe to touch the current song, check if it has finished
|
2022-07-25 23:42:36 +00:00
|
|
|
|
if (Game1.currentSong == null || Game1.currentSong.IsStopped || Game1.requestedMusicTrack.ToLower().Contains("ambient"))
|
|
|
|
|
{
|
2022-07-27 01:29:49 +00:00
|
|
|
|
if (Game1.currentLocation.Name == WoodsName)
|
2022-07-26 20:26:26 +00:00
|
|
|
|
{
|
|
|
|
|
// The music for the secret woods is a bit of a special case.
|
|
|
|
|
Game1.changeMusicTrack("woodsTheme");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// General case, let the game figure out what song to play.
|
|
|
|
|
Game1.playMorningSong();
|
|
|
|
|
}
|
2022-07-25 23:42:36 +00:00
|
|
|
|
this.Monitor.Log("Restarted music");
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-27 01:29:49 +00:00
|
|
|
|
|
|
|
|
|
private void ResetMusicSecretWoods(object? sender, WarpedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// The game won't touch the music when entering the woods after 1800, causing the previously playing
|
|
|
|
|
// music to keep playing. Hence we stop it and let CheckMusicNeedsRestarting play the woods theme.
|
|
|
|
|
// However, after dark, let it keep playing the ambient night sound.
|
|
|
|
|
if (e.IsLocalPlayer && e.NewLocation.Name == WoodsName && !Game1.isDarkOut())
|
|
|
|
|
{
|
|
|
|
|
Game1.changeMusicTrack("none");
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-25 23:42:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|