From 33d817f394a85c774b506cca3457ad9254f3b1f9 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Thu, 16 Oct 2025 19:47:05 -0500 Subject: [PATCH] feat(component): add ComponentValidateBase --- src/component/Util.cpp | 24 ++++++++++++++++++++++++ src/component/Util.hpp | 2 ++ 2 files changed, 26 insertions(+) diff --git a/src/component/Util.cpp b/src/component/Util.cpp index 9baedf7..e73dcc3 100644 --- a/src/component/Util.cpp +++ b/src/component/Util.cpp @@ -127,3 +127,27 @@ int32_t BuildComponentArray(uint32_t varArrayLength, st_race** varArrayPtr) { return 1; } + +int32_t ComponentValidateBase(st_race* varArray, int32_t raceId, int32_t sexId, COMPONENT_VARIATIONS sectionIndex, int32_t variationIndex, int32_t colorIndex) { + if (sectionIndex >= NUM_COMPONENT_VARIATIONS || variationIndex < 0) { + return 0; + } + + auto& section = varArray[(raceId * UNITSEX_NUM_SEXES + sexId)].sections[sectionIndex]; + + if (variationIndex >= section.variationCount || section.variationCount == 0) { + return 0; + } + + if (colorIndex < 0) { + return 0; + } + + auto& variation = section.variationArray[variationIndex]; + + if (colorIndex >= variation.colorCount || variation.colorCount == 0) { + return 0; + } + + return 1; +} diff --git a/src/component/Util.hpp b/src/component/Util.hpp index 21e44db..bff6a00 100644 --- a/src/component/Util.hpp +++ b/src/component/Util.hpp @@ -28,4 +28,6 @@ struct st_variation { int32_t BuildComponentArray(uint32_t varArrayLength, st_race** varArrayPtr); +int32_t ComponentValidateBase(st_race* varArray, int32_t raceId, int32_t sexId, COMPONENT_VARIATIONS sectionIndex, int32_t variationIndex, int32_t colorIndex); + #endif