From 895896710e6ff5455d10d602b5d32f5713ef10ff Mon Sep 17 00:00:00 2001 From: shoaib11120 Date: Sun, 16 Jan 2022 17:10:03 +0530 Subject: [PATCH] Added colliding sound --- stardew-access/ModEntry.cs | 53 +++++++++++++++++++-------- stardew-access/Patches/MenuPatches.cs | 34 +++++------------ stardew-access/manifest.json | 2 +- 3 files changed, 47 insertions(+), 42 deletions(-) diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 951f984..37ca32d 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -50,6 +50,8 @@ namespace stardew_access ScreenReader.initializeScreenReader(); // Initialize the screen reader + this.initializeSounds(); + harmony = new Harmony(ModManifest.UniqueID); // Init harmony #endregion @@ -239,30 +241,49 @@ namespace stardew_access }); #endregion - #region Custom Drop Item Sound + helper.Events.Input.ButtonPressed += this.OnButtonPressed; + helper.Events.GameLoop.UpdateTicked += this.onUpdateTicked; + } + + private void initializeSounds() + { try { - CueDefinition sa_drop_item = new CueDefinition(); - sa_drop_item.name = "sa_drop_item"; - sa_drop_item.instanceLimit = 1; - sa_drop_item.limitBehavior = CueDefinition.LimitBehavior.ReplaceOldest; - SoundEffect audio; - string filePathCombined = Path.Combine(this.Helper.DirectoryPath, "drop_item.wav"); - using (FileStream stream = new(filePathCombined, FileMode.Open)) + #region Drop Item Sound + CueDefinition dropItemCueDef = new CueDefinition(); + dropItemCueDef.name = "sa_drop_item"; + dropItemCueDef.instanceLimit = 1; + dropItemCueDef.limitBehavior = CueDefinition.LimitBehavior.ReplaceOldest; + SoundEffect dropItemAudio; + string dropItemFilePath = Path.Combine(this.Helper.DirectoryPath, "sounds/drop_item.wav"); + using (FileStream stream = new(dropItemFilePath, FileMode.Open)) { - audio = SoundEffect.FromStream(stream); + dropItemAudio = SoundEffect.FromStream(stream); } - sa_drop_item.SetSound(audio, Game1.audioEngine.GetCategoryIndex("Sound"), false); - Game1.soundBank.AddCue(sa_drop_item); + dropItemCueDef.SetSound(dropItemAudio, Game1.audioEngine.GetCategoryIndex("Sound"), false); + #endregion + + #region Colliding sound + CueDefinition collidingCueDef = new CueDefinition(); + collidingCueDef.name = "sa_colliding"; + collidingCueDef.instanceLimit = 1; + collidingCueDef.limitBehavior = CueDefinition.LimitBehavior.ReplaceOldest; + SoundEffect collidingAudio; + string collidingFilePath = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/NPC.wav"); + using (FileStream stream = new(collidingFilePath, FileMode.Open)) + { + collidingAudio = SoundEffect.FromStream(stream); + } + collidingCueDef.SetSound(collidingAudio, Game1.audioEngine.GetCategoryIndex("Sound"), false); + #endregion + + Game1.soundBank.AddCue(dropItemCueDef); + Game1.soundBank.AddCue(collidingCueDef); } catch (Exception e) { - MainClass.monitor.Log($"Unable to initialize custom sounds:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + monitor.Log($"Unable to initialize custom sounds:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } - #endregion - - helper.Events.Input.ButtonPressed += this.OnButtonPressed; - helper.Events.GameLoop.UpdateTicked += this.onUpdateTicked; } private void onUpdateTicked(object sender, UpdateTickedEventArgs e) diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index fbde0f5..1136625 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -11,6 +11,7 @@ namespace stardew_access.Patches { private static string currentLetterText = " "; private static string currentLevelUpTitle = " "; + public static Vector2? prevTile = null; internal static bool PlaySoundPatch(string cueName) { @@ -24,34 +25,17 @@ namespace stardew_access.Patches if(cueName == "grassyStep" || cueName == "sandyStep" || cueName == "snowyStep" || cueName == "stoneStep" || cueName == "thudStep" || cueName == "woodyStep") { - if(!Game1.currentLocation.isTilePassable(Game1.player.nextPosition(Game1.player.getDirection()), Game1.viewport)) + Vector2 nextTile = CurrentPlayer.getNextTile(); + Rectangle rect = new Rectangle((int)nextTile.X * 64 + 1,(int) nextTile.Y * 64 + 1, 62, 62); + if (Game1.currentLocation.isCollidingPosition(rect, Game1.viewport, true, 0, glider: false, Game1.player, pathfinding: false)) { + if (prevTile != nextTile) + { + prevTile = nextTile; + Game1.playSound("sa_colliding"); + } return false; } - - #region Check for objects - Vector2 gt = CurrentPlayer.getNextTile(); - - if (Game1.currentLocation.isObjectAtTile((int)gt.X, (int)gt.Y)) - { - if (!Game1.currentLocation.getObjectAtTile((int)gt.X, (int)gt.Y).isPassable()) - return false; - } - #endregion - - #region Check for terrain features - Dictionary> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict; - if (terrainFeature.ContainsKey(gt)) - { - if (!terrainFeature[gt].Get().isPassable()) - return false; - } - #endregion - - #region Check for resource clumps - if(ReadTile.getResourceClumpAtTile((int)gt.X, (int) gt.Y)!=null) - return false; - #endregion } } catch (Exception e) diff --git a/stardew-access/manifest.json b/stardew-access/manifest.json index b8b89a4..051e25b 100644 --- a/stardew-access/manifest.json +++ b/stardew-access/manifest.json @@ -1,7 +1,7 @@ { "Name": "Stardew Access", "Author": "Mohammad Shoaib", - "Version": "1.0.16-beta", + "Version": "1.0.17-beta", "Description": "An accessibility mod with screen reader support!", "UniqueID": "shoaib.stardewaccess", "EntryDll": "stardew-access.dll",