RedCore
Loading...
Searching...
No Matches
ProfileBuilder.h
Go to the documentation of this file.
1#pragma once
2
3#include <actor/ProfileInfo.h>
4#include <basis/seadTypes.h>
5#include <actor/Profile.h>
6#include <telkin/Print.h>
7
8namespace red {
9
10template <size_t N>
12 char mValue[N];
13
14 constexpr ComptimeFixedString(const char (&str)[N]) {
15 for (size_t i = 0; i < N; i++) {
16 mValue[i] = str[i];
17 }
18 }
19
20 constexpr const char* cstr() const {
21 return mValue;
22 }
23};
24
25template <size_t N>
27
28/**
29 * @brief Base class for builder objects that operate on profiles. Tracks which fields were set and holds their data.
30 * @tparam Derived The type of builder which inherits this one. Used for casting for the builder pattern.
31 */
32template <typename Derived> //requires std::derived_from<T, ProfileBuilder>
34public:
35 /**
36 * @brief Set the @c ActorCreateInfo field in the profile.
37 * @return The builder object for chaining calls.
38 */
39 [[nodiscard]]
40 Derived& createInfo(const ActorCreateInfo* createInfo) {
42 tk::println("WARNING: .createInfo() called twice");
43 }
44
46 mCreateInfo = createInfo;
47 return *static_cast<Derived*>(this);
48 }
49
50 /**
51 * @brief Set the @c Flag field in the profile.
52 * @return The builder object for chaining calls.
53 */
54 [[nodiscard]]
55 Derived& flag(const Profile::Flag flag) {
56 if (mFlagModified) {
57 tk::println("WARNING: .flag() called twice");
58 }
59
60 mFlagModified = true;
61 mFlag = flag;
62 return *static_cast<Derived*>(this);
63 }
64
65 /**
66 * @brief Set the @c drawPriority field in the profile.
67 * @return The builder object for chaining calls.
68 */
69 [[nodiscard]]
70 Derived& drawPriority(const s16 drawPriority) {
72 tk::println("WARNING: .drawPriority() called twice");
73 }
74
76 mDrawPriority = drawPriority;
77 return *static_cast<Derived*>(this);
78 }
79
80 /**
81 * @brief Set the @c executePriority field in the profile.
82 * @note This is a custom field added by RedCore.
83 * @return The builder object for chaining calls.
84 */
85 [[nodiscard]]
86 Derived& executePriority(const s16 executePriority) {
88 tk::println("WARNING: .executePriority() called twice");
89 }
90
92 mExecutePriority = executePriority;
93 return *static_cast<Derived*>(this);
94 }
95
96 /**
97 * @brief Set the @c resources field in the profile.
98 * @tparam Args Comma-separated list of string literals representing which resources to load.
99 * @param type At what stage of the game to load these resources.
100 * @return The builder object for chaining calls.
101 */
102 template <ComptimeFixedString... Args> requires (sizeof...(Args) > 0)
103 [[nodiscard]]
105 static sead::SafeString sResources[] = { sead::SafeString(Args.cstr())... };
106 static bool instanciationUsed = false;
107 if (instanciationUsed) {
108 tk::println("WARNING: SafeArray instanciation already used. Might be bad...");
109 }
110 instanciationUsed = true;
111
112 mResourceCount = static_cast<u8>(sizeof...(Args));
115
116 return *static_cast<Derived*>(this);
117 }
118
119protected:
120 const ActorCreateInfo* mCreateInfo = nullptr; ///< The @c createInfo data for the profile we are building.
121 Profile::Flag mFlag = Profile::cFlag_None; ///< The @c flag data for the profile we are building.
122 s16 mDrawPriority = ProfileInfo::cProfileID_Max; ///< The @c drawPriority data for the profile we are building.
123 s16 mExecutePriority = ProfileInfo::cProfileID_Max; ///< The @c createInfo data for the profile we are building. This is a custom field added by RedCore.
124 u8 mResourceCount = 0; ///< The entry for @c ProfileInfo::cResNum for the profile we are building. This is stored separately for custom profiles.
125 sead::SafeString* mResources = nullptr; ///< The entry for @c ProfileInfo::cResList for the profile we are building. This is stored separately for custom profiles.
126 ProfileInfo::ResType mResourceType = ProfileInfo::cResType_Course; ///< The entry for @c ProfileInfo::cResType for the profile we are building. This is stored separately for custom profiles.
127 bool mCreateInfoModified = false; ///< Whether @c mCreateInfo was modified. Used for validation and partial application in @c red::ProfileEditBuilder.
128 bool mFlagModified = false; ///< Whether @c mFlag was modified. Used for validation and partial application in @c red::ProfileEditBuilder.
129 bool mDrawPriorityModified = false; ///< Whether @c mDrawPriority was modified. Used for validation and partial application in @c red::ProfileEditBuilder.
130 bool mExecutePriorityModified = false; ///< Whether @c mExecutePriority was modified. Used for validation and partial application in @c red::ProfileEditBuilder.
131 bool mResourcesModified = false; ///< Whether @c mResources was modified. Used for validation and partial application in @c red::ProfileEditBuilder.
132};
133
134}
Base class for builder objects that operate on profiles. Tracks which fields were set and holds their...
Definition ProfileBuilder.h:33
Profile::Flag mFlag
The flag data for the profile we are building.
Definition ProfileBuilder.h:121
bool mDrawPriorityModified
Whether mDrawPriority was modified. Used for validation and partial application in red::ProfileEditBu...
Definition ProfileBuilder.h:129
sead::SafeString * mResources
The entry for ProfileInfo::cResList for the profile we are building. This is stored separately for cu...
Definition ProfileBuilder.h:125
bool mExecutePriorityModified
Whether mExecutePriority was modified. Used for validation and partial application in red::ProfileEdi...
Definition ProfileBuilder.h:130
s16 mDrawPriority
The drawPriority data for the profile we are building.
Definition ProfileBuilder.h:122
bool mFlagModified
Whether mFlag was modified. Used for validation and partial application in red::ProfileEditBuilder.
Definition ProfileBuilder.h:128
Derived & flag(const Profile::Flag flag)
Set the Flag field in the profile.
Definition ProfileBuilder.h:55
s16 mExecutePriority
The createInfo data for the profile we are building. This is a custom field added by RedCore.
Definition ProfileBuilder.h:123
u8 mResourceCount
The entry for ProfileInfo::cResNum for the profile we are building. This is stored separately for cus...
Definition ProfileBuilder.h:124
bool mCreateInfoModified
Whether mCreateInfo was modified. Used for validation and partial application in red::ProfileEditBuil...
Definition ProfileBuilder.h:127
Derived & drawPriority(const s16 drawPriority)
Set the drawPriority field in the profile.
Definition ProfileBuilder.h:70
Derived & executePriority(const s16 executePriority)
Set the executePriority field in the profile.
Definition ProfileBuilder.h:86
Derived & createInfo(const ActorCreateInfo *createInfo)
Set the ActorCreateInfo field in the profile.
Definition ProfileBuilder.h:40
bool mResourcesModified
Whether mResources was modified. Used for validation and partial application in red::ProfileEditBuild...
Definition ProfileBuilder.h:131
ProfileInfo::ResType mResourceType
The entry for ProfileInfo::cResType for the profile we are building. This is stored separately for cu...
Definition ProfileBuilder.h:126
Definition ActorDonutBlock.h:5
ComptimeFixedString(const char(&)[N]) -> ComptimeFixedString< N >
Definition ProfileBuilder.h:11
constexpr const char * cstr() const
Definition ProfileBuilder.h:20
constexpr ComptimeFixedString(const char(&str)[N])
Definition ProfileBuilder.h:14
char mValue[N]
Definition ProfileBuilder.h:12