From af0eb67a6534d909748c02aefc58da7755969d75 Mon Sep 17 00:00:00 2001 From: leca Date: Mon, 3 Jun 2024 02:26:23 +0300 Subject: [PATCH] Fix save and load. --- scripts/Earth.gd | 19 ++++++++++--------- scripts/God.gd | 2 +- scripts/Tile.gd | 26 ++++++++------------------ scripts/world.gd | 1 - todo | 9 ++++++++- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/scripts/Earth.gd b/scripts/Earth.gd index a918a80..0b4bf41 100644 --- a/scripts/Earth.gd +++ b/scripts/Earth.gd @@ -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() diff --git a/scripts/God.gd b/scripts/God.gd index 21ea59b..242b502 100644 --- a/scripts/God.gd +++ b/scripts/God.gd @@ -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() diff --git a/scripts/Tile.gd b/scripts/Tile.gd index d94b11e..5901972 100644 --- a/scripts/Tile.gd +++ b/scripts/Tile.gd @@ -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 diff --git a/scripts/world.gd b/scripts/world.gd index 994e857..0b847e3 100644 --- a/scripts/world.gd +++ b/scripts/world.gd @@ -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 diff --git a/todo b/todo index e85e7c1..f3dc98e 100644 --- a/todo +++ b/todo @@ -1,2 +1,9 @@ -Починить кривую загрузку мира, в результате которой плюсики по всему миру Упростить устройство тайла, сделать единственную модель со сменяемым через скрипт материалом +Создать следующие типы тайлов: + * Лес + * Озеро + * Море (Будут отличаться глубиной и чуть-чуть цветом) + * Река (возможно) + * Горы + * Пустыни +Создать первый прототип людей и поселений