2013-07-21 06:27:47 -06:00
|
|
|
package controllers
|
|
|
|
|
2013-10-17 11:53:04 -06:00
|
|
|
import chess.format.Forsyth
|
|
|
|
import chess.{ Situation, Variant }
|
|
|
|
|
2013-07-21 06:27:47 -06:00
|
|
|
import lila.app._
|
2013-07-21 09:29:35 -06:00
|
|
|
import lila.game.GameRepo
|
2013-07-21 06:27:47 -06:00
|
|
|
import views._
|
|
|
|
|
|
|
|
object Editor extends LilaController with BaseGame {
|
|
|
|
|
2014-06-28 05:10:44 -06:00
|
|
|
def index = load("")
|
|
|
|
|
|
|
|
def load(urlFen: String) = Open { implicit ctx =>
|
|
|
|
val fenStr = Some(urlFen.trim.replace("_", " ")).filter(_.nonEmpty) orElse get("fen")
|
2014-02-17 02:12:19 -07:00
|
|
|
makeListMenu map { listMenu =>
|
2014-02-25 12:59:48 -07:00
|
|
|
val decodedFen = fenStr.map { java.net.URLDecoder.decode(_, "UTF-8").trim }.filter(_.nonEmpty)
|
2013-10-17 11:53:04 -06:00
|
|
|
val situation = (decodedFen flatMap Forsyth.<<< map (_.situation)) | Situation(Variant.Standard)
|
2014-02-25 12:59:48 -07:00
|
|
|
val fen = Forsyth >> situation
|
2014-09-28 08:17:07 -06:00
|
|
|
Ok(html.board.editor(listMenu, situation, fen, animationDuration = Env.api.EditorAnimationDuration))
|
2013-07-21 09:29:35 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-17 02:12:19 -07:00
|
|
|
def game(id: String) = Open { implicit ctx =>
|
|
|
|
OptionResult(GameRepo game id) { game =>
|
2014-06-28 05:10:44 -06:00
|
|
|
Redirect(routes.Editor.load(
|
2013-07-21 09:29:35 -06:00
|
|
|
get("fen") | (chess.format.Forsyth >> game.toChess)
|
|
|
|
))
|
2013-07-21 06:27:47 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|