mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
VT: shit is still rolling
- We might need virtual disk image... Former-commit-id: c3278cd9fe1ddad8b26b45577fecb0500365d38b
This commit is contained in:
@@ -36,7 +36,7 @@ class StateGraphicComputerTest : BasicGameState() {
|
||||
}
|
||||
|
||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||
val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram
|
||||
/*val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram
|
||||
|
||||
// it's a-me, Mario!
|
||||
(0..3).forEach {
|
||||
@@ -84,7 +84,7 @@ class StateGraphicComputerTest : BasicGameState() {
|
||||
0,1,1,1,0,0,0,0,
|
||||
0,0,2,2,2,0,0,0,
|
||||
0,0,2,2,2,2,0,0
|
||||
))
|
||||
))*/
|
||||
}
|
||||
|
||||
var angle = 0.0
|
||||
@@ -99,7 +99,7 @@ class StateGraphicComputerTest : BasicGameState() {
|
||||
computer.update(container, delta)
|
||||
|
||||
|
||||
val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram
|
||||
/*val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram
|
||||
val sprites = vcard.sprites
|
||||
angle += delta / 1000.0
|
||||
|
||||
@@ -114,7 +114,7 @@ class StateGraphicComputerTest : BasicGameState() {
|
||||
sprites[2].posY = (Math.sin(angle) * 0 + 100).roundInt()
|
||||
|
||||
sprites[3].posX = (Math.cos(angle) * 80 + 100).roundInt()
|
||||
sprites[3].posY = (Math.sin(angle) * 0 + 100).roundInt()
|
||||
sprites[3].posY = (Math.sin(angle) * 0 + 100).roundInt()*/
|
||||
}
|
||||
|
||||
override fun getID() = Terrarum.STATE_ID_TEST_TTY
|
||||
|
||||
@@ -72,6 +72,8 @@ class StateUITest : BasicGameState() {
|
||||
})
|
||||
|
||||
actor.inventory.add(ItemCodex[16], 543)
|
||||
|
||||
actor.inventory.getByID(Tile.STONE)!!.item equipTo actor
|
||||
}
|
||||
|
||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||
|
||||
@@ -20,8 +20,8 @@ import org.newdawn.slick.state.StateBasedGame
|
||||
class StateVTTest : BasicGameState() {
|
||||
|
||||
// HiRes: 100x64, LoRes: 80x25
|
||||
val computerInside = TerrarumComputer(8)
|
||||
val vt = SimpleTextTerminal(SimpleTextTerminal.AMETHYST_NOVELTY, 80, 25,
|
||||
val computerInside = TerrarumComputer(peripheralSlots = 8)
|
||||
val vt = SimpleTextTerminal(SimpleTextTerminal.AMBER, 80, 25,
|
||||
computerInside, colour = false, hires = false)
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.luaj.vm2.lib.OneArgFunction
|
||||
import org.luaj.vm2.lib.TwoArgFunction
|
||||
import org.luaj.vm2.lib.ZeroArgFunction
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.toHex
|
||||
import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
|
||||
import net.torvald.terrarum.virtualcomputer.luaapi.Term.Companion.checkIBM437
|
||||
import java.io.*
|
||||
@@ -87,7 +88,7 @@ internal class Filesystem(globals: Globals, computer: TerrarumComputer) {
|
||||
// Worst-case: we're on Windows or using a FAT32 partition mounted in *nix.
|
||||
// Note: we allow / as the path separator and expect all \s to be converted
|
||||
// accordingly before the path is passed to the file system.
|
||||
private val invalidChars = Regex("""[\\:*?"<>|]""") // original OC uses Set(); we use regex
|
||||
private val invalidChars = Regex("""[<>:"|?*\u0000-\u001F]""") // original OC uses Set(); we use regex
|
||||
|
||||
fun isValidFilename(name: String) = !name.contains(invalidChars)
|
||||
|
||||
@@ -117,15 +118,23 @@ internal class Filesystem(globals: Globals, computer: TerrarumComputer) {
|
||||
// remove first '/' in path
|
||||
var path = luapath.checkIBM437().validatePath()
|
||||
if (path.startsWith('/')) path = path.substring(1)
|
||||
|
||||
|
||||
val finalPath: String
|
||||
|
||||
if (path.startsWith("media/")) {
|
||||
val device = path.substring(6, 9)
|
||||
val subPath = path.substring(9)
|
||||
return computerDir + this.computerValue.getAsString("device") + subPath
|
||||
finalPath = computerDir + this.computerValue.getAsString("device") + subPath
|
||||
}
|
||||
else {
|
||||
return computerDir + this.computerValue.getAsString("boot") + "/" + path
|
||||
finalPath = computerDir + this.computerValue.getAsString("boot") + "/" + path
|
||||
}
|
||||
|
||||
// remove trailing slash
|
||||
return if (finalPath.endsWith("\\") || finalPath.endsWith("/"))
|
||||
finalPath.substring(0, finalPath.length - 1)
|
||||
else
|
||||
finalPath
|
||||
}
|
||||
|
||||
fun combinePath(base: String, local: String) : String {
|
||||
@@ -166,7 +175,7 @@ internal class Filesystem(globals: Globals, computer: TerrarumComputer) {
|
||||
class IsDirectory(val computer: TerrarumComputer) : OneArgFunction() {
|
||||
override fun call(path: LuaValue) : LuaValue {
|
||||
Filesystem.ensurePathSanity(path)
|
||||
|
||||
|
||||
val isDir = Files.isDirectory(Paths.get(computer.getRealPath(path)).toAbsolutePath())
|
||||
val exists = Files.exists(Paths.get(computer.getRealPath(path)).toAbsolutePath())
|
||||
|
||||
|
||||
@@ -37,8 +37,6 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal {
|
||||
private val colourKey: Int
|
||||
get() = backColour.shl(4) or (foreColour).and(0xFF)
|
||||
|
||||
override var lastInputByte = -1
|
||||
|
||||
override fun getColor(index: Int) = videoCard.CLUT[index]
|
||||
|
||||
override val displayW: Int; get() = videoCard.width //+ 2 * borderSize
|
||||
@@ -272,11 +270,6 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal {
|
||||
}
|
||||
}
|
||||
|
||||
override fun getKeyPress(): Int? {
|
||||
//TODO("not implemented")
|
||||
return null
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val WHITE7500 = Color(0xe4eaff)
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ open class SimpleTextTerminal(
|
||||
* Terminals must support AT LEAST 4 colours.
|
||||
* Color index 0 must be default background, index 3 must be default foreground
|
||||
*/
|
||||
open protected val colours = if (colour) CLUT else CLUT.copyOfRange(0, 3)
|
||||
open protected val colours = if (colour) CLUT else CLUT.copyOfRange(0, 4)
|
||||
|
||||
val phosphor = if (colour) WHITE7500 else phosphorColour
|
||||
open val colourScreen = if (colour) Color(8, 8, 8) else Color(19, 19, 19)
|
||||
@@ -339,26 +339,10 @@ open class SimpleTextTerminal(
|
||||
}
|
||||
}
|
||||
|
||||
override var lastInputByte: Int = -1
|
||||
var sb: StringBuilder = StringBuilder()
|
||||
private var inputOpen = false
|
||||
private var keyPressVisible = false
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
lastInputByte = c.toInt()
|
||||
|
||||
if (inputOpen) {
|
||||
if (c == ASCII_CR)
|
||||
printChar(ASCII_LF)
|
||||
else if (keyPressVisible)
|
||||
printChar(c)
|
||||
if (!asciiControlInUse.contains(c)) sb.append(c)
|
||||
else if (key == Key.BACKSPACE && sb.isNotEmpty()) sb.deleteCharAt(sb.length - 1)
|
||||
}
|
||||
host.keyPressed(key, c)
|
||||
}
|
||||
|
||||
override fun getKeyPress(): Int? = lastInputByte
|
||||
|
||||
private fun isOOB(x: Int, y: Int) =
|
||||
(x < 0 || y < 0 || x >= width || y >= height)
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ interface Terminal : Teletype {
|
||||
var backColour: Int
|
||||
var foreColour: Int
|
||||
|
||||
var lastInputByte: Int
|
||||
|
||||
// to be used in UI
|
||||
override val displayW: Int
|
||||
val displayH: Int
|
||||
@@ -65,17 +63,4 @@ interface Terminal : Teletype {
|
||||
fun emitTone(duration: Millisec, freq: Double)
|
||||
|
||||
override fun bell(pattern: String)
|
||||
/** Requires keyPressed() event to be processed.
|
||||
*
|
||||
* null indicates the input stream is waiting for an input
|
||||
*
|
||||
* implementation:
|
||||
*
|
||||
* private var lastInputByte: Int? = null
|
||||
* override fun keyPressed(key: Int, c: Char) {
|
||||
lastInputByte = c.toInt()
|
||||
lastInputByte = null
|
||||
}
|
||||
*/
|
||||
fun getKeyPress(): Int?
|
||||
}
|
||||
Reference in New Issue
Block a user