Skip to content

Commit

Permalink
added reading mod.ff, added detected dependencies box
Browse files Browse the repository at this point in the history
  • Loading branch information
kruumy committed Mar 10, 2023
1 parent fb1dc46 commit 307ccce
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 15 deletions.
13 changes: 10 additions & 3 deletions EasyZoneBuilder.Core/DependencyGraphUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Dictionary<string, string[]>> json = new Dictionary<string, Dictionary<string, string[]>>();
Expand Down Expand Up @@ -45,7 +47,6 @@ public static async Task GenerateDependencyGraphJson()
}
File.WriteAllText("dependency_graph.json", Core.TinyJson.JSONWriter.ToJson(newJson));
}

public static IEnumerable<string> 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
Expand All @@ -54,8 +55,14 @@ public static IEnumerable<string> GetRequiredZones( ModCSV csv )
foreach ( KeyValuePair<string, AssetType> asset in csv )
{
string dependency_graph_assetQuery = $"{asset.Value}:{asset.Key}";
List<string> queryResult = dependency_graph[ dependency_graph_assetQuery ];
assets_zones.Add(new KeyValuePair<string, List<string>>(asset.Key, queryResult));
if ( dependency_graph.TryGetValue(dependency_graph_assetQuery, out List<string> queryResult) )
{
assets_zones.Add(new KeyValuePair<string, List<string>>(asset.Key, queryResult));
}
else
{
return Array.Empty<string>();
}
}
Dictionary<string, int> finalZoneScore = new Dictionary<string, int>();
while ( assets_zones.Count > 0 )
Expand Down
15 changes: 15 additions & 0 deletions EasyZoneBuilder.Core/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> assets = await ZoneBuilder.ListAssets(assetType, FastFile);
foreach ( string asset in assets )
{
CSV[ asset ] = assetType;
}
}
CSV.Push();
}

public void SyncCSVToPrecache()
{
List<string> toRemoveFromPreacache = new List<string>();
Expand Down
34 changes: 32 additions & 2 deletions EasyZoneBuilder.GUI/Mod.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<Grid.RowDefinitions>
<RowDefinition Height="35"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="35"></RowDefinition>
<RowDefinition Height="35"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.Column="0">
<Grid.ColumnDefinitions>
Expand All @@ -30,11 +31,19 @@
Margin="5"
Content="Read mod.csv"
Click="ReadModCsvBtn_Click">
<Button.ContextMenu>
<ContextMenu>
<MenuItem
x:Name="readFastFileContextMenu"
Header="Read mod.ff"
Click="readFastFileContextMenu_Click">
</MenuItem>
</ContextMenu>
</Button.ContextMenu>
</Button>
</Grid>
<DataGrid x:Name="CsvGrid"
Grid.Row="1"
Loaded="CsvGrid_Loaded"
AutoGenerateColumns="False"
SelectionMode="Single"
Margin="5">
Expand Down Expand Up @@ -67,6 +76,27 @@
</DataGrid>

<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
Content="Detected Zones:"
Margin="5">
</Label>
<TextBox
x:Name="detectedZonesBox"
Grid.Column="1"
Margin="5"
IsReadOnly="True"
TextAlignment="Left"
TextWrapping="NoWrap"
VerticalContentAlignment="Center">
</TextBox>
</Grid>

<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
Expand Down
38 changes: 31 additions & 7 deletions EasyZoneBuilder.GUI/Mod.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}
}
}
}
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@
<a href="https://paypal.me/JPauls281"><img src="https://img.shields.io/badge/Donate-Paypal-orange?style=flat-square"></a>
</div>

<h4 align="center">Build zones fast</h4>
<h4 align="center">Build zones fast!</h4>

<div align="center">
<a href="preview.png">
<img src="preview.png" alt="Preivew" Width="auto" Height="auto">
</a>
</div>

### 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.
```
```

0 comments on commit 307ccce

Please sign in to comment.