import { WWA } from "./wwa_main" ; import { Direction as Dir , Position , speedList , PartsType , Coord , Direction } from "./wwa_data" ; import { Player } from "./wwa_parts_player" ; export class ObjectMovingData { private _currentPos : Position ; public constructor ( private _player , private _objectID , private _srcPos , private _destPos , private _dir ) { this . _currentPos = this . _srcPos . clone ( ) ; } public update ( ) { var speedIndex = this . _player . getSpeedIndex ( ) ; this . _currentPos = this . _currentPos . getNextFramePosition ( this . _dir , speedList [ speedIndex ] , speedList [ speedIndex ] ) ; return this . _currentPos ; } public get isAchievedDestination ( ) : boolean { return this . _currentPos . equals ( this . _destPos ) ; } public get currentPosition ( ) : Position { return this . _currentPos ; } public get beforePosition ( ) : Position { return this . _srcPos ; } public get destination ( ) : Position { return this . _destPos ; } public get objID ( ) : number { return this . _objectID ; } } export class ObjectMovingDataManager { private _queue : ObjectMovingData [ ] ; public constructor ( private _wwa , private _player ) { this . clear ( ) ; } public add ( objectID , srcPos , destPos , dir ) { this . _queue . push ( new ObjectMovingData ( this . _player , objectID , srcPos , destPos , dir ) ) ; } public update ( ) { var endObjects = [ ] ; var continueObjects = [ ] ; for ( var i = 0 ; i < this . _queue . length ; i ++ ) { this . _queue [ i ] . update ( ) ; if ( this . _queue [ i ] . isAchievedDestination ) { endObjects . push ( this . _queue [ i ] ) ; this . _wwa . setPartsOnPosition ( PartsType . OBJECT , 0 , this . _queue [ i ] . beforePosition . getPartsCoord ( ) ) ; this . _wwa . setPartsOnPosition ( PartsType . OBJECT , this . _queue [ i ] . objID , this . _queue [ i ] . destination . getPartsCoord ( ) ) ; } else { continueObjects . push ( this . _queue [ i ] ) ; } } this . _queue = continueObjects ; return endObjects ; } public clear ( ) { this . _queue = [ ] ; } public get objectMovingData ( ) : ObjectMovingData [ ] { return this . objectMovingData ; } public getOffsetByBeforePartsCoord ( coord ) { var result = this . _queue . filter ( ( x ) => { return x . beforePosition . getPartsCoord ( ) . equals ( coord ) ; } ) ; if ( result . length === 0 ) { return null ; } return result [ 0 ] . currentPosition . getOffsetCoord ( ) ; } }