Большая пачка обновлений
This commit is contained in:
+59
-20
@@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LinqToDB.Tools;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@@ -7,6 +8,7 @@ using Pf2eModel;
|
||||
using Pf2eModel.Model;
|
||||
using Pf2eModel.Model.Base;
|
||||
using Pf2eModel.Model.Enum;
|
||||
using static LinqToDB.Common.Configuration;
|
||||
|
||||
namespace Pf2eViewer;
|
||||
|
||||
@@ -31,7 +33,7 @@ public partial class MainViewForm : Form
|
||||
TypesListBox.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
public const int PerPage = 20;
|
||||
public const int PerPage = 30;
|
||||
|
||||
public int Count;
|
||||
|
||||
@@ -50,6 +52,7 @@ public partial class MainViewForm : Form
|
||||
|
||||
private void UpdateTreeView()
|
||||
{
|
||||
EntityTreeView.Nodes.Clear();
|
||||
EntityType type = (EntityType) TypesListBox.SelectedItem!;
|
||||
|
||||
Count = Context.Entities.Count(e => e.Type == type);
|
||||
@@ -63,14 +66,6 @@ public partial class MainViewForm : Form
|
||||
EntityGridView.DataSource = Context.Entities
|
||||
.Where(e => e.Type == (EntityType) TypesListBox.SelectedItem)
|
||||
.OrderBy(e => e.Id)
|
||||
.Include(e => e.Sources)
|
||||
.ThenInclude(s => s.Source)
|
||||
.Include(e => e.Aliases)
|
||||
.Include(e => e.Keywords)
|
||||
.Include(e => e.Externals)
|
||||
.ThenInclude(x => x.Target)
|
||||
.Include(e => e.Traits)
|
||||
.ThenInclude(t => t.Entity)
|
||||
.Select(e => new EntityGridRow(e))
|
||||
.Skip((Page - 1) * PerPage)
|
||||
.Take(PerPage)
|
||||
@@ -99,22 +94,18 @@ public partial class MainViewForm : Form
|
||||
{
|
||||
Page = 1;
|
||||
}
|
||||
|
||||
private void PrevPageButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Page--;
|
||||
}
|
||||
|
||||
private void NextPageButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Page++;
|
||||
}
|
||||
|
||||
private void LastPageButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Page = MaxPage;
|
||||
}
|
||||
|
||||
private void PageTextBox_KeyPress(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
|
||||
@@ -141,13 +132,42 @@ public partial class MainViewForm : Form
|
||||
|
||||
EntityGridRow data = (EntityGridRow) row.DataBoundItem;
|
||||
|
||||
string json = SerializeEntity(data.GetEntity());
|
||||
ViewEntity(data.Id);
|
||||
}
|
||||
|
||||
public void ViewEntity(int id)
|
||||
{
|
||||
EntityTreeView.Nodes.Clear();
|
||||
|
||||
Entity? entity = Context.Entities
|
||||
.Where(e => e.Id == id && e.Type == (EntityType) TypesListBox.SelectedItem!)
|
||||
.Include(e => e.Sources)
|
||||
.ThenInclude(s => s.Source)
|
||||
.Include(e => e.Aliases)
|
||||
.Include(e => e.Keywords)
|
||||
.Include(e => e.Externals)
|
||||
.ThenInclude(x => x.Target)
|
||||
.Include(e => e.Traits)
|
||||
.ThenInclude(t => t.Entity)
|
||||
.FirstOrDefault()
|
||||
;
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
DescriptionTextBox.Text = "Not found";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
string json = SerializeEntity(entity);
|
||||
|
||||
JsonToTreeview(EntityTreeView, json, "Entity");
|
||||
|
||||
DescriptionTextBox.Text = data.GetEntity().Description.Replace("\\r", "").Replace("\\n", "\\r\\n");
|
||||
DescriptionTextBox.Text = entity.Description.Replace("\\r", "").Replace("\\n", "\\r\\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public string SerializeEntity(Entity entity)
|
||||
{
|
||||
JsonSerializerSettings settings = new()
|
||||
@@ -161,21 +181,40 @@ public partial class MainViewForm : Form
|
||||
string result = JsonConvert.SerializeObject(entity, settings);
|
||||
|
||||
Type type = EntityOfTypeAttribute.Resolve(entity);
|
||||
string subResult = JsonConvert.SerializeObject(ResolveEntity(entity), settings);
|
||||
string subResult = JsonConvert.SerializeObject(ResolveSubEntity(entity), settings);
|
||||
|
||||
return result[..^1] + $",\"SubEntity\":{subResult}}}";
|
||||
}
|
||||
|
||||
public IEntity? ResolveEntity(Entity entity)
|
||||
public IEntity? ResolveSubEntity(Entity entity)
|
||||
{
|
||||
switch (entity.Type)
|
||||
{
|
||||
case EntityType.Ancestry:
|
||||
return Context.Ancestries
|
||||
.Include(a => a.AncestryBoosts)
|
||||
.FirstOrDefault(e => e.Id == entity.Id);
|
||||
}
|
||||
|
||||
return null;
|
||||
case EntityType.Background:
|
||||
return Context.Backgrounds
|
||||
.Include(b => b.BackgroundBoosts)
|
||||
.Include(b => b.BackgroundSkills)
|
||||
.ThenInclude(t => t.Training)
|
||||
.Include(b => b.BackgroundItems)
|
||||
.FirstOrDefault(e => e.Id == entity.Id);
|
||||
|
||||
case EntityType.Class:
|
||||
return Context.Classes
|
||||
.Include(c => c.ClassKeyAbilities)
|
||||
.Include(c => c.ClassTrainings)
|
||||
.ThenInclude(t => t.Training)
|
||||
.Include(c => c.ClassProgressions)
|
||||
.FirstOrDefault(c => c.Id == entity.Id);
|
||||
|
||||
default:
|
||||
Type type = EntityOfTypeAttribute.Resolve(entity);
|
||||
return (IEntity?) Context.Find(type, entity.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public static void JsonToTreeview(TreeView treeView, string jsonString, string rootName)
|
||||
|
||||
Reference in New Issue
Block a user