[+] Setting of score rounding and fix bugs

This commit is contained in:
Clansty
2024-08-08 14:49:20 +08:00
parent d0aecc76ed
commit a6a8734599
9 changed files with 106 additions and 8 deletions

View File

@@ -0,0 +1,24 @@
import { onMount } from 'svelte';
const useLocalStorage = <T>(key: string, initialValue: T) => {
let value = initialValue;
const currentValue = localStorage.getItem(key);
if (currentValue) value = JSON.parse(currentValue);
const save = () => {
localStorage.setItem(key, JSON.stringify(value));
};
return {
get value() {
return value;
},
set value(v: T) {
value = v;
save();
},
};
};
export default useLocalStorage;

View File

@@ -137,6 +137,8 @@ export const EN_REF_SETTINGS = {
'settings.fields.waccaInfiniteWp.desc': 'Set WP to 999999',
'settings.fields.waccaAlwaysVip.name': 'Wacca: Always VIP',
'settings.fields.waccaAlwaysVip.desc': 'Set VIP expiration date to 2077-01-01',
'settings.fields.rounding.name': 'Score Rounding',
'settings.fields.rounding.desc': 'Round the score to one decimal place',
'settings.mai2.name': 'Player Name',
'settings.profile.picture': 'Profile Picture',
'settings.profile.upload-new': 'Upload New',

View File

@@ -146,6 +146,8 @@ const zhSettings: typeof EN_REF_SETTINGS = {
'settings.fields.waccaInfiniteWp.desc': '将 WP 设置为 999999',
'settings.fields.waccaAlwaysVip.name': 'Wacca: 永久会员',
'settings.fields.waccaAlwaysVip.desc': '将 VIP 到期时间设置为 2077-01-01',
'settings.fields.rounding.name': '分数舍入',
'settings.fields.rounding.desc': '把分数四舍五入到一位小数',
'settings.mai2.name': '玩家名字',
'settings.profile.picture': '头像',
'settings.profile.upload-new': '上传',

View File

@@ -76,10 +76,10 @@ export function getMult(achievement: number, game: GameName) {
}
export function roundFloor(achievement: number, game: GameName, digits = 2) {
achievement /= 10000
// Round, but if the rounded number reaches the next rank, use floor instead
const mult = getMult(achievement, game);
achievement /= 10000
const rounded = achievement.toFixed(digits);
if (getMult(+rounded, game)[2] === mult[2]) return rounded;
if (getMult(+rounded * 10000, game)[2] === mult[2] && rounded !== '101.0') return rounded;
return (+rounded - Math.pow(10, -digits)).toFixed(digits);
}