extends RefCounted

# The original trigger still owns quest effects. Combat scenes now belong to
# the real opponent in its room; old story checks must verify that link too.
const ALIASES := {"mld_entry_d1": "mld_entry", "mld_entry_d2": "mld_entry",
	"ti_gras_d4_lair": "ti_gras_d3_lair", "ti_gras_d4_fuses": "ti_gras_d3_fuses"}

static func scene_for_trigger(id: String) -> String:
	var trigger: Dictionary = DataCatalog.STORY_TRIGGERS.get(id, {})
	if trigger.is_empty():
		return ""
	var scene := str(trigger.get("scene", ""))
	if not scene.is_empty():
		return scene if DataCatalog.STORY_SCENES.has(scene) else ""
	scene = str(ALIASES.get(id, id))
	if not DataCatalog.STORY_SCENES.has(scene):
		return ""
	var room_filter := ""
	for condition: Dictionary in trigger.get("conditions", []):
		var parts := str(condition.get("path", "")).split(".")
		if parts.size() == 3 and parts[0] == "rooms" and parts[2] == "current" and condition.get("operator", "") == "truthy":
			room_filter = parts[1]
	for room_id: String in DataCatalog.ROOMS:
		if not room_filter.is_empty() and room_filter != room_id:
			continue
		for presentation: Dictionary in DataCatalog.ROOMS[room_id].get("combat_scenes", []):
			for field: String in ["intro_scene", "defeat_scene", "flee_scene"]:
				if presentation.get(field, "") == scene:
					return scene
	return ""
