Templates - Wieku/danser-go GitHub Wiki

Templates (Statistics)

Description

Templates (Statistics) are custom text components that utilize go's text/template functionality to add display of additional data with possibility to do some basic scripting.

WARNING: Templating is not that performant, so keep components minimal to avoid re-rendering (aka executing) large chunks on each value update.

Basic usage

To utilize stats described below, prepend the stat name with dot (.) encased in double brackets, like {{ .artist }}

Numerical statistics have an option to roll smoothly to final value, similarly to how current pp or score counters work. To do that, use a .statRollX formula where stat is your desired stat (like cStars) and X is a number of decimal points to roll into (like 3). So resulting stat will look like this: .cStarsRoll3. Adding S at the end automatically converts to string (.cStarsRoll3S is an equivalent to .cStarsRoll3 | formatF 3)

To start - open the config editor and scroll down to (almost) the end of Gameplay section or search for statistics, and click the + button. You have an option to control size, color, opacity, position, text alignment, anchoring (anchor BottomRight and Position -100x-100 means the text will be displayed 100 osu!screen pixels away from the bottom right corner). osu!screen size - 1366x768 at 16:9, no matter the resolution you've set. Displayed text uses the HUD Font.

Simple text

Template: Lorem ipsum

Song artist/title/difficulty

Template: {{ .artist }} - {{ .title }} [{{version}}]

Current SR rolled to 3 decimal points

Template: SR: {{formatF 3 .cStarsRoll3}} or SR: {{.cStarsRoll3 | formatF 3}} or SR: {{.cStarsRoll3S}}

Static accuracy up to 2 decimal points with trailing zeros removed

Template: Acc: {{formatF0 2 (mul 100 .acc)}}% or Acc: {{(mul 100 .acc) | formatF0 2}}%

HP bar made of hyphen characters (because why not)

Template: {{"-" | repeat (int (mul .currentHP 50))}}

Stats that can be used:

Statistic Type Description
artist string Artist of the song
title string Title of the song
creator string Creator of the beatmap
version string Difficulty version of the beatmap
baseAR float Base Approach Rate (AR)
realAR float Actual Approach Rate (AR), after DA, EZ/HR and Speed Mods
baseOD float Base Overall Difficulty (OD)
realOD float Actual Overall Difficulty (OD), after DA, EZ/HR and Speed Mods
baseCS float Base Circle Size (CS)
realCS float Actual Circle Size (CS), after Difficulty Adjust
baseHP float Base Health Drain (HP)
realHP float Actual Health Drain (HP), after Difficulty Adjust
avgBPM float Average Beats Per Minute (BPM)
bpm float BPM considering speed modifiers
speed float Speed modifier
timeFromStart int Time from the start of the beatmap
timeToEnd int Time to the end of the beatmap
mods array List of active mods (array of (Acronym, Name) tuples)
modsA string String of active mod acronyms (like HDHRDT)
name string Username
currentHP float Current Health (0 - 1 value)
starsAim float Stars for aiming (Aim)
starsSpeed float Stars for speed (Speed)
starsFL float Stars for Flashlight (FL)
stars float Total number of stars
cStarsAim float Current stars for aiming (Aim)
cStarsSpeed float Current stars for speed (Speed)
cStarsFL float Current stars for Flashlight (FL)
cStars float Current total number of stars
score int Score
countMiss int Number of missed objects
count50 int Number of 50-point hits scored
count100 int Number of 100-point hits scored
count300 int Number of 300-point hits scored
countTicks int Number of slider ticks scored
countSB int Number of slider breaks
maxTicks int Maximum achievable number of slider ticks
countSliderEnds int Number of slider ends scored
maxSliderEnds int Maximum achievable number of slider ends
combo int Current combo
maxCombo int Maximum combo achieved
acc float Accuracy (0 - 1 value)
grade string Grade (D, C, A, S, SH, SS, SSH)
pp float Total Performance Points (PP)
ppAim float PP for aiming (Aim)
ppSpeed float PP for speed (Speed)
ppAcc float PP for accuracy (Accuracy)
ppFL float PP for Flashlight (FL)
fcPP float Full Combo PP
fcPPAim float Full Combo PP for aiming (Aim)
fcPPSpeed float Full Combo PP for speed (Speed)
fcPPAcc float Full Combo PP for accuracy (Accuracy)
fcPPFL float Full Combo PP for Flashlight (FL)
ssPP float SS PP (100% accuracy)
ssPPAim float SS PP for aiming (Aim)
ssPPSpeed float SS PP for speed (Speed)
ssPPAcc float SS PP for accuracy (Accuracy)
ssPPFL float SS PP for Flashlight (FL)
kps int Clicks per second

