Etterna 0.74.4
Loading...
Searching...
No Matches
Profile.h
1#ifndef Profile_H
2#define Profile_H
3
4#include "Etterna/Models/Misc/DateTime.h"
5#include "Etterna/Models/Misc/GameConstantsAndTypes.h"
6#include "Etterna/Models/Misc/Grade.h"
7#include "Etterna/Models/HighScore/HighScore.h"
8#include "Etterna/Models/Lua/LuaReference.h"
9#include "Etterna/Models/Songs/SongUtil.h" // for SongID
10#include "Etterna/Models/StepsAndStyles/StepsUtil.h" // for StepsID
11#include "Etterna/Models/StepsAndStyles/StyleUtil.h" // for StyleID
12#include "Etterna/Models/Misc/XMLProfile.h"
13#include "Etterna/Models/Misc/DBProfile.h"
14#include "arch/LoadingWindow/LoadingWindow.h"
15
16#include <map>
17#include <set>
18
19#include <unordered_map>
20
21class XNode;
22struct lua_State;
23struct Playlist;
24
25// Current file versions
26extern const std::string ETT_XML;
27
35extern const std::string EDITABLE_INI;
36
47extern const std::string DONT_SHARE_SIG;
48
49extern const std::string PUBLIC_KEY_FILE;
50extern const std::string SCREENSHOTS_SUBDIR;
51extern const std::string REPLAY_SUBDIR;
52extern const std::string EDIT_STEPS_SUBDIR;
53extern const std::string LASTGOOD_SUBDIR;
54// extern const std::string RIVAL_SUBDIR;
55
57const unsigned int PROFILE_MAX_DISPLAY_NAME_LENGTH = 64;
58
59class Style;
60
61class Song;
62class Steps;
63struct Game;
64
65// future goalman stuff - Mina
67{
68 public:
69 float oldrate = 1.F;
70 float rate = 1.F;
71 float percent = .93F;
72 float oldpercent = .93F;
73 int priority = 1;
74 bool achieved = false;
75 DateTime timeassigned;
76 DateTime timeachieved;
77 std::string comment;
78 std::string chartkey;
79
80 // which specific score was this goal achieved by, reminder to consider
81 // what happens when individual score deletion is possibly added -mina
82 std::string scorekey;
83
84 [[nodiscard]] auto CreateNode() const -> XNode*;
85 void LoadFromNode(const XNode* pNode);
86
87 [[nodiscard]] auto GetPBUpTo() const -> HighScore*;
88
89 auto DebugString() const -> std::string
90 {
91 return "(ScoreGoal ck: " + chartkey +
92 ", rate: " + std::to_string(rate) +
93 ", oldrate: " + std::to_string(oldrate) +
94 ", percent: " + std::to_string(percent) +
95 ", oldpercent: " + std::to_string(oldpercent) +
96 ", achieved: " + std::to_string(achieved) +
97 ", dtassigned: " + timeassigned.GetString() + ")";
98 }
99
100 // If the scoregoal has already been completed prior to being assigned, flag
101 // it as a vacuous goal
102 void CheckVacuity();
103
104 void UploadIfNotVacuous();
105 void ReUploadIfNotVacuous();
106
107 // Vacuous goals will remain in memory for the session but not be written
108 // during save -mina
109 bool vacuous = false;
110
111 void PushSelf(lua_State* L);
112};
113
115{
116 public:
117 void Add(ScoreGoal& sg) { goals.emplace_back(sg); }
118 auto Get() -> std::vector<ScoreGoal>& { return goals; }
119 std::vector<ScoreGoal> goals;
120
121 [[nodiscard]] auto CreateNode() const -> XNode*;
122 void LoadFromNode(const XNode* pNode);
123};
124
130{
131 public:
136 // When adding new score related data, add logic for handling it to
137 // MergeScoresFromOtherProfile. -Kyz
138 // When adding any new fields, add them to SwapExceptPriority. Anything not
139 // added to SwapExceptPriority won't be swapped correctly when the user
140 // changes the list priority of a profile. -Kyz
142 : m_sGuid(MakeGuid())
143 {
144 m_lastSong.Unset();
145 m_fPlayerRating = 0.F;
146 FOREACH_ENUM(Skillset, ss)
147 m_fPlayerSkillsets[ss] = 0.F;
148
149 m_LastPlayedDate.Init();
150 m_lastRankedChartkeyCheck.Init();
151
152 FOREACH_ENUM(Difficulty, i)
153 m_iNumSongsPlayedByDifficulty[i] = 0;
154 for (auto& i : m_iNumSongsPlayedByMeter) {
155 i = 0;
156 }
157
158 ZERO(m_iNumStagesPassedByGrade);
159 m_UserTable.Unset();
160 }
161
162 // smart accessors
163 auto GetDisplayNameOrHighScoreName() const -> std::string;
164 auto GetDefaultModifiers(const Game* pGameType,
165 std::string& sModifiersOut) const -> bool;
166 void SetDefaultModifiers(const Game* pGameType,
167 const std::string& sModifiers);
168
169 void AddStepTotals(int iNumTapsAndHolds,
170 int iNumJumps,
171 int iNumHolds,
172 int iNumRolls,
173 int iNumMines,
174 int iNumHands,
175 int iNumLifts);
176
177 // Profiles of the same type and priority are sorted by dir name.
178 int m_ListPriority{ 0 };
179 // Profile Playlists
180 std::map<std::string, Playlist> allplaylists;
181
182 // Editable data
183 std::string m_sDisplayName;
184 // Dont edit this. Should be unique (Is it?)
185 std::string m_sProfileID;
192
193 // General data
194 static auto MakeGuid() -> std::string;
195 auto GetGuid() -> std::string* { return &m_sGuid; }
196 std::string m_sGuid;
197 std::map<std::string, std::string> m_sDefaultModifiers;
198 SortOrder m_SortOrder{ SortOrder_Invalid };
199 Difficulty m_LastDifficulty{ Difficulty_Invalid };
200 StepsType m_LastStepsType{ StepsType_Invalid };
201 SongID m_lastSong;
202 int m_iCurrentCombo{ 0 };
203 int m_iTotalSessions{ 0 };
204 int m_iTotalSessionSeconds{ 0 };
205 int m_iTotalGameplaySeconds{ 0 };
206 int m_iTotalDancePoints{ 0 };
207 int m_iNumExtraStagesPassed{ 0 };
208 int m_iNumExtraStagesFailed{ 0 };
209 int m_iNumToasties{ 0 };
210 int m_iTotalTapsAndHolds{ 0 };
211 int m_iTotalJumps{ 0 };
212 int m_iTotalHolds{ 0 };
213 int m_iTotalRolls{ 0 };
214 int m_iTotalMines{ 0 };
215 int m_iTotalHands{ 0 };
216 int m_iTotalLifts{ 0 };
217 float m_fPlayerRating;
218 float m_fPlayerSkillsets[NUM_Skillset]{};
220 bool m_bNewProfile{ false };
221
222 // seriously why is this not a thing -mina
223 std::string profiledir;
224 bool IsEtternaProfile{ false };
231 mutable std::string m_sLastPlayedMachineGuid;
232 mutable DateTime m_LastPlayedDate;
233 mutable DateTime m_lastRankedChartkeyCheck;
234 /* These stats count twice in the machine profile if two players are
235 * playing; that's the only approach that makes sense for ByDifficulty and
236 * ByMeter. */
237 std::map<StyleID, int> m_iNumSongsPlayedByStyle;
238 int m_iNumSongsPlayedByDifficulty[NUM_Difficulty]{};
239 int m_iNumSongsPlayedByMeter[MAX_METER + 1]{};
245 int m_iNumStagesPassedByGrade[NUM_Grade]{};
246
247 // if anymore of these are added they should be enum'd to reduce copy pasta
248 // -mina and also should be sets
249 void AddToFavorites(const std::string& ck) { FavoritedCharts.emplace(ck); }
250 void AddToPermaMirror(const std::string& ck)
251 {
252 PermaMirrorCharts.emplace(ck);
253 }
254 void RemoveFromFavorites(const std::string& ck);
255 void RemoveFromPermaMirror(const std::string& ck);
256 std::set<std::string> FavoritedCharts;
257 std::set<std::string> PermaMirrorCharts;
258
259 // more future goalman stuff -mina
260 bool AddGoal(const std::string& ck);
261 void RemoveGoal(const std::string& ck, DateTime assigned);
262 bool LoadGoalIfNew(ScoreGoal goal);
263 std::unordered_map<std::string, GoalsForChart> goalmap;
264 void FillGoalTable();
265 std::vector<ScoreGoal*> goaltable;
266 int sortmode = 1; // 1=date 2=rate 3=name 4=priority 5=diff, init to name
267 // because that's the default- mina
268 int filtermode = 1; // 1=all, 2=completed, 3=uncompleted
269 bool asc = false;
270
271 auto HasGoal(const std::string& ck) const -> bool
272 {
273 return goalmap.count(ck) == 1;
274 }
275 auto GetLowestGoalForRate(const std::string& ck, float rate) -> ScoreGoal&;
276 void SetAnyAchievedGoals(const std::string& ck,
277 float& rate,
278 const HighScore& pscore);
279
280 /* store arbitrary data for the theme within a profile */
281 LuaTable m_UserTable;
282
283 // this actually does use scoreman atm
284 auto GetBestGrade(const Song* song, StepsType st) const -> Grade;
285 auto GetBestWifeScore(const Song* song, StepsType st) const -> float;
286
287 // Screenshot Data
288 std::vector<Screenshot> m_vScreenshots;
289 void AddScreenshot(const Screenshot& screenshot);
290 int GetNextScreenshotIndex() const { return static_cast<int>(m_vScreenshots.size()); }
291
292 // Init'ing
293 void InitAll()
294 {
295 InitEditableData();
296 InitGeneralData();
297 InitScreenshotData();
298 }
299 void InitEditableData();
300 void InitGeneralData();
301 void InitScreenshotData();
302 void ClearStats();
303
304 void swap(Profile& other);
305
306 // Loading and saving
307 void HandleStatsPrefixChange(std::string dir);
308 auto LoadAllFromDir(const std::string& sDir, LoadingWindow* ld)
309 -> ProfileLoadResult;
310 auto LoadStatsFromDir(std::string dir, bool require_signature)
311 -> ProfileLoadResult;
312 void LoadTypeFromDir(const std::string& dir);
313 void LoadCustomFunction(const std::string& sDir);
314 auto SaveAllToDir(const std::string& sDir) const -> bool;
315
316 auto LoadEditableDataFromDir(const std::string& sDir) -> ProfileLoadResult;
317
318 void SaveTypeToDir(const std::string& dir) const;
319 void SaveEditableDataToDir(const std::string& sDir) const;
320
321 void CalculateStatsFromScores(LoadingWindow* ld);
322 void CalculateStatsFromScores();
323
324 void SaveStatsWebPageToDir(const std::string& sDir) const;
325
326 static void MoveBackupToDir(const std::string& sFromDir,
327 const std::string& sToDir);
328 static auto MakeUniqueFileNameNoExtension(
329 const std::string& sDir,
330 const std::string& sFileNameBeginning) -> std::string;
331 static auto MakeFileNameNoExtension(const std::string& sFileNameBeginning,
332 int iIndex) -> std::string;
333
334 // Lua
335 void PushSelf(lua_State* L);
336
337 private:
338 XMLProfile XMLProf;
339 DBProfile DBProf;
340};
341
342#endif
Definition DBProfile.h:20
Opens and displays the loading banner.
Definition LoadingWindow.h:9
Definition LuaReference.h:105
Player data that persists between sessions.
Definition Profile.h:130
bool m_bNewProfile
Is this a brand new profile?
Definition Profile.h:220
std::string m_sLastPlayedMachineGuid
Which machine did we play on last, based on the Guid?
Definition Profile.h:231
Profile()
Set up the Profile with default values.
Definition Profile.h:141
int m_iNumTotalSongsPlayed
Count the total number of songs played.
Definition Profile.h:244
std::string m_sLastUsedHighScoreName
The last used name for high scoring purposes.
Definition Profile.h:191
Definition Profile.h:67
Definition SongUtil.h:186
Holds all music metadata and steps for one song.
Definition Song.h:65
Holds note information for a Song.
Definition Steps.h:42
Definition Style.h:22
Definition XMLProfile.h:11
Definition XmlFile.h:95
A standard way of determining the date and the time.
Definition DateTime.h:81
auto GetString() const -> std::string
Retrieve a string representation of the current date and time.
Definition DateTime.cpp:115
void Init()
Initialize the date and time.
Definition DateTime.cpp:16
Holds information about a particular style of a game (e.g. "single", "double").
Definition Game.h:33
Definition Profile.h:115
The high score that is earned by a player.
Definition HighScore.h:18
Definition Difficulty.h:63
the picture taken of the high score.
Definition HighScore.h:241