25 lines
735 B
Scala
25 lines
735 B
Scala
package controllers
|
|
|
|
import javax.inject._
|
|
import play.api.mvc._
|
|
import play.api.libs.json._
|
|
import models.Brick
|
|
|
|
@Singleton
|
|
class GameController @Inject()(val controllerComponents: ControllerComponents) extends BaseController {
|
|
|
|
implicit val brickWrites: Writes[Brick] = Json.writes[Brick]
|
|
implicit val brickReads: Reads[Brick] = Json.reads[Brick]
|
|
|
|
def index(): Action[AnyContent] = Action { implicit request: Request[AnyContent] =>
|
|
Ok(views.html.game())
|
|
}
|
|
|
|
def getBricks: Action[AnyContent] = Action {
|
|
|
|
val source = scala.io.Source.fromFile("conf/bricks.json")
|
|
val jsonString = try source.mkString finally source.close()
|
|
val bricks = Json.parse(jsonString).as[List[Brick]]
|
|
Ok(Json.toJson(bricks))
|
|
}
|
|
}
|