Skip to content

Commit 307ccce

Browse files
committed
added reading mod.ff, added detected dependencies box
1 parent fb1dc46 commit 307ccce

File tree

5 files changed

+99
-15
lines changed

5 files changed

+99
-15
lines changed

EasyZoneBuilder.Core/DependencyGraphUtil.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace EasyZoneBuilder.Core
88
{
99
public static class DependencyGraphUtil
1010
{
11+
// TODO remove GenerateDependencyGraphJson and add a RegenerateZones(params string[] zones)
12+
1113
public static async Task GenerateDependencyGraphJson()
1214
{
1315
Dictionary<string, Dictionary<string, string[]>> json = new Dictionary<string, Dictionary<string, string[]>>();
@@ -45,7 +47,6 @@ public static async Task GenerateDependencyGraphJson()
4547
}
4648
File.WriteAllText("dependency_graph.json", Core.TinyJson.JSONWriter.ToJson(newJson));
4749
}
48-
4950
public static IEnumerable<string> GetRequiredZones( ModCSV csv )
5051
{
5152
// 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<string> GetRequiredZones( ModCSV csv )
5455
foreach ( KeyValuePair<string, AssetType> asset in csv )
5556
{
5657
string dependency_graph_assetQuery = $"{asset.Value}:{asset.Key}";
57-
List<string> queryResult = dependency_graph[ dependency_graph_assetQuery ];
58-
assets_zones.Add(new KeyValuePair<string, List<string>>(asset.Key, queryResult));
58+
if ( dependency_graph.TryGetValue(dependency_graph_assetQuery, out List<string> queryResult) )
59+
{
60+
assets_zones.Add(new KeyValuePair<string, List<string>>(asset.Key, queryResult));
61+
}
62+
else
63+
{
64+
return Array.Empty<string>();
65+
}
5966
}
6067
Dictionary<string, int> finalZoneScore = new Dictionary<string, int>();
6168
while ( assets_zones.Count > 0 )

EasyZoneBuilder.Core/Mod.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ public async Task BuildZone()
2626
await ZoneBuilder.BuildZone(CSV, FastFile);
2727
}
2828

29+
public async Task ReadZone()
30+
{
31+
CSV.Clear();
32+
foreach ( string type in typeof(AssetType).GetEnumNames() )
33+
{
34+
AssetType assetType = AssetTypeUtil.Parse(type);
35+
IEnumerable<string> assets = await ZoneBuilder.ListAssets(assetType, FastFile);
36+
foreach ( string asset in assets )
37+
{
38+
CSV[ asset ] = assetType;
39+
}
40+
}
41+
CSV.Push();
42+
}
43+
2944
public void SyncCSVToPrecache()
3045
{
3146
List<string> toRemoveFromPreacache = new List<string>();

EasyZoneBuilder.GUI/Mod.xaml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<Grid.RowDefinitions>
1111
<RowDefinition Height="35"></RowDefinition>
1212
<RowDefinition Height="*"></RowDefinition>
13-
<RowDefinition Height="50"></RowDefinition>
13+
<RowDefinition Height="35"></RowDefinition>
14+
<RowDefinition Height="35"></RowDefinition>
1415
</Grid.RowDefinitions>
1516
<Grid Grid.Row="0" Grid.Column="0">
1617
<Grid.ColumnDefinitions>
@@ -30,11 +31,19 @@
3031
Margin="5"
3132
Content="Read mod.csv"
3233
Click="ReadModCsvBtn_Click">
34+
<Button.ContextMenu>
35+
<ContextMenu>
36+
<MenuItem
37+
x:Name="readFastFileContextMenu"
38+
Header="Read mod.ff"
39+
Click="readFastFileContextMenu_Click">
40+
</MenuItem>
41+
</ContextMenu>
42+
</Button.ContextMenu>
3343
</Button>
3444
</Grid>
3545
<DataGrid x:Name="CsvGrid"
3646
Grid.Row="1"
37-
Loaded="CsvGrid_Loaded"
3847
AutoGenerateColumns="False"
3948
SelectionMode="Single"
4049
Margin="5">
@@ -67,6 +76,27 @@
6776
</DataGrid>
6877

6978
<Grid Grid.Row="2">
79+
<Grid.ColumnDefinitions>
80+
<ColumnDefinition Width="auto"></ColumnDefinition>
81+
<ColumnDefinition Width="*"></ColumnDefinition>
82+
</Grid.ColumnDefinitions>
83+
<Label
84+
Grid.Column="0"
85+
Content="Detected Zones:"
86+
Margin="5">
87+
</Label>
88+
<TextBox
89+
x:Name="detectedZonesBox"
90+
Grid.Column="1"
91+
Margin="5"
92+
IsReadOnly="True"
93+
TextAlignment="Left"
94+
TextWrapping="NoWrap"
95+
VerticalContentAlignment="Center">
96+
</TextBox>
97+
</Grid>
98+
99+
<Grid Grid.Row="3">
70100
<Grid.ColumnDefinitions>
71101
<ColumnDefinition Width="*"></ColumnDefinition>
72102
<ColumnDefinition Width="*"></ColumnDefinition>

EasyZoneBuilder.GUI/Mod.xaml.cs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,29 @@ private void selectedMod_Loaded( object sender, RoutedEventArgs e )
2222
selectedMod.ItemsSource = Core.Settings.IW4.Mods;
2323
}
2424

25-
private void CsvGrid_Loaded( object sender, RoutedEventArgs e )
25+
public void ReadModCsvBtn_Click( object sender, RoutedEventArgs e )
2626
{
2727
if ( selectedMod.SelectedItem is Core.Mod sMod )
2828
{
29+
if ( sMod.CSV.Count <= 0 && sMod.FastFile.Exists )
30+
{
31+
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) )
32+
{
33+
readFastFileContextMenu_Click(sender, e);
34+
}
35+
}
2936
sMod.CSV.Pull();
37+
detectedZonesBox.Text = string.Empty;
38+
foreach ( string zone in DependencyGraphUtil.GetRequiredZones(sMod.CSV) )
39+
{
40+
detectedZonesBox.Text += zone + ", ";
41+
}
42+
if ( detectedZonesBox.Text.Length > 2 )
43+
{
44+
detectedZonesBox.Text = detectedZonesBox.Text.Remove(detectedZonesBox.Text.Length - 2, 2);
45+
}
3046
CsvGrid.ItemsSource = sMod.CSV;
3147
}
32-
33-
}
34-
35-
public void ReadModCsvBtn_Click( object sender, RoutedEventArgs e )
36-
{
37-
CsvGrid_Loaded(sender, e);
3848
CsvGrid.Items.Refresh();
3949
}
4050

