extends Node

const MODEL_PATH = "/home/nandi/.local/share/godot/app_userdata/open-vt/Live2DModels/Haru/Haru.model3.json"

func report(key: String, value) -> void:
	print("PROBE %s=%s" % [key, JSON.stringify(value)])

func _ready() -> void:
	report("engine_version", Engine.get_version_info())
	report("model_exists", FileAccess.file_exists(MODEL_PATH))
	report("class_exists", ClassDB.class_exists("GDCubismUserModel"))
	report("loader_exists", ClassDB.class_exists("GDCubismModelLoader"))

	if ClassDB.class_exists("GDCubismModelLoader"):
		var loader = ClassDB.instantiate("GDCubismModelLoader")
		report("instantiate_loader", loader != null)
		if loader != null and loader.has_method("load_model"):
			var shaders = [
				load("res://addons/gd_cubism/res/shader/2d_cubism_norm_add.gdshader"),
				load("res://addons/gd_cubism/res/shader/2d_cubism_norm_mix.gdshader"),
				load("res://addons/gd_cubism/res/shader/2d_cubism_norm_mul.gdshader"),
				load("res://addons/gd_cubism/res/shader/2d_cubism_mask.gdshader"),
			]
			report("shader_count", shaders.size())
			var model = loader.load_model(MODEL_PATH, shaders, false)
			report("load_model_result", model != null)
			if model != null:
				report("instantiate_user_model", true)
				add_child(model)
				await get_tree().process_frame
				report("model_initialized", model.is_initialized() if model.has_method("is_initialized") else false)
	else:
		report("instantiate_loader", false)

	get_tree().quit()
