WTF are you doing anna lyse?

This commit is contained in:
Michal Pikulski
2025-11-02 13:29:42 +01:00
parent ebca297d28
commit 14416e141e
23 changed files with 867 additions and 1480 deletions

View File

@@ -2,14 +2,26 @@
using Pathfinding;
using AppleHills.Core.Settings;
using Core;
using Core.SaveLoad;
using Bootstrap;
namespace Input
{
/// <summary>
/// Saveable data for PlayerTouchController state
/// </summary>
[System.Serializable]
public class PlayerSaveData
{
public Vector3 worldPosition;
public Quaternion worldRotation;
}
/// <summary>
/// Handles player movement in response to tap and hold input events.
/// Supports both direct and pathfinding movement modes, and provides event/callbacks for arrival/cancellation.
/// </summary>
public class PlayerTouchController : MonoBehaviour, ITouchInputConsumer
public class PlayerTouchController : MonoBehaviour, ITouchInputConsumer, ISaveParticipant
{
// --- Movement State ---
private Vector3 targetPosition;
@@ -55,6 +67,9 @@ namespace Input
private bool interruptMoveTo;
private LogVerbosity _logVerbosity = LogVerbosity.Warning;
// Save system tracking
private bool hasBeenRestored;
void Awake()
{
aiPath = GetComponent<AIPath>();
@@ -71,6 +86,9 @@ namespace Input
// Initialize settings reference using GetSettingsObject
_settings = GameManager.GetSettingsObject<IPlayerFollowerSettings>();
// Register for post-boot initialization
BootCompletionService.RegisterInitAction(InitializePostBoot);
}
void Start()
@@ -79,6 +97,29 @@ namespace Input
_logVerbosity = DeveloperSettingsProvider.Instance.GetSettings<DebugSettings>().inputLogVerbosity;
}
private void InitializePostBoot()
{
// Register with save system after boot
if (SaveLoadManager.Instance != null)
{
SaveLoadManager.Instance.RegisterParticipant(this);
Logging.Debug("[PlayerTouchController] Registered with SaveLoadManager");
}
else
{
Logging.Warning("[PlayerTouchController] SaveLoadManager not available for registration");
}
}
void OnDestroy()
{
// Unregister from save system
if (SaveLoadManager.Instance != null)
{
SaveLoadManager.Instance.UnregisterParticipant(GetSaveId());
}
}
/// <summary>
/// Handles tap input. Always uses pathfinding to move to the tapped location.
/// Cancels any in-progress MoveToAndNotify.
@@ -415,5 +456,52 @@ namespace Input
Logging.Debug($"[PlayerTouchController] {message}");
}
}
#region ISaveParticipant Implementation
public bool HasBeenRestored => hasBeenRestored;
public string GetSaveId()
{
return "PlayerController";
}
public string SerializeState()
{
var saveData = new PlayerSaveData
{
worldPosition = transform.position,
worldRotation = transform.rotation
};
return JsonUtility.ToJson(saveData);
}
public void RestoreState(string serializedData)
{
if (string.IsNullOrEmpty(serializedData))
{
Logging.Debug("[PlayerTouchController] No saved state to restore");
hasBeenRestored = true;
return;
}
try
{
var saveData = JsonUtility.FromJson<PlayerSaveData>(serializedData);
if (saveData != null)
{
transform.position = saveData.worldPosition;
transform.rotation = saveData.worldRotation;
hasBeenRestored = true;
Logging.Debug($"[PlayerTouchController] Restored position: {saveData.worldPosition}");
}
}
catch (System.Exception ex)
{
Logging.Warning($"[PlayerTouchController] Failed to restore state: {ex.Message}");
}
}
#endregion
}
}