-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from doki-theme/editorColor
Usability & Consistency Maintenance
- Loading branch information
Showing
74 changed files
with
1,008 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import path from "path"; | ||
import fs from "fs"; | ||
import {masterThemesDirectory, walkAndBuildTemplates} from "./BuildFunctions"; | ||
import {MasterDokiThemeDefinition} from "doki-build-source"; | ||
|
||
console.log("Preparing to create color."); | ||
|
||
type RGBArray = [number, number, number, number]; | ||
|
||
function hex_to_rgba(a: string): RGBArray { | ||
'#' == a[0] && (a = a.substring(1)); | ||
6 > a.length && (a += '000000'.substr(0, 6 - a.length)); | ||
return [parseInt(a.substring(0, 2), 16), | ||
parseInt(a.substring(2, 4), 16), | ||
parseInt(a.substring(4, 6), 16), | ||
a.length > 6 ? parseInt(a.substring(6, 8), 16) : 0xFF | ||
]; | ||
} | ||
|
||
function rgb_to_hex(a: RGBArray) { | ||
const b = (a[2] | a[1] << 8 | a[0] << 16).toString(16); | ||
return '000000'.substr(0, 6 - b.length) + b; | ||
} | ||
|
||
function blendColors( | ||
base: RGBArray, | ||
added: RGBArray, | ||
): RGBArray { | ||
const mix = []; | ||
const overlayAlpha = added[3] / 0xFF; | ||
const baseAlpha = base[3] / 0xFF; | ||
mix[3] = 1 - (1 - overlayAlpha) * (1 - baseAlpha); // alpha | ||
mix[0] = Math.round((added[0] * overlayAlpha / mix[3]) + (base[0] * baseAlpha * (1 - overlayAlpha) / mix[3])); // red | ||
mix[1] = Math.round((added[1] * overlayAlpha / mix[3]) + (base[1] * baseAlpha * (1 - overlayAlpha) / mix[3])); // green | ||
mix[2] = Math.round((added[2] * overlayAlpha / mix[3]) + (base[2] * baseAlpha * (1 - overlayAlpha) / mix[3])); // blue | ||
return mix as RGBArray; | ||
} | ||
|
||
function addNewColor(dokiTheme: { dokiThemeDefinition: MasterDokiThemeDefinition; dokiFileDefinitionPath: string }) { | ||
if(!dokiTheme.dokiThemeDefinition.dark) return; | ||
|
||
const baseColor = hex_to_rgba( | ||
dokiTheme.dokiThemeDefinition.colors.headerColor | ||
); | ||
const overlayColor = hex_to_rgba( | ||
"#1a8bff30", | ||
) | ||
const gray = hex_to_rgba("#6f6f6f30") | ||
const orange = hex_to_rgba("#e57e1a50") | ||
const rose = hex_to_rgba("#c03a7f30") | ||
const violet = hex_to_rgba("#6441d030") | ||
const yellow = hex_to_rgba("#d3cb2f25") | ||
const red = hex_to_rgba("#d0222225") | ||
const purple = hex_to_rgba("#701fd025") | ||
|
||
dokiTheme.dokiThemeDefinition.colors["fileYellow"] = '#' + rgb_to_hex(blendColors(baseColor, yellow)) | ||
dokiTheme.dokiThemeDefinition.colors["fileRed"] = '#' + rgb_to_hex(blendColors(baseColor, red)) | ||
dokiTheme.dokiThemeDefinition.colors["filePurple"] = '#' + rgb_to_hex(blendColors(baseColor, purple)) | ||
} | ||
|
||
walkAndBuildTemplates() | ||
.then((dokiThemes) => { | ||
return dokiThemes | ||
.reduce( | ||
(accum, dokiTheme) => | ||
accum.then(() => { | ||
addNewColor(dokiTheme); | ||
fs.writeFileSync(dokiTheme.dokiFileDefinitionPath, | ||
JSON.stringify(dokiTheme.dokiThemeDefinition, null, 2) | ||
); | ||
|
||
return Promise.resolve("dun") | ||
}), | ||
Promise.resolve("") | ||
); | ||
}) | ||
.then(() => { | ||
console.log("Color Creation Complete!"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.