Skip to content
Merged

A #6

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
406 changes: 386 additions & 20 deletions src/main_scene/main_scene.cpp

Large diffs are not rendered by default.

31 changes: 29 additions & 2 deletions src/main_scene/main_scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

#include <godot_cpp/classes/node3d.hpp>
#include <godot_cpp/classes/camera3d.hpp>
#include <godot_cpp/classes/world3d.hpp>
#include <godot_cpp/classes/input_event_mouse_button.hpp>
#include <godot_cpp/classes/input_event_mouse_motion.hpp>
#include <godot_cpp/classes/physics_direct_space_state3d.hpp>
#include <godot_cpp/classes/physics_ray_query_parameters3d.hpp>
#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/option_button.hpp>
#include <godot_cpp/classes/label.hpp>
Expand All @@ -17,6 +21,8 @@
#include <godot_cpp/classes/collision_shape3d.hpp>
#include <godot_cpp/classes/concave_polygon_shape3d.hpp>
#include <godot_cpp/classes/scene_tree.hpp>
#include <godot_cpp/classes/v_box_container.hpp>
#include <godot_cpp/classes/scene_tree_timer.hpp>
#include <godot_cpp/classes/tween.hpp>
#include <godot_cpp/classes/property_tweener.hpp>
#include <godot_cpp/classes/engine.hpp>
Expand All @@ -26,6 +32,7 @@
#include <fstream>
#include <vector>
#include <map>
#include <cmath>

#include "../utils/utils.hpp"

