Enable the selection of constellation bounds through the mod file

This commit is contained in:
Alexander Bock
2017-07-29 01:57:16 -04:00
parent ad5ca816a9
commit c04b379520
3 changed files with 52 additions and 4 deletions
@@ -1,3 +1,8 @@
local zodiacs = {
"Cancer", "Taurus", "Pisces", "Aries", "Libra", "Aquarius", "Capricornus", "Scorpius",
"Virgo", "Sagittarius", "Gemini", "Leo"
}
return {
-- Stars module
{
@@ -6,7 +11,8 @@ return {
Renderable = {
Type = "RenderableConstellationBounds",
File = "${OPENSPACE_DATA}/scene/constellationbounds/data/bound_20.dat",
ConstellationFile = "${OPENSPACE_DATA}/scene/constellationbounds/data/constellations.dat"
ConstellationFile = "${OPENSPACE_DATA}/scene/constellationbounds/data/constellations.dat",
-- ConstellationSelection = zodiacs
},
Transform = {
Rotation = {
@@ -44,6 +44,11 @@ public:
void removeOptions();
const std::vector<Option>& options() const;
using TemplateProperty<std::vector<int>>::operator std::vector<int>;
using TemplateProperty<std::vector<int>>::operator=;
private:
static const std::string OptionsKey;
std::string generateAdditionalDescription() const;
@@ -158,10 +158,47 @@ RenderableConstellationBounds::RenderableConstellationBounds(
addProperty(_distance);
fillSelectionProperty();
_constellationSelection.onChange([this]() { selectionPropertyHasChanged(); });
addProperty(_constellationSelection);
_constellationSelection.onChange(
[this]() { selectionPropertyHasChanged(); }
);
if (dictionary.hasKey(SelectionInfo.identifier)) {
const ghoul::Dictionary selection = dictionary.value<ghoul::Dictionary>(
SelectionInfo.identifier
);
std::vector<properties::SelectionProperty::Option> options =
_constellationSelection.options();
std::vector<int> selectedIndices;
for (int i = 1; i <= selection.size(); ++i) {
const std::string s = selection.value<std::string>(std::to_string(i));
auto it = std::find_if(
options.begin(),
options.end(),
[&s](const properties::SelectionProperty::Option& o) {
return o.description == s;
}
);
if (it == options.end()) {
// The user has specified a constellation name that doesn't exist
LWARNINGC(
"RenderableConstellationBounds",
"Option '" << s << "' not found in list of constellations"
);
}
else {
// If the found the option, we push the index of the found value into the
// array
selectedIndices.push_back(static_cast<int>(
std::distance(options.begin(), it)
));
}
}
_constellationSelection = selectedIndices;
}
}
void RenderableConstellationBounds::initialize() {