TechPickerScreen colors - skinnable and prettier Future Tech (#9033)

This commit is contained in:
SomeTroglodyte
2023-03-25 19:34:49 +01:00
committed by GitHub
parent 708daf9816
commit 09cff6e55f
4 changed files with 37 additions and 18 deletions

View File

@ -20,17 +20,28 @@ class UiElementDocsWriter {
val startIndex = originalLines.indexOf(startMarker).takeIf { it != -1 } ?: (endIndex + 1)
val elements = mutableListOf<String>()
val backgroundRegex = Regex("""getUiBackground\((\X*?)"(?<path>.*)"[ ,\n\r]*((BaseScreen\.)?skinStrings\.(?<default>.*)Shape)?\X*?\)""")
val colorRegex = Regex("""
getUIColor\s*\(\s* # function call, whitespace around opening round bracket optional. All \s also allow line breaks!
"(?<path>[^"]*)"\s* # captures "path", anything between double-quotes, not allowing for embedded quotes
(?:,\s* # group for optional default parameter
(?:default\s*=\s*)? # allow for named parameter
(?:Colors\s*\(|colorFromRGB\s*\(|Color\.) # recognize only Color constructor, colorFromRGB helper, or Color.* constants as argument
(?<default>[^)]*) # capture "default" up until a closing round bracket
)\s*\) # ends default parameter group and checks closing round bracket of the getUIColor call
""", RegexOption.COMMENTS)
for (file in srcFile.walk()) {
if (file.path.endsWith(".kt")) {
val results = Regex("getUiBackground\\((\\X*?)\"(?<path>.*)\"[ ,\n\r]*((BaseScreen\\.)?skinStrings\\.(?<defaultShape>.*)Shape)?\\X*?\\)")
.findAll(file.readText())
for (result in results) {
val sourceText = file.readText()
val matches: Sequence<MatchResult> =
backgroundRegex.findAll(sourceText) + colorRegex.findAll(sourceText)
for (result in matches) {
val path = result.groups["path"]?.value
val name = path?.takeLastWhile { it != '/' } ?: ""
val defaultShape = result.groups["defaultShape"]?.value
val default = result.groups["default"]?.value
if (name.isNotBlank())
elements.add("| ${path!!.dropLast(name.length)} | $name | $defaultShape | |")
elements.add("| ${path!!.dropLast(name.length)} | $name | $default | |")
}
}
}