Skip to content

Commit b885acd

Browse files
committed
improve error message in ReverseResolver and add cheat sheet
1 parent 406dd7b commit b885acd

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,38 @@ You need to manually move the generated RUL2 files from the `target` directory
133133
to the correct locations in the `Controller` directory and then commit them into the git repository.
134134
For more information on Metarules, see https://github.com/memo33/metarules.
135135

136+
#### Metarules Cheat Sheet
137+
138+
Some functions for interacting with IDs and RUL2 code effectively are listed here.
139+
Type `sbt console` to enter the interactive REPL. Then:
140+
```scala
141+
resolve(Ard3~EW & Avenue~NS) // convert a metarule Tile to an ID
142+
// val result = IdTile(0x51021300,2,1)
143+
144+
transduce(Ard3~EW | (Road ~> Ard3)~EW & Avenue~NS) // convert a metarule to RUL2
145+
// 0x51020000,3,0,0x04008900,0,0=0x51020000,3,0,0x51021300,2,1
146+
// 0x51020000,1,0,0x04008900,0,0=0x51020000,1,0,0x51021300,0,0
147+
148+
transduce(Sam2~(0,0,11,3) | Street~(11,2,2,0) | % | Sam2~(11,2,2,0)) // alternative syntax
149+
// 0x5E571200,3,0,0x5F500900,1,0=0x5E571200,3,0,0x5E576200,1,0
150+
151+
preimage(0x57294745) // convert an ID to a metarule Tile
152+
// val result = List(L2Rhw8c~(0,+2,0,-2) & Glr3~(3,0,0,1))
153+
154+
preimage(IdTile(0x57294745,2,1)) // convert an ID with rotation to a metarule Tile
155+
// val result = List(L2Rhw8c~(0,+2,0,-2) & Glr3~(1,3,0,0))
156+
157+
preimage(resolve(Street~(2,2,2,2))) // result can be ambiguous if multiple definitions exist
158+
// val result = List(Street~(2,2,2,2), Street~(0,2,0,2) & Street~(2,0,2,0))
159+
160+
(Road~(2,0,2,0)).symmetries // find the symmetries of a tile
161+
// val result = Dih2A((0,0), (2,0), (0,1), (2,1))
162+
(Ard3~ES & Ard3~NE).symmetries
163+
// val result = Cyc2D((0,0), (2,1))
164+
```
165+
166+
See [metarules](https://github.com/memo33/metarules) for more details.
167+
136168
### Compiling Locale Files
137169

138170
To convert all the translations contained in the directory [ltext/](ltext/)

src/main/scala/module/ReverseResolver.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ class ReverseResolver private[module] (val reverseTileMap: collection.Map[Int, :
1313
case x: IdTile => x.id
1414
case id: Int => id
1515
}
16+
1617
def isDefinedAt(idTile: IdTile | Int): Boolean = reverseTileMap.contains(toId(idTile))
18+
1719
def apply(idTile: IdTile | Int): ::[Tile] = {
18-
val fiber = reverseTileMap.apply(toId(idTile))
20+
val id = toId(idTile)
21+
val fiber =
22+
try reverseTileMap.apply(id)
23+
catch { case e: java.util.NoSuchElementException => throw new java.util.NoSuchElementException(f"0x$id%08X (ID not defined in any metarule ID resolver)") }
1924
idTile match {
2025
case x: IdTile => fiber.map(_ * x.rf).asInstanceOf[::[Tile]]
2126
case id: Int => fiber

0 commit comments

Comments
 (0)