diff --git a/GeneralMods/HappyBirthday/Framework/BirthdayEvents.cs b/GeneralMods/HappyBirthday/Framework/BirthdayEvents.cs index b09086b1..6d248b6f 100644 --- a/GeneralMods/HappyBirthday/Framework/BirthdayEvents.cs +++ b/GeneralMods/HappyBirthday/Framework/BirthdayEvents.cs @@ -23,7 +23,7 @@ namespace Omegasis.HappyBirthday.Framework EventHelper e = new EventHelper("CommunityCenterBirthday",19950, conditions, new EventStartData(EventStartData.MusicToPlayType.Continue, 32, 16, new EventStartData.FarmerData(32, 22, EventHelper.FacingDirection.Up),new List())); e.globalFadeIn(); e.moveFarmerUp(6, EventHelper.FacingDirection.Up, false); - e.ViewportLerpTileOffset(new Microsoft.Xna.Framework.Point(0,-6),60*6); + e.ViewportLerpTileOffset(new Microsoft.Xna.Framework.Point(0,-6),60*6,true); e.addObjectToPlayersInventory(64, 22,true); e.showMessage("Community center birthday here."); diff --git a/GeneralMods/StardustCore/Events/EventHelperExtensions.cs b/GeneralMods/StardustCore/Events/EventHelperExtensions.cs index 8cc04f30..a242f3e1 100644 --- a/GeneralMods/StardustCore/Events/EventHelperExtensions.cs +++ b/GeneralMods/StardustCore/Events/EventHelperExtensions.cs @@ -58,7 +58,7 @@ namespace StardustCore.Events /// /// /// How many frames (aka update ticks) it takes to finish. Aka 60~=1 second - public static void ViewportLerpTileOffset(this EventHelper EventHelper, Point NewTilePositionOffset, int Frames=60) + public static void ViewportLerpTileOffset(this EventHelper EventHelper, Point NewTilePositionOffset, int Frames=60,bool Concurrent=false) { StringBuilder b = new StringBuilder(); b.Append("Omegasis.EventFramework.ViewportLerp "); @@ -67,6 +67,8 @@ namespace StardustCore.Events b.Append((NewTilePositionOffset.Y * Game1.tileSize)); b.Append(" "); b.Append(Frames); + b.Append(" "); + b.Append(Concurrent); EventHelper.add(b); } diff --git a/GeneralMods/StardustCore/Events/EventManager.cs b/GeneralMods/StardustCore/Events/EventManager.cs index 3109d340..028647e7 100644 --- a/GeneralMods/StardustCore/Events/EventManager.cs +++ b/GeneralMods/StardustCore/Events/EventManager.cs @@ -17,16 +17,18 @@ namespace StardustCore.Events /// /// Event logic that occurs when the specialized command appears. /// - public Dictionary> customEventLogic; + public Dictionary> customEventLogic; + public Dictionary> concurrentEventActions; + public bool eventStarted; public EventManager() { this.events = new Dictionary(); - this.customEventLogic = new Dictionary>(); - + this.customEventLogic = new Dictionary>(); + this.concurrentEventActions = new Dictionary>(); this.customEventLogic.Add("Omegasis.EventFramework.AddObjectToPlayersInventory", ExtraEventActions.addObjectToPlayerInventory); this.customEventLogic.Add("Omegasis.EventFramework.ViewportLerp", ExtraEventActions.ViewportLerp); @@ -46,11 +48,17 @@ namespace StardustCore.Events /// /// /// - public void addCustomEventLogic(string CommandName,Action Function) + public void addCustomEventLogic(string CommandName,Action Function) { this.customEventLogic.Add(CommandName, Function); } + public void addConcurrentEvent(string EventData,Action Function) + { + + this.concurrentEventActions.Add(EventData, Function); + } + /// /// Hooked into the game's update tick. /// @@ -59,9 +67,23 @@ namespace StardustCore.Events if (Game1.CurrentEvent == null) return; string commandName = this.getGameCurrentEventCommandStringName(); //HappyBirthday.ModMonitor.Log("Current event command name is: " + commandName, StardewModdingAPI.LogLevel.Info); + + foreach(KeyValuePair> pair in this.concurrentEventActions) + { + pair.Value.Invoke(this,pair.Key); + } + if (string.IsNullOrEmpty(commandName)) return; if (this.customEventLogic.ContainsKey(commandName)){ - this.customEventLogic[commandName].Invoke(this.getGameCurrentEventCommandString()); + this.customEventLogic[commandName].Invoke(this,this.getGameCurrentEventCommandString()); + } + } + + public virtual void finishConcurrentEvent(string Key) + { + if (this.concurrentEventActions.ContainsKey(Key)) + { + this.concurrentEventActions.Remove(Key); } } diff --git a/GeneralMods/StardustCore/Events/ExtraEventActions.cs b/GeneralMods/StardustCore/Events/ExtraEventActions.cs index b9a5983b..d77cc1e1 100644 --- a/GeneralMods/StardustCore/Events/ExtraEventActions.cs +++ b/GeneralMods/StardustCore/Events/ExtraEventActions.cs @@ -22,7 +22,7 @@ namespace StardustCore.Events /// Adds the item from Game1.ObjectInformation to the player's inventory from the given event string. /// /// - public static void addObjectToPlayerInventory(string EventData) + public static void addObjectToPlayerInventory(EventManager EventManager,string EventData) { string[] splits = EventData.Split(' '); string name = splits[0]; @@ -34,7 +34,7 @@ namespace StardustCore.Events Game1.CurrentEvent.CurrentCommand++; } - public static void ViewportLerp(string EventData) + public static void ViewportLerp(EventManager EventManager,string EventData) { string[] splits = EventData.Split(' '); string name = splits[0]; @@ -42,6 +42,15 @@ namespace StardustCore.Events int xEndPosition =Convert.ToInt32(splits[1]); int yEndPosition = Convert.ToInt32(splits[2]); int frames = Convert.ToInt32(splits[3]); + bool concurrent = Convert.ToBoolean(splits[4]); + if (concurrent) + { + if (EventManager.concurrentEventActions.ContainsKey(EventData)==false) + { + EventManager.addConcurrentEvent(EventData, ViewportLerp); + ++Game1.CurrentEvent.CurrentCommand; //I've been told ++ is more efficient than ++; + } + } if (StartedLerp==false) { @@ -58,7 +67,11 @@ namespace StardustCore.Events OldViewportPosition = new Point(0, 0); CurrentViewportLerpAmount = 0; StartedLerp = false; - ++Game1.CurrentEvent.CurrentCommand; //I've been told ++ is more efficient than ++; + if(concurrent==false)++Game1.CurrentEvent.CurrentCommand; //I've been told ++ is more efficient than ++; + else + { + EventManager.finishConcurrentEvent(EventData); + } return; } Vector2 currentLerp = Vector2.Lerp(new Vector2(OldViewportPosition.X, OldViewportPosition.Y), new Vector2(OldViewportPosition.X + xEndPosition, OldViewportPosition.Y + yEndPosition), (float)((float)CurrentViewportLerpAmount/(float)frames));