tool
extends Node2D
class_name Piece

export var size: int = 160

var order: int = 0
var taquin_position := Vector2.ZERO
var taquin_index := Vector2.ZERO
var piece_scale := Vector2(0.25, 0.25)

func _ready() -> void:
	$ColorRect.rect_size = Vector2(size, size)
	$ColorRect/Label.text = str(order)

	# We need a dedicated material to have separate uniform,
	# otherwise uniforms will be shared.
	var mat = $ColorRect.material.duplicate() as ShaderMaterial
	mat.set_shader_param("scale", Vector3(piece_scale.x, piece_scale.y, 1.0))
	mat.set_shader_param("offset", Vector3(taquin_position.x, taquin_position.y, 0.0))
	$ColorRect.material = mat

func debug_print(name: String):
	print("%s order: %s" % [name, order])
	print("%s taquin index: %s" % [name, taquin_index])
	print("%s taquin position: %s" % [name, position])
