From 8a53b814c5cc51ee48a33bb954eb0a82de15e376 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Fri, 14 Sep 2007 19:49:45 +0200 Subject: [PATCH] Factor declaration of shogi characters. --- data/scripts/shogi_themelib.lua | 23 +++ data/themes/figurines/ShogiTTF/theme.lua | 33 ++-- data/themes/pieces/ShogiTTF/theme.lua | 264 +++++++++++++++---------------- 3 files changed, 171 insertions(+), 149 deletions(-) rewrite data/themes/pieces/ShogiTTF/theme.lua (66%) diff --git a/data/scripts/shogi_themelib.lua b/data/scripts/shogi_themelib.lua index 595f6fe..8465659 100644 --- a/data/scripts/shogi_themelib.lua +++ b/data/scripts/shogi_themelib.lua @@ -78,6 +78,29 @@ function shogi_moves(moves) end end +shogichars = {} +-- standard Shogi +shogichars["king"] = {"0x7389", {"0x7389", "0x5c06"}} +shogichars["jade general"] = {"0x738b", {"0x738b", "0x5c06"}} +shogichars["flying chariot"] = {"0x98db", {"0x98db", "0x8eca"}} +shogichars["bishop"] = {"0x89d2", {"0x89d2", "0x884c"}} +shogichars["gold general"] = {"0x91d1", {"0x91d1", "0x5c06"}} +shogichars["silver general"] = {"0x9280", {"0x9280", "0x5c06"}} +shogichars["knight"] = {"0x6842", {"0x6842", "0x99ac"}} +shogichars["incense chariot"] = {"0x9999", {"0x9999", "0x8eca"}} +shogichars["pawn"] = {"0x6b69", {"0x6b69", "0x5175"}} +shogichars["dragon king"] = {"0x9f8d", {"0x9f8d", "0x738b"}} +shogichars["dragon horse"] = {"0x99ac", {"0x9f8d", "0x99ac"}} +shogichars["narigin"] = {"0x5168", {"0x6210", "0x9280"}} +shogichars["narikei"] = {"0x572d", {"0x6210", "0x6842"}} +shogichars["narikyo"] = {"0x674f", {"0x6210", "0x9999"}} +shogichars["tokin"] = {"0x3068", {"0x3068", "0x91d1"}} +-- Sho Shogi +shogichars["drunken elephant"] = {"0x9154", {"0x9154", "0x8c61"}} +shogichars["crown prince"] = {"0x592a", {"0x592a", "0x5b50"}} +-- Chess compatibility (part of Dai Shogi) +shogichars["free king"] = {"0x5954", {"0x5954", "0x738b"}} + shogimoves_king = { {-1,1},{0,1},{1,1}, {-1,0},{1,0}, diff --git a/data/themes/figurines/ShogiTTF/theme.lua b/data/themes/figurines/ShogiTTF/theme.lua index 3dba409..74ccd78 100644 --- a/data/themes/figurines/ShogiTTF/theme.lua +++ b/data/themes/figurines/ShogiTTF/theme.lua @@ -1,4 +1,5 @@ import("piece_theme.lua") +import("shogi_themelib.lua") function Fig(char) return Glyph("mikachan.ttf", char, 2) @@ -14,20 +15,18 @@ theme.num_3 = Fig("0x4e09") theme.num_2 = Fig("0x4e8c") theme.num_1 = Fig("0x4e00") -theme.king1 = Fig("0x738b") -theme.king2 = Fig("0x7389") -theme.rook = Fig("0x98db") -theme.p_rook = Fig("0x9f8d") -theme.bishop = Fig("0x89d2") -theme.p_bishop = Fig("0x99ac") -theme.gold = Fig("0x91d1") -theme.silver = Fig("0x9280") -theme.p_silver = Fig("0x5168") -theme.knight = Fig("0x6842") -theme.p_knight = Fig("0x572d") -theme.lance = Fig("0x9999") -theme.p_lance = Fig("0x674f") -theme.pawn = Fig("0x6b69") -theme.p_pawn = Fig("0x3068") - - +theme.king1 = Fig(shogichars["jade general"][1]) +theme.king2 = Fig(shogichars["king"][1]) +theme.rook = Fig(shogichars["flying chariot"][1]) +theme.p_rook = Fig(shogichars["dragon king"][1]) +theme.bishop = Fig(shogichars["bishop"][1]) +theme.p_bishop = Fig(shogichars["dragon horse"][1]) +theme.gold = Fig(shogichars["gold general"][1]) +theme.silver = Fig(shogichars["silver general"][1]) +theme.p_silver = Fig(shogichars["narigin"][1]) +theme.knight = Fig(shogichars["knight"][1]) +theme.p_knight = Fig(shogichars["narikei"][1]) +theme.lance = Fig(shogichars["incense chariot"][1]) +theme.p_lance = Fig(shogichars["narikyo"][1]) +theme.pawn = Fig(shogichars["pawn"][1]) +theme.p_pawn = Fig(shogichars["tokin"][1]) diff --git a/data/themes/pieces/ShogiTTF/theme.lua b/data/themes/pieces/ShogiTTF/theme.lua dissimilarity index 66% index 7098dfd..63925b6 100644 --- a/data/themes/pieces/ShogiTTF/theme.lua +++ b/data/themes/pieces/ShogiTTF/theme.lua @@ -1,132 +1,132 @@ -import("piece_theme.lua") -import("shogi_themelib.lua") - -shadow=7.0 -shadow_color="#404050" -shadow_offset_x=6 -shadow_offset_y=4 -shadow_grow=5 - -theme.options = OptList { - BoolOpt("moves_overlay", "Moves overlay", true), - BoolOpt("single_kanji", "Single kanji on tiles", false), - SelectOpt("symbols", "Symbol set", BoolOptList { --- BoolOpt("use_predefined", "Predefined", true, OptList { --- ComboOpt("font", "Symbol set", fontnames) --- }), - BoolOpt("use_custom", "Custom font", false, OptList { - UrlOpt("file", "SVG glyph directory", "../../figurines/ShogiTTF/mikachan.ttf") - }), --- BoolOpt("use_system", "System font", false, OptList { --- FontOpt("font", "System font", Font("Arial", true, true)) --- }), - }) -} - -function addChar(complete, single, promoted) - return function(i, size) - font = theme.options.symbols.options.use_custom.sub_options.file.value - if theme.options.single_kanji.value then - i:draw_glyph(Rect(size*0.2,size*0.25,size*0.6,size*0.6), font, single, - promoted and "#d00000" or "#004000", - "#fff3c8", 4, false) - else - --local charsize, margin1, margin2 = 0.45, 0.09, -0.02 -- epgyobld - local charsize, margin1, margin2 = 0.4, 0.12, 0 - i:draw_glyph(Rect(size*(0.5-charsize/2),size*margin1,size*charsize,size*charsize), - font, complete[1], promoted and "#d00000" or "#004000", - "#fff3c8", 4, false) - i:draw_glyph(Rect(size*(0.5-charsize/2),size*(0.5+margin2),size*charsize,size*charsize), - font, complete[2], promoted and "#d00000" or "#004000", - "#fff3c8", 4, false) - end - return i - end -end - -function shogi_piece(first, char, white, promoted, ratio, moves) - return addShadow(overlay(tile(white, ratio), - shogi_moves(moves), - addChar(first, char, promoted))) -end - -theme.black_king = shogi_piece({"0x738b", "0x5c06"}, "0x738b", false, false, 1, - shogimoves_king) -theme.black_rook = shogi_piece({"0x98db", "0x8eca"}, "0x98db", false, false, 0.96, - shogimoves_rook) -theme.black_p_rook = shogi_piece({"0x9f8d", "0x738b"}, "0x9f8d", false, true, 0.96, - shogimoves_dragon) -theme.black_bishop = shogi_piece({"0x89d2", "0x884c"}, "0x89d2", false, false, 0.93, - shogimoves_bishop) -theme.black_p_bishop = shogi_piece({"0x9f8d", "0x99ac"}, "0x99ac", false, true, 0.93, - shogimoves_horse) -theme.black_gold = shogi_piece({"0x91d1", "0x5c06"}, "0x91d1", false, false, 0.9, - shogimoves_gold) -theme.black_silver = shogi_piece({"0x9280", "0x5c06"}, "0x9280", false, false, 0.9, - shogimoves_silver) -theme.black_p_silver = shogi_piece({"0x6210", "0x9280"}, "0x5168", false, true, 0.9, - shogimoves_gold) -theme.black_knight = shogi_piece({"0x6842", "0x99ac"}, "0x6842", false, false, 0.86, - shogimoves_knight) -theme.black_p_knight = shogi_piece({"0x6210", "0x6842"}, "0x572d", false, true, 0.86, - shogimoves_gold) -theme.black_lance = shogi_piece({"0x9999", "0x8eca"}, "0x9999", false, false, 0.83, - shogimoves_lance) -theme.black_p_lance = shogi_piece({"0x6210", "0x9999"}, "0x674f", false, true, 0.83, - shogimoves_gold) -theme.black_pawn = shogi_piece({"0x6b69", "0x5175"}, "0x6b69", false, false, 0.8, - shogimoves_pawn) -theme.black_p_pawn = shogi_piece({"0x3068", "0x91d1"}, "0x3068", false, true, 0.8, - shogimoves_gold) - -theme.white_king = shogi_piece({"0x7389", "0x5c06"}, "0x7389", true, false, 1, - shogimoves_king) -theme.white_rook = shogi_piece({"0x98db", "0x8eca"}, "0x98db", true, false, 0.96, - shogimoves_rook) -theme.white_p_rook = shogi_piece({"0x9f8d", "0x738b"}, "0x9f8d", true, true, 0.96, - shogimoves_dragon) -theme.white_bishop = shogi_piece({"0x89d2", "0x884c"}, "0x89d2", true, false, 0.93, - shogimoves_bishop) -theme.white_p_bishop = shogi_piece({"0x9f8d", "0x99ac"}, "0x99ac", true, true, 0.93, - shogimoves_horse) -theme.white_gold = shogi_piece({"0x91d1", "0x5c06"}, "0x91d1", true, false, 0.9, - shogimoves_gold) -theme.white_silver = shogi_piece({"0x9280", "0x5c06"}, "0x9280", true, false, 0.9, - shogimoves_silver) -theme.white_p_silver = shogi_piece({"0x6210", "0x9280"}, "0x5168", true, true, 0.9, - shogimoves_gold) -theme.white_knight = shogi_piece({"0x6842", "0x99ac"}, "0x6842", true, false, 0.86, - shogimoves_knight) -theme.white_p_knight = shogi_piece({"0x6210", "0x6842"}, "0x572d", true, true, 0.86, - shogimoves_gold) -theme.white_lance = shogi_piece({"0x9999", "0x8eca"}, "0x9999", true, false, 0.83, - shogimoves_lance) -theme.white_p_lance = shogi_piece({"0x6210", "0x9999"}, "0x674f", true, true, 0.83, - shogimoves_gold) -theme.white_pawn = shogi_piece({"0x6b69", "0x5175"}, "0x6b69", true, false, 0.8, - shogimoves_pawn) -theme.white_p_pawn = shogi_piece({"0x3068", "0x91d1"}, "0x3068", true, true, 0.8, - shogimoves_gold) - --- Sho Shogi - -theme.black_drunken_elephant = shogi_piece({"0x9154", "0x8c61"}, "0x9154", false, false, 1, - shogimoves_drunken_elephant) -theme.black_p_drunken_elephant = shogi_piece({"0x592a", "0x5b50"}, "0x592a", false, true, 1, - shogimoves_king) - -theme.white_drunken_elephant = shogi_piece({"0x9154", "0x8c61"}, "0x9154", true, false, 1, - shogimoves_drunken_elephant) -theme.white_p_drunken_elephant = shogi_piece({"0x592a", "0x5b50"}, "0x592a", true, true, 1, - shogimoves_king) - --- This is part of Dai Shohi - -theme.black_freeking = shogi_piece({"0x5954", "0x738b"}, "0x5954", false, false, 1, - shogimoves_freeking) -theme.white_freeking = shogi_piece({"0x5954", "0x738b"}, "0x5954", true, false, 1, - shogimoves_freeking) - --- To be able to adapt this theme to chess too -theme.black_queen = theme.black_freeking -theme.white_queen = theme.white_freeking +import("piece_theme.lua") +import("shogi_themelib.lua") + +shadow=7.0 +shadow_color="#404050" +shadow_offset_x=6 +shadow_offset_y=4 +shadow_grow=5 + +theme.options = OptList { + BoolOpt("moves_overlay", "Moves overlay", true), + BoolOpt("single_kanji", "Single kanji on tiles", false), + SelectOpt("symbols", "Symbol set", BoolOptList { +-- BoolOpt("use_predefined", "Predefined", true, OptList { +-- ComboOpt("font", "Symbol set", fontnames) +-- }), + BoolOpt("use_custom", "Custom font", false, OptList { + UrlOpt("file", "SVG glyph directory", "../../figurines/ShogiTTF/mikachan.ttf") + }), +-- BoolOpt("use_system", "System font", false, OptList { +-- FontOpt("font", "System font", Font("Arial", true, true)) +-- }), + }) +} + +function addChar(complete, single, promoted) + return function(i, size) + font = theme.options.symbols.options.use_custom.sub_options.file.value + if theme.options.single_kanji.value then + i:draw_glyph(Rect(size*0.2,size*0.25,size*0.6,size*0.6), font, single, + promoted and "#d00000" or "#004000", + "#fff3c8", 4, false) + else + --local charsize, margin1, margin2 = 0.45, 0.09, -0.02 -- epgyobld + local charsize, margin1, margin2 = 0.4, 0.12, 0 + i:draw_glyph(Rect(size*(0.5-charsize/2),size*margin1,size*charsize,size*charsize), + font, complete[1], promoted and "#d00000" or "#004000", + "#fff3c8", 4, false) + i:draw_glyph(Rect(size*(0.5-charsize/2),size*(0.5+margin2),size*charsize,size*charsize), + font, complete[2], promoted and "#d00000" or "#004000", + "#fff3c8", 4, false) + end + return i + end +end + +function shogi_piece(first, char, white, promoted, ratio, moves) + return addShadow(overlay(tile(white, ratio), + shogi_moves(moves), + addChar(first, char, promoted))) +end + +theme.black_king = shogi_piece(shogichars["jade general"][2], shogichars["jade general"][1], + false, false, 1, shogimoves_king) +theme.black_rook = shogi_piece(shogichars["flying chariot"][2], shogichars["flying chariot"][1], + false, false, 0.96, shogimoves_rook) +theme.black_p_rook = shogi_piece(shogichars["dragon king"][2], shogichars["dragon king"][1], + false, true, 0.96, shogimoves_dragon) +theme.black_bishop = shogi_piece(shogichars["bishop"][2], shogichars["bishop"][1], + false, false, 0.93, shogimoves_bishop) +theme.black_p_bishop = shogi_piece(shogichars["dragon horse"][2], shogichars["dragon horse"][1], + false, true, 0.93, shogimoves_horse) +theme.black_gold = shogi_piece(shogichars["gold general"][2], shogichars["gold general"][1], + false, false, 0.9, shogimoves_gold) +theme.black_silver = shogi_piece(shogichars["silver general"][2], shogichars["silver general"][1], + false, false, 0.9, shogimoves_silver) +theme.black_p_silver = shogi_piece(shogichars["narikei"][2], shogichars["narikei"][1], + false, true, 0.9, shogimoves_gold) +theme.black_knight = shogi_piece(shogichars["knight"][2], shogichars["knight"][1], + false, false, 0.86, shogimoves_knight) +theme.black_p_knight = shogi_piece(shogichars["narikei"][2], shogichars["narikei"][1], + false, true, 0.86, shogimoves_gold) +theme.black_lance = shogi_piece(shogichars["incense chariot"][2], shogichars["incense chariot"][1], + false, false, 0.83, shogimoves_lance) +theme.black_p_lance = shogi_piece(shogichars["narikyo"][2], shogichars["narikyo"][1], + false, true, 0.83, shogimoves_gold) +theme.black_pawn = shogi_piece(shogichars["pawn"][2], shogichars["pawn"][1], + false, false, 0.8, shogimoves_pawn) +theme.black_p_pawn = shogi_piece(shogichars["tokin"][2], shogichars["tokin"][1], + false, true, 0.8, shogimoves_gold) + +theme.white_king = shogi_piece(shogichars["king"][2], shogichars["king"][1], + true, false, 1, shogimoves_king) +theme.white_rook = shogi_piece(shogichars["flying chariot"][2], shogichars["flying chariot"][1], + true, false, 0.96, shogimoves_rook) +theme.white_p_rook = shogi_piece(shogichars["dragon king"][2], shogichars["dragon king"][1], + true, true, 0.96, shogimoves_dragon) +theme.white_bishop = shogi_piece(shogichars["bishop"][2], shogichars["bishop"][1], + true, false, 0.93, shogimoves_bishop) +theme.white_p_bishop = shogi_piece(shogichars["dragon horse"][2], shogichars["dragon horse"][1], + true, true, 0.93, shogimoves_horse) +theme.white_gold = shogi_piece(shogichars["gold general"][2], shogichars["gold general"][1], + true, false, 0.9, shogimoves_gold) +theme.white_silver = shogi_piece(shogichars["silver general"][2], shogichars["silver general"][1], + true, false, 0.9, shogimoves_silver) +theme.white_p_silver = shogi_piece(shogichars["narikei"][2], shogichars["narikei"][1], + true, true, 0.9, shogimoves_gold) +theme.white_knight = shogi_piece(shogichars["knight"][2], shogichars["knight"][1], + true, false, 0.86, shogimoves_knight) +theme.white_p_knight = shogi_piece(shogichars["narikei"][2], shogichars["narikei"][1], + true, true, 0.86, shogimoves_gold) +theme.white_lance = shogi_piece(shogichars["incense chariot"][2], shogichars["incense chariot"][1], + true, false, 0.83, shogimoves_lance) +theme.white_p_lance = shogi_piece(shogichars["narikyo"][2], shogichars["narikyo"][1], + true, true, 0.83, shogimoves_gold) +theme.white_pawn = shogi_piece(shogichars["pawn"][2], shogichars["pawn"][1], + true, false, 0.8, shogimoves_pawn) +theme.white_p_pawn = shogi_piece(shogichars["tokin"][2],shogichars["tokin"][1], + true, true, 0.8, shogimoves_gold) + +-- Sho Shogi + +theme.black_drunken_elephant = shogi_piece(shogichars["drunken elephant"][2], shogichars["drunken elephant"][1], + false, false, 1, shogimoves_drunken_elephant) +theme.black_p_drunken_elephant = shogi_piece(shogichars["crown prince"][2], shogichars["crown prince"][1], + false, true, 1, shogimoves_king) + +theme.white_drunken_elephant = shogi_piece(shogichars["drunken elephant"][2], shogichars["drunken elephant"][1], + true, false, 1, shogimoves_drunken_elephant) +theme.white_p_drunken_elephant = shogi_piece(shogichars["crown prince"][2], shogichars["crown prince"][1], + true, true, 1, shogimoves_king) + +-- This is part of Dai Shohi + +theme.black_freeking = shogi_piece(shogichars["free king"][2], shogichars["free king"][1], + false, false, 1, shogimoves_freeking) +theme.white_freeking = shogi_piece(shogichars["free king"][2], shogichars["free king"][1], + true, false, 1, shogimoves_freeking) + +-- To be able to adapt this theme to chess too +theme.black_queen = theme.black_freeking +theme.white_queen = theme.white_freeking -- 2.11.4.GIT