Added wall generation to building
This commit is contained in:
parent
d0bb1ac5f0
commit
931aa8b350
@ -26,7 +26,7 @@ offset_bottom = 635.0
|
||||
text = "Confirm"
|
||||
|
||||
[node name="GameCam" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 24.5127, 23.2849, 20.9667)
|
||||
transform = Transform3D(1, 0, 0, 0, 0.182236, 0.983255, 0, -0.983255, 0.182236, 24.5127, 23.2849, 20.9667)
|
||||
size = 31.34
|
||||
script = ExtResource("3_7jktm")
|
||||
|
||||
|
||||
@ -27,58 +27,14 @@ func _ready():
|
||||
var tile = load_tile.instantiate()
|
||||
tile.set_position(pos)
|
||||
|
||||
tile.grid_pos = pos
|
||||
|
||||
tile.update(0, 2)
|
||||
|
||||
tile_dict[pos] = tile
|
||||
|
||||
add_child(tile)
|
||||
|
||||
func build_selection(b):
|
||||
#When the build or destroy button is clicked, changes the selected tiles to match the button's request
|
||||
|
||||
if not build_allowed:
|
||||
return
|
||||
|
||||
for i in selection_dict:
|
||||
var tile_selected = tile_dict[i]
|
||||
tile_selected.update(1, 4)
|
||||
|
||||
selection_dict.clear()
|
||||
|
||||
for i in tile_dict:
|
||||
#if not selection_dict.has(i):
|
||||
var tile_selected = tile_dict[i]
|
||||
tile_selected.update(1, 0)
|
||||
|
||||
func clear_selection():
|
||||
#When the clear button is clicked, it clears the selected tiles without doing anything.
|
||||
|
||||
for i in tile_dict:
|
||||
var tile_selected = tile_dict[i]
|
||||
tile_selected.update(1, 0)
|
||||
build_allowed = true
|
||||
|
||||
selection_dict.clear()
|
||||
|
||||
func end_select_drag():
|
||||
#Adds dragged tiles to the current selection on mouse-up
|
||||
|
||||
tile_count_x_hist = 0
|
||||
tile_count_z_hist = 0
|
||||
|
||||
selection_dict.merge(selection_drag_dict)
|
||||
|
||||
if verify_room():
|
||||
build_allowed = true
|
||||
for i in selection_dict:
|
||||
tile_dict[i].update(3, 0)
|
||||
else:
|
||||
build_allowed = false
|
||||
for i in selection_dict:
|
||||
tile_dict[i].update(4, 0)
|
||||
|
||||
selection_drag_dict.clear()
|
||||
|
||||
func draw_tile_click(click_pos):
|
||||
#starts a selection drag
|
||||
|
||||
@ -109,7 +65,8 @@ func init_select_drag(float_build_start_pos, float_build_mouse_pos):
|
||||
for z in range(min(0, tile_count_z), max(0, tile_count_z) + 1):
|
||||
var select_drag_pos = build_start_pos + Vector3i(x, 0, z)
|
||||
if tile_dict.has(select_drag_pos):
|
||||
select_drag_array.append(select_drag_pos)
|
||||
if not tile_dict[select_drag_pos].construction_mode == 4:
|
||||
select_drag_array.append(select_drag_pos)
|
||||
|
||||
if select_drag_array:
|
||||
draw_select_drag(select_drag_array)
|
||||
@ -117,29 +74,27 @@ func init_select_drag(float_build_start_pos, float_build_mouse_pos):
|
||||
func draw_select_drag(array):
|
||||
#Clears previous drag, then calls tile selection on all currently dragged tiles
|
||||
|
||||
selection_drag_dict.clear()
|
||||
|
||||
for i in tile_dict:
|
||||
if not selection_dict.has(i):
|
||||
var tile_selected = tile_dict[i]
|
||||
tile_selected.update(1, 0)
|
||||
|
||||
selection_drag_dict.clear()
|
||||
|
||||
for i in array:
|
||||
var id = i
|
||||
select_tile(id)
|
||||
select_tile(i)
|
||||
|
||||
func select_tile(pos):
|
||||
#Tells tiles to be selected
|
||||
|
||||
var tile = tile_dict[pos]
|
||||
|
||||
if not tile.construction_mode == 4:
|
||||
print(tile.construction_mode)
|
||||
if build_allowed:
|
||||
tile.update(3, 0)
|
||||
else:
|
||||
tile.update(4, 0)
|
||||
selection_drag_dict[pos] = tile
|
||||
selection_drag_dict[pos] = tile
|
||||
|
||||
if build_allowed:
|
||||
tile.update(3, 0)
|
||||
else:
|
||||
tile.update(4, 0)
|
||||
|
||||
func verify_room():
|
||||
#Verifies that a given selection is fully contiguous
|
||||
@ -148,6 +103,8 @@ func verify_room():
|
||||
var verify_queue_array = [verify_array[0]]
|
||||
var verify_checked_array = []
|
||||
|
||||
var wall_dict = {}
|
||||
|
||||
while verify_array:
|
||||
if not verify_queue_array:
|
||||
|
||||
@ -155,21 +112,77 @@ func verify_room():
|
||||
|
||||
var verify_pos = verify_queue_array.pop_back()
|
||||
|
||||
var verify_neighbor_array = [
|
||||
Vector3i(verify_pos.x + 1, 0, verify_pos.z),
|
||||
Vector3i(verify_pos.x - 1, 0, verify_pos.z),
|
||||
Vector3i(verify_pos.x, 0, verify_pos.z + 1),
|
||||
Vector3i(verify_pos.x, 0, verify_pos.z - 1)
|
||||
]
|
||||
var verify_neighbor_array = tile_dict[verify_pos].neighbor_array
|
||||
|
||||
for n in verify_neighbor_array:
|
||||
|
||||
if selection_dict.has(n):
|
||||
if not verify_checked_array.has(n):
|
||||
if not verify_queue_array.has(n):
|
||||
verify_queue_array.append(n)
|
||||
if selection_dict.has(verify_pos + n):
|
||||
if not verify_checked_array.has(verify_pos + n):
|
||||
if not verify_queue_array.has(verify_pos + n):
|
||||
verify_queue_array.append(verify_pos + n)
|
||||
|
||||
verify_checked_array.append(verify_pos)
|
||||
verify_array.erase(verify_pos)
|
||||
|
||||
return true
|
||||
|
||||
func end_select_drag():
|
||||
#Adds dragged tiles to the current selection on mouse-up
|
||||
|
||||
tile_count_x_hist = 0
|
||||
tile_count_z_hist = 0
|
||||
|
||||
selection_dict.merge(selection_drag_dict)
|
||||
|
||||
for i in selection_dict.keys():
|
||||
var tile = selection_dict[i]
|
||||
for j in range(4):
|
||||
tile.update_face(j, 1)
|
||||
var neighbor = 0
|
||||
for j in tile.neighbor_array:
|
||||
if not selection_dict.has(i + j):
|
||||
tile.update_face(neighbor, 2)
|
||||
neighbor = neighbor + 1
|
||||
|
||||
if verify_room():
|
||||
build_allowed = true
|
||||
for i in selection_dict:
|
||||
tile_dict[i].update(3, 0)
|
||||
else:
|
||||
build_allowed = false
|
||||
for i in selection_dict:
|
||||
tile_dict[i].update(4, 0)
|
||||
|
||||
selection_drag_dict.clear()
|
||||
|
||||
func build_selection():
|
||||
#When the build or destroy button is clicked, changes the selected tiles to match the button's request
|
||||
|
||||
if not build_allowed:
|
||||
return
|
||||
|
||||
for i in selection_dict:
|
||||
var tile_selected = tile_dict[i]
|
||||
tile_selected.update(1, 4)
|
||||
|
||||
selection_dict.clear()
|
||||
|
||||
for i in tile_dict:
|
||||
#if not selection_dict.has(i):
|
||||
var tile_selected = tile_dict[i]
|
||||
tile_selected.update(1, 0)
|
||||
|
||||
func clear_selection():
|
||||
#When the clear button is clicked, it clears the selected tiles without doing anything.
|
||||
|
||||
for i in selection_dict:
|
||||
var tile_selected = selection_dict[i]
|
||||
tile_selected.update(1, 0)
|
||||
build_allowed = true
|
||||
|
||||
for i in selection_dict.keys():
|
||||
var tile = selection_dict[i]
|
||||
for j in range(4):
|
||||
tile.update_face(j, 1)
|
||||
|
||||
selection_dict.clear()
|
||||
|
||||
@ -43,7 +43,7 @@ func _on_area_3d_input_event(_camera, event, event_position, _normal, _shade_id)
|
||||
|
||||
func _on_confirm_button_pressed() -> void:
|
||||
if place.build_allowed:
|
||||
place.build_selection(true)
|
||||
place.build_selection()
|
||||
is_building = false
|
||||
emit_signal("room_built")
|
||||
else:
|
||||
|
||||
9
tiles/base_tile/base_wall.tscn
Normal file
9
tiles/base_tile/base_wall.tscn
Normal file
@ -0,0 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://diovc4myisuow"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_xdfmn"]
|
||||
|
||||
[node name="Node3D" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 0.1, 0.5, 0.5, 0.05)
|
||||
mesh = SubResource("BoxMesh_xdfmn")
|
||||
@ -37,7 +37,7 @@ var red = preload("res://tiles/base_tile/red.tres")
|
||||
var blue = preload("res://tiles/base_tile/blue.tres")
|
||||
var lightblue = preload("res://tiles/base_tile/lightblue.tres")
|
||||
|
||||
var faces = {
|
||||
var face_dict = {
|
||||
"floor": null,
|
||||
"north": null,
|
||||
"east": null,
|
||||
@ -45,12 +45,55 @@ var faces = {
|
||||
"west": null
|
||||
}
|
||||
|
||||
var neighbor_array = [
|
||||
Vector3i(0, 0, -1),
|
||||
Vector3i(1, 0, 0),
|
||||
Vector3i(0, 0, 1),
|
||||
Vector3i(-1, 0, 0),
|
||||
]
|
||||
|
||||
var wall_array = [
|
||||
Vector3i(0, 0, 0),
|
||||
Vector3i(1, 0, 0),
|
||||
Vector3i(1, 0, 1),
|
||||
Vector3i(0, 0, 1),
|
||||
]
|
||||
|
||||
var load_wall = preload("res://tiles/base_tile/base_wall.tscn")
|
||||
|
||||
var grid_pos = null
|
||||
|
||||
var wall_dict = {}
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
func invalid_this_tile():
|
||||
pass
|
||||
|
||||
func update_face(neighbor_index, mode):
|
||||
|
||||
var face = neighbor_array[neighbor_index]
|
||||
|
||||
if mode == 1:
|
||||
for i in wall_dict.keys():
|
||||
wall_dict[i].queue_free()
|
||||
wall_dict.erase(i)
|
||||
|
||||
if mode == 2:
|
||||
if not wall_dict.has(face):
|
||||
|
||||
var wall = load_wall.instantiate()
|
||||
|
||||
wall.position = wall_array[neighbor_index]
|
||||
|
||||
wall.rotation_degrees = Vector3(0, neighbor_index * -90, 0)
|
||||
|
||||
wall_dict[face] = wall
|
||||
|
||||
add_child(wall)
|
||||
|
||||
|
||||
func update(sel_mode: int = 0, con_mode: int = 0):
|
||||
|
||||
if sel_mode:
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://gs6yynwvvot2"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://gs6yynwvvot2"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://jqjcr7dxjnbt" path="res://tiles/base_tile/tile.gd" id="1_v7x5k"]
|
||||
[ext_resource type="PlaneMesh" uid="uid://bis4hdushjnjm" path="res://tiles/base_tile/base_floor.tres" id="2_ipr02"]
|
||||
[ext_resource type="Script" uid="uid://df68d87131dv7" path="res://tiles/base_tile/wall.gd" id="3_tmpem"]
|
||||
|
||||
[node name="Tile" type="Node3D"]
|
||||
script = ExtResource("1_v7x5k")
|
||||
@ -13,15 +14,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0, 0.5)
|
||||
mesh = ExtResource("2_ipr02")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Walls" type="Node" parent="."]
|
||||
|
||||
[node name="NorthWall" type="Node3D" parent="Walls"]
|
||||
|
||||
[node name="EastWall" type="Node3D" parent="Walls"]
|
||||
|
||||
[node name="SouthWall" type="Node3D" parent="Walls"]
|
||||
|
||||
[node name="WestWall" type="Node3D" parent="Walls"]
|
||||
[node name="Walls" type="Node3D" parent="."]
|
||||
script = ExtResource("3_tmpem")
|
||||
|
||||
[node name="Label3D" type="Label3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.0668138, 0.997765, 0, -0.997765, 0.0668138, 0.341829, 0.0223614, 0.130147)
|
||||
|
||||
14
tiles/base_tile/wall.gd
Normal file
14
tiles/base_tile/wall.gd
Normal file
@ -0,0 +1,14 @@
|
||||
extends Node3D
|
||||
|
||||
var wall = preload("res://tiles/base_tile/base_wall.tscn")
|
||||
|
||||
var _debug_face_mode = {
|
||||
1: "none",
|
||||
2: "full",
|
||||
3: "partial",
|
||||
4: "door"
|
||||
}
|
||||
|
||||
func update(walls: Dictionary):
|
||||
for i in walls:
|
||||
print(i)
|
||||
1
tiles/base_tile/wall.gd.uid
Normal file
1
tiles/base_tile/wall.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://df68d87131dv7
|
||||
Loading…
Reference in New Issue
Block a user