Broad tidying, door creation
This commit is contained in:
parent
a1dec4b25c
commit
2f5f465799
@ -1,54 +1,67 @@
|
|||||||
extends Node3D
|
extends Node3D
|
||||||
|
|
||||||
var tile_grid_size = 64
|
var tile_grid_size: int = 32
|
||||||
|
|
||||||
var load_tile = preload("res://tiles/base_tile/base_tile.tscn")
|
var load_tile = preload("res://tiles/base_tile/base_tile.tscn")
|
||||||
var load_room = preload("res://places/base_place/base_room.tscn")
|
var load_room = preload("res://places/base_place/base_room.tscn")
|
||||||
var load_door = preload("res://tiles/base_tile/base_door.tscn")
|
var load_door = preload("res://tiles/base_tile/base_door.tscn")
|
||||||
|
|
||||||
var place_tile_dict = {}
|
#Contains all tiles in a workplace.
|
||||||
|
var place_tile_dict: Dictionary = {}
|
||||||
|
|
||||||
var selection_drag_dict = {}
|
#Contains the tiles in the current selection drag
|
||||||
var selection_dict = {}
|
var selection_drag_dict: Dictionary = {}
|
||||||
|
#Contains all the tiles that have been selected in the current build
|
||||||
|
var selection_dict: Dictionary = {}
|
||||||
|
|
||||||
var room_dict = {}
|
#Contains all rooms in a workplace.
|
||||||
|
var room_dict: Dictionary = {}
|
||||||
|
|
||||||
var tile_count_x_hist = null
|
#Tracks the previous amount of tiles counted in a selection drac
|
||||||
var tile_count_z_hist = null
|
var tile_count_x_hist: int = 0
|
||||||
|
var tile_count_z_hist: int = 0
|
||||||
|
|
||||||
var build_allowed = true
|
#Tracks is confirming a build is allowed
|
||||||
|
var build_confirm_allowed: bool = true
|
||||||
|
|
||||||
var current_room = null
|
#Tracks parts of the room currently being built
|
||||||
var current_room_walls = []
|
var current_room: Object = null
|
||||||
var current_door = null
|
var current_room_walls: Array = []
|
||||||
|
var current_door: Object = null
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
|
||||||
#connect("wall_built", record_walls)
|
#TEMP: Sets up a simple 2D grid of blank tiles.
|
||||||
|
|
||||||
#Sets up a simple 2D grid of blank tiles.
|
|
||||||
|
|
||||||
for x in range(tile_grid_size):
|
for x in range(tile_grid_size):
|
||||||
for z in range (tile_grid_size):
|
for z in range (tile_grid_size):
|
||||||
var pos = Vector3i(x, 0, z)
|
var pos = Vector3i(x, 0, z)
|
||||||
|
|
||||||
var tile = load_tile.instantiate()
|
var tile: Object = load_tile.instantiate()
|
||||||
tile.set_position(pos)
|
tile.set_position(pos)
|
||||||
|
|
||||||
tile.grid_pos = pos
|
tile.grid_pos = pos
|
||||||
|
|
||||||
tile.update(0, 2)
|
tile.update(Tile.SEL_MODE.NONE, Tile.CON_MODE.CLOSED)
|
||||||
|
|
||||||
place_tile_dict[pos] = tile
|
place_tile_dict[pos] = tile
|
||||||
|
|
||||||
add_child(tile)
|
add_child(tile)
|
||||||
|
|
||||||
|
var pos: Vector3i = Vector3i(1, 0, 1)
|
||||||
|
|
||||||
|
var tile: Object = place_tile_dict[pos]
|
||||||
|
|
||||||
|
selection_drag_dict[pos] = tile
|
||||||
|
end_select_drag()
|
||||||
|
build_selection()
|
||||||
|
|
||||||
func draw_tile_click(click_pos):
|
func draw_tile_click(click_pos):
|
||||||
#starts a selection drag
|
#starts a selection drag
|
||||||
|
|
||||||
var build_start_pos: Vector3i = click_pos.floor()
|
var build_start_pos: Vector3i = click_pos.floor()
|
||||||
tile_count_x_hist = 0
|
#tile_count_x_hist = 0
|
||||||
tile_count_z_hist = 0
|
#tile_count_z_hist = 0
|
||||||
|
|
||||||
if place_tile_dict.has(build_start_pos):
|
if place_tile_dict.has(build_start_pos):
|
||||||
select_tile(build_start_pos)
|
select_tile(build_start_pos)
|
||||||
@ -56,13 +69,13 @@ func draw_tile_click(click_pos):
|
|||||||
func init_select_drag(float_build_start_pos, float_build_mouse_pos):
|
func init_select_drag(float_build_start_pos, float_build_mouse_pos):
|
||||||
#Creats an array of dragged tiles between mouse start and current position
|
#Creats an array of dragged tiles between mouse start and current position
|
||||||
|
|
||||||
var select_drag_array = []
|
var select_drag_array: Array = []
|
||||||
|
|
||||||
var build_start_pos: Vector3i = float_build_start_pos.floor()
|
var build_start_pos: Vector3i = float_build_start_pos.floor()
|
||||||
var build_mouse_pos: Vector3i = float_build_mouse_pos.floor()
|
var build_mouse_pos: Vector3i = float_build_mouse_pos.floor()
|
||||||
|
|
||||||
var tile_count_x = build_mouse_pos.x - build_start_pos.x
|
var tile_count_x: int = build_mouse_pos.x - build_start_pos.x
|
||||||
var tile_count_z = build_mouse_pos.z - build_start_pos.z
|
var tile_count_z: int = build_mouse_pos.z - build_start_pos.z
|
||||||
|
|
||||||
if not tile_count_x_hist == tile_count_x or not tile_count_z_hist == tile_count_z:
|
if not tile_count_x_hist == tile_count_x or not tile_count_z_hist == tile_count_z:
|
||||||
|
|
||||||
@ -71,9 +84,9 @@ func init_select_drag(float_build_start_pos, float_build_mouse_pos):
|
|||||||
|
|
||||||
for x in range(min(0, tile_count_x), max(0, tile_count_x) + 1):
|
for x in range(min(0, tile_count_x), max(0, tile_count_x) + 1):
|
||||||
for z in range(min(0, tile_count_z), max(0, tile_count_z) + 1):
|
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)
|
var select_drag_pos: Vector3i = build_start_pos + Vector3i(x, 0, z)
|
||||||
if place_tile_dict.has(select_drag_pos):
|
if place_tile_dict.has(select_drag_pos):
|
||||||
if not place_tile_dict[select_drag_pos].construction_mode == 4:
|
if not place_tile_dict[select_drag_pos].construction_mode == Tile.CON_MODE.BUILT:
|
||||||
select_drag_array.append(select_drag_pos)
|
select_drag_array.append(select_drag_pos)
|
||||||
|
|
||||||
if select_drag_array:
|
if select_drag_array:
|
||||||
@ -84,8 +97,8 @@ func draw_select_drag(array):
|
|||||||
|
|
||||||
for i in place_tile_dict:
|
for i in place_tile_dict:
|
||||||
if not selection_dict.has(i):
|
if not selection_dict.has(i):
|
||||||
var tile_selected = place_tile_dict[i]
|
var tile: Object = place_tile_dict[i]
|
||||||
tile_selected.update(1, 0)
|
tile.update(Tile.SEL_MODE.NONE, )
|
||||||
|
|
||||||
selection_drag_dict.clear()
|
selection_drag_dict.clear()
|
||||||
|
|
||||||
@ -95,30 +108,30 @@ func draw_select_drag(array):
|
|||||||
func select_tile(pos):
|
func select_tile(pos):
|
||||||
#Tells tiles to be selected
|
#Tells tiles to be selected
|
||||||
|
|
||||||
var tile = place_tile_dict[pos]
|
var tile: Object = place_tile_dict[pos]
|
||||||
|
|
||||||
selection_drag_dict[pos] = tile
|
selection_drag_dict[pos] = tile
|
||||||
|
|
||||||
if build_allowed:
|
if build_confirm_allowed:
|
||||||
tile.update(3, 0)
|
tile.update(Tile.SEL_MODE.BUILD, )
|
||||||
else:
|
else:
|
||||||
tile.update(4, 0)
|
tile.update(Tile.SEL_MODE.INVALID, )
|
||||||
|
|
||||||
func verify_room():
|
func verify_room():
|
||||||
#Verifies that a given selection is fully contiguous
|
#Verifies that a given selection is fully contiguous
|
||||||
|
|
||||||
var verify_array = selection_dict.keys()
|
var verify_array: Array = selection_dict.keys()
|
||||||
var verify_queue_array = [verify_array[0]]
|
var verify_queue_array: Array = [verify_array[0]]
|
||||||
var verify_checked_array = []
|
var verify_checked_array: Array = []
|
||||||
|
|
||||||
while verify_array:
|
while verify_array:
|
||||||
if not verify_queue_array:
|
if not verify_queue_array:
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
var verify_pos = verify_queue_array.pop_back()
|
var verify_pos: Vector3i = verify_queue_array.pop_back()
|
||||||
|
|
||||||
var verify_neighbor_array = place_tile_dict[verify_pos].neighbor_array
|
var verify_neighbor_array: Array = place_tile_dict[verify_pos].direction_vector_array
|
||||||
|
|
||||||
for n in verify_neighbor_array:
|
for n in verify_neighbor_array:
|
||||||
|
|
||||||
@ -141,60 +154,61 @@ func end_select_drag():
|
|||||||
selection_dict.merge(selection_drag_dict)
|
selection_dict.merge(selection_drag_dict)
|
||||||
|
|
||||||
for i in selection_dict.keys():
|
for i in selection_dict.keys():
|
||||||
var tile = selection_dict[i]
|
var tile:Object = selection_dict[i]
|
||||||
for j in range(4):
|
for j in range(4):
|
||||||
tile.update_face(j, 1)
|
tile.update_face(j, Tile.FACE_MODE.NONE)
|
||||||
var neighbor = 0
|
for j in range(4):
|
||||||
for j in tile.neighbor_array:
|
if not selection_dict.has(i + tile.direction_vector_array[j]):
|
||||||
if not selection_dict.has(i + j):
|
tile.update_face(j, Tile.FACE_MODE.FULL)
|
||||||
tile.update_face(neighbor, 2)
|
|
||||||
neighbor = neighbor + 1
|
|
||||||
|
|
||||||
if verify_room():
|
if verify_room():
|
||||||
build_allowed = true
|
build_confirm_allowed = true
|
||||||
for i in selection_dict:
|
for i in selection_dict:
|
||||||
place_tile_dict[i].update(3, 0)
|
place_tile_dict[i].update(Tile.SEL_MODE.BUILD, )
|
||||||
else:
|
else:
|
||||||
build_allowed = false
|
build_confirm_allowed = false
|
||||||
for i in selection_dict:
|
for i in selection_dict:
|
||||||
place_tile_dict[i].update(4, 0)
|
place_tile_dict[i].update(Tile.SEL_MODE.INVALID, )
|
||||||
|
|
||||||
selection_drag_dict.clear()
|
selection_drag_dict.clear()
|
||||||
|
|
||||||
func build_selection():
|
func build_selection():
|
||||||
#When the build or destroy button is clicked, changes the selected tiles to match the button's request
|
#When the build or destroy button is clicked, changes the selected tiles to match the button's request
|
||||||
|
|
||||||
if not build_allowed:
|
if not build_confirm_allowed:
|
||||||
return
|
return
|
||||||
|
|
||||||
for i in selection_dict:
|
if selection_dict:
|
||||||
var tile_selected = place_tile_dict[i]
|
|
||||||
tile_selected.update(1, 4)
|
|
||||||
|
|
||||||
var room = create_room()
|
for i in selection_dict:
|
||||||
|
var tile: Object = place_tile_dict[i]
|
||||||
|
tile.update(Tile.SEL_MODE.NONE, Tile.CON_MODE.BUILT)
|
||||||
|
|
||||||
selection_dict.clear()
|
var room: Object = create_room()
|
||||||
|
|
||||||
return room
|
selection_dict.clear()
|
||||||
|
|
||||||
|
return room
|
||||||
|
|
||||||
func clear_selection():
|
func clear_selection():
|
||||||
#When the clear button is clicked, it clears the selected tiles without doing anything.
|
#When the clear button is clicked, it clears the selected tiles without doing anything.
|
||||||
|
|
||||||
for i in selection_dict:
|
for i in selection_dict:
|
||||||
var tile_selected = selection_dict[i]
|
var tile: Object = selection_dict[i]
|
||||||
tile_selected.update(1, 0)
|
tile.update(Tile.SEL_MODE.NONE, )
|
||||||
build_allowed = true
|
build_confirm_allowed = true
|
||||||
|
|
||||||
for i in selection_dict.keys():
|
for i in selection_dict.keys():
|
||||||
var tile = selection_dict[i]
|
var tile: Object = selection_dict[i]
|
||||||
for j in range(4):
|
for j in Tile.DIRECTION:
|
||||||
tile.update_face(j, 1)
|
tile.update_face(j, Tile.FACE_MODE.NONE)
|
||||||
|
|
||||||
selection_dict.clear()
|
selection_dict.clear()
|
||||||
|
|
||||||
func create_room():
|
func create_room():
|
||||||
|
#Creates a room from the selected tiles.
|
||||||
|
|
||||||
var room = load_room.instantiate()
|
var room: Object = load_room.instantiate()
|
||||||
|
|
||||||
room.position = (selection_dict.keys().min())
|
room.position = (selection_dict.keys().min())
|
||||||
|
|
||||||
@ -211,45 +225,78 @@ func create_room():
|
|||||||
|
|
||||||
return room
|
return room
|
||||||
|
|
||||||
#func record_walls():
|
|
||||||
|
|
||||||
|
|
||||||
func create_door():
|
func create_door():
|
||||||
|
#Creates a door to be placed.
|
||||||
|
|
||||||
for i in current_room.room_tile_dict.keys():
|
for i in current_room.room_tile_dict.keys():
|
||||||
for j in current_room.room_tile_dict[i].wall_dict.keys():
|
for j in current_room.room_tile_dict[i].wall_dict.keys():
|
||||||
current_room_walls.append((Vector3(i) + Vector3(0.5, 0, 0.5)) + Vector3(j) / 2)
|
current_room_walls.append((Vector3(i) + Vector3(0.5, 0, 0.5)) + Vector3(j) / 2)
|
||||||
|
|
||||||
current_door = true
|
var door: Object = load_door.instantiate()
|
||||||
|
|
||||||
var door = load_door.instantiate()
|
|
||||||
|
|
||||||
door.room = current_room
|
door.room = current_room
|
||||||
|
|
||||||
add_child(door)
|
add_child(door)
|
||||||
|
|
||||||
return door
|
current_door = door
|
||||||
|
|
||||||
|
func hover_door(mouse_pos):
|
||||||
|
#Hovers the door at the closest wall segment to the mouse in the current room
|
||||||
|
|
||||||
|
|
||||||
func hover_door(position):
|
|
||||||
|
|
||||||
if not current_door:
|
if not current_door:
|
||||||
current_door = create_door()
|
create_door()
|
||||||
|
|
||||||
var closest = null
|
var closest: Vector3
|
||||||
var closest_distance = INF
|
var closest_distance: float = INF
|
||||||
|
|
||||||
for i in current_room_walls:
|
for i in current_room_walls:
|
||||||
var distance = position.distance_to(i)
|
var distance: float = mouse_pos.distance_to(i)
|
||||||
if closest_distance > distance:
|
if closest_distance > distance:
|
||||||
closest_distance = distance
|
closest_distance = distance
|
||||||
closest = i
|
closest = i
|
||||||
|
|
||||||
current_door.position = closest
|
current_door.position = closest
|
||||||
current_door.rotation_degrees = Vector3(0, 180 * fmod(closest.x, 1), 0)
|
current_door.rotation_degrees = Vector3(0, 180 * fmod(closest.z, 1), 0)
|
||||||
|
|
||||||
|
func confirm_door():
|
||||||
|
#Builds the door at the hovered location
|
||||||
|
|
||||||
|
var tile_1: Object
|
||||||
|
var tile_2: Object
|
||||||
|
|
||||||
|
if fmod(current_door.position.x, 1) == 0:
|
||||||
|
tile_1 = place_tile_dict[Vector3i(current_door.position.x, 0, current_door.position.z)]
|
||||||
|
tile_2 = place_tile_dict[Vector3i(current_door.position.x - 1, 0, current_door.position.z)]
|
||||||
|
else:
|
||||||
|
tile_1 = place_tile_dict[Vector3i(current_door.position.x, 0, current_door.position.z)]
|
||||||
|
tile_2 = place_tile_dict[Vector3i(current_door.position.x, 0, current_door.position.z - 1)]
|
||||||
|
|
||||||
|
var tile_1_door_face: Vector3i = tile_2.position - tile_1.position
|
||||||
|
|
||||||
|
var tile_1_door_face_direction: int = tile_1.direction_vector_array.find(tile_1_door_face)
|
||||||
|
|
||||||
|
tile_1.update_face(tile_1_door_face_direction, Tile.FACE_MODE.DOOR, current_door)
|
||||||
|
|
||||||
|
var tile_1_room: Object = tile_1.room_id
|
||||||
|
|
||||||
|
tile_1_room.room_door_array.append(current_door)
|
||||||
|
|
||||||
|
var tile_2_door_face: Vector3i = tile_1.position - tile_2.position
|
||||||
|
|
||||||
|
var tile_2_door_face_direction: int = tile_2.direction_vector_array.find(tile_2_door_face)
|
||||||
|
|
||||||
|
tile_2.update_face(tile_2_door_face_direction, Tile.FACE_MODE.DOOR, current_door)
|
||||||
|
|
||||||
|
var tile_2_room: Object = tile_2.room_id
|
||||||
|
|
||||||
|
tile_2_room.room_door_array.append(current_door)
|
||||||
|
|
||||||
|
current_door.door_room_array = [tile_1_room, tile_2_room]
|
||||||
|
|
||||||
|
print(current_door.door_room_array)
|
||||||
|
|
||||||
func build_door():
|
|
||||||
current_room = null
|
current_room = null
|
||||||
current_room_walls = []
|
current_room_walls = []
|
||||||
current_door = null
|
current_door = null
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,10 @@ var room_tile_dict = {}
|
|||||||
|
|
||||||
var path_grid = AStar3D.new()
|
var path_grid = AStar3D.new()
|
||||||
|
|
||||||
var neighbor_array = [
|
var room_door_array = []
|
||||||
|
|
||||||
|
#TODO: replace with global dict?
|
||||||
|
var direction_array = [
|
||||||
Vector3i(0, 0, -1),
|
Vector3i(0, 0, -1),
|
||||||
Vector3i(1, 0, 0),
|
Vector3i(1, 0, 0),
|
||||||
Vector3i(0, 0, 1),
|
Vector3i(0, 0, 1),
|
||||||
@ -16,8 +19,6 @@ func _ready():
|
|||||||
|
|
||||||
init_path_grid()
|
init_path_grid()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func init_path_grid():
|
func init_path_grid():
|
||||||
@ -26,7 +27,7 @@ func init_path_grid():
|
|||||||
var id = path_grid.get_available_point_id()
|
var id = path_grid.get_available_point_id()
|
||||||
path_grid.add_point(id, i)
|
path_grid.add_point(id, i)
|
||||||
|
|
||||||
for n in neighbor_array:
|
for n in direction_array:
|
||||||
if room_tile_dict.has(i + n):
|
if room_tile_dict.has(i + n):
|
||||||
var closest = path_grid.get_closest_point(i + n)
|
var closest = path_grid.get_closest_point(i + n)
|
||||||
if (i + n) == Vector3i(path_grid.get_point_position(closest)):
|
if (i + n) == Vector3i(path_grid.get_point_position(closest)):
|
||||||
|
|||||||
@ -3,61 +3,62 @@ extends Node3D
|
|||||||
var load_place = preload("res://places/base_place/base_place.tscn")
|
var load_place = preload("res://places/base_place/base_place.tscn")
|
||||||
var place = load_place.instantiate()
|
var place = load_place.instantiate()
|
||||||
|
|
||||||
var build_enabled = false
|
enum ROOM_BUILD_STATE {NONE, ALLOWED, IS_BUILDING, IS_PLACING_DOOR}
|
||||||
var is_building = false
|
|
||||||
var is_placing_door = false
|
#Tracks the current build state.
|
||||||
|
var room_build_state = 0
|
||||||
|
|
||||||
|
|
||||||
var last_room = null
|
var last_room = null
|
||||||
|
|
||||||
var build_start_pos = null
|
#Tracks the position that was first clicked to start a build drag
|
||||||
|
var build_drag_start_pos = null
|
||||||
|
|
||||||
signal room_built
|
signal room_built
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
#TEMP loads in a workplace.
|
||||||
add_child(place)
|
add_child(place)
|
||||||
|
|
||||||
func _input(event):
|
|
||||||
pass
|
|
||||||
|
|
||||||
func _on_build_toggle(toggled_on):
|
func _on_build_toggle(toggled_on):
|
||||||
build_enabled = toggled_on
|
#Responds to the 'Build A Room' toggle
|
||||||
|
if toggled_on:
|
||||||
|
room_build_state = ROOM_BUILD_STATE.ALLOWED
|
||||||
if not toggled_on:
|
if not toggled_on:
|
||||||
place.clear_selection()
|
place.clear_selection()
|
||||||
|
room_build_state = ROOM_BUILD_STATE.NONE
|
||||||
|
|
||||||
func _on_area_3d_input_event(_camera, event, event_position, _normal, _shade_id):
|
func _on_area_3d_input_event(_camera, event, event_position, _normal, _shade_id):
|
||||||
#Checks input events from the mouse planex
|
#Checks input events from the mouse plane
|
||||||
|
|
||||||
if event.is_action_pressed("select") && build_enabled:
|
if Input.is_action_pressed("select") && room_build_state == ROOM_BUILD_STATE.ALLOWED:
|
||||||
build_start_pos = event_position
|
room_build_state = ROOM_BUILD_STATE.IS_BUILDING
|
||||||
is_building = event
|
build_drag_start_pos = event_position
|
||||||
place.draw_tile_click(build_start_pos)
|
place.draw_tile_click(build_drag_start_pos)
|
||||||
|
|
||||||
elif is_building:
|
elif room_build_state == ROOM_BUILD_STATE.IS_BUILDING:
|
||||||
if Input.is_action_pressed("select"):
|
if Input.is_action_pressed("select"):
|
||||||
place.init_select_drag(build_start_pos, event_position)
|
place.init_select_drag(build_drag_start_pos, event_position)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
is_building = event
|
room_build_state = ROOM_BUILD_STATE.ALLOWED
|
||||||
place.end_select_drag()
|
place.end_select_drag()
|
||||||
|
|
||||||
elif is_placing_door:
|
elif room_build_state == ROOM_BUILD_STATE.IS_PLACING_DOOR:
|
||||||
if not event.button_mask:
|
if not Input.is_action_pressed("select"):
|
||||||
place.hover_door(event_position)
|
place.hover_door(event_position)
|
||||||
|
|
||||||
if event.is_action_pressed("select"):
|
if Input.is_action_pressed("select"):
|
||||||
is_placing_door = false
|
room_build_state = ROOM_BUILD_STATE.NONE
|
||||||
place.build_door()
|
place.confirm_door()
|
||||||
emit_signal("room_built")
|
emit_signal("room_built")
|
||||||
|
|
||||||
|
|
||||||
func _on_confirm_button_pressed() -> void:
|
func _on_confirm_button_pressed() -> void:
|
||||||
if is_building:
|
if place.selection_dict:
|
||||||
if place.build_allowed:
|
if room_build_state == ROOM_BUILD_STATE.ALLOWED:
|
||||||
last_room = place.build_selection()
|
if place.build_confirm_allowed:
|
||||||
build_enabled = false
|
last_room = place.build_selection()
|
||||||
is_building = false
|
room_build_state = ROOM_BUILD_STATE.IS_PLACING_DOOR
|
||||||
is_placing_door = true
|
|
||||||
|
|
||||||
#
|
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://0d1d5e1u2fys"]
|
[gd_scene load_steps=3 format=3 uid="uid://0d1d5e1u2fys"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://d24sr2dat4lj0" path="res://places/place_manager.gd" id="1_rcbs8"]
|
[ext_resource type="Script" uid="uid://d24sr2dat4lj0" path="res://places/place_manager.gd" id="1_rcbs8"]
|
||||||
|
|
||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_rcbs8"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_rcbs8"]
|
||||||
size = Vector3(256, 0, 256)
|
size = Vector3(256, 0, 256)
|
||||||
|
|
||||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_vil6d"]
|
|
||||||
|
|
||||||
[node name="PlaceManager" type="Node3D"]
|
[node name="PlaceManager" type="Node3D"]
|
||||||
script = ExtResource("1_rcbs8")
|
script = ExtResource("1_rcbs8")
|
||||||
|
|
||||||
@ -16,7 +14,4 @@ script = ExtResource("1_rcbs8")
|
|||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 128, 0, 128)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 128, 0, 128)
|
||||||
shape = SubResource("BoxShape3D_rcbs8")
|
shape = SubResource("BoxShape3D_rcbs8")
|
||||||
|
|
||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="FloorPlane"]
|
|
||||||
mesh = SubResource("CapsuleMesh_vil6d")
|
|
||||||
|
|
||||||
[connection signal="input_event" from="FloorPlane" to="." method="_on_area_3d_input_event"]
|
[connection signal="input_event" from="FloorPlane" to="." method="_on_area_3d_input_event"]
|
||||||
|
|||||||
@ -20,6 +20,7 @@ config/icon="res://icon.svg"
|
|||||||
select={
|
select={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.2,
|
||||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
main_cam_up={
|
main_cam_up={
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
extends Node3D
|
extends Node3D
|
||||||
|
|
||||||
var room = null
|
var room = null
|
||||||
|
|
||||||
|
var door_room_array = []
|
||||||
|
|||||||
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
[ext_resource type="Script" uid="uid://dptw3xl225fxk" path="res://tiles/base_tile/base_door.gd" id="1_8olbq"]
|
[ext_resource type="Script" uid="uid://dptw3xl225fxk" path="res://tiles/base_tile/base_door.gd" id="1_8olbq"]
|
||||||
|
|
||||||
[sub_resource type="PrismMesh" id="PrismMesh_2crd3"]
|
[sub_resource type="BoxMesh" id="BoxMesh_8olbq"]
|
||||||
|
|
||||||
[node name="BaseDoor" type="Node3D"]
|
[node name="BaseDoor" type="Node3D"]
|
||||||
script = ExtResource("1_8olbq")
|
script = ExtResource("1_8olbq")
|
||||||
|
|
||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
transform = Transform3D(-3.93403e-08, 0, 0.2, 0, 0.5, 0, -0.9, 0, -8.74228e-09, 0, 0.25, 0)
|
||||||
mesh = SubResource("PrismMesh_2crd3")
|
mesh = SubResource("BoxMesh_8olbq")
|
||||||
|
|||||||
@ -1,34 +1,10 @@
|
|||||||
extends Node3D
|
extends Node3D
|
||||||
|
class_name Tile
|
||||||
|
|
||||||
var id = null
|
var id = null
|
||||||
|
|
||||||
var _debug_sel_mode = {
|
#This tile's current construction and selection modes.
|
||||||
1: "not selected",
|
|
||||||
2: "room select",
|
|
||||||
3: "build select",
|
|
||||||
4: "invalid select"
|
|
||||||
}
|
|
||||||
|
|
||||||
var _debug_con_mode = {
|
|
||||||
1: "non interactalble",
|
|
||||||
2: "closed",
|
|
||||||
3: "open",
|
|
||||||
4: "built",
|
|
||||||
5: "reinforced",
|
|
||||||
6: "under construction"
|
|
||||||
}
|
|
||||||
|
|
||||||
var _debug_face_mode = {
|
|
||||||
1: "none",
|
|
||||||
2: "full",
|
|
||||||
3: "partial",
|
|
||||||
4: "door"
|
|
||||||
}
|
|
||||||
|
|
||||||
# list of objects contained within
|
|
||||||
|
|
||||||
var construction_mode = 0
|
var construction_mode = 0
|
||||||
|
|
||||||
var selection_mode = 0
|
var selection_mode = 0
|
||||||
|
|
||||||
var orange = preload("res://tiles/base_tile/orange.tres")
|
var orange = preload("res://tiles/base_tile/orange.tres")
|
||||||
@ -37,25 +13,34 @@ var red = preload("res://tiles/base_tile/red.tres")
|
|||||||
var blue = preload("res://tiles/base_tile/blue.tres")
|
var blue = preload("res://tiles/base_tile/blue.tres")
|
||||||
var lightblue = preload("res://tiles/base_tile/lightblue.tres")
|
var lightblue = preload("res://tiles/base_tile/lightblue.tres")
|
||||||
|
|
||||||
var face_dict = {
|
#Lists of possible states for various modes.
|
||||||
"floor": null,
|
enum SEL_MODE {NONE, ROOM, BUILD, INVALID}
|
||||||
"north": null,
|
|
||||||
"east": null,
|
|
||||||
"south": null,
|
|
||||||
"west": null
|
|
||||||
}
|
|
||||||
|
|
||||||
var neighbor_array = [
|
enum CON_MODE {NONE, NON_INTERACTABLE, CLOSED, OPEN, BUILT, REINFORCED, CONSTRUCTION}
|
||||||
|
|
||||||
|
enum DIRECTION {NORTH, EAST, SOUTH, WEST}
|
||||||
|
|
||||||
|
enum FACE_MODE {NONE, FULL, PARTIAL, DOOR}
|
||||||
|
|
||||||
|
var direction_vector_array = [
|
||||||
|
# North
|
||||||
Vector3i(0, 0, -1),
|
Vector3i(0, 0, -1),
|
||||||
|
# East
|
||||||
Vector3i(1, 0, 0),
|
Vector3i(1, 0, 0),
|
||||||
|
# South
|
||||||
Vector3i(0, 0, 1),
|
Vector3i(0, 0, 1),
|
||||||
|
# West
|
||||||
Vector3i(-1, 0, 0),
|
Vector3i(-1, 0, 0),
|
||||||
]
|
]
|
||||||
|
|
||||||
var wall_array = [
|
var wall_position_array = [
|
||||||
|
# North
|
||||||
Vector3i(0, 0, 0),
|
Vector3i(0, 0, 0),
|
||||||
|
# East
|
||||||
Vector3i(1, 0, 0),
|
Vector3i(1, 0, 0),
|
||||||
|
# South
|
||||||
Vector3i(1, 0, 1),
|
Vector3i(1, 0, 1),
|
||||||
|
# West
|
||||||
Vector3i(0, 0, 1),
|
Vector3i(0, 0, 1),
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -76,23 +61,23 @@ func _ready():
|
|||||||
func invalid_this_tile():
|
func invalid_this_tile():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func update_face(neighbor_index, mode):
|
func update_face(direction, mode, door = null):
|
||||||
|
#Updates the faces of this tile.
|
||||||
|
var face = direction_vector_array[direction]
|
||||||
|
|
||||||
var face = neighbor_array[neighbor_index]
|
if mode == FACE_MODE.NONE:
|
||||||
|
|
||||||
if mode == 1:
|
|
||||||
for i in wall_dict.keys():
|
for i in wall_dict.keys():
|
||||||
wall_dict[i].queue_free()
|
wall_dict[i].queue_free()
|
||||||
wall_dict.erase(i)
|
wall_dict.erase(i)
|
||||||
|
|
||||||
if mode == 2:
|
if mode == FACE_MODE.FULL:
|
||||||
if not wall_dict.has(face):
|
if not wall_dict.has(face):
|
||||||
|
|
||||||
var wall = load_wall.instantiate()
|
var wall = load_wall.instantiate()
|
||||||
|
|
||||||
wall.position = wall_array[neighbor_index]
|
wall.position = wall_position_array[direction]
|
||||||
|
|
||||||
wall.rotation_degrees = Vector3(0, neighbor_index * -90, 0)
|
wall.rotation_degrees = Vector3(0, direction * -90, 0)
|
||||||
|
|
||||||
wall_dict[face] = wall
|
wall_dict[face] = wall
|
||||||
|
|
||||||
@ -100,66 +85,58 @@ func update_face(neighbor_index, mode):
|
|||||||
|
|
||||||
add_child(wall)
|
add_child(wall)
|
||||||
|
|
||||||
|
if mode == FACE_MODE.DOOR:
|
||||||
|
wall_dict[face].queue_free()
|
||||||
|
wall_dict.erase(face)
|
||||||
|
wall_dict[face] = door
|
||||||
|
|
||||||
func update(sel_mode: int = 0, con_mode: int = 0):
|
|
||||||
|
|
||||||
if sel_mode:
|
func update(sel_mode: int = SEL_MODE.NONE, con_mode: int = CON_MODE.NONE):
|
||||||
if sel_mode != selection_mode:
|
#Updates the selection and construction modes of this tile.
|
||||||
|
|
||||||
selection_mode = sel_mode
|
if sel_mode != selection_mode:
|
||||||
|
|
||||||
if sel_mode == 1:
|
selection_mode = sel_mode
|
||||||
# not selected
|
|
||||||
$Floor/FloorMesh.set_material_overlay(null)
|
|
||||||
|
|
||||||
elif sel_mode == 2:
|
if sel_mode == SEL_MODE.NONE:
|
||||||
# room selection
|
$Floor/FloorMesh.set_material_overlay(null)
|
||||||
for i in $Walls.get_children():
|
|
||||||
i.Mesh.set_material_override(orange)
|
|
||||||
|
|
||||||
elif sel_mode == 3:
|
elif sel_mode == SEL_MODE.ROOM:
|
||||||
# build selection
|
for i in $Walls.get_children():
|
||||||
$Floor/FloorMesh.set_material_overlay(lightblue)
|
i.Mesh.set_material_override(orange)
|
||||||
#for i in $Walls.get_children():
|
|
||||||
#i.Mesh.set_material_override(blue)
|
|
||||||
|
|
||||||
elif sel_mode == 4:
|
elif sel_mode == SEL_MODE.BUILD:
|
||||||
# invalid selection
|
$Floor/FloorMesh.set_material_overlay(lightblue)
|
||||||
$Floor/FloorMesh.set_material_overlay(orange)
|
|
||||||
#for i in $Walls.get_children():
|
elif sel_mode == SEL_MODE.INVALID:
|
||||||
#i.set_material_override(red)
|
$Floor/FloorMesh.set_material_overlay(orange)
|
||||||
else:
|
|
||||||
pass
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
if con_mode:
|
if con_mode:
|
||||||
if con_mode != construction_mode:
|
if con_mode != construction_mode:
|
||||||
|
|
||||||
construction_mode = con_mode
|
construction_mode = con_mode
|
||||||
|
|
||||||
if con_mode == 1:
|
if con_mode == CON_MODE.NON_INTERACTABLE:
|
||||||
# non-interactable
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif con_mode == 2:
|
elif con_mode == CON_MODE.CLOSED:
|
||||||
# closed
|
|
||||||
$Floor/FloorMesh.set_material_override(gray)
|
$Floor/FloorMesh.set_material_override(gray)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif con_mode == 3:
|
elif con_mode == CON_MODE.OPEN:
|
||||||
# open
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif con_mode == 4:
|
elif con_mode == CON_MODE.BUILT:
|
||||||
# built
|
|
||||||
$Floor/FloorMesh.set_material_override(null)
|
$Floor/FloorMesh.set_material_override(null)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif con_mode == 5:
|
elif con_mode == CON_MODE.REINFORCED:
|
||||||
# reinforced
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif con_mode == 6:
|
elif con_mode == CON_MODE.CONSTRUCTION:
|
||||||
# under construction
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -2,7 +2,23 @@
|
|||||||
|
|
||||||
[ext_resource type="Script" uid="uid://jqjcr7dxjnbt" path="res://tiles/base_tile/base_tile.gd" id="1_yoisu"]
|
[ext_resource type="Script" uid="uid://jqjcr7dxjnbt" path="res://tiles/base_tile/base_tile.gd" id="1_yoisu"]
|
||||||
[ext_resource type="PlaneMesh" uid="uid://bis4hdushjnjm" path="res://tiles/base_tile/base_floor.tres" id="2_wxg2y"]
|
[ext_resource type="PlaneMesh" uid="uid://bis4hdushjnjm" path="res://tiles/base_tile/base_floor.tres" id="2_wxg2y"]
|
||||||
[ext_resource type="Script" uid="uid://df68d87131dv7" path="res://tiles/base_tile/base_wall.gd" id="3_enx1c"]
|
|
||||||
|
[sub_resource type="GDScript" id="GDScript_3aog3"]
|
||||||
|
script/source = "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)
|
||||||
|
"
|
||||||
|
|
||||||
[node name="Tile" type="Node3D"]
|
[node name="Tile" type="Node3D"]
|
||||||
script = ExtResource("1_yoisu")
|
script = ExtResource("1_yoisu")
|
||||||
@ -15,7 +31,7 @@ mesh = ExtResource("2_wxg2y")
|
|||||||
skeleton = NodePath("../..")
|
skeleton = NodePath("../..")
|
||||||
|
|
||||||
[node name="Walls" type="Node3D" parent="."]
|
[node name="Walls" type="Node3D" parent="."]
|
||||||
script = ExtResource("3_enx1c")
|
script = SubResource("GDScript_3aog3")
|
||||||
|
|
||||||
[node name="Label3D" type="Label3D" parent="."]
|
[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)
|
transform = Transform3D(1, 0, 0, 0, 0.0668138, 0.997765, 0, -0.997765, 0.0668138, 0.341829, 0.0223614, 0.130147)
|
||||||
|
|||||||
@ -1,14 +0,0 @@
|
|||||||
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 +0,0 @@
|
|||||||
uid://df68d87131dv7
|
|
||||||
Loading…
Reference in New Issue
Block a user