aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/GameSession/MapText.gd
blob: 619c72ff4ab3f4fd8fd685d90f9c530db01c9247 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class_name MapText
extends Node3D

@export var _map_view : MapView

var _province_name_font : Font

const _province_name_scale : float = 1.0 / 48.0

func _ready() -> void:
   _province_name_font = AssetManager.get_font(&"mapfont_56")

func _clear_children() -> void:
   var child_count : int = get_child_count()
   while child_count > 0:
      child_count -= 1
      var child : Node = get_child(child_count)
      remove_child(child)
      child.queue_free()

func generate_map_names() -> void:
   _clear_children()

   for dict : Dictionary in GameSingleton.get_province_names():
      _add_province_name(dict)

func _add_province_name(dict : Dictionary) -> void:
   const identifier_key : StringName = &"identifier"
   const position_key : StringName = &"position"
   const rotation_key : StringName = &"rotation"
   const scale_key : StringName = &"scale"

   var label : Label3D = Label3D.new()

   label.set_draw_flag(Label3D.FLAG_DOUBLE_SIDED, false)
   label.set_modulate(Color.BLACK)
   label.set_outline_size(0)
   label.set_font(_province_name_font)
   label.set_vertical_alignment(VERTICAL_ALIGNMENT_BOTTOM)

   var identifier : String = dict[identifier_key]
   label.set_name(identifier)
   label.set_text(GUINode.format_province_name(identifier))

   label.set_position(_map_view._map_to_world_coords(dict[position_key]) + Vector3(0, 0.001, 0))

   label.rotate_x(-PI / 2)
   label.rotate_y(dict.get(rotation_key, 0.0))

   label.scale *= dict.get(scale_key, 1.0) * _province_name_scale

   add_child(label)