From 387480b2cfad10eb12317799ea7f8349616b2da3 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Thu, 31 Jul 2025 19:34:16 +0200 Subject: [PATCH] work on edith --- .gitmodules | 2 +- EDPlayerJournal | 2 +- edith.sln | 2 +- src/Construction/Colony.cs | 31 ++++++++ src/Construction/ColonyBuilder.cs | 27 +++++++ src/Construction/ConstructionHelperPage.cs | 90 ++++++++++++++++++++++ src/Construction/Depot.cs | 33 ++++++++ src/Construction/Resource.cs | 43 +++++++++++ src/Edith.cs | 57 ++++++++++++-- src/IPage.cs | 7 ++ src/MainWindow.cs | 69 +++++++++++++++++ src/OverviewPage.cs | 30 ++++++++ src/Program.cs | 8 ++ src/edith.csproj | 4 +- 14 files changed, 395 insertions(+), 10 deletions(-) create mode 100644 src/Construction/Colony.cs create mode 100644 src/Construction/ColonyBuilder.cs create mode 100644 src/Construction/ConstructionHelperPage.cs create mode 100644 src/Construction/Depot.cs create mode 100644 src/Construction/Resource.cs create mode 100644 src/IPage.cs create mode 100644 src/MainWindow.cs create mode 100644 src/OverviewPage.cs create mode 100644 src/Program.cs diff --git a/.gitmodules b/.gitmodules index 98c476e..e92d8d4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "EDPlayerJournal"] path = EDPlayerJournal - url = git@aror.org:florian/EDPlayerJournal + url = git@aror.org:florian/EDPlayerJournal.git diff --git a/EDPlayerJournal b/EDPlayerJournal index ec41c71..f21bf5e 160000 --- a/EDPlayerJournal +++ b/EDPlayerJournal @@ -1 +1 @@ -Subproject commit ec41c718b17a417fe04b61abee288f481466c127 +Subproject commit f21bf5ea5e3116fb1ec44bb90d2917506862d66e diff --git a/edith.sln b/edith.sln index 27180a2..ed63a64 100644 --- a/edith.sln +++ b/edith.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "edith", "src\edith.csproj", "{50890DE0-B2B9-CDA8-C696-480FAC830AC9}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Edith", "src\Edith.csproj", "{50890DE0-B2B9-CDA8-C696-480FAC830AC9}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EDPlayerJournal", "EDPlayerJournal\EDPlayerJournal\EDPlayerJournal.csproj", "{5FAB13DD-1F3D-7390-D11A-F56738487BB3}" EndProject diff --git a/src/Construction/Colony.cs b/src/Construction/Colony.cs new file mode 100644 index 0000000..0a3cbb3 --- /dev/null +++ b/src/Construction/Colony.cs @@ -0,0 +1,31 @@ +using Terminal.Gui.Views; +using EDPlayerJournal; + +namespace Edith.Construction; + +internal class Colony : ITreeNode { + public StarSystem System { get; set; } = new(); + + private List depots = new(); + + public List Depots => depots; + + public IList Children { + get { return depots.ToList(); } + } + + public object Tag { + get { return System; } + set { } + } + + public string Text { + get { return ToString(); } + set { } + } + + public override string ToString() { + return $" ☀ {System.Name}"; + } +} + diff --git a/src/Construction/ColonyBuilder.cs b/src/Construction/ColonyBuilder.cs new file mode 100644 index 0000000..8423afa --- /dev/null +++ b/src/Construction/ColonyBuilder.cs @@ -0,0 +1,27 @@ +using Terminal.Gui.Views; + +namespace Edith.Construction; + +internal class ColonyBuilder : ITreeBuilder { + public bool SupportsCanExpand => true; + + public bool CanExpand(ITreeNode toExpand) { + if (toExpand is Colony) { + return ((Colony)toExpand).Depots.Count > 0; + } else if (toExpand is Depot) { + return ((Depot)toExpand).Resources.Count > 0; + } + + return false; + } + + public IEnumerable GetChildren(ITreeNode forObject) { + if (forObject is Colony) { + return ((Colony)forObject).Depots.ToList(); + } else if (forObject is Depot) { + return ((Depot)forObject).Resources.ToList(); + } + + return new List(); + } +} diff --git a/src/Construction/ConstructionHelperPage.cs b/src/Construction/ConstructionHelperPage.cs new file mode 100644 index 0000000..0836873 --- /dev/null +++ b/src/Construction/ConstructionHelperPage.cs @@ -0,0 +1,90 @@ +using Edith; +using Terminal.Gui.Views; +using Terminal.Gui.ViewBase; +using Terminal.Gui.Drawing; +using EDPlayerJournal.Entries; + +namespace Edith.Construction; + +internal class ConstructionHelperPage : IPage { + private Tab view; + private TreeView tree; + private TileView tiles; + + public Tab View => view; + + private List colonies = new(); + + public string Name => "Construction"; + + public ConstructionHelperPage() { + tiles = new TileView(2) { + Height = Dim.Fill(), + Width = Dim.Fill(), + BorderStyle = LineStyle.None, + }; + + tree = new TreeView() { + Height = Dim.Fill(), + Width = Dim.Fill(), + TreeBuilder = new ColonyBuilder(), + }; + + tiles.Tiles.ElementAt(0).ContentView.Add(tree); + + view = new Tab() { + DisplayText = "Construction", + View = tiles, + }; + + if (Edith.Instance.Watcher != null) { + Edith.Instance.Watcher.NewJournalEntry += Watcher_NewJournalEntry; + } + } + + private void UpdateData(ColonisationConstructionDepotEntry e) { + var system = Edith.Instance.Commander.System; + var station = Edith.Instance.Commander.Station; + + if (system == null || station == null) { + return; + } + + Colony? colony = colonies.FirstOrDefault(x => x.System.Name == system.Name, null); + if (colony == null) { + colony = new() { System = system }; + colonies.Add(colony); + tree.AddObject(colony); + } + + Depot? depot = colony.Depots.FirstOrDefault(x => x.Station.Name == station.Name, null); + if (depot == null) { + depot = new() { Station = station, Progress = e.ConstructionProgress }; + colony.Depots.Add(depot); + } + + foreach (var resource in e.ResourcesRequired) { + Resource? r = depot.Resources.FirstOrDefault(x => x.ConstructionResource.Name == resource.Name, null); + if (r == null) { + r = new() { ConstructionResource = resource }; + depot.Resources.Add(r); + } else { + r.ConstructionResource = resource; + tree.RefreshObject(r, false); + } + } + } + + private void Watcher_NewJournalEntry(Entry entry) { + if (!entry.Is(Events.ColonisationConstructionDepot)) { + return; + } + + ColonisationConstructionDepotEntry? e = entry as ColonisationConstructionDepotEntry; + if (e == null) { + return; + } + + UpdateData(e); + } +} diff --git a/src/Construction/Depot.cs b/src/Construction/Depot.cs new file mode 100644 index 0000000..2043ee3 --- /dev/null +++ b/src/Construction/Depot.cs @@ -0,0 +1,33 @@ +using EDPlayerJournal; +using Terminal.Gui.Views; + +namespace Edith.Construction; + +internal class Depot : ITreeNode { + public Station Station { get; set; } = new(); + + public double Progress { get; set; } = 0.0; + + private List resources = new(); + + public List Resources => resources; + + public IList Children { + get { return resources.ToList(); } + } + + public object Tag { + get { return Station; } + set { } + } + + public string Text { + get { return ToString(); } + set { } + } + + public override string ToString() { + string percent = (Progress * 100.0).ToString("00.0"); + return String.Format($" ⚓ {percent}% {Station.Name}"); + } +} diff --git a/src/Construction/Resource.cs b/src/Construction/Resource.cs new file mode 100644 index 0000000..abb4bd8 --- /dev/null +++ b/src/Construction/Resource.cs @@ -0,0 +1,43 @@ +using EDPlayerJournal.Entries; +using System; +using System.Text; +using Terminal.Gui.Views; + +namespace Edith.Construction; + +internal class Resource : ITreeNode { + public ConstructionResource ConstructionResource { get; set; } = new(); + + public IList Children => new List(); + + public object Tag { + get { return ConstructionResource; } + set { } + } + + public string Text { + get { return ToString(); } + set { } + } + + public override string ToString() { + StringBuilder builder = new(); + + if (ConstructionResource.ProvidedAmount >= ConstructionResource.RequiredAmount) { + builder.Append(" ✓ "); + } else if (ConstructionResource.ProvidedAmount > 0) { + builder.Append(" ⛭ "); + } else { + builder.Append(" ␀ "); + } + + ulong remaining = ConstructionResource.RequiredAmount - + ConstructionResource.ProvidedAmount; + + builder.AppendFormat("{0,5}", remaining); + builder.Append(": "); + builder.Append(ConstructionResource.NameLocalised); + + return builder.ToString(); + } +} diff --git a/src/Edith.cs b/src/Edith.cs index ce940da..df3d884 100644 --- a/src/Edith.cs +++ b/src/Edith.cs @@ -1,9 +1,56 @@ - +using System; +using Terminal.Gui.App; +using EDPlayerJournal; +using EDPlayerJournal.Entries; +using EDPlayerJournal.CommanderContext; + namespace Edith; -public class Program -{ - public static void Main(string[] args) { +internal class Edith { + private MainWindow? window = null; + public MainWindow? Window => window; + private PlayerJournal? journal = null; + public PlayerJournal? Journal => journal; + + private JournalStream? watcher = null; + public JournalStream? Watcher => watcher; + + private CommanderContext commander = new(); + public CommanderContext Commander => commander; + + private static Edith instance = new(); + public static Edith Instance => instance; + + private Edith() { } -} \ No newline at end of file + + private void SetupJournal() { + journal = new(); + watcher = new(journal); + + watcher.NewJournalEntry += Watcher_NewJournalEntry; + } + + private void Watcher_NewJournalEntry(Entry entry) { + try { + commander.Update(entry); + } catch (Exception) { + } + } + + public void Run() { + try { + SetupJournal(); + } catch (Exception e) { + Console.WriteLine("fatal error watching journal: " + e); + return; + } + + window = new MainWindow(); + + Application.Init(); + Application.Run(window); + window.Dispose(); + } +} diff --git a/src/IPage.cs b/src/IPage.cs new file mode 100644 index 0000000..cae90f6 --- /dev/null +++ b/src/IPage.cs @@ -0,0 +1,7 @@ +namespace Edith { + internal interface IPage { + Terminal.Gui.Views.Tab View { get; } + + string Name { get; } + } +} diff --git a/src/MainWindow.cs b/src/MainWindow.cs new file mode 100644 index 0000000..2c0dd1b --- /dev/null +++ b/src/MainWindow.cs @@ -0,0 +1,69 @@ +using Terminal.Gui.ViewBase; +using Terminal.Gui.Views; +using Terminal.Gui.Drawing; +using Terminal.Gui.Input; +using Terminal.Gui.Drivers; + +using Edith.Construction; + +namespace Edith; + +internal class MainWindow : Window { + private TabView contentView; + private FrameView commandView; + private TextField command; + + private List pageTypes = new() { + typeof(OverviewPage), + typeof(ConstructionHelperPage), + }; + + private List pages = new(); + + public MainWindow() { + Title = "Elite: Dangerous Intelligent Terminal Helper (EDITH)"; + BorderStyle = LineStyle.None; + + commandView = new FrameView() { + Title = "Command", + //BorderStyle = LineStyle.None, + Height = 3, + Width = Dim.Fill(), + Y = Pos.Bottom(this) - 3, + }; + + command = new TextField() { + Caption = "> _", + Width = Dim.Fill() + }; + commandView.Add(command); + Add(commandView); + + contentView = new TabView() { + Title = "Elite: Dangerous Intelligent Terminal Helper (EDITH)", + BorderStyle = LineStyle.Single, + Height = Dim.Fill() - command.Height, + Width = Dim.Fill() + }; + Add(contentView); + + foreach (Type pageType in pageTypes) { + var page = Activator.CreateInstance(pageType) as IPage; + if (page != null) { + contentView.AddTab(page.View, false); + pages.Add(page); + } + } + } + + public void ShowPage(string name) { + int page = pages + .IndexOf(x => string.Compare(x.Name, name, StringComparison.InvariantCultureIgnoreCase) == 0) + ; + if (page < 0) { + return; + } + + contentView.SwitchTabBy(page); + } +} diff --git a/src/OverviewPage.cs b/src/OverviewPage.cs new file mode 100644 index 0000000..6948bde --- /dev/null +++ b/src/OverviewPage.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Terminal.Gui.ViewBase; +using Terminal.Gui.Views; +using Terminal.Gui.Drawing; + +namespace Edith { + internal class OverviewPage : IPage { + private Tab overview; + + public Tab View => overview; + + public string Name => "Overview"; + + public OverviewPage() { + var tiles = new TileView(2) { + Height = Dim.Fill(), + Width = Dim.Fill(), + }; + + overview = new Tab() { + DisplayText = "Overview", + View = tiles, + }; + } + } +} diff --git a/src/Program.cs b/src/Program.cs new file mode 100644 index 0000000..437db10 --- /dev/null +++ b/src/Program.cs @@ -0,0 +1,8 @@ +namespace Edith; + +public class Program +{ + public static void Main(string[] args) { + Edith.Instance.Run(); + } +} \ No newline at end of file diff --git a/src/edith.csproj b/src/edith.csproj index d73c007..b0887d0 100644 --- a/src/edith.csproj +++ b/src/edith.csproj @@ -8,8 +8,8 @@ - - + +