Preliminary saving and loading

This commit is contained in:
effie 2025-07-10 00:24:28 +10:00
parent 2f5f465799
commit 1bb038d8b7
12 changed files with 376 additions and 201 deletions

View File

@ -1 +1,7 @@
extends Node extends Node
func save_game():
var save_data = {}

View File

@ -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://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="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="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://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"] [node name="Game" type="Node"]
script = ExtResource("1_feb5d") script = ExtResource("1_feb5d")
@ -25,6 +26,21 @@ offset_right = 243.0
offset_bottom = 635.0 offset_bottom = 635.0
text = "Confirm" 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="."] [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) transform = Transform3D(1, 0, 0, 0, 0.182236, 0.983255, 0, -0.983255, 0.182236, 24.5127, 23.2849, 20.9667)
size = 31.34 size = 31.34
@ -32,6 +48,11 @@ script = ExtResource("3_7jktm")
[node name="PlaceManager" parent="." instance=ExtResource("2_fc0e3")] [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="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/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"] [connection signal="room_built" from="PlaceManager" to="InterfaceLayer/BuildToggle" method="_on_room_built"]

38
interface/save_load.gd Normal file
View 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)

View File

@ -0,0 +1 @@
uid://bdf7ll8y2htic

View File

@ -1,6 +1,6 @@
extends Node3D 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_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")
@ -30,7 +30,7 @@ var current_room_walls: Array = []
var current_door: Object = null var current_door: Object = null
func _ready(): func _ready():
self.name = "BasePlace"
#TEMP: Sets up a simple 2D grid of blank tiles. #TEMP: Sets up a simple 2D grid of blank tiles.
for x in range(tile_grid_size): for x in range(tile_grid_size):
@ -41,30 +41,51 @@ func _ready():
tile.set_position(pos) tile.set_position(pos)
tile.grid_pos = 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 place_tile_dict[pos] = tile
add_child(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 var tile = place_tile_dict[pos]
end_select_drag()
build_selection() 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): 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_z_hist = 0
if place_tile_dict.has(build_start_pos): 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): 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
@ -98,7 +119,7 @@ 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: Object = place_tile_dict[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() selection_drag_dict.clear()
@ -113,9 +134,9 @@ func select_tile(pos):
selection_drag_dict[pos] = tile selection_drag_dict[pos] = tile
if build_confirm_allowed: if build_confirm_allowed:
tile.update(Tile.SEL_MODE.BUILD, ) tile.selection_mode = Tile.SEL_MODE.BUILD
else: else:
tile.update(Tile.SEL_MODE.INVALID, ) tile.selection_mode = 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
@ -131,7 +152,7 @@ func verify_room():
var verify_pos: Vector3i = verify_queue_array.pop_back() 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: for n in verify_neighbor_array:
@ -153,73 +174,74 @@ 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:Object = selection_dict[i] #var tile:Object = selection_dict[i]
for j in range(4): #for j in range(4):
tile.update_face(j, Tile.FACE_MODE.NONE) #tile.update_face(j, Tile.FACE_MODE.NONE)
for j in range(4): #for j in range(4):
if not selection_dict.has(i + tile.direction_vector_array[j]): #if not selection_dict.has(i + tile.direction_vector_array[j]):
tile.update_face(j, Tile.FACE_MODE.FULL) #tile.update_face(j, Tile.FACE_MODE.FULL)
if verify_room(): if verify_room():
build_confirm_allowed = true build_confirm_allowed = true
for i in selection_dict: 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: else:
build_confirm_allowed = false build_confirm_allowed = false
for i in selection_dict: 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() 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 button is clicked, changes the selected tiles to match the button's request
if not build_confirm_allowed: if not build_confirm_allowed:
return return
if selection_dict: if selection_dict:
var room: Object = create_room(selection_dict)
for i in selection_dict: for i in selection_dict:
var tile: Object = place_tile_dict[i] var tile: Object = place_tile_dict[i]
tile.update(Tile.SEL_MODE.NONE, Tile.CON_MODE.BUILT) tile.selection_mode = Tile.SEL_MODE.NONE
tile.construction_mode = Tile.CON_MODE.BUILT
var room: Object = create_room()
selection_dict.clear() selection_dict.clear()
return room #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: Object = selection_dict[i] var tile: Object = selection_dict[i]
tile.update(Tile.SEL_MODE.NONE, ) tile.selection_mode = Tile.SEL_MODE.NONE
build_confirm_allowed = true build_confirm_allowed = true
for i in selection_dict.keys(): #for i in selection_dict.keys():
var tile: Object = selection_dict[i] #var tile: Object = selection_dict[i]
for j in Tile.DIRECTION: #for j in range(4):
tile.update_face(j, Tile.FACE_MODE.NONE) #tile.update_face(j, Tile.FACE_MODE.NONE)
selection_dict.clear() selection_dict.clear()
func create_room(): func create_room(selection):
#Creates a room from the selected tiles. #Creates a room from the selected tiles.
var room: Object = load_room.instantiate() 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()) room.name = str("Room", room.get_instance_id())
add_child(room) add_child(room)
for i in room.room_tile_dict: for i in room.room_tile_dict:
place_tile_dict[i].room_id = room place_tile_dict[i].room = room
current_room = room current_room = room
@ -243,8 +265,6 @@ func create_door():
func hover_door(mouse_pos): func hover_door(mouse_pos):
#Hovers the door at the closest wall segment to the mouse in the current room #Hovers the door at the closest wall segment to the mouse in the current room
if not current_door: if not current_door:
create_door() create_door()
@ -295,8 +315,13 @@ func confirm_door():
current_door.door_room_array = [tile_1_room, tile_2_room] current_door.door_room_array = [tile_1_room, tile_2_room]
print(current_door.door_room_array)
current_room = null current_room = null
current_room_walls = [] current_room_walls = []
current_door = null 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

