Files
OpenSpace/data/assets/util/property_helper.asset
T
Alexander Bock df68ab557d * Rudimentary fix to make side_by_side stereo work in master
* Fix Triton asset file
 * Display an error if no Property matches a regex in setPropertyValue
 * Correct user-facing name for some Moon assets
 * Add fade in and fade out helping functions
 * Reenable label fading in New Horizons
 * Added GUI hint to hide uninteresting nodes
 * Set Hidden Hint on barycenter nodes
2018-03-17 16:54:42 -04:00

51 lines
2.0 KiB
Plaintext

-- Function that returns the string that inverts the fully qualified boolean property 'property'
local invert = function(prop)
local escaped_property = "'" .. prop .. "'"
return "openspace.setPropertyValue(" .. escaped_property .. ", not openspace.getPropertyValue(" .. escaped_property .. "));"
end
-- Function that returns the string that increments the 'property' by the 'value'
local increment = function(prop, value)
local v = value or 1
local escaped_property = "'" .. prop .. "'"
return "openspace.setPropertyValue(" .. escaped_property .. ", openspace.getPropertyValue(" .. escaped_property .. ") + " .. v .. ");"
end
-- Function that returns the string that decrements the 'property' by the 'value'
local decrement = function(prop, value)
return increment(prop, -value)
end
local fade = function(prop, value, duration)
assert(type(prop) == "string", "prop must be a number")
assert(type(duration) == "number", "duration must be a number")
local escaped_property = "'" .. prop .. "'"
return "openspace.setPropertyValue(" .. escaped_property ..", " .. tostring(value) .. ", " .. tostring(duration) .. ")"
end
local fadeOut = function(prop, duration)
return fade(prop, 0.0, duration)
end
local fadeIn = function(prop, duration)
return fade(prop, 1.0, duration)
end
local fadeInOut = function(prop, duration)
assert(type(prop) == "string", "prop must be a number")
assert(type(duration) == "number", "duration must be a number")
local escaped_property = "'" .. prop .. "'"
-- If the value is > 0.5 fade out, otherwise fade in
return "local v = openspace.getPropertyValue(" .. escaped_property .. "); if v <= 0.5 then " .. fadeIn(prop, duration) .. " else " .. fadeOut(prop, duration) .. " end"
end
asset.export('invert', invert)
asset.export('increment', increment)
asset.export('decrement', decrement)
asset.export('fade', fade)
asset.export('fadeIn', fadeIn)
asset.export('fadeOut', fadeOut)
asset.export('fadeInOut', fadeInOut)