Skip to content

Commit

Permalink
Fixed another issue with updating Fray/2
Browse files Browse the repository at this point in the history
  • Loading branch information
Bathtor committed Apr 14, 2019
1 parent c8814d6 commit c33c6dc
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 17 deletions.
2 changes: 1 addition & 1 deletion model/epmodel.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name := "EP Model Root"

organization in ThisBuild := "com.lkroll.ep"

version in ThisBuild := "1.12.1"
version in ThisBuild := "1.12.2"

scalaVersion in ThisBuild := "2.12.8"

Expand Down
4 changes: 2 additions & 2 deletions script/epapiscript.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ name := "EP API Script"

organization := "com.lkroll.ep"

version := "1.0.0"
version := "1.0.1"

scalaVersion := "2.12.8"

resolvers += Resolver.bintrayRepo("lkrollcom", "maven")

libraryDependencies += "com.lkroll.roll20" %%% "roll20-api-framework" % "0.10.0"
libraryDependencies += "com.lkroll.ep" %%% "epcompendium-core" % "5.0.0"
libraryDependencies += "com.lkroll.ep" %%% "ep-model" % "1.12.1"
libraryDependencies += "com.lkroll.ep" %%% "ep-model" % "1.12.2"
libraryDependencies += "com.lkroll.common" %%% "common-data-tools" % "1.3.+"
libraryDependencies += "com.lihaoyi" %%% "fastparse" % "1.+"
libraryDependencies += "org.rogach" %%% "scallop" % "3.1.+"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.lkroll.ep.api.compendium

import scala.concurrent.Future
import scala.concurrent.ExecutionContext

import com.lkroll.roll20.core._
import com.lkroll.roll20.api._
Expand All @@ -35,8 +36,9 @@ import APIImplicits._;

