61 lines
2.7 KiB
C#
61 lines
2.7 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;
|
|
|
|
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]);
|
|
}
|
|
}
|
|
}
|
|
} |