Commit 5c2c0bce authored by Mitchell Schwitzer's avatar Mitchell Schwitzer

setting up for git flow

parent f226bbf8
name := "scalamtg"
name := "org/github/schwitzerm/scalamtg"
organization := "org.github.schwitzerm"
sbtVersion := "0.13.9"
......@@ -27,5 +27,8 @@ libraryDependencies ++= {
"org.scalatest" %% "scalatest" % "2.2.6" % "test"
)
scalaLibs ++ scalazLibs ++ scalaTestLibs
val argonaut = "io.argonaut" %% "argonaut" % "6.1" // json parser
val scalafx = "org.scalafx" %% "scalafx" % "8.0.92-R10" // scalafx, for primitive gui
scalaLibs ++ scalazLibs ++ scalaTestLibs ++ Seq(argonaut, scalafx)
}
package org.github.schwitzerm.mtgjsonimport
import java.io.File
import scala.util.{Failure, Success, Try}
object FileHandler {
val userDir = System.getProperty("user.home")
val cardDir = userDir + "/.scalamtg/cards/"
val dir = new File(cardDir)
def getJsonFiles: Option[Seq[File]] = dir.exists && dir.isDirectory match {
case true =>
val files = dir.listFiles.filter(f => f.isFile && f.getName.contains("*.json"))
if(!files.isEmpty) Some(files) else None
case false => None
}
def loadJsonFile(file: File): Option[String] = {
val source = scala.io.Source.fromFile(file)
Try(source.getLines.mkString("\n")) match {
case Success(s) => Some(s)
case Failure(e) => None
}
}
}
package org.github.schwitzerm.mtgjsonimport
object JsonParser {
case class SetData()
}
package org.github.schwitzerm.scalamtg.card
import org.github.schwitzerm.scalamtg.card.components.{Ability, CardSetInfo, ManaCost}
import org.github.schwitzerm.scalamtg.types.Colour
import org.github.schwitzerm.scalamtg.types.base.CardSubTypes
case class Card(
name: String,
manaCost: Option[ManaCost],
colours: Seq[Colour],
types: Seq[CardSubTypes],
abilities: Seq[Ability],
power: Int,
toughness: Int,
flavourText: Option[String],
cardSetInfo: CardSetInfo,
artist: String)
{
def convertedManaCost: Int = manaCost match
{
case Some(m) => m.convertedManaCost
case None => 0
}
implicit def CardCodecJson = Argonaut.casecodec22()
}
package scalamtg.card.components
import scalamtg.card.Card
package org.github.schwitzerm.scalamtg.card.components
sealed trait Ability
......
package scalamtg.card.components
package org.github.schwitzerm.scalamtg.card.components
case class CardSetInfo(
expansions: Seq[Expansion],
......
package scalamtg.card.components
package org.github.schwitzerm.scalamtg.card.components
sealed trait Expansion {
val name: String
......
package scalamtg.card.components
package org.github.schwitzerm.scalamtg.card.components
import scala.collection.SortedMap
import scalamtg.syntax.MapOps._
import scalamtg.types.Mana
import org.github.schwitzerm.scalamtg.syntax.MapOps._
import org.github.schwitzerm.scalamtg.types.Mana
case class ManaCost(iv: SortedMap[Mana, Int]) extends SortedMap[Mana, Int] {
override implicit def ordering: Ordering[Mana] = iv.ordering
......@@ -34,7 +34,7 @@ case class ManaCost(iv: SortedMap[Mana, Int]) extends SortedMap[Mana, Int] {
sb.toString()
}
def convertedManaCost: Int = iv.foldLeft[Int](0)((z, h) => z + h._2)
def convertedManaCost: Int = iv.values.sum
}
object ManaCost {
......
package scalamtg.card.components
package org.github.schwitzerm.scalamtg.card.components
sealed trait Rarity
......
package scalamtg.syntax
package org.github.schwitzerm.scalamtg.syntax
import scala.collection.SortedMap
......
package scalamtg.types
package org.github.schwitzerm.scalamtg.types
sealed trait Colour
......@@ -11,4 +11,7 @@ object Colour {
// not really a colour, but easier to represent as one instead of checking for the absence of colours
case object Colourless extends Colour
// from newer sets, may not be necessary as Devoid is an ability... time wil tell.
case object Devoid extends Colour
}
package scalamtg.types
package org.github.schwitzerm.scalamtg.types
sealed trait Mana extends Ordered[Mana] {
val order: Int
......
package scalamtg.types.base
package org.github.schwitzerm.scalamtg.types.base
abstract class Artifact extends Permanent
package scalamtg.types.base
package org.github.schwitzerm.scalamtg.types.base
sealed trait CardSubTypes
......
package scalamtg.types.base
package org.github.schwitzerm.scalamtg.types.base
abstract class Creature extends Permanent
package scalamtg.types.base
package org.github.schwitzerm.scalamtg.types.base
abstract class Enchantment extends Permanent
package scalamtg.types.base
package org.github.schwitzerm.scalamtg.types.base
abstract class Instant extends Spell
package scalamtg.types.base
package org.github.schwitzerm.scalamtg.types.base
abstract class Land extends Permanent
package org.github.schwitzerm.scalamtg.types.base
trait Permanent
package scalamtg.types.base
package org.github.schwitzerm.scalamtg.types.base
abstract class Planeswalker extends Permanent
package scalamtg.types.base
package org.github.schwitzerm.scalamtg.types.base
abstract class Sorcery extends Spell
package org.github.schwitzerm.scalamtg.types.base
trait Spell
package scalamtg.card
import scalamtg.card.components._
import scalamtg.types.{Colour, Mana}
import scalamtg.types.base.{CardSubTypes, Creature}
case class AkrasanSquire() extends Creature with Card {
override val name: String = "Akrasan Squire"
override val flavourText: Option[String] = Some(
"""
|Bant's armies are primarily composed of members of the Mortar caste, loyal commoners who haven't yet earned a
|sigil.
""".stripMargin
)
override val cardSetInfo: CardSetInfo = CardSetInfo(Seq(Expansion.ShardsOfAlara), Rarity.Common, new CollectorsNumbers)
override val artist: String = "Todd Lockwood"
override val manaCost: Option[ManaCost] = Some(
ManaCost(Mana.WhiteMana -> 1)
)
override val colours: Seq[Colour] = Seq(
Colour.White
)
override val types: Seq[CardSubTypes] = Seq(
CardSubTypes.Human,
CardSubTypes.Soldier
)
override val power: Int = 1
override val toughness: Int = 1
}
package scalamtg.card
import scalamtg.types.Colour
import scalamtg.types.base.CardSubTypes
import scalamtg.card.components.{CardSetInfo, ManaCost}
trait Card {
val name: String
val flavourText: Option[String]
val cardSetInfo: CardSetInfo
val artist: String
val manaCost: Option[ManaCost]
val colours: Seq[Colour]
val types: Seq[CardSubTypes]
val power: Int
val toughness: Int
def convertedManaCost: Int = manaCost match {
case Some(m) => m.convertedManaCost
case None => 0
}
}
package scalamtg.types.base
trait Permanent
package scalamtg.types.base
trait Spell
import org.scalatest.FlatSpec
import scalamtg.card.components.ManaCost
import scalamtg.types.Mana
import org.github.schwitzerm.scalamtg.card.components.ManaCost
import org.github.schwitzerm.scalamtg.types.Mana
class ManaCostTests extends FlatSpec {
"A mana cost of 2U" should "stringify" in {
val manaCost = ManaCost(
Mana.BlueMana -> 1,
Mana.AnyMana -> 2
)
assert(manaCost.toString() == "2U")
}
"A mana cost of WUBRG" should "stringify" in {
val manaCost = ManaCost(
Mana.WhiteMana -> 1,
Mana.BlueMana -> 1,
Mana.BlackMana -> 1,
Mana.RedMana -> 1,
Mana.GreenMana -> 1
)
assert(manaCost.toString() == "WUBRG")
}
"A mana cost of 1WUBRG" should "stringify" in {
val manaCost = ManaCost(
Mana.WhiteMana -> 1,
Mana.BlueMana -> 1,
Mana.BlackMana -> 1,
Mana.RedMana -> 1,
Mana.GreenMana -> 1,
Mana.AnyMana -> 1
)
assert(manaCost.toString() == "1WUBRG")
}
val testManaCost = ManaCost(
Mana.BlackMana -> 1,
Mana.ColourlessMana -> 1,
Mana.AnyMana -> 2
)
"A mana cost of 2CB" should "stringify" in {
val manaCost = ManaCost(
Mana.BlackMana -> 1,
Mana.ColourlessMana -> 1,
Mana.AnyMana -> 2
)
assert(manaCost.toString() == "2CB")
assert(testManaCost.toString() == "2CB")
}
it should "have a converted mana cost of 4" in {
assert(testManaCost.convertedManaCost == 4)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment