package com.editev.chess.printer; import com.editev.chess.GameHTML; /** Prints any Javascript definitions needed for the chess board. * * @see See the source here. */ public class JavascriptPrinter extends Printer { /** Start of the Javascript headers. */ private static final String HEADER_START = "\n" ; /** Prints any Javascript definitions needed for the chess board. * @param game the GameHTML with the board status and PrintStream for this board. */ public void print( GameHTML game ) { if (!game.hasJavascript) return; game.out.print( HEADER_START ); game.out.print( " base = '"+ game.baseURL +"?moves=';\n" ); game.out.print( " moves = '"+ game.moves +"';\n" ); if (game.moves.length() == 0) { game.out.print( " move = base + moves ;\n" ); } else { game.out.print( " move = base + moves +'/';\n" ); } game.out.print( " target = base + moves + '&target=';\n\n" ); game.out.print( HEADER_FUNCTIONS ); game.out.print( HEADER_END ); } }