extends Node3D

@export var arena_size: float = 14.0
@export var show_grid: bool = true

func _ready() -> void:
	if show_grid:
		_draw_grid()

func _draw_grid() -> void:
	var grid_mat := StandardMaterial3D.new()
	grid_mat.albedo_color = Color(0.2, 0.2, 0.3, 0.5)
	grid_mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
	grid_mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
	var step := 4.0
	var n := int(arena_size / step)
	for i in range(-n, n + 1):
		for axis in [0, 1]:
			var msh := MeshInstance3D.new()
			var box := BoxMesh.new()
			if axis == 0:
				box.size = Vector3(0.05, 0.01, arena_size * 2)
				msh.position = Vector3(i * step, 0.005, 0)
			else:
				box.size = Vector3(arena_size * 2, 0.01, 0.05)
				msh.position = Vector3(0, 0.005, i * step)
			msh.mesh = box
			msh.material_override = grid_mat
			add_child(msh)