View File

@ -2,7 +2,7 @@
[ext_resource type="Script" uid="uid://n4vvqmlmq5fp" path="res://places/base_place/base_place.gd" id="1_uq3a8"] [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") script = ExtResource("1_uq3a8")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]

View File

@ -8,11 +8,11 @@ var room_door_array = []
#TODO: replace with global dict? #TODO: replace with global dict?
var direction_array = [ 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),
Vector3i(-1, 0, 0), Vector3i(-1, 0, 0),
] ]
func _ready(): func _ready():
self.name = str("Room", self.get_instance_id()) self.name = str("Room", self.get_instance_id())
@ -21,6 +21,17 @@ func _ready():
pass 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(): func init_path_grid():
for i in room_tile_dict.keys(): for i in room_tile_dict.keys():

View File

@ -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"] [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"] [node name="BaseRoom" type="Node3D"]
script = ExtResource("1_3l4mp") script = ExtResource("1_3l4mp")
[node name="ConnectMesh" type="MeshInstance3D" parent="."]
visible = false
mesh = SubResource("SphereMesh_3l4mp")

View File

@ -3,7 +3,7 @@ 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()
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. #Tracks the current build state.
var room_build_state = 0 var room_build_state = 0
@ -24,33 +24,34 @@ func _on_build_toggle(toggled_on):
#Responds to the 'Build A Room' toggle #Responds to the 'Build A Room' toggle
if toggled_on: if toggled_on:
room_build_state = ROOM_BUILD_STATE.ALLOWED room_build_state = ROOM_BUILD_STATE.ALLOWED
if not toggled_on: else:
place.clear_selection() place.clear_selection()
room_build_state = ROOM_BUILD_STATE.NONE 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 #Checks input events from the mouse plane
if Input.is_action_pressed("select") && room_build_state == ROOM_BUILD_STATE.ALLOWED: match room_build_state:
room_build_state = ROOM_BUILD_STATE.IS_BUILDING ROOM_BUILD_STATE.ALLOWED:
build_drag_start_pos = event_position if Input.is_action_pressed("select"):
place.draw_tile_click(build_drag_start_pos) 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: ROOM_BUILD_STATE.BUILDING:
if Input.is_action_pressed("select"): if Input.is_action_pressed("select"):
place.init_select_drag(build_drag_start_pos, event_position) place.init_select_drag(build_drag_start_pos, event_position)
else: else:
room_build_state = ROOM_BUILD_STATE.ALLOWED room_build_state = ROOM_BUILD_STATE.ALLOWED
place.end_select_drag() place.end_select_drag()
elif room_build_state == ROOM_BUILD_STATE.IS_PLACING_DOOR: #ROOM_BUILD_STATE.IS_PLACING_DOOR:
if not Input.is_action_pressed("select"): #if Input.is_action_pressed("select"):
place.hover_door(event_position) #room_build_state = ROOM_BUILD_STATE.NONE
#place.confirm_door()
if Input.is_action_pressed("select"): #emit_signal("room_built")
room_build_state = ROOM_BUILD_STATE.NONE #else:
place.confirm_door() #place.hover_door(event_position)
emit_signal("room_built")
func _on_confirm_button_pressed() -> void: func _on_confirm_button_pressed() -> void:

View File

