class_docstr: A trajectory recording wrapper. Supports both standard gym envs and BaseEnvs, as well as environments
  that provide more access -- SerializableEnvMixin for access to environment components
  and RecordableEnvMixin for access to MazeState and MazeExecution objects.
  
  :param env: the environment to wrap.
class_docstr_tok: ["A","trajectory","recording","wrapper",".","Supports","both","standard","gym","envs","and","BaseEnvs",",","as","well","as","environments","that","provide","more","access","--","SerializableEnvMixin","for","access","to","environment","components","and","RecordableEnvMixin","for","access","to","MazeState","and","MazeExecution","objects",".",":","param","env",":","the","environment","to","wrap","."]
docstr: Records final state of the episode and dispatches the record to trajectory data writers.
docstr_tok: ["Records","final","state","of","the","episode","and","dispatches","the","record","to","trajectory","data","writers","."]
code: def _write_episode_record(self):
      """Records final state of the episode and dispatches the record to trajectory data writers."""
      # Do not record empty episodes
      if (
          not self.episode_record
          or len(self.episode_record.step_records) == 0
      ):
          return
  
      # Record the final state
      env_time = (
          self.env.get_env_time()
          if isinstance(self.env, TimeEnvMixin)
          else None
      )
      event_collection = EventCollection(
          self.env.get_step_events()
          if isinstance(self.env, EventEnvMixin)
          else []
      )
      step_event_log = StepEventLog(env_time, events=event_collection)
      final_step_record = StateRecord(
          env_time=env_time,
          maze_state=self.last_maze_state,
          maze_action=None,
          step_event_log=step_event_log,
          reward=None,
          done=None,
          info=None,
          serializable_components=self.last_serializable_components,
      )
      self.episode_record.step_records.append(final_step_record)
  
      # Write out the current episode
      TrajectoryWriterRegistry.record_trajectory_data(
          self.episode_record
      )
  
imports: import uuid
  from copy import deepcopy
  from typing import Union, Any, Tuple, Dict, Optional
  from maze.core.annotations import override
  from maze.core.env.base_env import BaseEnv
  from maze.core.env.event_env_mixin import EventEnvMixin
  from maze.core.env.maze_action import MazeActionType
  from maze.core.env.maze_env import MazeEnv
  from maze.core.env.maze_state import MazeStateType
  from maze.core.env.recordable_env_mixin import RecordableEnvMixin
  from maze.core.env.serializable_env_mixin import SerializableEnvMixin
  from maze.core.env.simulated_env_mixin import SimulatedEnvMixin
  from maze.core.env.time_env_mixin import TimeEnvMixin
  from maze.core.events.event_collection import EventCollection
  from maze.core.log_events.step_event_log import StepEventLog
  from maze.core.rendering.keyboard_controlled_trajectory_viewer import KeyboardControlledTrajectoryViewer
  from maze.core.trajectory_recording.records.raw_maze_state import RawState, RawMazeAction
  from maze.core.trajectory_recording.records.state_record import StateRecord
  from maze.core.trajectory_recording.records.trajectory_record import StateTrajectoryRecord
  from maze.core.trajectory_recording.writers.trajectory_writer_registry import TrajectoryWriterRegistry
  from maze.core.wrappers.wrapper import Wrapper
label_desc: Use image node_id 7 for calling the TrajectoryRecordingWrapper obj's underlying member method code with example usage: obj._write_episode_record() without return types