mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-16 05:24:06 +09:00
custom asset archive loading
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user