missed a file

main
Walker Fowlkes 7 months ago
parent 8cd16f5d92
commit 90e354d4dc

@ -0,0 +1,49 @@
package net.brokenmoon.redcontrol.api
import com.simon816.j65el02.device.ByteDiskDriver
import com.simon816.j65el02.device.DiskDriver
import com.simon816.j65el02.device.FileDiskDriver
import net.brokenmoon.redcontrol.RedControl
import net.fabricmc.loader.api.FabricLoader
import net.minecraft.data.client.BlockStateVariantMap.TriFunction
import java.net.URI
import kotlin.io.path.absolute
import kotlin.io.path.createDirectories
import kotlin.io.path.exists
object DriveFactory {
private val gamedir = FabricLoader.getInstance().gameDir.resolve("redbin").absolute()
val extendedDrivers = HashMap<String,TriFunction<URI,String,String,DiskDriver?>>()
fun createDriver(uri: URI, name: String, serial: String): DiskDriver? {
if (!gamedir.exists()) {gamedir.createDirectories()}
return when (uri.scheme) {
"img" -> {
val bytes = RedControl.images[uri.host+uri.path]?: return null
ByteDiskDriver(bytes,name,serial)
}
"save" -> {
val path = gamedir.resolve(uri.host+uri.path).absolute()
if (path.startsWith(gamedir)) {
return FileDiskDriver(path,name,serial,false)
} else { return null }
}
"rosave" -> {
val path = gamedir.resolve(uri.host+uri.path).absolute()
if (path.startsWith(gamedir)) {
return FileDiskDriver(path,name,serial,false)
} else { return null }
}
"http", "https" -> {return null}
else -> {
if (extendedDrivers.containsKey(uri.scheme)) {
return extendedDrivers[uri.scheme]!!.apply(uri,name,serial)
} else {return null}
}
}
}
}
@FunctionalInterface
interface PentaFunction<A1,A2,A3,A4,R> {
fun execute(a1: A1,a2: A2,a3: A3,a4: A4): R
}
Loading…
Cancel
Save