Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
main ▾

Modern-Apps.git / scripts / unblockjam / level_tools / src / convert.go

convert.go58 lines · 1.1 KiBRaw
1package rush_conv
2
3import (
4 "github.com/fogleman/rush"
5)
6
7func tocoord(position int, board_size int) (int, int) {
8 x := position % board_size
9 y := board_size - 1 - (position / board_size)
10 return x, y
11}
12
13func tosize(size int, orientation int) (int, int) {
14 if orientation == 0 {
15 return size, 1
16 }
17 return 1, size
18}
19
20func Convert(board_desc string) Board {
21 board, _ := rush.NewBoardFromString(board_desc)
22
23 blocks := make([]Block, 0, len(board.Pieces)+len(board.Walls))
24
25 for _, piece := range board.Pieces {
26 x, y := tocoord(piece.Position, board.Width)
27 if piece.Orientation == 1 {
28 y -= piece.Size - 1
29 }
30 w, h := tosize(piece.Size, int(piece.Orientation))
31 blocks = append(blocks, Block{
32 X: x,
33 Y: y,
34 Width: w,
35 Height: h,
36 })
37 }
38 for _, wall := range board.Walls {
39 x, y := tocoord(wall, board.Width)
40 blocks = append(blocks, Block{
41 X: x,
42 Y: y,
43 Width: 1,
44 Height: 1,
45 Fixed: true,
46 })
47 }
48
49 return Board{
50 Blocks: blocks,
51 Exit: Exit{
52 X: board.Width,
53 Y: board.Height / 2,
54 },
55 Width: board.Width,
56 Height: board.Height,
57 }
58}