Add some helper scripts to modify property values (appendToList, add, invertBoolean)

This commit is contained in:
Emma Broman
2023-02-08 16:00:34 +01:00
parent be122a5a73
commit 2027815157

View File

@@ -1,20 +1,20 @@
openspace.documentation = {
{
Name = "markInterestingNodes",
Arguments = { sceneGraphNode = "[ String ]" },
Arguments = { sceneGraphNodes = "String[]" },
Documentation = "This function marks the scene graph nodes identified by name " ..
"as interesting, which will provide shortcut access to focus buttons and " ..
"as interesting, which will provide shortcut access to focus buttons and " ..
"featured properties"
},
{
Name = "markInterestingTimes",
Arguments = { times = "[ Table ]" },
Arguments = { times = "Table[]" },
Documentation = "This function marks interesting times for the current scene, " ..
"which will create shortcuts for a quick access"
},
{
Name = "removeInterestingNodes",
Arguments = { sceneGraphNode = "[ String ]" },
Arguments = { sceneGraphNodes = "String[]" },
Documentation = "This function removes unmarks the scene graph nodes " ..
"identified by name as interesting, thus removing the shortcuts from the " ..
"features properties list"
@@ -39,6 +39,26 @@ openspace.documentation = {
Arguments = { oldKey = "String", newKey = "String" },
Documentation = "Rebinds all scripts from the old key (first argument) to the " ..
"new key (second argument)"
},
{
Name = "appendToListProperty",
Arguments = { identifier = "String", value = "any" },
Documentation = "Add a value to the list property with the given identifier. " ..
"The value can be any type, as long as it is the correct type for the given " ..
"property. Note that a number will be converted to a string automatically."
},
{
Name = "addToPropertyValue",
Arguments = { identifier = "String", value = "String | Number" },
Documentation = "Add a value to the property with the given identifier. " ..
"Works on both numerical and string properties, where adding to a string " ..
"property means appending the given string value to the existing string value."
},
{
Name = "invertBooleanProperty",
Arguments = { identifier = "String" },
Documentation = "Inverts the value of a boolean property with the given "..
"identifier"
}
}
@@ -82,3 +102,38 @@ openspace.rebindKey = function(oldKey, newKey)
openspace.bindKey(newKey, v)
end
end
openspace.appendToListProperty = function(propertyIdentifier, newItem)
local list = openspace.getPropertyValue(propertyIdentifier)
if type(list) ~= 'table' then
openspace.printError(
"Error when calling script 'openspace.appendToListProperty': " ..
"Could not append to non-list property '" .. propertyIdentifier .. "'"
)
return;
end
table.insert(list, newItem)
openspace.setPropertyValueSingle(propertyIdentifier, list)
end
openspace.addToPropertyValue = function(propertyIdentifier, valueToAdd)
local value = openspace.getPropertyValue(propertyIdentifier)
if type(value) == 'string' then
value = value .. valueToAdd;
else
value = value + valueToAdd;
end
openspace.setPropertyValueSingle(propertyIdentifier, value)
end
openspace.invertBooleanProperty = function(propertyIdentifier)
local value = openspace.getPropertyValue(propertyIdentifier)
if type(value) ~= 'boolean' then
openspace.printError(
"Error when calling script 'openspace.invertBooleanProperty': " ..
"Could not invert non-boolean property '" .. propertyIdentifier .. "'"
)
return;
end
openspace.setPropertyValueSingle(propertyIdentifier, not value)
end