@@ -75,5 +85,19 @@ private void writePrecacheBtn_Click( object sender, RoutedEventArgs e )
7585
MessageBox.Show("Wrote to _precache.gsc successfully!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
7686
}
7787
}
88+
89+
private async void readFastFileContextMenu_Click( object sender, RoutedEventArgs e )
90+
{
91+
if ( selectedMod.SelectedItem is Core.Mod sMod && sMod.FastFile.Exists )
92+
{
93+
ReadModCsvBtn.IsEnabled = false;
94+
object oldContent = ReadModCsvBtn.Content;
95+
ReadModCsvBtn.Content = "Reading...";
96+
await sMod.ReadZone();
97+
ReadModCsvBtn_Click(sender, e);
98+
ReadModCsvBtn.Content = oldContent;
99+
ReadModCsvBtn.IsEnabled = true;
100+
}
101+
}
78102
}
79103
}

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,27 @@
1010
<a href="https://paypal.me/JPauls281"><img src="https://img.shields.io/badge/Donate-Paypal-orange?style=flat-square"></a>
1111
</div>
1212

13-
<h4 align="center">Build zones fast</h4>
13+
<h4 align="center">Build zones fast!</h4>
1414

1515
<div align="center">
1616
<a href="preview.png">
1717
<img src="preview.png" alt="Preivew" Width="auto" Height="auto">
1818
</a>
1919
</div>
2020

21-
### Repository Structure
21+
## Support
22+
23+
| Name | Status |
24+
| --- | --- |
25+
| [IW4X Zonebuilder](https://github.com/XLabsProject/iw4x-client) ||
26+
| [Zonebuilder](https://github.com/RagdollPhysics/zonebuilder) ||
27+
| [Zonetool](https://github.com/ZoneTool/zonetool) ||
28+
29+
## Repository Structure
2230
```
2331
EasyZoneBuilder-iw4
2432
├── EasyZoneBuilder.Core
2533
│ ├── Core Functionality.
2634
├── EasyZoneBuilder.GUI
2735
│ ├── WPF Front-end.
28-
```
36+
```

0 commit comments

Comments
 (0)