From 90e354d4dcba67bfee08b680d73de26b16d34558 Mon Sep 17 00:00:00 2001 From: Walker Fowlkes Date: Fri, 12 Apr 2024 20:16:42 -0700 Subject: [PATCH] missed a file --- .../brokenmoon/redcontrol/api/DriveFactory.kt | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/java/net/brokenmoon/redcontrol/api/DriveFactory.kt diff --git a/src/main/java/net/brokenmoon/redcontrol/api/DriveFactory.kt b/src/main/java/net/brokenmoon/redcontrol/api/DriveFactory.kt new file mode 100644 index 0000000..02be2f4 --- /dev/null +++ b/src/main/java/net/brokenmoon/redcontrol/api/DriveFactory.kt @@ -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>() + 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 { + fun execute(a1: A1,a2: A2,a3: A3,a4: A4): R +} \ No newline at end of file