Add Sho Shogi variant.
[tagua/yd.git] / data / scripts / shogi_themelib.lua
blob8907d5e966f03c77ce38fe9387cfedc2f8a8481d
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, args)
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 local flip = (white or args.flipped) and not (white and args.flipped)
16 if flip then
17 i:translate(-size, -size)
18 i:rotate(180)
19 b:translate(-size, -size)
20 b:rotate(180)
21 end
23 if ratio then
24 i:scale(ratio, ratio)
25 i:translate(size*(1-ratio)*0.5, size*(1-ratio)*0.5)
26 b:scale(ratio, ratio)
27 b:translate(size*(1-ratio)*0.5, size*(1-ratio)*0.5)
28 end
30 i:draw_glyph(Rect(0,0,size,size), "../ShogiSVG-TTF/Shogi.ttf", "0x2c", "black", b)
31 --i:draw_svg(Rect(0,0,size,size), "../ShogiSVG/tile.svg")
32 return i
33 end
34 end
36 function draw_arrowhead(i, p, vx,vy, length, rwidth, linecolor,linewidth)
37 -- normalize to 1 the direction vector
38 local vl = (vx*vx + vy*vy)^0.5
39 vx,vy = vx/vl, vy/vl
40 -- the component vector along the arrow direction
41 local vxdirect, vydirect = -vx*length, -vy*length
42 -- an orthogonal vector of requested relative width
43 local vxortho,vyortho = vydirect*rwidth, -vxdirect*rwidth
45 i:draw_line(p,Point(p.x+vxdirect+vxortho,p.y-vydirect-vyortho), linecolor,linewidth)
46 i:draw_line(p,Point(p.x+vxdirect-vxortho,p.y-vydirect+vyortho), linecolor,linewidth)
47 end
49 function shogi_moves(moves)
50 return function(i,size)
51 if not theme.options.moves_overlay.value then
52 return i
53 end
55 local index, move
56 --local xcenter, ycenter, width = size/2, size/2, size/4
57 local xcenter, ycenter, width = 0.8*size, 0.82*size, 0.08*size
58 local tilesize,shortsize = 0.8*width, 0.3*width
59 local arrowlen,arrowrwidth = 0.2*width, 0.5
60 local centerpoint = Point(xcenter,ycenter)
61 local b = Brush("red")
62 for index,move in ipairs(moves) do
63 local x,y,long = move[1],move[2],move[3]
64 if long then
65 local p2 = Point(xcenter+1.5*x*width, ycenter-1.5*y*width)
66 i:draw_line(centerpoint,p2, "purple",1)
67 draw_arrowhead(i, p2, x,y, arrowlen,arrowrwidth, "purple",1)
68 else
69 i:draw_line(centerpoint, Point(xcenter+x*width,ycenter-y*width),"red",1)
70 i:fill_rect(Rect(xcenter+x*width-shortsize/2, ycenter-y*width-shortsize/2,
71 shortsize, shortsize), b)
72 end
73 end
75 -- the tile
76 i:fill_rect(Rect(xcenter-tilesize/2,ycenter-tilesize/2,
77 tilesize,tilesize), b)
79 return i
80 end
81 end
83 shogichars = {}
84 -- standard Shogi
85 shogichars["king"] = {"0x7389", {"0x7389", "0x5c06"}}
86 shogichars["jade general"] = {"0x738b", {"0x738b", "0x5c06"}}
87 shogichars["flying chariot"] = {"0x98db", {"0x98db", "0x8eca"}}
88 shogichars["bishop"] = {"0x89d2", {"0x89d2", "0x884c"}}
89 shogichars["gold general"] = {"0x91d1", {"0x91d1", "0x5c06"}}
90 shogichars["silver general"] = {"0x9280", {"0x9280", "0x5c06"}}
91 shogichars["knight"] = {"0x6842", {"0x6842", "0x99ac"}}
92 shogichars["incense chariot"] = {"0x9999", {"0x9999", "0x8eca"}}
93 shogichars["pawn"] = {"0x6b69", {"0x6b69", "0x5175"}}
94 shogichars["dragon king"] = {"0x9f8d", {"0x9f8d", "0x738b"}}
95 shogichars["dragon horse"] = {"0x99ac", {"0x9f8d", "0x99ac"}}
96 shogichars["narigin"] = {"0x5168", {"0x6210", "0x9280"}}
97 shogichars["narikei"] = {"0x572d", {"0x6210", "0x6842"}}
98 shogichars["narikyo"] = {"0x674f", {"0x6210", "0x9999"}}
99 shogichars["tokin"] = {"0x3068", {"0x3068", "0x91d1"}}
100 -- Sho Shogi
101 shogichars["drunken elephant"] = {"0x9154", {"0x9154", "0x8c61"}}
102 shogichars["crown prince"] = {"0x592a", {"0x592a", "0x5b50"}}
103 -- Chess compatibility (part of Dai Shogi)
104 shogichars["free king"] = {"0x5954", {"0x5954", "0x738b"}}
106 shogimoves_king = {
107 {-1,1},{0,1},{1,1},
108 {-1,0},{1,0},
109 {-1,-1},{0,-1},{1,-1}}
110 shogimoves_rook = {{-1,0,1},{1,0,1},{0,-1,1},{0,1,1}}
111 shogimoves_dragon = {
112 {-1,0,1},{1,0,1},{0,-1,1},{0,1,1},
113 {-1,-1},{1,-1},{-1,1},{1,1}}
114 shogimoves_bishop = {{-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1}}
115 shogimoves_horse = {
116 {-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1},
117 {-1,0},{1,0},{0,-1},{0,1}}
118 shogimoves_gold = {
119 {-1,1},{0,1},{1,1},
120 {-1,0},{1,0},{0,-1}}
121 shogimoves_silver = {
122 {-1,1},{0,1},{1,1},
123 {-1,-1},{1,-1}}
124 shogimoves_knight = {{-1,2},{1,2}}
125 shogimoves_lance = {{0,1,1}}
126 shogimoves_pawn = {{0,1}}
128 shogimoves_drunken_elephant = {
129 {-1,1},{0,1},{1,1},
130 {-1,0},{1,0},
131 {-1,-1},{1,-1}}
133 shogimoves_freeking = {
134 {-1,1,1},{0,1,1},{1,1,1},
135 {-1,0,1},{1,0,1},
136 {-1,-1,1},{0,-1,1},{1,-1,1}}