File size: 1,833 Bytes
dec56a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { fmtSigned } from '../utils/format.js';

const COMPONENTS = [
  { key: 'base_reward', label: 'Base (prosperity)' },
  { key: 'productivity_bonus', label: 'Productivity bonus' },
  { key: 'survival_bonus', label: 'Survival bonus' },
  { key: 'over_alloc_penalty', label: 'Over-alloc penalty' },
  { key: 'under_alloc_penalty', label: 'Under-alloc penalty' },
  { key: 'critical_penalty', label: 'Critical penalty' },
];

export default function RewardCard({ reward, cumulative }) {
  if (!reward) return null;

  const max = Math.max(
    1,
    ...COMPONENTS.map(c => Math.abs(reward[c.key] || 0)),
  );

  return (
    <div className="card">
      <h3>
        Reward breakdown
        <span className="meta">cum {fmtSigned(cumulative, 1)}</span>
      </h3>
      <div className="body">
        {COMPONENTS.map(({ key, label }) => {
          const v = reward[key] || 0;
          const pct = (Math.abs(v) / max) * 50;
          return (
            <div className="reward-row" key={key}>
              <span className="rname">{label}</span>
              <div className="rbar">
                {v >= 0 ? (
                  <div className="pos" style={{ width: `${pct}%` }} />
                ) : (
                  <div className="neg" style={{ width: `${pct}%` }} />
                )}
              </div>
              <span className="rval" style={{ color: v < 0 ? 'var(--accent-bad)' : v > 0 ? 'var(--accent-good)' : 'var(--text-dim)' }}>
                {fmtSigned(v, 2)}
              </span>
            </div>
          );
        })}
        <div className="reward-total">
          <span>Step total</span>
          <span style={{ color: reward.total < 0 ? 'var(--accent-bad)' : 'var(--accent-good)' }}>
            {fmtSigned(reward.total, 2)}
          </span>
        </div>
      </div>
    </div>
  );
}