-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIdeafinder.gd
44 lines (31 loc) · 1.15 KB
/
Ideafinder.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
extends Control
onready var sentence := $CenterContainer/VBoxContainer/HBoxContainer/Sentence
onready var words : PopupMenu = $CenterContainer/VBoxContainer/HBoxContainer2/MenuButton.get_popup()
onready var result := $CenterContainer/VBoxContainer/Result
func _ready() -> void:
for word in Content.words:
words.add_item(word)
words.connect("id_pressed", self, "_word_pressed")
_on_Generate_pressed()
randomize()
func rand_word(word : String) -> String:
return Content.words[word][randi() % Content.words[word].size()]
func replace(string : String, what : String, forwhat : String) -> String:
var p = string.find(what)
if p == 0:
return forwhat + string.right(what.length())
return string.substr(0, p) + forwhat + string.substr(p + what.length())
func generate(line : String) -> String:
var result := line
for word in Content.words:
var pos = result.find(word)
while pos != -1:
result = replace(result, word, rand_word(word))
pos = result.find(word)
return result
func _word_pressed(id : int) -> void:
sentence.insert_text_at_cursor(words.get_item_text(id))
pass
func _on_Generate_pressed():
result.text = generate(sentence.text)
pass