예제 #1
0
        public static bool Play(ref Cue __instance)
        {
            string name = __instance.Name;

            foreach (ActiveMusic a in CustomMusicMod.Active.Where(m => m.Id == name))
            {
                a.Dispose();
            }

            CustomMusicMod.Active.RemoveWhere(m => m.Id == name);

            bool custom = false;

            if (nextCue.Key == name)
            {
                custom  = true;
                name    = nextCue.Value;
                nextCue = new KeyValuePair <string, string>("none", "none");
            }
            bool ret = true;

            try
            {
                var songs = CustomMusicMod.Music.Where(m => m.Id == name && CustomMusicMod.checkConditions(m.Conditions)).ToList();

                if (songs.Count > 0 && songs.First() is StoredMusic music)
                {
                    ActiveMusic active = new ActiveMusic(__instance.Name, music.Sound.CreateInstance(), ref __instance, music.Ambient, music.Loop);
                    CustomMusicMod.Active.Add(active);
                    if (CustomMusicMod.config.Debug)
                    {
                        CustomMusicMod.SMonitor.Log("Playing: " + name + (custom ? " (custom)" : " (Changed)"), StardewModdingAPI.LogLevel.Trace);
                    }
                    ret = false;
                }
                else if (CustomMusicMod.config.Debug)
                {
                    CustomMusicMod.SMonitor.Log("Playing: " + name, StardewModdingAPI.LogLevel.Trace);
                }
            }
            catch
            {
            }

            return(ret);
        }
예제 #2
0
        public static bool Play3(string name, SoundBank soundbank)
        {
            bool custom = false;

            if (nextCue.Key == name)
            {
                custom  = true;
                name    = nextCue.Value;
                nextCue = new KeyValuePair <string, string>("none", "none");
            }
            bool ret = true;

            try
            {
                string preset = "Default";

                if (CustomMusicMod.config.Presets.ContainsKey(name))
                {
                    preset = CustomMusicMod.config.Presets[name];
                }

                if (preset == "Vanilla")
                {
                    return(ret);
                }

                List <StoredMusic> songs = null;

                if (preset != "Default" && preset != "Random" && preset != "Any")
                {
                    songs = CustomMusicMod.Music.Where(m => Path.GetFileNameWithoutExtension(m.Path) == preset).ToList();
                }

                if (preset == "Any")
                {
                    songs = CustomMusicMod.Music.ToList();
                }

                if (songs == null || songs.Count() == 0)
                {
                    songs = CustomMusicMod.Music.Where(m => m.Id == name && CustomMusicMod.checkConditions(m.Conditions)).ToList();
                }

                if (preset == "Random" || preset == "Any")
                {
                    songs.Add(new StoredMusic()
                    {
                        Id = "Vanilla"
                    });
                }

                if (songs.Count > 0 && songs.First() is StoredMusic music)
                {
                    if (songs.Count > 1)
                    {
                        music = songs[Game1.random.Next(songs.Count())];
                    }

                    if (music.Id == "Vanilla")
                    {
                        return(ret);
                    }

                    music.Sound.Play(CustomMusicMod.config.SoundVolume, 0f, 0f);

                    if (CustomMusicMod.config.Debug)
                    {
                        CustomMusicMod.SMonitor.Log("Playing: " + name + (custom ? " (custom)" : " (Changed)"), StardewModdingAPI.LogLevel.Trace);
                    }
                    ret = false;
                }
                else if (CustomMusicMod.config.Debug)
                {
                    CustomMusicMod.SMonitor.Log("Playing: " + name, StardewModdingAPI.LogLevel.Trace);
                }
            }
            catch
            {
            }

            return(ret);
        }
