Skip to content

Commit

Permalink
Abstract preset flags
Browse files Browse the repository at this point in the history
centralize where flag names are stored, and hide from editor list by default
  • Loading branch information
pizzaboxer committed Jul 23, 2023
1 parent 44c9d49 commit e5d6ac0
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 140 deletions.
141 changes: 101 additions & 40 deletions Bloxstrap/FastFlagManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Bloxstrap
using System.Windows.Input;
using System.Windows.Media.Animation;

namespace Bloxstrap
{
public class FastFlagManager : JsonManager<Dictionary<string, string>>
{
Expand All @@ -7,22 +10,57 @@ public class FastFlagManager : JsonManager<Dictionary<string, string>>
// this is the value of the 'FStringPartTexturePackTablePre2022' flag
public const string OldTexturesFlagValue = "{\"foil\":{\"ids\":[\"rbxassetid://7546645012\",\"rbxassetid://7546645118\"],\"color\":[255,255,255,255]},\"brick\":{\"ids\":[\"rbxassetid://7546650097\",\"rbxassetid://7546645118\"],\"color\":[204,201,200,232]},\"cobblestone\":{\"ids\":[\"rbxassetid://7546652947\",\"rbxassetid://7546645118\"],\"color\":[212,200,187,250]},\"concrete\":{\"ids\":[\"rbxassetid://7546653951\",\"rbxassetid://7546654144\"],\"color\":[208,208,208,255]},\"diamondplate\":{\"ids\":[\"rbxassetid://7547162198\",\"rbxassetid://7546645118\"],\"color\":[170,170,170,255]},\"fabric\":{\"ids\":[\"rbxassetid://7547101130\",\"rbxassetid://7546645118\"],\"color\":[105,104,102,244]},\"glass\":{\"ids\":[\"rbxassetid://7547304948\",\"rbxassetid://7546645118\"],\"color\":[254,254,254,7]},\"granite\":{\"ids\":[\"rbxassetid://7547164710\",\"rbxassetid://7546645118\"],\"color\":[113,113,113,255]},\"grass\":{\"ids\":[\"rbxassetid://7547169285\",\"rbxassetid://7546645118\"],\"color\":[165,165,159,255]},\"ice\":{\"ids\":[\"rbxassetid://7547171356\",\"rbxassetid://7546645118\"],\"color\":[255,255,255,255]},\"marble\":{\"ids\":[\"rbxassetid://7547177270\",\"rbxassetid://7546645118\"],\"color\":[199,199,199,255]},\"metal\":{\"ids\":[\"rbxassetid://7547288171\",\"rbxassetid://7546645118\"],\"color\":[199,199,199,255]},\"pebble\":{\"ids\":[\"rbxassetid://7547291361\",\"rbxassetid://7546645118\"],\"color\":[208,208,208,255]},\"corrodedmetal\":{\"ids\":[\"rbxassetid://7547184629\",\"rbxassetid://7546645118\"],\"color\":[159,119,95,200]},\"sand\":{\"ids\":[\"rbxassetid://7547295153\",\"rbxassetid://7546645118\"],\"color\":[220,220,220,255]},\"slate\":{\"ids\":[\"rbxassetid://7547298114\",\"rbxassetid://7547298323\"],\"color\":[193,193,193,255]},\"wood\":{\"ids\":[\"rbxassetid://7547303225\",\"rbxassetid://7547298786\"],\"color\":[227,227,227,255]},\"woodplanks\":{\"ids\":[\"rbxassetid://7547332968\",\"rbxassetid://7546645118\"],\"color\":[212,209,203,255]},\"asphalt\":{\"ids\":[\"rbxassetid://9873267379\",\"rbxassetid://9438410548\"],\"color\":[123,123,123,234]},\"basalt\":{\"ids\":[\"rbxassetid://9873270487\",\"rbxassetid://9438413638\"],\"color\":[154,154,153,238]},\"crackedlava\":{\"ids\":[\"rbxassetid://9438582231\",\"rbxassetid://9438453972\"],\"color\":[74,78,80,156]},\"glacier\":{\"ids\":[\"rbxassetid://9438851661\",\"rbxassetid://9438453972\"],\"color\":[226,229,229,243]},\"ground\":{\"ids\":[\"rbxassetid://9439044431\",\"rbxassetid://9438453972\"],\"color\":[114,114,112,240]},\"leafygrass\":{\"ids\":[\"rbxassetid://9873288083\",\"rbxassetid://9438453972\"],\"color\":[121,117,113,234]},\"limestone\":{\"ids\":[\"rbxassetid://9873289812\",\"rbxassetid://9438453972\"],\"color\":[235,234,230,250]},\"mud\":{\"ids\":[\"rbxassetid://9873319819\",\"rbxassetid://9438453972\"],\"color\":[130,130,130,252]},\"pavement\":{\"ids\":[\"rbxassetid://9873322398\",\"rbxassetid://9438453972\"],\"color\":[142,142,144,236]},\"rock\":{\"ids\":[\"rbxassetid://9873515198\",\"rbxassetid://9438453972\"],\"color\":[154,154,154,248]},\"salt\":{\"ids\":[\"rbxassetid://9439566986\",\"rbxassetid://9438453972\"],\"color\":[220,220,221,255]},\"sandstone\":{\"ids\":[\"rbxassetid://9873521380\",\"rbxassetid://9438453972\"],\"color\":[174,171,169,246]},\"snow\":{\"ids\":[\"rbxassetid://9439632387\",\"rbxassetid://9438453972\"],\"color\":[218,218,218,255]}}";

public static IReadOnlyDictionary<string, string> PresetFlags = new Dictionary<string, string>
{
{ "HTTP.Log", "DFLogHttpTraceLight" },

{ "HTTP.Proxy.Enable", "DFFlagDebugEnableHttpProxy" },
{ "HTTP.Proxy.Address.1", "DFStringDebugPlayerHttpProxyUrl" },
{ "HTTP.Proxy.Address.2", "DFStringHttpCurlProxyHostAndPort" },
{ "HTTP.Proxy.Address.3", "DFStringHttpCurlProxyHostAndPortForExternalUrl" },

{ "Rendering.Framerate", "DFIntTaskSchedulerTargetFps" },
{ "Rendering.Fullscreen", "FFlagHandleAltEnterFullscreenManually" },
{ "Rendering.TexturePack", "FStringPartTexturePackTable2022" },

{ "Rendering.DPI.Disable", "DFFlagDisableDPIScale" },
{ "Rendering.DPI.Variable", "DFFlagVariableDPIScale2" },

{ "Rendering.Mode.D3D11", "FFlagDebugGraphicsPreferD3D11" },
{ "Rendering.Mode.D3D10", "FFlagDebugGraphicsPreferD3D11FL10" },
{ "Rendering.Mode.Vulkan", "FFlagDebugGraphicsPreferVulkan" },
{ "Rendering.Mode.Vulkan.Fix", "FFlagRenderVulkanFixMinimizeWindow" },
{ "Rendering.Mode.OpenGL", "FFlagDebugGraphicsPreferOpenGL" },

{ "Rendering.Lighting.Voxel", "DFFlagDebugRenderForceTechnologyVoxel" },
{ "Rendering.Lighting.ShadowMap", "FFlagDebugForceFutureIsBrightPhase2" },
{ "Rendering.Lighting.Future", "FFlagDebugForceFutureIsBrightPhase3" },

{ "UI.Hide", "DFIntCanHideGuiGroupId" },
{ "UI.FlagState", "FStringDebugShowFlagState" },

{ "UI.Menu.GraphicsSlider", "FFlagFixGraphicsQuality" },

{ "UI.Menu.Style.DisableV2", "FFlagDisableNewIGMinDUA" },
{ "UI.Menu.Style.EnableV4", "FFlagEnableInGameMenuControls" }
};

// only one missing here is Metal because lol
public static IReadOnlyDictionary<string, string> RenderingModes => new Dictionary<string, string>
{
{ "Automatic", "" },
{ "Vulkan", "FFlagDebugGraphicsPreferVulkan" },
{ "Direct3D 11", "FFlagDebugGraphicsPreferD3D11" },
{ "Direct3D 10", "FFlagDebugGraphicsPreferD3D11FL10" },
{ "OpenGL", "FFlagDebugGraphicsPreferOpenGL" }
{ "Automatic", "None" },
{ "Vulkan", "Vulkan" },
{ "Direct3D 11", "D3D11" },
{ "Direct3D 10", "D3D10" },
{ "OpenGL", "OpenGL" }
};

public static IReadOnlyDictionary<string, string> LightingTechnologies => new Dictionary<string, string>
public static IReadOnlyDictionary<string, string> LightingModes => new Dictionary<string, string>
{
{ "Chosen by game", "" },
{ "Voxel (Phase 1)", "DFFlagDebugRenderForceTechnologyVoxel" },
{ "ShadowMap (Phase 2)", "FFlagDebugForceFutureIsBrightPhase2" },
{ "Future (Phase 3)", "FFlagDebugForceFutureIsBrightPhase3" }
{ "Chosen by game", "None" },
{ "Voxel (Phase 1)", "Voxel" },
{ "ShadowMap (Phase 2)", "ShadowMap" },
{ "Future (Phase 3)", "Future" }
};

// this is one hell of a dictionary definition lmao
Expand All @@ -33,35 +71,35 @@ public class FastFlagManager : JsonManager<Dictionary<string, string>>
"Default",
new Dictionary<string, string?>
{
{ "FFlagDisableNewIGMinDUA", null },
{ "FFlagEnableInGameMenuControls", null }
{ "DisableV2", null },
{ "EnableV4", null }
}
},

{
"Version 1 (2015)",
new Dictionary<string, string?>
{
{ "FFlagDisableNewIGMinDUA", "True" },
{ "FFlagEnableInGameMenuControls", "False" }
{ "DisableV2", "True" },
{ "EnableV4", "False" }
}
},

{
"Version 2 (2020)",
new Dictionary<string, string?>
{
{ "FFlagDisableNewIGMinDUA", "False" },
{ "FFlagEnableInGameMenuControls", "False" }
{ "DisableV2", "False" },
{ "EnableV4", "False" }
}
},

{
"Version 4 (2023)",
new Dictionary<string, string?>
{
{ "FFlagDisableNewIGMinDUA", "True" },
{ "FFlagEnableInGameMenuControls", "True" }
{ "DisableV2", "True" },
{ "EnableV4", "True" }
}
}
};
Expand All @@ -82,22 +120,6 @@ public void SetValue(string key, object? value)
}
}

