Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.
/ KyberBrowser Public archive

Commit

Permalink
use modoverrides when hosting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dyvinia committed Oct 13, 2023
1 parent 7c93044 commit 4b9a15e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
8 changes: 5 additions & 3 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ public App() {

DispatcherUnhandledException += Application_DispatcherUnhandledException;

DownloadKyber();
GetProxies();
GetMapsModes();
Task.Run(() => {
DownloadKyber();
GetProxies();
GetMapsModes();
});
}

protected override async void OnStartup(StartupEventArgs e) {
Expand Down
2 changes: 1 addition & 1 deletion Windows/HostWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
</StackPanel>

<StackPanel Orientation="Vertical" VerticalAlignment="Bottom">
<ComboBox x:Name="ModDataComboBox" DisplayMemberPath="Name" Margin="0 0 0 4" ToolTip="Select ModData" Height="30" FontFamily="/Fonts/Univers.ttf #Linotype Univers 520 CnMedium" Padding="6 0 0 0" FontSize="16" VerticalContentAlignment="Center" Foreground="#FFA3A3A3"/>
<ComboBox x:Name="ModDataComboBox" DisplayMemberPath="Name" Margin="0 0 0 4" ToolTip="Select ModData" Height="30" FontFamily="/Fonts/Univers.ttf #Linotype Univers 520 CnMedium" Padding="6 0 0 0" FontSize="16" VerticalContentAlignment="Center" Foreground="#FFA3A3A3" SelectionChanged="ModDataComboBox_SelectionChanged"/>

<Grid>
<Grid.ColumnDefinitions>
Expand Down
31 changes: 28 additions & 3 deletions Windows/HostWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public HostWindow() {
}

private void GetMaps() {
if (ModeComboBox.SelectedItem is null) return;

Dictionary<string, string> mapOverrides = ((dynamic)ModeComboBox.SelectedItem).Value.MapOverrides?.ToObject<Dictionary<string, string>>();
string[] selectedMapKeys = ((dynamic)ModeComboBox.SelectedItem).Value.Maps.ToObject<string[]>();

Expand All @@ -58,9 +60,7 @@ public void UpdatePingSiteComboBox() {
PingSiteComboBox.SelectedIndex = 0;
}

private void ModeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
GetMaps();
}
private void ModeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) => GetMaps();

private void MaxPlayersTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e) {
TextBox tBox = (TextBox)sender;
Expand All @@ -76,6 +76,31 @@ private void MaxPlayersTextBox_LostFocus(object sender, RoutedEventArgs e) {
tBox.Text = "2";
}

private void ModDataComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
if (ModDataComboBox.SelectedItem is null) return;

Dictionary<string, dynamic> selectedModes = App.Modes.ToDictionary(m => m.Key, m => m.Value.DeepClone());

DirectoryInfo selectedModData = ModDataComboBox.SelectedItem as DirectoryInfo;
string selectedModsJson = Path.Combine(selectedModData.FullName, "patch", "mods.json");
if (File.Exists(selectedModsJson)) {
// reset modes
selectedModes = App.Modes.ToDictionary(m => m.Key, m => m.Value.DeepClone());
dynamic[] mods = JsonConvert.DeserializeObject<dynamic[]>(File.ReadAllText(selectedModsJson));

Dictionary<string, string> modOverrides = App.ModOverrides.FirstOrDefault(m => mods.Any(o => ((string)o.name).Contains(m.Key))).Value ?? new();
foreach (var modOverride in modOverrides) {
if (selectedModes.ContainsKey(modOverride.Key))
selectedModes[modOverride.Key].Name = modOverride.Value;
}
}

// refresh combobox
int selectedIndex = ModeComboBox.SelectedIndex;
ModeComboBox.ItemsSource = selectedModes;
ModeComboBox.SelectedIndex = selectedIndex;
}

public void UpdateModDataComboBox() {
string path = Path.Combine(Path.GetDirectoryName(Config.Settings.BF2Path) ?? "", "ModData");

Expand Down

0 comments on commit 4b9a15e

Please sign in to comment.