Skip to content

Commit

Permalink
Update to The War Within
Browse files Browse the repository at this point in the history
  • Loading branch information
BAndysc committed Aug 23, 2024
1 parent 00763dd commit 69c7b41
Show file tree
Hide file tree
Showing 30 changed files with 1,121 additions and 99 deletions.
2 changes: 1 addition & 1 deletion WDE.DatabaseEditors/Data/Structs/DatabaseColumnJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public bool Equals(ColumnFullName x, ColumnFullName y)

public int GetHashCode(ColumnFullName obj)
{
return HashCode.Combine(obj.ForeignTable, obj.ColumnName);
return HashCode.Combine(obj.ForeignTable?.ToLowerInvariant(), obj.ColumnName.ToLowerInvariant());
}
}

Expand Down
8 changes: 8 additions & 0 deletions WDE.DatabaseEditors/Loaders/DatabaseTableDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ await messageBoxService.ShowDialog(new MessageBoxFactory<bool>()

var conditionsResult = new ConditionsOnlyDatabaseSource(definition.Condition.SourceGroupColumn?.Name.ColumnName, definition.Condition.SourceEntryColumn?.ColumnName, definition.Condition.SourceIdColumn?.ColumnName);
result = conditionsResult;
var fakeColumns = new List<ColumnFullName>();
if (definition.Condition.SourceGroupColumn != null)
fakeColumns.Add(definition.Condition.SourceGroupColumn.Name);
if (definition.Condition.SourceEntryColumn != null)
fakeColumns.Add(definition.Condition.SourceEntryColumn.Value);
if (definition.Condition.SourceIdColumn != null)
fakeColumns.Add(definition.Condition.SourceIdColumn.Value);
columns = fakeColumns;

foreach (var key in keys)
{
Expand Down
137 changes: 137 additions & 0 deletions WDE.DatabaseEditors/Services/GenericTableQueryParserProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ private bool TryBuildKey(DatabaseTableDefinitionJson definition, DatabaseForeign

public async Task<bool> ParseDelete(DeleteQuery deleteQuery, IQueryParsingContext context)
{
if (deleteQuery.TableName == DatabaseTable.WorldTable("conditions"))
return ParseDeleteConditions(deleteQuery, context);

var defi = tableDefinitionProvider.GetDefinitionByTableName(deleteQuery.TableName);
if (defi == null)
return false;
Expand Down Expand Up @@ -135,8 +138,75 @@ public async Task<bool> ParseDelete(DeleteQuery deleteQuery, IQueryParsingContex
return true;
}

private bool ParseDeleteConditions(DeleteQuery deleteConditions, IQueryParsingContext context)
{
foreach (var where in deleteConditions.Where.Conditions)
{
var sourceTypeColumn = where.Columns.IndexOf("SourceTypeOrReferenceId");
if (sourceTypeColumn == -1)
return false;

if (!(where.Values[sourceTypeColumn] is long sourceType))
return false;

var defi = tableDefinitionProvider.Definitions.FirstOrDefault(d =>
d.IsOnlyConditionsTable == OnlyConditionMode.IgnoreTableCompletely &&
d.Condition?.SourceType == sourceType);

if (defi == null || defi.PrimaryKey.Count != 1)
return false;

var sourceEntryColumn = where.Columns.IndexOf("SourceEntry");
var sourceGroupColumn = where.Columns.IndexOf("SourceGroup");
var sourceIdColumn = where.Columns.IndexOf("SourceId");

DatabaseKey? key = null;

if (defi.Condition!.SourceEntryColumn.HasValue && defi.PrimaryKey[0] == defi.Condition!.SourceEntryColumn.Value)
{
if (sourceEntryColumn == -1)
return false;

if (where.Values[sourceEntryColumn] is not long sourceEntry)
return false;

key = new DatabaseKey(sourceEntry);
}
else if (defi.Condition!.SourceGroupColumn != null && defi.PrimaryKey[0] == defi.Condition!.SourceGroupColumn.Name)
{
if (sourceGroupColumn == -1)
return false;

if (where.Values[sourceGroupColumn] is not long sourceGroup)
return false;

key = new DatabaseKey(sourceGroup);
}
else if (defi.Condition!.SourceIdColumn.HasValue && defi.PrimaryKey[0] == defi.Condition!.SourceIdColumn.Value)
{
if (sourceIdColumn == -1)
return false;

if (where.Values[sourceIdColumn] is not long sourceId)
return false;

key = new DatabaseKey(sourceId);
}

if (!key.HasValue)
return false;

context.ProduceItem(new DatabaseTableSolutionItem(key.Value, false, true, new DatabaseTable(defi.DataDatabaseType, defi.TableName), false));
}

return true;
}

public async Task<bool> ParseInsert(InsertQuery query, IQueryParsingContext context)
{
if (query.TableName == DatabaseTable.WorldTable("conditions"))
return ParseInsertConditions(query, context);

var defi = tableDefinitionProvider.GetDefinitionByTableName(query.TableName);
if (defi == null)
return false;
Expand Down Expand Up @@ -180,6 +250,73 @@ public async Task<bool> ParseInsert(InsertQuery query, IQueryParsingContext cont
return true;
}

private bool ParseInsertConditions(InsertQuery query, IQueryParsingContext context)
{
var sourceTypeColumn = query.Columns.IndexOf("SourceTypeOrReferenceId");
if (sourceTypeColumn == -1)
return false;

var sourceEntryColumn = query.Columns.IndexOf("SourceEntry");
var sourceGroupColumn = query.Columns.IndexOf("SourceGroup");
var sourceIdColumn = query.Columns.IndexOf("SourceId");

if (sourceEntryColumn == -1 && sourceGroupColumn == -1 && sourceIdColumn == -1)
return false;

foreach (var insert in query.Inserts)
{
if (!(insert[sourceTypeColumn] is long sourceType))
return false;

var defi = tableDefinitionProvider.Definitions.FirstOrDefault(d =>
d.IsOnlyConditionsTable == OnlyConditionMode.IgnoreTableCompletely &&
d.Condition?.SourceType == sourceType);

if (defi == null || defi.PrimaryKey.Count != 1)
return false;

DatabaseKey? key = null;

if (defi.Condition!.SourceEntryColumn.HasValue && defi.PrimaryKey[0] == defi.Condition!.SourceEntryColumn.Value)
{
if (sourceEntryColumn == -1)
return false;

if (insert[sourceEntryColumn] is not long sourceEntry)
return false;

key = new DatabaseKey(sourceEntry);
}
else if (defi.Condition!.SourceGroupColumn != null && defi.PrimaryKey[0] == defi.Condition!.SourceGroupColumn.Name)
{
if (sourceGroupColumn == -1)
return false;

if (insert[sourceGroupColumn] is not long sourceGroup)
return false;

key = new DatabaseKey(sourceGroup);
}
else if (defi.Condition!.SourceIdColumn.HasValue && defi.PrimaryKey[0] == defi.Condition!.SourceIdColumn.Value)
{
if (sourceIdColumn == -1)
return false;

if (insert[sourceIdColumn] is not long sourceId)
return false;

key = new DatabaseKey(sourceId);
}

if (!key.HasValue)
return false;

context.ProduceItem(new DatabaseTableSolutionItem(key.Value, false, true, new DatabaseTable(defi.DataDatabaseType, defi.TableName), false));
}

return true;
}

public async Task<bool> ParseUpdate(UpdateQuery query, IQueryParsingContext context)
{
var defi = tableDefinitionProvider.GetDefinitionByTableName(query.TableName);
Expand Down
17 changes: 17 additions & 0 deletions WDE.PacketViewer.Avalonia/Views/StoryTellerDocumentView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:WDE.PacketViewer.ViewModels;assembly=WDE.PacketViewer"
xmlns:avaloniaEdit="https://github.com/avaloniaui/avaloniaedit"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:DataType="viewModels:StoryTellerDocumentViewModel"
x:Class="WDE.PacketViewer.Avalonia.Views.StoryTellerDocumentView">
<avaloniaEdit:TextEditor Document="{CompiledBinding Document, Converter={x:Static NativeTextDocumentConverter.Instance}}"
BorderThickness="0"
Name="Editor"
PointerMoved="Editor_OnPointerMoved"
ContextRequested="Editor_OnContextRequested"
AvalonEditExtra.SyntaxExtension="story"
ShowLineNumbers="True" FontFamily="Consolas,Menlo,Courier,Courier New" />
</UserControl>
Loading

0 comments on commit 69c7b41

Please sign in to comment.