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; bool actionChanged = false; if (!actionDecisionResults.TryAdd(entityId, actionDecisionResult)) { actionChanged = actionDecisionResult.ActionType != actionDecisionResults[entityId].ActionType; if (actionChanged) actionDecisionResults[entityId] = actionDecisionResult.GetSnapshot(); else actionDecisionResults[entityId]?.RestoreSnapshot(actionDecisionResult); } if (!battleActionDatas.TryAdd(entityId, battleActionData)) { if (actionChanged) battleActionDatas[entityId] = battleActionData.GetSnapshot(); else battleActionDatas[entityId]?.RestoreSnapshot(battleActionData); } entity.RestoreSnapshot(entitySnapshots[entityId]); } } } }