palette textures! working with palettes will be a breezegit status!
This commit is contained in:
parent
7974ac26c4
commit
f1ad9d5825
10 changed files with 65 additions and 8 deletions
50
scripts/palette_texture.gd
Normal file
50
scripts/palette_texture.gd
Normal file
|
@ -0,0 +1,50 @@
|
|||
tool
|
||||
class_name PaletteTexture
|
||||
extends ImageTexture
|
||||
|
||||
|
||||
export (Array, Color) var colors := [] setget _set_colors
|
||||
export var convert_from: Texture = null setget _convert_from
|
||||
|
||||
|
||||
var _data := PoolByteArray()
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
colors.resize(16)
|
||||
colors.fill(Color.white)
|
||||
_data.resize(16 * 4)
|
||||
_data.fill(255)
|
||||
_update_image()
|
||||
|
||||
|
||||
func _set_colors(new_array: Array) -> void:
|
||||
if new_array.size() == 16:
|
||||
colors = new_array
|
||||
_update_image()
|
||||
|
||||
|
||||
func _update_image() -> void:
|
||||
for i in colors.size():
|
||||
var c: Color = colors[i]
|
||||
var j: int = i * 4
|
||||
_data[j] = c.r8
|
||||
_data[j + 1] = c.g8
|
||||
_data[j + 2] = c.b8
|
||||
_data[j + 3] = c.a8
|
||||
|
||||
var image := Image.new()
|
||||
image.create_from_data(4, 4, false, Image.FORMAT_RGBA8, _data)
|
||||
create_from_image(image, 0)
|
||||
|
||||
|
||||
func _convert_from(texture: Texture) -> void:
|
||||
if texture != null and texture.get_size() == Vector2(4.0, 4.0):
|
||||
var image := texture.get_data()
|
||||
image.lock()
|
||||
for x in 4:
|
||||
for y in 4:
|
||||
colors[x + (y * 4)] = image.get_pixel(x, y)
|
||||
print(colors[x + (y * 4)])
|
||||
image.unlock()
|
||||
_update_image()
|
Loading…
Add table
Add a link
Reference in a new issue