general cleanup, making stuff a bit more uniform; cleaned up term lib a bit; fixed redstone. again -.-; small network fix and renamed signal to 'modem_message'; converting tabs to align to properly instead of just replacing them with two spaces; word wrapping when writing to term with wrap enabled

This commit is contained in:
Florian Nücke 2013-11-22 00:33:57 +01:00
parent 413a4ede2a
commit 71cfa6104a
17 changed files with 175 additions and 154 deletions

View File

@ -14,7 +14,7 @@ local line = nil
while true do
local w, h = component.primary("gpu").getResolution()
term.clear()
term.cursorBlink(false)
term.setCursorBlink(false)
local i = 1
while i < h do
if not line then
@ -32,14 +32,14 @@ while true do
end
i = i + 1
end
term.cursor(1, h)
term.setCursor(1, h)
term.write(":")
term.cursorBlink(true)
term.setCursorBlink(true)
while true do
local event, address, char, code = coroutine.yield("key_down")
if component.isPrimary(address) then
if code == keyboard.keys.q then
term.cursorBlink(false)
term.setCursorBlink(false)
term.clearLine()
return
elseif code == keyboard.keys.space then

View File

@ -3,15 +3,14 @@ local gpuAvailable, screenAvailable = false, false
local cursorX, cursorY = 1, 1
local cursorBlink = nil
local function gpu() return component.primary("gpu") end
local function toggleBlink()
if term.isAvailable() then
local alt = gpu().get(cursorX, cursorY)
if alt ~= cursorBlink.alt then
gpu().set(cursorX, cursorY, cursorBlink.alt)
cursorBlink.alt = alt
cursorBlink.state = not cursorBlink.state
cursorBlink.state = not cursorBlink.state
if cursorBlink.state then
cursorBlink.alt = component.gpu.get(cursorX, cursorY)
component.gpu.set(cursorX, cursorY, unicode.char(0x2588)) -- solid block
else
component.gpu.set(cursorX, cursorY, cursorBlink.alt)
end
end
end
@ -20,56 +19,57 @@ end
function term.clear()
if term.isAvailable() then
local w, h = gpu().getResolution()
gpu().fill(1, 1, w, h, " ")
local w, h = component.gpu.getResolution()
component.gpu.fill(1, 1, w, h, " ")
end
cursorX, cursorY = 1, 1
end
function term.clearLine()
if term.isAvailable() then
local w = gpu().getResolution()
gpu().fill(1, cursorY, w, 1, " ")
local w = component.gpu.getResolution()
component.gpu.fill(1, cursorY, w, 1, " ")
end
cursorX = 1
end
function term.cursor(col, row)
if col and row then
local w, h = gpu().getResolution()
cursorX = math.min(math.max(col, 1), w)
cursorY = math.min(math.max(row, 1), h)
end
function term.getCursor(col, row)
return cursorX, cursorY
end
function term.cursorBlink(enabled)
checkArg(1, enabled, "boolean", "nil")
local function start(alt)
end
local function stop()
end
if enabled ~= nil then
if enabled then
if not cursorBlink then
cursorBlink = {}
cursorBlink.id = event.timer(0.5, toggleBlink, math.huge)
cursorBlink.state = false
cursorBlink.alt = unicode.char(0x2588) -- solid block
elseif not cursorBlink.state then
toggleBlink()
end
elseif cursorBlink then
event.cancel(cursorBlink.id)
if cursorBlink.state then
toggleBlink()
end
cursorBlink = nil
end
function term.setCursor(col, row)
checkArg(1, col, "number")
checkArg(2, row, "number")
if cursorBlink and cursorBlink.state then
toggleBlink()
end
cursorX = col
cursorY = row
end
function term.getCursorBlink()
return cursorBlink ~= nil
end
function term.setCursorBlink(enabled)
checkArg(1, enabled, "boolean")
if enabled then
if not cursorBlink then
cursorBlink = {}
cursorBlink.id = event.timer(0.5, toggleBlink, math.huge)
cursorBlink.state = false
elseif not cursorBlink.state then
toggleBlink()
end
elseif cursorBlink then
event.cancel(cursorBlink.id)
if cursorBlink.state then
toggleBlink()
end
cursorBlink = nil
end
end
function term.isAvailable()
return gpuAvailable and screenAvailable
end
@ -79,30 +79,30 @@ function term.read(history)
history = history or {}
table.insert(history, "")
local current = #history
local start = term.cursor()
local start = term.getCursor()
local cursor, scroll = 1, 0
local function remove()
local x = start - 1 + cursor - scroll
local w = gpu().getResolution()
gpu().copy(x + 1, cursorY, w - x, 1, -1, 0)
local w = component.gpu.getResolution()
component.gpu.copy(x + 1, cursorY, w - x, 1, -1, 0)
local cursor = cursor + (w - x)
local char = unicode.sub(history[current], cursor, cursor)
if unicode.len(char) == 0 then
char = " "
end
gpu().set(w, cursorY, char)
component.gpu.set(w, cursorY, char)
end
local function render()
local w = gpu().getResolution()
local w = component.gpu.getResolution()
local str = unicode.sub(history[current], 1 + scroll, 1 + scroll + w - (start - 1))
str = str .. string.rep(" ", (w - (start - 1)) - unicode.len(str))
gpu().set(start, cursorY, str)
component.gpu.set(start, cursorY, str)
end
local function scrollEnd()
local w = gpu().getResolution()
local w = component.gpu.getResolution()
cursor = unicode.len(history[current]) + 1
scroll = math.max(0, cursor - (w - (start - 1)))
render()
@ -110,36 +110,36 @@ function term.read(history)
local function scrollLeft()
scroll = scroll - 1
local w = gpu().getResolution()
gpu().copy(start, cursorY, w - start - 1, 1, 1, 0)
local w = component.gpu.getResolution()
component.gpu.copy(start, cursorY, w - start - 1, 1, 1, 0)
local cursor = w - (start - 1) + scroll
local char = unicode.sub(history[current], cursor, cursor)
if unicode.len(char) == 0 then
char = " "
end
gpu().set(1, cursorY, char)
component.gpu.set(1, cursorY, char)
end
local function scrollRight()
scroll = scroll + 1
local w = gpu().getResolution()
gpu().copy(start + 1, cursorY, w - start, 1, -1, 0)
local w = component.gpu.getResolution()
component.gpu.copy(start + 1, cursorY, w - start, 1, -1, 0)
local cursor = w - (start - 1) + scroll
local char = unicode.sub(history[current], cursor, cursor)
if unicode.len(char) == 0 then
char = " "
end
gpu().set(w, cursorY, char)
component.gpu.set(w, cursorY, char)
end
local function update()
local w = gpu().getResolution()
local w = component.gpu.getResolution()
local cursor = cursor - 1
local x = start - 1 + cursor - scroll
if cursor < unicode.len(history[current]) then
gpu().copy(x, cursorY, w - x, 1, 1, 0)
component.gpu.copy(x, cursorY, w - x, 1, 1, 0)
end
gpu().set(x, cursorY, unicode.sub(history[current], cursor, cursor))
component.gpu.set(x, cursorY, unicode.sub(history[current], cursor, cursor))
end
local function copyIfNecessary()
@ -151,18 +151,17 @@ function term.read(history)
local function updateCursor()
cursorX = start - 1 + cursor - scroll
if not term.cursorBlink() then
term.cursorBlink(true)
if not term.getCursorBlink() then
term.setCursorBlink(true)
end
end
local function onKeyDown(char, code)
if not term.isAvailable() then return end
local w = gpu().getResolution()
local w = component.gpu.getResolution()
local blink = false
if code == keyboard.keys.back then
if cursor > 1 then
term.cursorBlink(false)
term.setCursorBlink(false)
copyIfNecessary()
history[#history] = unicode.sub(history[#history], 1, cursor - 2) ..
unicode.sub(history[#history], cursor)
@ -174,7 +173,7 @@ function term.read(history)
end
elseif code == keyboard.keys.delete then
if cursor <= unicode.len(history[current]) then
term.cursorBlink(false)
term.setCursorBlink(false)
copyIfNecessary()
history[#history] = unicode.sub(history[#history], 1, cursor - 1) ..
unicode.sub(history[#history], cursor + 1)
@ -182,7 +181,7 @@ function term.read(history)
end
elseif code == keyboard.keys.left then
if cursor > 1 then
term.cursorBlink(false)
term.setCursorBlink(false)
blink = true
cursor = cursor - 1
if cursor - scroll < 1 then
@ -191,7 +190,7 @@ function term.read(history)
end
elseif code == keyboard.keys.right then
if cursor < unicode.len(history[current]) + 1 then
term.cursorBlink(false)
term.setCursorBlink(false)
blink = true
cursor = cursor + 1
if cursor - scroll > w - (start - 1) then
@ -200,27 +199,27 @@ function term.read(history)
end
elseif code == keyboard.keys.home then
if cursor > 1 then
term.cursorBlink(false)
term.setCursorBlink(false)
blink = true
cursor, scroll = 1, 0
render()
end
elseif code == keyboard.keys["end"] then
if cursor < unicode.len(history[current]) + 1 then
term.cursorBlink(false)
term.setCursorBlink(false)
blink = true
scrollEnd()
end
elseif code == keyboard.keys.up then
if current > 1 then
term.cursorBlink(false)
term.setCursorBlink(false)
blink = true
current = current - 1
scrollEnd()
end
elseif code == keyboard.keys.down then
if current < #history then
term.cursorBlink(false)
term.setCursorBlink(false)
blink = true
current = current + 1
scrollEnd()
@ -242,7 +241,7 @@ function term.read(history)
return true, nil
end
elseif not keyboard.isControl(char) then
term.cursorBlink(false)
term.setCursorBlink(false)
copyIfNecessary()
history[#history] = unicode.sub(history[#history], 1, cursor - 1) ..
unicode.char(char) ..
@ -255,13 +254,13 @@ function term.read(history)
end
updateCursor()
if blink then -- immediately show cursor
term.cursorBlink(true)
term.setCursorBlink(true)
end
end
local function onClipboard(value)
copyIfNecessary()
term.cursorBlink(false)
term.setCursorBlink(false)
local l = value:find("\n", 1, true)
if l then
history[#history] = history[#history] .. unicode.sub(value, 1, l - 1)
@ -278,18 +277,21 @@ function term.read(history)
if history[#history] == "" then
table.remove(history)
end
term.cursorBlink(false)
term.setCursorBlink(false)
print()
end
term.cursorBlink(true)
term.setCursorBlink(true)
while term.isAvailable() do
local ok, event, address, charOrValue, code = pcall(event.pull)
if not ok then
cleanup()
error("interrupted", 0)
end
if type(address) == "string" and component.isPrimary(address) then
if term.isAvailable() and
type(address) == "string" and
component.isPrimary(address)
then
if event == "key_down" then
local done, result = onKeyDown(charOrValue, code)
if done then
@ -310,44 +312,50 @@ function term.read(history)
end
function term.write(value, wrap)
value = tostring(value)
if unicode.len(value) == 0 or not term.isAvailable() then
if not term.isAvailable() then
return
end
local blink = term.cursorBlink()
term.cursorBlink(false)
value = value:gsub("\t", " ")
local w, h = gpu().getResolution()
value = tostring(value)
if unicode.len(value) == 0 then
return
end
value = text.detab(value)
local w, h = component.gpu.getResolution()
local blink = term.getCursorBlink()
term.setCursorBlink(false)
local function checkCursor()
if cursorX > w then
cursorX = 1
cursorY = cursorY + 1
end
if cursorY > h then
gpu().copy(1, 1, w, h, 0, -1)
gpu().fill(1, h, w, 1, " ")
component.gpu.copy(1, 1, w, h, 0, -1)
component.gpu.fill(1, h, w, 1, " ")
cursorY = h
end
end
for line, nl in value:gmatch("([^\r\n]*)([\r\n]?)") do
while wrap and unicode.len(line) > w - cursorX + 1 do
local partial = unicode.sub(line, 1, w - cursorX + 1)
line = unicode.sub(line, unicode.len(partial) + 1)
gpu().set(cursorX, cursorY, partial)
cursorX = cursorX + unicode.len(partial)
while wrap and unicode.len(line) > w - (cursorX - 1) do
local partial = unicode.sub(line, 1, w - (cursorX - 1))
local wordWrapped = partial:match("(.*[^a-zA-Z0-9._])")
if wordWrapped or unicode.len(partial) > w then
partial = wordWrapped or partial
line = unicode.sub(line, unicode.len(partial) + 1)
component.gpu.set(cursorX, cursorY, partial)
end
cursorX = math.huge
checkCursor()
end
if unicode.len(line) > 0 then
gpu().set(cursorX, cursorY, line)
component.gpu.set(cursorX, cursorY, line)
cursorX = cursorX + unicode.len(line)
end
if unicode.len(nl) == 1 then
cursorX = 1
cursorY = cursorY + 1
cursorX = math.huge
checkCursor()
end
end
term.cursorBlink(blink)
term.setCursorBlink(blink)
end
-------------------------------------------------------------------------------

View File

@ -0,0 +1,14 @@
local text = {}
function text.detab(value, tabWidth)
checkArg(1, value, "string")
checkArg(2, tabWidth, "number", "nil")
tabWidth = tabWidth or 4
local function rep(match)
local spaces = tabWidth - match:len() % tabWidth
return match .. string.rep(" ", spaces)
end
return value:gsub("([^\n]-)\t", rep)
end
_G.text = text

View File

@ -63,7 +63,7 @@ class PacketHandler extends CommonPacketHandler {
def onComputerStateResponse(p: PacketParser) =
p.readTileEntity[Computer]() match {
case Some(t) => t.isOn = p.readBoolean()
case Some(t) => t.isRunning = p.readBoolean()
case _ => // Invalid packet.
}

View File

@ -15,7 +15,7 @@ object CaseRenderer extends TileEntitySpecialRenderer {
override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float) = {
val computer = tileEntity.asInstanceOf[Case]
if (computer.isOn) {
if (computer.isRunning) {
GL11.glPushAttrib(0xFFFFFF)
RenderState.disableLighting()

View File

@ -189,13 +189,13 @@ object RobotRenderer extends TileEntitySpecialRenderer {
val timeJitter = robot.hashCode
val hover =
if (robot.isOn) (Math.sin(timeJitter + worldTime / 20.0) * 0.03).toFloat
if (robot.isRunning) (Math.sin(timeJitter + worldTime / 20.0) * 0.03).toFloat
else -0.03f
GL11.glTranslatef(0, hover, 0)
if (MinecraftForgeClient.getRenderPass == 0) {
val offset = timeJitter + worldTime / 20.0
renderChassis(robot.isOn, offset)
renderChassis(robot.isRunning, offset)
}
robot.equippedItem match {

View File

@ -21,7 +21,7 @@ class Case(val parent: SimpleDelegator) extends Computer with SimpleDelegate {
override def getBlockTextureFromSide(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection) = {
getIcon(localSide, world.getBlockTileEntity(x, y, z) match {
case computer: tileentity.Case => computer.isOn
case computer: tileentity.Case => computer.isRunning
case _ => false
})
}

View File

@ -2,6 +2,7 @@ package li.cil.oc.common.block
import cpw.mods.fml.common.{Loader, Optional}
import java.util
import li.cil.oc.client.renderer.block.BlockRenderer
import li.cil.oc.common.tileentity
import li.cil.oc.{Config, CreativeTab}
import net.minecraft.block.Block
@ -17,7 +18,6 @@ import net.minecraft.world.{IBlockAccess, World}
import net.minecraftforge.common.ForgeDirection
import powercrystals.minefactoryreloaded.api.rednet.{IRedNetNetworkContainer, RedNetConnectionType, IConnectableRedNet}
import scala.collection.mutable
import li.cil.oc.client.renderer.block.BlockRenderer
/**
* Block proxy for all real block implementations.
@ -134,13 +134,13 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) {
override def canConnectRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.canConnectRedstone(
world, x, y, z, toLocal(world, x, y, z, side match {
world, x, y, z, side match {
case -1 => ForgeDirection.UP
case 0 => ForgeDirection.NORTH
case 1 => ForgeDirection.EAST
case 2 => ForgeDirection.SOUTH
case 3 => ForgeDirection.WEST
}))
})
case _ => false
}
@ -235,15 +235,13 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) {
override def isProvidingStrongPower(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.isProvidingStrongPower(
world, x, y, z, toLocal(world, x, y, z, ForgeDirection.getOrientation(side).getOpposite))
case Some(subBlock) => subBlock.isProvidingStrongPower(world, x, y, z, ForgeDirection.getOrientation(side).getOpposite)
case _ => 0
}
override def isProvidingWeakPower(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.isProvidingWeakPower(
world, x, y, z, toLocal(world, x, y, z, ForgeDirection.getOrientation(side).getOpposite))
case Some(subBlock) => subBlock.isProvidingWeakPower(world, x, y, z, ForgeDirection.getOrientation(side).getOpposite)
case _ => 0
}

View File

@ -9,21 +9,21 @@ import li.cil.oc.util.{PackedColor, Persistable}
import net.minecraft.nbt.NBTTagCompound
trait Buffer extends Environment with Persistable {
protected val buffer_ = new component.Buffer(this)
protected val _buffer = new component.Buffer(this)
protected var bufferIsDirty_ = false
protected var _bufferIsDirty = false
protected var currentGui_ = None: Option[gui.Buffer]
protected var _currentGui = None: Option[gui.Buffer]
def buffer = buffer_
def buffer = _buffer
def bufferIsDirty = bufferIsDirty_
def bufferIsDirty = _bufferIsDirty
def bufferIsDirty_=(value: Boolean) = bufferIsDirty_ = value
def bufferIsDirty_=(value: Boolean) = _bufferIsDirty = value
def currentGui = currentGui_
def currentGui = _currentGui
def currentGui_=(value: Option[gui.Buffer]) = currentGui_ = value
def currentGui_=(value: Option[gui.Buffer]) = _currentGui = value
def node: Node = buffer.node

View File

@ -11,24 +11,24 @@ import net.minecraftforge.common.ForgeDirection
import scala.Some
abstract class Computer(isRemote: Boolean) extends Environment with ComponentInventory with Rotatable with Redstone with Analyzable {
protected val computer_ = if (isRemote) null else new component.Computer(this)
protected val _computer = if (isRemote) null else new component.Computer(this)
def computer = computer_
def computer = _computer
def node = if (isClient) null else computer.node
override def isClient = computer == null
private var isRunning = false
private var _isRunning = false
private var hasChanged = false
// ----------------------------------------------------------------------- //
def isOn = isRunning
def isRunning = _isRunning
def isOn_=(value: Boolean) = {
isRunning = value
def isRunning_=(value: Boolean) = {
_isRunning = value
world.markBlockForRenderUpdate(x, y, z)
this
}
@ -57,11 +57,11 @@ abstract class Computer(isRemote: Boolean) extends Environment with ComponentInv
world.markTileEntityChunkModified(x, y, z, this)
}
if (isRunning != computer.isRunning) {
if (_isRunning != computer.isRunning) {
isOutputEnabled = hasRedstoneCard && computer.isRunning
ServerPacketSender.sendComputerState(this, computer.isRunning)
}
isRunning = computer.isRunning
_isRunning = computer.isRunning
updateRedstoneInput()

View File

@ -34,10 +34,10 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
override def node = if (isClient) null else computer.node
override val buffer_ = new common.component.Buffer(this) {
override val _buffer = new common.component.Buffer(this) {
override def maxResolution = (48, 14)
}
override val computer_ = if (isRemote) null else new component.Robot(this)
override val _computer = if (isRemote) null else new component.Robot(this)
val (battery, distributor, gpu, keyboard) = if (isServer) {
val battery = api.Network.newNode(this, Visibility.Network).withConnector(10000).create()
val distributor = new component.PowerDistributor(this)

View File

@ -214,9 +214,9 @@ class RobotProxy(val robot: Robot) extends Computer(robot.isClient) with ISidedI
override def computer = robot.computer
override def isOn = robot.isOn
override def isRunning = robot.isRunning
override def isOn_=(value: Boolean) = robot.isOn_=(value)
override def isRunning_=(value: Boolean) = robot.isRunning_=(value)
override def markAsChanged() = robot.markAsChanged()

View File

@ -27,7 +27,7 @@ class PacketHandler extends CommonPacketHandler {
def onComputerStateRequest(p: PacketParser) =
p.readTileEntity[Computer]() match {
case Some(t) => PacketSender.sendComputerState(t, t.isOn, Option(p.player))
case Some(t) => PacketSender.sendComputerState(t, t.isRunning, Option(p.player))
case _ => // Invalid packet.
}

View File

@ -256,6 +256,7 @@ class Computer(val owner: tileentity.Computer) extends ManagedComponent with Con
else {
verifyComponents() // In case we're resuming after loading.
state.pop()
// TODO Assertion of "no future" in switchTo can fail when coming from here, why?
switchTo(state.top) // Trigger execution if necessary.
}
}

View File

@ -73,7 +73,7 @@ class NetworkCard extends ManagedComponent {
openPorts.clear()
if (message.name == "network.message") message.data match {
case Array(port: Integer, args@_*) if openPorts.contains(port) =>
node.sendToReachable("computer.signal", Seq("network_message", message.source.address, Int.box(port), Int.box(-1)) ++ args: _*)
node.sendToReachable("computer.signal", Seq("modem_message", message.source.address, Int.box(port)) ++ args: _*)
case _ =>
}
}

View File

@ -16,11 +16,11 @@ import scala.collection.{immutable, mutable}
trait Component extends api.network.Component with Persistable {
val name: String
def visibility = visibility_
def visibility = _visibility
private lazy val callbacks = Component.callbacks(host.getClass)
private var visibility_ = Visibility.None
private var _visibility = Visibility.None
def setVisibility(value: Visibility) = {
if (value.ordinal() > reachability.ordinal()) {
@ -28,7 +28,7 @@ trait Component extends api.network.Component with Persistable {
"' node with reachability '" + reachability + "'. It will be limited to the node's reachability.")
}
if (FMLCommonHandler.instance.getEffectiveSide == Side.SERVER) {
if (network != null) visibility_ match {
if (network != null) _visibility match {
case Visibility.Neighbors => value match {
case Visibility.Network => addTo(reachableNodes)
case Visibility.None => removeFrom(neighbors)
@ -47,7 +47,7 @@ trait Component extends api.network.Component with Persistable {
case _ =>
}
}
visibility_ = value
_visibility = value
}
}
@ -94,13 +94,13 @@ trait Component extends api.network.Component with Persistable {
override def load(nbt: NBTTagCompound) {
super.load(nbt)
if (nbt.hasKey(Config.namespace + "component.visibility")) {
visibility_ = Visibility.values()(nbt.getInteger(Config.namespace + "component.visibility"))
_visibility = Visibility.values()(nbt.getInteger(Config.namespace + "component.visibility"))
}
}
override def save(nbt: NBTTagCompound) {
super.save(nbt)
nbt.setInteger(Config.namespace + "component.visibility", visibility_.ordinal())
nbt.setInteger(Config.namespace + "component.visibility", _visibility.ordinal())
}
}

View File

@ -13,29 +13,29 @@ import net.minecraft.nbt._
class TextBuffer(var width: Int, var height: Int, initialDepth: PackedColor.Depth.Value) extends Persistable {
def this(size: (Int, Int), depth: PackedColor.Depth.Value) = this(size._1, size._2, depth)
private var depth_ = initialDepth
private var _depth = initialDepth
private var foreground_ = 0xFFFFFF
private var _foreground = 0xFFFFFF
private var background_ = 0x000000
private var _background = 0x000000
private var packed = PackedColor.pack(foreground_, background_, depth_)
private var packed = PackedColor.pack(_foreground, _background, _depth)
def foreground = foreground_
def foreground = _foreground
def foreground_=(value: Int) = {
foreground_ = value
packed = PackedColor.pack(foreground_, background_, depth_)
_foreground = value
packed = PackedColor.pack(_foreground, _background, _depth)
}
def background = background_
def background = _background
def background_=(value: Int) = {
background_ = value
packed = PackedColor.pack(foreground_, background_, depth_)
_background = value
packed = PackedColor.pack(_foreground, _background, _depth)
}
def depth = depth_
def depth = _depth
def depth_=(value: PackedColor.Depth.Value) = {
if (depth != value) {
@ -43,13 +43,13 @@ class TextBuffer(var width: Int, var height: Int, initialDepth: PackedColor.Dept
val rowColor = color(row)
for (col <- 0 until width) {
val packed = rowColor(col)
val fg = PackedColor.unpackForeground(packed, depth_)
val bg = PackedColor.unpackBackground(packed, depth_)
val fg = PackedColor.unpackForeground(packed, _depth)
val bg = PackedColor.unpackBackground(packed, _depth)
rowColor(col) = PackedColor.pack(fg, bg, value)
}
}
depth_ = value
packed = PackedColor.pack(foreground_, background_, depth_)
_depth = value
packed = PackedColor.pack(_foreground, _background, _depth)
true
}
else false
@ -176,7 +176,7 @@ class TextBuffer(var width: Int, var height: Int, initialDepth: PackedColor.Dept
set(0, i, line)
}
depth_ = PackedColor.Depth(nbt.getInteger("depth"))
_depth = PackedColor.Depth(nbt.getInteger("depth"))
foreground = nbt.getInteger("foreground")
background = nbt.getInteger("background")
@ -199,9 +199,9 @@ class TextBuffer(var width: Int, var height: Int, initialDepth: PackedColor.Dept
}
nbt.setTag("buffer", b)
nbt.setInteger("depth", depth_.id)
nbt.setInteger("foreground", foreground_)
nbt.setInteger("background", background_)
nbt.setInteger("depth", _depth.id)
nbt.setInteger("foreground", _foreground)
nbt.setInteger("background", _background)
val c = new NBTTagList()
for (i <- 0 until height) {