Skip to content

Commit

Permalink
Fix Json
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarokIce committed Jun 2, 2024
1 parent 5a97979 commit b906e10
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/main/kotlin/club/someoneice/ovo/core/CoreHandler.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package club.someoneice.ovo.core

import club.someoneice.ovo.util.JsonHandler
import club.someoneice.ovo.util.gson
import com.google.gson.reflect.TypeToken
import club.someoneice.ovo.util.json
import cpw.mods.fml.common.Loader
import net.minecraft.block.Block
import net.minecraft.creativetab.CreativeTabs
Expand Down Expand Up @@ -41,9 +40,11 @@ class CoreHandler {
JsonHandler.dataScan(baseFile, packagePathList)

if (packagePathList.isEmpty()) return@run
fun readWithOriginal(file: File): HashMap<String, String>? {
val type = object: TypeToken<HashMap<String, String>>() {}.type
return gson.fromJson(file.readText(), type) as HashMap<String, String>?
fun readWithOriginal(file: File): HashMap<String, String> {
val map = HashMap<String, String>()
val raw = json.tryPullObjectOrEmpty(file.readText())
if (raw.isEmpty) return map
return map.apply { raw.obj.forEach { (k, v) -> this[k] = v.toString() } }
}

for (i in packagePathList) {
Expand All @@ -55,7 +56,7 @@ class CoreHandler {
}

OVOMain.Logger.info("Such OVO-Package: $i")
val modid = readWithOriginal(packageInfo)?.let { it["modid"] } ?: "ovo"
val modid = readWithOriginal(packageInfo)["modid"] ?: "ovo"
DataProcessor(packagePath, modid)

// if (OVOMain.ManaMetalModInstall) MMMCoreRunner("${basePath}\\${i}")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/club/someoneice/ovo/core/OVOMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class OVOMain {
@Mod.EventHandler
fun initializationModEvent(event: FMLInitializationEvent) {
Logger.info("OVO is Start loading!")
// TODO
CoreHandler()
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/club/someoneice/ovo/data/BlockData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data class BlockData (
val dropItem: ArrayList<Ingredient> = Lists.newArrayList(Ingredient("this", 1, 0)),
val group: String = "",

// 0: Simple, 1: All-sides, 2: Log
// 0: Simple, 1: All-Sides, 2: Log, 3: Tile-Entity
val rotationType: Int = 0
) {
fun registerBlock(): Block {
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/club/someoneice/ovo/util/JsonHandler.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package club.someoneice.ovo.util

import com.google.gson.reflect.TypeToken
import java.io.File
import java.lang.reflect.ParameterizedType

object JsonHandler {
fun <T> dataScan(file: File, list: ArrayList<T>) {
if (file.name.endsWith(".json5")) json5Reader(file.readText(), list)
else jsonReader(file.readText(), list)
json5Reader(file.readText(), list)
// else jsonReader(file.readText(), list)
}

private fun <T> json5Reader(text: String, list: ArrayList<T>) {
val dataClazz: Class<out T> = (list.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<out T>
list.addAll(json.tryPullAsClassList(dataClazz, text))
}

/*
private fun <T> jsonReader(text: String, list: ArrayList<T>) {
val type = object: TypeToken<List<T>>() {}.type
list.addAll(gson.fromJson(text, type) as List<T>)
}
*/
}
3 changes: 1 addition & 2 deletions src/main/kotlin/club/someoneice/ovo/util/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ fun EntityPlayer.giveOrThrowOut(item: ItemStack) {
this.worldObj.spawnEntityInWorld(EntityItem(this.worldObj, this.posX, this.posY, this.posZ, item))
}

val json: JSON = JSON.json5
val gson: Gson = GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create()
val json: JSON = JSON.json5

0 comments on commit b906e10

Please sign in to comment.