Etterna 0.74.4
Loading...
Searching...
No Matches
StepsUtil.h
1#ifndef STEPS_UTIL_H
2#define STEPS_UTIL_H
3
4#include "Etterna/Models/Misc/Difficulty.h"
5#include "Etterna/Models/Misc/GameConstantsAndTypes.h"
6#include "RageUtil/Utils/RageUtil_CachedObject.h"
7
8class Steps;
9class Song;
10class Profile;
11class XNode;
12
15{
16 public:
18 Song* pSong{ nullptr };
20 Steps* pSteps{ nullptr };
23 SongAndSteps() = default;
29 SongAndSteps(Song* pSong_, Steps* pSteps_)
30 : pSong(pSong_)
31 , pSteps(pSteps_)
32 {
33 }
39 auto operator==(const SongAndSteps& other) const -> bool
40 {
41 return pSong == other.pSong && pSteps == other.pSteps;
42 }
48 auto operator<(const SongAndSteps& other) const -> bool
49 {
50 if (pSong != other.pSong) {
51 return pSong < other.pSong;
52 }
53 return pSteps < other.pSteps;
54 }
55};
56
58namespace StepsUtil {
59auto
60CompareNotesPointersByRadarValues(const Steps* pSteps1, const Steps* pSteps2)
61 -> bool;
62auto
63CompareNotesPointersByMeter(const Steps* pSteps1, const Steps* pSteps2) -> bool;
64auto
65CompareNotesPointersByDifficulty(const Steps* pSteps1, const Steps* pSteps2)
66 -> bool;
67void
68SortNotesArrayByDifficulty(std::vector<Steps*>& vpStepsInOut);
69auto
70CompareStepsPointersByTypeAndDifficulty(const Steps* pStep1,
71 const Steps* pStep2) -> bool;
72void
73SortStepsByTypeAndDifficulty(std::vector<Steps*>& vpStepsInOut);
74void
75SortStepsPointerArrayByNumPlays(std::vector<Steps*>& vpStepsInOut,
76 ProfileSlot slot,
77 bool bDescending);
78void
79SortStepsPointerArrayByNumPlays(std::vector<Steps*>& vpStepsInOut,
80 const Profile* pProfile,
81 bool bDescending);
82auto
83CompareStepsPointersByDescription(const Steps* pStep1, const Steps* pStep2)
84 -> bool;
85void
86SortStepsByDescription(std::vector<Steps*>& vpStepsInOut);
87} // namespace StepsUtil
88
90{
91 StepsType st{ StepsType_Invalid };
92 Difficulty dc{ Difficulty_Invalid };
93 std::string ck;
94 std::string sDescription;
95 unsigned uHash{ 0 };
96 mutable CachedObjectPointer<Steps> m_Cache;
97
98 public:
105 : sDescription("")
106 {
107 }
108 void Unset() { FromSteps(nullptr); }
109 void FromSteps(const Steps* p);
110 auto ToSteps(const Song* p, bool bAllowNull) const -> Steps*;
111 // FIXME: (interferes with unlimited charts per song)
112 // When performing comparisons, the hash value 0 is considered equal to
113 // all other values. This is because the hash value for a Steps is
114 // discarded immediately after loading and figuring out a way to preserve
115 // and cache it turned into a mess that still didn't work.
116 // When scores are looked up by the theme, the theme passes in a Steps
117 // which is transformed into a StepsID, which is then used to index into a
118 // map. So when the theme goes to look up the scores for a Steps, the
119 // Steps has a hash value of 0, unless it has been played. But when the
120 // scores are saved, the Steps has a correct hash value. So before a
121 // Steps is played, the scores could not be correctly accessed. This was
122 // only visible on Edit charts because scores on all other difficulties
123 // are saved without a hash value.
124 // Making operator< and operator== treat 0 as equal to all other hash
125 // values allows the theme to fetch the scores even though the Steps has
126 // a cleared hash value, but is not a good long term solution because the
127 // description field isn't always going to be unique.
128 // -Kyz
129 auto operator<(const StepsID& rhs) const -> bool;
130 auto operator==(const StepsID& rhs) const -> bool;
131 auto MatchesStepsType(StepsType s) const -> bool { return st == s; }
132
133 auto CreateNode() const -> XNode*;
134 void LoadFromNode(const XNode* pNode);
135 auto ToString() const -> std::string;
136 auto IsValid() const -> bool;
137
138 auto GetStepsType() const -> StepsType { return st; }
139 auto GetDifficulty() const -> Difficulty { return dc; }
140 auto GetKey() const -> std::string { return ck; }
141 auto GetDescription() const -> std::string
142 {
143 return (dc == Difficulty_Edit ? sDescription : std::string());
144 }
145 auto GetHash() const -> unsigned { return uHash; }
146};
147
148#endif
Definition RageUtil_CachedObject.h:117
Player data that persists between sessions.
Definition Profile.h:130
A Song and one of its Steps.
Definition StepsUtil.h:15
SongAndSteps()=default
Set up a blank Song and Step.
auto operator<(const SongAndSteps &other) const -> bool
Compare two sets of Songs and Steps to see if they are not equal.
Definition StepsUtil.h:48
auto operator==(const SongAndSteps &other) const -> bool
Compare two sets of Songs and Steps to see if they are equal.
Definition StepsUtil.h:39
SongAndSteps(Song *pSong_, Steps *pSteps_)
Set up the specified Song and Step.
Definition StepsUtil.h:29
Steps * pSteps
the Steps we're using.
Definition StepsUtil.h:20
Song * pSong
the Song we're using.
Definition StepsUtil.h:18
Holds all music metadata and steps for one song.
Definition Song.h:65
Definition StepsUtil.h:90
StepsID()
Set up the StepsID with default values.
Definition StepsUtil.h:104
Holds note information for a Song.
Definition Steps.h:42
Definition XmlFile.h:95
Utility functions for working with Steps.
Definition StepsUtil.h:58