Skip to content

Commit 9e4fa2c

Browse files
committed
Reactivated Team support, fixed RegistryFaction return value
1 parent ed01c70 commit 9e4fa2c

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

Source/Factions/Private/Factions/Faction.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88

99
const FFaction FFaction::NoFaction(NO_FACTION_NAME);
1010

11+
FFaction::FFaction(const FGenericTeamId& InTeam)
12+
{
13+
if (InTeam.GetId() != FGenericTeamId::NoTeam.GetId())
14+
{
15+
const UFactionsSettings* Settings = FFactionsModule::GetFactionManager();
16+
if (Settings)
17+
{
18+
TArray<FName> Keys;
19+
Settings->Factions.GetKeys(Keys);
20+
21+
if (Keys.IsValidIndex(InTeam.GetId()))
22+
{
23+
Name = Keys[InTeam.GetId()];
24+
return;
25+
}
26+
}
27+
}
28+
Name = NO_FACTION_NAME;
29+
}
30+
1131
bool FFaction::GetFactionInfo(FFactionInfo& Info) const
1232
{
1333
const UFactionsSettings* Settings = FFactionsModule::GetFactionManager();
@@ -73,3 +93,26 @@ const ETeamAttitude::Type FFaction::GetAttitudeTowards(const FFaction& Other) co
7393

7494
return FoundRelationPtr->Attitude;
7595
}
96+
97+
const FGenericTeamId FFaction::GetTeam() const
98+
{
99+
if (IsNone()) {
100+
return FGenericTeamId::NoTeam;
101+
}
102+
103+
const UFactionsSettings* Settings = FFactionsModule::GetFactionManager();
104+
check(Settings);
105+
106+
TArray<FName> Keys;
107+
Settings->Factions.GetKeys(Keys);
108+
109+
//Find Id
110+
const int32 Id = Keys.IndexOfByKey(Name);
111+
if (Id == INDEX_NONE || Id >= FGenericTeamId::NoTeam.GetId())
112+
{
113+
// If Faction ID is 255 or higher, Teams won't support it.
114+
return FGenericTeamId::NoTeam;
115+
}
116+
117+
return { static_cast<uint8>(Id) };
118+
}

Source/Factions/Private/FactionsLibrary.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ FFaction UFactionsLibrary::RegistryFaction(const FName& Name, const FFactionInfo
99
UFactionsSettings* Settings = FFactionsModule::GetFactionManager();
1010
check(Settings);
1111

12-
return Settings->Internal_RegistryFaction(Name, FactionInfo);
12+
Settings->Internal_RegistryFaction(Name, FactionInfo);
13+
14+
// Return the faction, won't be valid if its not registered
15+
return { Name };
1316
}
1417

1518
bool UFactionsLibrary::UnregistryFaction(FFaction Faction)

Source/Factions/Public/Factions/Faction.h

+4-17
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,8 @@ struct FACTIONS_API FFaction
4040
: Name(Name)
4141
{}
4242

43-
FFaction(const FGenericTeamId& InTeam)
44-
{
45-
/*if (InTeam.GetId() == FGenericTeamId::NoTeam.GetId())
46-
Id = NO_FACTION;
47-
else
48-
Id = InTeam.GetId();*/
49-
}
43+
FFaction(const FGenericTeamId& InTeam);
44+
5045

5146
/**
5247
* Find the information of a faction
@@ -62,16 +57,6 @@ struct FACTIONS_API FFaction
6257
*/
6358
bool SetFactionInfo(const FFactionInfo& NewInfo) const;
6459

65-
const FGenericTeamId GetTeam() const {
66-
/*if (Id == NO_FACTION || Id >= FGenericTeamId::NoTeam.GetId())
67-
{*/
68-
// If Faction ID is 255 or higher, Teams won't support it.
69-
return FGenericTeamId::NoTeam;
70-
/*}
71-
72-
return FGenericTeamId(Id);*/
73-
}
74-
7560
bool IsNone() const;
7661

7762
/**
@@ -103,4 +88,6 @@ struct FACTIONS_API FFaction
10388
FName GetIdName() const {
10489
return Name;
10590
}
91+
92+
const FGenericTeamId GetTeam() const;
10693
};

0 commit comments

Comments
 (0)