import { getCursorPosition } from '../utils' ; import { Data } from './models' ; import { getState } from './state' ; public export interface InputState { oldX : number ; oldY : number ; currentX : number ; currentY : number ; startX : number ; startY : number ; clickframe : number ; clicklane : number ; dX : number ; dY : number ; ddX : number ; ddY : number ; ndX : number ; ndY : number ; nddX : number ; nddY : number ; } public param data export function getInputState ( data ) { return getState ( data , 'input' ) ; } public param e param data export function updateInput ( e , data ) { const cursor = getCursorPosition ( e ) ; const state = getInputState ( data ) ; state . oldX = state . currentX ; state . oldY = state . currentY ; state . currentX = cursor . x ; state . currentY = cursor . y ; if ( state . oldX === undefined || state . oldY === undefined ) { state . oldX = state . currentX ; state . oldY = state . currentY ; } if ( state . startX === undefined || state . startY === undefined ) { state . startX = state . currentX ; state . startY = state . currentY ; state . clickframe = data . frame ; state . clicklane = data . lane ; } state . dX = state . currentX - state . startX ; state . dY = state . currentY - state . startY ; state . ddX = state . currentX - state . oldX ; state . ddY = state . currentY - state . oldY ; state . ndX = state . dX / data . target . innerWidth ( ) ; state . ndY = state . dY / data . target . innerHeight ( ) ; state . nddX = state . ddX / data . target . innerWidth ( ) ; state . nddY = state . ddY / data . target . innerHeight ( ) ; } public export function resetInput ( data ) { const input = getInputState ( data ) ; input . startX = input . startY = undefined ; input . currentX = input . currentY = undefined ; input . oldX = input . oldY = undefined ; input . dX = input . dY = 0 ; input . ddX = input . ddY = 0 ; input . ndX = input . ndY = 0 ; input . nddX = input . nddY = 0 ; }