Skip to content

Commit

Permalink
Merge branch 'feature/2327-spansh' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkael committed Jan 1, 2025
2 parents 178e034 + 2ed2553 commit 0175cf9
Show file tree
Hide file tree
Showing 157 changed files with 1,372,532 additions and 16,437 deletions.
42 changes: 21 additions & 21 deletions BgsService/BgsFactionData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EddiDataDefinitions;
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -9,7 +10,7 @@ namespace EddiBgsService
partial class BgsService
{
/// <summary> The endpoint we will use for faction queries (using the BGS rest client) </summary>
public const string factionEndpoint = "v5/factions?";
public const string factionEndpoint = "v5/factions";

public static class FactionParameters
{
Expand Down Expand Up @@ -52,40 +53,39 @@ public static class FactionParameters

// Faction data from EliteBGS (allows search by faction name - EDSM can only search by system name).
// If a systemName is provided, we can filter factions that share a name according to whether they have a presence in a known system
[CanBeNull]
public Faction GetFactionByName(string factionName, string systemName = null)
{
if (string.IsNullOrEmpty(factionName)) { return null; }

List<KeyValuePair<string, object>> queryList = new List<KeyValuePair<string, object>>()
var queryList = new List<KeyValuePair<string, object>>()
{
new KeyValuePair<string, object>(FactionParameters.factionName, factionName)
};
List<Faction> factions = GetFactions(factionEndpoint, queryList);
var factions = GetFactions(factionEndpoint, queryList);

// If a systemName is provided, we can filter factions that share a name according to whether they have a presence in a known system
if (systemName != null && factions?.Count > 1)
{
foreach (Faction faction in factions)
{
faction.presences = faction.presences.Where(f => f.systemName == systemName)?.ToList();
}
factions = factions.Where( f =>
f.presences.Any(
p => p.systemName.Equals( systemName, StringComparison.InvariantCultureIgnoreCase ) ) )
.ToList();
}

return factions?.FirstOrDefault(f => f.name == factionName) ?? new Faction()
{
name = factionName
};
return factions?.FirstOrDefault( f =>
f.name.Equals( factionName, StringComparison.InvariantCultureIgnoreCase ) );
}

public List<Faction> GetFactions(string endpoint, List<KeyValuePair<string, object>> queryList)
{
if (queryList.Count > 0)
{
List<object> responses = GetData(bgsRestClient, endpoint, queryList);
var responses = GetData(bgsRestClient, endpoint, queryList);

if (responses?.Count > 0)
{
List<Faction> factions = ParseFactionsParallel(responses);
var factions = ParseFactionsParallel(responses);
return factions?.OrderBy(x => x.name).ToList();
}
}
Expand All @@ -95,7 +95,7 @@ public List<Faction> GetFactions(string endpoint, List<KeyValuePair<string, obje
private List<Faction> ParseFactionsParallel(List<object> responses)
{
// it is OK to allow nulls into this list; they will be handled upstream
List<Faction> factions = responses.AsParallel().Select(ParseFaction).ToList();
var factions = responses.AsParallel().Select(ParseFaction).ToList();
return factions;
}

Expand All @@ -105,19 +105,19 @@ public Faction ParseFaction(object response)
{
Logging.Debug($"Response from EliteBGS bgsRestClient endpoint {factionEndpoint} is: ", response);

IDictionary<string, object> factionJson = Deserializtion.DeserializeData(response.ToString());
Faction faction = new Faction
var factionJson = Deserializtion.DeserializeData(response.ToString());
var faction = new Faction
{
name = (string)factionJson["name"],
updatedAt = (DateTime)factionJson["updated_at"],
Government = Government.FromName((string)factionJson["government"]),
Allegiance = Superpower.FromName((string)factionJson["allegiance"])
};

foreach (object presence in (List<object>)factionJson["faction_presence"])
foreach (var presence in (List<object>)factionJson["faction_presence"])
{
IDictionary<string, object> presenceJson = (IDictionary<string, object>)presence;
FactionPresence factionPresence = new FactionPresence
var presenceJson = (IDictionary<string, object>)presence;
var factionPresence = new FactionPresence
{
systemName = JsonParsing.getString(presenceJson, "system_name"),
influence = (JsonParsing.getOptionalDecimal(presenceJson, "influence") ?? 0) * 100, // Convert from a 0-1 range to a percentage
Expand Down Expand Up @@ -154,7 +154,7 @@ public Faction ParseFaction(object response)
{
if ( obj is IDictionary<string, object> pendingState )
{
FactionTrendingState pTrendingState = new FactionTrendingState(
var pTrendingState = new FactionTrendingState(
FactionState.FromEDName(JsonParsing.getString(pendingState, "state")) ?? FactionState.None,
JsonParsing.getOptionalInt(pendingState, "trend")
);
Expand All @@ -172,7 +172,7 @@ public Faction ParseFaction(object response)
{
if ( obj is IDictionary<string, object> recoveringState )
{
FactionTrendingState rTrendingState = new FactionTrendingState(
var rTrendingState = new FactionTrendingState(
FactionState.FromEDName(JsonParsing.getString(recoveringState, "state")) ?? FactionState.None,
JsonParsing.getOptionalInt(recoveringState, "trend")
);
Expand Down
21 changes: 5 additions & 16 deletions BgsService/BgsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ public interface IBgsRestClient

public partial class BgsService : IBgsService
{
// This API only returns data for the "live" galaxy, game version 4.0 or later.
private static readonly System.Version minGameVersion = new System.Version(4, 0);
private static System.Version currentGameVersion { get; set; }

public readonly IBgsRestClient bgsRestClient;
private readonly IBgsRestClient bgsRestClient;

private const string bgsBaseUrl = "https://elitebgs.app/api/ebgs/";

Expand All @@ -45,8 +41,10 @@ public BgsService(IBgsRestClient bgsRestClient = null)
/// <summary> Specify the endpoint (e.g. EddiBgsService.Endpoint.factions) and a list of queries as KeyValuePairs </summary>
public List<object> GetData(IBgsRestClient restClient, string endpoint, List<KeyValuePair<string, object>> queries)
{
if (!(queries?.Any() ?? false)) { return null; }
if (currentGameVersion != null && currentGameVersion < minGameVersion) { return null; }
if ( ( !queries?.Any() ?? false ) || ( queries?.Any( q =>
string.IsNullOrEmpty( q.Key ) ||
string.IsNullOrEmpty( q.Value.ToString() ) ) ?? false ) )
{ return null; }

var docs = new List<object>();
var currentPage = 1;
Expand Down Expand Up @@ -80,15 +78,6 @@ public List<object> GetData(IBgsRestClient restClient, string endpoint, List<Key
return null;
}

public static void SetGameVersion(System.Version version)
{
currentGameVersion = version;
if (currentGameVersion != null && currentGameVersion < minGameVersion)
{
Logging.Warn($"Service disabled. Game version is {currentGameVersion}, service returns data for version {minGameVersion} or later.");
}
}

private PageResponse PageRequest(IBgsRestClient restClient, RestRequest request, int page)
{
request.AddOrUpdateParameter("page", page);
Expand Down
38 changes: 22 additions & 16 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,32 @@ Full details of the variables available for each noted event, and VoiceAttack in
## 4.1.0-b4
* Core
* Added `Coriolis (Beta)` export target to Ship Monitor and `coriolisbeta` plugin command.
* Added new ship type `Mandalay` and modules.
* Added and updated powerplay object definitions.
* Fixed cargo need calculations. (#2645)
* Fixed child scripts not always using the latest state variables in their contexts.
* Fixed missing `systemname` property in the `Star scanned` event.
* Fixed a null reference exception which could occur when deleting scripts.
* Simplified and centralized legacy game mode handling.
* Updated star system lookups to use Spansh APIs rather than EDSM APIs.
* Definitions
* Added new ship types `Mandalay` and `Cobra Mk 5` and modules.
* Added and updated powerplay object definitions.
* Added star property `luminosityclass`.
* Added star system property `contestingpowers`.
* Removed the `permitname` property from the `system` object (permit data is now calculated and permit names are not stored / not always known).
* Events
* `Carrier jumped` event updated to expose new Powerplay properties.
* `Holoscreen hacked` event added.
* `Jumped` event updated to expose new Powerplay properties.
* `Location` event updated to expose new Powerplay properties.
* `Power commodity fast tracked` obsolete event removed.
* `Power defected` obsolete event removed.
* `Power expansion vote cast` obsolete event removed.
* `Power preparation vote cast` obsolete event removed.
* `Power micro resources collected` event added.
* `Power micro resources delivered` event added.
* `Powerplay` event updated to remove the obsolete `votes` property (Powerplay 2.0 does not use a voting system).
* `Signal detected` event updated to include new Powerplay properties.
* `Star scanned` event updated to add missing `systemname` property.
* Speech Responder
* Events
* `Carrier jumped` event updated to expose new Powerplay properties.
* `Holoscreen hacked` event added.
* `Jumped` event updated to expose new Powerplay properties.
* `Location` event updated to expose new Powerplay properties.
* `Power commodity fast tracked` obsolete event removed.
* `Power defected` obsolete event removed.
* `Power expansion vote cast` obsolete event removed.
* `Power preparation vote cast` obsolete event removed.
* `Power micro resources collected` event added.
* `Power micro resources delivered` event added.
* `Powerplay` event updated to remove the obsolete `votes` property (Powerplay 2.0 does not use a voting system).
* `Signal detected` event updated to include new Powerplay properties.
* Scripts
* `Carrier jumped` script updated to include new Powerplay details.
* `Holoscreen hacked` event added.
Expand Down
5 changes: 1 addition & 4 deletions CompanionAppService/Endpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public abstract class Endpoint

protected JObject GetEndpoint(string endpointURL)
{
if ( CompanionAppService.unitTesting ) { return null; }
JObject newJson = null;
try
{
Expand Down Expand Up @@ -59,16 +60,12 @@ public class CompanionApiEndpointEventArgs : EventArgs

public readonly JObject fleetCarrierJson;

public readonly bool fromLegacyServer;

public CompanionApiEndpointEventArgs(string serverUrl, JObject profileJson, JObject marketJson, JObject shipyardJson, JObject fleetCarrierJson)
{
this.profileJson = profileJson;
this.marketJson = marketJson;
this.shipyardJson = shipyardJson;
this.fleetCarrierJson = fleetCarrierJson;

fromLegacyServer = serverUrl == CompanionAppService.LEGACY_SERVER;
}
}
}
12 changes: 12 additions & 0 deletions ConfigService/Configurations/EDDIConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ public class EDDIConfiguration : Config
[JsonProperty("homeSystem")]
public string HomeSystem { get; set; }

[JsonProperty( "homeSystemAddress" )]
public ulong? HomeSystemAddress { get; set; }

[JsonProperty("homeStation")]
public string HomeStation { get; set; }

[JsonProperty( "homeStationMarketID" )]
public long? HomeStationMarketID { get; set; }

[JsonProperty("destinationSystem")]
public string DestinationSystem { get; set; }

[JsonProperty( "destinationSystemAddress" )]
public ulong? DestinationSystemAddress { get; set; }

[JsonProperty("squadronName")]
public string SquadronName { get; set; }

Expand Down Expand Up @@ -71,6 +80,9 @@ public string squadronPower
[JsonProperty("squadronSystem")]
public string SquadronSystem { get; set; }

[JsonProperty( "squadronSystemAddress" )]
public ulong? SquadronSystemAddress { get; set; }

[JsonProperty("squadronFaction")]
public string SquadronFaction { get; set; }

Expand Down
Loading

0 comments on commit 0175cf9

Please sign in to comment.