mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
Inventory UI on ingame
This commit is contained in:
@@ -75,7 +75,7 @@ internal class Filesystem(globals: Globals, computer: TerrarumComputer) {
|
||||
* return value is there for chaining only.
|
||||
*/
|
||||
fun VDPath.dropMount(): VDPath {
|
||||
if (this.hierarchy.size >= 2 && this[0].toCanonicalString() == "media") {
|
||||
if (this.hierarchy.size >= 2 && this[0].toCanonicalString(sysCharset) == "media") {
|
||||
this.hierarchy.removeAt(0) // drop "media"
|
||||
this.hierarchy.removeAt(0) // drop whatever mount symbol
|
||||
}
|
||||
@@ -105,7 +105,7 @@ internal class Filesystem(globals: Globals, computer: TerrarumComputer) {
|
||||
fun TerrarumComputer.getTargetDisk(path: VDPath) : VirtualDisk? {
|
||||
if (path.hierarchy.size >= 2 &&
|
||||
Arrays.equals(path[0], "media".toEntryName(DiskEntry.NAME_LENGTH, sysCharset))) {
|
||||
val diskName = path[1].toCanonicalString()
|
||||
val diskName = path[1].toCanonicalString(sysCharset)
|
||||
val disk = this.diskRack[diskName]
|
||||
|
||||
return disk
|
||||
@@ -149,8 +149,9 @@ internal class Filesystem(globals: Globals, computer: TerrarumComputer) {
|
||||
val table = LuaTable()
|
||||
try {
|
||||
val directoryContents = computer.getDirectoryEntries(path)!!
|
||||
println("[Filesystem] directoryContents size: ${directoryContents.size}")
|
||||
directoryContents.forEachIndexed { index, diskEntry ->
|
||||
table.insert(index + 1, LuaValue.valueOf(diskEntry.filename.toCanonicalString()))
|
||||
table.insert(index + 1, LuaValue.valueOf(diskEntry.filename.toCanonicalString(sysCharset)))
|
||||
}
|
||||
}
|
||||
catch (e: KotlinNullPointerException) {}
|
||||
@@ -219,8 +220,22 @@ internal class Filesystem(globals: Globals, computer: TerrarumComputer) {
|
||||
return tryBool {
|
||||
val path = VDPath(path.checkPath(), sysCharset)
|
||||
val disk = computer.getTargetDisk(path)!!
|
||||
val dirList = computer.getDirectoryEntries(path.getParent())
|
||||
var makeNew = true
|
||||
|
||||
VDUtil.addDir(disk, path.getParent(), path.last())
|
||||
// check dupes
|
||||
if (dirList != null) {
|
||||
for (entry in dirList) {
|
||||
if (Arrays.equals(path.last(), entry.filename)) {
|
||||
makeNew = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (makeNew) {
|
||||
VDUtil.addDir(disk, path.getParent(), path.last())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -497,17 +512,3 @@ internal class Filesystem(globals: Globals, computer: TerrarumComputer) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* drops appended NULs and return resulting ByteArray as String
|
||||
*/
|
||||
private fun ByteArray.toCanonicalString(): String {
|
||||
var lastIndexOfRealStr = 0
|
||||
for (i in this.lastIndex downTo 0) {
|
||||
if (this[i] != 0.toByte()) {
|
||||
lastIndexOfRealStr = i
|
||||
break
|
||||
}
|
||||
}
|
||||
return String(this.sliceArray(0..lastIndexOfRealStr))
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class WorldInformationProvider(globals: Globals) {
|
||||
companion object {
|
||||
fun getWorldTimeInLuaFormat() : LuaTable {
|
||||
val t = LuaTable()
|
||||
val time = if (Terrarum.gameStarted) Terrarum.ingame!!.world.time else WorldTime()
|
||||
val time = if (Terrarum.ingame != null) Terrarum.ingame!!.world.time else WorldTime()
|
||||
|
||||
// int Terrarum World Time format
|
||||
t["hour"] = time.hours
|
||||
@@ -43,7 +43,7 @@ class WorldInformationProvider(globals: Globals) {
|
||||
|
||||
/** evaluate single C date format */
|
||||
fun String.evalAsDate(): String {
|
||||
val time = if (Terrarum.gameStarted) Terrarum.ingame!!.world.time else WorldTime()
|
||||
val time = if (Terrarum.ingame != null) Terrarum.ingame!!.world.time else WorldTime()
|
||||
return when (this) {
|
||||
"%a" -> time.getDayNameShort()
|
||||
"%A" -> time.getDayNameFull()
|
||||
|
||||
@@ -56,12 +56,12 @@ object VDUtil {
|
||||
override fun toString(): String {
|
||||
val sb = StringBuilder()
|
||||
if (hierarchy.size > 0) {
|
||||
sb.append(hierarchy[0].toCanonicalString())
|
||||
sb.append(hierarchy[0].toCanonicalString(Charsets.UTF_8))
|
||||
}
|
||||
if (hierarchy.size > 1) {
|
||||
(1..hierarchy.lastIndex).forEach {
|
||||
sb.append('/')
|
||||
sb.append(hierarchy[it].toCanonicalString())
|
||||
sb.append(hierarchy[it].toCanonicalString(Charsets.UTF_8))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,12 +209,12 @@ object VDUtil {
|
||||
/**
|
||||
* Get list of entries of directory.
|
||||
*/
|
||||
fun getDirectoryEntries(disk: VirtualDisk, entry: DiskEntry): Array<DiskEntry> {
|
||||
if (entry.contents !is EntryDirectory)
|
||||
fun getDirectoryEntries(disk: VirtualDisk, dirToSearch: DiskEntry): Array<DiskEntry> {
|
||||
if (dirToSearch.contents !is EntryDirectory)
|
||||
throw IllegalArgumentException("The entry is not directory")
|
||||
|
||||
val entriesList = ArrayList<DiskEntry>()
|
||||
entry.contents.entries.forEach {
|
||||
dirToSearch.contents.entries.forEach {
|
||||
val entry = disk.entries[it]
|
||||
if (entry != null) entriesList.add(entry)
|
||||
}
|
||||
@@ -697,7 +697,7 @@ fun String.toEntryName(length: Int, charset: Charset): ByteArray {
|
||||
buffer.put(stringByteArray.sliceArray(0..minOf(length, stringByteArray.size) - 1))
|
||||
return buffer.array
|
||||
}
|
||||
fun ByteArray.toCanonicalString(): String {
|
||||
fun ByteArray.toCanonicalString(charset: Charset): String {
|
||||
var lastIndexOfRealStr = 0
|
||||
for (i in this.lastIndex downTo 0) {
|
||||
if (this[i] != 0.toByte()) {
|
||||
@@ -705,7 +705,7 @@ fun ByteArray.toCanonicalString(): String {
|
||||
break
|
||||
}
|
||||
}
|
||||
return String(this.sliceArray(0..lastIndexOfRealStr))
|
||||
return String(this.sliceArray(0..lastIndexOfRealStr), charset)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -102,7 +102,7 @@ class DiskEntry(
|
||||
// content
|
||||
val contents: DiskEntryContent
|
||||
) {
|
||||
fun getFilenameString(charset: Charset) = if (entryID == 0) ROOTNAME else String(filename, charset)
|
||||
fun getFilenameString(charset: Charset) = if (entryID == 0) ROOTNAME else filename.toCanonicalString(charset)
|
||||
|
||||
val serialisedSize: Int
|
||||
get() = contents.getSizeEntry() + HEADER_SIZE
|
||||
|
||||
Reference in New Issue
Block a user