using System; using ColdMint.scripts.debug; using Godot; namespace ColdMint.scripts.stateMachine; /// /// Context of the state machine /// 状态机的上下文环境 /// public class StateContext { private State _currentState; /// /// Previous state /// 前一个状态 /// private State _previousState; /// /// The state context holds the current state /// 状态上下文持有当前状态 /// public State CurrentState { get => _currentState; set { if (_currentState == value) { LogCat.LogWarning("try_to_set_the_same_state", label: LogCat.LogLabel.StateContext); return; } LogCat.LogWithFormat("state_change", label: LogCat.LogLabel.StateContext, _currentState, value); OnStateChange?.Invoke(_currentState, value); _previousState = _currentState; _currentState = value; } } /// /// Previous state /// 前一个状态 /// public State PreviousState { get => _previousState; set => _previousState = value; } /// /// When the state changes /// 当状态改变时 /// public Action? OnStateChange; /// /// owner /// 主人 /// public Node? Owner { get; set; } }