local globe = asset.require("../../earth")



local Name = "Solar Rainfall - Monthly (NASA)"
local Identifier = "noaa-sos-atmosphere-globe-rainfall"
local Description = [[Globally, rain is the main source of fresh water for plants and
animals rainfall is essential for life across Earth's landscapes. In addition to moving
tremendous amounts of water through Earth's atmosphere, rain clouds also move tremendous
amounts of energy. When water evaporates from the surface and rises as vapor into the
atmosphere, it carries heat from the sun-warmed surface with it. Later, when the water
vapor condenses to form cloud droplets and rain, the heat is released into the
atmosphere. This heating is a major part of Earth's energy budget and climate]]
local URL = "https://sos.noaa.gov/catalog/datasets/rainfall-monthly-nasa/"


local syncedDirectory = asset.syncedResource({
  Name = Name,
  Type = "HttpSynchronization",
  Identifier = Identifier,
  Version = 1,
  UnzipFiles = true
})


local Layer = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "TemporalTileLayer",
  Mode = "Folder",
  Folder = {
    Folder = syncedDirectory .. "1440",
    -- See https://en.cppreference.com/w/cpp/io/manip/get_time for an explanation of the
    -- time formatting string
    Format = "TRMM_3B43M_%Y-%m.PNG"
  },
  Description = Description
}

local Colorbar = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "ScreenSpaceImageLocal",
  TexturePath = syncedDirectory .. "colorbar.png",
  FaceCamera = false,
  BackgroundColor = { 1.0, 1.0, 1.0, 1.0 },
  CartesianPosition = { 0.0, -0.5, -2.0 }
}


asset.onInitialize(function()
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", Layer)
  openspace.addScreenSpaceRenderable(Colorbar)
end)

asset.onDeinitialize(function()
  openspace.removeScreenSpaceRenderable(Colorbar)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", Layer)
end)

asset.export(Layer)
asset.export(Colorbar)



asset.meta = {
  Name = Name,
  Version = "1.0",
  Description = Description .. "Data provided by the National Oceanic and Atmospheric Administration",
  Author = "National Oceanic and Atmospheric Administration",
  URL = URL,
  License = "https://sos.noaa.gov/copyright/"
}
