Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 67 additions & 11 deletions src/tracker/ui/Difficulty.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
easing: cubicOut
});

const difficultyBarLevels = {
low: 0.33,
high: 0.66
}

$: {
if ($dif.thresholds.last().minValue > 0) {
difficultyBar.set(
Expand All @@ -27,38 +32,89 @@
)
);
}

// Set low & high thresholds on meter (causes colour change)
// Low: first non-zero XP budget
// High: Second-highest XP budget (highest is off the chart)
// If both are equal, only set one.
if ($dif.thresholds.length > 2) {
difficultyBarLevels.high = $dif.thresholds[$dif.thresholds.length - 2].minValue / $dif.thresholds.last().minValue;
}
for(const threshold of $dif.thresholds) {
if (threshold.minValue / $dif.thresholds.last().minValue >= difficultyBarLevels.high) {
break;
}

if (threshold.minValue > 0) {
difficultyBarLevels.low = threshold.minValue / $dif.thresholds.last().minValue;
break;
}
}

}
$: summary = $dif.difficulty.summary;
</script>

<div class="difficulty-bar-container" aria-label={summary}>
<span>{$dif.labels?.[0] ?? ""}</span>
<span
><meter
class="difficulty-bar"
min="0"
low="0.33"
high="0.66"
low="{difficultyBarLevels.low}"
high="{difficultyBarLevels.high}"
optimum="0"
value={$difficultyBar}
/></span
>
<span>{$dif.labels?.last() ?? ""}</span>
/>
<ol class="thresholds">
{#each $dif.thresholds as level}
<li style="left:calc({level.minValue / $dif.thresholds.last().minValue * 100}% - 1px)">
<span>{level.displayName}</span>
</li>
{/each}
</ol>

</span>
<span>{$dif.difficulty.displayName ?? ""}</span>
</div>

<style>
.difficulty-bar-container {
display: grid;
grid-template-columns: auto 1fr auto;
grid-template-columns: 1fr auto;
gap: 0.5rem;
align-items: center;
align-items: start;
padding: 0 0.5rem;
margin-bottom: 0.5rem;
width: 100%;
}
.difficulty-bar {
width: 100%;
border: 1px solid #ccc;
border-radius: 3px;
border:none;
}

.difficulty-bar-container .thresholds {
list-style-type: none;
margin:0;
padding:0;
position:relative;
height:2rem;
top:-5px;
}

.difficulty-bar-container .thresholds li {
display:inline-block;
border-left:1px solid #ccc;
position:absolute;
width:0px;
height:0.35rem
}

.difficulty-bar-container .thresholds li span {
font-size:x-small;
position:relative;
top: 0.3rem;
text-align:center;
display:inline-block;
width:10em;
left:-5em;
}
</style>