using System.Collections.Generic; using Code.Game.Entities; using Code.OfficeGame.BattleMode.Actions; using UnityEngine; namespace Code.OfficeGame.BattleMode.Snapshots { public class SnapshotUtilityNonStatic { Dictionary actionDataSnapshots = new(); Dictionary resultsSnapshots = new(); Dictionary entitySnapshots = new(); public void GetSnapshots( Dictionary entities, Dictionary actionDecisionResults, Dictionary battleActionDatas) { foreach (var (entityId, entity) in entities) { if (!actionDecisionResults.TryGetValue(entityId, out var actionDecisionResult) || !battleActionDatas.TryGetValue(entityId, out var battleActionData)) { entity.EntityPreviewVisuals.ShowPreviewState(spawnStaticSnapshotGhost: false); continue; } entity.EntityPreviewVisuals.ShowPreviewState(spawnStaticSnapshotGhost: true); resultsSnapshots[entityId] = actionDecisionResult.GetSnapshot(); actionDataSnapshots[entityId] = battleActionData.GetSnapshot(); entitySnapshots[entityId] = entity.GetSnapshot(); } } public void RestoreFromSnapshots( Dictionary entities, Dictionary actionDecisionResults, Dictionary battleActionDatas) { foreach (var (entityId, entity) in entities) { if (!resultsSnapshots.TryGetValue(entityId, out var actionDecisionResult) || !actionDataSnapshots.TryGetValue(entityId, out var battleActionData)) continue; if (actionDecisionResults.TryGetValue(entityId, out var currentDecisionResult) && battleActionDatas.TryGetValue(entityId, out var currentActionData)) { Debug.Log( $"Restoring {actionDecisionResult.ActionType} of {currentDecisionResult.ActionType} for {entityId}"); Debug.Log( $"Also {battleActionData} of {currentActionData} for {entityId}"); } actionDecisionResults[entityId] = actionDecisionResult.GetSnapshot(); battleActionDatas[entityId] = battleActionData.GetSnapshot(); entity.RestoreSnapshot(entitySnapshots[entityId]); } } } }