6
6
#define NOS_SETTINGS_SUBSYSTEM_H_INCLUDED
7
7
#include " Nodos/Types.h"
8
8
9
- typedef enum nosSettingsFileDirectory {
10
- NOS_SETTINGS_FILE_DIRECTORY_LOCAL , // Module's root folder
11
- NOS_SETTINGS_FILE_DIRECTORY_WORKSPACE , // Engine's config folder
12
- NOS_SETTINGS_FILE_DIRECTORY_GLOBAL // AppData folder
13
- } nosSettingsFileDirectory ;
14
-
15
- typedef nosResult (* nosPfnSettingsItemUpdate )(const char * entryName , nosBuffer itemValue );
9
+ // NOS_RESULT_SUCCESS: Item value will be serialized to the WriteDirectories
10
+ // NOS_RESULT_FAIL: Default item value will be serialized to the WriteDirectories
11
+ typedef nosResult (*nosPfnSettingsEntryUpdate)(const char * entryName, nosBuffer itemValue);
12
+ typedef uint64_t nosSettingsEntryId;
16
13
17
14
#if NOS_HAS_CPLUSPLUS_20
18
- #include "EditorEvents_generated.h"
19
- typedef nos ::sys ::settings ::editor ::SettingsEditorItem nosSettingsEditorItem ;
15
+ typedef nos::fb::Visualizer* nosSettingsEditorVisualizer;
20
16
#else
21
- typedef void * nosSettingsEditorItem ;
17
+ typedef void * nosSettingsEditorVisualizer ;
22
18
#endif
23
19
24
20
typedef struct nosSettingsEntryParams {
25
21
nosName TypeName;
26
- nosBuffer Buffer ; // Don't forget to free this buffer
22
+ // Default value of the buffer
23
+ // If nosPfnSettingsEntryUpdate callback returns NOS_SETTINGS_ENTRY_NON_COMPATIBLE, this will be saved
24
+ // Don't forget to free this buffer
25
+ nosBuffer DefaultValueBuffer;
27
26
const char * EntryName; // If NULL, "default" will be used
28
- nosSettingsFileDirectory Directory ;
27
+ nosPfnSettingsEntryUpdate UpdateCallback; // Callback to update the entry value
28
+ nosSettingsEditorVisualizer Visualizer; // Visualizer for the entry in editor
29
+ const char * DisplayName;
30
+ // Target module name, editor can decide where to place this entry
31
+ // For example, if this is "nos.sys.device", editor can place this entry under "Devices" section
32
+ const char * UiTargetName;
29
33
} nosSettingsEntryParams;
30
34
31
35
typedef struct nosSettingsSubsystem
32
36
{
33
- // parameters->directory will be set to found directory
34
- // if parameters->typeName == 0, it will be set to first typename found in the closest file
35
- // parameters->directory is ignored because closest one is chosen
36
- nosResult (NOSAPI_CALL * ReadSettingsEntry )(nosSettingsEntryParams * parameters );
37
- // parameters->typeName should be a valid typename
38
- // if parameters->directory is not set, it will be set to NOS_SETTINGS_FILE_DIRECTORY_LOCAL
39
- nosResult (NOSAPI_CALL * WriteSettingsEntry )(const nosSettingsEntryParams * parameters );
40
-
41
-
42
- // Editor related functions
43
-
44
- nosResult (NOSAPI_CALL * RegisterEditorSettings )(u64 itemCount , const nosSettingsEditorItem * * itemList , nosPfnSettingsItemUpdate itemUpdateCallback , nosSettingsFileDirectory saveDirectory );
45
- nosResult (NOSAPI_CALL * UnregisterEditorSettings )( );
37
+ nosResult (NOSAPI_CALL *RegisterEntry)(const nosSettingsEntryParams* parameters);
38
+ nosResult (NOSAPI_CALL* UpdateEntryValue)(const char * entryName, nosBuffer value);
39
+ // An entry can only be unregistered by the plugin it's registered from
40
+ void (NOSAPI_CALL* UnregisterEntry)(const char * entryName);
46
41
} nosSettingsSubsystem;
47
42
48
43
#pragma region Helper Declarations & Macros
49
44
// Make sure these are same with nossys file.
50
45
#define NOS_SETTINGS_SUBSYSTEM_NAME " nos.sys.settings"
51
46
52
- #define NOS_SETTINGS_SUBSYSTEM_VERSION_MAJOR 0
53
- #define NOS_SETTINGS_SUBSYSTEM_VERSION_MINOR 10
47
+ #define NOS_SETTINGS_SUBSYSTEM_VERSION_MAJOR 1
48
+ #define NOS_SETTINGS_SUBSYSTEM_VERSION_MINOR 0
54
49
55
50
extern struct nosPluginInfo nosSettingsModuleInfo;
56
51
extern nosSettingsSubsystem* nosSettings;
@@ -61,6 +56,43 @@ extern nosSettingsSubsystem* nosSettings;
61
56
62
57
#define NOS_SETTINGS_IMPORT () NOS_IMPORT_DEP(NOS_SETTINGS_SUBSYSTEM_NAME, nosSettingsModuleInfo, nosSettings)
63
58
59
+ #if NOS_HAS_CPLUSPLUS_20
60
+ #include " Types_generated.h"
61
+ #include < Nodos/Name.hpp>
62
+
63
+ namespace nos ::sys::settings {
64
+ inline nosResult RegisterEntry (std::string const & entryName, std::string const & typeName, nosPfnSettingsEntryUpdate updateCallback, std::optional<nosBuffer> defaultVal = std::nullopt, std::optional<std::string> displayName = std::nullopt, std::optional<std::string> targetName = std::nullopt, std::optional<nos::fb::TVisualizer> visualizer = std::nullopt) {
65
+ nosSettingsEntryParams params{};
66
+ params.EntryName = entryName.empty () ? NULL : entryName.c_str ();
67
+ params.TypeName = nos::Name (typeName);
68
+ params.UpdateCallback = updateCallback;
69
+
70
+ if (displayName.has_value () && !displayName->empty ())
71
+ params.DisplayName = displayName->c_str ();
72
+ else
73
+ params.DisplayName = params.EntryName ;
74
+
75
+ if (defaultVal.has_value ())
76
+ params.DefaultValueBuffer = *defaultVal;
77
+
78
+ if (targetName.has_value () && !targetName->empty ())
79
+ params.UiTargetName = targetName->c_str ();
80
+
81
+ nos::Buffer visualizerBuf;
82
+ if (visualizer.has_value ()) {
83
+ visualizerBuf = nos::Buffer::From (*visualizer);
84
+ params.Visualizer = visualizerBuf.As <nos::fb::Visualizer>();
85
+ }
86
+
87
+ return nosSettings->RegisterEntry (¶ms);
88
+ }
89
+
90
+ inline void UnregisterEntry (std::string const & entryName) {
91
+ nosSettings->UnregisterEntry (entryName.c_str ());
92
+ }
93
+ }
94
+ #endif // NOS_HAS_CPLUSPLUS_20
95
+
64
96
#pragma endregion
65
97
66
98
0 commit comments