﻿//----------------------------------------------
// UTAGE: Unity Text Adventure Game Engine
// Copyright 2014 Ryohei Tokimura
//----------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Utage
{
	//Adx2用のファイルロード管理
	public class Adx2AssetFile : AssetFileBase
	{
		public Adx2AssetFile(AssetFileManager mangager, AssetFileInfo fileInfo, IAssetFileSettingData settingData, Adx2LeForUtage adx2LeForUtage)
			: base(mangager, fileInfo, settingData)
		{
			this.Adx2LeForUtage = adx2LeForUtage;
			this.CueName = FilePathUtil.GetFileNameWithoutExtension(this.FileName);
			this.SoundSetting = settingData as IAssetFileSoundSettingData;

			if (SoundSetting.RowData != null)
			{
				this.CueSheet = settingData.RowData.ParseCellOptional<string>("CueSheet", Adx2LeForUtage.DefaultQueSheet);
			}
			else
			{
				this.CueSheet = Adx2LeForUtage.DefaultQueSheet;
			}
		}

		public Adx2LeForUtage Adx2LeForUtage { get; protected set; }
		public string CueSheet { get; protected set; }
		public string CueName { get; protected set; }
		public IAssetFileSoundSettingData SoundSetting { get; protected set; }


		public override bool CheckCacheOrLocal()
		{
			return true;
		}

		public override IEnumerator LoadAsync( Action onComplete, Action onFailed )
		{
			if (CriAtom.GetCueSheet(this.CueSheet) == null)
			{
				string acbPath = this.CueSheet + ".acb";
				string awbPath = this.CueSheet + ".awb";
				CriAtom.AddCueSheet(this.CueSheet, acbPath, awbPath);
			}
			IsLoadEnd = true;
			if (onComplete != null) onComplete();
			yield break;
		}
		public override void Unload()
		{
			IsLoadEnd = false;		
		}
	}
}