class CharacterImport(val c: EPCharacter) extends Importable {
private var morphId: Option[String] = None;
private var skillSet: Option[SkillImport] = None;

override def updateLabel: String = s"Character <c.name>";
override def updateLabel: String = s"Character ${c.name}";
override def importInto(char: Character, idPool: RowIdPool, cache: ImportCache): Result[String] = {
char.name = c.name;
char.attribute(epmodel.genderId) <<= c.gender.entryName;
Expand All @@ -61,9 +63,13 @@ class CharacterImport(val c: EPCharacter) extends Importable {

// Skills
val skillRes = c.skills.foldLeft(Ok("Ok").asInstanceOf[Result[String]]) { (acc, skill) =>
val res = SkillImport(skill).importInto(char, idPool, cache);
val skilli = SkillImport(skill);
val res = skilli.importInto(char, idPool, cache);
res match {
case Ok(_) => acc // ignore ok
case Ok(_) => {
this.skillSet = Some(skilli); // latest successful skill
acc // ignore ok
}
case Err(err) => acc match {
case Ok(_) => res // replace oks with errors
case Err(errAcc) => Err(s"${errAcc}, ${err}")
Expand Down Expand Up @@ -158,15 +164,19 @@ class CharacterImport(val c: EPCharacter) extends Importable {
l
}

override def triggerWorkers(char: Character): Future[Unit] = {
this.morphId match {
override def triggerWorkers(char: Character)(implicit ec: ExecutionContext): Future[Unit] = {
val morphF = this.morphId match {
case rowId @ Some(_) => {
// just setting a morph active, should cause almost all dynamic values on the sheet to be recalculated
val f = char.createRepeating(MorphSection.active, rowId).setWithWorker(true);
this.morphId = None; // reset to not activate twice
f
}
case None => Future.failed(new RuntimeException("You must import a character, before triggering workers!"))
};
this.skillSet match {
case Some(skilli) => morphF.flatMap(_ => skilli.triggerWorkers(char))
case None => morphF
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,21 @@ object EPCompendiumImportCommand extends EPCommand[EPCompendiumImportConf] {
case Failure(e) => Future.successful(List(s"Failed to parse data from sheet: ${e.getMessage}"))
}
} else {
var childUpdates = List.empty[String];
toImport.foreach { i =>
i.importInto(char, idPool, importCache) match {
case Ok(msg) => childUpdates ::= s"Imported ${i.updateLabel} ($msg)"
case Err(msg) => childUpdates ::= s"Failed to import ${i.updateLabel} (correctly): $msg"
val childUpdates = toImport.foldLeft(Future.successful(List.empty[String])) { (accf, i) =>
accf.flatMap { acc =>
i.importInto(char, idPool, importCache) match {
case Ok(msg) => {
val res = s"Imported ${i.updateLabel} ($msg)" :: acc;
i.triggerWorkers(char).map(_ => res)
}
case Err(msg) => {
val res = s"Failed to import ${i.updateLabel} (correctly): $msg" :: acc;
Future.successful(res)
}
}
}
}
Future.successful(childUpdates.reverse)
};
childUpdates
};

val updateF = updates.map(u => char.name -> u).recover {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ import com.lkroll.ep.compendium._
import com.lkroll.roll20.core._
import com.lkroll.roll20.api._
import com.lkroll.ep.model.ActiveSkillSection
import scala.concurrent.ExecutionContext

trait Importable {
def updateLabel: String;
def importInto(char: Character, idPool: RowIdPool, cache: ImportCache): Result[String];
def children: List[Importable] = Nil;
def triggerWorkers(char: Character): Future[Unit] = Future.successful(());
def triggerWorkers(char: Character)(implicit ec: ExecutionContext): Future[Unit] = Future.successful(());
}

object Importable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import com.lkroll.ep.compendium._
import com.lkroll.ep.compendium.utils.OptionPickler._
import com.lkroll.ep.model.{ EPCharModel => epmodel, ActiveSkillSection, KnowledgeSkillSection, Skills, Aptitude => ModelAptitude }
import APIImplicits._;
import scala.concurrent.Future
import scala.concurrent.ExecutionContext
import scala.util.Try

object SkillConversions {
def compendiumCat2modelCat(c: SkillCategory): Skills.SkillCategory.SkillCategory = {
Expand Down Expand Up @@ -76,9 +79,13 @@ object SkillConversions {
}

case class SkillImport(s: CharacterSkill) extends Importable {

private var assignedRowId: Option[String] = None;

def updateLabel: String = s.name;
def importInto(char: Character, idPool: RowIdPool, cache: ImportCache): Result[String] = {
val rowId = Some(idPool.generateRowId());
this.assignedRowId = rowId;

s.cls match {
case SkillClass.Active => {
Expand Down Expand Up @@ -135,12 +142,28 @@ case class SkillImport(s: CharacterSkill) extends Importable {
}
}
}

override def triggerWorkers(char: Character)(implicit ec: ExecutionContext): Future[Unit] = {
val r = Try(this.assignedRowId.get).map(rowId => {
s.cls match {
case SkillClass.Active => {
char.createRepeating(ActiveSkillSection.skillName, Some(rowId)).setWithWorker(s.name); // force trigger of Fray/2 worker
}
case _ => Future.successful(())
}
});
Future.fromTry(r).flatten
}
}

case class SkillDefImport(s: SkillDef) extends Importable {

private var assignedRowId: Option[String] = None;

def updateLabel: String = s.name;
def importInto(char: Character, idPool: RowIdPool, cache: ImportCache): Result[String] = {
val rowId = Some(idPool.generateRowId());
this.assignedRowId = rowId;

s.cls match {
case SkillClass.Active => {
Expand Down Expand Up @@ -197,4 +220,16 @@ case class SkillDefImport(s: SkillDef) extends Importable {
}
}
}

override def triggerWorkers(char: Character)(implicit ec: ExecutionContext): Future[Unit] = {
val r = Try(this.assignedRowId.get).map(rowId => {
s.cls match {
case SkillClass.Active => {
char.createRepeating(ActiveSkillSection.skillName, Some(rowId)).setWithWorker(s.name); // force trigger of Fray/2 worker
}
case _ => Future.successful(())
}
});
Future.fromTry(r).flatten
}
}
2 changes: 1 addition & 1 deletion sheet/epsheet.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name := "EP Sheet Root"

organization in ThisBuild := "com.lkroll.ep"

version in ThisBuild := "1.12.1"
version in ThisBuild := "1.12.2"

scalaVersion in ThisBuild := "2.12.8"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ object SkillWorkers extends SheetWorker {

val museSkillTotalCalc = museSkillTotalCalcOp.all(museSkills);

val nop1: Option[String] => ChainingDecision = (f) => ExecuteChain;
val nop7: Option[Tuple7[Int, Int, Int, Int, Int, Int, Int]] => ChainingDecision = (f) => ExecuteChain;
val museAptSkillCalc = bind(op(museCog, museCoo, museInt, museRef, museSav, museSom, museWil)) apply (nop7, museSkillTotalCalc);

Expand Down Expand Up @@ -137,6 +138,11 @@ object SkillWorkers extends SheetWorker {

onRemove(activeSkills, (_: Roll20.EventInfo) => { EPWorkers.searchFrayAndSetHalved(); () });

val setFrayHalved = nop { _: Option[Unit] =>
EPWorkers.searchFrayAndSetHalved()
};
val activeSkillNameChange = bind(op(activeSkills.skillName)) apply (nop1, setFrayHalved);

private def getActiveSkills(): Future[List[Skills.ActiveSkillTuple]] = {
import Skills.ActiveSkillTuple;
getRowAttrs(activeSkills, Seq(activeSkills.rowId, activeSkills.skillName, activeSkills.category, activeSkills.linkedAptitude, activeSkills.field)).map(_.map {
Expand Down

0 comments on commit c33c6dc

Please sign in to comment.