using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Text;
using Mox.Shared;
using Mox.Shared.Serializer;

namespace Game.Shared
{
	public class GameState : Serializable
	{
		public override void Serialize(Serializer _serializer)
		{
			if (_serializer.StartChild("GameState"))
			{
				int iVersion = 1;
				_serializer.Serialize(ref iVersion, nameof(iVersion), 0);

				if (iVersion != 1)
				{
					throw new SerializationException("Invalid game state version");
				}

				_serializer.Serialize(ref m_bPlayMusic, nameof(PlayMusic), true);
				_serializer.EndChild();
			}

			if (_serializer.IsLoading)
			{
				InvalidateProperties();
			}
		}

		private void InvalidateProperties()
		{
			PlayMusic = PlayMusic;
		}

		public bool PlayMusic
		{
			get => m_bPlayMusic;
			set
			{
				m_bPlayMusic = value;

				if (m_bPlayMusic)
				{
					ProgramBase.Instance.PlaySound("music", true);
				}
				else
				{
					ProgramBase.Instance.StopSound("music");
				}
			}
		}

		private bool m_bPlayMusic = true;
	}
}
