Codingale / EliteAPI

.NET API for Elite: Dangerous Journal | Hook in-game events to code!

Home Page:https://docs.somfic.com/project/eliteapi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EliteAPI

An Elite: Dangerous API library for .NET

Discord Codacy grade GitHub release GitHub

When playing Elite: Dangerous, many in-game events are outputted to the Journal log files. EliteAPI makes use of these files to provide live information about in-game events in a .NET environment.

Installation

EliteAPI is distributed through the NuGet package manager; the recommended way to install this library. Alternatively, the library could also be compiled to retrieve the .dll file.

.NET Platform

EliteAPI targets .NET Standard 2.0. Creating applications using the latest version of .NET Core is the most recommended. If needed, .NET Framework 4.6.1 or higher is also supported.

Installation using NuGet

EliteAPI is listed as EliteAPI on NuGet. A reference to the library can be made in a number of different ways through NuGet, here are the most common ones.

Platform Syntax
Package manager Install-Package EliteAPI
.NET CLI dotnet add package EliteAPI
Package reference <PackageReference Include="EliteAPI"/>
Paket CLI paket add EliteAPI

Getting started

Dependency Injection

EliteAPI is bundeled with Depedency Injection. It is recommended that you use a host when working with the API. EliteAPI contains an extension method AddEliteAPI() that adds all the required services to your IServiceCollection.

Below is an example of how to create a host in a .NET Core environment, and how to set up the API.

using EliteAPI;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
private static async Task Main(string[] args) {

     // Create a host that uses EliteAPI
     IHost host = Host.CreateDefaultBuilder()
          .ConfigureServices((context, service) =>
          {
               service.AddEliteAPI();
               service.AddTransient<MyAppService>(); // Example
          })
          .Build();

     // Get the EliteDangerousAPI api object
     var api = Host.Services.GetService<IEliteDangerousAPI>();
     
     // Start the api
     await api.StartAsync();
     
     // Run forever
     await Task.Delay(-1);
}

Hooking into an event

EliteAPI constantly scans the Journal log files for new in-game events. Whenever a new event is detected it is invoked in the api. There are multiple ways to hook into an event.

Through events

EliteAPI has an individual event for every event logged in the Journal files. These events can be found in the IEliteDangerousAPI.Events property. The event is automatically invoked whenever the specified action is peformed in-game.

api.Events.BountyEvent += (sender, e) =>
{
     // Triggered whenever we collect a bounty
     Console.WriteLine("Collected {0} from {1}", e.TotalReward, e.Target);

     var gear = api.Status.Gear;
};

Through attributes

In-game events can be assigned to specific methods using the EliteDangerousEvent attribute. The method must be public, in a public class that derives from EliteDangerousEventModule and must also be added through the EliteAPI configuration. This registeres this class as a service to your IServiceCollection.

service.AddEliteAPI(config => {
     config.AddEventModule<CombatModule>();
});

Which in-game event triggers the method is based on the method's first parameter type.

public class CombatModule : EliteDangerousEventModule {

     public CombatModule(IServiceProvider services) : base(services) {  }

     [EliteDangerousEvent]
     public async Task NewBounty(BountyEvent e) {
          // Triggered whenever we collect a bounty
          Console.WriteLine("Collected {0} from {1}", e.TotalReward, e.Target);

          var gear = EliteAPI.Status.Gear;
     }
}

Configuration

EliteAPI can be configured using configuration files.

[EliteAPI]
Journalpath = "W:\\"

Visual Studio Code

If you run through vs code, you must change the parameter Console from internal to external in launch.json. From.

"console": "internalConsole"

To.

"console": "externalTerminal"

License

EliteAPI is distributed under the MIT license.

About

.NET API for Elite: Dangerous Journal | Hook in-game events to code!

https://docs.somfic.com/project/eliteapi

License:MIT License


Languages

Language:C# 91.4%Language:Vue 6.1%Language:JavaScript 1.6%Language:SCSS 0.8%Language:HTML 0.1%