Bugs fixes, Lint fixes, Refactoring
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit

This commit is contained in:
2022-08-29 13:38:46 +02:00
parent e3f90e0d48
commit a54a264447
35 changed files with 652 additions and 401 deletions

View File

@ -0,0 +1,13 @@
//
// File.swift
//
//
// Created by Thibaut Schmitt on 29/08/2022.
//
import Foundation
enum ColorStyle: String, Decodable {
case light
case all
}

View File

@ -0,0 +1,92 @@
//
// ParsedColor.swift
//
//
// Created by Thibaut Schmitt on 20/12/2021.
//
import Foundation
struct ParsedColor {
let name: String
let light: String
let dark: String
// Generate Contents.json content
func contentsJSON() -> String {
let lightARGB = light.colorComponent()
let darkARGB = dark.colorComponent()
let allComponents = [
lightARGB.alpha, lightARGB.red, lightARGB.green, lightARGB.blue,
darkARGB.alpha, darkARGB.red, darkARGB.green, darkARGB.blue
].map {
$0.isEmpty
}
guard allComponents.contains(true) == false else {
let error = ColorToolError.badColorDefinition(light, dark)
print(error.localizedDescription)
ColorTool.exit(withError: error)
}
return """
{
"colors": [
{
"color": {
"color-space": "srgb",
"components": {
"alpha": "0x\(lightARGB.alpha)",
"blue": "0x\(lightARGB.blue)",
"green": "0x\(lightARGB.green)",
"red": "0x\(lightARGB.red)",
}
},
"idiom": "universal"
},
{
"appearances": [
{
"appearance": "luminosity",
"value": "dark"
}
],
"color": {
"color-space": "srgb",
"components": {
"alpha": "0x\(darkARGB.alpha)",
"blue": "0x\(darkARGB.blue)",
"green": "0x\(darkARGB.green)",
"red": "0x\(darkARGB.red)",
}
},
"idiom": "universal"
}
],
"info": {
"author": "xcode",
"version": 1
}
}
"""
}
func getColorProperty() -> String {
"""
/// Color \(name) is \(light) (light) or \(dark) (dark)"
@objc var \(name): UIColor {
UIColor(named: "\(name)")!
}
"""
}
func getColorStaticProperty() -> String {
"""
/// Color \(name) is \(light) (light) or \(dark) (dark)"
static var \(name): UIColor {
UIColor(named: "\(name)")!
}
"""
}
}