import * as Bacon from 'baconjs' ; import Point from 'slime-finder/point' ; import Chunk from 'slime-finder/chunk' ; import CoordsModel from '../model/coords' ; declare var $ ; Bacon . $ . init ( $ ) ; export default class CoordsView { protected readonly changes : Bacon . EventStream < ( p : Point ) => Point > ; protected readonly chunk : Bacon . Observable < Chunk > ; constructor ( coords ) { this . changes = $ ( '#position-x, #position-z' ) . asEventStream ( 'input' ) . map ( ( ) => { return ( ) => new Point ( Number ( $ ( '#position-x' ) . val ( ) ) , Number ( $ ( '#position-z' ) . val ( ) ) ) ; } ) ; coords . changes . plug ( this . changes ) ; coords . prop . onValue ( ( p ) => { $ ( '#position-x' ) . val ( p . x ) ; $ ( '#position-z' ) . val ( p . z ) ; } ) ; this . chunk = coords . prop . map ( ( p ) => { return new Chunk ( p ) ; } ) ; this . chunk . onValue ( ( c ) => { $ ( '#chunk-from-x' ) . text ( c . origin . x ) ; $ ( '#chunk-from-z' ) . text ( c . origin . z ) ; $ ( '#chunk-to-x' ) . text ( c . origin . x + 15 ) ; $ ( '#chunk-to-z' ) . text ( c . origin . z + 15 ) ; if ( c . isSlimy ) { $ ( '#chunk-is-slimy' ) . fadeIn ( 50 ) ; } else { $ ( '#chunk-is-slimy' ) . fadeOut ( 50 ) ; } } ) ; } }