chip-gameV3/Assets/Scripts/Common/GameFSM/CheckSettingsPasswordState.cs
sega 8a6d23b77d Реорг Scripts
Разделено на 4 модуля
- Menu
- Gameplay
- Settings
- Common
2026-07-15 10:49:55 +03:00

98 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using UnityEngine;
public class CheckSettingsPasswordState : IState
{
EnterPasswordPanel panel;
public void enter()
{
panel = GameManager.instance.enterPasswordPanel;
Debug.Log("[Проход в настройки]");
//Пароль не установлен.
bool Pwd = SettingsManager.GetBool("PasswordOnSettings", false);
if (!Pwd)
{
Debug.Log("[Пароля нет, заходим братья]");
GameManager.instance.stateMachine.ChangeState(new SettingsState());
return;
}
//Пароль есть.
//Получить пароль.
string password = ExternalFilesGetter.GetSettingsPassword();
//Если он не валидный, то сбросить настройку и пропустить.
if (password == null)
{
Debug.Log("[Файла пароля нет. Сброс пароля. Заход в настройки]");
disableCheck();
GameManager.instance.stateMachine.ChangeState(new SettingsState());
return;
}
if (PasswordValid(password))
{
// если валидный, то запускаем ввод пароля
panel.gameObject.SetActive(true);
panel.Initialize(password);
}
else
{
Debug.Log("[пароль невалидный. Сброс пароля. Заход в настройки]");
disableCheck();
ExternalFilesGetter.SetPassword("");
GameManager.instance.stateMachine.ChangeState(new SettingsState());
}
}
private static void disableCheck()
{
Setting setting = SettingsManager.Container.TryGetSetting("PasswordOnSettings");
setting.ChangeValue(-1);//ставим false
SettingsManager.OnSettingsChanged?.Invoke();
}
public void exit()
{
panel.gameObject.SetActive(false);
}
public void update()
{
panel._Update();
if (panel.truePassword)
{
GameManager.instance.stateMachine.ChangeState(new SettingsState());
}
}
private bool PasswordValid(string password)
{
if(password.Length!=12) return false;
List<string> combinations = SplitPasswordIntoPairs(password);
List<string> validCombinations = new List<string> { "L1", "L2", "R1", "R2", "A1", "A2", "P1", "P2" };
foreach (string combination in combinations)
{
if (!validCombinations.Contains(combination)) return false;
}
return true;
}
List<string> SplitPasswordIntoPairs(string password)
{
List<string> result = new List<string>();
for (int i = 0; i < password.Length; i += 2)
{
result.Add(password.Substring(i, 2));
}
return result;
}
}