Files
OpenSpace/data/assets/util/slide_deck_helper.asset
Alexander Bock 705c898ccd Asset File cleanup (#2713)
* Updating all assets to new coding style
* Cleaning up asset files
* Moving default_actions and default_keybindings files
* Changing procedural globes to explicitly specified globes
* Move Spice loading explicitly to the initialize part and also deinitialize
* Removing unused asset files
  * Removing asset_helper
  * Removing scale_model_helper asset
  * Removing script_scheduler_helper
  * Removing testing_keybindings
  * Remove procedural_globe
2023-05-28 17:23:20 +02:00

105 lines
2.8 KiB
Lua

function createDeck(identifier, defaultRenderableProperties)
return {
SlideIdentifiers = {},
IdentifierPrefix = identifier,
CurrentSlideIndex = 1,
DefaultRenderableProperties = defaultRenderableProperties,
Visible = true
}
end
function removeDeck(deck)
for i, identifier in pairs(deck.SlideIdentifiers) do
openspace.removeScreenSpaceRenderable(identifier)
end
end
function addSlide(deck, path)
local index = #deck.SlideIdentifiers + 1
local identifier = deck.IdentifierPrefix .. index
local spec = {
Type = "ScreenSpaceImageLocal",
Identifier = identifier,
Name = identifier,
TexturePath = path
}
for key, value in pairs(deck.DefaultRenderableProperties) do
spec[key] = value
end
openspace.addScreenSpaceRenderable(spec)
deck.SlideIdentifiers[#deck.SlideIdentifiers + 1] = identifier
end
function setCurrentSlide(deck, index, interpolationDuration)
if (interpolationDuration == nil) then
interpolationDuration = 0
end
if (index < 0) then
index = 0
end
if (index > #deck.SlideIdentifiers + 1) then
index = #deck.SlideIdentifiers + 1
end
deck.CurrentSlideIndex = index
if not deck.Visible then
return
end
for i, identifier in pairs(deck.SlideIdentifiers) do
local opacity = 0
if (index == i) then
opacity = 1
end
if interpolationDuration == 0 then
openspace.setPropertyValueSingle("ScreenSpace." .. identifier .. ".Opacity", opacity)
else
openspace.setPropertyValueSingle("ScreenSpace." .. identifier .. ".Opacity", opacity, interpolationDuration, "QuadraticEaseOut")
end
end
end
function goToNextSlide(deck, interpolationDuration)
setCurrentSlide(deck, deck.CurrentSlideIndex + 1, interpolationDuration)
end
function goToPreviousSlide(deck, interpolationDuration)
setCurrentSlide(deck, deck.CurrentSlideIndex - 1, interpolationDuration)
end
function toggleSlides(deck, interpolationDuration)
deck.Visible = not deck.Visible
if deck.Visible then
for i, identifier in pairs(deck.SlideIdentifiers) do
local opacity = 0
if (i == deck.CurrentSlideIndex) then
opacity = 1
end
openspace.setPropertyValueSingle(
"ScreenSpace." .. identifier .. ".Opacity", opacity,
interpolationDuration, "QuadraticEaseOut")
end
else
for i, identifier in pairs(deck.SlideIdentifiers) do
openspace.setPropertyValueSingle(
"ScreenSpace." .. identifier .. ".Opacity", 0,
interpolationDuration, "QuadraticEaseOut")
end
end
end
asset.export("createDeck", createDeck)
asset.export("removeDeck", removeDeck)
asset.export("addSlide", addSlide)
asset.export("setCurrentSlide", setCurrentSlide)
asset.export("goToNextSlide", goToNextSlide)
asset.export("goToPreviousSlide", goToPreviousSlide)
asset.export("toggleSlides", toggleSlides)