asset.require("./trail")
local transforms = asset.require("../transforms")
local kernel = asset.require("../kernels")



local labelsPath = asset.syncedResource({
  Name = "Saturn Labels",
  Type = "HttpSynchronization",
  Identifier = "saturn_labels",
  Version = 1
})


local Tethys = {
  Identifier = "Tethys",
  Parent = transforms.SaturnBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "TETHYS",
      Observer = "SATURN BARYCENTER"
    },
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "IAU_TETHYS",
      DestinationFrame = "GALACTIC"
    }
  },
  Renderable = {
    Type = "RenderableGlobe",
    Radii = 531100,
    SegmentsPerPatch = 64,
    Layers = {},
    Labels = {
      Enabled = false,
      FileName = labelsPath .. "tethys.labels",
      AlignmentOption = "Horizontally", -- or Circularly
      FontSize = 20.0,
      Size = 8.3,
      FadeInEnabled = true,
      FadeOutEnabled = true,
      FadeDistances = { 500000.0, 1500000.0 },
      DistanceEPS = 200000.0,
      Color = { 1.0, 1.0, 0.0 }
    }
  },
  Tag = { "moon_solarSystem", "moon_giants", "moon_saturn" },
  GUI = {
    Path = "/Solar System/Planets/Saturn/Major Moons/Tethys"
  }
}

local TethysLabel = {
  Identifier = "TethysLabel",
  Parent = Tethys.Identifier,
  Renderable = {
    Enabled = false,
    Type = "RenderableLabel",
    Text = "Tethys",
    FontSize = 70.0,
    Size = 6.0,
    MinMaxSize = { 1, 25 },
    OrientationOption = "Camera View Direction",
    BlendMode = "Normal",
    EnableFading = true,
    FadeUnit = "Gm",
    FadeDistances = { 0.3, 10.0 },
    FadeWidths = { 0.15, 10.0 }
  },
  Tag = { "solarsystem_labels", "moon_labels", "major_moon_labels", "moon_major_saturn" },
  GUI = {
    Name = "Tethys Label",
    Path = "/Solar System/Planets/Saturn/Major Moons/Tethys",
    Description = "Label for Saturn's moon Tethys"
  }
}


asset.onInitialize(function()
  openspace.spice.loadKernel(kernel.sat441)

  openspace.addSceneGraphNode(Tethys)
  openspace.addSceneGraphNode(TethysLabel)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(TethysLabel)
  openspace.removeSceneGraphNode(Tethys)

  openspace.spice.unloadKernel(kernel.sat441)
end)

asset.export(Tethys)
asset.export(TethysLabel)



asset.meta = {
  Name = "Tethys",
  Version = "1.0",
  Description = "Tethys globe with labels",
  Author = "OpenSpace Team",
  URL = "http://openspaceproject.com",
  License = "MIT license"
}
