-
Notifications
You must be signed in to change notification settings - Fork 6
/
Utils.gd
92 lines (74 loc) · 2.54 KB
/
Utils.gd
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
extends Node
func _init():
pass
func disconnect_signal(node:Node, _signal:String, _target:Node, _func:String)->void:
var param = [_signal, _target, _func]
if node.callv("is_connected", param):
node.callv("disconnect", param)
func connect_signal(node:Node, key:String, _signal:String, _target:Node, _func:String)->void:
disconnect_signal(node, _signal, _target, _func)
node.connect(_signal, _target, _func, [node, key])
func fill_options(node:OptionButton, data, capitalize:bool = false)->void:
node.clear()
if data is Array:
for value in data:
var v = value.capitalize() if capitalize else value
node.add_item(v)
var idx = node.get_item_count() - 1
node.set_item_metadata(idx, {"tooltip": "", "key": value})
node.set_meta("list", data)
elif data is Dictionary:
var popup = node.get_popup()
for key in data.keys():
var v = key.capitalize() if capitalize else key
node.add_item(v)
var idx = node.get_item_count() - 1
var tooltip = data.get(key, "")
if tooltip is Dictionary:
tooltip = tooltip.get("description", "")
node.set_item_metadata(idx, {"tooltip": tooltip, "key": key})
if not tooltip.empty():
popup.set_item_tooltip(idx, tooltip)
node.set_meta("dict", data)
Utils.update_option_tooltip(node, 0)
func update_option_tooltip(node:Node, idx:int)->void:
var meta = node.get_item_metadata(idx)
if not meta: return
var tooltip = meta.get("tooltip", "")
if tooltip.empty():
node.hint_tooltip = ""
else:
node.hint_tooltip = tooltip
func option_get_selected_key(node:OptionButton):
var meta = node.get_item_metadata(node.selected)
if not meta: return ""
return meta.get("key", "")
func option_select(node:OptionButton, value):
if value.empty():
node.select(0)
else:
if node.has_meta("list"):
var list = node.get_meta("list")
node.select(list.find(value))
elif node.has_meta("dict"):
var dict = node.get_meta("dict")
node.select(dict.keys().find(value))
update_option_tooltip(node, node.selected)
func load_external_texture(path:String):
var texture = null
var img = Image.new()
if img.load(path) == OK:
texture = ImageTexture.new()
texture.create_from_image(img)
return texture
func humanize_equipment_name(title):
title = title.replacen("_upgraded", "+")
title = title.replacen("_deckupgrade", "+")
title = title.replacen("_weakened", "-")
title = title.replacen("_downgraded", "-")
return title
func to_csv_equipment_name(title):
if title.ends_with("+") or title.ends_with("-"):
title = title.replacen("+", "_upgraded")
title = title.replacen("-", "_weakened")
return title