miijs 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +294 -15
- package/amiiboHandler.js +239 -0
- package/index.js +1171 -1394
- package/package.json +1 -1
- package/heightWeightConversion.js +0 -123
package/package.json
CHANGED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// ------------------------------
|
|
2
|
-
// Helpers
|
|
3
|
-
// ------------------------------
|
|
4
|
-
const clamp = (v, min, max) => Math.min(max, Math.max(min, v));
|
|
5
|
-
|
|
6
|
-
// ------------------------------
|
|
7
|
-
// Height (0..127) <-> feet/inches
|
|
8
|
-
// Calibrated so height=64 -> 67 inches exactly.
|
|
9
|
-
// Range: 36" (3'0") .. 84" (7'0").
|
|
10
|
-
// ------------------------------
|
|
11
|
-
const HEIGHT_MIN_IN = 36;
|
|
12
|
-
const HEIGHT_MAX_IN = 84;
|
|
13
|
-
const HEIGHT_RANGE_IN = HEIGHT_MAX_IN - HEIGHT_MIN_IN;
|
|
14
|
-
|
|
15
|
-
// Calibration target: slider mid (64) should be 67"
|
|
16
|
-
const HEIGHT_MID_SLIDER = 64;
|
|
17
|
-
const HEIGHT_MID_IN = 67;
|
|
18
|
-
|
|
19
|
-
// Compute exponent k so that x0^k = y0 (bias curve, invertible)
|
|
20
|
-
const x0 = HEIGHT_MID_SLIDER / 127; // ~0.50394
|
|
21
|
-
const y0 = (HEIGHT_MID_IN - HEIGHT_MIN_IN) / HEIGHT_RANGE_IN; // 31/48 ≈ 0.64583
|
|
22
|
-
const HEIGHT_EXP = Math.log(y0) / Math.log(x0); // ≈ 0.638 (computed once)
|
|
23
|
-
|
|
24
|
-
/** 0..127 -> { feet, inches, totalInches } */
|
|
25
|
-
function miiHeightToFeetInches(heightValue) {
|
|
26
|
-
const hv = clamp(heightValue | 0, 0, 127);
|
|
27
|
-
const x = hv / 127;
|
|
28
|
-
const s = Math.pow(x, HEIGHT_EXP); // calibrated bias
|
|
29
|
-
const inches = HEIGHT_MIN_IN + s * HEIGHT_RANGE_IN;
|
|
30
|
-
|
|
31
|
-
const totalInches = Math.round(inches);
|
|
32
|
-
const feet = Math.floor(totalInches / 12);
|
|
33
|
-
const inchesR = totalInches % 12;
|
|
34
|
-
|
|
35
|
-
return { feet, inches: inchesR, totalInches };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** inches -> 0..127 (inverse of the calibrated mapping) */
|
|
39
|
-
function inchesToMiiHeight(targetInches) {
|
|
40
|
-
const y = clamp((targetInches - HEIGHT_MIN_IN) / HEIGHT_RANGE_IN, 0, 1);
|
|
41
|
-
const x = Math.pow(y, 1 / HEIGHT_EXP);
|
|
42
|
-
return Math.round(x * 127);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// ------------------------------
|
|
46
|
-
// Weight (0..127) + height(0..127) <-> pounds
|
|
47
|
-
// Baseline by BMI; composition slider is nonlinear & invertible.
|
|
48
|
-
// Center (64) -> multiplier 1.0.
|
|
49
|
-
// ------------------------------
|
|
50
|
-
const BMI_AVG = 23.5; // gives ~150 lb at 67"
|
|
51
|
-
const WEIGHT_SPREAD = 0.35; // ±35% around baseline at extremes
|
|
52
|
-
const WEIGHT_GAMMA = 1.6; // steeper near ends, softer center
|
|
53
|
-
|
|
54
|
-
/** weight slider + height slider -> pounds */
|
|
55
|
-
function miiWeightToPounds(weightValue, heightValue) {
|
|
56
|
-
const wv = clamp(weightValue | 0, 0, 127);
|
|
57
|
-
const hv = clamp(heightValue | 0, 0, 127);
|
|
58
|
-
|
|
59
|
-
// Height in inches using the calibrated mapping
|
|
60
|
-
const { totalInches: H } = miiHeightToFeetInches(hv);
|
|
61
|
-
|
|
62
|
-
// BMI baseline
|
|
63
|
-
const base = (BMI_AVG * H * H) / 703;
|
|
64
|
-
|
|
65
|
-
// Nonlinear symmetric multiplier around 1.0 (64 -> 0 offset)
|
|
66
|
-
const d = clamp((wv - 64) / 63, -1, 1);
|
|
67
|
-
const multiplier = 1 + Math.sign(d) * WEIGHT_SPREAD * Math.pow(Math.abs(d), WEIGHT_GAMMA);
|
|
68
|
-
|
|
69
|
-
return Math.round(base * multiplier);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** pounds + height slider -> weight slider (inverse of above) */
|
|
73
|
-
function poundsToMiiWeight(pounds, heightValue) {
|
|
74
|
-
const hv = clamp(heightValue | 0, 0, 127);
|
|
75
|
-
const { totalInches: H } = miiHeightToFeetInches(hv);
|
|
76
|
-
const base = (BMI_AVG * H * H) / 703;
|
|
77
|
-
|
|
78
|
-
// Guard against tiny numeric drift outside the spread
|
|
79
|
-
const mult = clamp(pounds / base, 1 - WEIGHT_SPREAD * 1.0001, 1 + WEIGHT_SPREAD * 1.0001);
|
|
80
|
-
|
|
81
|
-
let d;
|
|
82
|
-
if (Math.abs(mult - 1) < 1e-9) {
|
|
83
|
-
d = 0;
|
|
84
|
-
} else if (mult > 1) {
|
|
85
|
-
d = Math.pow((mult - 1) / WEIGHT_SPREAD, 1 / WEIGHT_GAMMA);
|
|
86
|
-
} else {
|
|
87
|
-
d = -Math.pow((1 - mult) / WEIGHT_SPREAD, 1 / WEIGHT_GAMMA);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const wv = Math.round(64 + 63 * clamp(d, -1, 1));
|
|
91
|
-
return clamp(wv, 0, 127);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// ------------------------------
|
|
95
|
-
// Quick checks (should match your expectations)
|
|
96
|
-
// ------------------------------
|
|
97
|
-
// Average points
|
|
98
|
-
// console.log(miiHeightToFeetInches(64), miiWeightToPounds(64, 64)); // ~5'7", ~150 lb
|
|
99
|
-
// Extremes
|
|
100
|
-
// console.log(miiHeightToFeetInches(0), miiWeightToPounds(0, 0)); // 3'0", ~28 lb
|
|
101
|
-
// console.log(miiHeightToFeetInches(127), miiWeightToPounds(127, 127)); // 7'0", ~318 lb
|
|
102
|
-
// Inverses
|
|
103
|
-
// const h = miiHeightToFeetInches(64);
|
|
104
|
-
// console.log(inchesToMiiHeight(h.totalInches)); // ~64
|
|
105
|
-
// const lbs = miiWeightToPounds(96, 64);
|
|
106
|
-
// console.log(lbs); // ~135
|
|
107
|
-
// console.log(poundsToMiiWeight(lbs, 64)); // ~96
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// ------------------------------
|
|
111
|
-
// Quick sanity checks
|
|
112
|
-
// ------------------------------
|
|
113
|
-
// Average points
|
|
114
|
-
console.log(miiHeightToFeetInches(64), miiWeightToPounds(64, 64)); // ~5'0", ~150 lb
|
|
115
|
-
// // Extremes
|
|
116
|
-
console.log(miiHeightToFeetInches(0), miiWeightToPounds(0, 0));//3'0, 28 lb
|
|
117
|
-
console.log(miiHeightToFeetInches(127), miiWeightToPounds(127, 127));//7'0 318 lb
|
|
118
|
-
// // Inverses
|
|
119
|
-
const h = miiHeightToFeetInches(64);
|
|
120
|
-
console.log(inchesToMiiHeight(h.totalInches)); // ~64
|
|
121
|
-
const lbs = miiWeightToPounds(96, 64);
|
|
122
|
-
console.log(lbs);//168
|
|
123
|
-
console.log(poundsToMiiWeight(lbs, 64)); // ~96
|