extends Node2D

const MODEL_PATH = "/home/nandi/.local/share/godot/app_userdata/open-vt/Live2DModels/Haru/Haru.model3.json"
const SHADERS = [
	preload("res://addons/gd_cubism/res/shader/2d_cubism_norm_add.gdshader"),
	preload("res://addons/gd_cubism/res/shader/2d_cubism_norm_mix.gdshader"),
	preload("res://addons/gd_cubism/res/shader/2d_cubism_norm_mul.gdshader"),
	preload("res://addons/gd_cubism/res/shader/2d_cubism_mask.gdshader"),
]

func _ready() -> void:
	var loader = ClassDB.instantiate("GDCubismModelLoader")
	if loader == null:
		push_error("minimal-haru: GDCubismModelLoader unavailable")
		get_tree().quit(1)
		return

	var model = loader.call("load_model", MODEL_PATH, SHADERS, true)
	if model == null:
		push_error("minimal-haru: failed to load Haru model")
		get_tree().quit(1)
		return

	model.set("mask_viewport_size", 2048)
	model.set_process(true)
	model.position = Vector2(640, 360)
	model.scale = Vector2.ONE * 0.12
	add_child(model)

	var physics = ClassDB.instantiate("GDCubismEffectPhysics")
	if physics != null:
		physics.name = "Physics"
		model.add_child(physics)

	await get_tree().process_frame

	print("MINIMAL_HARU loaded=true")
	print("MINIMAL_HARU initialized=%s" % JSON.stringify(model.call("is_initialized")))
	print("MINIMAL_HARU mesh_count=%s" % JSON.stringify(model.call("get_meshes").size()))
	print("MINIMAL_HARU position=%s" % JSON.stringify({"x": model.position.x, "y": model.position.y}))
	print("MINIMAL_HARU scale=%s" % JSON.stringify({"x": model.scale.x, "y": model.scale.y}))
	print("MINIMAL_HARU ready_for_interactive_use=true")
