mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 02:39:48 -04:00
Made the palette indicator returned by gpu.setForeground/setBackground as well as gpu.get the actual index or nil instead of true/false.
This commit is contained in:
parent
67b4ebf39d
commit
f79287e81e
@ -300,11 +300,13 @@ public interface TextBuffer extends ManagedEnvironment, Persistable {
|
||||
char get(int column, int row);
|
||||
|
||||
/**
|
||||
* Get the character in the text buffer at the specified location.
|
||||
* Get the foreground color of the text buffer at the specified location.
|
||||
* <p/>
|
||||
* <em>Important</em>: this may be a palette index.
|
||||
*
|
||||
* @param column the horizontal index.
|
||||
* @param row the vertical index.
|
||||
* @return the foregound color at that index.
|
||||
* @return the foreground color at that index.
|
||||
*/
|
||||
int getForegroundColor(int column, int row);
|
||||
|
||||
@ -320,6 +322,8 @@ public interface TextBuffer extends ManagedEnvironment, Persistable {
|
||||
|
||||
/**
|
||||
* Get the background color of the text buffer at the specified location.
|
||||
* <p/>
|
||||
* <em>Important</em>: this may be a palette index.
|
||||
*
|
||||
* @param column the horizontal index.
|
||||
* @param row the vertical index.
|
||||
|
@ -24,9 +24,9 @@ term.write("Press Ctrl+C to exit the interpreter.\n")
|
||||
component.gpu.setForeground(0xFFFFFF)
|
||||
|
||||
while term.isAvailable() do
|
||||
local foreground, palette = component.gpu.setForeground(0x00FF00)
|
||||
local foreground = component.gpu.setForeground(0x00FF00)
|
||||
term.write(tostring(env._PROMPT or "lua> "))
|
||||
component.gpu.setForeground(foreground, palette)
|
||||
component.gpu.setForeground(foreground)
|
||||
local command = term.read(history)
|
||||
if command == nil then -- eof
|
||||
return
|
||||
|
@ -104,9 +104,9 @@ if #args == 0 and (io.input() == io.stdin or options.i) and not options.c then
|
||||
term.clear()
|
||||
end
|
||||
while term.isAvailable() do
|
||||
local foreground, palette = component.gpu.setForeground(0xFF0000)
|
||||
local foreground = component.gpu.setForeground(0xFF0000)
|
||||
term.write(expand(os.getenv("PS1") or "$ "))
|
||||
component.gpu.setForeground(foreground, palette)
|
||||
component.gpu.setForeground(foreground)
|
||||
local command = term.read(history)
|
||||
if not command then
|
||||
term.write("exit\n")
|
||||
|
@ -32,10 +32,9 @@ end
|
||||
function stderrStream:write(str)
|
||||
local component = require("component")
|
||||
if component.isAvailable("gpu") and component.gpu.getDepth() > 1 then
|
||||
local foreground, palette = component.gpu.getForeground()
|
||||
component.gpu.setForeground(0xFF0000)
|
||||
local foreground = component.gpu.setForeground(0xFF0000)
|
||||
term.write(str, true)
|
||||
component.gpu.setForeground(foreground, palette)
|
||||
component.gpu.setForeground(foreground)
|
||||
else
|
||||
term.write(str, true)
|
||||
end
|
||||
|
@ -264,20 +264,26 @@ class TextBuffer(val owner: Container) extends ManagedComponent with api.compone
|
||||
def get(col: Int, row: Int) = data.get(col, row)
|
||||
|
||||
override def getForegroundColor(column: Int, row: Int) =
|
||||
PackedColor.unpackForeground(data.color(row)(column), data.format)
|
||||
if (isForegroundFromPalette(column, row)) {
|
||||
PackedColor.extractForeground(data.color(row)(column))
|
||||
}
|
||||
else {
|
||||
PackedColor.unpackForeground(data.color(row)(column), data.format)
|
||||
}
|
||||
|
||||
override def isForegroundFromPalette(column: Int, row: Int) = data.format match {
|
||||
case palette: PackedColor.PaletteFormat => palette.isFromPalette(PackedColor.extractForeground(data.color(row)(column)))
|
||||
case _ => false
|
||||
}
|
||||
override def isForegroundFromPalette(column: Int, row: Int) =
|
||||
data.format.isFromPalette(PackedColor.extractForeground(data.color(row)(column)))
|
||||
|
||||
override def getBackgroundColor(column: Int, row: Int) =
|
||||
PackedColor.unpackBackground(data.color(row)(column), data.format)
|
||||
if (isBackgroundFromPalette(column, row)) {
|
||||
PackedColor.extractBackground(data.color(row)(column))
|
||||
}
|
||||
else {
|
||||
PackedColor.unpackBackground(data.color(row)(column), data.format)
|
||||
}
|
||||
|
||||
override def isBackgroundFromPalette(column: Int, row: Int) = data.format match {
|
||||
case palette: PackedColor.PaletteFormat => palette.isFromPalette(PackedColor.extractBackground(data.color(row)(column)))
|
||||
case _ => false
|
||||
}
|
||||
override def isBackgroundFromPalette(column: Int, row: Int) =
|
||||
data.format.isFromPalette(PackedColor.extractBackground(data.color(row)(column)))
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def renderText() = relativeLitArea != 0 && proxy.render()
|
||||
|
@ -79,10 +79,16 @@ abstract class GraphicsCard extends component.ManagedComponent {
|
||||
def setBackground(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
val color = args.checkInteger(0)
|
||||
screen(s => {
|
||||
val oldColor = s.getBackgroundColor
|
||||
val oldIsPalette = s.isBackgroundFromPalette
|
||||
val oldValue = s.getBackgroundColor
|
||||
val (oldColor, oldIndex) =
|
||||
if (s.isBackroundFromPalette) {
|
||||
(s.getPaletteColor(oldValue), oldValue)
|
||||
}
|
||||
else {
|
||||
(oldValue, Unit)
|
||||
}
|
||||
s.setBackgroundColor(color, args.count > 1 && args.checkBoolean(1))
|
||||
result(oldColor, oldIsPalette)
|
||||
result(oldColor, oldIndex)
|
||||
})
|
||||
}
|
||||
|
||||
@ -93,10 +99,16 @@ abstract class GraphicsCard extends component.ManagedComponent {
|
||||
def setForeground(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
val color = args.checkInteger(0)
|
||||
screen(s => {
|
||||
val oldColor = s.getForegroundColor
|
||||
val oldIsPalette = s.isForegroundFromPalette
|
||||
val oldValue = s.getForegroundColor
|
||||
val (oldColor, oldIndex) =
|
||||
if (s.isForegroundFromPalette) {
|
||||
(s.getPaletteColor(oldValue), oldValue)
|
||||
}
|
||||
else {
|
||||
(oldValue, Unit)
|
||||
}
|
||||
s.setForegroundColor(color, args.count > 1 && args.checkBoolean(1))
|
||||
result(oldColor, oldIsPalette)
|
||||
result(oldColor, oldIndex)
|
||||
})
|
||||
}
|
||||
|
||||
@ -176,7 +188,25 @@ abstract class GraphicsCard extends component.ManagedComponent {
|
||||
val x = args.checkInteger(0) - 1
|
||||
val y = args.checkInteger(1) - 1
|
||||
screen(s => {
|
||||
result(s.get(x, y), s.getForegroundColor(x, y), s.getBackgroundColor(x, y), s.isForegroundFromPalette(x, y), s.isBackgroundFromPalette(x, y))
|
||||
val fgValue = s.getForegroundColor(x, y)
|
||||
val (fgColor, fgIndex) =
|
||||
if (s.isForegroundFromPalette(x, y)) {
|
||||
(s.getPaletteColor(fgValue), fgValue)
|
||||
}
|
||||
else {
|
||||
(fgValue, Unit)
|
||||
}
|
||||
|
||||
val bgValue = s.getBackgroundColor(x, y)
|
||||
val (bgColor, bgIndex) =
|
||||
if (s.isBackgroundFromPalette(x, y)) {
|
||||
(s.getPaletteColor(bgValue), bgValue)
|
||||
}
|
||||
else {
|
||||
(bgValue, Unit)
|
||||
}
|
||||
|
||||
result(s.get(x, y), fgColor, bgColor, fgIndex, bgIndex)
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user