Yeah, if you’re not already too attached to Harlowe…here’s the same code for SugarCube:
Story Stylesheet (same as Harlowe)
.statBar {
width: 20em; /* Overall stat-bar width (in 'm' characters) */
background: #fb5; /* Right-side background color */
color: #111; /* Text color */
font-weight: bold;
margin: 0.5ex auto;
position: relative;
}
.statBar div {
position: relative;
z-index: 1;
}
.statBar .statLeftBg {
position: absolute;
top: 0px;
left: 0px;
background: #1a5; /* Left-side background color */
z-index: 0;
}
Story JavaScript (defines <<fair_plus>>)
// <<fair_plus "$stat" _change>>
Macro.add('fair_plus', {
handler: function() {
var percent = State.getVar(this.args[0]), change = this.args[1]
var end = 50 + 50 * Math.sign(change)
percent += Math.abs(change)/100 * (end - percent)
State.setVar(this.args[0], percent)
}
})
passage with widget tag (defines <<opposed_stat>>, <<fair_minus>>)
<<widget "fair_minus">><<fair_plus $args[0] -$args[1]>><</widget>>
<<widget "opposed_stat">><<nobr>>
<div class="statBar">
<div style="float:right"> $args[1] <<= 100-$args[2]>>% </div>
<<= '<div class="statLeftBg" style="width:'+$args[2]+'%"> </div>'>>
<div> $args[0] $args[2]%</div>
</div>
<</nobr>><</widget>>
<!-- Initialize a stat. -->
<<set $Limelight to 50>>
<!-- Change a stat (note that negative values are ok) -->
<<fair_plus "$Limelight" -30>>
<!-- Display a stat bar -->
<<opposed_stat "Limelight" "Shadows" $Limelight>>