mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 20:14:05 +09:00
modules can now have their own config files
This commit is contained in:
@@ -11,7 +11,7 @@ object JsonFetcher {
|
||||
|
||||
private var jsonString: StringBuffer? = null
|
||||
|
||||
@Throws(java.nio.file.NoSuchFileException::class)
|
||||
@Throws(java.io.IOException::class)
|
||||
operator fun invoke(jsonFilePath: String): JsonValue {
|
||||
jsonString = StringBuffer() // reset buffer every time it called
|
||||
readJsonFileAsString(jsonFilePath)
|
||||
@@ -25,7 +25,7 @@ object JsonFetcher {
|
||||
return JsonReader().parse(jsonString.toString())
|
||||
}
|
||||
|
||||
@Throws(java.nio.file.NoSuchFileException::class)
|
||||
@Throws(java.io.IOException::class)
|
||||
operator fun invoke(jsonFile: java.io.File): JsonValue {
|
||||
jsonString = StringBuffer() // reset buffer every time it called
|
||||
readJsonFileAsString(jsonFile.canonicalPath)
|
||||
@@ -39,7 +39,7 @@ object JsonFetcher {
|
||||
return JsonReader().parse(jsonString.toString())
|
||||
}
|
||||
|
||||
@Throws(java.nio.file.NoSuchFileException::class)
|
||||
@Throws(java.io.IOException::class)
|
||||
private fun readJsonFileAsString(path: String) {
|
||||
java.nio.file.Files.lines(java.nio.file.FileSystems.getDefault().getPath(path)).forEach(
|
||||
{ jsonString!!.append(it) }
|
||||
@@ -63,6 +63,12 @@ object JsonFetcher {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates [JsonValue] over its siblings.
|
||||
*
|
||||
* @param map JsonValue to iterate over
|
||||
* @param action A `function(index, `Name of the sibling or a stringified integer if the `map` is an array`, `JsonValue representation of the sibling`)` -> `Unit`
|
||||
*/
|
||||
fun forEachSiblingsIndexed(map: JsonValue, action: (Int, String, JsonValue) -> Unit) {
|
||||
var counter = 0
|
||||
var entry = map.child
|
||||
@@ -74,5 +80,13 @@ object JsonFetcher {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates [JsonValue] over its siblings.
|
||||
* @param action A function(`Name of the sibling or a stringified integer if the `map` is an array`, `JsonValue representation of the sibling`)` -> `Unit`
|
||||
*/
|
||||
fun JsonValue.forEachSiblings(action: (String, JsonValue) -> Unit) = JsonFetcher.forEachSiblings(this, action)
|
||||
/**
|
||||
* Iterates [JsonValue] over its siblings.
|
||||
* @param action A `function(index, `Name of the sibling or a stringified integer if the `map` is an array`, `JsonValue representation of the sibling`)` -> `Unit`
|
||||
*/
|
||||
fun JsonValue.forEachSiblingsIndexed(action: (Int, String, JsonValue) -> Unit) = JsonFetcher.forEachSiblingsIndexed(this, action)
|
||||
Reference in New Issue
Block a user