mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-26 22:43:40 -04:00
Merge branch 'master' of github.com:MightyPirates/OpenComputers into MC1.7
This commit is contained in:
commit
f1cbe10edb
@ -36,6 +36,12 @@ object PackedColor {
|
||||
|
||||
def inflate(value: Int): Int
|
||||
|
||||
def validate(value: Color) {
|
||||
if (value.isPalette) {
|
||||
throw new IllegalArgumentException("color palette not supported")
|
||||
}
|
||||
}
|
||||
|
||||
def deflate(value: Color): Byte
|
||||
|
||||
override def load(nbt: NBTTagCompound) {}
|
||||
@ -48,12 +54,20 @@ object PackedColor {
|
||||
|
||||
override def inflate(value: Int) = if (value == 0) 0x000000 else 0xFFFFFF
|
||||
|
||||
override def deflate(value: Color) = (if (value.value == 0) 0 else 1).toByte
|
||||
override def deflate(value: Color) = {
|
||||
(if (value.value == 0) 0 else 1).toByte
|
||||
}
|
||||
}
|
||||
|
||||
abstract class PaletteFormat extends ColorFormat {
|
||||
override def inflate(value: Int) = palette(math.max(0, math.min(palette.length - 1, value)))
|
||||
|
||||
override def validate(value: Color) {
|
||||
if (value.isPalette && (value.value < 0 || value.value >= palette.length)) {
|
||||
throw new IllegalArgumentException("invalid palette index")
|
||||
}
|
||||
}
|
||||
|
||||
override def deflate(value: Color) =
|
||||
if (value.isPalette) (math.max(0, value.value) % palette.length).toByte
|
||||
else palette.map(delta(value.value, _)).zipWithIndex.minBy(_._1)._2.toByte
|
||||
|
@ -27,15 +27,19 @@ class TextBuffer(var width: Int, var height: Int, initialFormat: PackedColor.Col
|
||||
def foreground = _foreground
|
||||
|
||||
def foreground_=(value: PackedColor.Color) = {
|
||||
format.validate(value)
|
||||
_foreground = value
|
||||
packed = PackedColor.pack(_foreground, _background, _format)
|
||||
this
|
||||
}
|
||||
|
||||
def background = _background
|
||||
|
||||
def background_=(value: PackedColor.Color) = {
|
||||
format.validate(value)
|
||||
_background = value
|
||||
packed = PackedColor.pack(_foreground, _background, _format)
|
||||
this
|
||||
}
|
||||
|
||||
def format = _format
|
||||
|
Loading…
x
Reference in New Issue
Block a user