mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 19:25:20 -04:00
Properly erroring for invalid indexes in gpu.get now and (probably?) fixing a bug in term.isWide.
This commit is contained in:
parent
ef9506fd82
commit
cb0e51efbb
@ -81,17 +81,20 @@ function term.setCursorBlink(enabled)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function term.isWide(x, y)
|
function term.isWide(x, y)
|
||||||
local charLeft, char = component.gpu.get(x - 1, y), component.gpu.get(x, y)
|
local char = component.gpu.get(x, y)
|
||||||
if unicode.isWide(char) then
|
if unicode.isWide(char) then
|
||||||
-- The char at the specified position is a wide char.
|
-- The char at the specified position is a wide char.
|
||||||
return true
|
return true
|
||||||
elseif char == " " and charLeft and unicode.isWide(charLeft) then
|
|
||||||
-- The char left to the specified position is a wide char.
|
|
||||||
return true, true
|
|
||||||
else
|
|
||||||
-- Not a wide char.
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
if char == " " and x > 1 then
|
||||||
|
local charLeft = component.gpu.get(x - 1, y)
|
||||||
|
if charLeft and unicode.isWide(charLeft) then
|
||||||
|
-- The char left to the specified position is a wide char.
|
||||||
|
return true, true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Not a wide char.
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function term.isAvailable()
|
function term.isAvailable()
|
||||||
|
@ -273,25 +273,31 @@ class TextBuffer(val owner: Container) extends ManagedComponent with api.compone
|
|||||||
|
|
||||||
override def getForegroundColor(column: Int, row: Int) =
|
override def getForegroundColor(column: Int, row: Int) =
|
||||||
if (isForegroundFromPalette(column, row)) {
|
if (isForegroundFromPalette(column, row)) {
|
||||||
PackedColor.extractForeground(data.color(row)(column))
|
PackedColor.extractForeground(color(column, row))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PackedColor.unpackForeground(data.color(row)(column), data.format)
|
PackedColor.unpackForeground(color(column, row), data.format)
|
||||||
}
|
}
|
||||||
|
|
||||||
override def isForegroundFromPalette(column: Int, row: Int) =
|
override def isForegroundFromPalette(column: Int, row: Int) =
|
||||||
data.format.isFromPalette(PackedColor.extractForeground(data.color(row)(column)))
|
data.format.isFromPalette(PackedColor.extractForeground(color(column, row)))
|
||||||
|
|
||||||
override def getBackgroundColor(column: Int, row: Int) =
|
override def getBackgroundColor(column: Int, row: Int) =
|
||||||
if (isBackgroundFromPalette(column, row)) {
|
if (isBackgroundFromPalette(column, row)) {
|
||||||
PackedColor.extractBackground(data.color(row)(column))
|
PackedColor.extractBackground(color(column, row))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PackedColor.unpackBackground(data.color(row)(column), data.format)
|
PackedColor.unpackBackground(color(column, row), data.format)
|
||||||
}
|
}
|
||||||
|
|
||||||
override def isBackgroundFromPalette(column: Int, row: Int) =
|
override def isBackgroundFromPalette(column: Int, row: Int) =
|
||||||
data.format.isFromPalette(PackedColor.extractBackground(data.color(row)(column)))
|
data.format.isFromPalette(PackedColor.extractBackground(color(column, row)))
|
||||||
|
|
||||||
|
private def color(column: Int, row: Int) = {
|
||||||
|
if (column < 0 || column >= getWidth || row < 0 || row >= getHeight)
|
||||||
|
throw new IndexOutOfBoundsException()
|
||||||
|
else data.color(row)(column)
|
||||||
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
override def renderText() = relativeLitArea != 0 && proxy.render()
|
override def renderText() = relativeLitArea != 0 && proxy.render()
|
||||||
|
@ -95,7 +95,11 @@ class TextBuffer(var width: Int, var height: Int, initialFormat: PackedColor.Col
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get the char at the specified index. */
|
/** Get the char at the specified index. */
|
||||||
def get(col: Int, row: Int) = buffer(row)(col)
|
def get(col: Int, row: Int) = {
|
||||||
|
if (col < 0 || col >= width || row < 0 || row >= height)
|
||||||
|
throw new IndexOutOfBoundsException()
|
||||||
|
else buffer(row)(col)
|
||||||
|
}
|
||||||
|
|
||||||
/** String based fill starting at a specified location. */
|
/** String based fill starting at a specified location. */
|
||||||
def set(col: Int, row: Int, s: String, vertical: Boolean): Boolean =
|
def set(col: Int, row: Int, s: String, vertical: Boolean): Boolean =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user