47 lines
1.2 KiB
GDScript
47 lines
1.2 KiB
GDScript
class_name StepVisualization
|
|
extends Node2D
|
|
|
|
static var game_manager: GameManager
|
|
static var world: World
|
|
#
|
|
# Dictionary[Array[Vector2i], bool] ([from, to], string)
|
|
static var draw_lines: Dictionary = {}
|
|
|
|
|
|
static func add_line(from: Vector2i, to: Vector2i, label: String) -> void:
|
|
draw_lines[[from, to]] = label
|
|
|
|
|
|
static func add_line_tileset(from: Vector2i, to: Vector2i, label: String) -> void:
|
|
var from_tileset: Vector2i = world.tilemap_ground.cell_to_local(from)
|
|
var to_tileset: Vector2i = world.tilemap_ground.cell_to_local(to)
|
|
draw_lines[[from_tileset, to_tileset]] = label
|
|
|
|
|
|
func game_tick_start():
|
|
draw_lines.clear()
|
|
|
|
|
|
func game_tick_end():
|
|
queue_redraw()
|
|
|
|
var label_font = Control.new().get_theme_default_font()
|
|
|
|
@export var line_color: Color = Color("red")
|
|
@export var text_color: Color = Color("white")
|
|
|
|
|
|
func _ready() -> void:
|
|
pass
|
|
|
|
|
|
func _draw() -> void:
|
|
# draw all draw_lines with their labels
|
|
for key in draw_lines.keys():
|
|
var from: Vector2i = key[0]
|
|
var to: Vector2i = key[1]
|
|
var label: String = draw_lines[key]
|
|
draw_line(from, to, line_color, 2)
|
|
var center: Vector2 = (from + to) / 2
|
|
draw_string(label_font, center, label, 0, -1, 12, text_color)
|