extends Node2D

var cubism_model

func _ready() -> void:
	var klass = ClassDB.instantiate("GDCubismUserModel")
	if klass == null:
		push_error("viewer_min: GDCubismUserModel class unavailable")
		return

	cubism_model = klass
	add_child(cubism_model)

	var model_path = "res://addons/gd_cubism/example/res/live2d/Haru/Haru.model3.json"
	cubism_model.set("assets", model_path)

	await get_tree().process_frame
	await get_tree().process_frame

	print("MINIVIEW_HARU assets_assigned=true")

	var canvas_info = cubism_model.get_canvas_info()
	var viewport_size = get_viewport_rect().size
	if not canvas_info.is_empty():
		var size_px = canvas_info.size_in_pixels
		var scale = viewport_size.y / max(size_px.x, size_px.y)
		cubism_model.position = viewport_size / 2.0
		cubism_model.scale = Vector2(scale, scale)

	print("MINIVIEW_HARU loaded=true")
	print("MINIVIEW_HARU assets=%s" % model_path)
