custom asset archive loading

This commit is contained in:
minjaesong
2026-02-20 13:23:32 +09:00
parent 2dea82bb9c
commit 97d22913bf
7 changed files with 72 additions and 28 deletions

View File

@@ -1,11 +1,14 @@
package net.torvald.terrarum
import com.badlogic.gdx.Files
import com.badlogic.gdx.files.FileHandle
import com.badlogic.gdx.utils.GdxRuntimeException
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.archivers.Clustfile
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.archivers.ClustfileInputStream
import java.io.File
import java.io.InputStream
/**
* A GDX FileHandle backed by a Clustfile from TerranVirtualDisk.
* Allows transparent asset loading from .tevd archives using all standard GDX APIs.
@@ -30,6 +33,10 @@ class ClustfileHandle(private val clustfile: Clustfile) : FileHandle() {
override fun path(): String = clustfile.path
init {
type = Files.FileType.Internal // just a dummy value
}
override fun extension(): String {
val n = name()
val dotIndex = n.lastIndexOf('.')
@@ -62,5 +69,12 @@ class ClustfileHandle(private val clustfile: Clustfile) : FileHandle() {
return File(clustfile.path)
}
override fun sibling(name: String?): FileHandle {
if (name == null) throw GdxRuntimeException("Sibling name must not be null.")
val parentPath = clustfile.parent ?: throw GdxRuntimeException("Cannot get the sibling of the root.")
val siblingPath = if (parentPath.endsWith("/")) "$parentPath$name" else "$parentPath/$name"
return ClustfileHandle(Clustfile(clustfile.DOM, siblingPath))
}
override fun toString(): String = clustfile.path
}