package scotlandyard.servlets.maps;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import scotlandyard.engine.impl.Engine;
import scotlandyard.engine.spec.IGame;
import scotlandyard.servlets.HttpServletEx;
/**
* map container
*/
public class map_container extends HttpServletEx {
private static final long serialVersionUID = 1876218763812L;
private String selected_game;
public map_container() {super();}
public map_container(String selected_game){
super();
this.selected_game=selected_game;
}
@Override
public void setHeader(HttpServletResponse response) {
response.setHeader("Content-Type", "text/html");
}
@Override
public String processRequest(Map<String, String> parameters, String sid) throws ServletException {
final StringBuffer sb = new StringBuffer();
if(parameters.get("selected_game")!=null){
this.selected_game=parameters.get("selected_game");
}
try{
final IGame game = Engine.instance().games.get(this.selected_game);
if(game==null){
throw new Exception("Game is not known");
}
sb.append("<div><div id='map_canvas' style='width: 100%; height: 850px'></div>");
sb.append("<div id='turn' style='position: absolute' class='ui-widget-content'></div>");
sb.append("<script>");
sb.append(" $(document).ready(function(){");
sb.append(" set_current_map('" + this.getServerBaseUrl()+game.getMapPath() +"');");
sb.append(" });");
sb.append("</script></div>");
}catch(Exception e){
sb.setLength(0);
//sb.append("{\"msg\" : \"EXCEPTION : "+(e.getMessage()+"").replace("\"", "'")+"\", \"className\" : \""+getClass().getName()+"\"}");
sb.append("<script>");
sb.append(" $(document).ready(function(){");
sb.append(" $('#content_page').val('introduction.html');");
sb.append(" $('#selected_game').val('');");
sb.append(" $('#fMain').submit();");
sb.append(" });");
sb.append("</script>");
}
return sb.toString();
}
}