Skip to content

Commit

Permalink
Add deduplicator and ore helper QOL
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Dec 10, 2024
1 parent 5f808a1 commit 366724c
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 18 deletions.
18 changes: 18 additions & 0 deletions cmangos-designer/Helpers/Converter.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
Expand Down Expand Up @@ -64,5 +75,12 @@
<TextBox x:Name="textBoxTcParserToCmangosEntry" Grid.Column="3" Grid.Row="8" Grid.RowSpan="1" PlaceholderText="Input go entry here" AcceptsReturn="True" TextWrapping="Wrap" Margin="5"/>
<TextBox x:Name="textBoxTcParserToCmangosNumber" Grid.Column="3" Grid.Row="9" Grid.RowSpan="1" PlaceholderText="Input starting number here" AcceptsReturn="True" TextWrapping="Wrap" Margin="5"/>
<Button x:Name="buttonConvertTcParserToCmangos" Grid.Column="3" Grid.Row="10" Grid.RowSpan="2" Click="buttonConvertTcParserToCmangos_Click">Convert to clipboard</Button>

<TextBlock x:Name="textBlockDeduplicator" Grid.Column="0" Grid.Row="12">Deduplicator</TextBlock>
<TextBox x:Name="textBoxDeduplicator" Grid.Column="0" Grid.Row="13" Grid.RowSpan="4" PlaceholderText="Input deduplication sql here" AcceptsReturn="True" TextWrapping="Wrap" Margin="5"/>
<ComboBox x:Name="comboBoxDeduplicator" Header="Table" ItemsSource="{x:Bind DeduplicatorBinding, Mode=OneWay}"
PlaceholderText="Pick a table" Grid.Column="0" Grid.Row="17" Grid.RowSpan="5" Grid.ColumnSpan="5" SelectionChanged="comboBoxDeduplicate_SelectionChanged"/>
<CheckBox x:Name="checkBoxDeduplicator" Grid.Column="0" Grid.Row="19">Parameter</CheckBox>
<Button x:Name="buttonConvertDeduplicator" Grid.Column="0" Grid.Row="20" Grid.RowSpan="2" Click="buttonDeduplicate_Click">Deduplicate to clipboard</Button>
</Grid>
</Page>
46 changes: 46 additions & 0 deletions cmangos-designer/Helpers/Converter.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public sealed partial class Converter : Page
public ObservableCollection<string> TCToCmangosConverterBinding { get; set; } = new ObservableCollection<string>();
public ObservableCollection<string> VmangosToCmangosConverterBinding { get; set; } = new ObservableCollection<string>();
public ObservableCollection<string> TcParserToCmangosConverterBinding { get; set; } = new ObservableCollection<string>();
public ObservableCollection<string> DeduplicatorBinding { get; set; } = new ObservableCollection<string>();

private Timer timer;

Expand All @@ -59,6 +60,9 @@ public Converter()
TcParserToCmangosConverterBinding.Add("creature");
TcParserToCmangosConverterBinding.Add("gameobject");

DeduplicatorBinding.Add("creature");
DeduplicatorBinding.Add("gameobject");

sniffConverterComboBox.SelectedIndex = 0;

timer = null;
Expand Down Expand Up @@ -658,9 +662,51 @@ private async void buttonConvertTcParserToCmangos_Click(object sender, RoutedEve
Clipboard.SetContent(dataPackage);
}

private void buttonDeduplicate_Click(object sender, RoutedEventArgs e)
{
string[] lines = null;
lines = textBoxDeduplicator.Text.Split(new char[] { '\r' }); // why the fuck textbox in winui 3 uses \r line separator is beyond me

string output = "";

List<(float position_x, float position_y, float position_z)> gos = new();

int i = 0;
foreach (var line in lines)
{
var lineSplit = line.Split(',');
if (lineSplit.Count() < 10)
continue;

float x = float.Parse(lineSplit[4], CultureInfo.InvariantCulture);
float y = float.Parse(lineSplit[5], CultureInfo.InvariantCulture);
float z = float.Parse(lineSplit[6], CultureInfo.InvariantCulture);

if (gos.Any(p => p.position_x == x && p.position_y == y && p.position_z == z))
continue;

gos.Add((x,y,z));

lineSplit[0] = "(@GGUID+" + i;
++i;

output += string.Join(',', lineSplit) + '\n';
}

DataPackage dataPackage = new DataPackage();
dataPackage.RequestedOperation = DataPackageOperation.Copy;
dataPackage.SetText(output);
Clipboard.SetContent(dataPackage);
}

