Skip to content

Commit

Permalink
every copy of jiayi is personalized
Browse files Browse the repository at this point in the history
  • Loading branch information
phasephasephase committed Jan 7, 2024
1 parent d1892df commit 561e17b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
3 changes: 2 additions & 1 deletion JiayiLauncher/Appearance/PaletteGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ public static void CreatePalette()
);

var allChannelsAverage = (averageColor.R + averageColor.G + averageColor.B) / 3;
allChannelsAverage = Math.Clamp(allChannelsAverage + Random.Shared.Next(-20, 20), 0, 255);
var dark = allChannelsAverage < 200; // prefer dark

// values and stuff
var accent = palette[0];
var accent = palette[Random.Shared.Next(0, palette.Count / 2)];
Color primaryBackground;
Color secondaryBackground;

Expand Down
8 changes: 5 additions & 3 deletions JiayiLauncher/Settings/JiayiSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using JiayiLauncher.Appearance;
using JiayiLauncher.Features.Mods;
Expand Down Expand Up @@ -157,7 +158,7 @@ public float[] MovementSpeed
public bool UseBackgroundImage
{
get => _themeState.ThemeStyles.GetProperty(":root", "--background-image")?.Value != "none";
set => _themeState.UpdateTheme("--background-image", value ? $"url('')" : "none");
set => _themeState.UpdateTheme("--background-image", value ? "url('')" : "none");

}

Expand Down Expand Up @@ -196,7 +197,7 @@ public string BackgroundImageUrl
if (Instance.UseBackgroundImage)
return Regex.Match(_themeState.ThemeStyles.GetProperty(":root", "--background-image")?.Value ?? "",
@"url\(\'(?<url>[^']+)\'\)").Groups["url"].Value;
_themeState.UpdateTheme("--background-image", $"none");
_themeState.UpdateTheme("--background-image", "none");
return string.Empty;
}
set
Expand All @@ -208,7 +209,8 @@ public string BackgroundImageUrl

[JsonIgnore]
[Setting("Generate palette from background", "Appearance",
"Create a color palette based on your background image. Videos are NOT supported.", "UseBackgroundImage")]
"Create a color palette based on your background image. Videos are NOT supported.", "UseBackgroundImage",
"Palette generation is memory intensive and may take a while. Every generated palette is slightly different.")]
public (string, Action) GeneratePalette { get; set; } = ("Generate", () =>
{
if (!Instance.UseBackgroundImage) return;
Expand Down
5 changes: 1 addition & 4 deletions JiayiLauncher/Shared/ThemeController.razor
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@

var theme = CssBuilder.FromFile(themeStyles);
theme.UpdateProperty(":root", new CssProperty("--background-image",
$"url('./themes/{JiayiSettings.Instance.Theme}/background.gif'), " +
$"url('./themes/{JiayiSettings.Instance.Theme}/background.png'), " +
$"url('./themes/{JiayiSettings.Instance.Theme}/background.jpg')"));
ThemeState.Instance.ApplyTheme(theme);
$"url('{JiayiSettings.Instance.BackgroundImageUrl}')"));

await base.OnInitializedAsync();
}
Expand Down

0 comments on commit 561e17b

Please sign in to comment.