Permalink
Browse files

json says hello

  • Loading branch information...
ilanpillemer committed Jul 30, 2017
1 parent d05520b commit 28102e83400d7f12a2c843bf5d48da7c34d7ab16
Showing with 35 additions and 5 deletions.
  1. +2 −0 README.md
  2. +31 −5 app/controllers/HomeController.scala
  3. +2 −0 build.sbt
View
@@ -0,0 +1,2 @@
[Under Construction](http://textfiles.com/underconstruction/)
@@ -3,6 +3,7 @@ package controllers
import javax.inject._
import play.api._
import play.api.mvc._
import play.api.libs.json._
import play.api.libs.streams.ActorFlow
import akka.stream.Materializer
@@ -26,15 +27,40 @@ class HomeController @Inject()(cc: ControllerComponents)
object RoomActor {
def props(out: ActorRef) = Props(new RoomActor(out))
val sampleRoom : JsValue = Json.obj(
"type" -> "location",
"name" -> "bob",
"fullName" -> "sample scala room",
"description" -> """So.. once there was a sample scala room.
|and this room was well described.
|in detail. So much detail. Bigly.""".stripMargin,
"exits" -> Json.obj(
"N" -> "North",
"S" -> "South",
"W" -> "West",
"E" -> "East"
),
"commands" -> Json.obj(
"/play" -> "play with play"
),
"roomInventory" -> List("yoyo","top")
)
}
class RoomActor(out: ActorRef) extends Actor {
val pattern = """(?s)(\w+),([^,]*),(.*)""".r
def receive = {
case "marco" => out ! ("polo")
case pattern ("roomHello", id, payload) => out ! ("Hi Mediator")
case pattern ("roomGoodbye", id, payload) => out ! ("Bye Mediator")
case _ => out ! ("whatever, I dont care...")
def receive = {
case str : String => str match {
case "marco" => out ! ("polo")
case pattern ("roomHello", id, payload) => out ! ("player," + (Json.parse(payload) \ "userId").as[String] + "," + RoomActor.sampleRoom.toString)
case pattern ("roomJoin", id, payload) => out ! ("player," + (Json.parse(payload) \ "userId").as[String] + "," + RoomActor.sampleRoom.toString)
case pattern ("roomGoodbye", id, payload) => out ! ("Don't slam door on way out, please.")
case pattern ("roomPart", id, payload) => out ! ("Don't slam door on way out, please.")
case pattern ("room", id, payload) => out ! ("Your wish is my command.")
case _ => out ! ("whatever, I dont care...")
}
case _ => out ! ("So long, and thanks for the fish.")
}
override def preStart = out ! ("""ack,{
View
@@ -1,6 +1,8 @@
name := """sample scala room"""
organization := "com.ilanpillemer"
scalacOptions ++= Seq("-deprecation", "-feature")
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)

0 comments on commit 28102e8

Please sign in to comment.