<commit_before>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ActionRecorder : MonoBehaviour
{

    bool pressed = false;

    public enum RecordingState
    {
        RECORDING,
        NOT_RECORDING,
        PLAYBACK
    }

    public KeyCode playKey;
    public KeyCode recordKey;

    public RecordingState recordingState;

    public List<Vector3> positions = new List<Vector3>();
    // Use this for initialization

    float t = 1f;

    void Start()
    {
        recordingState = RecordingState.NOT_RECORDING;

    }

    // Update is called once per frame
    void Update()
    {
        Debug.Log("Positions: " + positions.Count);

        ToggleRecord(recordKey);

        //      if (recordingState != RecordingState.RECORDING) { 
        //          PlayRecording(playKey);
        //      }

        //if (recordingState == RecordingState.RECORDING) {
        //	RecordMovement (transform.position);
        //} 

        //if (recordingState == RecordingState.NOT_RECORDING) {
        //	return;
        //	}

        //if (recordingState == RecordingState.PLAYBACK) {
        //	MoveBasedOnRecording ();
        //}
    }

    private void FixedUpdate()
    {
 
        if (recordingState != RecordingState.RECORDING)
        {
            PlayRecording(playKey);
        }

        if (recordingState == RecordingState.RECORDING)
        {
            RecordMovement(transform.position);
        }


        if (recordingState == RecordingState.PLAYBACK)
        {
            MoveBasedOnRecording();
        }

    }

    private Vector3 posAtRecordStart;
    private int lastRecIndex;

    void ToggleRecord(KeyCode key)
    {
        if (Input.GetKeyDown(key))
        {
            posAtRecordStart = transform.position;

            if (recordingState == RecordingState.NOT_RECORDING || recordingState == RecordingState.PLAYBACK)
            {
                recordingState = RecordingState.RECORDING;
                return;
            }
            if (recordingState == RecordingState.RECORDING || recordingState == RecordingState.PLAYBACK)
            {
                recordingState = RecordingState.NOT_RECORDING;
                lastRecIndex = positions.Count - 1;
                return;
            }
        }
    }


    void RecordMovement(Vector3 playerPos)
    {
        positions.Add(playerPos);
    }

    float w = 0.1f;

    private int playbackIndex = 0;

    void MoveBasedOnRecording()
    {
        playbackIndex++;
        Debug.Log(playbackIndex);
        transform.position = positions[playbackIndex];
        if (transform.position == positions[positions.Count-1]) {
            playbackIndex = 0;
            transform.position = positions[0];   
        }
     }

    void PlayRecording(KeyCode key)
    {
        if (Input.GetKeyDown(key))
        {
            recordingState = RecordingState.PLAYBACK;
        }
    }


}<commit_msg>Rotation recording works but is buggy<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ActionRecorder : MonoBehaviour
{
    public enum RecordingState
    {
        RECORDING,
        NOT_RECORDING,
        PLAYBACK
    }

    public KeyCode playKey;
    public KeyCode recordKey;

    public RecordingState recordingState;

    List<Vector3> positions = new List<Vector3>();
    //List<Vector3> rotations = new List<Vector3>();
    List<Quaternion> rotations = new List<Quaternion>();

    float t = 1f;

    void Start()
    {
        recordingState = RecordingState.NOT_RECORDING;

    }
    // Update is called once per frame
    void Update()
    {
        ToggleRecord(recordKey);

        if (recordingState != RecordingState.RECORDING)
        {
            PlayRecording(playKey);
        }
    }

    private void FixedUpdate()
    {
 
        if (recordingState == RecordingState.RECORDING)
        {
            RecordMovement(transform.position);
             RecordRotation(transform.rotation);
        }


        if (recordingState == RecordingState.PLAYBACK)
        {
            MoveBasedOnRecording();
            RotateBasedOnRecording();
        }

    }

    private Vector3 posAtRecordStart;
    private int lastRecIndex;

    void ToggleRecord(KeyCode key)
    {
        if (Input.GetKeyDown(key))
        {
            if (recordingState == RecordingState.NOT_RECORDING || recordingState == RecordingState.PLAYBACK)
            {
                recordingState = RecordingState.RECORDING;
                return;
            }
            if (recordingState == RecordingState.RECORDING || recordingState == RecordingState.PLAYBACK)
            {
                recordingState = RecordingState.NOT_RECORDING;
                return;
            }
        }
    }


    void RecordMovement(Vector3 playerPos)
    {
        positions.Add(playerPos);
    }

    private int playbackIndex = 0;

    void MoveBasedOnRecording()
    {
        playbackIndex++;
        Debug.Log(playbackIndex);
        transform.position = positions[playbackIndex];
        if (transform.position == positions[positions.Count-1]) {
            playbackIndex = 0;
            transform.position = positions[0];   
        }
     }

    void PlayRecording(KeyCode key)
    {
        if (Input.GetKeyDown(key))
        {
            recordingState = RecordingState.PLAYBACK;
        }
    }

    //void RecordRotation(Vector3 playerRot) {
    //    rotations.Add(playerRot);
    //}

    void RecordRotation(Quaternion playerRot)
    {
        rotations.Add(playerRot);
    }

    private int rotPlaybackIndex = 0;

    //void RotateBasedOnRecording() {

    //    rotPlaybackIndex++;
    //    transform.rotation = Quaternion.Euler(rotations[rotPlaybackIndex]);
    //    //rotPlaybackIndex++;
    //    //transform.rotation = rotations[rotPlaybackIndex];
    //    if (transform.rotation.eulerAngles == rotations[rotations.Count - 1])
    //    {
    //        rotPlaybackIndex = 0;
    //        transform.rotation = Quaternion.Euler(rotations[0]);
    //    }
    //}

    void RotateBasedOnRecording()
    {
        Debug.Log("this is the quaternion version");
        rotPlaybackIndex++;
        transform.rotation = rotations[rotPlaybackIndex];
         if (transform.rotation == rotations[rotations.Count - 1])
        {
            rotPlaybackIndex = 0;
            transform.rotation = rotations[0];
        }
    }


}
{'fraction_non_alphanumeric': 0.09495641344956414, 'fraction_numerical': 0.004825653798256538, 'mean_word_length': 1.9085559076505205, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5565371', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1758, 'n_words': 326}