-
Notifications
You must be signed in to change notification settings - Fork 1
/
LoonyLips.gd
81 lines (55 loc) · 1.85 KB
/
LoonyLips.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
extends Control
# $DisplayText == get_node("DisplayText")
var player_words : Array
var current_story : Dictionary
onready var PlayerText : LineEdit = $VBoxContainer/HBoxContainer/PlayerText
onready var DisplayText : Label = $VBoxContainer/DisplayText
func _ready ():
set_current_story_from_json()
DisplayText.text = " <kastor.code/> \n\nWelcome to Loony Lips! We're going to tell a story and have a wonderful time!\n\n"
check_player_words_length()
PlayerText.grab_focus()
func _on_PlayerText_text_entered (new_text):
add_to_player_words()
func _on_TextureButton_pressed ():
if (is_story_done()):
get_tree().reload_current_scene()
else:
add_to_player_words()
func set_current_story ():
randomize()
var stories = $StoryBook.get_child_count()
var selected_story = randi() % stories
current_story.prompts = $StoryBook.get_child(selected_story).prompts
current_story.story = $StoryBook.get_child(selected_story).story
func set_current_story_from_json ():
randomize()
var stories = get_from_json("StoryBook.json")
current_story = stories[randi() % stories.size()]
func get_from_json (filename):
var file = File.new()
file.open(filename, File.READ)
var text = file.get_as_text()
var data = parse_json(text)
file.close()
return data
func add_to_player_words ():
player_words.append(PlayerText.text)
DisplayText.text = ""
PlayerText.clear()
check_player_words_length()
func is_story_done ():
return player_words.size() == current_story.prompts.size()
func check_player_words_length ():
if (is_story_done()):
end_game()
else:
prompt_player()
func tell_story ():
DisplayText.text = current_story.story % player_words
func prompt_player ():
DisplayText.text += "May I have " + current_story.prompts[player_words.size()] + " please?"
func end_game ():
PlayerText.queue_free()
$VBoxContainer/HBoxContainer/Label.text = "Again"
tell_story()