Skip to content

Commit

Permalink
Added character, skill, and psi sleight import options
Browse files Browse the repository at this point in the history
  • Loading branch information
Bathtor committed Feb 24, 2019
1 parent 9520a85 commit 91dbd57
Show file tree
Hide file tree
Showing 11 changed files with 631 additions and 50 deletions.
10 changes: 6 additions & 4 deletions script/epapiscript.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ name := "EP API Script"

organization := "com.lkroll.ep"

version := "0.9.0"
version := "0.10.0"

scalaVersion := "2.12.6"
scalaVersion := "2.12.8"

libraryDependencies += "com.lkroll.roll20" %%% "roll20-api-framework" % "0.8.+"
libraryDependencies += "com.lkroll.ep" %%% "epcompendium-core" % "3.3.0-SNAPSHOT"
resolvers += Resolver.bintrayRepo("lkrollcom", "maven")

libraryDependencies += "com.lkroll.roll20" %%% "roll20-api-framework" % "0.9.0"
libraryDependencies += "com.lkroll.ep" %%% "epcompendium-core" % "4.0.0"
libraryDependencies += "com.lkroll.ep" %%% "ep-model" % "1.10.0"
libraryDependencies += "com.lihaoyi" %%% "fastparse" % "1.+"
libraryDependencies += "org.rogach" %%% "scallop" % "3.1.+"
Expand Down
2 changes: 1 addition & 1 deletion script/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.2.0
sbt.version=1.2.8
5 changes: 3 additions & 2 deletions script/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.24")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.26")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.0")

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2017 Lars Kroll <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
package com.lkroll.ep.api.compendium

import scala.concurrent.Future

import com.lkroll.roll20.core._
import com.lkroll.roll20.api._
import com.lkroll.ep.compendium._
import com.lkroll.ep.compendium.utils.OptionPickler._
import com.lkroll.ep.model.{ EPCharModel => epmodel, IdentitiesSection, MorphSection }
import APIImplicits._;

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

