Немного работы
This commit is contained in:
@@ -18,7 +18,7 @@ internal class AonprdLoader(AonprdImporter importer)
|
||||
|
||||
foreach (KeyValuePair<string, JToken?> kvp in indexJson)
|
||||
{
|
||||
string file = kvp.Key.ToString();
|
||||
string file = kvp.Key;
|
||||
JArray items = (JArray)kvp.Value!;
|
||||
|
||||
foreach (JToken item in items)
|
||||
|
||||
+2
@@ -19,6 +19,8 @@ internal abstract partial class AbstractProcessor(AonprdProcessorInput input)
|
||||
{
|
||||
protected DatabaseHelper Helper = DatabaseHelper.Instance;
|
||||
|
||||
protected StringHelper StringHelper = StringHelper.Instance;
|
||||
|
||||
public readonly Pf2eDbContext Context = DatabaseHelper.DbContext;
|
||||
|
||||
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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Pf2eModel.Model.Structure;
|
||||
using Pf2eModel.Model.Structure;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Subclasses;
|
||||
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ using Pf2eModel.Model.Enum;
|
||||
namespace Pf2eModel.Migrations
|
||||
{
|
||||
[DbContext(typeof(Pf2eDbContext))]
|
||||
[Migration("20250425111349_1")]
|
||||
[Migration("20250425164659_1")]
|
||||
partial class _1
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -141,7 +141,7 @@ public class LocaleString : ICollection<LocaleItem>
|
||||
|
||||
foreach (KeyValuePair<string, JToken?> item in json)
|
||||
{
|
||||
result[item.Key] = item.ToString();
|
||||
result[item.Key] = item.Value?.ToString() ?? "";
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -7,7 +7,7 @@ using Pf2eModel.Model.Structure.ClassRelation;
|
||||
namespace Pf2eModel.Model.Structure;
|
||||
|
||||
[EntityOfType(EntityType.Class)]
|
||||
public partial class Class : IEntity
|
||||
public class Class : IEntity
|
||||
{
|
||||
[Key]
|
||||
[Column(Order = 1)]
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eModel;
|
||||
using Pf2eModel.Model;
|
||||
using Pf2eModel.Model.Base;
|
||||
using Pf2eModel.Model.Common.I18n;
|
||||
using Pf2eModel.Model.Structure;
|
||||
|
||||
namespace Pf2eViewer;
|
||||
namespace Pf2eViewer.Converters;
|
||||
|
||||
internal class EntityConverter : JsonConverter
|
||||
{
|
||||
@@ -38,12 +40,12 @@ internal class EntityConverter : JsonConverter
|
||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
Dictionary<string, object?> dictionary = DictionarySerialization(value!);
|
||||
/*
|
||||
|
||||
if (value.GetType() != typeof(Entity))
|
||||
{
|
||||
dictionary.Remove("Entity");
|
||||
}
|
||||
*/
|
||||
|
||||
switch (value)
|
||||
{
|
||||
case Entity entity:
|
||||
@@ -55,6 +57,9 @@ internal class EntityConverter : JsonConverter
|
||||
break;
|
||||
}
|
||||
|
||||
serializer.Serialize(writer, dictionary);
|
||||
|
||||
/*
|
||||
writer.WriteStartObject();
|
||||
|
||||
foreach (KeyValuePair<string, object> keyValuePair in dictionary)
|
||||
@@ -65,6 +70,7 @@ internal class EntityConverter : JsonConverter
|
||||
}
|
||||
|
||||
writer.WriteEndObject();
|
||||
*/
|
||||
}
|
||||
|
||||
private void ProcessTrait(Dictionary<string, object?> dictionary, Trait trait)
|
||||
@@ -83,6 +89,11 @@ internal class EntityConverter : JsonConverter
|
||||
dictionary.Remove("Description");
|
||||
}
|
||||
|
||||
private void ProcessSubclass(Dictionary<string, object?> dictionary, Subclass entity)
|
||||
{
|
||||
dictionary.Remove("Group");
|
||||
}
|
||||
|
||||
public override bool CanRead => false;
|
||||
|
||||
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();
|
||||
FirstPageButton = new Button();
|
||||
ResultSplitContainer = new SplitContainer();
|
||||
EntityTreeView = new TreeView();
|
||||
JsonWebView = new Microsoft.Web.WebView2.WinForms.WebView2();
|
||||
DescriptionTextBox = new TextBox();
|
||||
((System.ComponentModel.ISupportInitialize) RootSplitContainer).BeginInit();
|
||||
RootSplitContainer.Panel1.SuspendLayout();
|
||||
@@ -56,6 +56,7 @@ partial class MainViewForm
|
||||
ResultSplitContainer.Panel1.SuspendLayout();
|
||||
ResultSplitContainer.Panel2.SuspendLayout();
|
||||
ResultSplitContainer.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize) JsonWebView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// RootSplitContainer
|
||||
@@ -212,7 +213,7 @@ partial class MainViewForm
|
||||
//
|
||||
// ResultSplitContainer.Panel1
|
||||
//
|
||||
ResultSplitContainer.Panel1.Controls.Add(EntityTreeView);
|
||||
ResultSplitContainer.Panel1.Controls.Add(JsonWebView);
|
||||
//
|
||||
// ResultSplitContainer.Panel2
|
||||
//
|
||||
@@ -221,13 +222,19 @@ partial class MainViewForm
|
||||
ResultSplitContainer.SplitterDistance = 467;
|
||||
ResultSplitContainer.TabIndex = 1;
|
||||
//
|
||||
// EntityTreeView
|
||||
// JsonWebView
|
||||
//
|
||||
EntityTreeView.Dock = DockStyle.Fill;
|
||||
EntityTreeView.Location = new Point(0, 0);
|
||||
EntityTreeView.Name = "EntityTreeView";
|
||||
EntityTreeView.Size = new Size(467, 688);
|
||||
EntityTreeView.TabIndex = 0;
|
||||
JsonWebView.AllowExternalDrop = true;
|
||||
JsonWebView.CreationProperties = null;
|
||||
JsonWebView.DefaultBackgroundColor = Color.White;
|
||||
JsonWebView.Dock = DockStyle.Fill;
|
||||
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
|
||||
//
|
||||
@@ -264,6 +271,7 @@ partial class MainViewForm
|
||||
ResultSplitContainer.Panel2.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize) ResultSplitContainer).EndInit();
|
||||
ResultSplitContainer.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize) JsonWebView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@@ -273,7 +281,6 @@ partial class MainViewForm
|
||||
private SplitContainer InnerSplitContainer;
|
||||
private ListBox TypesListBox;
|
||||
private DataGridView EntityGridView;
|
||||
private TreeView EntityTreeView;
|
||||
private SplitContainer ResultSplitContainer;
|
||||
private TextBox DescriptionTextBox;
|
||||
private Panel PaginationPagel;
|
||||
@@ -283,4 +290,5 @@ partial class MainViewForm
|
||||
private Button FirstPageButton;
|
||||
private TextBox PageTextBox;
|
||||
private TextBox PaginationLabel;
|
||||
private Microsoft.Web.WebView2.WinForms.WebView2 JsonWebView;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Pf2eModel.Model;
|
||||
using Pf2eModel.Model.Base;
|
||||
using Pf2eModel.Model.Common.I18n;
|
||||
using Pf2eModel.Model.Enum;
|
||||
using Pf2eViewer.Converters;
|
||||
|
||||
namespace Pf2eViewer;
|
||||
|
||||
@@ -15,12 +16,22 @@ public partial class MainViewForm : Form
|
||||
{
|
||||
public Pf2eDbContext Context = new();
|
||||
|
||||
public string JsonViewerHtml = string.Empty;
|
||||
|
||||
private DarkModeCS dm = null;
|
||||
|
||||
public MainViewForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
dm = new DarkModeCS(this) { ColorMode = DarkModeCS.DisplayMode.SystemDefault };
|
||||
|
||||
Reset();
|
||||
|
||||
EntityGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
|
||||
using StreamReader reader = new("Resources/json-viewer.html");
|
||||
JsonViewerHtml = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
@@ -50,7 +61,7 @@ public partial class MainViewForm : Form
|
||||
|
||||
private void UpdateTreeView()
|
||||
{
|
||||
EntityTreeView.Nodes.Clear();
|
||||
// EntityTreeView.Nodes.Clear();
|
||||
EntityType type = (EntityType)TypesListBox.SelectedItem!;
|
||||
|
||||
Count = Context.Entities.Count(e => e.Type == type);
|
||||
@@ -142,7 +153,7 @@ public partial class MainViewForm : Form
|
||||
|
||||
public void ViewEntity(int id)
|
||||
{
|
||||
EntityTreeView.Nodes.Clear();
|
||||
// EntityTreeView.Nodes.Clear();
|
||||
|
||||
Entity? entity = Context
|
||||
.Entities.Where(e => e.Id == id && e.Type == (EntityType)TypesListBox.SelectedItem!)
|
||||
@@ -163,19 +174,47 @@ public partial class MainViewForm : Form
|
||||
|
||||
string json = SerializeEntity(entity);
|
||||
|
||||
JsonToTreeview(EntityTreeView, json, "Entity");
|
||||
// JsonToTreeview(EntityTreeView, json, "Entity");
|
||||
|
||||
RenderJson(json);
|
||||
|
||||
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)
|
||||
{
|
||||
JsonSerializerSettings settings = new()
|
||||
{
|
||||
Converters =
|
||||
[
|
||||
new EntityConverter(),
|
||||
new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy() },
|
||||
new EntityConverter(),
|
||||
new LocaleStringConverter(),
|
||||
],
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3179.45" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -15,4 +16,9 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="Resources\json-viewer.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</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