Skip to content

Commit

Permalink
fixed incorrect iphone contents.json issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kindlychung committed Dec 17, 2016
1 parent 0e4eae0 commit 0fe7ebc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Binary file not shown.
10 changes: 8 additions & 2 deletions genicon/dataModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,25 @@ public struct Info: Jsonifiable {
}
}

public enum Platform: String {
case mac = "mac"
case iphone = "iphone"
}

public struct ImageInfo: Jsonifiable {
let size: String
let scale: String
let idiom = "mac"
private var idiom = ""
var filename: String
let realSize: Int
let realSizeString: String
public init(size sz: Int, scale sc: Int) {
public init(size sz: Int, scale sc: Int, platform: Platform) {
realSize = sz * sc
realSizeString = sizeString(realSize)
size = sizeString(sz)
scale = scaleString(sc)
filename = iconFilename(sizeString: realSizeString)
idiom = platform.rawValue
}
var json: String {
let sizeJson = jsonify(pair: ("size", size), quoteValue: true)
Expand Down
8 changes: 4 additions & 4 deletions genicon/generateJson.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

import Foundation

public func generateContents(sizes: [Int], scales: [Int]) -> Contents {
public func generateContents(sizes: [Int], scales: [Int], platform: Platform) -> Contents {
var contents = Contents()
for sz in sizes {
for sc in scales {
let img = ImageInfo(size: sz, scale: sc)
let img = ImageInfo(size: sz, scale: sc, platform: platform)
contents.images.append(img)
}
}
Expand All @@ -21,5 +21,5 @@ public func generateContents(sizes: [Int], scales: [Int]) -> Contents {

public let macSizes = [16, 32, 128, 512]
public let macScales = [1, 2]
public let iosSizes = [20, 29, 40, 60]
public let iosScales = [2, 3]
public let iphoneSizes = [20, 29, 40, 60]
public let iphoneScales = [2, 3]
12 changes: 6 additions & 6 deletions genicon/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

let args = CommandLine.arguments
if args.contains("--help") || args.contains("-h") || args.dropFirst().isEmpty {
print("\n genicon: A command line tool for generating icons for Cocoa apps.\n", "© Kaiyin Zhong 2016\n\n", "Usage: \n", "genicon [options] INPUT OUTPUT_FOLDER\n\n", "--help, -h Print this message.\n", "--mac Generate icons for macOS.\n", "--ios Generate icons for iOS. When neither --mac nor --ios is given, mac icons are generated by default.\n")
print("\n genicon: A command line tool for generating icons for Cocoa apps.\n", "© Kaiyin Zhong 2016\n\n", "Usage: \n", "genicon [options] INPUT OUTPUT_FOLDER\n\n", "--help, -h Print this message.\n", "--mac Generate icons for macOS.\n", "--iphone Generate icons for iPhone. When neither --mac nor --iphone is given, mac icons are generated by default.\n")
exit(0)
}

Expand Down Expand Up @@ -39,11 +39,11 @@ do {

// generate Contents.json
var contents: Contents = Contents()
// when neither --mac nor --ios is given, mac icons are generated by default.
if args.contains("--mac") || !args.contains("--ios"){
contents = generateContents(sizes: macSizes, scales: macScales)
} else if args.contains("--ios") {
contents = generateContents(sizes: iosSizes, scales: iosScales)
// when neither --mac nor --iphone is given, mac icons are generated by default.
if args.contains("--mac") || !args.contains("--iphone"){
contents = generateContents(sizes: macSizes, scales: macScales, platform: .mac)
} else if args.contains("--iphone") {
contents = generateContents(sizes: iphoneSizes, scales: iphoneScales, platform: .iphone)
}

let jsonFilename = "Contents.json"
Expand Down

0 comments on commit 0fe7ebc

Please sign in to comment.