Preliminary saving and loading
This commit is contained in:
parent
2f5f465799
commit
1bb038d8b7
23
game.tscn
23
game.tscn
@ -1,9 +1,10 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://x8xo5b1b3q41"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://x8xo5b1b3q41"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b2ytri51qn3r0" path="res://game.gd" id="1_feb5d"]
|
||||
[ext_resource type="Script" uid="uid://bi7t6jxlfl0ln" path="res://interface/build_toggle.gd" id="2_7jktm"]
|
||||
[ext_resource type="PackedScene" uid="uid://0d1d5e1u2fys" path="res://places/place_manager.tscn" id="2_fc0e3"]
|
||||
[ext_resource type="Script" uid="uid://cgfibq8ku7tey" path="res://interface/game_cam.gd" id="3_7jktm"]
|
||||
[ext_resource type="Script" uid="uid://bdf7ll8y2htic" path="res://interface/save_load.gd" id="5_7jktm"]
|
||||
|
||||
[node name="Game" type="Node"]
|
||||
script = ExtResource("1_feb5d")
|
||||
@ -25,6 +26,21 @@ offset_right = 243.0
|
||||
offset_bottom = 635.0
|
||||
text = "Confirm"
|
||||
|
||||
[node name="SaveButton" type="Button" parent="InterfaceLayer"]
|
||||
offset_left = 995.0
|
||||
offset_top = 609.0
|
||||
offset_right = 1141.0
|
||||
offset_bottom = 640.0
|
||||
text = "Save Current Map
|
||||
"
|
||||
|
||||
[node name="LoadButton" type="Button" parent="InterfaceLayer"]
|
||||
offset_left = 996.0
|
||||
offset_top = 573.0
|
||||
offset_right = 1142.0
|
||||
offset_bottom = 604.0
|
||||
text = "Load Map"
|
||||
|
||||
[node name="GameCam" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.182236, 0.983255, 0, -0.983255, 0.182236, 24.5127, 23.2849, 20.9667)
|
||||
size = 31.34
|
||||
@ -32,6 +48,11 @@ script = ExtResource("3_7jktm")
|
||||
|
||||
[node name="PlaceManager" parent="." instance=ExtResource("2_fc0e3")]
|
||||
|
||||
[node name="SaveLoad" type="Node" parent="."]
|
||||
script = ExtResource("5_7jktm")
|
||||
|
||||
[connection signal="toggled" from="InterfaceLayer/BuildToggle" to="PlaceManager" method="_on_build_toggle"]
|
||||
[connection signal="pressed" from="InterfaceLayer/BuildButton" to="PlaceManager" method="_on_confirm_button_pressed"]
|
||||
[connection signal="pressed" from="InterfaceLayer/SaveButton" to="SaveLoad" method="_on_save_button_pressed"]
|
||||
[connection signal="pressed" from="InterfaceLayer/LoadButton" to="SaveLoad" method="_on_load_button_pressed"]
|
||||
[connection signal="room_built" from="PlaceManager" to="InterfaceLayer/BuildToggle" method="_on_room_built"]
|
||||
|
||||
38
interface/save_load.gd
Normal file
38
interface/save_load.gd
Normal file
@ -0,0 +1,38 @@
|
||||
extends Node
|
||||
|
||||
func _on_save_button_pressed() -> void:
|
||||
var save_nodes = get_tree().get_nodes_in_group("SaveObjects")
|
||||
var save_file = FileAccess.open("user://savegame.save", FileAccess.WRITE)
|
||||
for node in save_nodes:
|
||||
|
||||
if not node.has_method("save"):
|
||||
print("no method")
|
||||
continue
|
||||
|
||||
var node_data = node.save()
|
||||
|
||||
save_file.store_var(node_data)
|
||||
|
||||
pass # Replace with function body.
|
||||
|
||||
func _on_load_button_pressed():
|
||||
|
||||
if not FileAccess.file_exists("user://savegame.save"):
|
||||
print("no save to load")
|
||||
return
|
||||
|
||||
#var save_nodes = get_tree().get_nodes_in_group("SaveObjects")
|
||||
#for i in save_nodes:
|
||||
#print(i)
|
||||
#i.free()
|
||||
|
||||
get_node("/root/Game/PlaceManager/BasePlace").free()
|
||||
|
||||
var save_file = FileAccess.open("user://savegame.save", FileAccess.READ)
|
||||
|
||||
while save_file.get_position() < save_file.get_length():
|
||||
var next_load = save_file.get_var()
|
||||
var load_object = load(next_load["scene_file_path"]).instantiate()
|
||||
for i in next_load.keys():
|
||||
load_object.set(i, next_load[i])
|
||||
get_node(next_load["parent"]).add_child(load_object)
|
||||
1
interface/save_load.gd.uid
Normal file
1
interface/save_load.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://bdf7ll8y2htic
|
||||
@ -1,6 +1,6 @@
|
||||
extends Node3D
|
||||
|
||||
var tile_grid_size: int = 32
|
||||
var tile_grid_size: int = 8
|
||||
|
||||
var load_tile = preload("res://tiles/base_tile/base_tile.tscn")
|
||||
var load_room = preload("res://places/base_place/base_room.tscn")
|
||||
@ -30,7 +30,7 @@ var current_room_walls: Array = []
|
||||
var current_door: Object = null
|
||||
|
||||
func _ready():
|
||||
|
||||
self.name = "BasePlace"
|
||||
#TEMP: Sets up a simple 2D grid of blank tiles.
|
||||
|
||||
for x in range(tile_grid_size):
|
||||
@ -41,30 +41,51 @@ func _ready():
|
||||
tile.set_position(pos)
|
||||
|
||||
tile.grid_pos = pos
|
||||
tile.name = str("Tile", tile.get_instance_id())
|
||||
|
||||
tile.update(Tile.SEL_MODE.NONE, Tile.CON_MODE.CLOSED)
|
||||
tile.selection_mode = Tile.SEL_MODE.NONE
|
||||
tile.construction_mode = Tile.CON_MODE.CLOSED
|
||||
|
||||
place_tile_dict[pos] = tile
|
||||
|
||||
add_child(tile)
|
||||
|
||||
var pos: Vector3i = Vector3i(1, 0, 1)
|
||||
tile.connect("neighbor_request", give_neighbors)
|
||||
|
||||
var tile: Object = place_tile_dict[pos]
|
||||
var pos = Vector3i(1, 0, 1)
|
||||
|
||||
selection_drag_dict[pos] = tile
|
||||
end_select_drag()
|
||||
build_selection()
|
||||
var tile = place_tile_dict[pos]
|
||||
|
||||
var trickydict = {pos: tile}
|
||||
|
||||
tile.room = create_room(trickydict)
|
||||
|
||||
tile.construction_mode = Tile.CON_MODE.BUILT
|
||||
|
||||
|
||||
#selection_drag_dict[pos] = tile
|
||||
#end_select_drag()
|
||||
#build_selection()
|
||||
|
||||
func save():
|
||||
var save_data = {
|
||||
"test": "test",
|
||||
"scene_file_path": scene_file_path,
|
||||
"parent": get_parent().get_path(),
|
||||
"place_tile_dict": place_tile_dict,
|
||||
"room_dict": room_dict
|
||||
}
|
||||
|
||||
return save_data
|
||||
|
||||
func draw_tile_click(click_pos):
|
||||
#starts a selection drag
|
||||
|
||||
var build_start_pos: Vector3i = click_pos.floor()
|
||||
#tile_count_x_hist = 0
|
||||
#tile_count_z_hist = 0
|
||||
|
||||
if place_tile_dict.has(build_start_pos):
|
||||
select_tile(build_start_pos)
|
||||
if not place_tile_dict[build_start_pos].construction_mode == Tile.CON_MODE.BUILT:
|
||||
select_tile(build_start_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
|
||||
@ -98,7 +119,7 @@ func draw_select_drag(array):
|
||||
for i in place_tile_dict:
|
||||
if not selection_dict.has(i):
|
||||
var tile: Object = place_tile_dict[i]
|
||||
tile.update(Tile.SEL_MODE.NONE, )
|
||||
tile.selection_mode = Tile.SEL_MODE.NONE
|
||||
|
||||
selection_drag_dict.clear()
|
||||
|
||||
@ -113,9 +134,9 @@ func select_tile(pos):
|
||||
selection_drag_dict[pos] = tile
|
||||
|
||||
if build_confirm_allowed:
|
||||
tile.update(Tile.SEL_MODE.BUILD, )
|
||||
tile.selection_mode = Tile.SEL_MODE.BUILD
|
||||
else:
|
||||
tile.update(Tile.SEL_MODE.INVALID, )
|
||||
tile.selection_mode = Tile.SEL_MODE.INVALID
|
||||
|
||||
func verify_room():
|
||||
#Verifies that a given selection is fully contiguous
|
||||
@ -131,7 +152,7 @@ func verify_room():
|
||||
|
||||
var verify_pos: Vector3i = verify_queue_array.pop_back()
|
||||
|
||||
var verify_neighbor_array: Array = place_tile_dict[verify_pos].direction_vector_array
|
||||
var verify_neighbor_array: Array = place_tile_dict[verify_pos].direction_vector_dict.values()
|
||||
|
||||
for n in verify_neighbor_array:
|
||||
|
||||
@ -153,73 +174,74 @@ func end_select_drag():
|
||||
|
||||
selection_dict.merge(selection_drag_dict)
|
||||
|
||||
for i in selection_dict.keys():
|
||||
var tile:Object = selection_dict[i]
|
||||
for j in range(4):
|
||||
tile.update_face(j, Tile.FACE_MODE.NONE)
|
||||
for j in range(4):
|
||||
if not selection_dict.has(i + tile.direction_vector_array[j]):
|
||||
tile.update_face(j, Tile.FACE_MODE.FULL)
|
||||
#for i in selection_dict.keys():
|
||||
#var tile:Object = selection_dict[i]
|
||||
#for j in range(4):
|
||||
#tile.update_face(j, Tile.FACE_MODE.NONE)
|
||||
#for j in range(4):
|
||||
#if not selection_dict.has(i + tile.direction_vector_array[j]):
|
||||
#tile.update_face(j, Tile.FACE_MODE.FULL)
|
||||
|
||||
if verify_room():
|
||||
build_confirm_allowed = true
|
||||
for i in selection_dict:
|
||||
place_tile_dict[i].update(Tile.SEL_MODE.BUILD, )
|
||||
place_tile_dict[i].selection_mode = Tile.SEL_MODE.BUILD
|
||||
else:
|
||||
build_confirm_allowed = false
|
||||
for i in selection_dict:
|
||||
place_tile_dict[i].update(Tile.SEL_MODE.INVALID, )
|
||||
place_tile_dict[i].selection_mode = Tile.SEL_MODE.INVALID
|
||||
|
||||
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
|
||||
#When the build button is clicked, changes the selected tiles to match the button's request
|
||||
|
||||
if not build_confirm_allowed:
|
||||
return
|
||||
|
||||
if selection_dict:
|
||||
|
||||
var room: Object = create_room(selection_dict)
|
||||
|
||||
for i in selection_dict:
|
||||
var tile: Object = place_tile_dict[i]
|
||||
tile.update(Tile.SEL_MODE.NONE, Tile.CON_MODE.BUILT)
|
||||
|
||||
var room: Object = create_room()
|
||||
tile.selection_mode = Tile.SEL_MODE.NONE
|
||||
tile.construction_mode = Tile.CON_MODE.BUILT
|
||||
|
||||
selection_dict.clear()
|
||||
|
||||
return room
|
||||
#return room
|
||||
|
||||
func clear_selection():
|
||||
#When the clear button is clicked, it clears the selected tiles without doing anything.
|
||||
|
||||
for i in selection_dict:
|
||||
var tile: Object = selection_dict[i]
|
||||
tile.update(Tile.SEL_MODE.NONE, )
|
||||
tile.selection_mode = Tile.SEL_MODE.NONE
|
||||
build_confirm_allowed = true
|
||||
|
||||
for i in selection_dict.keys():
|
||||
var tile: Object = selection_dict[i]
|
||||
for j in Tile.DIRECTION:
|
||||
tile.update_face(j, Tile.FACE_MODE.NONE)
|
||||
#for i in selection_dict.keys():
|
||||
#var tile: Object = selection_dict[i]
|
||||
#for j in range(4):
|
||||
#tile.update_face(j, Tile.FACE_MODE.NONE)
|
||||
|
||||
selection_dict.clear()
|
||||
|
||||
func create_room():
|
||||
func create_room(selection):
|
||||
#Creates a room from the selected tiles.
|
||||
|
||||
var room: Object = load_room.instantiate()
|
||||
|
||||
room.position = (selection_dict.keys().min())
|
||||
room.position = (selection.keys().min())
|
||||
|
||||
room.room_tile_dict = selection_dict.duplicate()
|
||||
room.room_tile_dict = selection.duplicate()
|
||||
|
||||
room.name = str("Room", room.get_instance_id())
|
||||
|
||||
add_child(room)
|
||||
|
||||
for i in room.room_tile_dict:
|
||||
place_tile_dict[i].room_id = room
|
||||
place_tile_dict[i].room = room
|
||||
|
||||
current_room = room
|
||||
|
||||
@ -243,8 +265,6 @@ func create_door():
|
||||
func hover_door(mouse_pos):
|
||||
#Hovers the door at the closest wall segment to the mouse in the current room
|
||||
|
||||
|
||||
|
||||
if not current_door:
|
||||
create_door()
|
||||
|
||||
@ -295,8 +315,13 @@ func confirm_door():
|
||||
|
||||
current_door.door_room_array = [tile_1_room, tile_2_room]
|
||||
|
||||
print(current_door.door_room_array)
|
||||
|
||||
current_room = null
|
||||
current_room_walls = []
|
||||
current_door = null
|
||||
|
||||
func give_neighbors(tile, grid_pos, directions):
|
||||
var neighbor_dict = {}
|
||||
for i in directions.keys():
|
||||
if place_tile_dict.has(directions[i] + grid_pos):
|
||||
neighbor_dict[directions[i]] = place_tile_dict[directions[i] + grid_pos]
|
||||
tile.neighbor_dict = neighbor_dict
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
[ext_resource type="Script" uid="uid://n4vvqmlmq5fp" path="res://places/base_place/base_place.gd" id="1_uq3a8"]
|
||||
|
||||
[node name="BasePlace" type="Node3D"]
|
||||
[node name="BasePlace" type="Node3D" groups=["SaveObjects"]]
|
||||
script = ExtResource("1_uq3a8")
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
|
||||
@ -8,11 +8,11 @@ var room_door_array = []
|
||||
|
||||
#TODO: replace with global dict?
|
||||
var direction_array = [
|
||||
Vector3i(0, 0, -1),
|
||||
Vector3i(1, 0, 0),
|
||||
Vector3i(0, 0, 1),
|
||||
Vector3i(-1, 0, 0),
|
||||
]
|
||||
Vector3i(0, 0, -1),
|
||||
Vector3i(1, 0, 0),
|
||||
Vector3i(0, 0, 1),
|
||||
Vector3i(-1, 0, 0),
|
||||
]
|
||||
|
||||
func _ready():
|
||||
self.name = str("Room", self.get_instance_id())
|
||||
@ -21,6 +21,17 @@ func _ready():
|
||||
|
||||
pass
|
||||
|
||||
func save():
|
||||
var save_data = {
|
||||
"test": "test",
|
||||
"scene_file_path": scene_file_path,
|
||||
"parent": get_parent().get_path(),
|
||||
"room_tile_dict": room_tile_dict,
|
||||
"room_door_array": room_door_array,
|
||||
"path_grid": path_grid
|
||||
}
|
||||
return save_data
|
||||
|
||||
func init_path_grid():
|
||||
|
||||
for i in room_tile_dict.keys():
|
||||
|
||||
@ -1,12 +1,6 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://f0b4ptwari8y"]
|
||||
[gd_scene load_steps=2 format=3 uid="uid://f0b4ptwari8y"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c2neixe7kpvma" path="res://places/base_place/base_room.gd" id="1_3l4mp"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_3l4mp"]
|
||||
|
||||
[node name="BaseRoom" type="Node3D"]
|
||||
script = ExtResource("1_3l4mp")
|
||||
|
||||
[node name="ConnectMesh" type="MeshInstance3D" parent="."]
|
||||
visible = false
|
||||
mesh = SubResource("SphereMesh_3l4mp")
|
||||
|
||||
@ -3,7 +3,7 @@ extends Node3D
|
||||
var load_place = preload("res://places/base_place/base_place.tscn")
|
||||
var place = load_place.instantiate()
|
||||
|
||||
enum ROOM_BUILD_STATE {NONE, ALLOWED, IS_BUILDING, IS_PLACING_DOOR}
|
||||
enum ROOM_BUILD_STATE {NONE, ALLOWED, BUILDING, IS_PLACING_DOOR}
|
||||
|
||||
#Tracks the current build state.
|
||||
var room_build_state = 0
|
||||
@ -24,33 +24,34 @@ func _on_build_toggle(toggled_on):
|
||||
#Responds to the 'Build A Room' toggle
|
||||
if toggled_on:
|
||||
room_build_state = ROOM_BUILD_STATE.ALLOWED
|
||||
if not toggled_on:
|
||||
else:
|
||||
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 plane
|
||||
|
||||
if Input.is_action_pressed("select") && room_build_state == ROOM_BUILD_STATE.ALLOWED:
|
||||
room_build_state = ROOM_BUILD_STATE.IS_BUILDING
|
||||
build_drag_start_pos = event_position
|
||||
place.draw_tile_click(build_drag_start_pos)
|
||||
match room_build_state:
|
||||
ROOM_BUILD_STATE.ALLOWED:
|
||||
if Input.is_action_pressed("select"):
|
||||
room_build_state = ROOM_BUILD_STATE.BUILDING
|
||||
build_drag_start_pos = event_position
|
||||
place.draw_tile_click(build_drag_start_pos)
|
||||
|
||||
elif room_build_state == ROOM_BUILD_STATE.IS_BUILDING:
|
||||
if Input.is_action_pressed("select"):
|
||||
place.init_select_drag(build_drag_start_pos, event_position)
|
||||
else:
|
||||
room_build_state = ROOM_BUILD_STATE.ALLOWED
|
||||
place.end_select_drag()
|
||||
ROOM_BUILD_STATE.BUILDING:
|
||||
if Input.is_action_pressed("select"):
|
||||
place.init_select_drag(build_drag_start_pos, event_position)
|
||||
else:
|
||||
room_build_state = ROOM_BUILD_STATE.ALLOWED
|
||||
place.end_select_drag()
|
||||
|
||||
elif room_build_state == ROOM_BUILD_STATE.IS_PLACING_DOOR:
|
||||
if not Input.is_action_pressed("select"):
|
||||
place.hover_door(event_position)
|
||||
|
||||
if Input.is_action_pressed("select"):
|
||||
room_build_state = ROOM_BUILD_STATE.NONE
|
||||
place.confirm_door()
|
||||
emit_signal("room_built")
|
||||
#ROOM_BUILD_STATE.IS_PLACING_DOOR:
|
||||
#if Input.is_action_pressed("select"):
|
||||
#room_build_state = ROOM_BUILD_STATE.NONE
|
||||
#place.confirm_door()
|
||||
#emit_signal("room_built")
|
||||
#else:
|
||||
#place.hover_door(event_position)
|
||||
|
||||
|
||||
func _on_confirm_button_pressed() -> void:
|
||||
|
||||
@ -15,6 +15,10 @@ run/main_scene="uid://x8xo5b1b3q41"
|
||||
config/features=PackedStringArray("4.4", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[global_group]
|
||||
|
||||
SaveObjects="Anything that will need to be saved when the game is."
|
||||
|
||||
[input]
|
||||
|
||||
select={
|
||||
|
||||
@ -4,8 +4,8 @@ class_name Tile
|
||||
var id = null
|
||||
|
||||
#This tile's current construction and selection modes.
|
||||
var construction_mode = 0
|
||||
var selection_mode = 0
|
||||
@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")
|
||||
@ -18,126 +18,218 @@ enum SEL_MODE {NONE, ROOM, BUILD, INVALID}
|
||||
|
||||
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),
|
||||
# East
|
||||
Vector3i(1, 0, 0),
|
||||
# South
|
||||
Vector3i(0, 0, 1),
|
||||
# West
|
||||
Vector3i(-1, 0, 0),
|
||||
]
|
||||
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_array = [
|
||||
# North
|
||||
Vector3i(0, 0, 0),
|
||||
# East
|
||||
Vector3i(1, 0, 0),
|
||||
# South
|
||||
Vector3i(1, 0, 1),
|
||||
# West
|
||||
Vector3i(0, 0, 1),
|
||||
]
|
||||
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")
|
||||
|
||||
var grid_pos = null
|
||||
@export var grid_pos = null
|
||||
|
||||
var wall_dict = {}
|
||||
@export var face_dict = {}: set = update_faces
|
||||
|
||||
var room_id = null
|
||||
@export var room = null
|
||||
|
||||
var neighbor_dict = []
|
||||
|
||||
signal wall_built
|
||||
|
||||
signal neighbor_request
|
||||
|
||||
func _ready():
|
||||
$Label3D.text = str(grid_pos)
|
||||
|
||||
|
||||
pass
|
||||
|
||||
func invalid_this_tile():
|
||||
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_face(direction, mode, door = null):
|
||||
#Updates the faces of this tile.
|
||||
var face = direction_vector_array[direction]
|
||||
func update_construction(mode):
|
||||
|
||||
if mode == FACE_MODE.NONE:
|
||||
for i in wall_dict.keys():
|
||||
wall_dict[i].queue_free()
|
||||
wall_dict.erase(i)
|
||||
construction_mode = mode
|
||||
|
||||
if mode == FACE_MODE.FULL:
|
||||
if not wall_dict.has(face):
|
||||
match mode:
|
||||
CON_MODE.NON_INTERACTABLE:
|
||||
face_dict = {}
|
||||
pass
|
||||
|
||||
var wall = load_wall.instantiate()
|
||||
CON_MODE.CLOSED:
|
||||
face_dict = {}
|
||||
$Floor/FloorMesh.set_material_override(gray)
|
||||
pass
|
||||
|
||||
wall.position = wall_position_array[direction]
|
||||
CON_MODE.OPEN:
|
||||
face_dict = {}
|
||||
pass
|
||||
|
||||
wall.rotation_degrees = Vector3(0, direction * -90, 0)
|
||||
CON_MODE.BUILT:
|
||||
$Floor/FloorMesh.set_material_override(null)
|
||||
|
||||
wall_dict[face] = wall
|
||||
update_neighbors()
|
||||
|
||||
emit_signal("wall_built", room_id)
|
||||
var temp_face_dict = {}
|
||||
|
||||
add_child(wall)
|
||||
for i in neighbor_dict.keys():
|
||||
if not neighbor_dict[i].room == room:
|
||||
#print(neighbor_dict[i].room)
|
||||
temp_face_dict[i] = null
|
||||
|
||||
if mode == FACE_MODE.DOOR:
|
||||
wall_dict[face].queue_free()
|
||||
wall_dict.erase(face)
|
||||
wall_dict[face] = door
|
||||
face_dict = temp_face_dict.duplicate()
|
||||
print(face_dict)
|
||||
|
||||
CON_MODE.REINFORCED:
|
||||
face_dict = {}
|
||||
pass
|
||||
|
||||
func update(sel_mode: int = SEL_MODE.NONE, con_mode: int = CON_MODE.NONE):
|
||||
#Updates the selection and construction modes of this tile.
|
||||
CON_MODE.CONSTRUCTION:
|
||||
pass
|
||||
pass
|
||||
|
||||
if sel_mode != selection_mode:
|
||||
|
||||
selection_mode = sel_mode
|
||||
|
||||
if sel_mode == SEL_MODE.NONE:
|
||||
func update_selection(mode):
|
||||
match mode:
|
||||
SEL_MODE.NONE:
|
||||
$Floor/FloorMesh.set_material_overlay(null)
|
||||
|
||||
elif sel_mode == SEL_MODE.ROOM:
|
||||
SEL_MODE.ROOM:
|
||||
for i in $Walls.get_children():
|
||||
i.Mesh.set_material_override(orange)
|
||||
|
||||
elif sel_mode == SEL_MODE.BUILD:
|
||||
SEL_MODE.BUILD:
|
||||
$Floor/FloorMesh.set_material_overlay(lightblue)
|
||||
|
||||
elif sel_mode == SEL_MODE.INVALID:
|
||||
SEL_MODE.INVALID:
|
||||
$Floor/FloorMesh.set_material_overlay(orange)
|
||||
|
||||
else:
|
||||
pass
|
||||
|
||||
if con_mode:
|
||||
if con_mode != construction_mode:
|
||||
|
||||
construction_mode = con_mode
|
||||
|
||||
if con_mode == CON_MODE.NON_INTERACTABLE:
|
||||
pass
|
||||
|
||||
elif con_mode == CON_MODE.CLOSED:
|
||||
$Floor/FloorMesh.set_material_override(gray)
|
||||
pass
|
||||
|
||||
elif con_mode == CON_MODE.OPEN:
|
||||
pass
|
||||
|
||||
elif con_mode == CON_MODE.BUILT:
|
||||
$Floor/FloorMesh.set_material_override(null)
|
||||
pass
|
||||
|
||||
elif con_mode == CON_MODE.REINFORCED:
|
||||
pass
|
||||
|
||||
elif con_mode == CON_MODE.CONSTRUCTION:
|
||||
pass
|
||||
|
||||
else:
|
||||
pass
|
||||
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
|
||||
|
||||
@ -1,26 +1,9 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://gs6yynwvvot2"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://gs6yynwvvot2"]
|
||||
|
||||
[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"]
|
||||
|
||||
[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" groups=["SaveObjects"]]
|
||||
script = ExtResource("1_yoisu")
|
||||
|
||||
[node name="Floor" type="Node3D" parent="."]
|
||||
@ -31,7 +14,6 @@ mesh = ExtResource("2_wxg2y")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Walls" type="Node3D" parent="."]
|
||||
script = SubResource("GDScript_3aog3")
|
||||
|
||||
[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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user