Refactoring of the interaction system and preliminary integration of save/load functionality across the game. (#44)

### Interactables Architecture Refactor
- Converted composition to inheritance, moved from component-based to class-based interactables. No more requirement for chain of "Interactable -> Item" etc.
- Created `InteractableBase` abstract base class with common functionality that replaces the old component
- Specialized child classes: `Pickup`, `ItemSlot`, `LevelSwitch`, `MinigameSwitch`, `CombinationItem`, `OneClickInteraction` are now children classes
- Light updates to the interactable inspector, moved some things arround, added collapsible inspector sections in the  UI for better editor experience

### State Machine Integration
- Custom `AppleMachine` inheritong from Pixelplacement's StateMachine which implements our own interface for saving, easy place for future improvements
- Replaced all previous StateMachines by `AppleMachine`
- Custom `AppleState`  extends from default `State`. Added serialization, split state logic into "EnterState", "RestoreState", "ExitState" allowing for separate logic when triggering in-game vs loading game
- Restores directly to target state without triggering transitional logic
- Migration tool converts existing instances

### Prefab Organization
- Saved changes from scenes into prefabs
- Cleaned up duplicated components, confusing prefabs hierarchies
- Created prefab variants where possible
- Consolidated Environment prefabs and moved them out of Placeholders subfolder into main Environment folder
- Organized item prefabs from PrefabsPLACEHOLDER into proper Items folder
- Updated prefab references - All scene references updated to new locations
- Removed placeholder files from Characters, Levels, UI, and Minigames folders

### Scene Updates
- Quarry scene with major updates
- Saved multiple working versions (Quarry, Quarry_Fixed, Quarry_OLD)
- Added proper lighting data
- Updated all interactable components to new architecture

### Minor editor tools
- New tool for testing cards from an editor window (no in-scene object required)
- Updated Interactable Inspector
- New debug option to opt in-and-out of the save/load system
- Tooling for easier migration

Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com>
Reviewed-on: #44
This commit is contained in:
2025-11-03 10:12:51 +00:00
parent d317fffad7
commit 011901eb8f
148 changed files with 969503 additions and 10746 deletions

View File

@@ -17,9 +17,10 @@ namespace Interactions
}
/// <summary>
/// Represents an interactable object that can respond to tap input events.
/// Base class for interactable objects that can respond to tap input events.
/// Subclasses should override OnCharacterArrived() to implement interaction-specific logic.
/// </summary>
public class Interactable : MonoBehaviour, ITouchInputConsumer
public class InteractableBase : MonoBehaviour, ITouchInputConsumer
{
[Header("Interaction Settings")]
public bool isOneTime;
@@ -34,8 +35,8 @@ namespace Interactions
// Helpers for managing interaction state
private bool _interactionInProgress;
private PlayerTouchController _playerRef;
private FollowerController _followerController;
protected PlayerTouchController _playerRef;
protected FollowerController _followerController;
private bool _isActive = true;
private InteractionEventType _currentEventType;
@@ -420,7 +421,7 @@ namespace Interactions
if (step != null && !step.IsStepUnlocked() && slot == null)
{
DebugUIMessage.Show("This step is locked!", Color.yellow);
BroadcastInteractionComplete(false);
CompleteInteraction(false);
// Reset variables for next time
_interactionInProgress = false;
_playerRef = null;
@@ -434,6 +435,9 @@ namespace Interactions
// Broadcast appropriate event
characterArrived?.Invoke();
// Call the virtual method for subclasses to override
OnCharacterArrived();
// Reset variables for next time
_interactionInProgress = false;
_playerRef = null;
@@ -441,6 +445,17 @@ namespace Interactions
return Task.CompletedTask;
}
/// <summary>
/// Called when the character has arrived at the interaction point.
/// Subclasses should override this to implement interaction-specific logic
/// and call CompleteInteraction(bool success) when done.
/// </summary>
protected virtual void OnCharacterArrived()
{
// Default implementation does nothing - subclasses should override
// and call CompleteInteraction when their logic is complete
}
private async void OnInteractionComplete(bool success)
{
// Dispatch InteractionComplete event
@@ -481,11 +496,25 @@ namespace Interactions
throw new NotImplementedException();
}
public void BroadcastInteractionComplete(bool success)
/// <summary>
/// Call this from subclasses to mark the interaction as complete.
/// </summary>
/// <param name="success">Whether the interaction was successful</param>
protected void CompleteInteraction(bool success)
{
interactionComplete?.Invoke(success);
}
/// <summary>
/// Legacy method for backward compatibility. Use CompleteInteraction instead.
/// </summary>
/// TODO: Remove this method in future versions
[Obsolete("Use CompleteInteraction instead")]
public void BroadcastInteractionComplete(bool success)
{
CompleteInteraction(success);
}
#if UNITY_EDITOR
/// <summary>
/// Draws gizmos for pickup interaction range in the editor.