-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rune.gd
72 lines (49 loc) · 1.63 KB
/
Rune.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
extends StaticBody2D
signal delete
onready var special_lines = $Special.get_children()
onready var consonant_lines = $Consonants.get_children()
onready var vowel_lines = $Vowels.get_children()
onready var invalid_points = $InvalidPoints.get_children()
onready var overlay = $Overlay
onready var label = $Overlay/ZSet/Label
var lines: Array
var parse_result: Runes.RuneParseResult = null
var parse_hash: String = ''
func _ready():
lines = []
lines.append_array(special_lines)
lines.append_array(consonant_lines)
lines.append_array(vowel_lines)
func detect(img: Image):
var is_invalid = false
for invalid_point in invalid_points:
if ImgUtil.get_value_at(img, invalid_point.global_position) < 0.5:
is_invalid = true
for line in lines:
if is_invalid:
line.status = RuneLine.Status.DEFAULT
else:
line.detect(img)
parse_result = Runes.parse(detected_lines())
parse_hash = ''
for line in lines:
parse_hash += '1' if line.status == RuneLine.Status.DETECTED else '0'
func show_parse_result():
if parse_result != null:
overlay.visible = true
label.text = str(parse_result)
func hide_parse_result():
overlay.visible = false
func detected_lines(set = lines):
var line_names = []
for line in set:
if line.status == RuneLine.Status.DETECTED:
line_names.append(line.get_name())
return line_names
func detected_line_count(set = lines):
return detected_lines(set).size()
func any_line_detected(set = lines):
return detected_line_count(set) > 0
func _on_Rune_input_event(viewport, event, shape_idx):
if event is InputEventMouseButton && event.button_index == BUTTON_RIGHT && event.pressed:
emit_signal('delete')