From 88b19c8fe286d1a84c20f57beeb962242a2f6288 Mon Sep 17 00:00:00 2001 From: ShoosGun Date: Tue, 6 Jul 2021 19:51:12 -0300 Subject: [PATCH] Cleaned PlaerStatesRequestEvent and added ForEach extension for ienumerables in Extensions --- QSB/Player/Events/PlayerStatesRequestEvent.cs | 44 ++++--------------- QSB/Utility/Extensions.cs | 6 +++ 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/QSB/Player/Events/PlayerStatesRequestEvent.cs b/QSB/Player/Events/PlayerStatesRequestEvent.cs index e116587b..04f242db 100644 --- a/QSB/Player/Events/PlayerStatesRequestEvent.cs +++ b/QSB/Player/Events/PlayerStatesRequestEvent.cs @@ -36,52 +36,26 @@ namespace QSB.Player.Events return; } - // TODO : CLEAN. THIS. SHIT. - - foreach (var condition in QSBWorldSync.DialogueConditions) - { - QSBEventManager.FireEvent(EventNames.DialogueCondition, condition.Key, condition.Value); - } - - foreach (var fact in QSBWorldSync.ShipLogFacts) - { - QSBEventManager.FireEvent(EventNames.QSBRevealFact, fact.Id, fact.SaveGame, false); - } + // TODO : CLEAN. THIS. SHIT. + QSBWorldSync.DialogueConditions.ForEach(condition => QSBEventManager.FireEvent(EventNames.DialogueCondition, condition.Key, condition.Value)); + QSBWorldSync.ShipLogFacts.ForEach(fact => QSBEventManager.FireEvent(EventNames.QSBRevealFact, fact.Id, fact.SaveGame, false)); + + //We could add a nested ForEach here, but, in my opinion, it would reduce readbility in this case - ShoosGun(Locochoco) foreach (var wallText in QSBWorldSync.GetWorldObjects().Where(x => x.AttachedObject.GetValue("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0)) - { - foreach (var id in wallText.GetTranslatedIds()) - { - QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.WallText, wallText.ObjectId, id); - } - } + wallText.GetTranslatedIds().ForEach(id => QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.WallText, wallText.ObjectId, id)); foreach (var computer in QSBWorldSync.GetWorldObjects().Where(x => x.AttachedObject.GetValue("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0)) - { - foreach (var id in computer.GetTranslatedIds()) - { - QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.Computer, computer.ObjectId, id); - } - } + computer.GetTranslatedIds().ForEach(id => QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.Computer, computer.ObjectId, id)); foreach (var vesselComputer in QSBWorldSync.GetWorldObjects().Where(x => x.AttachedObject.GetValue("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0)) - { - foreach (var id in vesselComputer.GetTranslatedIds()) - { - QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.VesselComputer, vesselComputer.ObjectId, id); - } - } + vesselComputer.GetTranslatedIds().ForEach(id => QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.VesselComputer, vesselComputer.ObjectId, id)); var list = QSBWorldSync.GetWorldObjects().ToList(); for (var i = 0; i < list.Count; i++) - { QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, i, list[i].ControllingPlayer); - } - foreach (var campfire in QSBWorldSync.GetWorldObjects()) - { - QSBEventManager.FireEvent(EventNames.QSBCampfireState, campfire.ObjectId, campfire.GetState()); - } + QSBWorldSync.GetWorldObjects().ForEach(campfire => QSBEventManager.FireEvent(EventNames.QSBCampfireState, campfire.ObjectId, campfire.GetState())); } } } \ No newline at end of file diff --git a/QSB/Utility/Extensions.cs b/QSB/Utility/Extensions.cs index 6ff474cf..df0ad9ae 100644 --- a/QSB/Utility/Extensions.cs +++ b/QSB/Utility/Extensions.cs @@ -63,5 +63,11 @@ namespace QSB.Utility public static float Map(this float value, float inputFrom, float inputTo, float outputFrom, float outputTo) => ((value - inputFrom) / (inputTo - inputFrom) * (outputTo - outputFrom)) + outputFrom; + + public static void ForEach(this System.Collections.Generic.IEnumerable enumerable, Action action) + { + foreach (var item in enumerable) + action(item); + } } }