Немного работы
This commit is contained in:
@@ -18,7 +18,7 @@ internal class AonprdLoader(AonprdImporter importer)
|
|||||||
|
|
||||||
foreach (KeyValuePair<string, JToken?> kvp in indexJson)
|
foreach (KeyValuePair<string, JToken?> kvp in indexJson)
|
||||||
{
|
{
|
||||||
string file = kvp.Key.ToString();
|
string file = kvp.Key;
|
||||||
JArray items = (JArray)kvp.Value!;
|
JArray items = (JArray)kvp.Value!;
|
||||||
|
|
||||||
foreach (JToken item in items)
|
foreach (JToken item in items)
|
||||||
|
|||||||
+2
@@ -19,6 +19,8 @@ internal abstract partial class AbstractProcessor(AonprdProcessorInput input)
|
|||||||
{
|
{
|
||||||
protected DatabaseHelper Helper = DatabaseHelper.Instance;
|
protected DatabaseHelper Helper = DatabaseHelper.Instance;
|
||||||
|
|
||||||
|
protected StringHelper StringHelper = StringHelper.Instance;
|
||||||
|
|
||||||
public readonly Pf2eDbContext Context = DatabaseHelper.DbContext;
|
public readonly Pf2eDbContext Context = DatabaseHelper.DbContext;
|
||||||
|
|
||||||
public readonly AonprdProcessorInput Input = input;
|
public readonly AonprdProcessorInput Input = input;
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors;
|
||||||
|
|
||||||
|
internal partial class StringHelper
|
||||||
|
{
|
||||||
|
private StringHelper() { }
|
||||||
|
|
||||||
|
public static StringHelper Instance { get; } = new();
|
||||||
|
|
||||||
|
[GeneratedRegex(@"^\[.*?\]\(.*?\)\s+(.*)$")]
|
||||||
|
private static partial Regex SourceSuffixRegex();
|
||||||
|
}
|
||||||
+1
-6
@@ -1,9 +1,4 @@
|
|||||||
using System;
|
using Pf2eModel.Model.Structure;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Pf2eModel.Model.Structure;
|
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Subclasses;
|
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Subclasses;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ using Pf2eModel.Model.Enum;
|
|||||||
namespace Pf2eModel.Migrations
|
namespace Pf2eModel.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(Pf2eDbContext))]
|
[DbContext(typeof(Pf2eDbContext))]
|
||||||
[Migration("20250425111349_1")]
|
[Migration("20250425164659_1")]
|
||||||
partial class _1
|
partial class _1
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -141,7 +141,7 @@ public class LocaleString : ICollection<LocaleItem>
|
|||||||
|
|
||||||
foreach (KeyValuePair<string, JToken?> item in json)
|
foreach (KeyValuePair<string, JToken?> item in json)
|
||||||
{
|
{
|
||||||
result[item.Key] = item.ToString();
|
result[item.Key] = item.Value?.ToString() ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using Pf2eModel.Model.Structure.ClassRelation;
|
|||||||
namespace Pf2eModel.Model.Structure;
|
namespace Pf2eModel.Model.Structure;
|
||||||
|
|
||||||
[EntityOfType(EntityType.Class)]
|
[EntityOfType(EntityType.Class)]
|
||||||
public partial class Class : IEntity
|
public class Class : IEntity
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[Column(Order = 1)]
|
[Column(Order = 1)]
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
using System.ComponentModel;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using Pf2eModel;
|
using Pf2eModel;
|
||||||
using Pf2eModel.Model;
|
using Pf2eModel.Model;
|
||||||
using Pf2eModel.Model.Base;
|
using Pf2eModel.Model.Base;
|
||||||
using Pf2eModel.Model.Common.I18n;
|
using Pf2eModel.Model.Common.I18n;
|
||||||
using Pf2eModel.Model.Structure;
|
using Pf2eModel.Model.Structure;
|
||||||
|
|
||||||
namespace Pf2eViewer;
|
namespace Pf2eViewer.Converters;
|
||||||
|
|
||||||
internal class EntityConverter : JsonConverter
|
internal class EntityConverter : JsonConverter
|
||||||
{
|
{
|
||||||
@@ -38,12 +40,12 @@ internal class EntityConverter : JsonConverter
|
|||||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
Dictionary<string, object?> dictionary = DictionarySerialization(value!);
|
Dictionary<string, object?> dictionary = DictionarySerialization(value!);
|
||||||
/*
|
|
||||||
if (value.GetType() != typeof(Entity))
|
if (value.GetType() != typeof(Entity))
|
||||||
{
|
{
|
||||||
dictionary.Remove("Entity");
|
dictionary.Remove("Entity");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
case Entity entity:
|
case Entity entity:
|
||||||
@@ -55,6 +57,9 @@ internal class EntityConverter : JsonConverter
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serializer.Serialize(writer, dictionary);
|
||||||
|
|
||||||
|
/*
|
||||||
writer.WriteStartObject();
|
writer.WriteStartObject();
|
||||||
|
|
||||||
foreach (KeyValuePair<string, object> keyValuePair in dictionary)
|
foreach (KeyValuePair<string, object> keyValuePair in dictionary)
|
||||||
@@ -65,6 +70,7 @@ internal class EntityConverter : JsonConverter
|
|||||||
}
|
}
|
||||||
|
|
||||||
writer.WriteEndObject();
|
writer.WriteEndObject();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessTrait(Dictionary<string, object?> dictionary, Trait trait)
|
private void ProcessTrait(Dictionary<string, object?> dictionary, Trait trait)
|
||||||
@@ -83,6 +89,11 @@ internal class EntityConverter : JsonConverter
|
|||||||
dictionary.Remove("Description");
|
dictionary.Remove("Description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ProcessSubclass(Dictionary<string, object?> dictionary, Subclass entity)
|
||||||
|
{
|
||||||
|
dictionary.Remove("Group");
|
||||||
|
}
|
||||||
|
|
||||||
public override bool CanRead => false;
|
public override bool CanRead => false;
|
||||||
|
|
||||||
public override object? ReadJson(
|
public override object? ReadJson(
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Pf2eModel.Model.Common.I18n;
|
||||||
|
|
||||||
|
namespace Pf2eViewer.Converters;
|
||||||
|
|
||||||
|
public class LocaleStringConverter : JsonConverter
|
||||||
|
{
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
return objectType == typeof(LocaleString);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
JObject result = new();
|
||||||
|
|
||||||
|
LocaleString str = (LocaleString)value!;
|
||||||
|
|
||||||
|
foreach (LocaleItem item in str)
|
||||||
|
{
|
||||||
|
result.Add(item.Locale.GetTypeString(), item.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.WriteTo(writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanRead => false;
|
||||||
|
|
||||||
|
public override object? ReadJson(
|
||||||
|
JsonReader reader,
|
||||||
|
Type objectType,
|
||||||
|
object? existingValue,
|
||||||
|
JsonSerializer serializer
|
||||||
|
)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException(
|
||||||
|
"Unnecessary because CanRead is false. The type will skip the converter."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
Generated
+17
-9
@@ -40,7 +40,7 @@ partial class MainViewForm
|
|||||||
PrevPageButton = new Button();
|
PrevPageButton = new Button();
|
||||||
FirstPageButton = new Button();
|
FirstPageButton = new Button();
|
||||||
ResultSplitContainer = new SplitContainer();
|
ResultSplitContainer = new SplitContainer();
|
||||||
EntityTreeView = new TreeView();
|
JsonWebView = new Microsoft.Web.WebView2.WinForms.WebView2();
|
||||||
DescriptionTextBox = new TextBox();
|
DescriptionTextBox = new TextBox();
|
||||||
((System.ComponentModel.ISupportInitialize) RootSplitContainer).BeginInit();
|
((System.ComponentModel.ISupportInitialize) RootSplitContainer).BeginInit();
|
||||||
RootSplitContainer.Panel1.SuspendLayout();
|
RootSplitContainer.Panel1.SuspendLayout();
|
||||||
@@ -56,6 +56,7 @@ partial class MainViewForm
|
|||||||
ResultSplitContainer.Panel1.SuspendLayout();
|
ResultSplitContainer.Panel1.SuspendLayout();
|
||||||
ResultSplitContainer.Panel2.SuspendLayout();
|
ResultSplitContainer.Panel2.SuspendLayout();
|
||||||
ResultSplitContainer.SuspendLayout();
|
ResultSplitContainer.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize) JsonWebView).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// RootSplitContainer
|
// RootSplitContainer
|
||||||
@@ -212,7 +213,7 @@ partial class MainViewForm
|
|||||||
//
|
//
|
||||||
// ResultSplitContainer.Panel1
|
// ResultSplitContainer.Panel1
|
||||||
//
|
//
|
||||||
ResultSplitContainer.Panel1.Controls.Add(EntityTreeView);
|
ResultSplitContainer.Panel1.Controls.Add(JsonWebView);
|
||||||
//
|
//
|
||||||
// ResultSplitContainer.Panel2
|
// ResultSplitContainer.Panel2
|
||||||
//
|
//
|
||||||
@@ -221,13 +222,19 @@ partial class MainViewForm
|
|||||||
ResultSplitContainer.SplitterDistance = 467;
|
ResultSplitContainer.SplitterDistance = 467;
|
||||||
ResultSplitContainer.TabIndex = 1;
|
ResultSplitContainer.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// EntityTreeView
|
// JsonWebView
|
||||||
//
|
//
|
||||||
EntityTreeView.Dock = DockStyle.Fill;
|
JsonWebView.AllowExternalDrop = true;
|
||||||
EntityTreeView.Location = new Point(0, 0);
|
JsonWebView.CreationProperties = null;
|
||||||
EntityTreeView.Name = "EntityTreeView";
|
JsonWebView.DefaultBackgroundColor = Color.White;
|
||||||
EntityTreeView.Size = new Size(467, 688);
|
JsonWebView.Dock = DockStyle.Fill;
|
||||||
EntityTreeView.TabIndex = 0;
|
JsonWebView.Location = new Point(0, 0);
|
||||||
|
JsonWebView.Name = "JsonWebView";
|
||||||
|
JsonWebView.Size = new Size(467, 688);
|
||||||
|
JsonWebView.TabIndex = 0;
|
||||||
|
JsonWebView.Visible = false;
|
||||||
|
JsonWebView.ZoomFactor = 1D;
|
||||||
|
JsonWebView.CoreWebView2InitializationCompleted += JsonWebView_CoreWebView2InitializationCompleted;
|
||||||
//
|
//
|
||||||
// DescriptionTextBox
|
// DescriptionTextBox
|
||||||
//
|
//
|
||||||
@@ -264,6 +271,7 @@ partial class MainViewForm
|
|||||||
ResultSplitContainer.Panel2.PerformLayout();
|
ResultSplitContainer.Panel2.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize) ResultSplitContainer).EndInit();
|
((System.ComponentModel.ISupportInitialize) ResultSplitContainer).EndInit();
|
||||||
ResultSplitContainer.ResumeLayout(false);
|
ResultSplitContainer.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize) JsonWebView).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +281,6 @@ partial class MainViewForm
|
|||||||
private SplitContainer InnerSplitContainer;
|
private SplitContainer InnerSplitContainer;
|
||||||
private ListBox TypesListBox;
|
private ListBox TypesListBox;
|
||||||
private DataGridView EntityGridView;
|
private DataGridView EntityGridView;
|
||||||
private TreeView EntityTreeView;
|
|
||||||
private SplitContainer ResultSplitContainer;
|
private SplitContainer ResultSplitContainer;
|
||||||
private TextBox DescriptionTextBox;
|
private TextBox DescriptionTextBox;
|
||||||
private Panel PaginationPagel;
|
private Panel PaginationPagel;
|
||||||
@@ -283,4 +290,5 @@ partial class MainViewForm
|
|||||||
private Button FirstPageButton;
|
private Button FirstPageButton;
|
||||||
private TextBox PageTextBox;
|
private TextBox PageTextBox;
|
||||||
private TextBox PaginationLabel;
|
private TextBox PaginationLabel;
|
||||||
|
private Microsoft.Web.WebView2.WinForms.WebView2 JsonWebView;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using Pf2eModel.Model;
|
|||||||
using Pf2eModel.Model.Base;
|
using Pf2eModel.Model.Base;
|
||||||
using Pf2eModel.Model.Common.I18n;
|
using Pf2eModel.Model.Common.I18n;
|
||||||
using Pf2eModel.Model.Enum;
|
using Pf2eModel.Model.Enum;
|
||||||
|
using Pf2eViewer.Converters;
|
||||||
|
|
||||||
namespace Pf2eViewer;
|
namespace Pf2eViewer;
|
||||||
|
|
||||||
@@ -15,12 +16,22 @@ public partial class MainViewForm : Form
|
|||||||
{
|
{
|
||||||
public Pf2eDbContext Context = new();
|
public Pf2eDbContext Context = new();
|
||||||
|
|
||||||
|
public string JsonViewerHtml = string.Empty;
|
||||||
|
|
||||||
|
private DarkModeCS dm = null;
|
||||||
|
|
||||||
public MainViewForm()
|
public MainViewForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
dm = new DarkModeCS(this) { ColorMode = DarkModeCS.DisplayMode.SystemDefault };
|
||||||
|
|
||||||
Reset();
|
Reset();
|
||||||
|
|
||||||
EntityGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
EntityGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
|
||||||
|
using StreamReader reader = new("Resources/json-viewer.html");
|
||||||
|
JsonViewerHtml = reader.ReadToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
@@ -50,7 +61,7 @@ public partial class MainViewForm : Form
|
|||||||
|
|
||||||
private void UpdateTreeView()
|
private void UpdateTreeView()
|
||||||
{
|
{
|
||||||
EntityTreeView.Nodes.Clear();
|
// EntityTreeView.Nodes.Clear();
|
||||||
EntityType type = (EntityType)TypesListBox.SelectedItem!;
|
EntityType type = (EntityType)TypesListBox.SelectedItem!;
|
||||||
|
|
||||||
Count = Context.Entities.Count(e => e.Type == type);
|
Count = Context.Entities.Count(e => e.Type == type);
|
||||||
@@ -142,7 +153,7 @@ public partial class MainViewForm : Form
|
|||||||
|
|
||||||
public void ViewEntity(int id)
|
public void ViewEntity(int id)
|
||||||
{
|
{
|
||||||
EntityTreeView.Nodes.Clear();
|
// EntityTreeView.Nodes.Clear();
|
||||||
|
|
||||||
Entity? entity = Context
|
Entity? entity = Context
|
||||||
.Entities.Where(e => e.Id == id && e.Type == (EntityType)TypesListBox.SelectedItem!)
|
.Entities.Where(e => e.Id == id && e.Type == (EntityType)TypesListBox.SelectedItem!)
|
||||||
@@ -163,19 +174,47 @@ public partial class MainViewForm : Form
|
|||||||
|
|
||||||
string json = SerializeEntity(entity);
|
string json = SerializeEntity(entity);
|
||||||
|
|
||||||
JsonToTreeview(EntityTreeView, json, "Entity");
|
// JsonToTreeview(EntityTreeView, json, "Entity");
|
||||||
|
|
||||||
|
RenderJson(json);
|
||||||
|
|
||||||
DescriptionTextBox.Text = entity.Description.Replace("\\r", "").Replace("\\n", "\\r\\n");
|
DescriptionTextBox.Text = entity.Description.Replace("\\r", "").Replace("\\n", "\\r\\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RenderJson(string json)
|
||||||
|
{
|
||||||
|
if (JsonWebView.CoreWebView2 == null)
|
||||||
|
{
|
||||||
|
JsonWebView.EnsureCoreWebView2Async();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string html = JsonViewerHtml.Replace("{JSON}", json);
|
||||||
|
JsonWebView.CoreWebView2.NavigateToString(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void JsonWebView_CoreWebView2InitializationCompleted(
|
||||||
|
object sender,
|
||||||
|
Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e
|
||||||
|
)
|
||||||
|
{
|
||||||
|
JsonWebView.Visible = true;
|
||||||
|
DataGridViewRow row = EntityGridView.SelectedRows[0];
|
||||||
|
|
||||||
|
EntityGridRow data = (EntityGridRow)row.DataBoundItem;
|
||||||
|
|
||||||
|
ViewEntity(data.Id);
|
||||||
|
}
|
||||||
|
|
||||||
public string SerializeEntity(Entity entity)
|
public string SerializeEntity(Entity entity)
|
||||||
{
|
{
|
||||||
JsonSerializerSettings settings = new()
|
JsonSerializerSettings settings = new()
|
||||||
{
|
{
|
||||||
Converters =
|
Converters =
|
||||||
[
|
[
|
||||||
new EntityConverter(),
|
|
||||||
new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy() },
|
new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy() },
|
||||||
|
new EntityConverter(),
|
||||||
|
new LocaleStringConverter(),
|
||||||
],
|
],
|
||||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3179.45" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -15,4 +16,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Properties\" />
|
<Folder Include="Properties\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="Resources\json-viewer.html">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<title>JSON Viewer</title>
|
||||||
|
<script src="https://pfau-software.de/json-viewer/dist/iife/index.js"></script>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
background: black;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<andypf-json-viewer indent="4"
|
||||||
|
expanded="true"
|
||||||
|
theme="classic-dark"
|
||||||
|
expand-icon-type="square"
|
||||||
|
show-data-types="false"
|
||||||
|
show-toolbar="false"
|
||||||
|
show-copy="false"
|
||||||
|
show-size="true">
|
||||||
|
{JSON}
|
||||||
|
</andypf-json-viewer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user