project-villain/tiles/base_tile/base_tile.gd

236 lines
5.0 KiB
GDScript

extends Node3D
class_name Tile
var id = null
#This tile's current construction and selection modes.
@export var construction_mode = 0: set = update_construction
@export var selection_mode = 0: set = update_selection
var orange = preload("res://tiles/base_tile/orange.tres")
var gray = preload("res://tiles/base_tile/gray.tres")
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")
#Lists of possible states for various modes.
enum SEL_MODE {NONE, ROOM, BUILD, INVALID}
enum CON_MODE {NONE, NON_INTERACTABLE, CLOSED, OPEN, BUILT, REINFORCED, CONSTRUCTION}
enum FACE_MODE {NONE, FULL, PARTIAL, DOOR}
var direction_vector_dict = {
"North": Vector3i(0, 0, -1),
"East": Vector3i(1, 0, 0),
"South": Vector3i(0, 0, 1),
"West": Vector3i(-1, 0, 0),
}
var wall_position_dict = {
"North": Vector3i(0, 0, 0),
"East": Vector3i(1, 0, 0),
"South": Vector3i(1, 0, 1),
"West": Vector3i(0, 0, 1),
}
var load_wall = preload("res://tiles/base_tile/base_wall.tscn")
@export var grid_pos = null
@export var face_dict = {}: set = update_faces
@export var room = null
var neighbor_dict = []
signal wall_built
signal neighbor_request
func _ready():
pass
func save():
var save_data = {
"test": "test",
"position": position,
"scene_file_path": scene_file_path,
"parent": get_parent().get_path(),
"grid_pos": grid_pos,
"face_dict": face_dict,
"room": room
}
return save_data
func update_faces(new_dict):
face_dict = new_dict
for i in $Walls.get_children():
i.queue_free()
for i in new_dict.keys():
var direction: String = direction_vector_dict.find_key(i)
var wall_pos = wall_position_dict[direction]
var wall = load_wall.instantiate()
wall.position = wall_position_dict[direction]
wall.name = str(direction, "Wall")
match direction:
"East":
wall.rotation_degrees = Vector3(0, -90, 0)
"South":
wall.rotation_degrees = Vector3(0, -180, 0)
"West":
wall.rotation_degrees = Vector3(0, -270, 0)
$Walls.add_child(wall)
func update_neighbors():
neighbor_dict = {}
emit_signal("neighbor_request", self, grid_pos, direction_vector_dict)
pass
func update_construction(mode):
construction_mode = mode
match mode:
CON_MODE.NON_INTERACTABLE:
face_dict = {}
pass
CON_MODE.CLOSED:
face_dict = {}
$Floor/FloorMesh.set_material_override(gray)
pass
CON_MODE.OPEN:
face_dict = {}
pass
CON_MODE.BUILT:
$Floor/FloorMesh.set_material_override(null)
update_neighbors()
var temp_face_dict = {}
for i in neighbor_dict.keys():
if not neighbor_dict[i].room == room:
#print(neighbor_dict[i].room)
temp_face_dict[i] = null
face_dict = temp_face_dict.duplicate()
print(face_dict)
CON_MODE.REINFORCED:
face_dict = {}
pass
CON_MODE.CONSTRUCTION:
pass
pass
func update_selection(mode):
match mode:
SEL_MODE.NONE:
$Floor/FloorMesh.set_material_overlay(null)
SEL_MODE.ROOM:
for i in $Walls.get_children():
i.Mesh.set_material_override(orange)
SEL_MODE.BUILD:
$Floor/FloorMesh.set_material_overlay(lightblue)
SEL_MODE.INVALID:
$Floor/FloorMesh.set_material_overlay(orange)
func update_face(direction, mode, door = null):
print("face update blanked")
pass
##Updates the faces of this tile.
#var face = direction_vector_array[direction]
#
#
#
#match mode:
#FACE_MODE.NONE:
#for i in wall_dict.keys():
#wall_dict[i].queue_free()
#wall_dict.erase(i)
#
#FACE_MODE.FULL:
#if not wall_dict.has(face):
#
#var wall = load_wall.instantiate()
#
#wall.position = wall_position_array[direction]
#
#wall.rotation_degrees = Vector3(0, direction * -90, 0)
#
#wall_dict[face] = wall
#
#emit_signal("wall_built", room_id)
#
#add_child(wall)
#
#FACE_MODE.DOOR:
#wall_dict[face].queue_free()
#wall_dict.erase(face)
#wall_dict[face] = door
#
#
func update(sel_mode: int = SEL_MODE.NONE, con_mode: int = CON_MODE.NONE):
print("update blanked")
pass
##Updates the selection and construction modes of this tile.
#
#if sel_mode != selection_mode:
#
#selection_mode = sel_mode
#
#match sel_mode:
#SEL_MODE.NONE:
#$Floor/FloorMesh.set_material_overlay(null)
#
#SEL_MODE.ROOM:
#for i in $Walls.get_children():
#i.Mesh.set_material_override(orange)
#
#SEL_MODE.BUILD:
#$Floor/FloorMesh.set_material_overlay(lightblue)
#
#SEL_MODE.INVALID:
#$Floor/FloorMesh.set_material_overlay(orange)
#
##if con_mode:
##if con_mode != construction_mode:
##
##construction_mode = con_mode
##
##match con_mode:
##CON_MODE.NON_INTERACTABLE:
##pass
##
##CON_MODE.CLOSED:
##$Floor/FloorMesh.set_material_override(gray)
##pass
##
##CON_MODE.OPEN:
##pass
##
##CON_MODE.BUILT:
##$Floor/FloorMesh.set_material_override(null)
##pass
##
##CON_MODE.REINFORCED:
##pass
##
##CON_MODE.CONSTRUCTION:
##pass