Fix save and load.

This commit is contained in:
leca 2024-06-03 02:26:23 +03:00
parent 280318b8d3
commit af0eb67a65
5 changed files with 27 additions and 30 deletions

View File

@ -14,21 +14,17 @@ func _ready():
add_child(start_tile);
pass
#func _process(delta):
#mark_free_tiles()
func _physics_process(delta):
mark_free_tiles()
func mark_free_tiles():
var tiles = get_children()
var available = []
for tile in tiles:
tile.update_tile()
if tile.tile_type == TileType.Empty: continue
var free_dirs = tile.get_free_dirs_around()
for dir in free_dirs:
var free_tile = tile_exemplar.instantiate()
free_tile.tile_type = TileType.Empty
free_tile.add_to_group("Persistent")
add_child(free_tile)
var pos: Vector3 = tile.position
match dir:
"north":
@ -39,7 +35,12 @@ func mark_free_tiles():
pos.z -= 10
"east":
pos.z += 10
if (available.has(pos)): continue
var free_tile = tile_exemplar.instantiate()
free_tile.tile_type = TileType.Empty
free_tile.add_to_group("Persistent")
add_child(free_tile)
free_tile.position = pos;
available.push_back(pos)
free_tile.update_tile()
#print("Created on " + str(pos) + " by " + str(tile.position))
#tiles = get_children()

View File

@ -52,7 +52,7 @@ func _physics_process(delta):
if Input.is_action_just_pressed("LMC") and eye_raycast.is_colliding() and !get_node("UI/ingame_menu").visible:
var target = eye_raycast.get_collider()
if "TileType" in target:
earth.mark_free_tiles()
#earth.mark_free_tiles()
target.tile_type = creating_tile_type
target.update_tile()
earth.mark_free_tiles()

View File

@ -7,12 +7,6 @@ enum TileType {
}
@export var tile_type: TileType = TileType.Empty;
var free_sides = {
"north": false,
"south": false,
"west": false,
"east": false,
}
func update_tile():
var children = find_children("*tile");
@ -25,7 +19,9 @@ func update_tile():
func _ready():
update_tile()
func _physics_process(delta):
func get_free_dirs_around():
var free_tiles_around = []
var space_state = get_world_3d().direct_space_state
var query_north = PhysicsRayQueryParameters3D.create(self.position + Vector3(0, 2.5, 0), self.position + Vector3(10, 2.5, 0))
@ -37,18 +33,12 @@ func _physics_process(delta):
var result_south = space_state.intersect_ray(query_south)
var result_west = space_state.intersect_ray(query_west)
var result_east = space_state.intersect_ray(query_east)
free_sides = {
"north": result_north == {},
"south": result_south == {},
"west": result_west == {},
"east": result_east == {}
}
func get_free_dirs_around():
var free_tiles_around = []
for side in free_sides.keys():
if free_sides[side]:
free_tiles_around.push_back(side)
if !result_north: free_tiles_around.push_back("north")
if !result_south: free_tiles_around.push_back("south")
if !result_west: free_tiles_around.push_back("west")
if !result_east: free_tiles_around.push_back("east")
return free_tiles_around

View File

@ -101,7 +101,6 @@ func load_world(save_name):
continue
new_object.set(i, node_data[i])
new_object.update_tile()
#get_tree().root.get_node("world/Earth").mark_free_tiles()
#await get_tree().create_timer(1).timeout

9
todo
View File

@ -1,2 +1,9 @@
Починить кривую загрузку мира, в результате которой плюсики по всему миру
Упростить устройство тайла, сделать единственную модель со сменяемым через скрипт материалом
Создать следующие типы тайлов:
* Лес
* Озеро
* Море (Будут отличаться глубиной и чуть-чуть цветом)
* Река (возможно)
* Горы
* Пустыни
Создать первый прототип людей и поселений