Expand All @@ -44,7 +51,9 @@ class MainScene : public Node3D {
bool is_solved = false;
AlgoType algo_type = BFS;

Label* node_label = nullptr;
Label* time_label = nullptr;
Label* move_label = nullptr;

Button* solve_button = nullptr;
Button* reset_button = nullptr;
Expand All @@ -53,6 +62,7 @@ class MainScene : public Node3D {

Ref<PackedScene> car2_template;
Ref<PackedScene> car3_template;
Ref<PackedScene> gate_template;
Ref<StandardMaterial3D> primary_piece_material;
Ref<StandardMaterial3D> non_primary_piece_material;
MeshInstance3D* floor = nullptr;
Expand All @@ -64,13 +74,25 @@ class MainScene : public Node3D {
Solution current_solution;
int current_move_index = -1;
bool is_animating_solution = false;
const float ANIMATION_DURATION = 0.5f;
const float ANIMATION_DURATION = 0.25f;

Camera3D* camera_node;
float zoom_speed = 0.5f;
float min_zoom_distance = 2.0f;
float max_zoom_distance = 20.0f;

int notification_count = 0;
VBoxContainer* notification_container = nullptr;
Label* notification_label_template = nullptr;

Node3D* dragged_car_node = nullptr;
Piece* dragged_piece_data = nullptr;
Vector3 drag_start_mouse_world_pos;
Vector3 drag_start_car_3d_pos;
Coordinates drag_start_piece_coords;
bool is_dragging_piece = false;
int current_manual_moves = 0;

void _animate_next_move();
void _on_move_animation_finished();
Vector3 _get_3d_position_for_piece_coords(const Coordinates& piece_top_left_coords, int piece_size, bool is_vertical_piece);
Expand All @@ -89,6 +111,11 @@ class MainScene : public Node3D {
void _clear_all_cars();
void _spawn_piece_as_car(const Piece& piece_data);

void add_notification(const String& p_message);

Coordinates _get_grid_coords_from_3d_position(const Vector3& pos_3d, int piece_size, bool is_vertical_piece);
bool _is_move_valid(const Coordinates& from_coords, const Coordinates& to_coords, char piece_id_moving, bool is_vertical);

protected:
static void _bind_methods();
void _notification(int p_what);
Expand All @@ -98,5 +125,5 @@ class MainScene : public Node3D {
~MainScene();

void _process(double delta) override;
void _input(const Ref<InputEvent>& event);
void _input(const Ref<InputEvent>& event) override;
};
4 changes: 2 additions & 2 deletions test/2.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
5 5
5
EAAA.
4
...P.
ED.PB
.D.PB
.DCCB
Expand Down
8 changes: 4 additions & 4 deletions tukang-parkir-simulator/export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="../../executable/godot cpp template.html"
export_path="../bin/web/Tukang Parkir Simulator.html"
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Export paths containing spaces can cause issues in build scripts; consider removing or escaping spaces or using underscores/hyphens.

Suggested change
export_path="../bin/web/Tukang Parkir Simulator.html"
export_path="../bin/web/Tukang_Parkir_Simulator.html"

Copilot uses AI. Check for mistakes.
patches=PackedStringArray()
encryption_include_filters=""
encryption_exclude_filters=""
Expand All @@ -22,7 +22,7 @@ script_export_mode=2

custom_template/debug=""
custom_template/release=""
variant/extensions_support=false
variant/extensions_support=true
variant/thread_support=false
vram_texture_compression/for_desktop=true
vram_texture_compression/for_mobile=false
Expand All @@ -47,13 +47,13 @@ progressive_web_app/background_color=Color(0, 0, 0, 1)
name="Windows Desktop"
platform="Windows Desktop"
runnable=true
advanced_options=false
advanced_options=true
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path=""
export_path="../bin/windows/Tukang Parkir Simulator.exe"
patches=PackedStringArray()
encryption_include_filters=""
encryption_exclude_filters=""
Expand Down
1 change: 1 addition & 0 deletions tukang-parkir-simulator/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ window/stretch/mode="viewport"

[rendering]

textures/canvas_textures/default_texture_filter=0
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"
19 changes: 19 additions & 0 deletions tukang-parkir-simulator/scenes/gate.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[gd_scene load_steps=2 format=3 uid="uid://dvm8u67mw7kiy"]

[sub_resource type="BoxShape3D" id="BoxShape3D_ghoj6"]
size = Vector3(0.15, 0.1, 0.15)

[node name="Gate" type="StaticBody3D"]

[node name="CSGPolygon3D" type="CSGPolygon3D" parent="."]
transform = Transform3D(-1, 1.19209e-07, 0, -1.19209e-07, -1, 0, 0, 0, 1, 0, 0.05, 0)
flip_faces = true
polygon = PackedVector2Array(0.2, 0.1, 0, 0.75, 0.35, 0.15, 0.1, -0.1)
mode = 1
spin_degrees = 360.0
spin_sides = 10
smooth_faces = true

[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.025, 1.1, 0.025)
shape = SubResource("BoxShape3D_ghoj6")
148 changes: 146 additions & 2 deletions tukang-parkir-simulator/scenes/main.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[gd_scene load_steps=12 format=3 uid="uid://deic8j1v28f5m"]
[gd_scene load_steps=15 format=3 uid="uid://deic8j1v28f5m"]

[ext_resource type="PackedScene" uid="uid://bj1kkdl8im8kb" path="res://scenes/car2.tscn" id="1_0wfyh"]
[ext_resource type="Shader" uid="uid://dif4yb3527o0r" path="res://scenes/floor.gdshader" id="1_sugp2"]
[ext_resource type="PackedScene" uid="uid://nk8hrlhom63t" path="res://scenes/car3.tscn" id="2_sugp2"]
[ext_resource type="PackedScene" uid="uid://dvm8u67mw7kiy" path="res://scenes/gate.tscn" id="4_jyhfs"]

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_kuqtn"]
sky_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
Expand All @@ -14,9 +15,9 @@ sky_material = SubResource("ProceduralSkyMaterial_kuqtn")
[sub_resource type="Environment" id="Environment_3lc0u"]
background_mode = 1
background_color = Color(0.364706, 0, 0.0862745, 1)
background_energy_multiplier = 4.0
sky = SubResource("Sky_whr1e")
tonemap_mode = 2
glow_enabled = true

[sub_resource type="ShaderMaterial" id="ShaderMaterial_jyhfs"]
render_priority = 0
Expand All @@ -38,6 +39,44 @@ size = Vector2(6, 6)
data = PackedVector3Array(50, 0, 50, -50, 0, 50, 50, 0, -50, -50, 0, 50, -50, 0, -50, 50, 0, -50)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_kuqtn"]
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Several StyleBoxFlat sub-resources share identical properties; consider defining a single reusable style resource and referencing it to reduce duplication and simplify future updates.

Suggested change
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_kuqtn"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_Shared"]

Copilot uses AI. Check for mistakes.
bg_color = Color(0.91815, 0, 0.228352, 1)
border_width_left = 5
border_width_top = 5
border_width_right = 5
border_width_bottom = 5
border_color = Color(0.825689, 0.839261, 7.70092e-07, 1)
corner_radius_top_left = 10
corner_radius_top_right = 10
corner_radius_bottom_right = 10
corner_radius_bottom_left = 10

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tbgi4"]
content_margin_left = 15.0
content_margin_right = 15.0
bg_color = Color(0.91815, 0, 0.228352, 1)
border_width_left = 5
border_width_top = 5
border_width_right = 5
border_width_bottom = 5
border_color = Color(0.825689, 0.839261, 7.70092e-07, 1)
corner_radius_top_left = 10
corner_radius_top_right = 10
corner_radius_bottom_right = 10
corner_radius_bottom_left = 10

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jyhfs"]
content_margin_left = 15.0
content_margin_right = 15.0
bg_color = Color(0.91815, 0, 0.228352, 1)
border_width_left = 5
border_width_top = 5
border_width_right = 5
border_width_bottom = 5
border_color = Color(0.825689, 0.839261, 7.70092e-07, 1)
corner_radius_top_left = 10
corner_radius_top_right = 10
corner_radius_bottom_right = 10
corner_radius_bottom_left = 10

[node name="Main" type="MainScene"]

Expand All @@ -55,6 +94,9 @@ sky_mode = 1
material_override = SubResource("ShaderMaterial_jyhfs")
mesh = SubResource("PlaneMesh_0wfyh")

[node name="Gate" parent="StaticBody3D/Floor" instance=ExtResource("4_jyhfs")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.5, 0.5, -0.5)

[node name="Car2" parent="StaticBody3D/Floor" instance=ExtResource("1_0wfyh")]
transform = Transform3D(1, 0, 1.06581e-14, 0, 1, 0, -1.06581e-14, 0, 1, -1.5, 0.5, -1)

Expand Down Expand Up @@ -83,6 +125,18 @@ offset_bottom = -26.0
grow_horizontal = 2
grow_vertical = 0
focus_mode = 0
theme_override_colors/font_color = Color(0.825689, 0.839261, 7.70092e-07, 1)
theme_override_font_sizes/font_size = 31
theme_override_styles/focus = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/disabled_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/disabled = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover_pressed_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/pressed_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/pressed = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/normal_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/normal = SubResource("StyleBoxFlat_kuqtn")
text = "Solve"

Expand All @@ -99,6 +153,18 @@ offset_bottom = -27.0
grow_horizontal = 2
grow_vertical = 0
focus_mode = 0
theme_override_colors/font_color = Color(0.825689, 0.839261, 7.70092e-07, 1)
theme_override_font_sizes/font_size = 31
theme_override_styles/focus = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/disabled_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/disabled = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover_pressed_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/pressed_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/pressed = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/normal_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/normal = SubResource("StyleBoxFlat_kuqtn")
text = "Load"

Expand All @@ -115,6 +181,18 @@ offset_bottom = -25.0
grow_horizontal = 2
grow_vertical = 0
focus_mode = 0
theme_override_colors/font_color = Color(0.825689, 0.839261, 7.70092e-07, 1)
theme_override_font_sizes/font_size = 31
theme_override_styles/focus = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/disabled_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/disabled = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover_pressed_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/pressed_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/pressed = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/normal_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/normal = SubResource("StyleBoxFlat_kuqtn")
text = "Reset"

Expand All @@ -127,6 +205,26 @@ offset_top = 25.0
offset_right = -30.0
offset_bottom = 69.0
grow_horizontal = 0
theme_override_styles/focus = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/disabled_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/disabled = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/hover = SubResource("StyleBoxFlat_tbgi4")
theme_override_styles/normal_mirrored = SubResource("StyleBoxFlat_kuqtn")
theme_override_styles/normal = SubResource("StyleBoxFlat_jyhfs")

[node name="NodeLabel" type="Label" parent="UI"]
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -177.0
offset_top = -23.0
offset_right = -99.0
grow_horizontal = 2
grow_vertical = 0
text = "Node: 0"

[node name="TimeLabel" type="Label" parent="UI"]
anchors_preset = 7
Expand All @@ -140,3 +238,49 @@ offset_right = 20.0
grow_horizontal = 2
grow_vertical = 0
text = "Time: 0.0s"

[node name="MoveLabel" type="Label" parent="UI"]
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = 111.0
offset_top = -25.0
offset_right = 189.0
offset_bottom = -2.0
grow_horizontal = 2
grow_vertical = 0
text = "Move: 0"

[node name="MarginContainer" type="MarginContainer" parent="UI"]
anchors_preset = 11
anchor_left = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -365.0
grow_horizontal = 0
grow_vertical = 2
mouse_filter = 2
theme_override_constants/margin_right = 20
theme_override_constants/margin_bottom = 20

[node name="ScrollContainer" type="ScrollContainer" parent="UI/MarginContainer"]
layout_mode = 2
mouse_filter = 2

[node name="VBoxContainer" type="VBoxContainer" parent="UI/MarginContainer/ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
mouse_filter = 2
theme_override_constants/separation = 20
alignment = 2

[node name="Label" type="Label" parent="UI/MarginContainer/ScrollContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 1
theme_override_styles/normal = SubResource("StyleBoxFlat_jyhfs")
text = "Congratulations! You reached the exit in \" + String::num_int64(current_manual_moves) + \" moves!"
vertical_alignment = 1
autowrap_mode = 1
Loading