
using System;

namespace Animrig
{
    public class Logger
    {
        public static Action<string> OnLog = null;
        public static void Log(string s)
        {
            if (OnLog != null) OnLog(s);
        }
        public static string FloatToStr(float f)
        {
            return f.ToString("F2");
        } 
        public static string IntToStr(int v)
        {
            return v.ToString();
        }
        public static string BoolToStr(bool b)
        {
            if (b)
                return "true";
            else
                return "false";
        }
        public static string FloatArrayToStr(float[] array)
        {
            string s = "";
            for (var i = 0; i < array.Length; i++)
            {
                if (i > 0) s += " , ";
                s += FloatToStr(array[i]);
            }
            return s;
        }
        public static string FloatColorToStr(Animrig.FloatColor c)
        {
            string s = FloatToStr(c.a) + "," + FloatToStr(c.r) + "," + FloatToStr(c.g) + "," + FloatToStr(c.b);
            return s;
        }
        public static string MatrixToStr(ref Matrix4 m)
        {
            string s = "";
            s += FloatToStr(m._11) + "," + FloatToStr(m._12) + "," + FloatToStr(m._13) + "," + FloatToStr(m._14);
            s += " , " + FloatToStr(m._21) + "," + FloatToStr(m._22) + "," + FloatToStr(m._23) + "," + FloatToStr(m._24);
            s += " , " + FloatToStr(m._31) + "," + FloatToStr(m._32) + "," + FloatToStr(m._33) + "," + FloatToStr(m._34);
            s += " , " + FloatToStr(m._41) + "," + FloatToStr(m._42) + "," + FloatToStr(m._43) + "," + FloatToStr(m._44);
            return s;
        }
        public static string VectorToStr(ref Vector3 v)
        {
            return FloatToStr(v.x) + " , " + FloatToStr(v.y) + " , " + FloatToStr(v.z);
        }
    }

    public class StateLogRenderer : StateRenderer
    {
        public string name = "";

        public StateLogRenderer(ObjectType dummyobjecttype)
            : base()
        {
            ObjectType = dummyobjecttype;
        }
        // common
        public override void Update(double deltatime, double deltaphysics)
        {
            Logger.Log(name + ".renderer.update : " + Logger.FloatToStr((float)deltatime));
            Logger.Log(name + ".renderer.state");
            Logger.Log("  priority.z : " + Logger.FloatToStr(DrawPriorityZ));
            Logger.Log("  priority.design : " + Logger.FloatToStr(DrawPriorityDesign));
            Logger.Log("  enable : " + Logger.BoolToStr(RendererEnable));
            Logger.Log("  visible : " + Logger.BoolToStr(RendererVisible));
            Logger.Log("  color : " + Logger.FloatColorToStr(TransColor));
            Logger.Log("  matrix : " + Logger.MatrixToStr(ref TransMatrix));
        }
        // spine
        public override void SetAnimation(int trackindex, int usetrack, string basename, bool loop, bool addanim, MixBlend trackmix, float duration, bool seekmode, float loopbegin, float loopend)
        {
            Logger.Log(name + ".renderer.SetAnimation");
            Logger.Log("  track : " + Logger.IntToStr(trackindex));
            Logger.Log("  name : " + basename);
            Logger.Log("  loop : " + Logger.BoolToStr(loop));
            Logger.Log("  addanimation : " + Logger.BoolToStr(addanim));
            if (trackmix == MixBlend.Replace)
                Logger.Log("  trackmix : replace");
            else
                Logger.Log("  trackmix : add");
            Logger.Log("  duration : " + Logger.FloatToStr(duration));
            Logger.Log("  seekmode : " + Logger.BoolToStr(seekmode));
            Logger.Log("  loopbegin : " + Logger.FloatToStr(loopbegin));
            Logger.Log("  loopend : " + Logger.FloatToStr(loopend));
        }
        public override void SetTrackBlendAlpha(int trackindex, int usetrack, float alpha1, float alpha2, float alpha3, float alpha4, bool exists)
        {
            var s = Logger.FloatToStr(alpha1) + " , " +
                Logger.FloatToStr(alpha2) + " , " +
                Logger.FloatToStr(alpha3) + " , " +
                Logger.FloatToStr(alpha4);
            Logger.Log(name + ".renderer.SetTrackBlendAlpha");
            Logger.Log("  layer exists : " + Logger.BoolToStr(exists));
            Logger.Log("  track : " + Logger.IntToStr(trackindex));
            Logger.Log("  alpha : " + s);
        }
        public override void SetTrackSeekTime(int trackindex, int usetrack, float time1, float time2, float time3, float time4, bool exists)
        {
            var s = Logger.FloatToStr(time1) + " , " +
                Logger.FloatToStr(time2) + " , " +
                Logger.FloatToStr(time3) + " , " +
                Logger.FloatToStr(time4);
            Logger.Log(name + ".renderer.SetTrackSeekTime");
            Logger.Log("  layer exists : " + Logger.BoolToStr(exists));
            Logger.Log("  track : " + Logger.IntToStr(trackindex));
            Logger.Log("  time : " + s);
        }
        public override void SetMixDuration(float duration)
        {
            Logger.Log(name + ".renderer.SetMixDuration : " + Logger.FloatToStr(duration));
        }
    }
}