Skip to content

Commit c6d45fc

Browse files
committed
Improving house default side selection logic
1 parent 6c184c7 commit c6d45fc

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/TSMapEditor/Helpers.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -384,24 +384,26 @@ public static Color GetHouseTypeUITextColor(HouseType houseType)
384384

385385
public static void FindDefaultSideForNewHouseType(HouseType houseType, Rules rules)
386386
{
387+
// Cut numbers from the end of the housetype's name (so, for example, GDI2 becomes GDI)
388+
string houseTypeIniName = houseType.ININame;
389+
while (houseTypeIniName.Length > 0 && char.IsDigit(houseTypeIniName[^1]))
390+
houseTypeIniName = houseTypeIniName[..^1];
391+
392+
if (string.IsNullOrWhiteSpace(houseTypeIniName))
393+
{
394+
houseType.Side = rules.Sides[0];
395+
return;
396+
}
397+
387398
for (int sideIndex = 0; sideIndex < rules.Sides.Count; sideIndex++)
388399
{
389400
string side = rules.Sides[sideIndex];
390401

391-
if (houseType.ININame.StartsWith(side))
402+
if (side.StartsWith(houseTypeIniName))
392403
{
393404
houseType.Side = side;
394405
break;
395406
}
396-
397-
if (side.EndsWith("Side") && side.Length > 4)
398-
{
399-
if (houseType.ININame.StartsWith(side[..4]))
400-
{
401-
houseType.Side = side;
402-
break;
403-
}
404-
}
405407
}
406408

407409
if (string.IsNullOrWhiteSpace(houseType.Side))

0 commit comments

Comments
 (0)