private void comboBoxTcParserToCmangos_SelectionChanged(object sender, SelectionChangedEventArgs e)
{

}

private void comboBoxDeduplicate_SelectionChanged(object sender, SelectionChangedEventArgs e)
{

}
}
}
90 changes: 72 additions & 18 deletions cmangos-designer/Helpers/OreHelper.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using static System.Net.Mime.MediaTypeNames;
using Windows.ApplicationModel.DataTransfer;
using Microsoft.Extensions.Logging;
using Windows.UI;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand Down Expand Up @@ -127,7 +128,30 @@ private async void buttonPickFile_Click(object sender, RoutedEventArgs e)
StorageFile file = await fileOpenPicker.PickSingleFileAsync();

if (file != null)
{
textBoxChosenFile.Text = file.Path;
await ChangeColorIfHasData(buttonCopyToClipboard0, textBoxEntries0.Text, textBoxNumber0.Text);
await ChangeColorIfHasData(buttonCopyToClipboard1, textBoxEntries1.Text, textBoxNumber1.Text);
await ChangeColorIfHasData(buttonCopyToClipboard2, textBoxEntries2.Text, textBoxNumber2.Text);
await ChangeColorIfHasData(buttonCopyToClipboard3, textBoxEntries3.Text, textBoxNumber3.Text);
await ChangeColorIfHasData(buttonCopyToClipboard4, textBoxEntries4.Text, textBoxNumber4.Text);
await ChangeColorIfHasData(buttonCopyToClipboard5, textBoxEntries5.Text, textBoxNumber5.Text);
await ChangeColorIfHasData(buttonCopyToClipboard6, textBoxEntries6.Text, textBoxNumber6.Text);
await ChangeColorIfHasData(buttonCopyToClipboard7, textBoxEntries7.Text, textBoxNumber7.Text);
await ChangeColorIfHasData(buttonCopyToClipboard8, textBoxEntries8.Text, textBoxNumber8.Text);
await ChangeColorIfHasData(buttonCopyToClipboard9, textBoxEntries9.Text, textBoxNumber9.Text);
await ChangeColorIfHasData(buttonCopyToClipboard10, textBoxEntries10.Text, textBoxNumber10.Text);
await ChangeColorIfHasData(buttonCopyToClipboard11, textBoxEntries11.Text, textBoxNumber11.Text);
await ChangeColorIfHasData(buttonCopyToClipboard12, textBoxEntries12.Text, textBoxNumber12.Text);
await ChangeColorIfHasData(buttonCopyToClipboard13, textBoxEntries13.Text, textBoxNumber13.Text);
await ChangeColorIfHasData(buttonCopyToClipboard14, textBoxEntries14.Text, textBoxNumber14.Text);
await ChangeColorIfHasData(buttonCopyToClipboard15, textBoxEntries15.Text, textBoxNumber15.Text);
await ChangeColorIfHasData(buttonCopyToClipboard16, textBoxEntries16.Text, textBoxNumber16.Text);
await ChangeColorIfHasData(buttonCopyToClipboard17, textBoxEntries17.Text, textBoxNumber17.Text);
await ChangeColorIfHasData(buttonCopyToClipboard18, textBoxEntries18.Text, textBoxNumber18.Text);
await ChangeColorIfHasData(buttonCopyToClipboard19, textBoxEntries19.Text, textBoxNumber19.Text);
await ChangeColorIfHasData(buttonCopyToClipboard20, textBoxEntries20.Text, textBoxNumber20.Text);
}
}

