From c7b279257f21e3da140d233bd50fc9f92d335335 Mon Sep 17 00:00:00 2001 From: Anthony Cerruti Date: Thu, 2 Jul 2020 10:26:19 -0700 Subject: [PATCH] Unify under one project --- build.sbt | 33 +- .../scala/tf/bug/fancadegraph/Argument.scala | 34 + .../scala/tf/bug/fancadegraph/Block.scala | 22 + .../tf/bug/fancadegraph/BlockDefinition.scala | 1186 +++++++++++++++++ .../scala/tf/bug/fancadegraph/Level.scala | 87 ++ .../main/scala/tf/bug/fancadegraph/Main.scala | 47 + .../main/scala/tf/bug/fancadegraph/Pin.scala | 6 + .../tf/bug/fancadegraph/PinDefinition.scala | 47 + project/plugins.sbt | 2 + .../scala/tf/bug/fancadescodec/Boundary.scala | 13 + .../tf/bug/fancadescodec/Cartridge.scala | 8 + .../scala/tf/bug/fancadescodec/Codecs.scala | 159 +++ .../scala/tf/bug/fancadescodec/Entry.scala | 10 + .../scala/tf/bug/fancadescodec/Faces.scala | 10 + .../scala/tf/bug/fancadescodec/Main.scala | 125 ++ .../scala/tf/bug/fancadescodec/Metadata.scala | 60 + .../main/scala/tf/bug/fancadescodec/Obj.scala | 651 +++++++++ .../scala/tf/bug/fancadescodec/Wire.scala | 8 + .../scala/tf/bug/fancadescodec/World.scala | 6 + .../tf/bug/fancadetagless/Constraint.scala | 0 .../scala/tf/bug/fancadetagless/Fancade.scala | 0 .../tf/bug/fancadetagless/Fanscript.scala | 0 .../scala/tf/bug/fancadetagless/Obj.scala | 0 .../tf/bug/fancadetagless/Rotation.scala | 0 .../scala/tf/bug/fancadetagless/Vector3.scala | 0 .../scala/tf/bug/fancadetagless/package.scala | 0 .../tf/bug/fancadetagless/FancadeSuite.scala | 0 27 files changed, 2510 insertions(+), 4 deletions(-) create mode 100644 graph/src/main/scala/tf/bug/fancadegraph/Argument.scala create mode 100644 graph/src/main/scala/tf/bug/fancadegraph/Block.scala create mode 100644 graph/src/main/scala/tf/bug/fancadegraph/BlockDefinition.scala create mode 100644 graph/src/main/scala/tf/bug/fancadegraph/Level.scala create mode 100644 graph/src/main/scala/tf/bug/fancadegraph/Main.scala create mode 100644 graph/src/main/scala/tf/bug/fancadegraph/Pin.scala create mode 100644 graph/src/main/scala/tf/bug/fancadegraph/PinDefinition.scala create mode 100644 project/plugins.sbt create mode 100644 scodec/src/main/scala/tf/bug/fancadescodec/Boundary.scala create mode 100644 scodec/src/main/scala/tf/bug/fancadescodec/Cartridge.scala create mode 100644 scodec/src/main/scala/tf/bug/fancadescodec/Codecs.scala create mode 100644 scodec/src/main/scala/tf/bug/fancadescodec/Entry.scala create mode 100644 scodec/src/main/scala/tf/bug/fancadescodec/Faces.scala create mode 100644 scodec/src/main/scala/tf/bug/fancadescodec/Main.scala create mode 100644 scodec/src/main/scala/tf/bug/fancadescodec/Metadata.scala create mode 100644 scodec/src/main/scala/tf/bug/fancadescodec/Obj.scala create mode 100644 scodec/src/main/scala/tf/bug/fancadescodec/Wire.scala create mode 100644 scodec/src/main/scala/tf/bug/fancadescodec/World.scala rename {core => tagless}/src/main/scala/tf/bug/fancadetagless/Constraint.scala (100%) rename {core => tagless}/src/main/scala/tf/bug/fancadetagless/Fancade.scala (100%) rename {core => tagless}/src/main/scala/tf/bug/fancadetagless/Fanscript.scala (100%) rename {core => tagless}/src/main/scala/tf/bug/fancadetagless/Obj.scala (100%) rename {core => tagless}/src/main/scala/tf/bug/fancadetagless/Rotation.scala (100%) rename {core => tagless}/src/main/scala/tf/bug/fancadetagless/Vector3.scala (100%) rename {core => tagless}/src/main/scala/tf/bug/fancadetagless/package.scala (100%) rename {core => tagless}/src/test/scala/tf/bug/fancadetagless/FancadeSuite.scala (100%) diff --git a/build.sbt b/build.sbt index 54e74a2..d598da6 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,31 @@ -lazy val core = (project in file("core")).settings( +lazy val scodec = (project in file("scodec")).settings( + organization := "tf.bug", + name := "fancadescodec", + version := "0.1.0", + scalaVersion := "2.13.2", + libraryDependencies ++= Seq( + "org.scodec" %% "scodec-core" % "1.11.7", + "org.scodec" %% "scodec-bits" % "1.1.14", + "org.scodec" %% "scodec-stream" % "2.0.0", + "org.typelevel" %% "cats-effect" % "2.1.2", + "org.typelevel" %% "cats-core" % "2.1.1", + "co.fs2" %% "fs2-core" % "2.3.0", + "co.fs2" %% "fs2-io" % "2.3.0", + ), + mainClass in assembly := Some("tf.bug.fancadescodec.Main"), +) + +lazy val graph = (project in file("graph")).settings( + organization := "tf.bug", + name := "fancadegraph", + version := "0.1.0", + scalaVersion := "2.13.2", + libraryDependencies ++= Seq( + "org.scala-graph" %% "graph-core" % "1.13.2", + ), +).dependsOn(scodec) + +lazy val tagless = (project in file("tagless")).settings( organization := "tf.bug", name := "fancadetagless", version := "0.1.0", @@ -9,10 +36,8 @@ lazy val core = (project in file("core")).settings( "org.typelevel" %% "cats-core" % "2.1.1", "org.typelevel" %% "cats-effect" % "2.1.2", "io.chrisdavenport" %% "fuuid" % "0.3.0", - "tf.bug" %% "fancadescodec" % "0.1.1", - "tf.bug" %% "fancadegraph" % "0.1.0", "org.scalameta" %% "munit" % "0.7.9" % Test, ), testFrameworks += new TestFramework("munit.Framework"), addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.11.0" cross CrossVersion.full), -) +).dependsOn(scodec, graph) diff --git a/graph/src/main/scala/tf/bug/fancadegraph/Argument.scala b/graph/src/main/scala/tf/bug/fancadegraph/Argument.scala new file mode 100644 index 0000000..d59f729 --- /dev/null +++ b/graph/src/main/scala/tf/bug/fancadegraph/Argument.scala @@ -0,0 +1,34 @@ +package tf.bug.fancadegraph + +import tf.bug.{fancadescodec => fansc} + +trait Argument[T] { + def encode(value: T)(pos: fansc.Position): Vector[fansc.Metadata] +} + +object Argument { + implicit val unitArg: Argument[Unit] = new Argument[Unit] { + override def encode(value: Unit)(pos: fansc.Position): Vector[fansc.Metadata] = Vector.empty + } + implicit val stringArg: Argument[String] = new Argument[String] { + override def encode(value: String)(pos: fansc.Position): Vector[fansc.Metadata] = Vector( + fansc.Metadata.Text(pos, value) + ) + } + implicit val floatArg: Argument[Float] = new Argument[Float] { + override def encode(value: Float)(pos: fansc.Position): Vector[fansc.Metadata] = Vector( + fansc.Metadata.Number(pos, value) + ) + } + implicit val soundOptionsArg: Argument[SoundOptions] = new Argument[SoundOptions] { + override def encode(value: SoundOptions)(pos: fansc.Position): Vector[fansc.Metadata] = Vector( + fansc.Metadata.PlaySoundLoop(pos, value.loop), + fansc.Metadata.PlaySoundSample(pos, value.sample) + ) + } +} + +case class SoundOptions( + loop: Boolean, + sample: fansc.Metadata.Sample +) diff --git a/graph/src/main/scala/tf/bug/fancadegraph/Block.scala b/graph/src/main/scala/tf/bug/fancadegraph/Block.scala new file mode 100644 index 0000000..213bfbf --- /dev/null +++ b/graph/src/main/scala/tf/bug/fancadegraph/Block.scala @@ -0,0 +1,22 @@ +package tf.bug.fancadegraph + +import tf.bug.fancadescodec.{Metadata, Position} + +case class Block[T]( + position: Position, + definition: BlockDefinition[T], + argument: T +)( + implicit ev: Argument[T] +) { + def metadata: Vector[Metadata] = ev.encode(argument)(position) +} + +object Block { + def apply(position: Position, definition: BlockDefinition[Unit]): Block[Unit] = + new Block( + position, + definition, + () + ) +} diff --git a/graph/src/main/scala/tf/bug/fancadegraph/BlockDefinition.scala b/graph/src/main/scala/tf/bug/fancadegraph/BlockDefinition.scala new file mode 100644 index 0000000..78f8853 --- /dev/null +++ b/graph/src/main/scala/tf/bug/fancadegraph/BlockDefinition.scala @@ -0,0 +1,1186 @@ +package tf.bug.fancadegraph + +import tf.bug.fancadescodec.Obj + +sealed trait BlockDefinition[T] { + val width: Int + val height: Int + val depth: Int + val pins: Vector[PinDefinition] + + val ids: Vector[Obj] // FIXME support custom blocks +} + +object BlockDefinition { + + sealed trait BuiltIn[T] extends BlockDefinition[T] { + val ids: Vector[Obj] + } + + sealed trait Tangible[T] extends BuiltIn[T] { + final override val pins: Vector[PinDefinition] = Vector() // FIXME + } + + case object Bricks extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.bricks) + } + case object Grass extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.grass) + } + case object GrassDotty extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.grassDotty) + } + case object Dirt extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.dirt) + } + case object DirtDotty extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.dirtDotty) + } + case object DirtSlab extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.dirtSlab) + } + case object FoliageSlab extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.foliageSlab) + } + case object FoliageDotty extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.foliageDotty) + } + case object FoliageTop extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.foliageTop) + } + case object Foliage extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.foliage) + } + case object FoliageBottom extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.foliageBottom) + } + case object Stone extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stone) + } + case object StoneDotty extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stoneDotty) + } + case object StoneSlab extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stoneSlab) + } + case object StoneTop extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stoneTop) + } + case object StoneBottom extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stoneBottom) + } + case object StoneBlock extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stoneBlock) + } + case object StonePillar extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stonePillar) + } + case object StoneHalf extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stoneHalf) + } + case object Slate extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.slate) + } + case object SlateDotty extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.slateDotty) + } + case object SlateNE extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.slateNE) + } + case object SlateNW extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.slateNW) + } + case object SlateSE extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.slateSE) + } + case object SlateSW extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.slateSW) + } + case object SlateTop extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.slateTop) + } + case object SlateBottom extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.slateBottom) + } + case object WoodLR extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.woodLR) + } + case object WoodDU extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.woodDU) + } + case object WoodNF extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.woodNF) + } + case object WoodLowLR extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.woodLowLR) + } + case object WoodLowNF extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.woodLowNF) + } + case object WoodHighLR extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.woodHighLR) + } + case object WoodHighNF extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.woodHighNF) + } + case object Steel extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.steel) + } + case object Box extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.box) + } + case object Sphere extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.sphere) + } + case object PhysicsBox extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.physicsBox) + } + case object PhysicsSphere extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.physicsSphere) + } + case object PassThrough extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.passThrough) + } + case object ScriptBlock extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.scriptBlock) + } + case object Flowers extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.flowers) + } + case object Particle extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.particle) + } + case object Marker extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.marker) + } + case object Shrub extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.shrub) + } + case object StickLR extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickLR) + } + case object StickDU extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickDU) + } + case object StickNF extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickNF) + } + case object StickRF extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickRF) + } + case object StickLF extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickLF) + } + case object StickLN extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickLN) + } + case object StickRN extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickRN) + } + case object StickRU extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickRU) + } + case object StickUF extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickUF) + } + case object StickLU extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickLU) + } + case object StickUN extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickUN) + } + case object StickRD extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickRD) + } + case object StickDF extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickDF) + } + case object StickLD extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickLD) + } + case object StickDN extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.stickDN) + } + + case object Arch extends Tangible[Unit] { + override val width: Int = 1 + override val height: Int = 2 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector(Obj.archLower, Obj.archHigher) + } + + case object Win extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector(Obj.win0, Obj.win1, Obj.win2, Obj.win3) + + val after: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.bottom(0) + ) + + val before: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Output, + PinPosition.top2(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + after, + before + ) + } + + case object Lose extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector(Obj.lose0, Obj.lose1, Obj.lose2, Obj.lose3) + + val after: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.bottom(0) + ) + + val before: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Output, + PinPosition.top2(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + after, + before + ) + } + + case object SetScore extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector(Obj.setScore0, Obj.setScore1, Obj.setScore2, Obj.setScore3) + + val after: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.bottom(0) + ) + + val before: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Output, + PinPosition.top2(0) + ) + + val score: PinDefinition = + PinDefinition( + PinType.Number, + PinDirection.Input, + PinPosition.left(1) + ) + + override val pins: Vector[PinDefinition] = Vector( + after, + before, + score + ) + } + + case object SetCamera extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 3 + override val ids: Vector[Obj] = Vector( + Obj.setCamera0, + Obj.setCamera1, + Obj.setCamera2, + Obj.setCamera3, + Obj.setCamera4, + Obj.setCamera5 + ) + + val after: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.bottom(0) + ) + + val before: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Output, + PinPosition.top3(0) + ) + + val position: PinDefinition = + PinDefinition( + PinType.Vector, + PinDirection.Input, + PinPosition.left(2) + ) + + val rotation: PinDefinition = + PinDefinition( + PinType.Rotation, + PinDirection.Input, + PinPosition.left(1) + ) + + val distance: PinDefinition = + PinDefinition( + PinType.Number, + PinDirection.Input, + PinPosition.left(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + after, + before, + position, + rotation, + distance + ) + } + + case object SetLight extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector(Obj.setLight0, Obj.setLight1, Obj.setLight2, Obj.setLight3) + + val after: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.bottom(0) + ) + + val before: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Output, + PinPosition.top2(0) + ) + + val position: PinDefinition = + PinDefinition( + PinType.Vector, + PinDirection.Input, + PinPosition.left(1) + ) + + val rotation: PinDefinition = + PinDefinition( + PinType.Rotation, + PinDirection.Input, + PinPosition.left(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + after, + before, + position, + rotation + ) + } + + case object Accelerometer extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector( + Obj.accelerometer0, + Obj.accelerometer1, + Obj.accelerometer2, + Obj.accelerometer3 + ) + + val output: PinDefinition = + PinDefinition( + PinType.Vector, + PinDirection.Output, + PinPosition.right2(1) + ) + + override val pins: Vector[PinDefinition] = Vector( + output + ) + } + + case object ScreenSize extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector( + Obj.screenSize0, + Obj.screenSize1, + Obj.screenSize2, + Obj.screenSize3 + ) + + val screenWidth: PinDefinition = + PinDefinition( + PinType.Number, + PinDirection.Output, + PinPosition.right2(1) + ) + + val screenHeight: PinDefinition = + PinDefinition( + PinType.Number, + PinDirection.Output, + PinPosition.right2(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + screenWidth, + screenHeight + ) + } + + case object GetPosition extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector( + Obj.getPosition0, + Obj.getPosition1, + Obj.getPosition2, + Obj.getPosition3 + ) + + val obj: PinDefinition = + PinDefinition( + PinType.Object, + PinDirection.Input, + PinPosition.left(1) + ) + + val position: PinDefinition = + PinDefinition( + PinType.Vector, + PinDirection.Output, + PinPosition.right2(1) + ) + + val rotation: PinDefinition = + PinDefinition( + PinType.Rotation, + PinDirection.Output, + PinPosition.right2(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + obj, + position, + rotation + ) + } + + case object SetPosition extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 3 + override val ids: Vector[Obj] = Vector( + Obj.setPosition0, + Obj.setPosition1, + Obj.setPosition2, + Obj.setPosition3, + Obj.setPosition4, + Obj.setPosition5 + ) + + val after: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.bottom(0) + ) + + val before: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.top3(0) + ) + + val obj: PinDefinition = + PinDefinition( + PinType.Object, + PinDirection.Input, + PinPosition.left(2) + ) + + val position: PinDefinition = + PinDefinition( + PinType.Vector, + PinDirection.Input, + PinPosition.left(1) + ) + + val rotation: PinDefinition = + PinDefinition( + PinType.Rotation, + PinDirection.Input, + PinPosition.left(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + after, + before, + obj, + position, + rotation + ) + } + + case object Raycast extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 3 + override val ids: Vector[Obj] = Vector( + Obj.raycast0, + Obj.raycast1, + Obj.raycast2, + Obj.raycast3, + Obj.raycast4, + Obj.raycast5 + ) + + val from: PinDefinition = + PinDefinition( + PinType.Vector, + PinDirection.Input, + PinPosition.left(2) + ) + + val to: PinDefinition = + PinDefinition( + PinType.Vector, + PinDirection.Input, + PinPosition.left(1) + ) + + val hit: PinDefinition = + PinDefinition( + PinType.Truth, + PinDirection.Output, + PinPosition.right2(2) + ) + + val hitPos: PinDefinition = + PinDefinition( + PinType.Vector, + PinDirection.Output, + PinPosition.right2(1) + ) + + val hitObj: PinDefinition = + PinDefinition( + PinType.Object, + PinDirection.Output, + PinPosition.right2(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + from, + to, + hit, + hitPos, + hitObj + ) + } + + case object GetSize extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector( + Obj.getSize0, + Obj.getSize1, + Obj.getSize2, + Obj.getSize3 + ) + + val obj: PinDefinition = + PinDefinition( + PinType.Object, + PinDirection.Input, + PinPosition.left(1) + ) + + val min: PinDefinition = + PinDefinition( + PinType.Vector, + PinDirection.Output, + PinPosition.right2(1) + ) + + val max: PinDefinition = + PinDefinition( + PinType.Vector, + PinDirection.Output, + PinPosition.right2(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + obj, + min, + max + ) + } + + case object SetVisible extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector( + Obj.setVisible0, + Obj.setVisible1, + Obj.setVisible2, + Obj.setVisible3 + ) + + val after: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.bottom(0) + ) + + val before: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Output, + PinPosition.top2(0) + ) + + val obj: PinDefinition = + PinDefinition( + PinType.Object, + PinDirection.Input, + PinPosition.left(1) + ) + + val visible: PinDefinition = + PinDefinition( + PinType.Truth, + PinDirection.Input, + PinPosition.left(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + after, + before, + obj, + visible + ) + } + + case object CreateObject extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector( + Obj.createObject0, + Obj.createObject1, + Obj.createObject2, + Obj.createObject3 + ) + + val after: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.bottom(0) + ) + + val before: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Output, + PinPosition.top2(0) + ) + + val original: PinDefinition = + PinDefinition( + PinType.Object, + PinDirection.Input, + PinPosition.left(1) + ) + + val copy: PinDefinition = + PinDefinition( + PinType.Object, + PinDirection.Output, + PinPosition.right2(1) + ) + + override val pins: Vector[PinDefinition] = Vector( + after, + before, + original, + copy + ) + } + + case object DestroyObject extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector( + Obj.destroyObject0, + Obj.destroyObject1, + Obj.destroyObject2, + Obj.destroyObject3 + ) + + val after: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.bottom(0) + ) + + val before: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Output, + PinPosition.top2(0) + ) + + val obj: PinDefinition = + PinDefinition( + PinType.Object, + PinDirection.Input, + PinPosition.left(1) + ) + + override val pins: Vector[PinDefinition] = Vector( + after, + before, + obj + ) + } + + case object PlaySound extends BuiltIn[SoundOptions] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector( + Obj.playSound0, + Obj.playSound1, + Obj.playSound2, + Obj.playSound3 + ) + + val after: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.bottom(0) + ) + + val before: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Output, + PinPosition.top2(0) + ) + + val volume: PinDefinition = + PinDefinition( + PinType.Number, + PinDirection.Input, + PinPosition.left(1) + ) + + val pitch: PinDefinition = + PinDefinition( + PinType.Number, + PinDirection.Input, + PinPosition.left(0) + ) + + val channel: PinDefinition = + PinDefinition( + PinType.Number, + PinDirection.Output, + PinPosition.right2(1) + ) + + override val pins: Vector[PinDefinition] = Vector( + after, + before, + volume, + pitch, + channel + ) + } + + case object StopSound extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector( + Obj.stopSound0, + Obj.stopSound1, + Obj.stopSound2, + Obj.stopSound3 + ) + + val after: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.bottom(0) + ) + + val before: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Output, + PinPosition.top2(0) + ) + + val channel: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.left(1) + ) + + override val pins: Vector[PinDefinition] = Vector( + after, + before, + channel + ) + } + + case object If extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector( + Obj.if0, + Obj.if1, + Obj.if2, + Obj.if3 + ) + + val after: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.bottom(0) + ) + + val before: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Output, + PinPosition.top2(0) + ) + + val condition: PinDefinition = + PinDefinition( + PinType.Truth, + PinDirection.Input, + PinPosition.left(1) + ) + + val ifTrue: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.right2(1) + ) + + val ifFalse: PinDefinition = + PinDefinition( + PinType.Pull, + PinDirection.Input, + PinPosition.right2(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + after, + before, + condition, + ifTrue, + ifFalse + ) + } + + case object AddNumbers extends BuiltIn[Unit] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 2 + override val ids: Vector[Obj] = Vector( + Obj.addNumbers0, + Obj.addNumbers1, + Obj.addNumbers2, + Obj.addNumbers3 + ) + + val input1: PinDefinition = + PinDefinition( + PinType.Number, + PinDirection.Input, + PinPosition.left(1) + ) + + val input2: PinDefinition = + PinDefinition( + PinType.Number, + PinDirection.Input, + PinPosition.left(0) + ) + + val output: PinDefinition = + PinDefinition( + PinType.Number, + PinDirection.Output, + PinPosition.right2(1) + ) + + override val pins: Vector[PinDefinition] = Vector( + input1, + input2, + output + ) + } + + case object NumberValue extends BuiltIn[Float] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector( + Obj.number0, + Obj.number1 + ) + + val output: PinDefinition = + PinDefinition( + PinType.Number, + PinDirection.Output, + PinPosition.right2(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + output + ) + } + + case object GetNumber extends BuiltIn[String] { + override val width: Int = 2 + override val height: Int = 1 + override val depth: Int = 1 + override val ids: Vector[Obj] = Vector( + Obj.getNumber0, + Obj.getNumber1 + ) + + val output: PinDefinition = + PinDefinition( + PinType.Pointer(PinType.Number), + PinDirection.Output, + PinPosition.right2(0) + ) + + override val pins: Vector[PinDefinition] = Vector( + output + ) + } + +} diff --git a/graph/src/main/scala/tf/bug/fancadegraph/Level.scala b/graph/src/main/scala/tf/bug/fancadegraph/Level.scala new file mode 100644 index 0000000..8ae44b4 --- /dev/null +++ b/graph/src/main/scala/tf/bug/fancadegraph/Level.scala @@ -0,0 +1,87 @@ +package tf.bug.fancadegraph + +import cats.data._ +import scalax.collection.Graph +import scalax.collection.GraphEdge.DiHyperEdge +import tf.bug.{fancadescodec => fansc} + +case class Level( + blocks: Set[Block[_]], + wires: Graph[Pin, DiHyperEdge] +) + +object Level { + + def validate(level: Level): Chain[String] = { + ??? + } + + def encode(level: Level): tf.bug.fancadescodec.Entry = { + val boundary = level.blocks.foldLeft(fansc.Boundary(0, 0, 0)) { + case (fansc.Boundary(lr, du, nf), block) => + val tlr = block.position.lr + block.definition.width + val tdu = block.position.du + block.definition.height + val tnf = block.position.nf + block.definition.depth + fansc.Boundary(lr.max(tlr), du.max(tdu), nf.max(tnf)) + } + val objs: Vector[fansc.Obj] = { + val initialVector = Vector.fill(boundary.sizeNF, boundary.sizeDU, boundary.sizeLR)(fansc.Obj.empty) + level.blocks.foldLeft(initialVector) { + case (ew, nb) => + val fansc.Position(sx, sy, sz) = nb.position + (0 until nb.definition.depth).foldLeft(ew) { + case (zw, z) => + (0 until nb.definition.height).foldLeft(zw) { + case (yw, y) => + (0 until nb.definition.width).foldLeft(yw) { + case (xw, x) => + val objInd = x + (y * nb.definition.width) + (z * nb.definition.width * nb.definition.height) + xw.updated(sz + z, xw(sz + z).updated(sy + y, xw(sz + z)(sy + y).updated(sx + x, nb.definition.ids(objInd)))) + } + } + } + } + }.flatten.flatten + val metadatas = level.blocks.toVector.map(_.metadata).flatten + val wires = level.wires.edges.toVector.map(_.edge).flatMap { + edge => + val from = edge.nodeSeq.head + edge.nodeSeq.tail.map { to => + if(from.definition.dataType == PinType.Pull) { + fansc.Wire( + to.owner.position, + from.owner.position, + to.definition.voxel, + from.definition.voxel + ) + } else { + fansc.Wire( + from.owner.position, + to.owner.position, + from.definition.voxel, + to.definition.voxel + ) + } + } + } + fansc.Entry( + Some(0x03), // TODO + "hello", // TODO + None, // TODO + Some(fansc.World( + boundary, + objs + )), + Some(metadatas), + Some(wires) + ) + } + + def toScodec(ours: Level): ValidatedNec[String, tf.bug.fancadescodec.Entry] = { + NonEmptyChain.fromChain(validate(ours)) + .fold[ValidatedNec[String, tf.bug.fancadescodec.Entry]]( + Validated.Valid(encode(ours)) + )(Validated.Invalid(_)) + } + +} diff --git a/graph/src/main/scala/tf/bug/fancadegraph/Main.scala b/graph/src/main/scala/tf/bug/fancadegraph/Main.scala new file mode 100644 index 0000000..cfd0e07 --- /dev/null +++ b/graph/src/main/scala/tf/bug/fancadegraph/Main.scala @@ -0,0 +1,47 @@ +package tf.bug.fancadegraph + +import cats.effect.{Blocker, ExitCode, IO, IOApp} +import cats.implicits._ +import fs2._ +import java.nio.file.{Paths, StandardOpenOption} +import scalax.collection.Graph +import scalax.collection.GraphEdge.DiHyperEdge +import scodec.stream.StreamEncoder +import tf.bug.fancadescodec.{Cartridge, Codecs, Position} + +object Main extends IOApp { + + override def run(args: List[String]): IO[ExitCode] = { + val winBlock = Block(Position(0, 0, 0), BlockDefinition.Win) + val loseBlock = Block(Position(0, 0, 3), BlockDefinition.Lose) + val loseAfter = Pin(loseBlock, BlockDefinition.Lose.after) + val winBefore = Pin(winBlock, BlockDefinition.Win.before) + val level = Level( + Set( + winBlock, + loseBlock + ), + Graph[Pin, DiHyperEdge]( + DiHyperEdge(winBefore, loseAfter) + ) + ) + + val output = Paths.get("""C:\Users\aprim\Documents\FancadeLevels\GraphTest""") + val cart = Cartridge( + "Graph Test", + "Raymond AC", + "Test of Fancade Graph Library", + Vector( + Level.encode(level) + ) + ) + + (for { + blocker <- Stream.resource(Blocker[IO]) + result <- Stream.emit[IO, Cartridge](cart) + .through(StreamEncoder.once(Codecs.encCartridge).toPipeByte[IO]) + .through(io.file.writeAll(output, blocker, Seq(StandardOpenOption.CREATE_NEW))) + } yield result).compile.drain.as(ExitCode.Success) + } + +} diff --git a/graph/src/main/scala/tf/bug/fancadegraph/Pin.scala b/graph/src/main/scala/tf/bug/fancadegraph/Pin.scala new file mode 100644 index 0000000..65a8a68 --- /dev/null +++ b/graph/src/main/scala/tf/bug/fancadegraph/Pin.scala @@ -0,0 +1,6 @@ +package tf.bug.fancadegraph + +case class Pin( + owner: Block[_], + definition: PinDefinition +) diff --git a/graph/src/main/scala/tf/bug/fancadegraph/PinDefinition.scala b/graph/src/main/scala/tf/bug/fancadegraph/PinDefinition.scala new file mode 100644 index 0000000..497bbbd --- /dev/null +++ b/graph/src/main/scala/tf/bug/fancadegraph/PinDefinition.scala @@ -0,0 +1,47 @@ +package tf.bug.fancadegraph + +import tf.bug.fancadescodec.Position + +case class PinDefinition( + dataType: PinType, + direction: PinDirection, + voxel: Position +) + +sealed trait PinType +object PinType { + + case object Number extends PinType + case object Object extends PinType + case object Vector extends PinType + case object Rotation extends PinType + case object Truth extends PinType + case object Constraint extends PinType + case object Pull extends PinType + + case class Pointer(of: PinType) extends PinType + +} + +sealed trait PinDirection +object PinDirection { + + case object Input extends PinDirection + case object Output extends PinDirection + +} + +object PinPosition { + + def bottom(n: Int): Position = Position(3 + (8 * n), 1, 0) + def top(depth: Int)(n: Int): Position = Position(3 + (8 * n), 1, 6 + (8 * (depth - 1))) + def left(n: Int): Position = Position(0, 1, 3 + (8 * n)) + def right(width: Int)(n: Int): Position = Position(6 + (8 * (width - 1)), 1, 3 + (8 * n)) + + val top1: Int => Position = top(1) + val top2: Int => Position = top(2) + val top3: Int => Position = top(3) + val top4: Int => Position = top(4) + val right2: Int => Position = right(2) + +} diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..f0390ca --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1,2 @@ +addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.11") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10") diff --git a/scodec/src/main/scala/tf/bug/fancadescodec/Boundary.scala b/scodec/src/main/scala/tf/bug/fancadescodec/Boundary.scala new file mode 100644 index 0000000..54a2f46 --- /dev/null +++ b/scodec/src/main/scala/tf/bug/fancadescodec/Boundary.scala @@ -0,0 +1,13 @@ +package tf.bug.fancadescodec + +case class Position( + lr: Int, + du: Int, + nf: Int + ) + +case class Boundary( + sizeLR: Int, + sizeDU: Int, + sizeNF: Int + ) diff --git a/scodec/src/main/scala/tf/bug/fancadescodec/Cartridge.scala b/scodec/src/main/scala/tf/bug/fancadescodec/Cartridge.scala new file mode 100644 index 0000000..c51f61f --- /dev/null +++ b/scodec/src/main/scala/tf/bug/fancadescodec/Cartridge.scala @@ -0,0 +1,8 @@ +package tf.bug.fancadescodec + +case class Cartridge( + title: String, + author: String, + description: String, + entries: Vector[Entry] + ) diff --git a/scodec/src/main/scala/tf/bug/fancadescodec/Codecs.scala b/scodec/src/main/scala/tf/bug/fancadescodec/Codecs.scala new file mode 100644 index 0000000..145b203 --- /dev/null +++ b/scodec/src/main/scala/tf/bug/fancadescodec/Codecs.scala @@ -0,0 +1,159 @@ +package tf.bug.fancadescodec + +import scodec._ +import scodec.bits.{BitVector, ByteVector} +import scodec.codecs._ + +object Codecs { + + lazy val low: Codec[Unit] = constant(BitVector.low(1L)) + lazy val high: Codec[Unit] = constant(BitVector.high(1L)) + + def optionC[A](b: Boolean, c: Codec[A]): Codec[Option[A]] = + optional(provide(b), c) + + lazy val fancadeString: Codec[String] = variableSizeBytes(uint8L, utf8) + + lazy val cartridgeMagic: Codec[Unit] = constant(ByteVector(0x1B, 0x00)) + lazy val entriesMagic: Codec[Unit] = constant(ByteVector(0x2C, 0x02)) + + lazy val cartridge: Codec[Cartridge] = + ( + cartridgeMagic ~> + fancadeString :: + fancadeString :: + fancadeString :: + (entriesMagic ~> vectorOfN(uint16L, entry)).hlist + ).as[Cartridge] + + lazy val boundary: Codec[Boundary] = + (uint16L :: uint16L :: uint16L).as[Boundary] + + lazy val position: Codec[Position] = + (uint16L :: uint16L :: uint16L).as[Position] + + lazy val face: Codec[Vector[Int]] = fixedSizeBytes(8L * 8L * 8L, vector(uint8L)) + lazy val faces: Codec[Faces] = + (face :: face :: face :: face :: face :: face).as[Faces] + + lazy val obj: Codec[Obj] = uint16L.xmap(Obj(_), _.id) + + lazy val world: Codec[World] = boundary.flatPrepend { b => + vectorOfN(provide(b.sizeLR * b.sizeDU * b.sizeNF), obj).hlist + }.as[World] + + lazy val wires: Codec[Vector[Wire]] = vectorOfN(uint16L, wire) + lazy val wire: Codec[Wire] = + (position :: position :: position :: position.hlist).as[Wire] + + lazy val metadatas: Codec[Vector[Metadata]] = vectorOfN(uint16L, metadata) + lazy val metadata: Codec[Metadata] = + discriminated[Metadata].by(uint16L) + .subcaseP(0x0100) { + case psl: Metadata.PlaySoundLoop => psl + } (metadataPlaySoundLoop) + .subcaseP(0x0201) { + case pss: Metadata.PlaySoundSample => pss + } (metadataPlaySoundSample) + .subcaseP(0x0400) { + case num: Metadata.Number => num + } (metadataNumber) + .subcaseP(0x0500) { + case triple: Metadata.Triple => triple + } (metadataTriple) + .subcaseP(0x0600) { + case text: Metadata.Text => text + } (metadataText) + .subcaseP(0x0700) { + case terminal: Metadata.Terminal => terminal + } (metadataTerminal) + + lazy val metadataPlaySoundLoop: Codec[Metadata.PlaySoundLoop] = + (position :: bool(8).hlist).as[Metadata.PlaySoundLoop] + lazy val metadataPlaySoundSample: Codec[Metadata.PlaySoundSample] = + (position :: sample.hlist).as[Metadata.PlaySoundSample] + lazy val metadataNumber: Codec[Metadata.Number] = + (position :: floatL.hlist).as[Metadata.Number] + lazy val metadataTriple: Codec[Metadata.Triple] = + (position :: floatL :: floatL :: floatL.hlist).as[Metadata.Triple] + lazy val metadataText: Codec[Metadata.Text] = + (position :: fancadeString.hlist).as[Metadata.Text] + lazy val metadataTerminal: Codec[Metadata.Terminal] = + (position :: fancadeString.hlist).as[Metadata.Terminal] + + lazy val sample: Codec[Metadata.Sample] = + discriminated[Metadata.Sample].by(uint16L) + .subcaseP(0) { + case chirp @ Metadata.Sample.Chirp => chirp + } (provide(Metadata.Sample.Chirp)) + .subcaseP(1) { + case scrape @ Metadata.Sample.Scrape => scrape + } (provide(Metadata.Sample.Scrape)) + .subcaseP(2) { + case squeek @ Metadata.Sample.Squeek => squeek + } (provide(Metadata.Sample.Squeek)) + .subcaseP(3) { + case engine @ Metadata.Sample.Engine => engine + } (provide(Metadata.Sample.Engine)) + .subcaseP(4) { + case button @ Metadata.Sample.Button => button + } (provide(Metadata.Sample.Button)) + .subcaseP(5) { + case ball @ Metadata.Sample.Ball => ball + } (provide(Metadata.Sample.Ball)) + .subcaseP(6) { + case piano @ Metadata.Sample.Piano => piano + } (provide(Metadata.Sample.Piano)) + .subcaseP(7) { + case marimba @ Metadata.Sample.Marimba => marimba + } (provide(Metadata.Sample.Marimba)) + .subcaseP(8) { + case pad @ Metadata.Sample.Pad => pad + } (provide(Metadata.Sample.Pad)) + .subcaseP(9) { + case beep @ Metadata.Sample.Beep => beep + } (provide(Metadata.Sample.Beep)) + .subcaseP(10) { + case plop @ Metadata.Sample.Plop => plop + } (provide(Metadata.Sample.Plop)) + .subcaseP(11) { + case flop @ Metadata.Sample.Flop => flop + } (provide(Metadata.Sample.Flop)) + .subcaseP(12) { + case splash @ Metadata.Sample.Splash => splash + } (provide(Metadata.Sample.Splash)) + .subcaseP(13) { + case boom @ Metadata.Sample.Boom => boom + } (provide(Metadata.Sample.Boom)) + .subcaseP(14) { + case hit @ Metadata.Sample.Hit => hit + } (provide(Metadata.Sample.Hit)) + .subcaseP(15) { + case clang @ Metadata.Sample.Clang => clang + } (provide(Metadata.Sample.Clang)) + .subcaseP(16) { + case jump @ Metadata.Sample.Jump => jump + } (provide(Metadata.Sample.Jump)) + + lazy val entry: Codec[Entry] = + ( low ~ low ~ low ~ low ~ + bool ~ bool ~ bool ~ bool ~ + low ~ low ~ low ~ bool ~ + high ~ low ~ low ~ low).consume { + case (_ ~ _ ~ _ ~ _ ~ isFaces ~ isWorld ~ isMetadata ~ isWires ~ _ ~ _ ~ _ ~ isVisible ~ _ ~ _ ~ _ ~ _) => + ( + optionC(isVisible, uint8L) :: + fancadeString :: + optionC(isFaces, faces) :: + optionC(isWorld, world) :: + optionC(isMetadata, metadatas) :: + optionC(isWires, wires).hlist + ).as[Entry] + } { + case Entry(vFlags, _, f, wd, mt, wr) => + (() ~ () ~ () ~ () ~ f.isDefined ~ wd.isDefined ~ mt.isDefined ~ wr.isDefined ~ () ~ () ~ () ~ vFlags.isDefined ~ () ~ () ~ () ~ ()) + } + + lazy val encCartridge: Codec[Cartridge] = zlib(cartridge) + +} diff --git a/scodec/src/main/scala/tf/bug/fancadescodec/Entry.scala b/scodec/src/main/scala/tf/bug/fancadescodec/Entry.scala new file mode 100644 index 0000000..44abb96 --- /dev/null +++ b/scodec/src/main/scala/tf/bug/fancadescodec/Entry.scala @@ -0,0 +1,10 @@ +package tf.bug.fancadescodec + +case class Entry( + visibilityFlags: Option[Int], + name: String, + faces: Option[Faces], + world: Option[World], + metadatas: Option[Vector[Metadata]], + wires: Option[Vector[Wire]] +) diff --git a/scodec/src/main/scala/tf/bug/fancadescodec/Faces.scala b/scodec/src/main/scala/tf/bug/fancadescodec/Faces.scala new file mode 100644 index 0000000..34fcdea --- /dev/null +++ b/scodec/src/main/scala/tf/bug/fancadescodec/Faces.scala @@ -0,0 +1,10 @@ +package tf.bug.fancadescodec + +case class Faces( + faceRight: Vector[Int], + faceLeft: Vector[Int], + faceUp: Vector[Int], + faceDown: Vector[Int], + faceFar: Vector[Int], + faceNear: Vector[Int] + ) diff --git a/scodec/src/main/scala/tf/bug/fancadescodec/Main.scala b/scodec/src/main/scala/tf/bug/fancadescodec/Main.scala new file mode 100644 index 0000000..c86e285 --- /dev/null +++ b/scodec/src/main/scala/tf/bug/fancadescodec/Main.scala @@ -0,0 +1,125 @@ +package tf.bug.fancadescodec + +import cats.effect._ +import cats.implicits._ +import fs2._ +import java.nio.file.Paths +import scodec.stream.{StreamDecoder, StreamEncoder} + +object Main extends IOApp { + + override def run(args: List[String]): IO[ExitCode] = { + (Stream.resource(Blocker[IO]) >>= write[IO]).compile.drain.as(ExitCode.Success) + } + + def read[F[_] : RaiseThrowable : Sync : ContextShift](blocker: Blocker): Stream[F, Unit] = { + val input = Paths.get("""C:\Users\aprim\Documents\FancadeLevels\MetaWires""") + io.file.readAll[F](input, blocker, 1024) + .through(StreamDecoder.once(Codecs.encCartridge).toPipeByte) + .evalMap(c => Sync[F].delay(println(c))) + } + + def write[F[_] : RaiseThrowable : Sync : ContextShift](blocker: Blocker): Stream[F, Unit] = { + val output = Paths.get("""C:\Users\aprim\Documents\FancadeLevels\AllTheSamples""") + + val outputCartridge = Cartridge( + "AllTheSamples", + "rayc", + "A Fancade game", + Vector( + Entry( + Some(0x03), + "New Level", + None, + Some( + World( + Boundary(2, 17, 2), + Vector.fill(17)(Vector(Obj.playSound0, Obj.playSound1)).flatten ++ Vector.fill(17)(Vector(Obj.playSound2, Obj.playSound3)).flatten + ) + ), + Some( + (0 until 17).map { case h => + Metadata.PlaySoundSample( + Position(0, h, 0), + h match { + case 0 => Metadata.Sample.Chirp + case 1 => Metadata.Sample.Scrape + case 2 => Metadata.Sample.Squeek + case 3 => Metadata.Sample.Engine + case 4 => Metadata.Sample.Button + case 5 => Metadata.Sample.Ball + case 6 => Metadata.Sample.Piano + case 7 => Metadata.Sample.Marimba + case 8 => Metadata.Sample.Pad + case 9 => Metadata.Sample.Beep + case 10 => Metadata.Sample.Plop + case 11 => Metadata.Sample.Flop + case 12 => Metadata.Sample.Splash + case 13 => Metadata.Sample.Boom + case 14 => Metadata.Sample.Hit + case 15 => Metadata.Sample.Clang + case 16 => Metadata.Sample.Jump + } + ) + }.toVector + ), + None + ) + ) + ) + + Stream.emit[F, Cartridge](outputCartridge) + .through(StreamEncoder.once(Codecs.encCartridge).toPipeByte) + .through(io.file.writeAll[F](output, blocker)) + } + + val paletteMap: ((Int, Int, Int)) => String = Map( + (238, 165, 162) -> "Brown 1", + (255, 255, 255) -> "Tan 1", + (192, 152, 255) -> "Purple 1", + (255, 203, 252) -> "Pink 1", + (255, 170, 170) -> "Red 1", + (255, 185, 142) -> "Orange 1", + (255, 255, 134) -> "Yellow 1", + (194, 255, 118) -> "Green 1", + (0, 205, 255) -> "Blue 1", + (255, 255, 255) -> "White 1", + (109, 111, 126) -> "Black 1", + (203, 117, 137) -> "Brown 2", + (255, 231, 207) -> "Tan 2", + (153, 122, 234) -> "Purple 2", + (255, 164, 224) -> "Pink 2", + (255, 81, 115) -> "Red 2", + (255, 123, 91) -> "Orange 2", + (255, 234, 0) -> "Yellow 2", + (72, 208, 85) -> "Green 2", + (0, 154, 255) -> "Blue 2", + (206, 208, 216) -> "White 2", + (68, 68, 83) -> "Black 2", + (156, 90, 100) -> "Brown 3", + (255, 195, 180) -> "Tan 3", + (113, 91, 173) -> "Purple 3", + (255, 123, 186) -> "Pink 3", + (205, 59, 86) -> "Red 3", + (215, 89, 71) -> "Orange 3", + (246, 185, 0) -> "Yellow 3", + (0, 147, 82) -> "Green 3", + (0, 117, 237) -> "Blue 3", + (156, 158, 173) -> "White 3", + (31, 31, 41) -> "Black 3", + ).withDefaultValue("Transparent") + val indexMap: String => Int = List( + "Black", + "White", + "Brown", + "Tan", + "Red", + "Orange", + "Yellow", + "Green", + "Blue", + "Purple", + "Pink" + ).flatMap(n => List(s"$n 3", s"$n 2", s"$n 1")).zipWithIndex.map { case (n, i) => (n, i + 1) }.toMap.withDefaultValue(0) + +} diff --git a/scodec/src/main/scala/tf/bug/fancadescodec/Metadata.scala b/scodec/src/main/scala/tf/bug/fancadescodec/Metadata.scala new file mode 100644 index 0000000..ad760aa --- /dev/null +++ b/scodec/src/main/scala/tf/bug/fancadescodec/Metadata.scala @@ -0,0 +1,60 @@ +package tf.bug.fancadescodec + +sealed trait Metadata + +object Metadata { + + case class PlaySoundLoop( + block: Position, + doLoop: Boolean + ) extends Metadata + + case class PlaySoundSample( + block: Position, + sample: Sample + ) extends Metadata + + sealed trait Sample + object Sample { + case object Chirp extends Sample + case object Scrape extends Sample + case object Squeek extends Sample + case object Engine extends Sample + case object Button extends Sample + case object Ball extends Sample + case object Piano extends Sample + case object Marimba extends Sample + case object Pad extends Sample + case object Beep extends Sample + case object Plop extends Sample + case object Flop extends Sample + case object Splash extends Sample + case object Boom extends Sample + case object Hit extends Sample + case object Clang extends Sample + case object Jump extends Sample + } + + case class Number( + block: Position, + value: Float + ) extends Metadata + + case class Text( + block: Position, + name: String + ) extends Metadata + + case class Triple( + block: Position, + x: Float, + y: Float, + z: Float + ) extends Metadata + + case class Terminal( + voxel: Position, + name: String + ) extends Metadata + +} \ No newline at end of file diff --git a/scodec/src/main/scala/tf/bug/fancadescodec/Obj.scala b/scodec/src/main/scala/tf/bug/fancadescodec/Obj.scala new file mode 100644 index 0000000..90318ee --- /dev/null +++ b/scodec/src/main/scala/tf/bug/fancadescodec/Obj.scala @@ -0,0 +1,651 @@ +package tf.bug.fancadescodec + +case class Obj( + id: Int +) extends AnyVal + +object Obj { + + final val empty = Obj(0) + + final val bricks = Obj(2) + final val grass = Obj(3) + final val grassDotty = Obj(4) + final val dirt = Obj(5) + final val dirtDotty = Obj(493) + final val dirtSlab = Obj(384) + final val foliageSlab = Obj(499) + final val foliageDotty = Obj(496) + final val foliageTop = Obj(497) + final val foliage = Obj(495) + final val foliageBottom = Obj(498) + final val stone = Obj(501) + final val stoneDotty = Obj(502) + final val stoneSlab = Obj(505) + final val stoneTop = Obj(503) + final val stoneBottom = Obj(504) + final val stoneBlock = Obj(1) + final val stonePillar = Obj(506) + final val stoneHalf = Obj(507) + final val slate = Obj(547) + final val slateDotty = Obj(548) + final val slateNE = Obj(549) + final val slateNW = Obj(550) + final val slateSE = Obj(551) + final val slateSW = Obj(552) + final val slateTop = Obj(553) + final val slateBottom = Obj(554) + final val woodLR = Obj(6) + final val woodDU = Obj(8) + final val woodNF = Obj(7) + final val woodLowLR = Obj(508) + final val woodLowNF = Obj(509) + final val woodHighLR = Obj(510) + final val woodHighNF = Obj(511) + final val steel = Obj(385) + final val box = Obj(388) + final val sphere = Obj(546) + final val physicsBox = Obj(425) + final val physicsSphere = Obj(426) + final val passThrough = Obj(448) + final val scriptBlock = Obj(545) + final val flowers = Obj(494) + final val particle = Obj(555) + final val marker = Obj(536) + final val shrub = Obj(500) + final val archLower = Obj(386) + final val archHigher = Obj(387) + final val stickLR = Obj(512) + final val stickDU = Obj(513) + final val stickNF = Obj(514) + final val stickRF = Obj(515) + final val stickLF = Obj(516) + final val stickLN = Obj(517) + final val stickRN = Obj(518) + final val stickRU = Obj(519) + final val stickUF = Obj(520) + final val stickLU = Obj(521) + final val stickUN = Obj(522) + final val stickRD = Obj(523) + final val stickDF = Obj(524) + final val stickLD = Obj(525) + final val stickDN = Obj(526) + + final val win0 = Obj(252) + final val win1 = Obj(253) + final val win2 = Obj(254) + final val win3 = Obj(255) + + final val lose0 = Obj(256) + final val lose1 = Obj(257) + final val lose2 = Obj(258) + final val lose3 = Obj(259) + + final val setScore0 = Obj(260) + final val setScore1 = Obj(261) + final val setScore2 = Obj(262) + final val setScore3 = Obj(263) + + final val setCamera0 = Obj(268) + final val setCamera1 = Obj(269) + final val setCamera2 = Obj(270) + final val setCamera3 = Obj(271) + final val setCamera4 = Obj(272) + final val setCamera5 = Obj(273) + + final val setLight0 = Obj(274) + final val setLight1 = Obj(275) + final val setLight2 = Obj(276) + final val setLight3 = Obj(277) + + final val screenSize0 = Obj(220) + final val screenSize1 = Obj(221) + final val screenSize2 = Obj(222) + final val screenSize3 = Obj(223) + + final val accelerometer0 = Obj(224) + final val accelerometer1 = Obj(225) + final val accelerometer2 = Obj(226) + final val accelerometer3 = Obj(227) + + final val getPosition0 = Obj(278) + final val getPosition1 = Obj(279) + final val getPosition2 = Obj(280) + final val getPosition3 = Obj(281) + + final val setPosition0 = Obj(282) + final val setPosition1 = Obj(283) + final val setPosition2 = Obj(284) + final val setPosition3 = Obj(285) + final val setPosition4 = Obj(286) + final val setPosition5 = Obj(287) + + final val raycast0 = Obj(228) + final val raycast1 = Obj(229) + final val raycast2 = Obj(230) + final val raycast3 = Obj(231) + final val raycast4 = Obj(232) + final val raycast5 = Obj(233) + + final val getSize0 = Obj(489) + final val getSize1 = Obj(490) + final val getSize2 = Obj(491) + final val getSize3 = Obj(492) + + final val setVisible0 = Obj(306) + final val setVisible1 = Obj(307) + final val setVisible2 = Obj(308) + final val setVisible3 = Obj(309) + + final val createObject0 = Obj(316) + final val createObject1 = Obj(317) + final val createObject2 = Obj(318) + final val createObject3 = Obj(319) + + final val destroyObject0 = Obj(320) + final val destroyObject1 = Obj(321) + final val destroyObject2 = Obj(322) + final val destroyObject3 = Obj(323) + + final val playSound0 = Obj(264) + final val playSound1 = Obj(265) + final val playSound2 = Obj(266) + final val playSound3 = Obj(267) + + final val stopSound0 = Obj(397) + final val stopSound1 = Obj(398) + final val stopSound2 = Obj(399) + final val stopSound3 = Obj(400) + + final val volumePitch0 = Obj(391) + final val volumePitch1 = Obj(392) + final val volumePitch2 = Obj(393) + final val volumePitch3 = Obj(394) + final val volumePitch4 = Obj(395) + final val volumePitch5 = Obj(396) + + final val addForce0 = Obj(298) + final val addForce1 = Obj(299) + final val addForce2 = Obj(300) + final val addForce3 = Obj(301) + final val addForce4 = Obj(302) + final val addForce5 = Obj(303) + final val addForce6 = Obj(304) + final val addForce7 = Obj(305) + + final val getVelocity0 = Obj(288) + final val getVelocity1 = Obj(289) + final val getVelocity2 = Obj(290) + final val getVelocity3 = Obj(291) + + final val setVelocity0 = Obj(292) + final val setVelocity1 = Obj(293) + final val setVelocity2 = Obj(294) + final val setVelocity3 = Obj(295) + final val setVelocity4 = Obj(296) + final val setVelocity5 = Obj(297) + + final val setLocked0 = Obj(310) + final val setLocked1 = Obj(311) + final val setLocked2 = Obj(312) + final val setLocked3 = Obj(313) + final val setLocked4 = Obj(314) + final val setLocked5 = Obj(315) + + final val setMass0 = Obj(328) + final val setMass1 = Obj(329) + final val setMass2 = Obj(330) + final val setMass3 = Obj(331) + + final val setFriction0 = Obj(332) + final val setFriction1 = Obj(333) + final val setFriction2 = Obj(334) + final val setFriction3 = Obj(335) + + final val setBounciness0 = Obj(336) + final val setBounciness1 = Obj(337) + final val setBounciness2 = Obj(338) + final val setBounciness3 = Obj(339) + + final val setGravity0 = Obj(324) + final val setGravity1 = Obj(325) + final val setGravity2 = Obj(326) + final val setGravity3 = Obj(327) + + final val addConstraint0 = Obj(340) + final val addConstraint1 = Obj(341) + final val addConstraint2 = Obj(342) + final val addConstraint3 = Obj(343) + final val addConstraint4 = Obj(344) + final val addConstraint5 = Obj(345) + + final val linearLimits0 = Obj(346) + final val linearLimits1 = Obj(347) + final val linearLimits2 = Obj(348) + final val linearLimits3 = Obj(349) + final val linearLimits4 = Obj(350) + final val linearLimits5 = Obj(351) + + final val angularLimits0 = Obj(352) + final val angularLimits1 = Obj(353) + final val angularLimits2 = Obj(354) + final val angularLimits3 = Obj(355) + final val angularLimits4 = Obj(356) + final val angularLimits5 = Obj(357) + + final val linearSpring0 = Obj(358) + final val linearSpring1 = Obj(359) + final val linearSpring2 = Obj(360) + final val linearSpring3 = Obj(361) + final val linearSpring4 = Obj(362) + final val linearSpring5 = Obj(363) + + final val angularSpring0 = Obj(364) + final val angularSpring1 = Obj(365) + final val angularSpring2 = Obj(366) + final val angularSpring3 = Obj(367) + final val angularSpring4 = Obj(368) + final val angularSpring5 = Obj(369) + + final val linearMotor0 = Obj(370) + final val linearMotor1 = Obj(371) + final val linearMotor2 = Obj(372) + final val linearMotor3 = Obj(373) + final val linearMotor4 = Obj(374) + final val linearMotor5 = Obj(375) + + final val angularMotor0 = Obj(376) + final val angularMotor1 = Obj(377) + final val angularMotor2 = Obj(378) + final val angularMotor3 = Obj(379) + final val angularMotor4 = Obj(380) + final val angularMotor5 = Obj(381) + + final val if0 = Obj(234) + final val if1 = Obj(235) + final val if2 = Obj(236) + final val if3 = Obj(237) + + final val playSensor0 = Obj(238) + final val playSensor1 = Obj(239) + final val playSensor2 = Obj(240) + final val playSensor3 = Obj(241) + + final val boxArtSensor0 = Obj(409) + final val boxArtSensor1 = Obj(410) + final val boxArtSensor2 = Obj(411) + final val boxArtSensor3 = Obj(412) + + final val touchSensor0 = Obj(242) + final val touchSensor1 = Obj(243) + final val touchSensor2 = Obj(244) + final val touchSensor3 = Obj(245) + final val touchSensor4 = Obj(246) + final val touchSensor5 = Obj(247) + + final val swipeSensor0 = Obj(248) + final val swipeSensor1 = Obj(249) + final val swipeSensor2 = Obj(250) + final val swipeSensor3 = Obj(251) + + final val collision0 = Obj(401) + final val collision1 = Obj(402) + final val collision2 = Obj(403) + final val collision3 = Obj(404) + final val collision4 = Obj(405) + final val collision5 = Obj(406) + + final val negate0 = Obj(90) + final val negate1 = Obj(91) + + final val inverse0 = Obj(440) + final val inverse1 = Obj(441) + + final val addNumbers0 = Obj(92) + final val addNumbers1 = Obj(93) + final val addNumbers2 = Obj(94) + final val addNumbers3 = Obj(95) + + final val addVectors0 = Obj(96) + final val addVectors1 = Obj(97) + final val addVectors2 = Obj(98) + final val addVectors3 = Obj(99) + + final val subtractNumbers0 = Obj(100) + final val subtractNumbers1 = Obj(101) + final val subtractNumbers2 = Obj(102) + final val subtractNumbers3 = Obj(103) + + final val subtractVectors0 = Obj(104) + final val subtractVectors1 = Obj(105) + final val subrtactVectors2 = Obj(106) + final val subtractVectors3 = Obj(107) + + final val multiply0 = Obj(108) + final val multiply1 = Obj(109) + final val multiply2 = Obj(110) + final val multiply3 = Obj(111) + + final val scale0 = Obj(112) + final val scale1 = Obj(113) + final val scale2 = Obj(114) + final val scale3 = Obj(115) + + final val rotate0 = Obj(116) + final val rotate1 = Obj(117) + final val rotate2 = Obj(118) + final val rotate3 = Obj(119) + + final val combine0 = Obj(120) + final val combine1 = Obj(121) + final val combine2 = Obj(122) + final val combine3 = Obj(123) + + final val divide0 = Obj(124) + final val divide1 = Obj(125) + final val divide2 = Obj(126) + final val divide3 = Obj(127) + + final val power0 = Obj(457) + final val power1 = Obj(458) + final val power2 = Obj(459) + final val power3 = Obj(460) + + final val equalNumbers0 = Obj(132) + final val equalNumbers1 = Obj(133) + final val equalNumbers2 = Obj(134) + final val equalNumbers3 = Obj(135) + + final val equalVectors0 = Obj(136) + final val equalVectors1 = Obj(137) + final val equalVectors2 = Obj(138) + final val equalVectors3 = Obj(139) + + final val equalObjects0 = Obj(140) + final val equalObjects1 = Obj(141) + final val equalObjects2 = Obj(142) + final val equalObjects3 = Obj(143) + + final val equalTruths0 = Obj(421) + final val equalTruths1 = Obj(422) + final val equalTruths2 = Obj(423) + final val equalTruths3 = Obj(424) + + final val lessThan0 = Obj(128) + final val lessThan1 = Obj(129) + final val lessThan2 = Obj(130) + final val lessThan3 = Obj(131) + + final val greaterThan0 = Obj(481) + final val greaterThan1 = Obj(482) + final val greaterThan2 = Obj(483) + final val greaterThan3 = Obj(484) + + final val and0 = Obj(146) + final val and1 = Obj(147) + final val and2 = Obj(148) + final val and3 = Obj(149) + + final val or0 = Obj(417) + final val or1 = Obj(418) + final val or2 = Obj(419) + final val or3 = Obj(420) + + final val not0 = Obj(144) + final val not1 = Obj(145) + + final val random0 = Obj(168) + final val random1 = Obj(169) + final val random2 = Obj(170) + final val random3 = Obj(171) + + final val randomSeed0 = Obj(485) + final val randomSeed1 = Obj(486) + final val randomSeed2 = Obj(487) + final val randomSeed3 = Obj(488) + + final val min0 = Obj(176) + final val min1 = Obj(177) + final val min2 = Obj(178) + final val min3 = Obj(179) + + final val max0 = Obj(180) + final val max1 = Obj(181) + final val max2 = Obj(182) + final val max3 = Obj(183) + + final val sin0 = Obj(413) + final val sin1 = Obj(414) + + final val cos0 = Obj(453) + final val cos1 = Obj(454) + + final val round0 = Obj(184) + final val round1 = Obj(185) + + final val floor0 = Obj(186) + final val floor1 = Obj(187) + + final val ceiling0 = Obj(188) + final val ceiling1 = Obj(189) + + final val absolute0 = Obj(455) + final val absolute1 = Obj(456) + + final val modulo0 = Obj(172) + final val modulo1 = Obj(173) + final val modulo2 = Obj(174) + final val modulo3 = Obj(175) + + final val breakVector0 = Obj(156) + final val breakVector1 = Obj(157) + final val breakVector2 = Obj(158) + final val breakVector3 = Obj(159) + final val breakVector4 = Obj(160) + final val breakVector5 = Obj(161) + + final val makeVector0 = Obj(150) + final val makeVector1 = Obj(151) + final val makeVector2 = Obj(152) + final val makeVector3 = Obj(153) + final val makeVector4 = Obj(154) + final val makeVector5 = Obj(155) + + final val breakRotation0 = Obj(442) + final val breakRotation1 = Obj(443) + final val breakRotation2 = Obj(444) + final val breakRotation3 = Obj(445) + final val breakRotation4 = Obj(446) + final val breakRotation5 = Obj(447) + + final val makeRotation0 = Obj(162) + final val makeRotation1 = Obj(163) + final val makeRotation2 = Obj(164) + final val makeRotation3 = Obj(165) + final val makeRotation4 = Obj(166) + final val makeRotation5 = Obj(167) + + final val distance0 = Obj(190) + final val distance1 = Obj(191) + final val distance2 = Obj(192) + final val distance3 = Obj(193) + + final val lerp0 = Obj(194) + final val lerp1 = Obj(195) + final val lerp2 = Obj(196) + final val lerp3 = Obj(197) + final val lerp4 = Obj(198) + final val lerp5 = Obj(199) + + final val axisAngle0 = Obj(200) + final val axisAngle1 = Obj(201) + final val axisAngle2 = Obj(202) + final val axisAngle3 = Obj(203) + + final val screenToWorld0 = Obj(216) + final val screenToWorld1 = Obj(217) + final val screenToWorld2 = Obj(218) + final val screenToWorld3 = Obj(219) + + final val worldToScreen0 = Obj(477) + final val worldToScreen1 = Obj(478) + final val worldToScreen2 = Obj(479) + final val worldToScreen3 = Obj(480) + + final val lineVsPlane0 = Obj(208) + final val lineVsPlane1 = Obj(209) + final val lineVsPlane2 = Obj(210) + final val lineVsPlane3 = Obj(211) + final val lineVsPlane4 = Obj(212) + final val lineVsPlane5 = Obj(213) + final val lineVsPlane6 = Obj(214) + final val lineVsPlane7 = Obj(215) + + final val lookRotation0 = Obj(204) + final val lookRotation1 = Obj(205) + final val lookRotation2 = Obj(206) + final val lookRotation3 = Obj(207) + + final val number0 = Obj(36) + final val number1 = Obj(37) + + final val vector0 = Obj(38) + final val vector1 = Obj(39) + final val vector2 = Obj(40) + final val vector3 = Obj(41) + + final val rotation0 = Obj(42) + final val rotation1 = Obj(43) + final val rotation2 = Obj(44) + final val rotation3 = Obj(45) + + final val true0 = Obj(449) + final val true1 = Obj(450) + + final val false0 = Obj(451) + final val false1 = Obj(452) + + final val comment = Obj(15) + + final val inspectNumber0 = Obj(16) + final val inspectNumber1 = Obj(17) + final val inspectNumber2 = Obj(18) + final val inspectNumber3 = Obj(19) + + final val inspectVector0 = Obj(20) + final val inspectVector1 = Obj(21) + final val inspectVector2 = Obj(22) + final val inspectVector3 = Obj(23) + + final val inspectRotation0 = Obj(24) + final val inspectRotation1 = Obj(25) + final val inspectRotation2 = Obj(26) + final val inspectRotation3 = Obj(27) + + final val inspectTruth0 = Obj(28) + final val inspectTruth1 = Obj(29) + final val inspectTruth2 = Obj(30) + final val inspectTruth3 = Obj(31) + + final val inspectObject0 = Obj(32) + final val inspectObject1 = Obj(33) + final val inspectObject2 = Obj(34) + final val inspectObject3 = Obj(35) + + final val getNumber0 = Obj(46) + final val getNumber1 = Obj(47) + + final val getObject0 = Obj(54) + final val getObject1 = Obj(55) + + final val getVector0 = Obj(48) + final val getVector1 = Obj(49) + + final val getRotation0 = Obj(50) + final val getRotation1 = Obj(51) + + final val getTruth0 = Obj(52) + final val getTruth1 = Obj(53) + + final val getConstraint0 = Obj(56) + final val getConstraint1 = Obj(57) + + final val setNumber0 = Obj(428) + final val setNumber1 = Obj(429) + + final val setObject0 = Obj(436) + final val setObject1 = Obj(437) + + final val setVector0 = Obj(430) + final val setVector1 = Obj(431) + + final val setRotation0 = Obj(432) + final val setRotation1 = Obj(433) + + final val setTruth0 = Obj(434) + final val setTruth1 = Obj(435) + + final val setConstraint0 = Obj(438) + final val setConstraint1 = Obj(439) + + final val setNumberReference0 = Obj(58) + final val setNumberReference1 = Obj(59) + final val setNumberReference2 = Obj(60) + final val setNumberReference3 = Obj(61) + + final val setObjectReference0 = Obj(74) + final val setObjectReference1 = Obj(75) + final val setObjectReference2 = Obj(76) + final val setObjectReference3 = Obj(77) + + final val setVectorReference0 = Obj(62) + final val setVectorReference1 = Obj(63) + final val setVectorReference2 = Obj(64) + final val setVectorReference3 = Obj(65) + + final val setRotationReference0 = Obj(66) + final val setRotationReference1 = Obj(67) + final val setRotationReference2 = Obj(68) + final val setRotationReference3 = Obj(69) + + final val setTruthReference0 = Obj(70) + final val setTruthReference1 = Obj(71) + final val setTruthReference2 = Obj(72) + final val setTruthReference3 = Obj(73) + + final val setConstraintReference0 = Obj(78) + final val setConstraintReference1 = Obj(79) + final val setConstraintReference2 = Obj(80) + final val setConstraintReference3 = Obj(81) + + final val listNumber0 = Obj(82) + final val listNumber1 = Obj(83) + final val listNumber2 = Obj(84) + final val listNumber3 = Obj(85) + + final val listObject0 = Obj(86) + final val listObject1 = Obj(87) + final val listObject2 = Obj(88) + final val listObject3 = Obj(89) + + final val listVector0 = Obj(461) + final val listVector1 = Obj(462) + final val listVector2 = Obj(463) + final val listVector3 = Obj(464) + + final val listRotation0 = Obj(465) + final val listRotation1 = Obj(466) + final val listRotation2 = Obj(467) + final val listRotation3 = Obj(468) + + final val listTruth0 = Obj(469) + final val listTruth1 = Obj(470) + final val listTruth2 = Obj(471) + final val listTruth3 = Obj(472) + + final val listConstraint0 = Obj(473) + final val listConstraint1 = Obj(474) + final val listConstraint2 = Obj(475) + final val listConstraint3 = Obj(476) + +} diff --git a/scodec/src/main/scala/tf/bug/fancadescodec/Wire.scala b/scodec/src/main/scala/tf/bug/fancadescodec/Wire.scala new file mode 100644 index 0000000..ba38bef --- /dev/null +++ b/scodec/src/main/scala/tf/bug/fancadescodec/Wire.scala @@ -0,0 +1,8 @@ +package tf.bug.fancadescodec + +case class Wire( + startNearLeftBottom: Position, + endNearLeftBottom: Position, + startVoxel: Position, + endVoxel: Position + ) diff --git a/scodec/src/main/scala/tf/bug/fancadescodec/World.scala b/scodec/src/main/scala/tf/bug/fancadescodec/World.scala new file mode 100644 index 0000000..4ba930a --- /dev/null +++ b/scodec/src/main/scala/tf/bug/fancadescodec/World.scala @@ -0,0 +1,6 @@ +package tf.bug.fancadescodec + +case class World( + boundary: Boundary, + objs: Vector[Obj] + ) diff --git a/core/src/main/scala/tf/bug/fancadetagless/Constraint.scala b/tagless/src/main/scala/tf/bug/fancadetagless/Constraint.scala similarity index 100% rename from core/src/main/scala/tf/bug/fancadetagless/Constraint.scala rename to tagless/src/main/scala/tf/bug/fancadetagless/Constraint.scala diff --git a/core/src/main/scala/tf/bug/fancadetagless/Fancade.scala b/tagless/src/main/scala/tf/bug/fancadetagless/Fancade.scala similarity index 100% rename from core/src/main/scala/tf/bug/fancadetagless/Fancade.scala rename to tagless/src/main/scala/tf/bug/fancadetagless/Fancade.scala diff --git a/core/src/main/scala/tf/bug/fancadetagless/Fanscript.scala b/tagless/src/main/scala/tf/bug/fancadetagless/Fanscript.scala similarity index 100% rename from core/src/main/scala/tf/bug/fancadetagless/Fanscript.scala rename to tagless/src/main/scala/tf/bug/fancadetagless/Fanscript.scala diff --git a/core/src/main/scala/tf/bug/fancadetagless/Obj.scala b/tagless/src/main/scala/tf/bug/fancadetagless/Obj.scala similarity index 100% rename from core/src/main/scala/tf/bug/fancadetagless/Obj.scala rename to tagless/src/main/scala/tf/bug/fancadetagless/Obj.scala diff --git a/core/src/main/scala/tf/bug/fancadetagless/Rotation.scala b/tagless/src/main/scala/tf/bug/fancadetagless/Rotation.scala similarity index 100% rename from core/src/main/scala/tf/bug/fancadetagless/Rotation.scala rename to tagless/src/main/scala/tf/bug/fancadetagless/Rotation.scala diff --git a/core/src/main/scala/tf/bug/fancadetagless/Vector3.scala b/tagless/src/main/scala/tf/bug/fancadetagless/Vector3.scala similarity index 100% rename from core/src/main/scala/tf/bug/fancadetagless/Vector3.scala rename to tagless/src/main/scala/tf/bug/fancadetagless/Vector3.scala diff --git a/core/src/main/scala/tf/bug/fancadetagless/package.scala b/tagless/src/main/scala/tf/bug/fancadetagless/package.scala similarity index 100% rename from core/src/main/scala/tf/bug/fancadetagless/package.scala rename to tagless/src/main/scala/tf/bug/fancadetagless/package.scala diff --git a/core/src/test/scala/tf/bug/fancadetagless/FancadeSuite.scala b/tagless/src/test/scala/tf/bug/fancadetagless/FancadeSuite.scala similarity index 100% rename from core/src/test/scala/tf/bug/fancadetagless/FancadeSuite.scala rename to tagless/src/test/scala/tf/bug/fancadetagless/FancadeSuite.scala