From e7deec7acc1e29b60f02312be64bbe2bd0f22780 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 1 Jun 2024 18:12:59 +0200 Subject: track which deck a card comes from in log show deck as tinted background color with shift key --- play.js | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'play.js') diff --git a/play.js b/play.js index 2e54aec..1d6f3bb 100644 --- a/play.js +++ b/play.js @@ -133,6 +133,8 @@ function to_suit(c) { } function to_value(c) { + if (to_suit(c) === 4) + return 10 return c & 15 } @@ -930,12 +932,26 @@ const colorize_H = '\u2665' const colorize_D = '\u2666' const colorize_R = '$1R' +const colorize_1 = '$1' +const colorize_2 = '$1' +const colorize_3 = '$1' +const colorize_4 = '$1' +const colorize_5 = '$1' + function colorize(text) { + text = text.replace(/1\^(\d+[\u2660\u2663\u2665\u2666R])/g, colorize_1) + text = text.replace(/2\^(\d+[\u2660\u2663\u2665\u2666R])/g, colorize_2) + text = text.replace(/3\^(\d+[\u2660\u2663\u2665\u2666R])/g, colorize_3) + text = text.replace(/4\^(\d+[\u2660\u2663\u2665\u2666R])/g, colorize_4) + text = text.replace(/5\^(\d+[\u2660\u2663\u2665\u2666R])/g, colorize_5) + text = text.replace(/(\d+)R/g, colorize_R) text = text.replaceAll("\u2660", colorize_S) text = text.replaceAll("\u2663", colorize_C) text = text.replaceAll("\u2665", colorize_H) text = text.replaceAll("\u2666", colorize_D) - text = text.replace(/(\d+)R/g, colorize_R) + +/* + */ return text } @@ -1242,6 +1258,22 @@ function sub_space(_match, p1) { return `${n}` } +const suit_icon = [ + '\u2660', + '\u2663', + '\u2665', + '\u2666', + 'R', +] + +function sub_tc(_match, p1) { + let c = p1 | 0 + let d = to_deck(c) + let v = to_value(c) + let s = to_suit(c) + return `${v}${suit_icon[s]}` +} + function on_log(text) { let p = document.createElement("div") @@ -1264,9 +1296,10 @@ function on_log(text) { text = text.replace(//g, ">") + text = colorize(text) text = text.replace(/S(\d+)/g, sub_space) text = text.replace(/P(\d+)/g, sub_piece) - text = colorize(text) + text = text.replace(/C(\d+)/g, sub_tc) if (text.match(/^\$(\d+)/)) { let fx = parseInt(text.substring(1)) -- cgit v1.2.3