Skip to content

Commit

Permalink
Move handler 1st test release
Browse files Browse the repository at this point in the history
  • Loading branch information
adityaganesh2k committed Mar 5, 2022
1 parent 6744b69 commit e615308
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 42 deletions.
63 changes: 29 additions & 34 deletions src/components/CubeD/CubeThree/CUBE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class CUBE {
// @ts-ignore
#mesh = []; // just add "default"
// @ts-ignore
#current_state:string[] = [] ;
current_state:string[] = [] ;
// @ts-ignore
#core = [];
scene: THREE.Scene;
Expand Down Expand Up @@ -178,74 +178,68 @@ export default class CUBE {
if( slider_mot == 0 )
{
//FIRST MOVE ENTERED BY USER
if( typeof this.#current_state === "undefined" )
if( typeof this.current_state === "undefined" )
{
console.log( moves );
var moves1 = scramble_read( moves, 0 );
fast_execute(this.scene, this.#mesh, 5, moves1);
this.#current_state = moves.slice();//storing the moves done on the cube
this.current_state = moves.slice();//storing the moves done on the cube
}
else
{
//USER APPENDED MOVES
if ( moves.length > this.#current_state.length )
if ( moves.length > this.current_state.length )
{
console.log( this.#current_state );
if( this.#current_state.length == 0 )

if( this.current_state.length == 0 )
{

var moves1 = scramble_read( moves, 0 );
console.log( moves1 );
fast_execute(this.scene, this.#mesh, 5, moves1);
this.#current_state = moves.slice();//storing the moves done on the cube
this.current_state = moves.slice();//storing the moves done on the cube
}
else if ( this.#current_state.length > 0 )
else if ( this.current_state.length > 0 )
{
var moves_check = moves.slice( 0, this.#current_state.length );
var moves_check = moves.slice( 0, this.current_state.length );
//previously done moves are same on the cube
if( JSON.stringify(moves_check) === JSON.stringify(this.#current_state) )
if( JSON.stringify(moves_check) === JSON.stringify(this.current_state) )
{
console.log( "**!!", typeof this.#mesh, this.#mesh );
var current_moves = moves.slice( this.#current_state.length );
var current_moves = moves.slice( this.current_state.length );
this.liveMove(current_moves, 0);//do the current moves
}
else
{
console.log( "****" );
console.log( moves );
this.fastMove(this.#current_state, 1);//inverse the previously done moves

this.fastMove(this.current_state, 1);//inverse the previously done moves
this.fastMove(moves, 0);//do the current moves
}
this.#current_state = moves.slice();//store the moves done on the cube
this.current_state = moves.slice();//store the moves done on the cube
}
}
//USER DELETED MOVES
else if ( moves.length < this.#current_state.length )
else if ( moves.length < this.current_state.length )
{
if( moves.length != 0 )
{
this.fastMove(this.#current_state, 1);//inverse the previously done moves
this.fastMove(this.current_state, 1);//inverse the previously done moves
this.fastMove(moves, 0);//do the current moves
this.#current_state = moves.slice();//store the moves done on the cube
this.current_state = moves.slice();//store the moves done on the cube
}
else
{
this.fastMove(this.#current_state, 1);//inverse the previously done move
this.#current_state = moves.slice();//store the moves done on the cube
this.fastMove(this.current_state, 1);//inverse the previously done move
this.current_state = moves.slice();//store the moves done on the cube
}


}
//USER MIGHT HAVE EDITED MOVES
else if ( moves.length == this.#current_state.length )
else if ( moves.length == this.current_state.length )
{
if(JSON.stringify(moves) !== JSON.stringify(this.#current_state))
if(JSON.stringify(moves) !== JSON.stringify(this.current_state))
{
console.log( JSON.stringify(moves) );

this.fastMove(this.#current_state, 1);//inverse the previously done moves
this.fastMove(this.current_state, 1);//inverse the previously done moves
this.fastMove(moves, 0);//do the current moves
this.#current_state = moves.slice();//store the moves done on the cube
this.current_state = moves.slice();//store the moves done on the cube

}

Expand All @@ -255,9 +249,9 @@ export default class CUBE {
// if(JSON.stringify(compare) !== )
// {
// console.log( "!===" );
// // console.log( this.#current_state );
// // console.log( this.current_state );
// // console.log( moves );
// this.fastMove(this.#current_state, 1);//inverse the previously done moves
// this.fastMove(this.current_state, 1);//inverse the previously done moves
// this.fastMove(moves, 0);//do the current moves


Expand All @@ -270,11 +264,12 @@ export default class CUBE {
else if ( slider_mot == 1 )
{
var slider_moves = moves.slice( 0 , scramble_length + slider_number + 1 );//moves till slider position
console.log( this.current_state );
console.log( slider_moves );
console.log(this.#current_state);
this.fastMove(this.#current_state, 1);//inverse the previously done moves
this.fastMove(this.current_state, 1);//inverse the previously done moves
this.fastMove( slider_moves , 0 );//do the current moves
this.#current_state = slider_moves;//store the moves in current state
this.current_state = slider_moves;//store the moves in current state

}


Expand Down
30 changes: 22 additions & 8 deletions src/components/CubeD/VirtualRubiks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import { animate_read } from './CubeThree/cube_animate_read_3';
import CUBE from './CubeThree/CUBE';
import getAlgs_URL from './Parser/getAlgs_URL';
import { useMoveNum, useSetMoveNum, usePlay } from './AlgProvider';
import { scramble_read } from './CubeThree/cube_scramble_read';
// import useSol from './AlgProvider';
// import useScra from './AlgProvider';
import validateAlgs from './Parser/validateAlg';
// import { face_plane_make } from "./CubeThree/cube_face_plane";

import { useAppSelector, useAppDispatch } from '../ReduxStore/hooks';
import { toggleplay } from '../ReduxStore/playSlice';
//let dispatch = useAppDispatch();
interface TProps {
widthp: number;
heightp: number;
Expand All @@ -21,7 +24,7 @@ interface TProps {
export const VirtualRubiksC = (props: TProps) => {
const mount = useRef(null);
let playBtn = useRef(false);
playBtn.current = usePlay();
playBtn.current = useAppSelector((state) => state.playBtn.value);
let MoveNum = useRef(0);
MoveNum.current = useMoveNum();
let MoveSet = useRef((_arg0: number): void => {});
Expand Down Expand Up @@ -114,9 +117,10 @@ export const VirtualRubiksC = (props: TProps) => {
};
/* CUBE ANIMATION HANDLER */
function cube_play() {
var cube_soln_animate = animate_read(soln, soln, [], 0);
var cube_soln_animate = scramble_read( val_soln ,0);

if (tick < cube_soln_animate.length) {
cube1.current_state = val_scra.concat( val_soln.slice( 0 , tick + 1 ) );
cube1.animateMove(cube_soln_animate[tick], 400);

tick = tick + 1;
Expand Down Expand Up @@ -210,16 +214,17 @@ export const VirtualRubiksC = (props: TProps) => {
MoveNum.current,
);
}

//console.log( play_flag);
if (playBtn.current && (play_flag == 0 || play_flag == 2)) {
// this is when the user initially presses the play button so that solution moves gets inversed
if (play_flag == 0) {
//INVERSE THE SOLUTION ONLY IF THE SLIDER WAS AT LAST MOVES
if (MoveNum.current == validateAlgs(val_soln.toString()).movesNum) {
cube1.fastMove(soln, 1);
cube1.fastMove(val_soln, 1);
}
//IF SLIDER NOT AT LAST MOVES START PLAYING ANIMATION FROM THE SLIDER MOVE
else {
else
{
tick = slider_no;
}

Expand All @@ -229,10 +234,19 @@ export const VirtualRubiksC = (props: TProps) => {
// this is done to see if pause was pressed in between
else if (play_flag == 2) {
//if slider is not where it was previously paused then move the tick value to current slider position
if (tick != slider_no) {
if (tick != slider_no)
{
if (MoveNum.current == validateAlgs(val_soln.toString()).movesNum) {
cube1.fastMove(val_soln, 1);
}
tick = slider_no;
mycube = setInterval(cube_play, 600);
} else {
}
else
{
if (MoveNum.current == validateAlgs(val_soln.toString()).movesNum) {
cube1.fastMove(val_soln, 1);
}
mycube = setInterval(cube_play, 600);
}

Expand Down

0 comments on commit e615308

Please sign in to comment.