assets manager: rename nullGet to getOrNull

This commit is contained in:
Bixilon 2022-05-10 22:57:52 +02:00
parent fe35f3fed3
commit 305e0fcb75
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
9 changed files with 15 additions and 15 deletions

View File

@ -49,7 +49,7 @@ interface AssetsManager {
/**
* Returns the input stream of an asset or null
*/
fun nullGet(path: ResourceLocation): InputStream?
fun getOrNull(path: ResourceLocation): InputStream?
/**
* Loads all assets

View File

@ -75,7 +75,7 @@ class DirectoryAssetsManager(
return FileUtil.readFile(path.filePath, false)
}
override fun nullGet(path: ResourceLocation): InputStream? {
override fun getOrNull(path: ResourceLocation): InputStream? {
if (path !in assets) {
return null
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -36,7 +36,7 @@ abstract class FileAssetsManager(private val canUnload: Boolean = true) : Assets
return ByteArrayInputStream(assets[path] ?: throw FileNotFoundException("Can not find asset $path"))
}
override fun nullGet(path: ResourceLocation): InputStream? {
override fun getOrNull(path: ResourceLocation): InputStream? {
return ByteArrayInputStream(assets[path] ?: return null)
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -123,7 +123,7 @@ class JarAssetsManager(
return ByteArrayInputStream(jarAssets[path.path] ?: throw FileNotFoundException("Can not find asset: $path"))
}
override fun nullGet(path: ResourceLocation): InputStream? {
override fun getOrNull(path: ResourceLocation): InputStream? {
if (path.namespace != ProtocolDefinition.DEFAULT_NAMESPACE) {
return null
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -140,7 +140,7 @@ class IndexAssetsManager(
return FileUtil.readFile(FileAssetsUtil.getPath(assets[path]?.hash ?: throw FileNotFoundException("Could not find asset $path")))
}
override fun nullGet(path: ResourceLocation): InputStream? {
override fun getOrNull(path: ResourceLocation): InputStream? {
return FileUtil.readFile(FileAssetsUtil.getPath(assets[path]?.hash ?: return null))
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -64,13 +64,13 @@ class PriorityAssetsManager(
operator fun plusAssign(manager: AssetsManager) = add(manager)
override fun get(path: ResourceLocation): InputStream {
return nullGet(path) ?: throw FileNotFoundException("Can not find assets-manager for $path")
return getOrNull(path) ?: throw FileNotFoundException("Can not find assets-manager for $path")
}
override fun nullGet(path: ResourceLocation): InputStream? {
override fun getOrNull(path: ResourceLocation): InputStream? {
val managers = this.managers[path.namespace] ?: return null
for (manager in managers) {
return manager.nullGet(path) ?: continue
return manager.getOrNull(path) ?: continue
}
return null
}

View File

@ -38,7 +38,7 @@ class PowderSnowOverlay(renderWindow: RenderWindow, z: Float) : SimpleOverlay(re
private val OVERLAY_TEXTURE = "misc/powder_snow_outline".toResourceLocation().texture()
override fun build(renderWindow: RenderWindow, z: Float): PowderSnowOverlay? {
if (renderWindow.connection.assetsManager.nullGet(OVERLAY_TEXTURE) == null) { // ToDo: Don't get twice
if (renderWindow.connection.assetsManager.getOrNull(OVERLAY_TEXTURE) == null) { // ToDo: Don't get twice
// overlay not yet available (< 1.17)
return null
}

View File

@ -35,7 +35,7 @@ class WorldBorderOverlay(renderWindow: RenderWindow, z: Float) : SimpleOverlay(r
private val OVERLAY_TEXTURE = "misc/vignette".toResourceLocation().texture()
override fun build(renderWindow: RenderWindow, z: Float): WorldBorderOverlay? {
if (renderWindow.connection.assetsManager.nullGet(OVERLAY_TEXTURE) == null) { // ToDo: Don't get twice
if (renderWindow.connection.assetsManager.getOrNull(OVERLAY_TEXTURE) == null) { // ToDo: Don't get twice
// overlay not yet available (< 1.17)
return null
}

View File

@ -81,7 +81,7 @@ class OpenGLTextureArray(
private fun readImageProperties(texture: ResourceLocation): ImageProperties? {
try {
val data = renderWindow.connection.assetsManager.nullGet("$texture.mcmeta".toResourceLocation())?.readAsString() ?: return null
val data = renderWindow.connection.assetsManager.getOrNull("$texture.mcmeta".toResourceLocation())?.readAsString() ?: return null
return Jackson.MAPPER.readValue(data, ImageProperties::class.java)
} catch (error: Throwable) {
error.printStackTrace()