extends Control

const SongElement = preload("res://Components/SongListItem.tscn")

# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var songlist = "https://pastebin.pl/view/raw/40dfc4fc"

# Called when the node enters the scene tree for the first time.
func _ready():
	$HTTPRequest.request(songlist)
	print(songlist)
#	var ItemListContent = ["We shall go this way","We shall go that way","which way shall we go?","I think we're lost"]
#	for ItemID in range(4):
#		$ItemList.add_item(ItemListContent[ItemID],null,true)


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass


func _on_HTTPRequest_request_completed(result, response_code, headers, body):
	var json = JSON.parse(body.get_string_from_utf8())
	if json.result != null:
		#print(json.result)
		for song in json.result:
			var thesongelement = SongElement.instance()
			thesongelement.setObject(song)
			$ScrollContainer/GridContainer.add_child(thesongelement)
