Skip to content

Commit

Permalink
📰 Remake Reader.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarokIce committed Aug 25, 2023
1 parent 01e8892 commit 597429b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 51 deletions.
13 changes: 1 addition & 12 deletions src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.google.gson.reflect.TypeToken
import cpw.mods.fml.common.Loader
import java.io.File
import java.io.FileNotFoundException
import java.nio.file.Files

class CoreRunner {
private val basePath: String = "${System.getProperty("user.dir")}\\ovo"
Expand Down Expand Up @@ -45,17 +44,7 @@ class CoreRunner {
private fun init() {
fun readWithOriginal(file: File): HashMap<String, String>? {
val type = object: TypeToken<HashMap<String, String>>() {}.type
val reader = Files.newInputStream(file.toPath())

return try {
val byte = ByteArray(file.length().toInt())
reader.read(byte)
reader.close()

gson.fromJson(String(byte), type) as HashMap<String, String>
} catch (_: Exception) {
null
}
return gson.fromJson(file.readText(), type) as HashMap<String, String>?
}

for (i in packagePathList) {
Expand Down
49 changes: 23 additions & 26 deletions src/main/kotlin/club/someoneice/ovo/core/JarRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class JarRunner {
val infoMappings: HashMap<String, JarUtil.UrlBuffered> = Maps.newHashMap()
fun <E>ArrayList<E>.addElement(e: E): ArrayList<E> {
this.add(e)
return this;
return this
}

for (buffered in JarUtil.getInstance().dataSet) {
val urlName = buffered.fileUrl;
val urlName = buffered.fileUrl
if (!urlName.contains("ovo/")) continue
val name = urlName.replace("ovo/", "").substring(0, urlName.replace("ovo/", "").indexOf("/"))
mappings[name] = mappings.getOrDefault(name, Lists.newArrayList()).addElement(buffered)
Expand All @@ -48,31 +48,28 @@ class JarRunner {
(gson.fromJson(JarUtil.getInstance().readFileFromUrl(infoMappings[key]), type) as HashMap<String, String>).let { it["modid"] }
for (url in mappings[key]!!) {
if (url == infoMappings[key]) continue
val fileName =
url.fileUrl.substring(url.fileUrl.lastIndexOf("/") + 1, url.fileUrl.lastIndexOf("."))
(
if (set.contains(fileName.lowercase())) fileName
else {
val path = url.fileUrl.replace("ovo/${key}/", "")
val filePath = path.substring(0, path.indexOf("/"))
if (set.contains(filePath.lowercase())) filePath
else null
}
)?.let {
val txt = JarUtil.getInstance().readFileFromUrl(url) ?: return@let
when (it.lowercase()) {
"Item".lowercase() -> CoreRunner.item.init (txt, DataList.dataItem)
"ItemFood".lowercase() -> CoreRunner.food.init (txt, DataList.dataItemFood)
"ItemGift".lowercase() -> CoreRunner.gift.init (txt, DataList.dataItemGift)
"ItemTool".lowercase() -> CoreRunner.tool.init (txt, DataList.dataItemTool)
"ItemWeapons".lowercase() -> CoreRunner.swords.init (txt, DataList.dataItemWeapons)
"Block".lowercase() -> CoreRunner.block.init (txt, DataList.dataBlock)
"Recipe".lowercase() -> CoreRunner.recipes.init (txt, DataList.dataRecipes)
"DeleteRecipe".lowercase() -> CoreRunner.delete_recipes.init (txt, DataList.dataDeleteRecipes)
"Biomes".lowercase() -> CoreRunner.biomes.init (txt, DataList.dataBiomes)
"Group".lowercase() -> CoreRunner.group.init (txt, DataList.dataGroup)
}
val fileName = url.fileUrl.substring(url.fileUrl.lastIndexOf("/") + 1, url.fileUrl.lastIndexOf("."))
if (set.contains(fileName.lowercase())) fileName
else {
val path = url.fileUrl.replace("ovo/${key}/", "")
val filePath = path.substring(0, path.indexOf("/"))
if (set.contains(filePath.lowercase())) filePath
else null
}?.let {
val txt = JarUtil.getInstance().readFileFromUrl(url) ?: return@let
when (it.lowercase()) {
"Item".lowercase() -> CoreRunner.item.init (txt, DataList.dataItem)
"ItemFood".lowercase() -> CoreRunner.food.init (txt, DataList.dataItemFood)
"ItemGift".lowercase() -> CoreRunner.gift.init (txt, DataList.dataItemGift)
"ItemTool".lowercase() -> CoreRunner.tool.init (txt, DataList.dataItemTool)
"ItemWeapons".lowercase() -> CoreRunner.swords.init (txt, DataList.dataItemWeapons)
"Block".lowercase() -> CoreRunner.block.init (txt, DataList.dataBlock)
"Recipe".lowercase() -> CoreRunner.recipes.init (txt, DataList.dataRecipes)
"DeleteRecipe".lowercase() -> CoreRunner.delete_recipes.init (txt, DataList.dataDeleteRecipes)
"Biomes".lowercase() -> CoreRunner.biomes.init (txt, DataList.dataBiomes)
"Group".lowercase() -> CoreRunner.group.init (txt, DataList.dataGroup)
}
}
}

DataProcessor(modid).init()
Expand Down
24 changes: 12 additions & 12 deletions src/main/kotlin/club/someoneice/ovo/core/object/DataList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import net.minecraft.creativetab.CreativeTabs

object DataList {
// Retain this map for other package to use.
var getGroup :HashMap<String, CreativeTabs> = Maps.newHashMap()
val getGroup :HashMap<String, CreativeTabs> = Maps.newHashMap()

var dataItem :ArrayList<ItemData> = Lists.newArrayList()
var dataItemGift :ArrayList<ItemGift> = Lists.newArrayList()
var dataItemFood :ArrayList<ItemFood> = Lists.newArrayList()
var dataItemTool :ArrayList<ItemTool> = Lists.newArrayList()
var dataItemWeapons :ArrayList<ItemWeapon> = Lists.newArrayList()
var dataBlock :ArrayList<BlockData> = Lists.newArrayList()
val dataItem :ArrayList<ItemData> = Lists.newArrayList()
val dataItemGift :ArrayList<ItemGift> = Lists.newArrayList()
val dataItemFood :ArrayList<ItemFood> = Lists.newArrayList()
val dataItemTool :ArrayList<ItemTool> = Lists.newArrayList()
val dataItemWeapons :ArrayList<ItemWeapon> = Lists.newArrayList()
val dataBlock :ArrayList<BlockData> = Lists.newArrayList()

var dataBiomes :ArrayList<BiomesData> = Lists.newArrayList()
var dataGroup :ArrayList<Group> = Lists.newArrayList()
var dataRecipes :ArrayList<Recipe> = Lists.newArrayList()
var dataDeleteRecipes :ArrayList<String> = Lists.newArrayList()
val dataBiomes :ArrayList<BiomesData> = Lists.newArrayList()
val dataGroup :ArrayList<Group> = Lists.newArrayList()
val dataRecipes :ArrayList<Recipe> = Lists.newArrayList()
val dataDeleteRecipes :ArrayList<String> = Lists.newArrayList()

// Clean all of the data list.
// Clean all the data list.
fun init() {
dataItem.clear()
dataBlock.clear()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/club/someoneice/ovo/json/JsonReaderBean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class JsonReaderBean<T> {
* @return Input the originalList, the object for return will put into the originalList.
* */
fun init(file: File, originalList: ArrayList<T>) {
this.init(file.reader().readText(), originalList)
this.init(file.readText(), originalList)
}

fun init(file: String, originalList: ArrayList<T>) {
Expand Down

0 comments on commit 597429b

Please sign in to comment.