using ExIni;

namespace CM3D2.MultipleMaids.Plugin
{
    public partial class MultipleMaids
    {
        public void Preference()
        {
            if (isPref)
                return;
            isPref = true;
            if (Preferences["config"]["hair_setting"].Value == "true")
            {
                isKamiyure = true;
                IniKey iniKey1 = Preferences["config"]["hair_radius"];
                IniKey iniKey2 = Preferences["config"]["hair_elasticity"];
                kamiyure2 = float.Parse(Preferences["config"]["hair_damping"].Value);
                kamiyure3 = float.Parse(iniKey2.Value);
                kamiyure4 = float.Parse(iniKey1.Value);
            }
            else
            {
                isKamiyure = false;
                kamiyure2 = 0.6f;
                kamiyure3 = 1f;
                kamiyure4 = 0.02f;
            }

            if (Preferences["config"]["skirt_setting"].Value == "true")
            {
                isSkirtyure = true;
                IniKey iniKey1 = Preferences["config"]["skirt_radius"];
                IniKey iniKey2 = Preferences["config"]["skirt_elasticity"];
                skirtyure2 = float.Parse(Preferences["config"]["skirt_damping"].Value);
                skirtyure3 = float.Parse(iniKey2.Value);
                skirtyure4 = float.Parse(iniKey1.Value);
            }
            else
            {
                isSkirtyure = false;
                skirtyure2 = 0.1f;
                skirtyure3 = 0.05f;
                skirtyure4 = 0.1f;
            }

            if (Preferences["config"]["hair_details"].Value == "true")
                isShosai = true;
            IniKey iniKey3 = Preferences["config"]["vr_scroll"];
            if (iniKey3.Value == "false")
            {
                isVRScroll = false;
            }
            else if (iniKey3.Value != "true")
            {
                Preferences["config"]["vr_scroll"].Value = "true";
                SaveConfig();
            }

            if (Preferences["config"]["shift_f7"].Value == "true")
                isF7S = true;
            if (Preferences["config"]["shift_f8"].Value == "false")
                isVR2 = false;
            IniKey iniKey4 = Preferences["config"]["ik_all"];
            if (iniKey4.Value == "true")
            {
                isIKAll = true;
                for (int index = 0; index < maxMaidCnt; ++index)
                    isIK[index] = true;
            }
            else if (iniKey4.Value != "false")
            {
                Preferences["config"]["ik_all"].Value = "true";
                SaveConfig();
                isIKAll = true;
                for (int index = 0; index < maxMaidCnt; ++index)
                    isIK[index] = true;
            }

            if (!int.TryParse(Preferences["config"]["scene_max"].Value, out maxPage))
            {
                maxPage = 100;
                Preferences["config"]["scene_max"].Value = "100";
                SaveConfig();
            }

            if (!int.TryParse(Preferences["config"]["kankyo_max"].Value, out kankyoMax))
            {
                kankyoMax = 20;
                Preferences["config"]["kankyo_max"].Value = "20";
                SaveConfig();
            }

            for (int index = 0; index < kankyoMax; ++index)
            {
                IniKey iniKey1 = Preferences["kankyo"]["kankyo" + (index + 1)];
                if (iniKey1.Value == null || iniKey1.Value == "")
                {
                    Preferences["kankyo"]["kankyo" + (index + 1)].Value = "環境" + (index + 1);
                    SaveConfig();
                }
            }

            maxPage /= 10;
        }
    }
}