- removed auto-theme option from settings
- added Colors library
- made LAB-based brightness identifier
This commit is contained in:
Observer KRypt0n_ 2021-11-13 14:02:18 +02:00
parent 09be222a1c
commit 316cbda838
No known key found for this signature in database
GPG key ID: DC5D4EC1303465DA
22 changed files with 152 additions and 57 deletions

View file

@ -14,7 +14,7 @@
| Game version | Launcher version | Patch version |
| :---: | :---: | :---: |
| 2.2.0 | 1.5.2 | 2.2.0 stable ✅ |
| 2.2.0 | 1.5.3 | 2.2.0 stable ✅ |
> ⚠️ New patch's version will be delayed for a week because of some author's personal reasons
@ -111,7 +111,7 @@ npm start
* <s>Add outdated files deletion when new game's update releases</s> *(1.1.0)*
* <s>Add installed packages deletion</s> *(1.2.0)*
* <s>Add voice packs support</s> (Thank @Maroxy for the developments in the previous versions) *(1.3.0)*
* <s>Color variants for progress bar's downloading text dependent on the background picture primary color</s> *(1.4.0)*
* <s>Color variants for progress bar's downloading text dependent on the background picture primary color</s> *(1.4.0, LAB-based in 1.5.3)*
* <s>Playing statistics</s> *(1.4.1)*
* <s>MangoHud support</s> (added HUD selector) *(1.5.0)*
* <s>Add vkBasalt support and "shaders library"</s> *(1.5.0)*

View file

