[API] Faction Context API#886
Conversation
| if (Multiplayer.Client == null || ignore) return true; | ||
|
|
||
| var spectatorId = Multiplayer.WorldComp.spectatorFaction.loadID; | ||
| var spectatorId = Multiplayer.WorldComp.spectatorFaction?.loadID; |
There was a problem hiding this comment.
Can null spectatorFaction ever happen? Seems to be forcefully installed even when there is none during MultiplayerWorldComp.ExposeData, it's not tested for null anywhere else either.
There was a problem hiding this comment.
Met one time with VAE...
There was a problem hiding this comment.
If I remember correctly, read it at MapComponent.FinalizeInit can cause issue, I was using new API patching this
https://github.com/Vanilla-Expanded/VanillaAspirationsExpanded/blob/abb0c64efc7861cc04a0f1909eeaa5a4f589aed0/1.5/Source/VAspirE/World%20and%20Map%20Components/WorldComponent_PawnList.cs#L22
Likely when MapComponent.FinalizeInit and WorldComponent.FinalizeInit is calling?
|
|
||
| public void PopFaction(Map map = null) => FactionExtensions.PopFaction(map); | ||
|
|
||
| public void RepeatForWorldFactions(Action action) |
There was a problem hiding this comment.
Wouldn't it be better to share a readonly faction list?
There was a problem hiding this comment.
You mean like we implement a IFacionData to expose factionDatas and ask modders to iter through it themselves?
There was a problem hiding this comment.
I'm struggling with this idea exposing factionData, cuz push/popfaction is serving situations that we set faction data of distinct faction and RepeatFaction serves the iterator through all player-factions so I think all the usages are covered?
Still not a big problem if modders using it wisely though.
There was a problem hiding this comment.
I get it. It works but damn it looks ugly haha. Users need to know exactly what's being injected into the context. Otherwise, if something isn't implemented, they'll be scratching their heads wondering why it fails with no hint that its not being injected. Making it explicit would help a lot.
MP.RepeatForWorldFactions(() =>
{
int id = Faction.OfPlayer.loadID;
var researchManager = Find.ResearchManager;
// Need to iterate again to get specific map faction
MP.RepeatForMapFactions(map, () => {
// Very ugly
if (id == Faction.OfPlayer.loadId)
{
var designationManager = mapFaction.designationManager;
// do stuff with map
}
});
// do stuff with world
});My suggestion somewhat:
foreach(var worldFaction in MP.Factions)
{
int id = worldFaction.factionId;
var researchManager = worldFaction.researchManager;
var mapFaction = worldFaction.Map(map);
var designationManager = mapFaction.designationManager;
// do stuff with world or map
}FactionWorldData and FactionMapData would need to be exposed as interfaces and those types need to implement them.
paired with rwmt/MultiplayerAPI#13
Hope it works correctly