/*
 * auto generated by tools(注意:千万不要手动修改本文件)
 * AudioObject
 */
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace OCES.Audio
{
[Serializable]
public partial class AudioObject : IBinarySerializable
{
	/// <summary>
	/// 唯一ID
	/// </summary>
	public uint Id { get; set; }

	/// <summary>
	/// 文件名
	/// </summary>
	public List<string> Name { get; set; }

	/// <summary>
	/// 备注
	/// </summary>
	public string Comment { get; set; }

	/// <summary>
	/// 初始延迟
	/// 单位秒
	/// </summary>
	public float InitialDelay { get; set; }

	/// <summary>
	/// -1 = 无限循环
	/// 0 = 不循环
	/// >= 1 按次数循环
	/// </summary>
	public short LoopCount { get; set; }

	/// <summary>
	/// 0 = SFX
	/// 1 = Voice
	/// 2 = Accent
	/// </summary>
	public MixingType MixingType { get; set; }

	/// <summary>
	/// 发音分组
	/// </summary>
	public uint Group { get; set; }

	/// <summary>
	/// 同时发音数限制
	/// </summary>
	public ushort ThrottleCount { get; set; }

	/// <summary>
	/// 最小发音间隔
	/// </summary>
	public ushort MinInterval { get; set; }

	/// <summary>
	/// 优先级
	/// </summary>
	public byte Priority { get; set; }

	/// <summary>
	/// 打断模式 
	/// 0 = 打断最早
	/// 1 = 打断最新
	/// </summary>
	public KillMode KillMode { get; set; }

	/// <summary>
	/// Pitch Step阈值 ms
	/// </summary>
	public uint PitchStepThreshold { get; set; }

	/// <summary>
	/// 阶段变化半音数
	/// </summary>
	public sbyte PitchStep { get; set; }

	/// <summary>
	/// step几步后就不再继续提升音高
	/// </summary>
	public byte PitchStepLimit { get; set; }

	/// <summary>
	/// 相关的触感反馈ID
	/// </summary>
	public uint Haptic { get; set; }

	/// <summary>
	/// 0 = 随机播放
	/// 1 = 顺序播放
	/// 2 = 混合播放
	/// </summary>
	public ContainerType ContainerType { get; set; }

	/// <summary>
	/// 0 = 步进
	/// 1 = 持续
	/// </summary>
	public bool ContainerPlayMode { get; set; }

	/// <summary>
	/// 按段落配置每段响应范围，用|分隔不同段落
	/// </summary>
	public string BlendRanges { get; set; }

	/// <summary>
	/// 0 = 指数
	/// 1 = 线形
	/// 2 = 对数
	/// </summary>
	public BlendCrossFadeType BlendCrossFadeType { get; set; }

	/// <summary>
	/// 指定避免重复的次数
	/// </summary>
	public byte LimitRepetition { get; set; }

	/// <summary>
	/// 0 = Standard
	/// 1 = Shuffle
	/// </summary>
	public bool RandomType { get; set; }

	/// <summary>
	/// Volume Step阈值 ms
	/// </summary>
	public uint VolumeStepThreshold { get; set; }

	/// <summary>
	/// 起始音量
	/// dB
	/// </summary>
	public int Volume { get; set; }

	/// <summary>
	/// 音量变化幅度
	/// dB
	/// </summary>
	public int VolumeStep { get; set; }


	public void DeSerialize(BinaryReader reader)
	{
		Id = reader.ReadUInt32();
		var nameCount = reader.ReadInt32();
		if (nameCount > 0)
		{
			Name = new List<string>();
			for (int i = 0; i < nameCount; i++)
			{
				Name.Add(reader.ReadString());
			}
		}
		else
		{
			Name = null;
		}
		Comment = reader.ReadString();
		InitialDelay = reader.ReadSingle();
		LoopCount = reader.ReadInt16();
		MixingType = (MixingType)reader.ReadByte();
		Group = reader.ReadUInt32();
		ThrottleCount = reader.ReadUInt16();
		MinInterval = reader.ReadUInt16();
		Priority = reader.ReadByte();
		KillMode = (KillMode)reader.ReadByte();
		PitchStepThreshold = reader.ReadUInt32();
		PitchStep = reader.ReadSByte();
		PitchStepLimit = reader.ReadByte();
		Haptic = reader.ReadUInt32();
		ContainerType = (ContainerType)reader.ReadByte();
		ContainerPlayMode = reader.ReadBoolean();
		BlendRanges = reader.ReadString();
		BlendCrossFadeType = (BlendCrossFadeType)reader.ReadByte();
		LimitRepetition = reader.ReadByte();
		RandomType = reader.ReadBoolean();
		VolumeStepThreshold = reader.ReadUInt32();
		Volume = reader.ReadInt32();
		VolumeStep = reader.ReadInt32();
	}

	public void Serialize(BinaryWriter writer)
	{
		writer.Write(Id);
		if (Name == null || Name.Count == 0)
		{
			writer.Write(0);
		}
		else
		{
			writer.Write(Name.Count);
			foreach (var t in Name)
			{
				writer.Write(t);
			}
		}
		writer.Write(Comment);
		writer.Write(InitialDelay);
		writer.Write(LoopCount);
		writer.Write((byte)MixingType);
		writer.Write(Group);
		writer.Write(ThrottleCount);
		writer.Write(MinInterval);
		writer.Write(Priority);
		writer.Write((byte)KillMode);
		writer.Write(PitchStepThreshold);
		writer.Write(PitchStep);
		writer.Write(PitchStepLimit);
		writer.Write(Haptic);
		writer.Write((byte)ContainerType);
		writer.Write(ContainerPlayMode);
		writer.Write(BlendRanges);
		writer.Write((byte)BlendCrossFadeType);
		writer.Write(LimitRepetition);
		writer.Write(RandomType);
		writer.Write(VolumeStepThreshold);
		writer.Write(Volume);
		writer.Write(VolumeStep);
	}
}

[Serializable]
public partial class AudioObjectConfig : IBinarySerializable
{
	Dictionary<uint,AudioObject> m_audioObjectInfos = new();
	List<AudioObject> m_audioObjectInfoList;

	public List<AudioObject> AudioObjectList()
	{
		this.m_audioObjectInfoList ??= new List<AudioObject>(this.m_audioObjectInfos.Values);
		return this.m_audioObjectInfoList;
	}

	public void DeSerialize(BinaryReader reader)
	{
		int count = reader.ReadInt32();
		for (int i = 0; i < count; i++)
		{
			AudioObject tempData = new();
			tempData.DeSerialize(reader);
			this.m_audioObjectInfos.Add(tempData.Id, tempData);
		}
	}

	public void Serialize(BinaryWriter writer)
	{
		writer.Write(this.m_audioObjectInfos.Count);
		foreach (AudioObject audioObject in this.m_audioObjectInfos.Values)
		{
			audioObject.Serialize(writer);
		}
	}

	public AudioObject QueryById(uint id)
	{
		return this.m_audioObjectInfos.GetValueOrDefault(id);
	}
}
}