override def updateLabel: String = s"Character <c.name>";
override def importInto(char: Character, idPool: RowIdPool, cache: ImportCache): Either[String, String] = {
char.name = c.name;
char.attribute(epmodel.genderId) <<= c.gender.entryName;
char.attribute(epmodel.actualAge) <<= c.age;
char.attribute(epmodel.motivations) <<= c.motivations.map(_.text).mkString(", ");
char.attribute(epmodel.faction) <<= c.faction;
char.attribute(epmodel.background) <<= c.background;
val moxie = char.createAttribute(epmodel.moxie);
moxie <<= c.moxie;
moxie.max = c.moxie.toString;
char.attribute(epmodel.miscNotes) <<= c.history.mkString("\n");
char.attribute(epmodel.async) <<= c.isAsync;

// Aptitudes
char.attribute(epmodel.cogBase) <<= c.aptitudes.base.cog.getOrElse(0);
char.attribute(epmodel.cooBase) <<= c.aptitudes.base.coo.getOrElse(0);
char.attribute(epmodel.intBase) <<= c.aptitudes.base.int.getOrElse(0);
char.attribute(epmodel.refBase) <<= c.aptitudes.base.ref.getOrElse(0);
char.attribute(epmodel.savBase) <<= c.aptitudes.base.sav.getOrElse(0);
char.attribute(epmodel.somBase) <<= c.aptitudes.base.som.getOrElse(0);
char.attribute(epmodel.wilBase) <<= c.aptitudes.base.wil.getOrElse(0);

// Skills
val skillRes = c.skills.foldLeft(Left("Ok").asInstanceOf[Either[String, String]]) { (acc, skill) =>
val res = SkillImport(skill).importInto(char, idPool, cache);
res match {
case Left(_) => acc // ignore lefts
case Right(err) => acc match {
case Left(_) => res // replace lefts with rights
case Right(errAcc) => Right(s"${errAcc}, ${err}")
}
}
};
var res = skillRes match {
case Left(_) => Left("Ok")
case Right(err) => Right(s"Some skills failed to import correctly:\n$err")
};
cache.reset(); // we changed all the skills here

// Identities
val identityRowId = Some(idPool.generateRowId());
char.createRepeating(IdentitiesSection.identity, identityRowId) <<= c.name;
char.createRepeating(IdentitiesSection.description, identityRowId) <<= "Primary ID";
char.createRepeating(IdentitiesSection.credits, identityRowId) <<= c.startingCredit;
char.createRepeating(IdentitiesSection.notes, identityRowId) <<= "Imported from JSON";
c.rep.foreach {
case (network, rep) =>
network.name match {
case "@-Rep" => {
char.createRepeating(IdentitiesSection.atRepScore, identityRowId) <<= rep;
}
case "c-Rep" => {
char.createRepeating(IdentitiesSection.cRepScore, identityRowId) <<= rep;
}
case "e-Rep" => {
char.createRepeating(IdentitiesSection.eRepScore, identityRowId) <<= rep;
}
case "f-Rep" => {
char.createRepeating(IdentitiesSection.fRepScore, identityRowId) <<= rep;
}
case "g-Rep" => {
char.createRepeating(IdentitiesSection.gRepScore, identityRowId) <<= rep;
}
case "i-Rep" => {
char.createRepeating(IdentitiesSection.iRepScore, identityRowId) <<= rep;
}
case "r-Rep" => {
char.createRepeating(IdentitiesSection.rRepScore, identityRowId) <<= rep;
}
case "u-Rep" => {
char.createRepeating(IdentitiesSection.uRepScore, identityRowId) <<= rep;
}
case "x-Rep" => {
char.createRepeating(IdentitiesSection.xRepScore, identityRowId) <<= rep;
}
case n => {
res = res match {
case Left(_) => Right(s"Unkown rep network $n!")
case Right(err) => Right(s"${err}\nUnkown rep network ${n}!")
}
}
}
}
val morphRowId = idPool.generateRowId();
val morphRes = MorphInstanceImport(c.activeMorph).importInto(char, morphRowId, cache);
res = (res, morphRes) match {
case (Left(_), Left(_)) => {
this.morphId = Some(morphRowId);
Left("Ok")
}
case (Left(_), x) => x
case (x, Left(_)) => {
this.morphId = Some(morphRowId);
x
}
case (Right(err), Right(errMorph)) => {
Right(s"${err}\nError during morph import: ${errMorph}")
}
};
res
}
override def children: List[Importable] = {
import Importable._;

var l: List[Importable] = Nil;
l ++= c.traits.map(trait2Import);
l ++= c.psiChiSleights.map(psiSleight2Import);
l ++= c.psiGammaSleights.map(psiSleight2Import);
l ++= c.gear.map(gearEntry2Import);
l ++= c.weapons.map {
case Left(w) => weapon2Import(w)
case Right(wwa) => wwa2Import(wwa)
};
l ++= c.armour.map {
case Left(a) => armour2Import(a)
case Right(ma) => moddedarmour2Import(ma)
};
l ++= c.software.map(software2Import);
l
}

