From 08046e5a1459f367a013816b147eb614815cf41a Mon Sep 17 00:00:00 2001 From: denglihong2007 <98096191+denglihong2007@users.noreply.github.com> Date: Thu, 1 Jan 2026 00:03:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=BD=A6=E7=AB=99?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRSim.Core/Abstractions/IPluginService.cs | 4 ++- CRSim.Core/Models/Plugin/PluginInfo.cs | 3 +++ CRSim.Core/Services/PluginService.cs | 25 +++++++++++++++---- .../DialogContents/CreateStationDialog.xaml | 3 +++ .../CreateStationDialog.xaml.cs | 16 ++++++++++-- 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/CRSim.Core/Abstractions/IPluginService.cs b/CRSim.Core/Abstractions/IPluginService.cs index 60296d6..c0417e1 100644 --- a/CRSim.Core/Abstractions/IPluginService.cs +++ b/CRSim.Core/Abstractions/IPluginService.cs @@ -1,4 +1,5 @@ -using CRSim.Core.Models.Plugin; +using CRSim.Core.Models; +using CRSim.Core.Models.Plugin; using System.Collections.ObjectModel; namespace CRSim.Core.Abstractions; @@ -28,4 +29,5 @@ public interface IPluginService Task InstallPluginLocalAsync(string filePath); Task PackPluginAsync(PluginInfo plugin, string filePath); Task LoadOnlinePluginsAsync(); + List<(string, Station)> GetStationData(); } \ No newline at end of file diff --git a/CRSim.Core/Models/Plugin/PluginInfo.cs b/CRSim.Core/Models/Plugin/PluginInfo.cs index 62c8fc8..ee2e734 100644 --- a/CRSim.Core/Models/Plugin/PluginInfo.cs +++ b/CRSim.Core/Models/Plugin/PluginInfo.cs @@ -83,4 +83,7 @@ public partial class PluginInfo : ObservableRecipient [ObservableProperty] private StyleInfo? styleInfo; + + [ObservableProperty] + private Json? data; } \ No newline at end of file diff --git a/CRSim.Core/Services/PluginService.cs b/CRSim.Core/Services/PluginService.cs index c0f1e60..a48d396 100644 --- a/CRSim.Core/Services/PluginService.cs +++ b/CRSim.Core/Services/PluginService.cs @@ -65,6 +65,7 @@ public class PluginService(INetworkService networkService, ISettingsService sett PluginFolderPath = Path.GetFullPath(pluginDir), RealIconPath = Path.Combine(Path.GetFullPath(pluginDir), "icon.png"), StyleInfo = manifest.Type == "ScreenStyle" ? JsonSerializer.Deserialize(File.ReadAllText(Path.Combine(Path.GetFullPath(pluginDir), StyleInfoFileName)),JsonContextWithCamelCase.Default.StyleInfo) : null, + Data = manifest.Type == "StationData" ? JsonSerializer.Deserialize(File.ReadAllText(Path.Combine(Path.GetFullPath(pluginDir), manifest.EntranceAssembly)), JsonContext.Default.Json) : null, }; if (info.IsUninstalling) { @@ -77,8 +78,15 @@ public class PluginService(INetworkService networkService, ISettingsService sett } IPluginService.LoadedPluginsInternal.Add(info); } + foreach (var info in IPluginService.LoadedPluginsInternal.Where(x => x.Manifest.Type == "StationData")) + { + if (info.LoadStatus != PluginLoadStatus.Disabled) + { + info.LoadStatus = PluginLoadStatus.Loaded; + } + } - foreach (var info in IPluginService.LoadedPluginsInternal) + foreach (var info in IPluginService.LoadedPluginsInternal.Where(x => x.Manifest.Type == "ScreenStyle")) { if(info.LoadStatus == PluginLoadStatus.Disabled) { @@ -88,7 +96,7 @@ public class PluginService(INetworkService networkService, ISettingsService sett var pluginDir = info.PluginFolderPath; try { - Console.WriteLine("Լز: " + manifest.Id); + Console.WriteLine("ԼزDLL: " + manifest.Id); var fullPath = Path.GetFullPath(Path.Combine(pluginDir, manifest.EntranceAssembly)); var loadContext = new PluginLoadContext(fullPath); var assembly = loadContext.LoadFromAssemblyPath(fullPath); @@ -111,11 +119,11 @@ public class PluginService(INetworkService networkService, ISettingsService sett services.AddSingleton(typeof(PluginBase), entranceObj); services.AddSingleton(entrance, entranceObj); info.LoadStatus = PluginLoadStatus.Loaded; - Console.WriteLine($"زɹ: {pluginDir} ({manifest.Version})"); + Console.WriteLine($"زDLLɹ: {pluginDir} ({manifest.Version})"); } catch (Exception ex) { - Console.WriteLine($"زʧ: {ex}"); + Console.WriteLine($"زDLLʧ: {ex}"); info.Exception = ex; info.LoadStatus = PluginLoadStatus.Error; } @@ -221,7 +229,14 @@ public class PluginService(INetworkService networkService, ISettingsService sett IPluginService.LoadedPluginsInternal.Add(info); await Task.CompletedTask; } - + public List<(string, Station)> GetStationData() + { + var result = IPluginService.LoadedPluginsInternal + .Where(p => p.Manifest.Type == "StationData" && p.Data is not null) + .SelectMany(p => p.Data.Stations.Select(s => (p.Manifest.Name, s))) + .ToList(); + return result; + } public async Task PackPluginAsync(PluginInfo plugin, string filePath) { var pluginDir = plugin.PluginFolderPath; diff --git a/CRSim/Views/DialogContents/CreateStationDialog.xaml b/CRSim/Views/DialogContents/CreateStationDialog.xaml index 25a814e..0d38f1d 100644 --- a/CRSim/Views/DialogContents/CreateStationDialog.xaml +++ b/CRSim/Views/DialogContents/CreateStationDialog.xaml @@ -11,6 +11,9 @@ + + diff --git a/CRSim/Views/DialogContents/CreateStationDialog.xaml.cs b/CRSim/Views/DialogContents/CreateStationDialog.xaml.cs index c23b7c7..a5aa66b 100644 --- a/CRSim/Views/DialogContents/CreateStationDialog.xaml.cs +++ b/CRSim/Views/DialogContents/CreateStationDialog.xaml.cs @@ -4,9 +4,16 @@ public sealed partial class CreateStationDialog : Page private readonly IDialogService _dialogService = App.GetService(); + private readonly IPluginService _pluginService = App.GetService(); + private Station? _parsedStation = null; - public Station? GeneratedStation => ToBoolean(Blank.IsChecked) ? new Station + private record StationRecord(string Name, Station Station); + + private List StationRecords { get; } + + public Station? GeneratedStation => ToBoolean(Plugin.IsChecked) ? (Station)comboBoxPlugin.SelectedValue : + ToBoolean(Blank.IsChecked) ? new Station { Name = textBoxBlank.Text, Platforms = [], @@ -23,12 +30,16 @@ public sealed partial class CreateStationDialog : Page private void Validate(object sender, object e) { - if (textBoxBlank == null) return; + if (textBoxBlank == null) return;//鴰ʼ bool isValid; if (ToBoolean(Blank.IsChecked)) { isValid = !string.IsNullOrWhiteSpace(textBoxBlank.Text); } + else if(ToBoolean(Plugin.IsChecked)) + { + isValid = comboBoxPlugin.SelectedValue is not null; + } else { isValid = _parsedStation != null; @@ -38,6 +49,7 @@ public sealed partial class CreateStationDialog : Page public CreateStationDialog(Action onValidityChanged) { + StationRecords = _pluginService.GetStationData().Select(x => new StationRecord($"{x.Item1}-{x.Item2.Name}",x.Item2)).ToList(); _onValidityChanged = onValidityChanged; InitializeComponent(); }