Fix toggleFade for multiple property owners, and add openspace.propertyOwner API function (#3721)

* Add a function for getting all propertyowners matching a certain regex
* Fix broken toggleFade - now works with multiple nodes
* Utilize updated toggle fade function in existing toggle actions
* Make `openspace.propertyOwner` work when only tag is included
* And make toggleFade work in a situation where tag matches both a screenspace renderable and scene graph node
* Remove mistakenly added scene graph node (it is really a screenspace renderable)
* Cleanup property check code to reuse check in both property and propertyowner function
This commit is contained in:
Emma Broman
2025-06-18 18:32:17 +02:00
committed by GitHub
parent b6d3704439
commit b51a3322e2
20 changed files with 334 additions and 296 deletions

View File

@@ -206,49 +206,45 @@ openspace.fadeIn = function(identifier, fadeTime, endScript)
local hasTag, _ = identifier:find("{")
local hasWild, _ = identifier:find("*")
-- Check if the properties exist
local hasEnabled = true
local hasFade = true
if hasTag ~= nil or hasWild ~= nil then
-- Regex, several nodes
local enabledPropertyList = openspace.property(enabledProperty)
if next(enabledPropertyList) == nil then
-- List is empty, no matches found
openspace.printError(
"Error when calling script 'openspace.fadeIn': " ..
"Could not find any property matching '" .. enabledProperty .. "'"
)
return
hasEnabled = false
end
local fadePropertyList = openspace.property(fadeProperty)
if next(fadePropertyList) == nil then
-- List is empty, no matches found
openspace.printError(
"Error when calling script 'openspace.fadeIn': " ..
"Could not find any property matching '" .. fadeProperty .. "'"
)
return
hasFade = false
end
else
-- Literal, single node
local hasEnabled = openspace.hasProperty(enabledProperty)
local hasFade = openspace.hasProperty(fadeProperty)
if not hasEnabled then
openspace.printError(
"Error when calling script 'openspace.fadeIn': " ..
"Could not find property '" .. enabledProperty .. "'"
)
return
elseif not hasFade then
openspace.printError(
"Error when calling script 'openspace.fadeIn': " ..
"Could not find property '" .. fadeProperty .. "'"
)
return
else
hasEnabled = openspace.hasProperty(enabledProperty)
hasFade = openspace.hasProperty(fadeProperty)
if hasEnabled then
isEnabled = openspace.propertyValue(enabledProperty)
end
end
if not hasEnabled then
openspace.printError(
"Error when calling script 'openspace.fadeIn': " ..
"Could not find property '" .. enabledProperty .. "'"
)
return
elseif not hasFade then
openspace.printError(
"Error when calling script 'openspace.fadeIn': " ..
"Could not find property '" .. fadeProperty .. "'"
)
return
end
-- If node is already enabled we only have to fade it
if not isEnabled then
openspace.setPropertyValue(fadeProperty, 0.0)
@@ -273,49 +269,45 @@ openspace.fadeOut = function(identifier, fadeTime, endScript)
local hasTag, _ = identifier:find("{")
local hasWild, _ = identifier:find("*")
-- Check if the properties exist
local hasEnabled = true
local hasFade = true
if hasTag ~= nil or hasWild ~= nil then
-- Regex, several nodes
local enabledPropertyList = openspace.property(enabledProperty)
if next(enabledPropertyList) == nil then
-- List is empty, no matches found
openspace.printError(
"Error when calling script 'openspace.fadeIn': " ..
"Could not find any property matching '" .. enabledProperty .. "'"
)
return
hasEnabled = false
end
local fadePropertyList = openspace.property(fadeProperty)
if next(fadePropertyList) == nil then
-- List is empty, no matches found
openspace.printError(
"Error when calling script 'openspace.fadeIn': " ..
"Could not find any property matching '" .. fadeProperty .. "'"
)
return
hasFade = false
end
else
-- Literal, single node
local hasEnabled = openspace.hasProperty(enabledProperty)
local hasFade = openspace.hasProperty(fadeProperty)
if not hasEnabled then
openspace.printError(
"Error when calling script 'openspace.fadeIn': " ..
"Could not find property '" .. enabledProperty .. "'"
)
return
elseif not hasFade then
openspace.printError(
"Error when calling script 'openspace.fadeIn': " ..
"Could not find property '" .. fadeProperty .. "'"
)
return
else
hasEnabled = openspace.hasProperty(enabledProperty)
hasFade = openspace.hasProperty(fadeProperty)
if hasEnabled then
isEnabled = openspace.propertyValue(enabledProperty)
end
end
if not hasEnabled then
openspace.printError(
"Error when calling script 'openspace.fadeIn': " ..
"Could not find property '" .. enabledProperty .. "'"
)
return
elseif not hasFade then
openspace.printError(
"Error when calling script 'openspace.fadeIn': " ..
"Could not find property '" .. fadeProperty .. "'"
)
return
end
-- If node is already disabled we don't have to do anything
if isEnabled then
local disableScript = "openspace.setPropertyValue('" .. enabledProperty .. "', false)"
@@ -334,17 +326,37 @@ openspace.toggleFade = function(renderable, fadeTime, endScript)
fadeTime = openspace.propertyValue("OpenSpaceEngine.FadeDuration")
end
local enabled = openspace.propertyValue(renderable .. ".Enabled")
local fadeState = openspace.propertyValue(renderable .. ".Fade")
local renderablesList = openspace.propertyOwner(renderable)
if (enabled) then
if (fadeState < 0.5) then
openspace.fadeIn(renderable, fadeTime-(fadeTime*fadeState), endScript)
else
openspace.fadeOut(renderable, fadeTime*fadeState, endScript)
if next(renderablesList) == nil then
-- List is empty, no matches found
openspace.printError(
"Error when calling script 'openspace.toggleFade': " ..
"Could not find any property owner matching '" .. renderable .. "'"
)
return
end
for i = 1, #renderablesList do
local renderable = renderablesList[i]
-- Skip any matches that do not have the properties we need
if openspace.hasProperty(renderable .. ".Enabled") and
openspace.hasProperty(renderable .. ".Fade")
then
local enabled = openspace.propertyValue(renderable .. ".Enabled")
local fadeState = openspace.propertyValue(renderable .. ".Fade")
if (enabled) then
if (fadeState < 0.5) then
openspace.fadeIn(renderable, fadeTime-(fadeTime*fadeState), endScript)
else
openspace.fadeOut(renderable, fadeTime*fadeState, endScript)
end
else
openspace.fadeIn(renderable, fadeTime, endScript)
end
end
else
openspace.fadeIn(renderable, fadeTime, endScript)
end
end