override def triggerWorkers(char: Character): Future[Unit] = {
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!"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ class EPCompendiumDataConf(_args: Seq[String]) extends ScallopAPIConf(_args) {
val augmentation = opt[String]("augmentation", descr = "Search for matches with &lt;param&gt; in augmentations.")(ScallopUtils.singleArgSpacedConverter(identity));
val armourMod = opt[String]("armour-mod", descr = "Search for matches with &lt;param&gt; in armour mods.")(ScallopUtils.singleArgSpacedConverter(identity));
val weaponAccessory = opt[String]("weapon-accessory", descr = "Search for matches with &lt;param&gt; in weapon accessories.")(ScallopUtils.singleArgSpacedConverter(identity));
val psiSleight = opt[String]("psi-sleight", descr = "Search for matches with &lt;param&gt; in psi sleights.")(ScallopUtils.singleArgSpacedConverter(identity));
val skill = opt[String]("skill", descr = "Search for matches with &lt;param&gt; in skills.")(ScallopUtils.singleArgSpacedConverter(identity));

val trailing = trailArg[List[String]]("trailing", hidden = true, required = false);

dependsOnAny(nameOnly, List(search, weapon, ammo, morph, morphModel, epTrait, derangement, disorder, armour, gear, software, substance, augmentation, armourMod, weaponAccessory));
dependsOnAny(rank, List(search, weapon, ammo, morph, morphModel, epTrait, derangement, disorder, armour, gear, software, substance, augmentation, armourMod, weaponAccessory));
dependsOnAny(rankMax, List(search, weapon, ammo, morph, morphModel, epTrait, derangement, disorder, armour, gear, software, substance, augmentation, armourMod, weaponAccessory));
dependsOnAny(nameOnly, List(search, weapon, ammo, morph, morphModel, epTrait, derangement, disorder, armour, gear, software, substance, augmentation, armourMod, weaponAccessory, psiSleight, skill));
dependsOnAny(rank, List(search, weapon, ammo, morph, morphModel, epTrait, derangement, disorder, armour, gear, software, substance, augmentation, armourMod, weaponAccessory, psiSleight, skill));
dependsOnAny(rankMax, List(search, weapon, ammo, morph, morphModel, epTrait, derangement, disorder, armour, gear, software, substance, augmentation, armourMod, weaponAccessory, psiSleight, skill));
dependsOnAll(withAmmo, List(weapon));
dependsOnAll(multiSearch, List(trailing));
requireOne(search, multiSearch, weapon, ammo, morph, morphModel, epTrait, derangement, disorder, armour, gear, software, substance, augmentation, armourMod, weaponAccessory);
requireOne(search, multiSearch, weapon, ammo, morph, morphModel, epTrait, derangement, disorder, armour, gear, software, substance, augmentation, armourMod, weaponAccessory, psiSleight, skill);
verify();

def forDataType(dataType: String): Option[org.rogach.scallop.ScallopOption[String]] = {
Expand All @@ -79,6 +82,8 @@ class EPCompendiumDataConf(_args: Seq[String]) extends ScallopAPIConf(_args) {
case Gear.dataType => Some(gear)
case MorphModel.dataType => Some(morphModel)
case MorphInstance.dataType => Some(morph)
case PsiSleight.dataType => Some(psiSleight)
case SkillDef.dataType => Some(skill)
case Software.dataType => Some(software)
case Substance.dataType => Some(substance)
case Weapon.dataType => Some(weapon)
Expand Down Expand Up @@ -207,6 +212,16 @@ object EPCompendiumDataCommand extends APICommand[EPCompendiumDataConf] {
ctx.reply(s"Searching for '$needle' in weapon accessories...");
val results = EPCompendium.findWeaponAccessories(needle);
handleResults(results, config, ctx);
} else if (config.psiSleight.isSupplied) {
val needle = config.psiSleight();
ctx.reply(s"Searching for '$needle' in psi sleights...");
val results = EPCompendium.findPsiSleights(needle);
handleResults(results, config, ctx);
} else if (config.skill.isSupplied) {
val needle = config.skill();
ctx.reply(s"Searching for '$needle' in skills...");
val results = EPCompendium.findSkillDefs(needle);
handleResults(results, config, ctx);
} else {
error(s"Unsupported options supplied: ${config.args}");
}
Expand Down Expand Up @@ -263,8 +278,10 @@ object EPCompendiumDataCommand extends APICommand[EPCompendiumDataConf] {
val aname = buttonSafeText(wwa.ammo.lookupName);
List(config.weapon <<= wname, config.withAmmo <<= aname)
}
case _: Substance => List(config.substance <<= name)
case _ => List.empty
case _: Substance => List(config.substance <<= name)
case _: SkillDef => List(config.skill <<= name)
case _: PsiSleight => List(config.psiSleight <<= name)
case _ => List.empty
}
}

Expand All @@ -281,6 +298,8 @@ object EPCompendiumDataCommand extends APICommand[EPCompendiumDataConf] {
case _: Gear => List(config.gear <<= name)
case _: MorphModel => List(config.morphModel <<= name)
case _: MorphInstance => List(config.morph <<= name)
case _: PsiSleight => List(config.psiSleight <<= name)
case _: SkillDef => List(config.skill <<= name)
case _: Software => List(config.software <<= name)
case _: Substance => List(config.substance <<= name)
case _: Weapon => List(config.weapon <<= name)
Expand Down Expand Up @@ -344,6 +363,16 @@ object EPCompendiumDataCommand extends APICommand[EPCompendiumDataConf] {
c.sublabel <<= buttonSafeText(skill)));
List("Damage" -> dmgButton, "Skill" -> skillButton)
}
case s: SkillDef => {
val c = SpecialRollsCommand.minConf;
val skill = s.name;
val skillButton = SpecialRollsCommand.invoke("Success Roll", List(
c.success <<= true,
c.target.name <<= s"?{$skill}",
c.label <<= buttonSafeText(s.templateTitle),
c.sublabel <<= buttonSafeText(s.templateSubTitle)));
List("Commands" -> skillButton)
}
case _ => List.empty
}
}
Expand Down
Loading

0 comments on commit 91dbd57

Please sign in to comment.