generated from SteamDeckHomebrew/Plugin-Template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
30 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,47 @@ | ||
import { classMap } from "decky-frontend-lib"; | ||
|
||
export var classHashMap = new Map<string, string>(); | ||
|
||
export function initializeClassHashMap() { | ||
const withoutLocalizationClasses = classMap.filter((module) => Object.keys(module).length < 1000); | ||
|
||
const allClasses = withoutLocalizationClasses | ||
.map((module) => { | ||
let filteredModule = {}; | ||
Object.entries(module).forEach(([propertyName, value]) => { | ||
// Filter out things that start with a number (eg: Breakpoints like 800px) | ||
// I have confirmed the new classes don't start with numbers | ||
if (isNaN(Number(value.charAt(0)))) { | ||
filteredModule[propertyName] = value; | ||
} | ||
}); | ||
return filteredModule; | ||
}) | ||
.filter((module) => { | ||
// Some modules will be empty after the filtering, remove those | ||
return Object.keys(module).length > 0; | ||
}); | ||
|
||
const mappings = allClasses.reduce((acc, cur) => { | ||
Object.entries(cur).forEach(([property, value]) => { | ||
if (acc[property]) { | ||
acc[property].push(value); | ||
} else { | ||
acc[property] = [value]; | ||
} | ||
}); | ||
return acc; | ||
}, {}); | ||
|
||
const hashMapNoDupes = Object.entries<string[]>(mappings).reduce<Map<string, string>>( | ||
(acc, entry) => { | ||
if (entry[1].length === 1) { | ||
acc.set(entry[1][0], entry[0]); | ||
} | ||
return acc; | ||
}, | ||
new Map() | ||
); | ||
|
||
classHashMap = hashMapNoDupes; | ||
} |
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