54 lines
1.4 KiB
GDScript
54 lines
1.4 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 add_factor: Vector2i = world.tilemap_ground.tilemap.tile_set.tile_size
|
|
add_factor.x /= 2
|
|
add_factor.y /= 2
|
|
|
|
var from_tileset: Vector2i = world.tilemap_ground.cell_to_local(from)
|
|
from_tileset.x += add_factor.x
|
|
from_tileset.y += add_factor.y
|
|
|
|
var to_tileset: Vector2i = world.tilemap_ground.cell_to_local(to)
|
|
to_tileset.x += add_factor.x
|
|
to_tileset.y += add_factor.y
|
|
|
|
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()
|
|
|
|
|
|
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, Color("red"), 2)
|
|
var center: Vector2 = (from + to) / 2
|
|
draw_string(label_font, center, label)
|