@ -15,6 +15,10 @@ run/main_scene="uid://x8xo5b1b3q41"
config/features=PackedStringArray("4.4", "Forward Plus") config/features=PackedStringArray("4.4", "Forward Plus")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[global_group]
SaveObjects="Anything that will need to be saved when the game is."
[input] [input]
select={ select={

View File

@ -4,8 +4,8 @@ class_name Tile
var id = null var id = null
#This tile's current construction and selection modes. #This tile's current construction and selection modes.
var construction_mode = 0 @export var construction_mode = 0: set = update_construction
var selection_mode = 0 @export var selection_mode = 0: set = update_selection
var orange = preload("res://tiles/base_tile/orange.tres") var orange = preload("res://tiles/base_tile/orange.tres")
var gray = preload("res://tiles/base_tile/gray.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 CON_MODE {NONE, NON_INTERACTABLE, CLOSED, OPEN, BUILT, REINFORCED, CONSTRUCTION}
enum DIRECTION {NORTH, EAST, SOUTH, WEST}
enum FACE_MODE {NONE, FULL, PARTIAL, DOOR} enum FACE_MODE {NONE, FULL, PARTIAL, DOOR}
var direction_vector_array = [ var direction_vector_dict = {
# North "North": Vector3i(0, 0, -1),
Vector3i(0, 0, -1), "East": Vector3i(1, 0, 0),
# East "South": Vector3i(0, 0, 1),
Vector3i(1, 0, 0), "West": Vector3i(-1, 0, 0),
# South }
Vector3i(0, 0, 1),
# West
Vector3i(-1, 0, 0),
]
var wall_position_array = [ var wall_position_dict = {
# North "North": Vector3i(0, 0, 0),
Vector3i(0, 0, 0), "East": Vector3i(1, 0, 0),
# East "South": Vector3i(1, 0, 1),
Vector3i(1, 0, 0), "West": Vector3i(0, 0, 1),
# South }
Vector3i(1, 0, 1),
# West
Vector3i(0, 0, 1),
]
var load_wall = preload("res://tiles/base_tile/base_wall.tscn") 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 wall_built
signal neighbor_request
func _ready(): func _ready():
$Label3D.text = str(grid_pos)
pass 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 pass
func update_face(direction, mode, door = null): func update_construction(mode):
#Updates the faces of this tile.
var face = direction_vector_array[direction]
if mode == FACE_MODE.NONE: construction_mode = mode
for i in wall_dict.keys():
wall_dict[i].queue_free()
wall_dict.erase(i)
if mode == FACE_MODE.FULL: match mode:
if not wall_dict.has(face): 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: face_dict = temp_face_dict.duplicate()
wall_dict[face].queue_free() print(face_dict)
wall_dict.erase(face)
wall_dict[face] = door
CON_MODE.REINFORCED:
face_dict = {}
pass
func update(sel_mode: int = SEL_MODE.NONE, con_mode: int = CON_MODE.NONE): CON_MODE.CONSTRUCTION:
#Updates the selection and construction modes of this tile. pass
pass
if sel_mode != selection_mode: func update_selection(mode):
match mode:
selection_mode = sel_mode SEL_MODE.NONE:
if sel_mode == SEL_MODE.NONE:
$Floor/FloorMesh.set_material_overlay(null) $Floor/FloorMesh.set_material_overlay(null)
elif sel_mode == SEL_MODE.ROOM: SEL_MODE.ROOM:
for i in $Walls.get_children(): for i in $Walls.get_children():
i.Mesh.set_material_override(orange) i.Mesh.set_material_override(orange)
elif sel_mode == SEL_MODE.BUILD: SEL_MODE.BUILD:
$Floor/FloorMesh.set_material_overlay(lightblue) $Floor/FloorMesh.set_material_overlay(lightblue)
elif sel_mode == SEL_MODE.INVALID: SEL_MODE.INVALID:
$Floor/FloorMesh.set_material_overlay(orange) $Floor/FloorMesh.set_material_overlay(orange)
else: func update_face(direction, mode, door = null):
pass print("face update blanked")
pass
if con_mode: ##Updates the faces of this tile.
if con_mode != construction_mode: #var face = direction_vector_array[direction]
#
construction_mode = con_mode #
#
if con_mode == CON_MODE.NON_INTERACTABLE: #match mode:
pass #FACE_MODE.NONE:
#for i in wall_dict.keys():
elif con_mode == CON_MODE.CLOSED: #wall_dict[i].queue_free()
$Floor/FloorMesh.set_material_override(gray) #wall_dict.erase(i)
pass #
#FACE_MODE.FULL:
elif con_mode == CON_MODE.OPEN: #if not wall_dict.has(face):
pass #
#var wall = load_wall.instantiate()
elif con_mode == CON_MODE.BUILT: #
$Floor/FloorMesh.set_material_override(null) #wall.position = wall_position_array[direction]
pass #
#wall.rotation_degrees = Vector3(0, direction * -90, 0)
elif con_mode == CON_MODE.REINFORCED: #
pass #wall_dict[face] = wall
#
elif con_mode == CON_MODE.CONSTRUCTION: #emit_signal("wall_built", room_id)
pass #
#add_child(wall)
else: #
pass #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

View File

@ -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="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"]
[sub_resource type="GDScript" id="GDScript_3aog3"] [node name="Tile" type="Node3D" groups=["SaveObjects"]]
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"]
script = ExtResource("1_yoisu") script = ExtResource("1_yoisu")
[node name="Floor" type="Node3D" parent="."] [node name="Floor" type="Node3D" parent="."]
@ -31,7 +14,6 @@ mesh = ExtResource("2_wxg2y")
skeleton = NodePath("../..") skeleton = NodePath("../..")
[node name="Walls" type="Node3D" parent="."] [node name="Walls" type="Node3D" parent="."]
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)