-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial draft for improved source gen * add tests for new generator and restructure generator project * keep ordering of data container properties in generated code * add data element analyzer and unittests, refactor data element generator * add new DataContainer attribute to data containers to enable new generator * update PropertyChangedSourceGenerator to use FAWMN * code cleanup for generators and analyzer * add TextKind type to better specify how a type should be treated * move data elements to reduce unnecessary namespace nesting * fix unittests after moving data elements to new namespace * fix tests for PropertyChangedGenerator * fix sonarlint warnings and issues from review
- Loading branch information
1 parent
aa083c9
commit 5311fe7
Showing
88 changed files
with
4,640 additions
and
2,038 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
WoWsShipBuilder.Common/DataContainers/Aircraft/AirstrikeDataContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
608 changes: 304 additions & 304 deletions
608
WoWsShipBuilder.Common/DataContainers/Aircraft/CvAircraftDataContainer.cs
Large diffs are not rendered by default.
Oops, something went wrong.
3 changes: 2 additions & 1 deletion
3
WoWsShipBuilder.Common/DataContainers/Armament/DepthChargesLauncherDataContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 84 additions & 84 deletions
168
WoWsShipBuilder.Common/DataContainers/Armament/PingerGunDataContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,103 @@ | ||
using Microsoft.Extensions.Logging; | ||
using WoWsShipBuilder.DataElements; | ||
using WoWsShipBuilder.DataElements.DataElementAttributes; | ||
using WoWsShipBuilder.DataElements.DataElements; | ||
using WoWsShipBuilder.DataStructures; | ||
using WoWsShipBuilder.DataStructures.Ship; | ||
using WoWsShipBuilder.Infrastructure.Utility; | ||
|
||
namespace WoWsShipBuilder.DataContainers | ||
namespace WoWsShipBuilder.DataContainers; | ||
|
||
[DataContainer] | ||
public partial record PingerGunDataContainer : DataContainerBase | ||
{ | ||
public partial record PingerGunDataContainer : DataContainerBase | ||
{ | ||
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "S")] | ||
public decimal Reload { get; set; } | ||
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "S")] | ||
public decimal Reload { get; set; } | ||
|
||
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "DegreePerSecond")] | ||
public decimal TraverseSpeed { get; set; } | ||
|
||
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "DegreePerSecond")] | ||
public decimal TraverseSpeed { get; set; } | ||
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "S")] | ||
public decimal TurnTime { get; set; } | ||
|
||
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "S")] | ||
public decimal TurnTime { get; set; } | ||
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "KM")] | ||
public decimal Range { get; set; } | ||
|
||
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "KM")] | ||
public decimal Range { get; set; } | ||
[DataElementType(DataElementTypes.Grouped | DataElementTypes.KeyValueUnit, GroupKey = "PingDuration", UnitKey = "S", LocalizationKeyOverride = "First")] | ||
public decimal FirstPingDuration { get; set; } | ||
|
||
[DataElementType(DataElementTypes.Grouped | DataElementTypes.KeyValue, GroupKey = "PingDuration", UnitKey = "S", NameLocalizationKey = "First")] | ||
public decimal FirstPingDuration { get; set; } | ||
[DataElementType(DataElementTypes.Grouped | DataElementTypes.KeyValueUnit, GroupKey = "PingDuration", UnitKey = "S", LocalizationKeyOverride = "Second")] | ||
public decimal SecondPingDuration { get; set; } | ||
|
||
[DataElementType(DataElementTypes.Grouped | DataElementTypes.KeyValue, GroupKey = "PingDuration", UnitKey = "S", NameLocalizationKey = "Second")] | ||
public decimal SecondPingDuration { get; set; } | ||
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "M")] | ||
public decimal PingWidth { get; set; } | ||
|
||
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "M")] | ||
public decimal PingWidth { get; set; } | ||
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "MPS")] | ||
public decimal PingSpeed { get; set; } | ||
|
||
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "MPS")] | ||
public decimal PingSpeed { get; set; } | ||
public static PingerGunDataContainer? FromShip(Ship ship, IEnumerable<ShipUpgrade> shipConfiguration, List<(string name, float value)> modifiers) | ||
{ | ||
if (!ship.PingerGunList.Any()) | ||
{ | ||
return null; | ||
} | ||
|
||
public static PingerGunDataContainer? FromShip(Ship ship, IEnumerable<ShipUpgrade> shipConfiguration, List<(string name, float value)> modifiers) | ||
PingerGun pingerGun; | ||
var pingerUpgrade = shipConfiguration.FirstOrDefault(c => c.UcType == ComponentType.Sonar); | ||
if (pingerUpgrade is null && ship.PingerGunList.Count is 1) | ||
{ | ||
if (!ship.PingerGunList.Any()) | ||
{ | ||
return null; | ||
} | ||
|
||
PingerGun pingerGun; | ||
var pingerUpgrade = shipConfiguration.FirstOrDefault(c => c.UcType == ComponentType.Sonar); | ||
if (pingerUpgrade is null && ship.PingerGunList.Count is 1) | ||
{ | ||
Logging.Logger.LogWarning("No sonar upgrade information found for ship {ShipName} even though there is one sonar module available", ship.Name); | ||
return null; | ||
} | ||
|
||
if (pingerUpgrade is null) | ||
{ | ||
throw new InvalidOperationException($"No sonar upgrade information found for ship {ship.Name} but there is more than one sonar module."); | ||
} | ||
|
||
// Safe approach is necessary because data up until 0.11.9#1 does not include this data due to an issue in the data converter | ||
if (pingerUpgrade.Components.TryGetValue(ComponentType.Sonar, out string[]? pingerGunInfo)) | ||
{ | ||
pingerGun = ship.PingerGunList[pingerGunInfo.First()]; | ||
} | ||
else | ||
{ | ||
Logging.Logger.LogWarning("Unable to retrieve sonar component from upgrade info for ship {} and ship upgrade {}", ship.Index, pingerUpgrade.Name); | ||
pingerGun = ship.PingerGunList.First().Value; | ||
} | ||
|
||
var pingSpeed = pingerGun.WaveParams.First().WaveSpeed.First(); | ||
var pingSpeedModifiers = modifiers.FindModifiers("pingerWaveSpeedCoeff"); | ||
pingSpeed = pingSpeedModifiers.Aggregate(pingSpeed, (current, pingSpeedModifier) => current * (decimal)pingSpeedModifier); | ||
|
||
var firstPingDuration = pingerGun.SectorParams[0].Lifetime; | ||
var firstPingDurationModifiers = modifiers.FindModifiers("firstSectorTimeCoeff"); | ||
firstPingDuration = firstPingDurationModifiers.Aggregate(firstPingDuration, (current, firstPingDurationModifier) => current * (decimal)firstPingDurationModifier); | ||
|
||
var secondPingDuration = pingerGun.SectorParams[1].Lifetime; | ||
var secondPingDurationModifiers = modifiers.FindModifiers("secondSectorTimeCoeff"); | ||
secondPingDuration = secondPingDurationModifiers.Aggregate(secondPingDuration, (current, secondPingDurationModifiersModifier) => current * (decimal)secondPingDurationModifiersModifier); | ||
|
||
var traverseSpeed = pingerGun.RotationSpeed[0]; | ||
|
||
var arModifiers = modifiers.FindModifiers("lastChanceReloadCoefficient"); | ||
var reload = arModifiers.Aggregate(pingerGun.WaveReloadTime, (current, arModifier) => current * (1 - ((decimal)arModifier / 100))); | ||
var pingReloadModifiers = modifiers.FindModifiers("pingerReloadCoeff"); | ||
reload = pingReloadModifiers.Aggregate(reload, (current, pingReloadModifier) => current * (decimal)pingReloadModifier); | ||
|
||
var pingerGunDataContainer = new PingerGunDataContainer | ||
{ | ||
TurnTime = Math.Round(180 / traverseSpeed, 1), | ||
TraverseSpeed = traverseSpeed, | ||
Reload = Math.Round(reload, 2), | ||
Range = pingerGun.WaveDistance / 1000, | ||
FirstPingDuration = Math.Round(firstPingDuration, 1), | ||
SecondPingDuration = Math.Round(secondPingDuration, 1), | ||
PingWidth = pingerGun.WaveParams.First().StartWaveWidth, | ||
PingSpeed = Math.Round(pingSpeed, 0), | ||
}; | ||
|
||
pingerGunDataContainer.UpdateDataElements(); | ||
|
||
return pingerGunDataContainer; | ||
Logging.Logger.LogWarning("No sonar upgrade information found for ship {ShipName} even though there is one sonar module available", ship.Name); | ||
return null; | ||
} | ||
|
||
if (pingerUpgrade is null) | ||
{ | ||
throw new InvalidOperationException($"No sonar upgrade information found for ship {ship.Name} but there is more than one sonar module."); | ||
} | ||
|
||
// Safe approach is necessary because data up until 0.11.9#1 does not include this data due to an issue in the data converter | ||
if (pingerUpgrade.Components.TryGetValue(ComponentType.Sonar, out string[]? pingerGunInfo)) | ||
{ | ||
pingerGun = ship.PingerGunList[pingerGunInfo.First()]; | ||
} | ||
else | ||
{ | ||
Logging.Logger.LogWarning("Unable to retrieve sonar component from upgrade info for ship {} and ship upgrade {}", ship.Index, pingerUpgrade.Name); | ||
pingerGun = ship.PingerGunList.First().Value; | ||
} | ||
|
||
var pingSpeed = pingerGun.WaveParams.First().WaveSpeed.First(); | ||
var pingSpeedModifiers = modifiers.FindModifiers("pingerWaveSpeedCoeff"); | ||
pingSpeed = pingSpeedModifiers.Aggregate(pingSpeed, (current, pingSpeedModifier) => current * (decimal)pingSpeedModifier); | ||
|
||
var firstPingDuration = pingerGun.SectorParams[0].Lifetime; | ||
var firstPingDurationModifiers = modifiers.FindModifiers("firstSectorTimeCoeff"); | ||
firstPingDuration = firstPingDurationModifiers.Aggregate(firstPingDuration, (current, firstPingDurationModifier) => current * (decimal)firstPingDurationModifier); | ||
|
||
var secondPingDuration = pingerGun.SectorParams[1].Lifetime; | ||
var secondPingDurationModifiers = modifiers.FindModifiers("secondSectorTimeCoeff"); | ||
secondPingDuration = secondPingDurationModifiers.Aggregate(secondPingDuration, (current, secondPingDurationModifiersModifier) => current * (decimal)secondPingDurationModifiersModifier); | ||
|
||
var traverseSpeed = pingerGun.RotationSpeed[0]; | ||
|
||
var arModifiers = modifiers.FindModifiers("lastChanceReloadCoefficient"); | ||
var reload = arModifiers.Aggregate(pingerGun.WaveReloadTime, (current, arModifier) => current * (1 - ((decimal)arModifier / 100))); | ||
var pingReloadModifiers = modifiers.FindModifiers("pingerReloadCoeff"); | ||
reload = pingReloadModifiers.Aggregate(reload, (current, pingReloadModifier) => current * (decimal)pingReloadModifier); | ||
|
||
var pingerGunDataContainer = new PingerGunDataContainer | ||
{ | ||
TurnTime = Math.Round(180 / traverseSpeed, 1), | ||
TraverseSpeed = traverseSpeed, | ||
Reload = Math.Round(reload, 2), | ||
Range = pingerGun.WaveDistance / 1000, | ||
FirstPingDuration = Math.Round(firstPingDuration, 1), | ||
SecondPingDuration = Math.Round(secondPingDuration, 1), | ||
PingWidth = pingerGun.WaveParams.First().StartWaveWidth, | ||
PingSpeed = Math.Round(pingSpeed, 0), | ||
}; | ||
|
||
pingerGunDataContainer.UpdateDataElements(); | ||
|
||
return pingerGunDataContainer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
WoWsShipBuilder.Common/DataContainers/Projectiles/ProjectileDataContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.