diff --git a/src/App.tsx b/src/App.tsx index 6668be8..02a8f01 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,6 +7,7 @@ import Play from './Pages/Play/Play'; import PlayRecorded from './Pages/Play/PlayRecorded'; import Record from './Pages/Record/Record'; import RebuildInfo from './Pages/RebuildInfo/RebuildInfo'; +import PlayLive from './Pages/PlayLive/PlayLive'; import {Routes as Switch, Route} from 'react-router-dom'; import './App.css'; @@ -22,6 +23,7 @@ function App() { } /> } /> } /> + } /> } /> diff --git a/src/Components/Header/Header.tsx b/src/Components/Header/Header.tsx index 4ba1962..7590c58 100644 --- a/src/Components/Header/Header.tsx +++ b/src/Components/Header/Header.tsx @@ -22,6 +22,7 @@ export default function Header() {
HOME RECORD + {/* LIVE PLAY */} DOCS SUPPORT
diff --git a/src/Components/NewOptions/NewOptions.styles.scss b/src/Components/NewOptions/NewOptions.styles.scss index 8e8af90..d242a3c 100644 --- a/src/Components/NewOptions/NewOptions.styles.scss +++ b/src/Components/NewOptions/NewOptions.styles.scss @@ -144,6 +144,13 @@ bottom: 60px; } +.disable_transitions{ + transition: none !important; + .Options_Data{ + transition: none !important; + } +} + @keyframes Enter{ 0%{ margin-Top: -50%; diff --git a/src/Components/NewOptions/Options.tsx b/src/Components/NewOptions/Options.tsx index e9cdfc9..ca2b651 100644 --- a/src/Components/NewOptions/Options.tsx +++ b/src/Components/NewOptions/Options.tsx @@ -1,9 +1,10 @@ -import React, { ReactElement,useState } from 'react' +import React, { ReactElement,useState, useEffect } from 'react' import './NewOptions.styles.scss'; import ChooseButton from './ChooseButtons/ChooseButton'; import ImageButton from './ImageButton/ImageButton'; import OptionsDescription from './OptionsDescription/OptionsDescription'; +import Preview from '../Preview/Preview'; import { Options as OptionsType } from '../../Utils/TypesForOptions'; @@ -14,8 +15,6 @@ import { Options_Presets as OptionsPresets} from './OptionsType/OptionsType'; import save_img from "../../Assets/save.png" -import Preview from '../Preview/Preview'; - interface OptionsProps{ isOpened:boolean, onGoBack:Function, @@ -27,14 +26,28 @@ interface OptionsProps{ export default function Options({isOpened,onGoBack,options,handleOptionsChange,reloadOptions}:OptionsProps):ReactElement { const [table,setTable] = useState<'blocks' | 'effects' | 'other' | 'presets'>('blocks'); + const [resizeDisable, setResizeDisable] = useState(''); const change_table = (name:'blocks' | 'effects' | 'other' | 'presets'):void =>{ setTable(name); } + useEffect(()=>{ + const resize_listener = () =>{ + setResizeDisable("disable_transitions"); + setTimeout(()=>{ + setResizeDisable(""); + },100) + } + + window.addEventListener('resize', resize_listener); + + return () => {window.removeEventListener('resize',resize_listener)} + }, []) + return ( -
+
diff --git a/src/Components/Preview/Preview.tsx b/src/Components/Preview/Preview.tsx index aea7f32..aad3d2c 100644 --- a/src/Components/Preview/Preview.tsx +++ b/src/Components/Preview/Preview.tsx @@ -92,14 +92,14 @@ export default function Preview({active}:PrevProps):React.ReactElement { width: props.width, height: props.height }) - setReady(false); - if(timeout_ref.current !== 0){ - clearTimeout(timeout_ref.current); - } - timeout_ref.current = setTimeout(()=>{ - setReady(true); - addKey(curr => curr + 1); - },500) + // setReady(false); + // if(timeout_ref.current !== 0){ + // clearTimeout(timeout_ref.current); + // } + // timeout_ref.current = setTimeout(()=>{ + // setReady(true); + // addKey(curr => curr + 1); + // },500) },[width_ref.current]) diff --git a/src/Components/Tracks/updatedTracks.tsx b/src/Components/Tracks/updatedTracks.tsx index 4a3a4f1..6b84fdd 100644 --- a/src/Components/Tracks/updatedTracks.tsx +++ b/src/Components/Tracks/updatedTracks.tsx @@ -64,6 +64,14 @@ const UpdatedTracks = ({width,height,Player,events,options,sound,number_of_white } },[events]) + useEffect(()=>{ + if(blocks){ + blocks.handle_resize(width,height,width/number_of_white_keys); + console.log('resize') + } + + },[width,height]); + useEffect(()=>{ if(blocks === undefined && pianoWhite.current && mainCtx.current && pianoBlack.current && gradCtx.current && EffectCtx.current){ const context = mainCtx.current.getContext('2d') diff --git a/src/Helpers/Blocks/pianoInteraction.ts b/src/Helpers/Blocks/pianoInteraction.ts index c56b38c..f44c0f9 100644 --- a/src/Helpers/Blocks/pianoInteraction.ts +++ b/src/Helpers/Blocks/pianoInteraction.ts @@ -25,6 +25,13 @@ export default class pianoInteraction{ }) } + public handle_resize(width:number, height:number):void { + this.black_key_height = (height-this.cnavas_offSet) / 1.5 + 5; + this.white_key_height = (height-this.cnavas_offSet) + 2; + this.width = width; + this.height = height; + } + public render():void { this.white_ctx.clearRect(0,0,this.width,this.height); this.black_ctx.clearRect(0,0,this.width,this.height); diff --git a/src/Helpers/Blocks/updatedBlocks.ts b/src/Helpers/Blocks/updatedBlocks.ts index 8ac56a9..38e5c7f 100644 --- a/src/Helpers/Blocks/updatedBlocks.ts +++ b/src/Helpers/Blocks/updatedBlocks.ts @@ -47,6 +47,15 @@ class Block{ this.pauseTime += time } + /** + * Put the block in different x_position + * @param pos_x: new x position of the block + */ + public block_alter_x_pos(pos_x: number){ + //I think the Y does not need to change, only the x position + this.pos_x = pos_x; + } + /** * Static method to calculate y position of a block if it existed, returns number * @param speed_y @@ -122,7 +131,7 @@ class Blocks{ private effect_manager: EffectsManager private sound_manager:soundManager | undefined - constructor(canvases: blocks_canvases, private options:OptionsType, private height:number, private width:number, nr_of_keys:number, key_width:number){ + constructor(canvases: blocks_canvases, private options:OptionsType, private height:number, private width:number, private nr_of_keys:number, private key_width:number){ this.blocks = [] this.notes_to_add = []; this.ctx = canvases.mainCtx; @@ -288,6 +297,26 @@ class Blocks{ this.notes_to_add = []; } + + /** + * Method handles the resize of the canvas, it needs to rerender the blocks + * @param width + * @param height + */ + public handle_resize(width:number,height:number, key_width: number):void { + this.key_width = key_width; + this.width = width; + this.height = height; + this.key_positions_map = this.__create_key_position_map(width, this.nr_of_keys, this.key_width); + this.height = height - (height / 5); + this.key_interactor.handle_resize(width,height / 5); + this.effect_manager.handle_resize(width, height - (height / 5)); + this.positions_to_render_line = this.RenderOctaveLines() + this.blocks.forEach(block =>{ + block.block_alter_x_pos(this.key_positions_map[block.noteNumber].position); + }) + } + /** * Function creates a map of key positions */ diff --git a/src/Helpers/Effects/DesignedEffects/Blank.ts b/src/Helpers/Effects/DesignedEffects/Blank.ts index f5a399e..6aee557 100644 --- a/src/Helpers/Effects/DesignedEffects/Blank.ts +++ b/src/Helpers/Effects/DesignedEffects/Blank.ts @@ -18,4 +18,8 @@ export default class Blank extends _Effect{ public update_effect(): void { } + + public handle_resze(width: number, height: number): void { + + } } \ No newline at end of file diff --git a/src/Helpers/Effects/DesignedEffects/Sparks.ts b/src/Helpers/Effects/DesignedEffects/Sparks.ts index b55a4eb..a4bc5c0 100644 --- a/src/Helpers/Effects/DesignedEffects/Sparks.ts +++ b/src/Helpers/Effects/DesignedEffects/Sparks.ts @@ -57,6 +57,11 @@ class Sparks extends Effect{ this.ctx.closePath() } + public handle_resze(width: number, height: number): void { + this.width = width; + this.height = height; + } + public update_effect(): void { const new_effects:Spark[] = []; this.sparks.forEach(spark =>{ diff --git a/src/Helpers/Effects/DesignedEffects/Squared.ts b/src/Helpers/Effects/DesignedEffects/Squared.ts index 907fb60..179a14d 100644 --- a/src/Helpers/Effects/DesignedEffects/Squared.ts +++ b/src/Helpers/Effects/DesignedEffects/Squared.ts @@ -75,6 +75,11 @@ class Squared extends Effect{ //Render Effects } + public handle_resze(width: number, height: number): void { + this.width = width; + this.height = height; + } + public update_effect(): void { const new_effects:Array = []; this.effects.map(efect =>{ diff --git a/src/Helpers/Effects/EffectsManager.ts b/src/Helpers/Effects/EffectsManager.ts index 20baf77..5bac777 100644 --- a/src/Helpers/Effects/EffectsManager.ts +++ b/src/Helpers/Effects/EffectsManager.ts @@ -11,7 +11,7 @@ import { Options } from '../../Utils/TypesForOptions'; export default class EffectsManager{ private effects:Effect; - constructor(private ctx:CanvasRenderingContext2D, width:number,private height:number, private key_width:number,effect_type:string, options:Options){ + constructor(private ctx:CanvasRenderingContext2D, width:number, private height:number, private key_width:number,private effect_type:string,private options:Options){ switch(effect_type){ case 'Sparks': this.effects = new Sparks(ctx, width, height, 1, 6,); @@ -28,6 +28,10 @@ export default class EffectsManager{ } } + public handle_resize(width:number, height: number){ + this.height = height; + this.effects.handle_resze(width, height); + } public generate_effect(pos_x:number):void{ this.effects.create_effect(pos_x, this.height, this.key_width); diff --git a/src/Helpers/Effects/_Effect.ts b/src/Helpers/Effects/_Effect.ts index 9720170..18ebf20 100644 --- a/src/Helpers/Effects/_Effect.ts +++ b/src/Helpers/Effects/_Effect.ts @@ -24,6 +24,11 @@ export default abstract class Effect{ */ public abstract update_effect():void; + /** + * Method handles the resize of the screen + */ + public abstract handle_resze(width:number, height:number):void; + /** * Method clears the Canvas */ diff --git a/src/Pages/Play/Play.tsx b/src/Pages/Play/Play.tsx index d202131..7f30781 100644 --- a/src/Pages/Play/Play.tsx +++ b/src/Pages/Play/Play.tsx @@ -39,7 +39,10 @@ export default function Play():React.ReactElement{ },[]) const resize_listener = useCallback(()=>{ - window.location.reload() + set_width_height({ + width: window.innerWidth, + height: window.innerHeight + }) },[]); const focus_listener = useCallback(()=>{ diff --git a/src/Pages/PlayLive/PlayLive.scss b/src/Pages/PlayLive/PlayLive.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/Pages/PlayLive/PlayLive.tsx b/src/Pages/PlayLive/PlayLive.tsx new file mode 100644 index 0000000..4a297f2 --- /dev/null +++ b/src/Pages/PlayLive/PlayLive.tsx @@ -0,0 +1,12 @@ +import React from 'react' +import "./PlayLive.scss" + +export default function PlayLive() { + return ( +
+

WORK IN PROGRESS

+

IF YOU SEE THIS, YOU HAVE DOWNLOADED PAGE FROM AVANT BRANCH

+

Then please be patient :)

+
+ ) +} diff --git a/src/Utils/handleOptionsChange.ts b/src/Utils/handleOptionsChange.ts index c4faacc..ebf7334 100644 --- a/src/Utils/handleOptionsChange.ts +++ b/src/Utils/handleOptionsChange.ts @@ -22,9 +22,6 @@ const handleOptionsChange = (event:ChangeEvent | {target:{name case 'Image': currentOptions.backgroundImage = event.target.value break; - case 'speed': - currentOptions.speed = parseInt(event.target.value); - break; case 'playSpeed': currentOptions.playSpeed = parseInt(event.target.value); break;