Adding sound cues
parent
895896710e
commit
ac9957954e
|
@ -0,0 +1,161 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using StardewValley;
|
||||||
|
using StardewValley.Objects;
|
||||||
|
using StardewValley.TerrainFeatures;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace stardew_access.Game
|
||||||
|
{
|
||||||
|
public class Radar
|
||||||
|
{
|
||||||
|
private List<Vector2> closed;
|
||||||
|
private List<Furniture> furnitures;
|
||||||
|
public List<string> exclusions;
|
||||||
|
|
||||||
|
public Radar()
|
||||||
|
{
|
||||||
|
closed = new List<Vector2>();
|
||||||
|
furnitures = new List<Furniture>();
|
||||||
|
exclusions = new List<string>();
|
||||||
|
|
||||||
|
exclusions.Add("stone");
|
||||||
|
exclusions.Add("weed");
|
||||||
|
exclusions.Add("twig");
|
||||||
|
exclusions.Add("coloured stone");
|
||||||
|
exclusions.Add("mine stone");
|
||||||
|
exclusions.Add("clay stone");
|
||||||
|
exclusions.Add("fossil stone");
|
||||||
|
exclusions.Add("crop");
|
||||||
|
exclusions.Add("giant crop");
|
||||||
|
exclusions.Add("grass");
|
||||||
|
exclusions.Add("tree");
|
||||||
|
exclusions.Add("flooring");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
Stopwatch sw = new Stopwatch();
|
||||||
|
sw.Start();
|
||||||
|
Vector2 currPosition = Game1.player.getTileLocation();
|
||||||
|
int limit = 5;
|
||||||
|
|
||||||
|
closed.Clear();
|
||||||
|
furnitures.Clear();
|
||||||
|
findTile(currPosition, currPosition, limit);
|
||||||
|
sw.Stop();
|
||||||
|
MainClass.monitor.Log($"Time taken:{sw.ElapsedMilliseconds}ms", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void findTile(Vector2 position, Vector2 center, int limit)
|
||||||
|
{
|
||||||
|
if (Math.Abs(position.X - center.X) > limit)
|
||||||
|
return;
|
||||||
|
if (Math.Abs(position.Y - center.Y) > limit)
|
||||||
|
return;
|
||||||
|
if (closed.Contains(position))
|
||||||
|
return;
|
||||||
|
|
||||||
|
closed.Add(position);
|
||||||
|
checkTile(position);
|
||||||
|
|
||||||
|
Vector2 northPosition = new Vector2(position.X, position.Y-1);
|
||||||
|
Vector2 eastPosition = new Vector2(position.X+1, position.Y);
|
||||||
|
Vector2 westPosition = new Vector2(position.X-1, position.Y);
|
||||||
|
Vector2 southPosition = new Vector2(position.X, position.Y+1);
|
||||||
|
|
||||||
|
findTile(northPosition, center, limit);
|
||||||
|
findTile(eastPosition, center, limit);
|
||||||
|
findTile(westPosition, center, limit);
|
||||||
|
findTile(southPosition, center, limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkTile(Vector2 position)
|
||||||
|
{
|
||||||
|
Dictionary<Vector2, Netcode.NetRef<TerrainFeature>> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict;
|
||||||
|
|
||||||
|
if (Game1.currentLocation.isObjectAtTile((int)position.X, (int)position.Y))
|
||||||
|
{
|
||||||
|
string? obj = ReadTile.getObjectNameAtTile((int)position.X, (int)position.Y);
|
||||||
|
StardewValley.Object @object = Game1.currentLocation.getObjectAtTile((int)position.X, (int)position.Y);
|
||||||
|
|
||||||
|
if (@object is Furniture)
|
||||||
|
{
|
||||||
|
if (!furnitures.Contains(@object as Furniture))
|
||||||
|
{
|
||||||
|
furnitures.Add(@object as Furniture);
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"FUR:{@object.DisplayName}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!exclusions.Contains(obj.ToLower()))
|
||||||
|
{
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"OBJ:{obj}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (terrainFeature.ContainsKey(position))
|
||||||
|
{
|
||||||
|
Netcode.NetRef<TerrainFeature> tr = terrainFeature[position];
|
||||||
|
string? terrain = ReadTile.getTerrainFeatureAtTile(tr);
|
||||||
|
if (tr != null)
|
||||||
|
{
|
||||||
|
if(tr.Get() is HoeDirt && !exclusions.Contains("crop"))
|
||||||
|
{
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"CROP:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if(tr.Get() is GiantCrop && !exclusions.Contains("giant crop"))
|
||||||
|
{
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"BUSH:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if (tr.Get() is Bush && !exclusions.Contains("bush"))
|
||||||
|
{
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"BUSH:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if (tr.Get() is CosmeticPlant && !exclusions.Contains("cosmetic plant"))
|
||||||
|
{
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"COSMETIC_PLANT:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if (tr.Get() is Flooring && !exclusions.Contains("flooring"))
|
||||||
|
{
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"FLOORING:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if (tr.Get() is FruitTree && !exclusions.Contains("fruit tree"))
|
||||||
|
{
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"FRUTI_TREE:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if (tr.Get() is Grass && !exclusions.Contains("grass"))
|
||||||
|
{
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"GRASS:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if (tr.Get() is Tree && !exclusions.Contains("tree"))
|
||||||
|
{
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"TREE:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if (tr.Get() is Quartz && !exclusions.Contains("quartz"))
|
||||||
|
{
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"QUARTZ:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if (tr.Get() is Leaf && !exclusions.Contains("leaf"))
|
||||||
|
{
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"LEAF:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if(!exclusions.Contains(terrain.ToLower()))
|
||||||
|
{
|
||||||
|
Game1.currentLocation.localSoundAt("sa_poi", position);
|
||||||
|
MainClass.monitor.Log($"TERRAIN:{tr}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -173,6 +173,22 @@ namespace stardew_access.Game
|
||||||
toReturn = "Fertilized " + toReturn;
|
toReturn = "Fertilized " + toReturn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(terrain.Get() is GiantCrop)
|
||||||
|
{
|
||||||
|
int whichCrop = (terrain.Get() as GiantCrop).which.Value;
|
||||||
|
switch (whichCrop)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
toReturn = "Cauliflower";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
toReturn = "Melon";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
toReturn = "Pumpkin";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (terrain.Get() is Bush)
|
else if (terrain.Get() is Bush)
|
||||||
{
|
{
|
||||||
toReturn = "Bush";
|
toReturn = "Bush";
|
||||||
|
|
|
@ -21,6 +21,7 @@ namespace stardew_access
|
||||||
public static IMonitor? monitor;
|
public static IMonitor? monitor;
|
||||||
AutoHotkeyEngine ahk;
|
AutoHotkeyEngine ahk;
|
||||||
public static string hudMessageQueryKey = "";
|
public static string hudMessageQueryKey = "";
|
||||||
|
public static Radar radar;
|
||||||
|
|
||||||
/*********
|
/*********
|
||||||
** Public methods
|
** Public methods
|
||||||
|
@ -54,6 +55,8 @@ namespace stardew_access
|
||||||
|
|
||||||
harmony = new Harmony(ModManifest.UniqueID); // Init harmony
|
harmony = new Harmony(ModManifest.UniqueID); // Init harmony
|
||||||
|
|
||||||
|
radar = new Radar();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Harmony Patches
|
#region Harmony Patches
|
||||||
|
@ -269,16 +272,29 @@ namespace stardew_access
|
||||||
collidingCueDef.instanceLimit = 1;
|
collidingCueDef.instanceLimit = 1;
|
||||||
collidingCueDef.limitBehavior = CueDefinition.LimitBehavior.ReplaceOldest;
|
collidingCueDef.limitBehavior = CueDefinition.LimitBehavior.ReplaceOldest;
|
||||||
SoundEffect collidingAudio;
|
SoundEffect collidingAudio;
|
||||||
string collidingFilePath = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/NPC.wav");
|
string collidingFilePath = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/colliding.ogg");
|
||||||
using (FileStream stream = new(collidingFilePath, FileMode.Open))
|
using (FileStream stream = new(collidingFilePath, FileMode.Open))
|
||||||
{
|
{
|
||||||
collidingAudio = SoundEffect.FromStream(stream);
|
collidingAudio = SoundEffect.FromStream(stream);
|
||||||
}
|
}
|
||||||
collidingCueDef.SetSound(collidingAudio, Game1.audioEngine.GetCategoryIndex("Sound"), false);
|
collidingCueDef.SetSound(collidingAudio, Game1.audioEngine.GetCategoryIndex("Sound"), false);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region POI sound
|
||||||
|
CueDefinition poiCueDef = new CueDefinition();
|
||||||
|
poiCueDef.name = "sa_poi";
|
||||||
|
SoundEffect poiAudio;
|
||||||
|
string poiFilePath = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/sound1.ogg");
|
||||||
|
using (FileStream stream = new(poiFilePath, FileMode.Open))
|
||||||
|
{
|
||||||
|
poiAudio = SoundEffect.FromStream(stream);
|
||||||
|
}
|
||||||
|
poiCueDef.SetSound(poiAudio, Game1.audioEngine.GetCategoryIndex("Footsteps"), false);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
Game1.soundBank.AddCue(dropItemCueDef);
|
Game1.soundBank.AddCue(dropItemCueDef);
|
||||||
Game1.soundBank.AddCue(collidingCueDef);
|
Game1.soundBank.AddCue(collidingCueDef);
|
||||||
|
Game1.soundBank.AddCue(poiCueDef);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -345,10 +361,16 @@ namespace stardew_access
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manual read tile
|
// Manual read tile
|
||||||
if(Equals(e.Button, SButton.J))
|
if (Equals(e.Button, SButton.J))
|
||||||
{
|
{
|
||||||
ReadTile.run(manuallyTriggered: true);
|
ReadTile.run(manuallyTriggered: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Manual read tile
|
||||||
|
if (Equals(e.Button, SButton.B))
|
||||||
|
{
|
||||||
|
radar.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SnapMouseToPlayer()
|
private void SnapMouseToPlayer()
|
||||||
|
|
Loading…
Reference in New Issue