Skip to content

Commit

Permalink
Cleaned up events to match naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Somfic committed Mar 11, 2024
1 parent 43a623e commit c832ab8
Show file tree
Hide file tree
Showing 84 changed files with 2,758 additions and 2,245 deletions.
39 changes: 37 additions & 2 deletions EliteAPI.Events.Generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
var description = schema["description"]?.Value<string>();

var properties = new List<(string type, string name)>();
var subClasses = new Dictionary<string, List<(string type, string name)>>();

if(schema["properties"] == null)
{
Expand All @@ -24,6 +25,10 @@
continue;

var propertyType = (string)property.First!["type"]!;

if (propertyName.EndsWith("ID") || propertyName.EndsWith("Address"))
propertyType = "string";

var propertyTypeName = GetCSharpType(propertyType);
properties.Add((propertyTypeName, propertyName));
}
Expand All @@ -39,20 +44,48 @@
var jsonPropertyAttribute = $"[JsonProperty(\"{property.name}\")]";
var propertyAttribute = $"public {property.type} {property.name} {{ get; init; }}";

if(property.type.StartsWith("SUBCLASS"))
continue;

if (!content.Contains(jsonPropertyAttribute))
{
Console.WriteLine($"Property {property.name} not found in {rawSchema.name}Event.cs");

var propertyLine = $"\n {jsonPropertyAttribute}\n {propertyAttribute}";
var propertyLine = $"\n {jsonPropertyAttribute}\n {propertyAttribute}\n";

// Add the property to the class file, just before the last bracket

var lastBracket = content.LastIndexOf('}');

content = content.Insert(lastBracket, propertyLine);

File.WriteAllText(file.FullName, content);
// Format the file
content = content.Replace("\n\n\n", "\n\n");

// Indent based on brackets
var lines = content.Split('\n');
var indent = 0;
for (var i = 0; i < lines.Length; i++)
{
var line = lines[i].Trim();
indent -= line.Count(c => c == '}');
indent += line.Count(c => c == '{');

if (line.StartsWith('{'))
{
lines[i] = new string('\t', indent - 1) + line;
}
else
{
lines[i] = new string('\t', indent) + line;
}


}

content = string.Join('\n', lines);

File.WriteAllText(file.FullName, content);
}
}
}
Expand All @@ -70,6 +103,8 @@ string GetCSharpType(string jsonType)
"number" => "double",
"integer" => "int",
"boolean" => "bool",
"object" => "SUBCLASS:OBJECT",
"array" => "SUBCLASS:ARRAY",
_ => jsonType
};
}
61 changes: 35 additions & 26 deletions EliteAPI.Events/ApproachSettlementEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,39 @@ namespace EliteAPI.Events;

public readonly struct ApproachSettlementEvent : IEvent
{
[JsonProperty("timestamp")]
public DateTime Timestamp { get; init; }

[JsonProperty("event")]
public string Event { get; init; }

[JsonProperty("Name")]
public string Name { get; init; }

[JsonProperty("MarketID")]
public string MarketId { get; init; }

[JsonProperty("SystemAddress")]
public string SystemAddress { get; init; }

[JsonProperty("BodyID")]
public string BodyId { get; init; }

[JsonProperty("BodyName")]
public string BodyName { get; init; }

[JsonProperty("Latitude")]
public double Latitude { get; init; }

[JsonProperty("Longitude")]
public double Longitude { get; init; }
[JsonProperty("timestamp")]
public DateTime Timestamp { get; init; }

[JsonProperty("event")]
public string Event { get; init; }

[JsonProperty("Name")]
public string Name { get; init; }

[JsonProperty("MarketID")]
public string MarketId { get; init; }

[JsonProperty("SystemAddress")]
public string SystemAddress { get; init; }

[JsonProperty("BodyID")]
public string BodyId { get; init; }

[JsonProperty("BodyName")]
public string BodyName { get; init; }

[JsonProperty("Latitude")]
public double Latitude { get; init; }

[JsonProperty("Longitude")]
public double Longitude { get; init; }

[JsonProperty("StationGovernment")]
public string StationGovernment { get; init; }

[JsonProperty("StationAllegiance")]
public string StationAllegiance { get; init; }

[JsonProperty("StationEconomy")]
public string StationEconomy { get; init; }
}
75 changes: 39 additions & 36 deletions EliteAPI.Events/BountyEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,43 @@ namespace EliteAPI.Events;

