extends Node2D

const ICONS = preload("res://Assets/UI/EventIcons.png")
const TEXTURE_SIZE = Vector2(7, 7)

enum TEXTURE {
	PLAYER
	MOB,
	PRESENT,
	BOSS
}
#var image = Image.new()
#var texture = Texture.new()
var level = []
var player_position = -1

func _ready():
	update()

func new_level():
	level.clear()
	player_position = -1
	update()

func place_in_screen_center():
	position.x = get_viewport_rect().size.x / 2 - (TEXTURE_SIZE.x * level.size()) / 2
	position.x -= TEXTURE_SIZE.x/2
	position.x = round(position.x)

func move_player():
	if player_position < level.size():
		#$Tween.interpolate_property(self, "player_position", player_position, player_position+1, 0.5, Tween.TRANS_QUAD, Tween.EASE_OUT)
		#$Tween.start()
		player_position += 1
		update()

func text_to_event_icon(string):
	match string:
		"entity":
			return TEXTURE.MOB
		"present":
			return TEXTURE.PRESENT
		"boss":
			return TEXTURE.BOSS

func _draw():
	var line_start = Vector2(TEXTURE_SIZE.x/2, TEXTURE_SIZE.y/2)
	var line_finish = Vector2(level.size() * TEXTURE_SIZE.x - TEXTURE_SIZE.x/2, TEXTURE_SIZE.y/2)
	draw_line(line_start, line_finish, Color.midnightblue)
	
	for i in level.size():
		var world_rect = Rect2(Vector2(i*TEXTURE_SIZE.x, 0), TEXTURE_SIZE)
		var scr_rect = Rect2(Vector2(level[i]*TEXTURE_SIZE.x, 0), TEXTURE_SIZE)
		draw_texture_rect_region(ICONS, world_rect, scr_rect)
	
	if player_position == -1:
		return
	var player_world_rect = Rect2(Vector2(player_position*TEXTURE_SIZE.x, 0), TEXTURE_SIZE)
	var player_scr_rect = Rect2(Vector2(TEXTURE.PLAYER*TEXTURE_SIZE.x, 0), TEXTURE_SIZE)
	draw_texture_rect_region(ICONS, player_world_rect, player_scr_rect)

