From 307ccceb2c84d0c00e4c93e65627d12d99901ec2 Mon Sep 17 00:00:00 2001 From: kruumy Date: Fri, 10 Mar 2023 00:55:04 -0500 Subject: [PATCH] added reading mod.ff, added detected dependencies box --- EasyZoneBuilder.Core/DependencyGraphUtil.cs | 13 +++++-- EasyZoneBuilder.Core/Mod.cs | 15 ++++++++ EasyZoneBuilder.GUI/Mod.xaml | 34 ++++++++++++++++-- EasyZoneBuilder.GUI/Mod.xaml.cs | 38 +++++++++++++++++---- README.md | 14 ++++++-- 5 files changed, 99 insertions(+), 15 deletions(-) diff --git a/EasyZoneBuilder.Core/DependencyGraphUtil.cs b/EasyZoneBuilder.Core/DependencyGraphUtil.cs index 43edcf8..9a4438f 100644 --- a/EasyZoneBuilder.Core/DependencyGraphUtil.cs +++ b/EasyZoneBuilder.Core/DependencyGraphUtil.cs @@ -8,6 +8,8 @@ namespace EasyZoneBuilder.Core { public static class DependencyGraphUtil { + // TODO remove GenerateDependencyGraphJson and add a RegenerateZones(params string[] zones) + public static async Task GenerateDependencyGraphJson() { Dictionary> json = new Dictionary>(); @@ -45,7 +47,6 @@ public static async Task GenerateDependencyGraphJson() } File.WriteAllText("dependency_graph.json", Core.TinyJson.JSONWriter.ToJson(newJson)); } - public static IEnumerable GetRequiredZones( ModCSV csv ) { // Took a lot of inspiration from https://github.com/XLabsProject/iw4-zone-asset-finder/blob/main/iw4-zone-asset-finder/Commands/BuildRequirements.cs @@ -54,8 +55,14 @@ public static IEnumerable GetRequiredZones( ModCSV csv ) foreach ( KeyValuePair asset in csv ) { string dependency_graph_assetQuery = $"{asset.Value}:{asset.Key}"; - List queryResult = dependency_graph[ dependency_graph_assetQuery ]; - assets_zones.Add(new KeyValuePair>(asset.Key, queryResult)); + if ( dependency_graph.TryGetValue(dependency_graph_assetQuery, out List queryResult) ) + { + assets_zones.Add(new KeyValuePair>(asset.Key, queryResult)); + } + else + { + return Array.Empty(); + } } Dictionary finalZoneScore = new Dictionary(); while ( assets_zones.Count > 0 ) diff --git a/EasyZoneBuilder.Core/Mod.cs b/EasyZoneBuilder.Core/Mod.cs index f4b8e2e..a08bf7d 100644 --- a/EasyZoneBuilder.Core/Mod.cs +++ b/EasyZoneBuilder.Core/Mod.cs @@ -26,6 +26,21 @@ public async Task BuildZone() await ZoneBuilder.BuildZone(CSV, FastFile); } + public async Task ReadZone() + { + CSV.Clear(); + foreach ( string type in typeof(AssetType).GetEnumNames() ) + { + AssetType assetType = AssetTypeUtil.Parse(type); + IEnumerable assets = await ZoneBuilder.ListAssets(assetType, FastFile); + foreach ( string asset in assets ) + { + CSV[ asset ] = assetType; + } + } + CSV.Push(); + } + public void SyncCSVToPrecache() { List toRemoveFromPreacache = new List(); diff --git a/EasyZoneBuilder.GUI/Mod.xaml b/EasyZoneBuilder.GUI/Mod.xaml index 254c226..cb202fc 100644 --- a/EasyZoneBuilder.GUI/Mod.xaml +++ b/EasyZoneBuilder.GUI/Mod.xaml @@ -10,7 +10,8 @@ - + + @@ -30,11 +31,19 @@ Margin="5" Content="Read mod.csv" Click="ReadModCsvBtn_Click"> + + + + + + @@ -67,6 +76,27 @@ + + + + + + + + + + diff --git a/EasyZoneBuilder.GUI/Mod.xaml.cs b/EasyZoneBuilder.GUI/Mod.xaml.cs index bcd266c..cd99fbe 100644 --- a/EasyZoneBuilder.GUI/Mod.xaml.cs +++ b/EasyZoneBuilder.GUI/Mod.xaml.cs @@ -22,19 +22,29 @@ private void selectedMod_Loaded( object sender, RoutedEventArgs e ) selectedMod.ItemsSource = Core.Settings.IW4.Mods; } - private void CsvGrid_Loaded( object sender, RoutedEventArgs e ) + public void ReadModCsvBtn_Click( object sender, RoutedEventArgs e ) { if ( selectedMod.SelectedItem is Core.Mod sMod ) { + if ( sMod.CSV.Count <= 0 && sMod.FastFile.Exists ) + { + if ( MessageBoxResult.Yes == MessageBox.Show("Empty mod.csv detected!\nWould you like to generate the mod.csv from the mod.ff?", "Notice", MessageBoxButton.YesNo, MessageBoxImage.Question) ) + { + readFastFileContextMenu_Click(sender, e); + } + } sMod.CSV.Pull(); + detectedZonesBox.Text = string.Empty; + foreach ( string zone in DependencyGraphUtil.GetRequiredZones(sMod.CSV) ) + { + detectedZonesBox.Text += zone + ", "; + } + if ( detectedZonesBox.Text.Length > 2 ) + { + detectedZonesBox.Text = detectedZonesBox.Text.Remove(detectedZonesBox.Text.Length - 2, 2); + } CsvGrid.ItemsSource = sMod.CSV; } - - } - - public void ReadModCsvBtn_Click( object sender, RoutedEventArgs e ) - { - CsvGrid_Loaded(sender, e); CsvGrid.Items.Refresh(); } @@ -75,5 +85,19 @@ private void writePrecacheBtn_Click( object sender, RoutedEventArgs e ) MessageBox.Show("Wrote to _precache.gsc successfully!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } } + + private async void readFastFileContextMenu_Click( object sender, RoutedEventArgs e ) + { + if ( selectedMod.SelectedItem is Core.Mod sMod && sMod.FastFile.Exists ) + { + ReadModCsvBtn.IsEnabled = false; + object oldContent = ReadModCsvBtn.Content; + ReadModCsvBtn.Content = "Reading..."; + await sMod.ReadZone(); + ReadModCsvBtn_Click(sender, e); + ReadModCsvBtn.Content = oldContent; + ReadModCsvBtn.IsEnabled = true; + } + } } } diff --git a/README.md b/README.md index 1cd2c0a..b3ed0e2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ -

Build zones fast

+

Build zones fast!

-### Repository Structure +## Support + +| Name | Status | +| --- | --- | +| [IW4X Zonebuilder](https://github.com/XLabsProject/iw4x-client) | ✅ | +| [Zonebuilder](https://github.com/RagdollPhysics/zonebuilder) | ❔ | +| [Zonetool](https://github.com/ZoneTool/zonetool) | ❔ | + +## Repository Structure ``` EasyZoneBuilder-iw4 ├── EasyZoneBuilder.Core │ ├── Core Functionality. ├── EasyZoneBuilder.GUI │ ├── WPF Front-end. -``` +``` \ No newline at end of file