From c9bfe5d55b85ee27b2b6bab428f52201d5ffb76e Mon Sep 17 00:00:00 2001 From: Lars Kroll Date: Mon, 7 Oct 2019 12:27:03 +0200 Subject: [PATCH] Support for Scribe logging in Compendium --- script/README.md | 6 ++++-- script/epapiscript.sbt | 1 + .../scala/com/lkroll/ep/api/EPScripts.scala | 10 ++++++++-- .../scala/com/lkroll/ep/api/Roll20Logger.scala | 17 +++++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 script/src/main/scala/com/lkroll/ep/api/Roll20Logger.scala diff --git a/script/README.md b/script/README.md index baf5b74..64fbc74 100644 --- a/script/README.md +++ b/script/README.md @@ -75,7 +75,7 @@ Installation ### Installation -- Open the **raw** text of the latest release of the script. At the time of writing that is [v0.9.0](https://github.com/Bathtor/EPSheet/releases/download/script-v0.9.0/ep-script.js). +- Open the **raw** text of the latest release of the script. At the time of writing that is [v1.0.2](https://github.com/Bathtor/EPSheet/releases/download/script-v1.0.2/ep-script.js). - Copy *all* the text -- **Ctrl+A** followed by **Ctrl+C** (**Cmd+A**, **Cmd+C** on a Mac) - Go to the API Script page for your Roll20 campaign - Paste the text into a new script, or override an older version if updating. Don't forget to give it a sensible name, e.g. `epscript.js`! @@ -83,7 +83,9 @@ Installation - Leave the Roll20 API Script page open, and open up your campaign view in a different tab/window. That should cause your sandbox to spin up. If no errors are reported, you should be good to go. #### EPCompendium -If you would like access to the EPCompendium-related features, you must also install the data script for the compendium. Follow the same procedure as above for the latest release of the EPCompendium, [v5.0.0](https://github.com/Bathtor/EPCompendium/releases/tag/v5.0.0) at the time of writing. Each Compendium release also contains a number of macros prepared to use with the script that you can just c&p into your campaign. +If you would like access to the EPCompendium-related features, you must also install the data script for the compendium. Follow the same procedure as above for the latest release of the EPCompendium, [v6.0.0](https://github.com/Bathtor/EPCompendium/releases/tag/v6.0.0) at the time of writing. Each Compendium release also contains a number of macros prepared to use with the script that you can just c&p into your campaign. + +**Note** that there's a load time dependency between the compendium script and the companion script, so make sure that the compendium script's tab is to the right of the companion script's. #### Updating If you need to update one of the script installed above, simply follow the same instructions as for a normal installation. Do make sure, that you always override old script versions, and never have two versions running in parallel! diff --git a/script/epapiscript.sbt b/script/epapiscript.sbt index 4927bcf..76c27c5 100644 --- a/script/epapiscript.sbt +++ b/script/epapiscript.sbt @@ -18,6 +18,7 @@ libraryDependencies += "com.lkroll.ep" %%% "ep-model" % "1.12.3" libraryDependencies += "com.lkroll.common" %%% "common-data-tools" % "1.3.+" libraryDependencies += "com.lihaoyi" %%% "fastparse" % "1.+" libraryDependencies += "org.rogach" %%% "scallop" % "3.3.+" +libraryDependencies += "com.outr" %%% "scribe" % "2.7.3" libraryDependencies += "org.scalactic" %%% "scalactic" % "3.0.8" % "test" libraryDependencies += "org.scalatest" %%% "scalatest" % "3.0.8" % "test" diff --git a/script/src/main/scala/com/lkroll/ep/api/EPScripts.scala b/script/src/main/scala/com/lkroll/ep/api/EPScripts.scala index 0d02dc1..be234c5 100644 --- a/script/src/main/scala/com/lkroll/ep/api/EPScripts.scala +++ b/script/src/main/scala/com/lkroll/ep/api/EPScripts.scala @@ -30,13 +30,19 @@ import com.lkroll.roll20.api.conf._ import com.lkroll.roll20.api.templates._ import com.lkroll.roll20.api.facade.Roll20API import com.lkroll.ep.model.{EPCharModel => epmodel} -import scalajs.js -import scalajs.js.JSON +import scala.scalajs.js +import scala.scalajs.js.JSON +import scala.scalajs.js.annotation._ import fastparse.all._ import util.{Failure, Success, Try} object EPScripts extends APIScriptRoot { + scribe.Logger.root + .clearHandlers() + .withHandler(writer = new Roll20Logger()) + .replace(Some("root")); + override lazy val outputTemplate: Option[TemplateRef] = epmodel.outputTemplate.map(_.ref); override def children: Seq[APIScript] = diff --git a/script/src/main/scala/com/lkroll/ep/api/Roll20Logger.scala b/script/src/main/scala/com/lkroll/ep/api/Roll20Logger.scala new file mode 100644 index 0000000..2f52780 --- /dev/null +++ b/script/src/main/scala/com/lkroll/ep/api/Roll20Logger.scala @@ -0,0 +1,17 @@ +package com.lkroll.ep.api + +import scribe._; +import scribe.writer.Writer; +import scribe.output.LogOutput +import com.lkroll.roll20.api.facade.Roll20API + +class Roll20Logger extends Writer { + override def write[M](record: LogRecord[M], output: LogOutput): Unit = { + val text = output.plainText; + Roll20API.log(text); + } + + override def dispose(): Unit = { + // do nothing + } +}