Cleaned PlaerStatesRequestEvent and added ForEach extension for ienumerables in Extensions

This commit is contained in:
ShoosGun 2021-07-06 19:51:12 -03:00
parent d309c5e205
commit 88b19c8fe2
2 changed files with 15 additions and 35 deletions

View File

@ -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<QSBWallText>().Where(x => x.AttachedObject.GetValue<bool>("_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<QSBComputer>().Where(x => x.AttachedObject.GetValue<bool>("_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<QSBVesselComputer>().Where(x => x.AttachedObject.GetValue<bool>("_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<IQSBQuantumObject>().ToList();
for (var i = 0; i < list.Count; i++)
{
QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, i, list[i].ControllingPlayer);
}
foreach (var campfire in QSBWorldSync.GetWorldObjects<QSBCampfire>())
{
QSBEventManager.FireEvent(EventNames.QSBCampfireState, campfire.ObjectId, campfire.GetState());
}
QSBWorldSync.GetWorldObjects<QSBCampfire>().ForEach(campfire => QSBEventManager.FireEvent(EventNames.QSBCampfireState, campfire.ObjectId, campfire.GetState()));
}
}
}

View File

@ -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<T>(this System.Collections.Generic.IEnumerable<T> enumerable, Action<T> action)
{
foreach (var item in enumerable)
action(item);
}
}
}