/**
* Generate OLL SVG images.
*
* This reads oll-images.def and renders one image for each non-comment line defined there.
*
* Let's go for something new, so why not do this in Kotlin - https://kotlinlang.org/ :-)
*
* 29Aug2016
*/
package de.rtner.ollgen
import java.io.File
val ITEMS = hashMapOf(//
'1' to Pair("""""", "ad"),
'2' to Pair("""""", "b"),
'3' to Pair("""""", "ce"),
'4' to Pair("""""", "f"),
'5' to Pair("""""", ""),
'6' to Pair("""""", "g"),
'7' to Pair("""""", "hj"),
'8' to Pair("""""", "k"),
'9' to Pair("""""", "il"),
'#' to Pair("""
""", ""),
'a' to Pair("""""", "d"),
'b' to Pair("""""", ""),
'c' to Pair("""""", "e"),
'd' to Pair("""""", "a"),
'e' to Pair("""""", "c"),
'f' to Pair("""""", ""),
'g' to Pair("""""", ""),
'h' to Pair("""""", "j"),
'i' to Pair("""""", "l"),
'j' to Pair("""""", "h"),
'k' to Pair("""""", ""),
'l' to Pair("""""", "i")
)
val svgFrame = File("oll-frame.svg").readText().split("")
var outputDir = File("cube-oll")
public class OLLLine {
val fn: String
val pattern: String
constructor(line: String) {
val s = line.split(":")
fn = s[0]
pattern = s[1]
}
fun createSvg() {
val sb = StringBuilder(svgFrame[0])
val items = pattern.toList()
val reduced = pattern.toMutableList()
items.forEach { item ->
ITEMS.get(item)?.let { pair ->
if( reduced.contains(item) ) {
reduced.removeAll(pair.second.toSet())
}
}
}
reduced.forEach { item ->
ITEMS.get(item)?.let {
sb.append("\t${it.first}\n")
}
}
sb.append(svgFrame[1])
val v = sb.toString()
File(outputDir,fn).writeText(v)
println("Created ${fn}")
}
}
fun main(args: Array) {
outputDir.mkdirs()
File("oll-images.def").useLines {
it.forEach { line ->
val t = line.trim()
if (t != "" && !t.startsWith('#')) {
OLLLine(line).createSvg()
}
}
}
}