71 lines
3.0 KiB
C#
71 lines
3.0 KiB
C#
using System.Collections.Generic;
|
|
using Code.Game.Entities;
|
|
using Code.OfficeGame.BattleMode.Actions;
|
|
using UnityEngine;
|
|
|
|
namespace Code.OfficeGame.BattleMode.Snapshots
|
|
{
|
|
public class SnapshotUtilityNonStatic
|
|
{
|
|
Dictionary<EntityId, BattleActionData> actionDataSnapshots = new();
|
|
Dictionary<EntityId, BattleActionDecisionResult> resultsSnapshots = new();
|
|
Dictionary<EntityId, EntitySnapshot> entitySnapshots = new();
|
|
|
|
public void GetSnapshots(
|
|
Dictionary<EntityId, EntityProperties> entities,
|
|
Dictionary<EntityId, BattleActionDecisionResult> actionDecisionResults,
|
|
Dictionary<EntityId, BattleActionData> 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<EntityId, EntityProperties> entities,
|
|
Dictionary<EntityId, BattleActionDecisionResult> actionDecisionResults,
|
|
Dictionary<EntityId, BattleActionData> 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]);
|
|
}
|
|
}
|
|
}
|
|
} |