asset.require("spice/base")



local TexturesPath = asset.syncedResource({
  Type = "HttpSynchronization",
  Name = "Streamnodes textures",
  Identifier = "streamnodes_legend",
  Version = 1
})


local Legend = {
  Identifier = "LegendFluxNodes-bastille-day-2000",
  Type = "ScreenSpaceImageLocal",
  TexturePath = TexturesPath .. "CMR_transparent_white_text.png",
  Scale = 0.15,
  CartesianPosition = { 0.677970, 0.0, -1.049180 },
  Rotation = { 0.0, 0.0, 0.56652 }
}

local ToggleLegend = {
  Identifier = "os.bastilleday.fluxnodelegend.ToggleLegend",
  Name = "Toggle the legend image",
  Command = [[
    if openspace.getPropertyValue("ScreenSpace.LegendFluxNodes-bastille-day-2000.Enabled") then
      openspace.setPropertyValueSingle(
        "ScreenSpace.LegendFluxNodes-bastille-day-2000.Fade",
        0.0,
        openspace.getPropertyValue("OpenSpaceEngine.FadeDuration"),
        "Linear",
        'openspace.setPropertyValueSingle("ScreenSpace.LegendFluxNodes-bastille-day-2000.Enabled", false)'
      )
    else
      openspace.setPropertyValueSingle("ScreenSpace.LegendFluxNodes-bastille-day-2000.Enabled", true)
      openspace.setPropertyValueSingle(
        "ScreenSpace.LegendFluxNodes-bastille-day-2000.Fade",
        1.0,
        openspace.getPropertyValue("OpenSpaceEngine.FadeDuration"),
        "Linear"
      )
    end
  ]],
  Documentation = "Toggle the legend image",
  GuiPath = "/Bastille-Day 2000",
  IsLocal = false
}

local HideLegend = {
  Identifier = "os.bastilleday.fluxnodelegend.HideLegend",
  Name = "Hides the legend image",
  Command = [[
    openspace.setPropertyValueSingle(
      "ScreenSpace.LegendFluxNodes-bastille-day-2000.Fade",
      0.0,
      openspace.getPropertyValue("OpenSpaceEngine.FadeDuration"),
      "Linear",
      'openspace.setPropertyValueSingle("ScreenSpace.LegendFluxNodes-bastille-day-2000.Enabled", false)'
    )
  ]],
  Documentation = "Hides the legend image",
  GuiPath = "/Bastille-Day 2000",
  IsLocal = false
}


asset.onInitialize(function()
  openspace.addScreenSpaceRenderable(Legend)
  openspace.action.registerAction(ToggleLegend)
  openspace.action.registerAction(HideLegend)
end)

asset.onDeinitialize(function()
  openspace.action.removeAction(HideLegend)
  openspace.action.removeAction(ToggleLegend)
  openspace.removeScreenSpaceRenderable(Legend)
end)

asset.export(Legend)
asset.export("ToggleLegend", ToggleLegend.Identifier)
asset.export("HideLegend", HideLegend.Identifier)



asset.meta = {
  Name = "Predictive Science Inc. Flux nodes legend for Bastille Days",
  Version = "1.1",
  Description = [[Screen space renderable image legend of flux nodes for the bastille day
    CME event]],
  Author = "Christian Adamsson, Emilie Ho",
  URL = "https://dx.doi.org/10.3847/1538-4357/aab36d",
  License = "MIT"
}
