/* ZimiGames: the Mahjong tile faces, drawn here (no fonts beyond the system's Latin), shared by Mahjong solitaire and the four-player game. A face is a number 0 to 41: 0-8 circles, 9-17 bamboo, 18-26 characters, 27-30 winds, 31-33 dragons, 34-37 flowers, 38-41 seasons. Our own art, GPL-3.0. No network, no modules. */ (function (root) { 'use strict'; var FIRST_FLOWER = 34, FIRST_SEASON = 38; var NAMES = ['circles', 'bamboo', 'characters']; var WIND = ['East', 'South', 'West', 'North'], DRAGON = ['Red dragon', 'Green dragon', 'White dragon']; var FLOWER = ['Plum', 'Orchid', 'Chrysanthemum', 'Bamboo flower'], SEASON = ['Spring', 'Summer', 'Autumn', 'Winter']; // A tile's name: from the string table when the page has one (mahjong.face.*), in English otherwise (node tests). function tr(id, vars, english) { return root.ZimiText && root.ZimiText.has(id) ? root.ZimiText.T(id, vars) : english; } function faceName(f) { if (f < 27) { var i = (f / 9) | 0; return tr('mahjong.face.number', { n: f % 9 + 1, suit: tr('mahjong.suit.' + i, null, NAMES[i]) }, (f % 9 + 1) + ' of ' + NAMES[i]); } if (f < 31) return tr('mahjong.face.wind', { wind: tr('mahjong.wind.' + (f - 27), null, WIND[f - 27]) }, WIND[f - 27] + ' wind'); if (f < 34) return tr('mahjong.dragon.' + (f - 31), null, DRAGON[f - 31]); return f < FIRST_SEASON ? tr('mahjong.flower.' + (f - FIRST_FLOWER), null, FLOWER[f - FIRST_FLOWER]) : tr('mahjong.season.' + (f - FIRST_SEASON), null, SEASON[f - FIRST_SEASON]); } // The four seasons are drawn as what they are (a sprout, the sun, a leaf, a snowflake), so no word is printed on a tile. var SEASON_ART = [ '', '', '', '' ]; // ── tile faces, drawn here (no fonts beyond the system's Latin) ── var INK = { 0: '#1565c0', 1: '#2e7d32', 2: '#c62828' }; function num(n, color) { return '' + n + ''; } function ring(cx, cy, r, color) { return ''; } function faceMarkup(f) { var s, c; if (f < 27) { var suit = (f / 9) | 0, n = f % 9 + 1; c = INK[suit]; s = num(n, c); if (suit === 0) s += ring(20, 42, 5.6, c); else if (suit === 1) s += ''; else s += ''; } else if (f < 31) { var mark = tr('mahjong4.initial.' + (f - 27), null, 'ESWN'[f - 27]); s = '' + mark + ''; s += ''; } else if (f === 31) { s = ''; } else if (f === 32) { s = ''; } else if (f === 33) { s = ''; } else if (f < FIRST_SEASON) { var k = f - FIRST_FLOWER, col = ['#d81b60', '#8e24aa', '#f9a825', '#43a047'][k]; s = ''; for (var p = 0; p < 5; p++) { var a = p * 1.2566 - 1.5708; s += ''; } s += '' + (k + 1) + ''; } else { var q = f - FIRST_SEASON, sc = ['#2e7d32', '#e65100', '#8d6e63', '#0277bd'][q]; s = SEASON_ART[q].replace(/COL/g, sc) + '' + (q + 1) + ''; } return ''; } root.MahjongTiles = { faceName: faceName, faceMarkup: faceMarkup, FIRST_FLOWER: FIRST_FLOWER, FIRST_SEASON: FIRST_SEASON }; })(typeof globalThis !== 'undefined' ? globalThis : this);