Skip to content

Commit

Permalink
Support for Scribe logging in Compendium
Browse files Browse the repository at this point in the history
  • Loading branch information
Bathtor committed Oct 7, 2019
1 parent 7749116 commit c9bfe5d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
6 changes: 4 additions & 2 deletions script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,17 @@ 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`!
- Save the script
- 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!
Expand Down
1 change: 1 addition & 0 deletions script/epapiscript.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
10 changes: 8 additions & 2 deletions script/src/main/scala/com/lkroll/ep/api/EPScripts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
17 changes: 17 additions & 0 deletions script/src/main/scala/com/lkroll/ep/api/Roll20Logger.scala
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit c9bfe5d

Please sign in to comment.