the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "NumberFormaters.h"
3#include "StatFormatter.h"
4#include "Stats.h"
5#include "Stat.h"
6
7Stat::DefaultFormat *Stat::defaultFormatter = new DefaultFormat();
8Stat::TimeFormatter *Stat::timeFormatter = new TimeFormatter();
9Stat::DistanceFormatter *Stat::distanceFormatter = new DistanceFormatter();
10
11// 4J Stu - Changed this to take in a printf format string instead
12DecimalFormat *Stat::decimalFormat = new DecimalFormat(L"%0(3).2f");
13
14void Stat::_init()
15{
16 awardLocallyOnly = false;
17}
18
19Stat::Stat(int id, const wstring& name, StatFormatter *formatter) : id(id), name(name), formatter(formatter)
20{
21 _init();
22}
23
24Stat::Stat(int id, const wstring& name) : id(id), name(name), formatter(defaultFormatter)
25{
26 _init();
27}
28
29Stat *Stat::setAwardLocallyOnly()
30{
31 awardLocallyOnly = true;
32 return this;
33}
34
35Stat *Stat::postConstruct()
36{
37 //if (Stats::statsById->containsKey(id))
38 //{
39 //throw new RuntimeException("Duplicate stat id: \"" + Stats::statsById->get(id)->name + "\" and \"" + name + "\" at id " + id); 4J - TODO
40 //}
41 Stats::all->push_back(this);
42
43 pair<int, Stat *> id1(id,this);
44#ifdef __PS3__
45 Stats::statsById->emplace(id1 );// assert(0); // MGH - TODO - FIX - find out where this move function comes from
46#else
47 Stats::statsById->emplace( move(id1) );
48#endif // __PS3__
49
50 return this;
51}
52
53bool Stat::isAchievement()
54{
55 return false;
56}
57
58wstring Stat::format(int value)
59{
60 return ((StatFormatter *)formatter)->format(value);
61}
62
63wstring Stat::toString()
64{
65 return name;
66}
67
68wstring Stat::TimeFormatter::format(int value)
69{
70 double seconds = value / 20.0;
71 double minutes = seconds / 60.0;
72 double hours = minutes / 60.0;
73 double days = hours / 24.0;
74 double years = days / 365.0;
75
76 if (years > 0.5)
77 {
78 return decimalFormat->format(years) + L" y";
79 }
80 else if (days > 0.5)
81 {
82 return decimalFormat->format(days) + L" d";
83 }
84 else if (hours > 0.5)
85 {
86 return decimalFormat->format(hours) + L" h";
87 }
88 else if (minutes > 0.5)
89 {
90 return decimalFormat->format(minutes) + L" m";
91 }
92
93 return _toString<double>(seconds) + L" s";
94}
95
96wstring Stat::DefaultFormat::format(int value)
97{
98 return NumberFormat::format( value ); //numberFormat->format(value);
99}
100
101wstring Stat::DistanceFormatter::format(int cm)
102{
103 double meters = cm / 100.0;
104 double kilometers = meters / 1000.0;
105
106 if (kilometers > 0.5)
107 {
108 return decimalFormat->format(kilometers) + L" km";
109
110 } else if (meters > 0.5)
111 {
112 return decimalFormat->format(meters) + L" m";
113 }
114 return _toString<int>(cm) + L" cm";
115}