diff --git a/project.godot b/project.godot index f38ad72..e985721 100644 --- a/project.godot +++ b/project.godot @@ -28,3 +28,9 @@ Menu={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null) ] } +"Next Generation"={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":78,"key_label":0,"unicode":110,"echo":false,"script":null) +] +} diff --git a/world.gd b/world.gd index f2f883d..2e3f273 100644 --- a/world.gd +++ b/world.gd @@ -25,6 +25,7 @@ enum CellStates { @onready var generation_world_size_y: LineEdit = $UI/WorldGeneration/VBoxContainer/WorldSize/Input_y @onready var generation_cell_size_x: LineEdit = $UI/WorldGeneration/VBoxContainer/CellSize/Input_x @onready var generation_cell_size_y: LineEdit = $UI/WorldGeneration/VBoxContainer/CellSize/Input_y +@onready var start_paused_button: CheckBox = $UI/WorldGeneration/VBoxContainer/FinalRow/StartPausedButton ## Other @onready var camera: Camera2D = $Camera2D @@ -52,15 +53,15 @@ func _ready() -> void: func _input(event: InputEvent) -> void: if event.is_action_pressed("Pause"): - if is_paused: generation_timer.start() - else: generation_timer.stop() - is_paused = !is_paused - background_ui.visible = is_paused + toggle_pause() + if is_paused and event.is_action_pressed("Next Generation"): + process_generation() + debug_generation_counter.text = "Generation: %s" % generation + debug_living_cells_counter.text = "Living Cells: %s" % total_living if event.is_action_pressed("Menu"): - is_paused = true - background_ui.visible = true - generation_ui.visible = true + toggle_pause() update_generation_ui() + generation_ui.visible = is_paused # @@ -76,17 +77,22 @@ func update_generation_ui() -> void: generation_world_size_y.text = str(world_size.y) generation_cell_size_x.text = str(cell_size.x) generation_cell_size_y.text = str(cell_size.y) + start_paused_button.button_pressed = false # # Conway Specific # func start_conway() -> void: + generation = 1 debug_world_seed.text = "World Seeed: %s" % world_seed - is_paused = false + debug_generation_counter.text = "Generation: %s" % generation generate_world() - generation_timer.start() + + debug_living_cells_counter.text = "Living Cells: %s" % total_living + + if not is_paused: generation_timer.start() # Center the camera on the world camera.position.x = world_size.x * cell_size.x / 2 @@ -152,6 +158,13 @@ func process_generation() -> void: cell_states = new_states +## Toggle Pause UI and Start/Stop Generation Timer +func toggle_pause() -> void: + if is_paused: generation_timer.start() + else: generation_timer.stop() + is_paused = !is_paused + background_ui.visible = is_paused + ## Create the cell using the rendering server ## This is only performed on initial world generation @@ -212,5 +225,8 @@ func _on_run_button_pressed() -> void: start_conway() +func _on_start_paused_button_toggled(button_pressed: bool) -> void: + is_paused = button_pressed + func _on_world_seed_generate_pressed() -> void: generation_seed.text = str(randi()) diff --git a/world.tscn b/world.tscn index 37e135e..848c3bf 100644 --- a/world.tscn +++ b/world.tscn @@ -178,15 +178,19 @@ select_all_on_focus = true [node name="FinalRow" type="HBoxContainer" parent="UI/WorldGeneration/VBoxContainer"] layout_mode = 2 -[node name="RunButton" type="Button" parent="UI/WorldGeneration/VBoxContainer/FinalRow"] +[node name="StartPausedButton" type="CheckBox" parent="UI/WorldGeneration/VBoxContainer/FinalRow"] layout_mode = 2 -text = "Run" +text = "Start Paused" [node name="Padding" type="VSeparator" parent="UI/WorldGeneration/VBoxContainer/FinalRow"] modulate = Color(1, 1, 1, 0) layout_mode = 2 size_flags_horizontal = 3 +[node name="RunButton" type="Button" parent="UI/WorldGeneration/VBoxContainer/FinalRow"] +layout_mode = 2 +text = "Run" + [node name="QuitButton" type="Button" parent="UI/WorldGeneration/VBoxContainer/FinalRow"] layout_direction = 3 layout_mode = 2 @@ -194,5 +198,6 @@ text = "Quit" [connection signal="timeout" from="GenerationTimer" to="." method="_on_generation_timer_timeout"] [connection signal="pressed" from="UI/WorldGeneration/VBoxContainer/Seed/Generate" to="." method="_on_world_seed_generate_pressed"] +[connection signal="toggled" from="UI/WorldGeneration/VBoxContainer/FinalRow/StartPausedButton" to="." method="_on_start_paused_button_toggled"] [connection signal="pressed" from="UI/WorldGeneration/VBoxContainer/FinalRow/RunButton" to="." method="_on_run_button_pressed"] [connection signal="pressed" from="UI/WorldGeneration/VBoxContainer/FinalRow/QuitButton" to="." method="_on_quit_button_pressed"]