1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Refactor pinned shapes and make them smart, closes #72

This commit is contained in:
tobspr
2020-06-12 18:38:13 +02:00
parent 8c01cc23d0
commit 3af6532d32
11 changed files with 215 additions and 56 deletions

View File

@@ -377,7 +377,23 @@ export function findNiceValue(num) {
return 0;
}
const roundAmount = 0.5 * Math_pow(10, Math_floor(Math_log10(num) - 1));
let roundAmount = 1;
if (num > 50000) {
roundAmount = 10000;
} else if (num > 20000) {
roundAmount = 5000;
} else if (num > 5000) {
roundAmount = 1000;
} else if (num > 2000) {
roundAmount = 500;
} else if (num > 1000) {
roundAmount = 100;
} else if (num > 100) {
roundAmount = 20;
} else if (num > 20) {
roundAmount = 5;
}
const niceValue = Math_floor(num / roundAmount) * roundAmount;
if (num >= 10) {
return Math_round(niceValue);
@@ -389,6 +405,8 @@ export function findNiceValue(num) {
return Math_round(niceValue * 100) / 100;
}
window.fn = findNiceValue;
/**
* Finds a nice integer value
* @see findNiceValue