public readonly struct BountyEvent : IEvent
{
[JsonProperty("timestamp")]
public DateTime Timestamp { get; init; }

[JsonProperty("event")]
public string Event { get; init; }

[JsonProperty("Rewards")]
public IReadOnlyCollection<BountyRewardInfo> Rewards { get; init; }

[JsonProperty("Target")]
public Localised Target { get; init; }

[JsonProperty("TotalReward")]
public long TotalReward { get; init; }

[JsonProperty("VictimFaction")]
public string VictimFaction { get; init; }

[JsonProperty("SharedWithOthers")]
public long SharedWithOthers { get; init; }

[JsonProperty("Faction")]
public string Faction { get; init; }


[JsonProperty("Reward")]
public long Reward { get; init; }

public readonly struct BountyRewardInfo
{
[JsonProperty("Faction")]
public string Faction { get; init; }

[JsonProperty("Reward")]
public long Reward { get; init; }
}
[JsonProperty("timestamp")]
public DateTime Timestamp { get; init; }

[JsonProperty("event")]
public string Event { get; init; }

[JsonProperty("Rewards")]
public IReadOnlyCollection<BountyRewardInfo> Rewards { get; init; }

[JsonProperty("Target")]
public Localised Target { get; init; }

[JsonProperty("TotalReward")]
public long TotalReward { get; init; }

[JsonProperty("VictimFaction")]
public string VictimFaction { get; init; }

[JsonProperty("SharedWithOthers")]
public long SharedWithOthers { get; init; }

[JsonProperty("Faction")]
public string Faction { get; init; }


[JsonProperty("Reward")]
public long Reward { get; init; }

public readonly struct BountyRewardInfo
{
[JsonProperty("Faction")]
public string Faction { get; init; }

[JsonProperty("Reward")]
public long Reward { get; init; }
}

[JsonProperty("PilotName")]
public string PilotName { get; init; }
}
33 changes: 18 additions & 15 deletions EliteAPI.Events/BuySuitEvent.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
using EliteAPI.Abstractions.Events;
using EliteAPI.Abstractions.Events;
using Newtonsoft.Json;

namespace EliteAPI.Events;

public readonly struct BuySuitEvent : IEvent
{
[JsonProperty("timestamp")]
public DateTime Timestamp { get; init; }

[JsonProperty("event")]
public string Event { get; init; }

[JsonProperty("Name")]
public Localised Name { get; init; }

[JsonProperty("Price")]
public long Price { get; init; }

[JsonProperty("SuitId")]
public string SuitId { get; init; }
[JsonProperty("timestamp")]
public DateTime Timestamp { get; init; }

[JsonProperty("event")]
public string Event { get; init; }

[JsonProperty("Name")]
public Localised Name { get; init; }

[JsonProperty("Price")]
public long Price { get; init; }

[JsonProperty("SuitId")]
public string SuitId { get; init; }

[JsonProperty("SuitID")]
public string SuitID { get; init; }
}
66 changes: 42 additions & 24 deletions EliteAPI.Events/CarrierFinanceEvent.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
using EliteAPI.Abstractions.Events;
using EliteAPI.Abstractions.Events;
using Newtonsoft.Json;

namespace EliteAPI.Events;

public readonly struct CarrierFinanceEvent : IEvent
{
[JsonProperty("timestamp")]
public DateTime Timestamp { get; init; }

[JsonProperty("event")]
public string Event { get; init; }

[JsonProperty("CarrierID")]
public string CarrierId { get; init; }

[JsonProperty("TaxRate")]
public long TaxRate { get; init; }

[JsonProperty("CarrierBalance")]
public long Balance { get; init; }

[JsonProperty("ReserveBalance")]
public long ReserveBalance { get; init; }

[JsonProperty("AvailableBalance")]
public long AvailableBalance { get; init; }

[JsonProperty("ReservePercent")]
public long ReservePercent { get; init; }
[JsonProperty("timestamp")]
public DateTime Timestamp { get; init; }

[JsonProperty("event")]
public string Event { get; init; }

[JsonProperty("CarrierID")]
public string CarrierId { get; init; }

[JsonProperty("TaxRate")]
public long TaxRate { get; init; }

[JsonProperty("CarrierBalance")]
public long Balance { get; init; }

[JsonProperty("ReserveBalance")]
public long ReserveBalance { get; init; }

[JsonProperty("AvailableBalance")]
public long AvailableBalance { get; init; }

[JsonProperty("ReservePercent")]
public long ReservePercent { get; init; }

[JsonProperty("TaxRate_pioneersupplies")]
public int TaxRatePioneerSupplies { get; init; }

[JsonProperty("TaxRate_shipyard")]
public int TaxRateShipyard { get; init; }

[JsonProperty("TaxRate_rearm")]
public int TaxRateRearm { get; init; }

[JsonProperty("TaxRate_outfitting")]
public int TaxRateOutfitting { get; init; }

[JsonProperty("TaxRate_refuel")]
public int TaxRateRefuel { get; init; }

[JsonProperty("TaxRate_repair")]
public int TaxRateRepair { get; init; }
}
Loading

0 comments on commit c832ab8

Please sign in to comment.