Sequencing works

This commit is contained in:
Aly 2020-07-26 16:57:09 -07:00
parent 2ef584a42a
commit 912eb26652
5 changed files with 78 additions and 18 deletions

View File

@ -54,15 +54,15 @@ object Level {
edge.nodeSeq.tail.map { to =>
if(from.definition.dataType == PinType.Pull) {
fansc.Wire(
to.owner.position,
from.owner.position,
to.basePosition,
from.basePosition,
to.definition.voxel,
from.definition.voxel
)
} else {
fansc.Wire(
from.owner.position,
to.owner.position,
from.basePosition,
to.basePosition,
from.definition.voxel,
to.definition.voxel
)

View File

@ -14,8 +14,8 @@ object Main extends IOApp {
override def run(args: List[String]): IO[ExitCode] = {
val winBlock = Block(Position(0, 0, 0), Exists(Template(BlockDefinition.Win, true)))
val loseBlock = Block(Position(0, 0, 3), Exists(Template(BlockDefinition.Lose, true)))
val loseAfter = Pin(loseBlock, BlockDefinition.Lose.after)
val winBefore = Pin(winBlock, BlockDefinition.Win.before)
val loseAfter = Pin(loseBlock.position, BlockDefinition.Lose.after)
val winBefore = Pin(winBlock.position, BlockDefinition.Win.before)
val level = Level(
Set(
winBlock,

View File

@ -1,6 +1,8 @@
package tf.bug.fancadegraph
import tf.bug.fancadescodec.Position
case class Pin(
owner: Block,
basePosition: Position,
definition: PinDefinition
)

View File

@ -7,6 +7,11 @@ import polymorphic._
import tf.bug.fancadegraph.Level
import tf.bug.fancadegraph.PinDefinition
import tf.bug.fancadegraph.Template
import tf.bug.fancadegraph.Block
import tf.bug.fancadescodec.Position
import scalax.collection.Graph
import scalax.collection.GraphEdge.DiHyperEdge
import tf.bug.fancadegraph.Pin
sealed trait FancadeF[A]
@ -56,25 +61,75 @@ object FancadeF {
i.map(original(_))
case Combine(f) =>
f.flatMap(origins(_, stack))
case Sequence(_, _, n) =>
origins(n, stack)
case Sequence(f, _, _) =>
origins(f, stack)
case Noop() =>
Vector.empty
}
}
def flatStack(vertices: Vector[FancadeF[Int]]): (Vector[Exists[Template]], Int => Option[Int]) = {
val blocks = vertices.collect(_ => ???)
(blocks, ())._2
???
def filteredIndex[A](vec: Vector[A], f: A => Boolean): Vector[(A, Int)] = {
vec.zipWithIndex.filter { case (e, _) => f(e) }
}
def render(f: Fix[FancadeF]): Level = {
val pc: PointerChain[Id, FancadeF] = PointerChain.deduplicate[Id, FancadeF](f)
val (stack, stackLookup) = flatStack(pc.vertices)
(stack, ())._2
(stackLookup, ())._2
???
val pcv: Vector[FancadeF[Int]] = pc.vertices
val bdVector: Vector[Exists[Template]] = pcv.collect {
case Create(_, template, _, _) => template
}
val blocks: Set[Block] = bdVector.zipWithIndex.map {
case (template, idx) =>
Block(
Position(0, idx, 0),
template
)
}.toSet
val pcf: Vector[(FancadeF[Int], Int)] = filteredIndex(pcv, (_: FancadeF[Int]) match {
case Create(_, _, _, _) => true
case _ => false
})
val pcfr: Int => Int =
idx => pcf.indexWhere { case (_, i) => i == idx }
val wires: Graph[Pin, DiHyperEdge] =
pcv.zipWithIndex.foldLeft(Graph.empty[Pin, DiHyperEdge]) {
case (graph, (entry, idx)) =>
entry match {
case Create(from, _, imports, _) =>
val thisH = pcfr(idx)
val dependencies: Vector[(Int, PinDefinition)] = from.flatMap(origins(_, pcv))
val newWires = imports.zip(dependencies).map {
case (thisPinD, (thatI, thatPinD)) =>
val thisPin = Pin(
Position(0, thisH, 0),
thisPinD
)
val thatPin = Pin(
Position(0, pcfr(thatI), 0),
thatPinD
)
DiHyperEdge(thatPin, thisPin)
}
graph ++ newWires
case Sequence(f, p, n) =>
if(pcv(n) == Noop()) graph
else {
val po = origins(f, pcv)
val to = Pin(
Position(0, pcfr(po.head._1), 0),
p
)
val fo = origins(n, pcv)
val from = Pin(
Position(0, pcfr(fo.head._1), 0),
fo.head._2
)
graph ++ Set(DiHyperEdge(from, to))
}
case _ => graph
}
}
Level(blocks, wires)
}
}

View File

@ -19,7 +19,10 @@ object Main extends IOApp {
override def run[G[_]](implicit interp: Fanscript[G]): G[Unit] = {
val screenSize = interp.screenSize
val screenWidth = interp.screenSizeWidth(screenSize)
val inspectWidth = interp.inspect(screenWidth, () => interp.unit)
val inspectWidth = interp.inspect(screenWidth, () => {
val screenHeight = interp.screenSizeHeight(screenSize)
interp.inspect(screenHeight, () => interp.unit)
})
inspectWidth
}
}