Add main menu
This commit is contained in:
parent
fef0b9ef96
commit
a7424f0a66
5 changed files with 194 additions and 15 deletions
|
@ -7,6 +7,9 @@ const GENERABLE_WORDS_FILENAME = "res://words/popular-filtered.txt"
|
||||||
const ALL_WORDS_FILENAME := "res://words/enable1.txt"
|
const ALL_WORDS_FILENAME := "res://words/enable1.txt"
|
||||||
|
|
||||||
|
|
||||||
|
var daily_mode := true
|
||||||
|
|
||||||
|
|
||||||
var generable_words: Dictionary
|
var generable_words: Dictionary
|
||||||
var all_words: Dictionary
|
var all_words: Dictionary
|
||||||
|
|
||||||
|
@ -33,20 +36,21 @@ func parse_words(filename: String, min_len: int, max_len: int) -> Dictionary:
|
||||||
dict[length].append(line.to_upper())
|
dict[length].append(line.to_upper())
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
for key in dict.keys():
|
|
||||||
print(key, ": ", dict[key].size())
|
|
||||||
|
|
||||||
|
|
||||||
return dict
|
return dict
|
||||||
|
|
||||||
|
|
||||||
func generate_word(length: int, random_seed = null) -> String:
|
func generate_word(length: int, random_seed = null) -> String:
|
||||||
|
var random_value: int
|
||||||
if typeof(random_seed) == TYPE_INT:
|
if typeof(random_seed) == TYPE_INT:
|
||||||
seed(random_seed)
|
var rng = RandomNumberGenerator.new()
|
||||||
|
rng.set_seed(random_seed)
|
||||||
|
random_value = rng.randi()
|
||||||
|
else:
|
||||||
|
random_value = randi()
|
||||||
|
|
||||||
var words_list := generable_words[length] as Array
|
var words_list := generable_words[length] as Array
|
||||||
|
|
||||||
return words_list[randi() % words_list.size()]
|
return words_list[random_value % words_list.size()]
|
||||||
|
|
||||||
|
|
||||||
func is_valid_word(word: String) -> bool:
|
func is_valid_word(word: String) -> bool:
|
||||||
|
|
20
src/Main.gd
20
src/Main.gd
|
@ -15,9 +15,11 @@ var letters := []
|
||||||
|
|
||||||
var target_word: String
|
var target_word: String
|
||||||
var current_guess: int
|
var current_guess: int
|
||||||
|
var ended: bool
|
||||||
|
|
||||||
onready var error_text_color_default = $C/V/V/ErrorText.get("custom_colors/font_color")
|
onready var error_text_color_default = $C/V/V/ErrorText.get("custom_colors/font_color")
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
for _i in range(guess_count):
|
for _i in range(guess_count):
|
||||||
var letter_array := []
|
var letter_array := []
|
||||||
|
@ -27,14 +29,21 @@ func _ready() -> void:
|
||||||
$C/V/LetterGrid.add_child(letter)
|
$C/V/LetterGrid.add_child(letter)
|
||||||
letters.append(letter_array)
|
letters.append(letter_array)
|
||||||
|
|
||||||
|
var random_seed = null
|
||||||
|
if Global.daily_mode:
|
||||||
var current_time := OS.get_datetime_from_unix_time(OS.get_unix_time())
|
var current_time := OS.get_datetime_from_unix_time(OS.get_unix_time())
|
||||||
current_time["hour"] = 0
|
current_time["hour"] = 0
|
||||||
current_time["minute"] = 0
|
current_time["minute"] = 0
|
||||||
current_time["second"] = 0
|
current_time["second"] = 0
|
||||||
var current_day_unix_time := OS.get_unix_time_from_datetime(current_time)
|
random_seed = OS.get_unix_time_from_datetime(current_time)
|
||||||
|
|
||||||
target_word = Global.generate_word(letter_count, current_day_unix_time)
|
$C/V/Title.text = "Daily " + $C/V/Title.text
|
||||||
|
else:
|
||||||
|
$C/V/Title.text = "Random " + $C/V/Title.text
|
||||||
|
|
||||||
|
target_word = Global.generate_word(letter_count, random_seed)
|
||||||
current_guess = 0
|
current_guess = 0
|
||||||
|
ended = false
|
||||||
|
|
||||||
|
|
||||||
func _on_GuessButton_pressed() -> void:
|
func _on_GuessButton_pressed() -> void:
|
||||||
|
@ -101,7 +110,6 @@ func guess_entered(guess: String) -> void:
|
||||||
var guess_text_node := find_node("GuessText") as LineEdit
|
var guess_text_node := find_node("GuessText") as LineEdit
|
||||||
guess_text_node.text = ""
|
guess_text_node.text = ""
|
||||||
|
|
||||||
var ended := false
|
|
||||||
var won := false
|
var won := false
|
||||||
|
|
||||||
if guess == target_word:
|
if guess == target_word:
|
||||||
|
@ -131,3 +139,9 @@ func show_error(text: String, color = null):
|
||||||
func hide_error():
|
func hide_error():
|
||||||
$C/V/V/ErrorText.text = ""
|
$C/V/V/ErrorText.text = ""
|
||||||
$ErrorFadeOut.stop()
|
$ErrorFadeOut.stop()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_MenuButton_pressed() -> void:
|
||||||
|
# TODO check if game is in progress and show confirmation popup
|
||||||
|
var error := get_tree().change_scene("res://src/Menu.tscn")
|
||||||
|
assert(not error)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=6 format=2]
|
[gd_scene load_steps=7 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://fonts/Louis George Cafe Bold.ttf" type="DynamicFontData" id=1]
|
[ext_resource path="res://fonts/Louis George Cafe Bold.ttf" type="DynamicFontData" id=1]
|
||||||
[ext_resource path="res://src/Main.gd" type="Script" id=2]
|
[ext_resource path="res://src/Main.gd" type="Script" id=2]
|
||||||
|
@ -11,6 +11,9 @@ font_data = ExtResource( 1 )
|
||||||
size = 24
|
size = 24
|
||||||
font_data = ExtResource( 1 )
|
font_data = ExtResource( 1 )
|
||||||
|
|
||||||
|
[sub_resource type="DynamicFont" id=4]
|
||||||
|
font_data = ExtResource( 1 )
|
||||||
|
|
||||||
[sub_resource type="Animation" id=3]
|
[sub_resource type="Animation" id=3]
|
||||||
resource_name = "ErrorFadeOut"
|
resource_name = "ErrorFadeOut"
|
||||||
length = 6.0
|
length = 6.0
|
||||||
|
@ -59,7 +62,7 @@ __meta__ = {
|
||||||
margin_right = 500.0
|
margin_right = 500.0
|
||||||
margin_bottom = 82.0
|
margin_bottom = 82.0
|
||||||
custom_fonts/font = SubResource( 1 )
|
custom_fonts/font = SubResource( 1 )
|
||||||
text = "Daily Gordle"
|
text = "Gordle"
|
||||||
align = 1
|
align = 1
|
||||||
|
|
||||||
[node name="LetterGrid" type="GridContainer" parent="C/V"]
|
[node name="LetterGrid" type="GridContainer" parent="C/V"]
|
||||||
|
@ -107,8 +110,22 @@ margin_right = 500.0
|
||||||
margin_bottom = 51.0
|
margin_bottom = 51.0
|
||||||
text = "Guess"
|
text = "Guess"
|
||||||
|
|
||||||
|
[node name="MenuButton" type="Button" parent="."]
|
||||||
|
anchor_left = 1.0
|
||||||
|
anchor_right = 1.0
|
||||||
|
margin_left = -65.0
|
||||||
|
margin_top = 10.0
|
||||||
|
margin_right = -10.0
|
||||||
|
margin_bottom = 36.0
|
||||||
|
custom_fonts/font = SubResource( 4 )
|
||||||
|
text = "Menu"
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
[node name="ErrorFadeOut" type="AnimationPlayer" parent="."]
|
[node name="ErrorFadeOut" type="AnimationPlayer" parent="."]
|
||||||
anims/ErrorFadeOut = SubResource( 3 )
|
anims/ErrorFadeOut = SubResource( 3 )
|
||||||
|
|
||||||
[connection signal="text_entered" from="C/V/V/H/GuessText" to="." method="_on_GuessText_text_entered"]
|
[connection signal="text_entered" from="C/V/V/H/GuessText" to="." method="_on_GuessText_text_entered"]
|
||||||
[connection signal="pressed" from="C/V/V/H/GuessButton" to="." method="_on_GuessButton_pressed"]
|
[connection signal="pressed" from="C/V/V/H/GuessButton" to="." method="_on_GuessButton_pressed"]
|
||||||
|
[connection signal="pressed" from="MenuButton" to="." method="_on_MenuButton_pressed"]
|
||||||
|
|
26
src/Menu.gd
Normal file
26
src/Menu.gd
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
extends CenterContainer
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
if OS.get_name() == "HTML5":
|
||||||
|
find_node("QuitButton").hide()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_DailyButton_pressed() -> void:
|
||||||
|
Global.daily_mode = true
|
||||||
|
var error := get_tree().change_scene("res://src/Main.tscn")
|
||||||
|
assert(not error)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_RandomButton_pressed() -> void:
|
||||||
|
Global.daily_mode = false
|
||||||
|
var error := get_tree().change_scene("res://src/Main.tscn")
|
||||||
|
assert(not error)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_CreditsButton_pressed() -> void:
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
func _on_QuitButton_pressed() -> void:
|
||||||
|
get_tree().notification(NOTIFICATION_WM_QUIT_REQUEST)
|
118
src/Menu.tscn
Normal file
118
src/Menu.tscn
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
[gd_scene load_steps=5 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://fonts/Louis George Cafe Bold.ttf" type="DynamicFontData" id=1]
|
||||||
|
[ext_resource path="res://src/Menu.gd" type="Script" id=2]
|
||||||
|
|
||||||
|
[sub_resource type="DynamicFont" id=1]
|
||||||
|
size = 96
|
||||||
|
font_data = ExtResource( 1 )
|
||||||
|
|
||||||
|
[sub_resource type="DynamicFont" id=2]
|
||||||
|
size = 24
|
||||||
|
font_data = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="Menu" type="CenterContainer"]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="V" type="VBoxContainer" parent="."]
|
||||||
|
margin_left = 165.0
|
||||||
|
margin_top = 183.0
|
||||||
|
margin_right = 475.0
|
||||||
|
margin_bottom = 776.0
|
||||||
|
custom_constants/separation = 80
|
||||||
|
|
||||||
|
[node name="V" type="VBoxContainer" parent="V"]
|
||||||
|
margin_right = 310.0
|
||||||
|
margin_bottom = 140.0
|
||||||
|
|
||||||
|
[node name="Title" type="Label" parent="V/V"]
|
||||||
|
margin_right = 310.0
|
||||||
|
margin_bottom = 108.0
|
||||||
|
custom_fonts/font = SubResource( 1 )
|
||||||
|
text = "Gordle"
|
||||||
|
align = 1
|
||||||
|
|
||||||
|
[node name="Subtitle" type="Label" parent="V/V"]
|
||||||
|
margin_top = 112.0
|
||||||
|
margin_right = 310.0
|
||||||
|
margin_bottom = 140.0
|
||||||
|
custom_fonts/font = SubResource( 2 )
|
||||||
|
text = "Wordle in Godot"
|
||||||
|
align = 1
|
||||||
|
|
||||||
|
[node name="V2" type="VBoxContainer" parent="V"]
|
||||||
|
margin_top = 220.0
|
||||||
|
margin_right = 310.0
|
||||||
|
margin_bottom = 593.0
|
||||||
|
custom_constants/separation = 30
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="V" type="VBoxContainer" parent="V/V2"]
|
||||||
|
margin_right = 310.0
|
||||||
|
margin_bottom = 110.0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="DailyButton" type="Button" parent="V/V2/V"]
|
||||||
|
margin_right = 310.0
|
||||||
|
margin_bottom = 47.0
|
||||||
|
text = "Daily Gordle"
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="V/V2/V"]
|
||||||
|
margin_top = 51.0
|
||||||
|
margin_right = 310.0
|
||||||
|
margin_bottom = 110.0
|
||||||
|
custom_fonts/font = SubResource( 2 )
|
||||||
|
text = "Changes every day
|
||||||
|
at midnight GMT"
|
||||||
|
align = 1
|
||||||
|
|
||||||
|
[node name="V2" type="VBoxContainer" parent="V/V2"]
|
||||||
|
margin_top = 140.0
|
||||||
|
margin_right = 310.0
|
||||||
|
margin_bottom = 219.0
|
||||||
|
rect_min_size = Vector2( 310, 0 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="RandomButton" type="Button" parent="V/V2/V2"]
|
||||||
|
margin_right = 310.0
|
||||||
|
margin_bottom = 47.0
|
||||||
|
text = "Random Gordle"
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="V/V2/V2"]
|
||||||
|
margin_top = 51.0
|
||||||
|
margin_right = 310.0
|
||||||
|
margin_bottom = 79.0
|
||||||
|
custom_fonts/font = SubResource( 2 )
|
||||||
|
text = "Different every time"
|
||||||
|
align = 1
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="CreditsButton" type="Button" parent="V/V2"]
|
||||||
|
margin_top = 249.0
|
||||||
|
margin_right = 310.0
|
||||||
|
margin_bottom = 296.0
|
||||||
|
text = "Credits"
|
||||||
|
|
||||||
|
[node name="QuitButton" type="Button" parent="V/V2"]
|
||||||
|
margin_top = 326.0
|
||||||
|
margin_right = 310.0
|
||||||
|
margin_bottom = 373.0
|
||||||
|
text = "Quit"
|
||||||
|
|
||||||
|
[connection signal="pressed" from="V/V2/V/DailyButton" to="." method="_on_DailyButton_pressed"]
|
||||||
|
[connection signal="pressed" from="V/V2/V2/RandomButton" to="." method="_on_RandomButton_pressed"]
|
||||||
|
[connection signal="pressed" from="V/V2/CreditsButton" to="." method="_on_CreditsButton_pressed"]
|
||||||
|
[connection signal="pressed" from="V/V2/QuitButton" to="." method="_on_QuitButton_pressed"]
|
Loading…
Reference in a new issue