extends Node2D

var sprite
var area
var collider
var loadedScript

export(String, FILE, "*.gd") var scriptName

var scriptSprite = { "Invisibility": "black",
					 "Slippery": "blue",
					 "Upscale": "red",
					 "ConfuseDirections": "yellow"}

# Called when the node enters the scene tree for the first time.
func _ready():
	randomize()
	sprite = get_node("Sprite")
	area = get_node("Area2D")
	if scriptName != "":
		loadedScript = load(scriptName).new()
	else:
		var i = randi() % scriptSprite.size()
		loadedScript = load("res://Scripts/PaintEffects/" + scriptSprite.keys()[i] + ".gd").new()
		sprite.texture = load("res://Assets/Buckets/" + scriptSprite.values()[i]	+ "_bucket.png")
	area.connect("body_entered", self, "onBodyEntered")

func onBodyEntered(body):
	body.addCoroutine(loadedScript.StartEffect(body))
	queue_free()