Functions that can be used:

Conversion Functions

Function Arguments Description
format format string, v ...any Formats a string using fmt.Sprintf rules.
formatF decimals int, v float Converts float to string with a specified number of decimal places.
formatF0 decimals int, v float Converts float to string with a specified number of decimal places, removing trailing zeros.
formatC v int64 Formats an integer into a string with thousand (comma) separators.
formatTime v int Formats a time value (in seconds) into a mm:ss string.
int v float Converts a float to an integer.
float v int Converts an integer to a float.

Text Functions

Function Arguments Description
repeat count int, str string Repeats a string a specified number of times.
lower str string Converts a string to lowercase.
upper str string Converts a string to uppercase.
hasPrefix str, prefix string Checks if a string has a specified prefix.
hasSuffix str, suffix string Checks if a string has a specified suffix.
split str, sep string Splits a string into a slice of substrings.
contains substr, str string Checks if a string contains a specified substring.
title a string Converts a string to title case.
trimSpace str string Trims leading and trailing whitespace from a string.
trimSuffix suffix, str string Trims a specified suffix from a string.
trimPrefix prefix, str string Trims a specified prefix from a string.
padLeft length any, str string Pads a string on the left with spaces to a specified length.
padRight length any, str string Pads a string on the right with spaces to a specified length.
join sep string, v any Joins a slice of strings into a single string with a specified separator.
addS a, b any Concatenates two values as strings.

Slice Functions

Function Arguments Description
list v ...any Creates a slice from a list of values.
append / push list any, v any Appends a value to a slice.
slice list any, indices ...any Slices a slice or array.

Float Math Functions

Function Arguments Description
add a, b int/float Adds two float values.
sub a, b int/float Subtracts one float value from another.
mul a, b int/float Multiplies two float values.
div a, b int/float Divides one float value by another.
pow a, b int/float Raises a float value to the power of another.
sqrt a int/float Calculates the square root of a float value.
round a int/float Rounds a float value to the nearest integer.
roundEven a int/float Rounds a float value to the nearest even integer.
floor a int/float Rounds a float value down to the nearest integer.
ceil a int/float Rounds a float value up to the nearest integer.
abs a int/float Calculates the absolute value of a float.
per a int/float Converts a float value to a percentage.
maxf a int/float, b ...int/float Returns the maximum (float) value from a list of float values.
minf a int/float, b ...int/float Returns the minimum value from a list of float values.
clampf a, b, c int/float Clamps a float value between two bounds.

int values are converted to float to avoid excessive casting.

Integer Math Functions

Function Arguments Description
addi a, b int/float Adds two integer values.
inc i int/float Increments an integer value by 1.
subi a, b int/float Subtracts one integer value from another.
muli a, b int/float Multiplies two integer values.
divi a, b int/float Divides one integer value by another.
modi a, b int/float Calculates the remainder of dividing one integer value by another.
absi a int/float Calculates the absolute value of an integer.
maxi a int/float, b ...int/float Returns the maximum value from a list of integer values.
mini a int/float, b ...int/float Returns the minimum value from a list of integer values.
clampi a, b, c int/float Clamps an integer value between two bounds.

float values are converted to int to avoid excessive casting.