Some code for folk who like "riddle-me-this" (lol) kind of deep dives

The related “Game Night Score Keeper” TW instance

At some point, when I figure out how to organize things, I’ll write a series of “in-depth” blog articles. For now, I’ll share some “shoot-from-the-hip” code.

I’m in the midst of some serious code refactoring of this TW instance, setting things up to make it (as much as possible) quick and easy to add scoresheets for new games added to the inventory.

For my efforts, I’ve decided to use the “Jaipur” game for design and test purposes.

Although Jaipur does not have a traditional “game-end score” process (i.e. whatever player had the greatest score wins; in Jaipur, the game winner is whoever wins 2 out 3 rounds), I’m setting up the scoresheet so that folk can choose a “traditional” way of scoring (as in who has the most points after three rounds in this case) if they want to.

The Jaipur scoring sheet is too big for one screenshot, so in 2 parts, followed by the code that defines the score sheet for a Jaipur playthrough:

From the “Jpr” (Jaipur) tiddler:

\define 🏁round(r)
 <<row """<span style="border:1px solid #DC4D01;border-radius: 15px;">🔸Round $r$🔸</span>"""
       """<hr style="border:5px solid #FFCD9B;border-radius: 15px;">""">>
 <<row "🐪 Camels:" """<<sh_input r$r$c🐪>><br>
                        <$let max={{{ [<session>tagging[]get[r$r$c🐪]maxall[]] }}}>
                        {{{ [<session>tagging[]r$r$c🐪<max>join[]match{!!title}then[✅ Camel Bonus !]] || txt }}}
                        </$let>""">>
 <<row "💎 Diamonds:" """<<sh_input r$r$d💎>>""" >>
 <<row "🥇 Gold:" """<<sh_input r$r$g🥇>>""" >>
 <<row "🥈 Silver:" """<<sh_input r$r$s🥈>>""" >>
 <<row "✨ Cloth:" """<<sh_input r$r$c✨>>""" >>
 <<row "🫚 Spice:" """<<sh_input r$r$s🫚>>""" >>
 <<row "👜 Leather:" """<<sh_input r$r$l👜>>""" >>
 <<row "🏆 3 Cards Sold Bonus:" """<<sh_input r$r$3🏆>>""" >>
 <<row "🏆 4 Cards Sold Bonus:" """<<sh_input r$r$4🏆>>""" >>
 <<row "🏆 5 Cards Sold Bonus:" """<<sh_input r$r$5🏆>>""" >>
\end
\define localScoresheet()
<<🏁round 1>>
<<🏁round 2>>
<<🏁round 3>>
\end
\define playerTotal()
 =[{!!title}match<r1c🐪Winner>then[5]]
 =[{!!title}match<r2c🐪Winner>then[5]]
 =[{!!title}match<r3c🐪Winner>then[5]]
 +[join[+]]
\end

<$let r1c🐪Max={{{ [{!!title}tagging[]get[r1c🐪]maxall[]] }}}
      r1c🐪Winner={{{ [{!!title}tagging[]r1c🐪<r1c🐪Max>join[,]]  }}}
      r2c🐪Max={{{ [{!!title}tagging[]get[r2c🐪]maxall[]] }}}
      r2c🐪Winner={{{ [{!!title}tagging[]r2c🐪<r2c🐪Max>join[,]]  }}}
      r3c🐪Max={{{ [{!!title}tagging[]get[r3c🐪]maxall[]] }}}
      r3c🐪Winner={{{ [{!!title}tagging[]r3c🐪<r3c🐪Max>join[,]]  }}}  >
  <<scoreSheet>>
</$let>

Then, from the “Scoresheet Macros” tiddler of global macros:

\define thr(label)
<th class="tar" style="vertical-align:top;">$label$</th>
\end
\define row(label:"label" cellVal)
 <tr><<thr """$label$""">>
  <$list filter="[<players>split[::]]">
   <td style="width:1em;vertical-align:top;">$cellVal$</td> 
  </$list>
 </tr>
\end
\define sh_textarea(fld)
<$edit-text class="stde" tag=textarea tiddler={{!!title}} field={{{ [[$fld$]] +[join[]] }}} disabled=<<🔐p>>/>
\end
\define sh_input(fld)
<$edit-text class="stdi" tag=input tiddler={{!!title}} field={{{ [[$fld$]] +[join[]] }}} disabled=<<🔐p>>/>
\end
\define sh_checkbox(fld val)
<$checkbox field="$fld$" checked="$val$"> Camel Token</$checkbox>
\end
\define scoreSheet()
 <$let session={{!!title}}
       players={{{ [{!!title}tag[s]tagging[]tag[sp]sort[]join[::]] }}}
       🔐p={{!!🔐p}} >
  <div style="max-width:100%;overflow:auto;">
   <table style="text-align:center;">
    <<row "Players:"
          """<$link to={{{ [{!!title}] }}}>
             {{{ [{!!title}tags[]tag[p]] [{!!title}tags[]tag[a]] +[else[???]] +[nth[1]] || lt }}}
          </$link>""">>
    <<localScoresheet>>
    <<row """<hr style="border:4px double black;">TOTAL SCORE:"""
          """<hr style="border:4px double black;">
             <$list variable=f filter={{{ [<playerTotal>!is[blank]else[undefined]] }}} >
             <iframe srcdoc={{{ [[<script> document.write(]] [<f>] [[);</script><body style="font-family:]] [{$:/themes/tiddlywiki/vanilla/settings/fontfamily}] [[;font-weight:bold;font-size:1.5em;text-align:center;"></body>]] +[join[]] }}} style="height:3.25em;border:3px double black;overflow:hidden;">
             </iframe></$list>""">>
   </table>
  </div>
 </$let>
\end

If a picture is worth a thousand words …

Just to clarify a couple of points.

The updates I’ve made this afternoon reflect a couple of things.

These scoresheets I’m working on, they aren’t making any attempt to identify who won a game.

Who won, that is left up to the players because folk can devise all sorts of home rules for any game in regards to winning conditions.

Jaipur-specific:

  • I’ve added round totals, so that folk can determine the winner of a round when playing by the “winning conditions” official rule (i.e. the game winner is the one who won 2 of 3 rounds)
  • I’m repeating the “players” header above the second and third round “breakpoints” because just the one header at the top scrolls out of view

image