// this will set the flag to the corresponding value if the condition is true
// if the condition is not true, the flag will be erased
public void SetValueIf(bool condition, string key, object? value)
{
if (condition)
SetValue(key, value);
else if (GetValue(key) is not null)
SetValue(key, null);
}

public void SetValueOnce(string key, object? value)
{
if (GetValue(key) is null)
SetValue(key, value);
}

// this returns null if the fflag doesn't exist
public string? GetValue(string key)
{
Expand All @@ -108,15 +130,54 @@ public void SetValueOnce(string key, object? value)
return null;
}

public void SetPreset(string prefix, object? value)
{
foreach (var pair in PresetFlags.Where(x => x.Key.StartsWith(prefix)))
SetValue(pair.Value, value);
}

public void SetPresetOnce(string key, object? value)
{
if (GetPreset(key) is null)
SetPreset(key, value);
}

public void SetPresetEnum(string prefix, string target, object? value)
{
foreach (var pair in PresetFlags.Where(x => x.Key.StartsWith(prefix)))
{
if (pair.Key.StartsWith($"{prefix}.{target}"))
SetValue(pair.Value, value);
else
SetValue(pair.Value, null);
}
}

public string? GetPreset(string name) => GetValue(PresetFlags[name]);

public string GetPresetEnum(IReadOnlyDictionary<string, string> mapping, string prefix, string value)
{
foreach (var mode in mapping)
{
if (mode.Key == mapping.First().Key)
continue;

if (App.FastFlags.GetPreset($"{prefix}.{mode.Value}") == value)
return mode.Key;
}

return mapping.First().Key;
}

