ColourPaletteSampler.gd 597 B

12345678910111213141516171819202122232425
  1. class_name ColourPaletteSampler
  2. extends Node
  3. @export var texture: Texture2D = null:
  4. set(value):
  5. texture = value
  6. update()
  7. signal updated
  8. @export var coords := Vector2i.ZERO
  9. @export var node_to_affect: Node = null
  10. @export var value_to_set := ""
  11. func _ready() -> void:
  12. update()
  13. Global.level_theme_changed.connect(update)
  14. func update() -> void:
  15. if node_to_affect == null or texture == null:
  16. return
  17. var colour_to_sample: Color = Color.WHITE
  18. var image = texture.get_image()
  19. colour_to_sample = image.get_pixelv(coords)
  20. node_to_affect.set(value_to_set, colour_to_sample)
  21. updated.emit()