Fix deserialization of shogi promotions.
[tagua/yd.git] / data / scripts / shogi_themelib.lua
blob720d9c9fb995d2d32d277cd215eeffcc5b4dd4f1
1 -- generic functions for shogi themes
2 -- FIXME: still depends on Shogi.ttf for the tile
4 function tile(white, ratio)
5 return function(size)
6 local i = Image(size,size)
7 i:clear()
9 local g = RadialGradient(Point(size*0.5,size*0.5), size*0.5, Point(size*0.3,size*0.3))
10 g[0] = "#ffeda2"
11 g[1] = "#c0a870"
12 local b = Brush(g)
14 if white then
15 i:translate(-size, -size)
16 i:rotate(180)
17 b:translate(-size, -size)
18 b:rotate(180)
19 end
21 if ratio then
22 i:scale(ratio, ratio)
23 i:translate(size*(1-ratio)*0.5, size*(1-ratio)*0.5)
24 b:scale(ratio, ratio)
25 b:translate(size*(1-ratio)*0.5, size*(1-ratio)*0.5)
26 end
28 i:draw_glyph(Rect(0,0,size,size), "../ShogiSVG-TTF/Shogi.ttf", "0x2c", "black", b)
29 --i:draw_svg(Rect(0,0,size,size), "../ShogiSVG/tile.svg")
30 return i
31 end
32 end
34 function draw_arrowhead(i, p, vx,vy, length, rwidth, linecolor,linewidth)
35 -- normalize to 1 the direction vector
36 local vl = (vx*vx + vy*vy)^0.5
37 vx,vy = vx/vl, vy/vl
38 -- the component vector along the arrow direction
39 local vxdirect, vydirect = -vx*length, -vy*length
40 -- an orthogonal vector of requested relative width
41 local vxortho,vyortho = vydirect*rwidth, -vxdirect*rwidth
43 i:draw_line(p,Point(p.x+vxdirect+vxortho,p.y-vydirect-vyortho), linecolor,linewidth)
44 i:draw_line(p,Point(p.x+vxdirect-vxortho,p.y-vydirect+vyortho), linecolor,linewidth)
45 end
47 function shogi_moves(moves)
48 return function(i,size)
49 if not theme.options.moves_overlay.value then
50 return i
51 end
53 local index, move
54 --local xcenter, ycenter, width = size/2, size/2, size/4
55 local xcenter, ycenter, width = 0.8*size, 0.82*size, 0.08*size
56 local tilesize,shortsize = 0.8*width, 0.3*width
57 local arrowlen,arrowrwidth = 0.2*width, 0.5
58 local centerpoint = Point(xcenter,ycenter)
59 local b = Brush("red")
60 for index,move in ipairs(moves) do
61 local x,y,long = move[1],move[2],move[3]
62 if long then
63 local p2 = Point(xcenter+1.5*x*width, ycenter-1.5*y*width)
64 i:draw_line(centerpoint,p2, "purple",1)
65 draw_arrowhead(i, p2, x,y, arrowlen,arrowrwidth, "purple",1)
66 else
67 i:draw_line(centerpoint, Point(xcenter+x*width,ycenter-y*width),"red",1)
68 i:fill_rect(Rect(xcenter+x*width-shortsize/2, ycenter-y*width-shortsize/2,
69 shortsize, shortsize), b)
70 end
71 end
73 -- the tile
74 i:fill_rect(Rect(xcenter-tilesize/2,ycenter-tilesize/2,
75 tilesize,tilesize), b)
77 return i
78 end
79 end
81 shogimoves_king = {
82 {-1,1},{0,1},{1,1},
83 {-1,0},{1,0},
84 {-1,-1},{0,-1},{1,-1}}
85 shogimoves_rook = {{-1,0,1},{1,0,1},{0,-1,1},{0,1,1}}
86 shogimoves_dragon = {
87 {-1,0,1},{1,0,1},{0,-1,1},{0,1,1},
88 {-1,-1},{1,-1},{-1,1},{1,1}}
89 shogimoves_bishop = {{-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1}}
90 shogimoves_horse = {
91 {-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1},
92 {-1,0},{1,0},{0,-1},{0,1}}
93 shogimoves_gold = {
94 {-1,1},{0,1},{1,1},
95 {-1,0},{1,0},{0,-1}}
96 shogimoves_silver = {
97 {-1,1},{0,1},{1,1},
98 {-1,-1},{1,-1}}
99 shogimoves_knight = {{-1,2},{1,2}}
100 shogimoves_lance = {{0,1,1}}
101 shogimoves_pawn = {{0,1}}
103 shogimoves_freeking = {
104 {-1,1,1},{0,1,1},{1,1,1},
105 {-1,0,1},{1,0,1},
106 {-1,-1,1},{0,-1,1},{1,-1,1}}