public override void Load()
{
base.Load();

// set to 9999 by default if it doesnt already exist
SetValueOnce("DFIntTaskSchedulerTargetFps", 9999);
SetValueOnce("FFlagHandleAltEnterFullscreenManually", "False");
SetValueOnce("DFFlagDisableDPIScale", "True");
SetValueOnce("DFFlagVariableDPIScale2", "False");
SetPresetOnce("Rendering.Framerate", 9999);
SetPresetOnce("Rendering.Fullscreen", "False");

SetPresetOnce("Rendering.DPI.Disable", "True");
SetPresetOnce("Rendering.DPI.Variable", "False");
}
}
}
1 change: 1 addition & 0 deletions Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
</Style>
</ui:Button.Style>
</ui:Button>
<ToggleButton Content="Show preset flags" Click="ToggleButton_Click" Margin="12,0,0,0" />
</StackPanel>
</Grid>
</ui:UiPage>
35 changes: 17 additions & 18 deletions Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

using Bloxstrap.UI.Elements.Dialogs;

Expand All @@ -35,14 +22,17 @@ public FastFlagEditorPage()
InitializeComponent();
}

private void Page_Loaded(object sender, RoutedEventArgs e)
private void ReloadList(bool showPresets = false)
{
// refresh list on page load to synchronize with preset page

_fastFlagList.Clear();

var presetFlags = FastFlagManager.PresetFlags.Values;

foreach (var pair in App.FastFlags.Prop)
{
if (!showPresets && presetFlags.Contains(pair.Key))
continue;

var entry = new FastFlag
{
Enabled = true,
Expand All @@ -62,6 +52,9 @@ private void Page_Loaded(object sender, RoutedEventArgs e)
DataGrid.ItemsSource = _fastFlagList;
}

// refresh list on page load to synchronize with preset page
private void Page_Loaded(object sender, RoutedEventArgs e) => ReloadList();

private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
int index = e.Row.GetIndex();
Expand Down Expand Up @@ -135,5 +128,11 @@ private void DeleteButton_Click(object sender, RoutedEventArgs e)
App.FastFlags.SetValue(entry.Name, null);
}
}

private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
if (sender is ToggleButton button)
ReloadList(button.IsChecked ?? false);
}
}
}
2 changes: 1 addition & 1 deletion Bloxstrap/UI/Elements/Menu/Pages/FastFlagsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Choose which lighting technology should be forced enabled in all games." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardControl.Header>
<ComboBox Margin="5,0,0,0" Padding="10,5,10,5" Width="200" ItemsSource="{Binding LightingTechnologies.Keys, Mode=OneTime}" Text="{Binding SelectedLightingTechnology, Mode=TwoWay}" />
<ComboBox Margin="5,0,0,0" Padding="10,5,10,5" Width="200" ItemsSource="{Binding LightingModes.Keys, Mode=OneTime}" Text="{Binding SelectedLightingMode, Mode=TwoWay}" />
</ui:CardControl>
<ui:CardControl Margin="0,8,0,0">
<ui:CardControl.Header>
Expand Down
Loading

0 comments on commit e5d6ac0

Please sign in to comment.