-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
33 scorecard #130
base: master
Are you sure you want to change the base?
33 scorecard #130
Changes from 6 commits
71f8609
60bb2b4
6888f42
4d4b59e
47cea77
509e67a
2c172cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,172 @@ | ||||||
{% load mathfilters %} | ||||||
<div class="text-center"> | ||||||
<canvas id="statcard" width="400" height="600"></canvas> | ||||||
</div> | ||||||
<script> | ||||||
function getLines(ctx, text, maxWidth) { | ||||||
let words = text.split(" "); | ||||||
let lines = []; | ||||||
let currentLine = words[0]; | ||||||
|
||||||
for (let i = 1; i < words.length; i++) { | ||||||
let word = words[i]; | ||||||
let width = ctx.measureText(currentLine + " " + word).width; | ||||||
if (width < maxWidth) { | ||||||
currentLine += " " + word; | ||||||
} else { | ||||||
lines.push(currentLine); | ||||||
currentLine = word; | ||||||
} | ||||||
} | ||||||
lines.push(currentLine); | ||||||
return lines; | ||||||
} | ||||||
|
||||||
const canvas = document.getElementById('statcard') | ||||||
const context = canvas.getContext('2d') | ||||||
const nodec = '{{ score.comment }}'.includes('No Dec/WO') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is unreliable. We could just display 0s for them (it's saved as 0 in the DB in that case anyway). BTW, there's also option to disable just WO ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left this on purpose as this comment is not that uncommon to gray it out. On every other outcome it's just 0 and working properly |
||||||
let diffColor | ||||||
switch ('{{ score.song.chart_info.diff }}') { | ||||||
case 'Beginner': | ||||||
diffColor = '#a355b8' | ||||||
break | ||||||
case 'Easy': | ||||||
diffColor = '#1ec51d' | ||||||
break | ||||||
case 'Medium': | ||||||
diffColor = '#d6db41' | ||||||
break | ||||||
case 'Hard': | ||||||
diffColor = '#ba3049' | ||||||
break | ||||||
case 'Challenge': | ||||||
diffColor = '#2691c5' | ||||||
break | ||||||
default: | ||||||
diffColor = '#ffffff' | ||||||
break | ||||||
} | ||||||
|
||||||
barWidth = 306 | ||||||
|
||||||
const sum = parseInt('{{ score.total_steps }}') | ||||||
const p = parseInt('{{ score.fantastics_plus }}') / sum * barWidth; | ||||||
const f = parseInt('{{ score.fantastics }}') / sum * barWidth; | ||||||
const e = parseInt('{{ score.excelents }}') / sum * barWidth; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
const g = parseInt('{{ score.greats }}') / sum * barWidth; | ||||||
const d = parseInt('{{ score.decents }}') / sum * barWidth; | ||||||
const w = parseInt('{{ score.wayoffs }}') / sum * barWidth; | ||||||
const m = parseInt('{{ score.misses }}') / sum * barWidth; | ||||||
|
||||||
context.fillStyle = '#000000' | ||||||
context.fillRect(0, 0, 400, 600) | ||||||
|
||||||
context.fillStyle = diffColor | ||||||
context.fillRect(47, 127, 65, 65) | ||||||
|
||||||
context.textAlign = 'center' | ||||||
if ('{{score.song.gs_ranked}}' === 'True') { | ||||||
context.fillStyle = '#38abb5' | ||||||
context.fillRect(350, 20, 30, 30) | ||||||
context.fillStyle = '#ffffff' | ||||||
context.font = '30px miso' | ||||||
context.fillText('GS', 365, 45) | ||||||
|
||||||
} | ||||||
|
||||||
context.strokeStyle = '#ffffff' | ||||||
context.rect(47, 210, 306, 30); | ||||||
context.stroke() | ||||||
|
||||||
let start = 47 | ||||||
context.fillStyle = '#21cce8' | ||||||
context.fillRect(start, 210, p, 30) | ||||||
start += p || 0 | ||||||
context.fillStyle = '#e0e0e0' | ||||||
context.fillRect(start, 210, f, 30) | ||||||
start += f || 0 | ||||||
context.fillStyle = '#e29c18' | ||||||
context.fillRect(start, 210, e, 30) | ||||||
start += e || 0 | ||||||
context.fillStyle = '#66c955' | ||||||
context.fillRect(start, 210, g, 30) | ||||||
start += g || 0 | ||||||
context.fillStyle = '#6365c9' | ||||||
context.fillRect(start, 210, d, 30) | ||||||
start += d || 0 | ||||||
context.fillStyle = '#e08c36' | ||||||
context.fillRect(start, 210, w, 30) | ||||||
start += w || 0 | ||||||
context.fillStyle = '#ff0000' | ||||||
context.fillRect(start, 210, m, 30) | ||||||
|
||||||
context.fillStyle = '#000000' | ||||||
context.font = '80px Wendy' | ||||||
context.fillText('{{ score.song.chart_info.diff_number }}' || '?', 86, 180) | ||||||
context.font = '30px Wendy' | ||||||
context.fillStyle = '#ffffff' | ||||||
if('{{ score.song.chart_info.steps_type}}'.includes('single')) context.fillText('SINGLE', 81, 123) | ||||||
if('{{ score.song.chart_info.steps_type}}'.includes('double')) context.fillText('DOUBLE', 81, 123) | ||||||
|
||||||
context.font = '50px miso' | ||||||
context.fillText('BoogieStats', 200, 45) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could get rid of the big branding at the top, there's a smaller one in the footer that's also a full address which might be more useful for getting new people on |
||||||
context.font = '18px miso' | ||||||
context.fontWeight = '500' | ||||||
context.fillText(`Played by {{ score.player.name }}`, 200, 70) | ||||||
context.fillText('on {{ score.submission_date }}', 200, 85) | ||||||
context.fillText('{{ song.chart_info.pack_name }}', 270, 200) | ||||||
context.font = '30px miso' | ||||||
context.fontWeight = '700' | ||||||
|
||||||
const lines = getLines(context, '{{ score.song.chart_info.title }}' || '{{ score.song.hash }}', 260) | ||||||
lines.forEach((line, i) => { | ||||||
context.fillText(line, 270, 170 - (lines.length * 20) + (i * 20)) | ||||||
}) | ||||||
context.font = '19px miso' | ||||||
context.fillText('{{ score.song.chart_info.artist }}', 270, 170) | ||||||
context.fillText('{{ score.song.chart_info.pack_name }}'.replace(''', `'`), 270, 190) | ||||||
|
||||||
context.font = '30px miso' | ||||||
context.textAlign = 'right' | ||||||
|
||||||
if (nodec) { | ||||||
context.fillStyle = 'gray' | ||||||
} | ||||||
context.fillText('DECENT', 190, 400) | ||||||
context.fillText('WAY OFF', 190, 440) | ||||||
|
||||||
context.fillStyle = '#ffffff' | ||||||
context.fillText('FANTASTIC', 190, 280) | ||||||
context.fillText('EXCELENT', 190, 320) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
context.fillText('GREAT', 190, 360) | ||||||
context.fillText('MISS', 190, 480) | ||||||
|
||||||
context.font = '50px Wendy' | ||||||
context.textAlign = 'left' | ||||||
context.fillStyle = '#21cce8' | ||||||
context.fillText(`${parseInt('{{ score.fantastics_plus }}') + parseInt('{{ score.fantastics }}')}`, 210, 283) | ||||||
context.fillStyle = '#e29c18' | ||||||
context.fillText('{{ score.excellents }}', 210, 323) | ||||||
context.fillStyle = '#66c955' | ||||||
context.fillText('{{ score.greats }}', 210, 363) | ||||||
context.fillStyle = nodec ? 'gray' : '#6365c9' | ||||||
context.fillText('{{ score.decents }}', 210, 403) | ||||||
context.fillStyle = nodec ? 'gray' : '#e08c36' | ||||||
context.fillText('{{ score.way_offs }} ', 210, 443) | ||||||
context.fillStyle = '#ff0000' | ||||||
context.fillText('{{ score.misses }} ', 210, 483) | ||||||
|
||||||
context.fillStyle = '#ffffff' | ||||||
context.font = '140px Wendy' | ||||||
context.textAlign = 'center' | ||||||
context.fillText('{{ score.itg_score|div:100|stringformat:".2f" }}', 200, 570) | ||||||
|
||||||
context.font = '40px Wendy' | ||||||
context.textAlign = 'right' | ||||||
context.fillText('EX', 355, 540) | ||||||
context.textAlign = 'center' | ||||||
context.fillText('{{ score.ex_score|div:100|stringformat:".2f" }}', 350, 570) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
||||||
context.font = '15px miso' | ||||||
context.fillText('boogiestats.andr.host', 200, 590) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should take it from the user's request, the domain can change any time + this codebase is open -- anyone can take it and host for themselves. See how it's done on the user manual page for filling configuration snippets. |
||||||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather avoid basing on external resources. Could we vendor these fonts? What are the licenses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Miso license, source:fontsquirell
L I C E N S E I N F O R M A T I O N
———————————————————-
You can use MISO for free.
You can share MISO with your friends
as long as you include this text file.
You are NOT permitted to sell MISO.
As for wendy: could by unlicensed as most pages skip that part but one page mentions:
EN: Only available for testing the font. Non-commercial and reproduction prohibited. Please contact the author for official purchase of use.
Could be boilerplate, needs doublecheck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a real issue because the fonts don't load reliably as described on PDGC. When browser cache is disabled they never display properly.