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



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


local Europa = {
  Identifier = "Europa",
  Parent = transforms.JupiterBarycenter.Identifier,
  Transform = {
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "IAU_EUROPA",
      DestinationFrame = "GALACTIC"
    },
    Translation = {
      Type = "SpiceTranslation",
      Target = "EUROPA",
      Observer = "JUPITER BARYCENTER"
    }
  },
  Renderable = {
    Type = "RenderableGlobe",
    Radii = 1560800,
    SegmentsPerPatch = 64,
    Layers = {},
    Labels = {
      Enabled = false,
      FileName = labelsPath .. "europa.labels",
      AlignmentOption = "Horizontally", -- or Circularly
      FontSize = 20.0,
      Size = 11.0,
      FadeInEnabled = true,
      FadeOutEnabled = true,
      FadeDistances = { 500000.0, 8000000.0 },
      DistanceEPS = 700000.0,
      Color = { 1.0, 1.0, 0.0 }
    }
  },
  Tag = { "moon_solarSystem", "moon_giants", "moon_jupiter", "moon_major_jupiter" },
  GUI = {
    Path = "/Solar System/Planets/Jupiter/Major Moons/Europa"
  }
}

local EuropaLabel = {
  Identifier = "EuropaLabel",
  Parent = Europa.Identifier,
  Renderable = {
    Enabled = false,
    Type = "RenderableLabel",
    Text = "Europa",
    FontSize = 70.0,
    Size = 6.0,
    MinMaxSize = { 1, 40 },
    OrientationOption = "Camera View Direction",
    BlendMode = "Additive",
    EnableFading = true,
    FadeUnit = "Gm",
    FadeDistances = { 1.0, 10.0 },
    FadeWidths = { 0.5, 10.0 }
  },
  Tag = { "solarsystem_labels", "moon_labels", "major_moon_labels" },
  GUI = {
    Name = "Europa Label",
    Path = "/Solar System/Planets/Jupiter/Major Moons/Europa",
    Description = "Label for Jupiter's moon Europa"
  }
}


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

  openspace.addSceneGraphNode(Europa)
  openspace.addSceneGraphNode(EuropaLabel)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(EuropaLabel)
  openspace.removeSceneGraphNode(Europa)

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

asset.export(Europa)
asset.export(EuropaLabel)



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