@ -1,6 +1,6 @@
{
"name": "an-anime-game-launcher",
"version": "1.5.2",
"version": "1.5.3",
"description": "An Anime Game Linux Launcher",
"author": "Nikita Podvirnyy <suimin.tu.mu.ga.mi@gmail.com>",
"contributors": [

View file

@ -111,16 +111,6 @@
</div>
<br>
<div class="checkbox" id="auto-theme">
<span i18id="AutoTheme">Automatic theme switching</span>
<div class="checkbox-mark">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="45.701px" height="45.7px" viewBox="0 0 45.701 45.7" xml:space="preserve"><g><g><path d="M20.687,38.332c-2.072,2.072-5.434,2.072-7.505,0L1.554,26.704c-2.072-2.071-2.072-5.433,0-7.504 c2.071-2.072,5.433-2.072,7.505,0l6.928,6.927c0.523,0.522,1.372,0.522,1.896,0L36.642,7.368c2.071-2.072,5.433-2.072,7.505,0 c0.995,0.995,1.554,2.345,1.554,3.752c0,1.407-0.559,2.757-1.554,3.752L20.687,38.332z"/></g></g></svg>
</div>
</div>
<br>
</div>
<div class="settings-item" id="runners">

View file

@ -7,7 +7,6 @@
"Voice": "Sprachpaket",
"VoiceNotification": "Für diese Funktion müssen Sie das neue Sprachpaket manuell im Spiel auswählen.",
"PreInstallationRequired": "vorinstallation erforderlich",
"AutoTheme": "Automatische Themenumschaltung",
"ToggleShadersText": "Verwenden Sie die Home-Taste, um Shader im Spiel umzuschalten",
"Shaders": "Shadern",
"Author": "Autor",

View file

@ -7,7 +7,6 @@
"Voice": "Voice Pack",
"VoiceNotification": "This feature requires you to manually select the new voice pack in the game",
"PreInstallationRequired": "pre-installation required",
"AutoTheme": "Automatic theme switching",
"ToggleShadersText": "Use Home button to toggle shaders in the game",
"Shaders": "Shaders",
"Author": "Author",

View file

@ -7,7 +7,6 @@
"Voice": "Voice Pack",
"VoiceNotification": "This feature requires you to manually select the new voice pack in the game",
"PreInstallationRequired": "pre-installation required",
"AutoTheme": "Automatic theme switching",
"ToggleShadersText": "Use Home button to toggle shaders in the game",
"Shaders": "Shaders",
"Author": "Author",

View file

@ -7,7 +7,6 @@
"Voice": "Voice Pack",
"VoiceNotification": "This feature requires you to manually select the new voice pack in the game",
"PreInstallationRequired": "pre-installation required",
"AutoTheme": "Automatic theme switching",
"ToggleShadersText": "Use Home button to toggle shaders in the game",
"Shaders": "Shaders",
"Author": "Author",

View file

@ -7,7 +7,6 @@
"Voice": "Voice Pack",
"VoiceNotification": "This feature requires you to manually select the new voice pack in the game",
"PreInstallationRequired": "pre-installation required",
"AutoTheme": "Automatic theme switching",
"ToggleShadersText": "Use Home button to toggle shaders in the game",
"Shaders": "Shaders",
"Author": "Author",

View file

@ -7,7 +7,6 @@
"Voice": "Voice Pack",
"VoiceNotification": "This feature requires you to manually select the new voice pack in the game",
"PreInstallationRequired": "pre-installation required",
"AutoTheme": "Automatic theme switching",
"ToggleShadersText": "Use Home button to toggle shaders in the game",
"Shaders": "Shaders",
"Author": "Author",

View file

@ -7,7 +7,6 @@
"Voice": "ボイスパック",
"VoiceNotification": "この機能を使用するには、ゲーム内の新しいボイスパックを手動で選択する必要があります",
"PreInstallationRequired": "事前インストールが必要",
"AutoTheme": "テーマの自動切り替え",
"ToggleShadersText": "ホームボタンを使用してゲーム内のシェーダを切り替えます",
"Shaders": "シェーダ",
"Author": "著者",

View file

@ -7,7 +7,6 @@
"Voice": "음성 팩",
"VoiceNotification": "이 기능을 사용하려면 게임에서 새 음성 팩을 수동으로 선택해야합니다",
"PreInstallationRequired": "사전 설치 필요",
"AutoTheme": "자동 테마 전환",
"ToggleShadersText": "홈 버튼을 사용하여 게임에서 쉐이더를 전환하십시오",
"Shaders": "쉐이더",
"Author": "저자",

View file

@ -7,7 +7,6 @@
"Voice": "Voice Pack",
"VoiceNotification": "This feature requires you to manually select the new voice pack in the game",
"PreInstallationRequired": "pre-installation required",
"AutoTheme": "Automatic theme switching",
"ToggleShadersText": "Use Home button to toggle shaders in the game",
"Shaders": "Shaders",
"Author": "Author",

View file

@ -7,7 +7,6 @@
"Voice": "Озвучка",
"VoiceNotification": "Эта настройка требует ручного переключения языка озвучки в настройках игры",
"PreInstallationRequired": "требуется предустановка",
"AutoTheme": "Автопереключение темы",
"ToggleShadersText": "Используйте кнопку Home для переключения шейдеров в игре",
"Shaders": "Шейдеры",
"Author": "Автор",

View file

@ -7,7 +7,6 @@
"Voice": "Voice Pack",
"VoiceNotification": "This feature requires you to manually select the new voice pack in the game",
"PreInstallationRequired": "pre-installation required",
"AutoTheme": "Automatic theme switching",
"ToggleShadersText": "Use Home button to toggle shaders in the game",
"Shaders": "Shaders",
"Author": "Author",

View file

@ -7,7 +7,6 @@
"Voice": "Voice Pack",
"VoiceNotification": "This feature requires you to manually select the new voice pack in the game",
"PreInstallationRequired": "pre-installation required",
"AutoTheme": "Automatic theme switching",
"ToggleShadersText": "Use Home button to toggle shaders in the game",
"Shaders": "Shaders",
"Author": "Author",

View file

@ -7,7 +7,6 @@
"Voice": "语音包",
"VoiceNotification": "This feature requires you to manually select the new voice pack in the game",
"PreInstallationRequired": "pre-installation required",
"AutoTheme": "Automatic theme switching",
"ToggleShadersText": "Use Home button to toggle shaders in the game",
"Shaders": "Shaders",
"Author": "Author",

View file

@ -7,7 +7,6 @@
"Voice": "語音包",
"VoiceNotification": "This feature requires you to manually select the new voice pack in the game",
"PreInstallationRequired": "pre-installation required",
"AutoTheme": "Automatic theme switching",
"ToggleShadersText": "Use Home button to toggle shaders in the game",
"Shaders": "Shaders",
"Author": "Author",

View file

@ -24,6 +24,14 @@ if (!fs.existsSync(constants.runnersDir))
if (!fs.existsSync(constants.dxvksDir))
fs.mkdirSync(constants.dxvksDir, { recursive: true });
/**
* Compatibilities
*/
// 1.5.2 -> ^1.6.0 (removed auto-theme option)
if (typeof LauncherLib.getConfig('autotheme') == 'boolean')
LauncherLib.deleteConfig('autotheme');
$(() => {
document.title = `${constants.placeholders.uppercase.full} Linux Launcher`;

109
src/ts/lib/Colors.ts Normal file
View file

@ -0,0 +1,109 @@
export type RGB = {
r: number;
g: number;
b: number;
};
export type XYZ = {
x: number;
y: number;
z: number;
};
export type LAB = {
l: number;
a: number;
b: number;
};
/**
* Based on https://stackoverflow.com/a/59602352
*/
export class Colors
{
// X, Y, Z of a "D65" light source.
// "D65" is a standard 6500K Daylight light source.
// https://en.wikipedia.org/wiki/Illuminant_D65
public static readonly D65 = [95.047, 100, 108.883];
/**
* Converts RGB color to CIE 1931 XYZ color space.
* https://www.image-engineering.de/library/technotes/958-how-to-convert-between-srgb-and-ciexyz
*/
public static rgb2xyz (rgb: RGB): XYZ
{
rgb.r = this.sRGBtoLinearRGB(rgb.r / 255);
rgb.g = this.sRGBtoLinearRGB(rgb.g / 255);
rgb.b = this.sRGBtoLinearRGB(rgb.b / 255);
const xyz: XYZ = {
x: 100 * (0.4124 * rgb.r + 0.3576 * rgb.g + 0.1805 * rgb.b),
y: 100 * (0.2126 * rgb.r + 0.7152 * rgb.g + 0.0722 * rgb.b),
z: 100 * (0.0193 * rgb.r + 0.1192 * rgb.g + 0.9505 * rgb.b)
};
return xyz;
}
/**
* Undoes gamma-correction from an RGB-encoded color.
* https://en.wikipedia.org/wiki/SRGB#Specification_of_the_transformation
* https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color
*/
public static sRGBtoLinearRGB (color: number): number
{
// Send this function a decimal sRGB gamma encoded color value
// between 0.0 and 1.0, and it returns a linearized value.
return color <= 0.04045 ?
color / 12.92 :
Math.pow((color + 0.055) / 1.055, 2.4);
}
/**
* Converts CIE 1931 XYZ colors to CIE L*a*b*.
* The conversion formula comes from <http://www.easyrgb.com/en/math.php>.
* https://github.com/cangoektas/xyz-to-lab/blob/master/src/index.js
*/
public static xyz2lab (xyz: XYZ): LAB
{
xyz.x /= this.D65[0];
xyz.y /= this.D65[1];
xyz.z /= this.D65[2];
xyz.x = xyz.x > 0.008856 ? Math.pow(xyz.x, 1 / 3) : xyz.x * 7.787 + 16 / 116;
xyz.y = xyz.y > 0.008856 ? Math.pow(xyz.y, 1 / 3) : xyz.y * 7.787 + 16 / 116;
xyz.z = xyz.z > 0.008856 ? Math.pow(xyz.z, 1 / 3) : xyz.z * 7.787 + 16 / 116;
return {
l: 116 * xyz.y - 16,
a: 500 * (xyz.x - xyz.y),
b: 200 * (xyz.y - xyz.z)
};
}
/**
* Convert RGB to LAB
*/
public static rgb2lab (rgb: RGB): LAB
{
return this.xyz2lab(this.rgb2xyz(rgb));
}
/**
* Convert RGB to brightness level (0 - 100, black - white)
*/
public static rgb2brightness (rgb: RGB): number
{
rgb.r = this.sRGBtoLinearRGB(rgb.r / 255);
rgb.g = this.sRGBtoLinearRGB(rgb.g / 255);
rgb.b = this.sRGBtoLinearRGB(rgb.b / 255);
let y = 100 * (0.2126 * rgb.r + 0.7152 * rgb.g + 0.0722 * rgb.b) / this.D65[1];
y = y > 0.008856 ? Math.pow(y, 1 / 3) : y * 7.787 + 16 / 116;
return 116 * y - 16;
}
}

View file

@ -28,7 +28,6 @@ const config = new store ({
patch: null, // Installed patch info ({ version, state } - related game's version and patch's state)
runner: null, // Selected runner ({ folder, executable })
rpc: false, // Discord RPC
autotheme: true, // Automatic theme switcher
playtime: 0, // Number of seconds user spent in game
hud: 'none', // none / dxvk / mangohud
shaders: 'none', // none / shader's folder

View file

@ -4,6 +4,7 @@ import { constants } from './constants';
import { LauncherLib } from './LauncherLib';
import { i18n } from './i18n';
import { Tools } from './Tools';
import { Colors } from './Colors';
type LauncherState =
'patch-unavailable' |
@ -231,7 +232,7 @@ export class LauncherUI
public static updateBackground (): void
{
LauncherLib.getBackgroundUri().then(uri => {
let style = `url(${uri})`;
const style = `url(${uri})`;
if ($('body').css('background-image') != style)
{
@ -240,28 +241,39 @@ export class LauncherUI
/**
* Calculating background's left-bottom corner mean brightness
* to make the progress bar's theme dark or light
*/
if (LauncherLib.getConfig('autotheme'))
{
Tools.getImagePixels(uri).then(pixels => {
let sector = pixels.filter(pixel => pixel.y < 186 && pixel.x < 720);
let meanBrightness = 0;
*/
Tools.getImagePixels(uri).then(pixels => {
const sector = pixels.filter(pixel => pixel.y > 514 && pixel.x < 720);
sector.forEach(pixel => meanBrightness += pixel.color.r + pixel.color.g + pixel.color.b);
// For some strange reasons we can't
// make an object of r-g-b properties
let meanColor = [0, 0, 0];
// TODO: convert RGB mean color to LAB to get real background brightness
meanBrightness /= sector.length * 3;
console.log(`Background's mean brightness is ${meanBrightness}`);
// Image is dark so we make the progress bar light
if (meanBrightness < 160)
$('#downloader-panel').removeClass('dark');
// Otherwise image is bright so the progress bar should be dark
else $('#downloader-panel').addClass('dark');
sector.forEach(pixel => {
meanColor[0] += pixel.color.r;
meanColor[1] += pixel.color.g;
meanColor[2] += pixel.color.b;
});
}
meanColor = meanColor.map(_ => _ / sector.length);
const meanBrightness = Colors.rgb2brightness({
r: meanColor[0],
g: meanColor[1],
b: meanColor[2]
});
console.log(`Mean color: rgb(${Math.round(meanColor[0])},${Math.round(meanColor[1])},${Math.round(meanColor[2])})`);
console.log(`Background mean brightness is ${meanBrightness}`);
// Image is dark so we make the progress bar light
if (meanBrightness < 50)
$('#downloader-panel').removeClass('dark');
// Otherwise image is bright so the progress bar should be dark
else if (!$('#downloader-panel').hasClass('dark'))
$('#downloader-panel').addClass('dark');
});
}
});
}

View file

@ -99,15 +99,6 @@ $(() => {
ipcRenderer.send('rpc-toggle');
});
/**
* Automatic theme switcher
*/
if (LauncherLib.getConfig('autotheme'))
$('#auto-theme').addClass('checkbox-active');
$('#auto-theme').on('classChange', () => LauncherLib.updateConfig('autotheme', $('#auto-theme').hasClass('checkbox-active')));
/**
* Shaders
*/