예제 #3
0
        public static bool Play2(string name, ref Cue __instance)
        {
            foreach (ActiveMusic a in CustomMusicMod.Active.Where(m => m.Id == name))
            {
                a.Dispose();
            }

            CustomMusicMod.Active.RemoveWhere(m => m.Id == name);

            bool custom = false;

            if (nextCue.Key == name)
            {
                custom  = true;
                name    = nextCue.Value;
                nextCue = new KeyValuePair <string, string>("none", "none");
            }
            bool ret = true;

            try
            {
                string preset = "Default";

                if (CustomMusicMod.config.Presets.ContainsKey(name))
                {
                    preset = CustomMusicMod.config.Presets[name];
                }

                if (preset == "Vanilla")
                {
                    return(ret);
                }

                List <StoredMusic> songs = null;

                if (preset != "Default" && preset != "Random" && preset != "Any")
                {
                    songs = CustomMusicMod.Music.Where(m => Path.GetFileNameWithoutExtension(m.Path) == preset).ToList();
                }

                if (preset == "Any")
                {
                    songs = CustomMusicMod.Music.ToList();
                }

                if (songs == null || songs.Count() == 0)
                {
                    songs = CustomMusicMod.Music.Where(m => m.Id == name && CustomMusicMod.checkConditions(m.Conditions)).ToList();
                }

                if (preset == "Random" || preset == "Any")
                {
                    songs.Add(new StoredMusic()
                    {
                        Id = "Vanilla"
                    });
                }

                if (songs.Count > 0 && songs.First() is StoredMusic music)
                {
                    if (songs.Count > 1)
                    {
                        music = songs[Game1.random.Next(songs.Count())];
                    }

                    if (music.Id == "Vanilla")
                    {
                        return(ret);
                    }

                    ActiveMusic active = new ActiveMusic(__instance.Name, music.Sound.CreateInstance(), music.Ambient, music.Loop);
                    CustomMusicMod.Active.Add(active);
                    if (CustomMusicMod.config.Debug)
                    {
                        CustomMusicMod.SMonitor.Log("Playing: " + name + (custom ? " (custom)" : " (Changed)"), StardewModdingAPI.LogLevel.Trace);
                    }
                    ret = false;
                }
                else if (CustomMusicMod.config.Debug)
                {
                    CustomMusicMod.SMonitor.Log("Playing: " + name, StardewModdingAPI.LogLevel.Trace);
                }
            }
            catch
            {
            }

            return(ret);
        }
예제 #4
0
        private void OnWarped(object sender, WarpedEventArgs e)
        {
            if (!(e.NewLocation is GameLocation) || !e.IsLocalPlayer)
            {
                return;
            }
            CurrentEmitters.ForEach(a => a.Dispose());
            CurrentEmitters.Clear();

            if (locations.TryGetValue(e.NewLocation.Name, out string name))
            {
                if (name.ToLower().StartsWith("cm:"))
                {
                    string[] n = name.Split(':');
                    if (n.Length <= 2 && Game1.currentSong != null && Game1.currentSong.Name is string s && s.Length > 0)
                    {
                        name += ":" + s;
                    }
                }
                Game1.changeMusicTrack(name);
            }

            if (emitterPlacements.TryGetValue(e.NewLocation.Name, out List <SoundEmitterPlacement> placements))
            {
                foreach (SoundEmitterPlacement emitter in placements.Where(p => CustomMusicMod.checkConditions(p.Conditions)))
                {
                    if (emitter.SoundId.ToLower().StartsWith("cm:"))
                    {
                        emitter.SoundId = emitter.SoundId.Substring(3);
                    }

                    var songs = CustomMusicMod.Music.Where(m => m.Id == emitter.SoundId && CustomMusicMod.checkConditions(m.Conditions)).ToList();
                    if (songs.FirstOrDefault() is StoredMusic music)
                    {
                        var         pos    = emitter.GetPosition();
                        ActiveMusic active = new ActiveMusic(emitter.SoundId + "_" + pos.X + "_" + pos.Y, music.Sound.CreateInstance(), music.Ambient, music.Loop, pos, emitter.DistanceModifier, emitter.VolumeModifier, emitter.MaxTileDistance);
                        CurrentEmitters.Add(active);
                    }
                }
            }

            if (e.NewLocation.Map is Map map && map.Properties.TryGetValue("SoundEmitters", out PropertyValue emittersValue) &&
                emittersValue != null &&
                emittersValue.ToString() is string emittersText &&
                emittersText != "")
            {
                var emittersData = emittersText.Split(';');
                foreach (string data in emittersData)
                {
                    if (data.Split(' ') is string[] emitter && emitter.Length >= 3 &&
                        float.TryParse(emitter[0], out float x) &&
                        float.TryParse(emitter[1], out float y) &&
                        emitter[2] is string aname)
                    {
                        float distance    = SoundEmitterPlacement.DefaultDistanceModifier;
                        float volume      = SoundEmitterPlacement.DefaultVolumeModifier;
                        int   maxDistance = SoundEmitterPlacement.DefaultMaxDistance;

                        if (aname.ToLower().StartsWith("cm:"))
                        {
                            aname = aname.Substring(3);
                        }

                        if (emitter.Length >= 4)
                        {
                            float.TryParse(emitter[3], out distance);
                        }

                        if (emitter.Length >= 5)
                        {
                            float.TryParse(emitter[4], out volume);
                        }

                        if (emitter.Length >= 6)
                        {
                            int.TryParse(emitter[5], out maxDistance);
                        }

                        var songs = CustomMusicMod.Music.Where(m => m.Id == aname && CustomMusicMod.checkConditions(m.Conditions)).ToList();
                        if (songs.FirstOrDefault() is StoredMusic music)
                        {
                            ActiveMusic active = new ActiveMusic(aname + "_" + x + "_" + y, music.Sound.CreateInstance(), music.Ambient, music.Loop, new Vector2(x, y), distance, volume, maxDistance);
                            CurrentEmitters.Add(active);
                        }
                    }
                }
            }
        }