Skip to content

Commit 9f61d69

Browse files
committed
split off a separate NwmRuleGenerator from RHW metarules
1 parent 6702092 commit 9f61d69

3 files changed

Lines changed: 49 additions & 17 deletions

File tree

src/main/scala/module/CompileAllMetarules.scala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ object CompileAllMetarules {
3838
CompileRealRailwayCode.start(tileOrientationCache = tileOrientationCache)
3939
LOGGER.info("compiling RHW metarule code")
4040
CompileRhwCode.start(tileOrientationCache = tileOrientationCache)
41+
LOGGER.info("compiling NWM metarule code")
42+
CompileNwmCode.start(tileOrientationCache = tileOrientationCache)
4143
LOGGER.info("compiling SAM metarule code")
4244
CompileSamCode.start(tileOrientationCache = tileOrientationCache)
4345
LOGGER.info("compiling Onslope metarule code")
@@ -46,11 +48,3 @@ object CompileAllMetarules {
4648
CompileRoundaboutCode.start(tileOrientationCache = tileOrientationCache)
4749
}
4850
}
49-
50-
// Compile individually with `sbt "runMain com.sc4nam.module.CompileRhwCode"`.
51-
object CompileRhwCode extends AbstractMain {
52-
lazy val resolve: IdResolver = new MiscResolver orElse new RealRailwayResolver orElse new RhwResolver orElse new NwmResolver orElse new ViaductResolver
53-
val generator = new RhwRuleGenerator(_)
54-
lazy val file = new File("target/RhwMetaGenerated_MANAGED.txt")
55-
}
56-
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.sc4nam.module
2+
3+
import io.github.memo33.metarules.meta._, syntax._
4+
import Network._, Flags._, Flag._, RotFlip._, Implicits._, group.SymGroup._
5+
import NetworkProperties._
6+
7+
class NwmRuleGenerator(var context: RuleTransducer.Context) extends RuleGenerator with Curve45Generator with CrossingGenerator {
8+
9+
def start(): Unit = {
10+
for (main <- NwmNetworks; base <- main.base) {
11+
Rules += main~WE | (base ~> main)~WE // ortho
12+
Rules += main~WE | (base ~> main)~WC // ortho stub
13+
withSharedDiagonals {
14+
Rules += main~SE~ES | (base ~> main)~WN~NW // diagonal
15+
}
16+
// curves
17+
createCurve45Rules(main)
18+
createCurve90Rules(main)
19+
20+
// crossings (O×O, O×D, D×O, D×D)
21+
for (minor <- CrossingGenerator.crossingNetworksOf(main)) {
22+
createCrossingRules(main, minor)
23+
}
24+
}
25+
}
26+
27+
}
28+
29+
// Compile individually with `sbt "runMain com.sc4nam.module.CompileNwmCode"`.
30+
object CompileNwmCode extends AbstractMain {
31+
lazy val resolve: IdResolver = new MiscResolver orElse new RealRailwayResolver orElse new RhwResolver orElse new NwmResolver orElse new ViaductResolver
32+
val generator = new NwmRuleGenerator(_)
33+
lazy val file = new java.io.File("target/NwmMetaGenerated_MANAGED.txt")
34+
}

src/main/scala/module/RhwRuleGenerator.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,27 @@ class RhwRuleGenerator(var context: RuleTransducer.Context) extends RuleGenerato
5454
def start(): Unit = {
5555
createMultiTileStarters()
5656

57-
for (main <- OverrideNetworks; base <- main.base; if main.isRhw || main.isNwm) { // TODO filtering
58-
if (main.isRhw || main.isNwm) {
59-
Rules += main~WE | (base ~> main)~WE // ortho
60-
Rules += main~WE | (base ~> main)~WC // ortho stub
61-
withSharedDiagonals {
62-
Rules += main~SE~ES | (base ~> main)~WN~NW // diagonal
63-
}
64-
createRules() // flush the buffer from time to time
57+
for (main <- RhwNetworks; base <- main.base) {
58+
Rules += main~WE | (base ~> main)~WE // ortho
59+
Rules += main~WE | (base ~> main)~WC // ortho stub
60+
withSharedDiagonals {
61+
Rules += main~SE~ES | (base ~> main)~WN~NW // diagonal
6562
}
6663
// curves
6764
createCurve45Rules(main)
6865
createCurve90Rules(main)
6966

70-
// TODO filtering
67+
// crossings (O×O, O×D, D×O, D×D)
7168
for (minor <- CrossingGenerator.crossingNetworksOf(main)) {
7269
createCrossingRules(main, minor)
7370
}
7471
}
7572
}
7673
}
74+
75+
// Compile individually with `sbt "runMain com.sc4nam.module.CompileRhwCode"`.
76+
object CompileRhwCode extends AbstractMain {
77+
lazy val resolve: IdResolver = new MiscResolver orElse new RealRailwayResolver orElse new RhwResolver orElse new NwmResolver orElse new ViaductResolver
78+
val generator = new RhwRuleGenerator(_)
79+
lazy val file = new java.io.File("target/RhwMetaGenerated_MANAGED.txt")
80+
}

0 commit comments

Comments
 (0)