66 m_errors.push_back(
"UpdatePreset: ID not found: " +
id);
111std::vector<std::string>
114 std::vector<std::string> result;
121 const std::string& name =
it->second.name;
122 if (name.find(
substring) != std::string::npos)
123 result.push_back(
id);
128std::vector<ConditionPreset>
131 std::vector<ConditionPreset> result;
181 std::ifstream
file(filepath);
184 m_errors.push_back(
"Load: cannot open file: " + filepath);
189 std::string
content((std::istreambuf_iterator<char>(
file)),
190 std::istreambuf_iterator<char>());
200 m_errors.push_back(
"Load: JSON parse error in file: " + filepath);
206 if (!
root.is_object() || !
root.contains(
"presets"))
208 m_errors.push_back(
"Load: missing 'presets' key in: " + filepath);
215 m_errors.push_back(
"Load: 'presets' is not an array in: " + filepath);
244 arr.push_back(
it->second.ToJson());
248 std::ofstream
file(filepath);
251 m_errors.push_back(
"Save: cannot open file for writing: " + filepath);
287 static bool seeded =
false;
290 std::srand(
static_cast<unsigned int>(std::time(
nullptr)));
295 for (
int i = 0;
i < 16; ++
i)
296 b[
i] =
static_cast<unsigned int>(std::rand()) & 0xFF;
298 b[6] = (
b[6] & 0x0F) | 0x40;
299 b[8] = (
b[8] & 0x3F) | 0x80;
301 std::ostringstream
oss;
302 oss << std::hex << std::setfill(
'0');
303 for (
int i = 0;
i < 16; ++
i)
305 if (
i == 4 ||
i == 6 ||
i == 8 ||
i == 10)
307 oss << std::setw(2) <<
b[
i];
310 return "preset_" +
oss.str();
Global registry for ConditionPreset objects, with CRUD, persistence, and validation.
ComponentTypeID GetComponentTypeID_Static()
void LoadFromPresetList(const std::vector< ConditionPreset > &presets)
Loads presets from a vector of ConditionPreset objects (clears existing data first).
size_t GetPresetCount() const
Returns the total number of presets in the registry.
void DeletePreset(const std::string &id)
Removes a preset from the registry.
static std::string GenerateID()
Generates a new UUID suitable for a preset ID.
std::map< std::string, ConditionPreset > m_presets
UUID -> ConditionPreset.
std::vector< std::string > m_order
UUIDs in insertion order.
void UpdatePreset(const std::string &id, const ConditionPreset &updated)
Replaces the data of an existing preset (id must already exist).
void Clear()
Clears all presets and resets error state.
std::vector< std::string > GetAllPresetIDs() const
Returns all preset UUIDs in display order.
bool ValidatePresetID(const std::string &id) const
Returns true when a preset with the given UUID exists.
std::vector< std::string > m_errors
Accumulated error messages.
std::string CreatePreset(const ConditionPreset &preset)
Adds a preset to the registry.
std::string DuplicatePreset(const std::string &id)
Creates an independent copy of an existing preset with a new UUID.
bool Save(const std::string &filepath) const
Saves all presets to a JSON file.
std::vector< ConditionPreset > GetFilteredPresets(const std::string &filter) const
Returns all presets whose name contains the filter substring.
std::vector< std::string > GetAllErrors() const
Returns all error messages accumulated since the last Clear().
bool Load(const std::string &filepath)
Loads presets from a JSON file (clears existing data first).
std::vector< std::string > FindPresetsByName(const std::string &substring) const
Returns UUIDs of all presets whose name contains a substring.
ConditionPreset * GetPreset(const std::string &id)
Returns a mutable pointer to the preset, or nullptr if not found.
< Provides AssetID and INVALID_ASSET_ID
A globally-stored, reusable condition expression.
static ConditionPreset FromJson(const nlohmann::json &data)
Deserializes a ConditionPreset from a JSON object.
std::string id
Global unique UUID (e.g. "preset_001")