Skip to content

Commit

Permalink
feat: spawn&kill scene and parenting transform (#2)
Browse files Browse the repository at this point in the history
* feat: spawn and kill scene

* split to components

* rust: add parenting with cyclic checker
godot: add grid and improve ui to test

* fix fmt
  • Loading branch information
leanmendoza authored May 25, 2023
1 parent 471b91d commit 7b49c80
Show file tree
Hide file tree
Showing 21 changed files with 14,989 additions and 388 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:

build:
name: Build and test
# if: ${{ github.ref == 'refs/heads/main' }}
if: ${{ github.ref == 'refs/heads/main' }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
Expand Down Expand Up @@ -170,7 +170,7 @@ jobs:
name: Export (all platforms)
needs: build
runs-on: ubuntu-latest
# if: ${{ github.ref == 'refs/heads/main' }}
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v2
- name: Download linux lib artifact
Expand Down
41 changes: 30 additions & 11 deletions godot/Main.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
extends Node

var scene_runner: SceneRunner
@onready var scene_list = $UI/Panel_Scenes/ItemList_Scenes

# Called when the node enters the scene tree for the first time.
func _process(delta):
%Label_FPS.set_text(str(Engine.get_frames_per_second()) + " FPS")

func _ready():
pass

var main_class: MainTestClass = MainTestClass.new()
print('main class created')
scene_runner = SceneRunner.new()
self.add_child(scene_runner)
print('scene_runner created')

$UI/Panel_SpawnScene/OptionButton_SceneToSpawn.clear()
for path in DirAccess.get_directories_at("res://assets/scenes"):
$UI/Panel_SpawnScene/OptionButton_SceneToSpawn.add_item(path)
$UI/Panel_SpawnScene/OptionButton_SceneToSpawn.select(0)
func _on_add_button_pressed():
var path = $UI/Panel_SpawnScene/OptionButton_SceneToSpawn.text
var scene_id = scene_runner.start_scene(path, Vector3(float($UI/Panel_SpawnScene/X.value) * 16, 0, float($UI/Panel_SpawnScene/Z.value) * 16))
var item = scene_list.add_item(path)
scene_list.set_item_metadata(item, scene_id)

main_class.start_scene()
self.add_child(main_class)

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
$Label.set_text("FPS " + str(Engine.get_frames_per_second()))
func _on_button_delete_scene_pressed():
var selected = scene_list.get_selected_items()
if selected.size() > 0:
var scene_id: int = scene_list.get_item_metadata(selected[0])
if scene_runner.kill_scene(scene_id):
print(scene_id, " scene deleted")
scene_list.remove_item(selected[0])
if scene_list.item_count > 0:
scene_list.select(0)
else:
print(scene_id, " couldn't delete scene")

223 changes: 199 additions & 24 deletions godot/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
[gd_scene load_steps=8 format=3 uid="uid://cyfwty2q3rdse"]
[gd_scene load_steps=11 format=3 uid="uid://cyfwty2q3rdse"]

[ext_resource type="Script" path="res://Main.gd" id="1_nv2ru"]
[ext_resource type="Script" path="res://Camera.gd" id="2_1rghv"]
[ext_resource type="Texture2D" uid="uid://m7i23bc2yyqt" path="res://grid.png" id="3_g6j8l"]

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_jtcv1"]
sky_top_color = Color(0.827451, 0.760784, 0.639216, 1)
sky_horizon_color = Color(0.615686, 0.560784, 0.619608, 1)
ground_bottom_color = Color(0.4, 0.278431, 0.207843, 1)
sun_angle_max = 120.0
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_4tfnw"]
sky_top_color = Color(0.384314, 0.454902, 0.54902, 1)

[sub_resource type="Sky" id="Sky_7xgv5"]
sky_material = SubResource("ProceduralSkyMaterial_jtcv1")
[sub_resource type="Sky" id="Sky_054c4"]
sky_material = SubResource("ProceduralSkyMaterial_4tfnw")

[sub_resource type="Environment" id="Environment_immgo"]
background_mode = 2
sky = SubResource("Sky_7xgv5")
sky = SubResource("Sky_054c4")
ambient_light_source = 3
ambient_light_color = Color(1, 1, 1, 1)
reflected_light_source = 2
volumetric_fog_emission = Color(0.635294, 0.635294, 0.635294, 1)
adjustment_brightness = 1.41

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_gyax8"]
albedo_color = Color(1, 0.67451, 1, 1)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_lovo8"]

[sub_resource type="PlaneMesh" id="PlaneMesh_x854j"]
material = SubResource("ShaderMaterial_lovo8")
size = Vector2(1024, 1024)

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_fstik"]
albedo_texture = ExtResource("3_g6j8l")
uv1_scale = Vector3(512, 512, 512)

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ftw7c"]
albedo_color = Color(0, 0.654902, 0.658824, 1)
Expand All @@ -33,24 +43,189 @@ script = ExtResource("2_1rghv")
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_immgo")

[node name="FloorCube3D" type="CSGBox3D" parent="."]
transform = Transform3D(16, 0, 0, 0, 0.026, 0, 0, 0, 16, 8, 0, 8)
material = SubResource("StandardMaterial3D_gyax8")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -0.5, 0.866025, 0, -0.866025, -0.5, 1, 22, 0)

[node name="Floor" type="MeshInstance3D" parent="."]
mesh = SubResource("PlaneMesh_x854j")
surface_material_override/0 = SubResource("StandardMaterial3D_fstik")

[node name="OriginCube3D" type="CSGBox3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.504672, 0)
material = SubResource("StandardMaterial3D_ftw7c")

[node name="SpotLight3D" type="SpotLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 17, 6)
[node name="UI" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="Label" type="Label" parent="."]
offset_right = 149.0
offset_bottom = 23.0
text = "FPS: "
[node name="Label_FPS" type="Label" parent="UI"]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -157.0
offset_top = 8.0
offset_right = -8.0
offset_bottom = 34.0
grow_horizontal = 0
text = "FPS"
horizontal_alignment = 2

[node name="Label2" type="Label" parent="."]
offset_top = 32.0
offset_right = 40.0
offset_bottom = 55.0
[node name="Label_Info" type="Label" parent="UI"]
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 8.0
offset_top = -34.0
offset_right = 386.0
offset_bottom = -8.0
grow_vertical = 0
text = "Move with WASD, camera with holding right-click"

[node name="Panel_SpawnScene" type="Panel" parent="UI"]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -432.0
offset_top = -179.0
offset_right = -208.0
offset_bottom = -8.0
grow_horizontal = 0
grow_vertical = 0

[node name="Button_AddScene" type="Button" parent="UI/Panel_SpawnScene"]
layout_mode = 1
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -97.0
offset_top = -39.0
offset_right = 95.0
offset_bottom = -8.0
grow_horizontal = 2
grow_vertical = 0
text = "Spawn scene"

[node name="X" type="SpinBox" parent="UI/Panel_SpawnScene"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -97.5313
offset_top = 80.0
offset_right = -14.4688
offset_bottom = 115.0
grow_horizontal = 2
min_value = -10.0
max_value = 10.0

[node name="Z" type="SpinBox" parent="UI/Panel_SpawnScene"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = 14.4688
offset_top = 80.0
offset_right = 97.5313
offset_bottom = 115.0
grow_horizontal = 2
min_value = -10.0
max_value = 10.0

[node name="Label" type="Label" parent="UI/Panel_SpawnScene"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -54.5
offset_top = 48.0
offset_right = 54.5
offset_bottom = 74.0
grow_horizontal = 2
text = "Parcel coords:"

[node name="OptionButton_SceneToSpawn" type="OptionButton" parent="UI/Panel_SpawnScene"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -96.0
offset_top = 8.0
offset_right = 96.0
offset_bottom = 39.0
grow_horizontal = 2
item_count = 2
selected = 0
popup/item_0/text = "parent_list"
popup/item_0/id = 0
popup/item_1/text = "cube_wave"
popup/item_1/id = 1

[node name="Panel_Scenes" type="Panel" parent="UI"]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -194.0
offset_top = -177.0
offset_right = -8.0
offset_bottom = -6.0
grow_horizontal = 0
grow_vertical = 0

[node name="ItemList_Scenes" type="ItemList" parent="UI/Panel_Scenes"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 16.0
offset_top = 27.0
offset_right = -16.0
offset_bottom = -47.0
grow_horizontal = 2
grow_vertical = 2

[node name="Button_DeleteScene" type="Button" parent="UI/Panel_Scenes"]
layout_mode = 1
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 15.0
offset_top = -39.0
offset_right = -17.0
offset_bottom = -8.0
grow_horizontal = 2
grow_vertical = 0
text = "Delete"

[node name="Label" type="Label" parent="UI/Panel_Scenes"]
layout_mode = 1
anchors_preset = 10
anchor_right = 1.0
offset_bottom = 26.0
grow_horizontal = 2
text = "Scenes"
horizontal_alignment = 1
vertical_alignment = 1

[node name="Control" type="Control" parent="UI"]
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0

[connection signal="pressed" from="UI/Panel_SpawnScene/Button_AddScene" to="." method="_on_add_button_pressed"]
[connection signal="pressed" from="UI/Panel_Scenes/Button_DeleteScene" to="." method="_on_button_delete_scene_pressed"]
Loading

0 comments on commit 7b49c80

Please sign in to comment.