Add SwiftLint HARD rules
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
import Foundation
|
||||
|
||||
struct ConvertArgument {
|
||||
|
||||
let width: String?
|
||||
let height: String?
|
||||
}
|
||||
|
@ -8,11 +8,13 @@
|
||||
import Foundation
|
||||
|
||||
enum TemplateRenderingIntent: String, Codable {
|
||||
|
||||
case template
|
||||
case original
|
||||
}
|
||||
|
||||
struct AssetContent: Codable, Equatable {
|
||||
|
||||
let images: [AssetImageDescription]
|
||||
let info: AssetInfo
|
||||
let properties: AssetProperties?
|
||||
@ -27,16 +29,17 @@ struct AssetContent: Codable, Equatable {
|
||||
self.properties = properties
|
||||
}
|
||||
|
||||
static func == (lhs: AssetContent, rhs: AssetContent) -> Bool {
|
||||
static func == (lhs: Self, rhs: Self) -> Bool {
|
||||
guard lhs.images.count == rhs.images.count else { return false }
|
||||
let lhsImages = lhs.images.sorted(by: { $0.filename < $1.filename })
|
||||
let rhsImages = rhs.images.sorted(by: { $0.filename < $1.filename })
|
||||
let lhsImages = lhs.images.sorted { $0.filename < $1.filename }
|
||||
let rhsImages = rhs.images.sorted { $0.filename < $1.filename }
|
||||
|
||||
return lhsImages == rhsImages
|
||||
}
|
||||
}
|
||||
|
||||
struct AssetImageDescription: Codable, Equatable {
|
||||
|
||||
let idiom: String
|
||||
let scale: String?
|
||||
let filename: String
|
||||
@ -53,11 +56,13 @@ struct AssetImageDescription: Codable, Equatable {
|
||||
}
|
||||
|
||||
struct AssetInfo: Codable, Equatable {
|
||||
|
||||
let version: Int
|
||||
let author: String
|
||||
}
|
||||
|
||||
struct AssetProperties: Codable, Equatable {
|
||||
|
||||
let preservesVectorRepresentation: Bool
|
||||
let templateRenderingIntent: TemplateRenderingIntent?
|
||||
|
||||
@ -70,6 +75,7 @@ struct AssetProperties: Codable, Equatable {
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
|
||||
case preservesVectorRepresentation = "preserves-vector-representation"
|
||||
case templateRenderingIntent = "template-rendering-intent"
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// ParsedImage.swift
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 24/01/2022.
|
||||
//
|
||||
@ -8,10 +8,14 @@
|
||||
import Foundation
|
||||
|
||||
enum ImageExtension: String {
|
||||
|
||||
case png
|
||||
}
|
||||
|
||||
struct ParsedImage {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
let name: String
|
||||
let tags: String
|
||||
let width: Int
|
||||
@ -33,34 +37,34 @@ struct ParsedImage {
|
||||
}
|
||||
|
||||
// MARK: - Convert
|
||||
|
||||
var convertArguments: (x1: ConvertArgument, x2: ConvertArgument, x3: ConvertArgument) {
|
||||
|
||||
var convertArguments: (x1: ConvertArgument, x2: ConvertArgument, x3: ConvertArgument) { // swiftlint:disable:this large_tuple
|
||||
var width1x = ""
|
||||
var height1x = ""
|
||||
var width2x = ""
|
||||
var height2x = ""
|
||||
var width3x = ""
|
||||
var height3x = ""
|
||||
|
||||
|
||||
if width != -1 {
|
||||
width1x = "\(width)"
|
||||
width2x = "\(width * 2)"
|
||||
width3x = "\(width * 3)"
|
||||
}
|
||||
|
||||
|
||||
if height != -1 {
|
||||
height1x = "\(height)"
|
||||
height2x = "\(height * 2)"
|
||||
height3x = "\(height * 3)"
|
||||
}
|
||||
|
||||
|
||||
return (x1: ConvertArgument(width: width1x, height: height1x),
|
||||
x2: ConvertArgument(width: width2x, height: height2x),
|
||||
x3: ConvertArgument(width: width3x, height: height3x))
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Assets
|
||||
|
||||
|
||||
func generateContentJson(isVector: Bool) -> String? {
|
||||
let encoder = JSONEncoder()
|
||||
encoder.outputFormatting = .prettyPrinted
|
||||
@ -77,9 +81,8 @@ struct ParsedImage {
|
||||
}
|
||||
|
||||
func generateImageContent(isVector: Bool) -> AssetContent {
|
||||
|
||||
if !imageExtensions.contains(.png) && isVector {
|
||||
//Generate svg
|
||||
// Generate svg
|
||||
return AssetContent(
|
||||
images: [
|
||||
AssetImageDescription(
|
||||
@ -97,7 +100,7 @@ struct ParsedImage {
|
||||
)
|
||||
)
|
||||
} else {
|
||||
//Generate png
|
||||
// Generate png
|
||||
return AssetContent(
|
||||
images: [
|
||||
AssetImageDescription(
|
||||
@ -125,17 +128,17 @@ struct ParsedImage {
|
||||
}
|
||||
|
||||
// MARK: - Extension property
|
||||
|
||||
|
||||
func getImageProperty(isStatic: Bool, isSwiftUI: Bool) -> String {
|
||||
if isSwiftUI {
|
||||
return """
|
||||
\(isStatic ? "static ": "")var \(name): Image {
|
||||
\(isStatic ? "static " : "")var \(name): Image {
|
||||
Image("\(name)")
|
||||
}
|
||||
"""
|
||||
}
|
||||
return """
|
||||
\(isStatic ? "static ": "")var \(name): UIImage {
|
||||
\(isStatic ? "static " : "")var \(name): UIImage {
|
||||
UIImage(named: "\(name)")!
|
||||
}
|
||||
"""
|
||||
|
@ -8,6 +8,7 @@
|
||||
import Foundation
|
||||
|
||||
enum PlatormTag: String {
|
||||
|
||||
case droid = "d"
|
||||
case ios = "i"
|
||||
}
|
||||
|
Reference in New Issue
Block a user