Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit 5be65ef

Browse files
committed
get RemainingJumpsInRoute from NavRoute.json
1 parent fa561e4 commit 5be65ef

File tree

8 files changed

+87
-24
lines changed

8 files changed

+87
-24
lines changed

Elite/Buttons/Hyperspace.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ private async Task HandleDisplay()
171171

172172
if (_primaryImage != null)
173173
{
174-
if (!bitmapImageIsGif && settings.Function != "SUPERCRUISE" && EliteData.StarSystem != EliteData.FsdTargetName && EliteData.RemainingJumpsInRoute > 0 && textHtmlColor != "#ff00ff")
174+
var remainingJumpsInRoute = EliteData.RouteList?.Count ?? 0;
175+
176+
if (!bitmapImageIsGif && settings.Function != "SUPERCRUISE" && /*EliteData.StarSystem != EliteData.FsdTargetName &&*/ remainingJumpsInRoute > 0 && textHtmlColor != "#ff00ff")
175177
{
176178
try
177179
{
@@ -189,19 +191,19 @@ private async Task HandleDisplay()
189191
var testFont = new Font(drawFont.Name, adjustedSize, drawFont.Style);
190192

191193
var adjustedSizeNew =
192-
graphics.MeasureString(EliteData.RemainingJumpsInRoute.ToString(),
194+
graphics.MeasureString(remainingJumpsInRoute.ToString(),
193195
testFont);
194196

195197
if (fontContainerHeight >= adjustedSizeNew.Height)
196198
{
197199
var stringSize =
198-
graphics.MeasureString(EliteData.RemainingJumpsInRoute.ToString(),
200+
graphics.MeasureString(remainingJumpsInRoute.ToString(),
199201
testFont);
200202

201203
var x = (width - stringSize.Width) / 2.0;
202204
var y = 28.0 * (width / 256.0);
203205

204-
graphics.DrawString(EliteData.RemainingJumpsInRoute.ToString(), testFont,
206+
graphics.DrawString(remainingJumpsInRoute.ToString(), testFont,
205207
textBrush, (float) x, (float) y);
206208

207209
testFont.Dispose();

Elite/Buttons/Route.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ private async Task HandleDisplay()
8383
var textBrush = _primaryBrush;
8484
var textHtmlColor = settings.PrimaryColor;
8585

86-
var isDisabled = EliteData.RemainingJumpsInRoute == 0;
86+
var remainingJumpsInRoute = EliteData.RouteList?.Count ?? 0;
87+
88+
89+
var isDisabled = remainingJumpsInRoute == 0;
8790

8891
if (isDisabled)
8992
{
@@ -97,7 +100,7 @@ private async Task HandleDisplay()
97100

98101
if (_primaryImage != null)
99102
{
100-
if (!bitmapImageIsGif && EliteData.StarSystem != EliteData.FsdTargetName && EliteData.RemainingJumpsInRoute > 0 && textHtmlColor != "#ff00ff")
103+
if (!bitmapImageIsGif && /*EliteData.StarSystem != EliteData.FsdTargetName &&*/ remainingJumpsInRoute > 0 && textHtmlColor != "#ff00ff")
101104
{
102105
try
103106
{
@@ -115,19 +118,19 @@ private async Task HandleDisplay()
115118
var testFont = new Font(drawFont.Name, adjustedSize, drawFont.Style);
116119

117120
var adjustedSizeNew =
118-
graphics.MeasureString(EliteData.RemainingJumpsInRoute.ToString(),
121+
graphics.MeasureString(remainingJumpsInRoute.ToString(),
119122
testFont);
120123

121124
if (fontContainerHeight >= adjustedSizeNew.Height)
122125
{
123126
var stringSize =
124-
graphics.MeasureString(EliteData.RemainingJumpsInRoute.ToString(),
127+
graphics.MeasureString(remainingJumpsInRoute.ToString(),
125128
testFont);
126129

127130
var x = (width - stringSize.Width) / 2.0;
128131
var y = 28.0 * (width / 256.0);
129132

130-
graphics.DrawString(EliteData.RemainingJumpsInRoute.ToString(), testFont,
133+
graphics.DrawString(remainingJumpsInRoute.ToString(), testFont,
131134
textBrush, (float) x, (float) y);
132135

133136
testFont.Dispose();
@@ -188,9 +191,10 @@ public override void KeyPressed(KeyPayload payload)
188191

189192
StreamDeckCommon.ForceStop = false;
190193

191-
var isDisabled = EliteData.RemainingJumpsInRoute == 0;
192-
193-
194+
var remainingJumpsInRoute = EliteData.RouteList?.Count ?? 0;
195+
196+
var isDisabled = remainingJumpsInRoute == 0;
197+
194198
if (!isDisabled)
195199
{
196200
StreamDeckCommon.SendKeypress(Program.Binding[BindingType.Ship].TargetNextRouteSystem);

Elite/EliteData.cs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using EliteJournalReader;
45
using EliteJournalReader.Events;
@@ -11,10 +12,14 @@ public class EliteData
1112

1213
public static bool UnderAttack = false;
1314
public static DateTime LastUnderAttackEvent = DateTime.Now;
14-
public static string FsdTargetName { get; set; }
15-
public static int RemainingJumpsInRoute { get; set; }
16-
public static string StarClass { get; set; }
15+
//public static string FsdTargetName { get; set; }
16+
//public static int RemainingJumpsInRoute { get; set; }
17+
//public static string StarClass { get; set; }
1718
public static string StarSystem { get; set; }
19+
20+
public static List<RouteItem> RouteList = new List<RouteItem>();
21+
22+
1823
public static int LimpetCount { get; set; }
1924

2025
public class Status
@@ -95,6 +100,26 @@ public class Status
95100

96101
public static Status StatusData = new Status();
97102

103+
public static void HandleNavRouteEvents(object sender, NavRouteEvent.NavRouteEventArgs info)
104+
{
105+
if (info?.Route == null || info.Route.Length < 2)
106+
{
107+
RouteList = new List<RouteItem>();
108+
}
109+
else
110+
{
111+
RouteList = info.Route.Select(
112+
x => new RouteItem
113+
{
114+
StarClass = x.StarClass,
115+
StarPos = x.StarPos,
116+
StarSystem = x.StarSystem,
117+
SystemAddress = x.SystemAddress,
118+
}).Skip(1).ToList();
119+
120+
}
121+
}
122+
98123
public static void HandleCargoEvents(object sender, CargoEvent.CargoEventArgs evt)
99124
{
100125
if (evt?.Inventory != null && evt?.Vessel == "Ship")
@@ -251,13 +276,13 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e)
251276

252277
case "FSDTarget":
253278
//When written: when selecting a star system to jump to
254-
var fsdTargetInfo = (FSDTargetEvent.FSDTargetEventArgs)e;
279+
//var fsdTargetInfo = (FSDTargetEvent.FSDTargetEventArgs)e;
255280

256-
EliteData.FsdTargetName = fsdTargetInfo.Name;
281+
//EliteData.FsdTargetName = fsdTargetInfo.Name;
257282

258-
EliteData.RemainingJumpsInRoute = fsdTargetInfo.RemainingJumpsInRoute;
283+
//EliteData.RemainingJumpsInRoute = fsdTargetInfo.RemainingJumpsInRoute;
259284

260-
EliteData.StarClass = fsdTargetInfo.StarClass;
285+
//EliteData.StarClass = fsdTargetInfo.StarClass;
261286

262287
break;
263288

@@ -276,7 +301,7 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e)
276301

277302
case "Cargo":
278303

279-
var cargoInfo = (CargoEvent.CargoEventArgs)e;
304+
//var cargoInfo = (CargoEvent.CargoEventArgs)e;
280305
/*
281306
if (cargoInfo.Vessel == "Ship")
282307
{
@@ -296,12 +321,18 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e)
296321

297322
case "Died":
298323

299-
var diedInfo = (DiedEvent.DiedEventArgs)e;
324+
//var diedInfo = (DiedEvent.DiedEventArgs)e;
300325

301326
EliteData.LimpetCount = 0;
302327

303328
break;
304329

330+
case "NavRouteClear":
331+
332+
EliteData.RouteList = new List<RouteItem>();
333+
334+
break;
335+
305336
}
306337

307338
}

Elite/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class Program
8787
public static KeyBindingWatcher KeyBindingWatcherStartPreset;
8888
public static StatusWatcher StatusWatcher;
8989
public static CargoWatcher CargoWatcher;
90+
public static NavRouteWatcher NavRouteWatcher;
9091
public static JournalWatcher JournalWatcher;
9192

9293
public static Dictionary<BindingType, UserBindings> Binding = new Dictionary<BindingType, UserBindings>();
@@ -505,6 +506,11 @@ static void Main(string[] args)
505506

506507
CargoWatcher.StartWatching();
507508

509+
NavRouteWatcher = new NavRouteWatcher(journalPath);
510+
511+
NavRouteWatcher.NavRouteUpdated += EliteData.HandleNavRouteEvents;
512+
513+
NavRouteWatcher.StartWatching();
508514
}
509515
catch (Exception ex)
510516
{

Elite/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("2.7.1.0")]
35-
[assembly: AssemblyFileVersion("2.7.1.0")]
34+
[assembly: AssemblyVersion("2.7.2.0")]
35+
[assembly: AssemblyFileVersion("2.7.2.0")]

Elite/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
"Name": "Elite Dangerous",
193193
"Icon": "Images/pluginIcon",
194194
"URL": "https://github.com/mhwlng/streamdeck-elite",
195-
"Version": "2.7.1",
195+
"Version": "2.7.2",
196196
"CodePath": "com.mhwlng.elite",
197197
"Category": "Elite Dangerous",
198198
"CategoryIcon": "Images/categoryIcon",

EliteJournalReader/EliteJournalReader.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<Reference Include="System.Xml" />
102102
</ItemGroup>
103103
<ItemGroup>
104+
<Compile Include="Events\NavRouteClear.cs" />
104105
<Compile Include="Events\ShipLockerEvent.cs" />
105106
<Compile Include="ShipLockerWatcher.cs">
106107
<SubType>Component</SubType>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Newtonsoft.Json.Linq;
7+
8+
namespace EliteJournalReader.Events
9+
{
10+
//When written: When the current plotted nav route is cleared
11+
public class NavRouteClearEvent : JournalEvent<NavRouteClearEvent.NavRouteClearEventArgs>
12+
{
13+
public NavRouteClearEvent() : base("NavRouteClear") { }
14+
15+
public class NavRouteClearEventArgs : JournalEventArgs
16+
{
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)