Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun parse(path: String): Map<String, Map<String, Recipe>> {
- val config = JSON.parse<Json>(getFile(path))
- return config.iterator().asSequence().map { child ->
- Recipe(
- name = child["name"].toString(),
- category = child["category"].toString(),
- energy = child["energy"].toString().toFloat(),
- inputs = child["ingredients"].unsafeCast<Json>().iterator().asSequence().map {
- it["name"].toString() to it["amount"].toString().toInt()
- }.toList(),
- outputs = child["products"].unsafeCast<Json>().iterator().asSequence().map {
- it["name"].toString() to it["amount"].toString().toInt()
- }.toList()
- )
- }.groupBy({ it.category }, { (it.name to it) })
- .map { it.key to it.value.toMap() }
- .toMap()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement