From 8908b51103f20c7d7f63419ed215bc8efac85468 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Fri, 2 Aug 2024 04:38:05 +0300 Subject: [PATCH] proper handling of nesting in coordinates --- Art/Stone_11-128x128.png.import | 9 +++++---- Scripts/Space/Space.gd | 11 ++++++++--- Scripts/Space/SpaceRegion.gd | 15 ++++++++++++++- Scripts/Space/SpaceSpawn.gd | 2 +- Spaces/Dungeon.tscn | 24 +++++++++++++----------- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/Art/Stone_11-128x128.png.import b/Art/Stone_11-128x128.png.import index 6440107..d8de625 100644 --- a/Art/Stone_11-128x128.png.import +++ b/Art/Stone_11-128x128.png.import @@ -3,19 +3,20 @@ importer="texture" type="CompressedTexture2D" uid="uid://eempmja460l5" -path="res://.godot/imported/Stone_11-128x128.png-74289798a2555c4732a5c0fbe1b7230c.ctex" +path.s3tc="res://.godot/imported/Stone_11-128x128.png-74289798a2555c4732a5c0fbe1b7230c.s3tc.ctex" metadata={ -"vram_texture": false +"imported_formats": ["s3tc_bptc"], +"vram_texture": true } [deps] source_file="res://Art/Stone_11-128x128.png" -dest_files=["res://.godot/imported/Stone_11-128x128.png-74289798a2555c4732a5c0fbe1b7230c.ctex"] +dest_files=["res://.godot/imported/Stone_11-128x128.png-74289798a2555c4732a5c0fbe1b7230c.s3tc.ctex"] [params] -compress/mode=0 +compress/mode=2 compress/high_quality=false compress/lossy_quality=0.7 compress/hdr_compression=1 diff --git a/Scripts/Space/Space.gd b/Scripts/Space/Space.gd index 8ab65c2..c07878a 100644 --- a/Scripts/Space/Space.gd +++ b/Scripts/Space/Space.gd @@ -22,8 +22,13 @@ func generate_geometry() -> Node3D: func get_spawn_point() -> Vector3: - for child in get_children(): - if child is SpaceSpawn: - return child.space_position(self) + var stack := [self] + + while stack: + var node = stack.pop_front() + for child in node.get_children(): + if child is SpaceSpawn: + return child.space_position(self) + stack.push_back(child) return Vector3.ZERO diff --git a/Scripts/Space/SpaceRegion.gd b/Scripts/Space/SpaceRegion.gd index b962f73..f60a252 100644 --- a/Scripts/Space/SpaceRegion.gd +++ b/Scripts/Space/SpaceRegion.gd @@ -1,7 +1,10 @@ +@tool extends SpaceEntity -class_name SpaceRegion +## Classic 2.5D sector beauty. +## +class_name SpaceRegion @export var elevation: float = 0.0 @export var height: float = 100.0 @@ -13,9 +16,19 @@ func generate_geometry(space: Space) -> Node3D: return _generate_geometry(space, true) +func _process(delta): + if Engine.is_editor_hint(): + self.texture = floor_texture + + func _generate_geometry(space: Space, looked_from_inside: bool) -> Node3D: var geometry := MeshInstance3D.new() geometry.name = name + geometry.position = Vector3( + position.x * space.unit_scale, + 0, + position.y * space.unit_scale, + ) var mesh := ArrayMesh.new() mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, _generate_wall_arrays(space, looked_from_inside)) diff --git a/Scripts/Space/SpaceSpawn.gd b/Scripts/Space/SpaceSpawn.gd index 0b180b7..20311b6 100644 --- a/Scripts/Space/SpaceSpawn.gd +++ b/Scripts/Space/SpaceSpawn.gd @@ -7,4 +7,4 @@ class_name SpaceSpawn func space_position(space: Space) -> Vector3: # todo: Get current region elevation - return Vector3(position.x * space.unit_scale, 0, position.y * space.unit_scale) + return Vector3(global_position.x * space.unit_scale, 0, global_position.y * space.unit_scale) diff --git a/Spaces/Dungeon.tscn b/Spaces/Dungeon.tscn index 74bb6ef..62cf890 100644 --- a/Spaces/Dungeon.tscn +++ b/Spaces/Dungeon.tscn @@ -1,33 +1,35 @@ -[gd_scene load_steps=8 format=3 uid="uid://deff7lt34nj0h"] +[gd_scene load_steps=7 format=3 uid="uid://deff7lt34nj0h"] [ext_resource type="Script" path="res://Scripts/Space/Space.gd" id="1_ckp7u"] [ext_resource type="Script" path="res://Scripts/Space/SpaceRegion.gd" id="2_s3h7s"] [ext_resource type="Texture2D" uid="uid://h0skytm8grcu" path="res://icon.svg" id="3_7vff1"] [ext_resource type="Texture2D" uid="uid://icmmuqquxhq3" path="res://Art/Stone_06-128x128.png" id="3_ondo6"] -[ext_resource type="Texture2D" uid="uid://buoupwtftxjse" path="res://Art/Stone_05-128x128.png" id="3_r08k8"] [ext_resource type="Texture2D" uid="uid://eempmja460l5" path="res://Art/Stone_11-128x128.png" id="4_mnswr"] [ext_resource type="Script" path="res://Scripts/Space/SpaceSpawn.gd" id="4_rhl23"] [node name="Dungeon" type="Node2D"] script = ExtResource("1_ckp7u") +unit_scale = 0.02 [node name="Room" type="Polygon2D" parent="."] -position = Vector2(-30, -8) -polygon = PackedVector2Array(30, 72, 262, 32, 497, 192, 286, 328, 94, 264) +texture_repeat = 2 +position = Vector2(440, 136) +texture = ExtResource("4_mnswr") +polygon = PackedVector2Array(-104, -80, 40, -112, 128, -16, 328, -56, 360, 16, 176, 56, 32, 96, -80, 64) +uv = PackedVector2Array(1.88, 5.28, 0.6, 1.44, 5.24, 0.64, 5.24, 0.64, 9.94, 3.84, 5.72, 6.56, 5.72, 6.56, 1.88, 5.28, 5.24, 0.64) script = ExtResource("2_s3h7s") wall_texture = ExtResource("3_ondo6") floor_texture = ExtResource("4_mnswr") [node name="Column" type="Polygon2D" parent="Room"] -position = Vector2(78, -8) -color = Color(0.665891, 0.820479, 1, 1) -polygon = PackedVector2Array(222, 168, 272, 136, 318, 184, 294, 232, 230, 216) +texture_repeat = 2 +polygon = PackedVector2Array(8, -40, 48, -64, 88, -24, 64, 0, 24, -8) +uv = PackedVector2Array(1.88, 5.28, 0.6, 1.44, 5.24, 0.64, 5.24, 0.64, 9.94, 3.84, 5.72, 6.56, 5.72, 6.56, 1.88, 5.28, 5.24, 0.64) script = ExtResource("2_s3h7s") -wall_texture = ExtResource("3_r08k8") -floor_texture = ExtResource("3_r08k8") +wall_texture = ExtResource("3_ondo6") -[node name="Spawn" type="Sprite2D" parent="."] -position = Vector2(72, 104) +[node name="Spawn" type="Sprite2D" parent="Room"] +position = Vector2(-48, 32) rotation = 0.159622 scale = Vector2(0.25, 0.25) texture = ExtResource("3_7vff1")