work on edith

This commit is contained in:
Florian Stinglmayr 2025-07-31 19:34:16 +02:00
parent 486d24c39c
commit 387480b2cf
14 changed files with 395 additions and 10 deletions

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "EDPlayerJournal"] [submodule "EDPlayerJournal"]
path = EDPlayerJournal path = EDPlayerJournal
url = git@aror.org:florian/EDPlayerJournal url = git@aror.org:florian/EDPlayerJournal.git

@ -1 +1 @@
Subproject commit ec41c718b17a417fe04b61abee288f481466c127 Subproject commit f21bf5ea5e3116fb1ec44bb90d2917506862d66e

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59 VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1 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 EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EDPlayerJournal", "EDPlayerJournal\EDPlayerJournal\EDPlayerJournal.csproj", "{5FAB13DD-1F3D-7390-D11A-F56738487BB3}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EDPlayerJournal", "EDPlayerJournal\EDPlayerJournal\EDPlayerJournal.csproj", "{5FAB13DD-1F3D-7390-D11A-F56738487BB3}"
EndProject EndProject

View File

@ -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<Depot> depots = new();
public List<Depot> Depots => depots;
public IList<ITreeNode> Children {
get { return depots.ToList<ITreeNode>(); }
}
public object Tag {
get { return System; }
set { }
}
public string Text {
get { return ToString(); }
set { }
}
public override string ToString() {
return $" ☀ {System.Name}";
}
}

View File

@ -0,0 +1,27 @@
using Terminal.Gui.Views;
namespace Edith.Construction;
internal class ColonyBuilder : ITreeBuilder<ITreeNode> {
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<ITreeNode> GetChildren(ITreeNode forObject) {
if (forObject is Colony) {
return ((Colony)forObject).Depots.ToList<ITreeNode>();
} else if (forObject is Depot) {
return ((Depot)forObject).Resources.ToList<ITreeNode>();
}
return new List<ITreeNode>();
}
}

View File

@ -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<ITreeNode> tree;
private TileView tiles;
public Tab View => view;
private List<Colony> colonies = new();
public string Name => "Construction";
public ConstructionHelperPage() {
tiles = new TileView(2) {
Height = Dim.Fill(),
Width = Dim.Fill(),
BorderStyle = LineStyle.None,
};
tree = new TreeView<ITreeNode>() {
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);
}
}

33
src/Construction/Depot.cs Normal file
View File

@ -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<Resource> resources = new();
public List<Resource> Resources => resources;
public IList<ITreeNode> Children {
get { return resources.ToList<ITreeNode>(); }
}
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}");
}
}

View File

@ -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<ITreeNode> Children => new List<ITreeNode>();
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();
}
}

View File

@ -1,9 +1,56 @@
 using System;
using Terminal.Gui.App;
using EDPlayerJournal;
using EDPlayerJournal.Entries;
using EDPlayerJournal.CommanderContext;
namespace Edith; namespace Edith;
public class Program internal class Edith {
{ private MainWindow? window = null;
public static void Main(string[] args) { 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() {
} }
}
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();
}
}

7
src/IPage.cs Normal file
View File

@ -0,0 +1,7 @@
namespace Edith {
internal interface IPage {
Terminal.Gui.Views.Tab View { get; }
string Name { get; }
}
}

69
src/MainWindow.cs Normal file
View File

@ -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<Type> pageTypes = new() {
typeof(OverviewPage),
typeof(ConstructionHelperPage),
};
private List<IPage> 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);
}
}

30
src/OverviewPage.cs Normal file
View File

@ -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,
};
}
}
}

8
src/Program.cs Normal file
View File

@ -0,0 +1,8 @@
namespace Edith;
public class Program
{
public static void Main(string[] args) {
Edith.Instance.Run();
}
}

View File

@ -8,8 +8,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Spectre.Console" Version="0.50.0" /> <PackageReference Include="Spectre.Console" Version="0.50.1-preview.0.22" />
<PackageReference Include="Spectre.Console.Cli" Version="0.50.0" /> <PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4532" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>