From f1ab533c8d3235d873d61c18ed9912d8490dcac3 Mon Sep 17 00:00:00 2001 From: jarv1s <19623185@std.stei.itb.ac.id> Date: Tue, 20 May 2025 00:09:04 +0700 Subject: [PATCH 1/4] feat: add gate --- src/main_scene/main_scene.cpp | 26 +++++++++++++++++++++--- src/main_scene/main_scene.hpp | 1 + test/2.txt | 4 ++-- tukang-parkir-simulator/scenes/gate.tscn | 19 +++++++++++++++++ tukang-parkir-simulator/scenes/main.tscn | 8 ++++++-- 5 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 tukang-parkir-simulator/scenes/gate.tscn diff --git a/src/main_scene/main_scene.cpp b/src/main_scene/main_scene.cpp index af26269..1327cb2 100644 --- a/src/main_scene/main_scene.cpp +++ b/src/main_scene/main_scene.cpp @@ -72,6 +72,7 @@ void MainScene::_notification(int p_what) { ResourceLoader* rl = ResourceLoader::get_singleton(); car2_template = rl->load("res://scenes/car2.tscn"); car3_template = rl->load("res://scenes/car3.tscn"); + gate_template = rl->load("res://scenes/gate.tscn"); primary_piece_material = rl->load("res://scenes/primary_material.tres"); non_primary_piece_material = rl->load("res://scenes/non_primary_material.tres"); @@ -389,6 +390,22 @@ void MainScene::_on_load_file_selected(const String& path) { reset_button->set_disabled(false); _clear_all_cars(); + + + Node3D* gate_node = Object::cast_to(gate_template->instantiate()); + if (gate_node) { + floor->add_child(gate_node); + + float actual_exit_col = static_cast(board.exit_coordinates.x - board.piece_padding); + float actual_exit_row = static_cast(board.exit_coordinates.y - board.piece_padding); + + float gate_x_pos = actual_exit_col - (static_cast(board.cols) / 2.0f) + 0.5f; + float gate_z_pos = actual_exit_row - (static_cast(board.rows) / 2.0f) + 0.5f; + float gate_y_pos = 0.5f; + + gate_node->set_position(Vector3(gate_x_pos, gate_y_pos, gate_z_pos)); + } + for (const auto& piece_data : this->pieces) { _spawn_piece_as_car(piece_data); } @@ -616,9 +633,12 @@ bool MainScene::load_input(String path, vector& pieces, Board& board) { } void MainScene::_clear_all_cars() { - for (Node3D* car_node : spawned_car_nodes) { - if (car_node && car_node->get_parent()) { - car_node->queue_free(); + if (floor) { + for (int i = floor->get_child_count() - 1; i >= 0; i--) { + Node *child = floor->get_child(i); + if (child) { + child->queue_free(); + } } } spawned_car_nodes.clear(); diff --git a/src/main_scene/main_scene.hpp b/src/main_scene/main_scene.hpp index 36920de..274c7ca 100644 --- a/src/main_scene/main_scene.hpp +++ b/src/main_scene/main_scene.hpp @@ -53,6 +53,7 @@ class MainScene : public Node3D { Ref car2_template; Ref car3_template; + Ref gate_template; Ref primary_piece_material; Ref non_primary_piece_material; MeshInstance3D* floor = nullptr; diff --git a/test/2.txt b/test/2.txt index c6557da..2760bbf 100644 --- a/test/2.txt +++ b/test/2.txt @@ -1,6 +1,6 @@ 5 5 -5 -EAAA. +4 +...P. ED.PB .D.PB .DCCB diff --git a/tukang-parkir-simulator/scenes/gate.tscn b/tukang-parkir-simulator/scenes/gate.tscn new file mode 100644 index 0000000..2b587b2 --- /dev/null +++ b/tukang-parkir-simulator/scenes/gate.tscn @@ -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") diff --git a/tukang-parkir-simulator/scenes/main.tscn b/tukang-parkir-simulator/scenes/main.tscn index 4b709ae..e198ae0 100644 --- a/tukang-parkir-simulator/scenes/main.tscn +++ b/tukang-parkir-simulator/scenes/main.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=12 format=3 uid="uid://deic8j1v28f5m"] +[gd_scene load_steps=13 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) @@ -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 @@ -55,6 +56,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) From 08805dff84a92765acfbddf62d1f7321ca6c91f5 Mon Sep 17 00:00:00 2001 From: jarv1s <19623185@std.stei.itb.ac.id> Date: Tue, 20 May 2025 01:07:25 +0700 Subject: [PATCH 2/4] feat: update UI labels for nodes, time, and moves; improve error handling --- src/main_scene/main_scene.cpp | 17 +++- src/main_scene/main_scene.hpp | 13 ++- tukang-parkir-simulator/export_presets.cfg | 4 +- tukang-parkir-simulator/project.godot | 1 + tukang-parkir-simulator/scenes/main.tscn | 110 ++++++++++++++++++++- 5 files changed, 136 insertions(+), 9 deletions(-) diff --git a/src/main_scene/main_scene.cpp b/src/main_scene/main_scene.cpp index 1327cb2..7044045 100644 --- a/src/main_scene/main_scene.cpp +++ b/src/main_scene/main_scene.cpp @@ -54,9 +54,15 @@ void MainScene::_notification(int p_what) { algo_button->select(0); } + node_label = get_node