private async Task showWrongDataFilledDialog(string message)
Expand Down Expand Up @@ -259,23 +283,53 @@ private async void buttonCopyToClipboard20_Click(object sender, RoutedEventArgs
}

private async void processButtonClick(string entriesText, string indexText)
{
string output = await ProcessData(entriesText, indexText, true);

DataPackage dataPackage = new DataPackage();
dataPackage.RequestedOperation = DataPackageOperation.Copy;
dataPackage.SetText(output);
Clipboard.SetContent(dataPackage);

saveFile();
}

private async Task ChangeColorIfHasData(Button button, string entriesText, string indexText)
{
if (await HasData(entriesText, indexText))
button.Background = new SolidColorBrush(Color.FromArgb(255, 79, 121, 66));
else
button.Background = new SolidColorBrush(Color.FromArgb(255, 136, 8, 8));
}

private async Task<bool> HasData(string entriesText, string indexText)
{
var output = await ProcessData(entriesText, indexText, false);
if (output == null)
return false;
return output.Length > 2;
}

private async Task<string?> ProcessData(string entriesText, string indexText, bool errors)
{
string output = "";
string[] lines = null;
bool success;

if (!System.IO.File.Exists(textBoxChosenFile.Text))
{
await showWrongDataFilledDialog("File does not exist");
return;
if (errors)
await showWrongDataFilledDialog("File does not exist");
return null;
}

int mapId = 0;
success = int.TryParse(textBoxMapId.Text, out mapId);
if (!success)
{
await showWrongDataFilledDialog("Couldnt parse mapId");
return;
if (errors)
await showWrongDataFilledDialog("Couldnt parse mapId");
return null;
}

string text = System.IO.File.ReadAllText(textBoxChosenFile.Text);
Expand All @@ -289,8 +343,9 @@ private async void processButtonClick(string entriesText, string indexText)
success = int.TryParse(entryText, out int entry);
if (!success)
{
await showWrongDataFilledDialog("Entries are wrongly formatted");
return;
if (errors)
await showWrongDataFilledDialog("Entries are wrongly formatted");
return null;
}
entries.Add(entry);
}
Expand All @@ -299,8 +354,9 @@ private async void processButtonClick(string entriesText, string indexText)
success = int.TryParse(indexText, out startingIndex);
if (!success)
{
await showWrongDataFilledDialog("Could not parse starting index");
return;
if (errors)
await showWrongDataFilledDialog("Could not parse starting index");
return null;
}
var gameObjects = new List<GameObjectParser>();
foreach (var line in lines)
Expand Down Expand Up @@ -342,10 +398,13 @@ private async void processButtonClick(string entriesText, string indexText)
}

bool isPhaseMask = false;
if (checkBoxFirstLine.IsChecked == true)
output = "INSERT INTO gameobject(guid, id, map, spawnMask" + (isPhaseMask ? ", phaseMask" : "") + ", position_x, position_y, position_z, orientation, rotation0, rotation1, rotation2, rotation3, spawntimesecsmin, spawntimesecsmax) VALUES\n";
else
output = ",\n";
if (gameObjects.Count() > 0)
{
if (checkBoxFirstLine.IsChecked == true)
output = "INSERT INTO gameobject(guid, id, map, spawnMask" + (isPhaseMask ? ", phaseMask" : "") + ", position_x, position_y, position_z, orientation, rotation0, rotation1, rotation2, rotation3, spawntimesecsmin, spawntimesecsmax) VALUES\n";
else
output = ",\n";
}
bool first = true;
foreach (var gameObject in gameObjects)
{
Expand All @@ -359,12 +418,7 @@ private async void processButtonClick(string entriesText, string indexText)
output += ";";
}

DataPackage dataPackage = new DataPackage();
dataPackage.RequestedOperation = DataPackageOperation.Copy;
dataPackage.SetText(output);
Clipboard.SetContent(dataPackage);

saveFile();
return output;
}
}
}

0 comments on commit 366724c

Please sign in to comment.