optimization

This commit is contained in:
leca 2024-06-03 02:53:59 +03:00
parent a7eadfcd06
commit 0626bf59ed
3 changed files with 9 additions and 26 deletions

View File

@ -15,8 +15,6 @@ func _ready():
add_child(start_tile);
pass
func _physics_process(delta):
mark_empty_tiles()
func mark_empty_tiles():
var tiles = get_children()
var available = []

View File

@ -14,6 +14,7 @@ var tile_materials = [ # must be in the same order as an enum above!
@export var tile_type: TileType = TileType.Empty
@onready var visible_mesh = $"CollisionMesh/VisibleMesh"
@onready var plus_sprite = $"CollisionMesh/plus_sprite"
func update_tile():
visible_mesh.material_override = tile_materials[tile_type]
plus_sprite.visible = tile_type == TileType.Empty
@ -43,7 +44,6 @@ func get_empty_dirs_around():
return empty_tiles_around
func save():
if tile_type == TileType.Empty: return {}
return {

View File

@ -47,18 +47,12 @@ func save_world():
func load_world(save_name):
if not FileAccess.file_exists("user://%s.save" % save_name):
return # Error! We don't have a save to load.
return
# We need to revert the game state so we're not cloning objects
# during loading. This will vary wildly depending on the needs of a
# project, so take care with this step.
# For our example, we will accomplish this by deleting saveable objects.
var save_nodes = get_tree().get_nodes_in_group("Persistent")
for i in save_nodes:
i.queue_free()
# Load the file line by line and process that dictionary to restore
# the object it represents.
var save_game = FileAccess.open("user://%s.save" % save_name, FileAccess.READ)
var json_string_world = save_game.get_line()
@ -71,40 +65,31 @@ func load_world(save_name):
return
world_info = json_world.get_data()
var earth = get_tree().root.get_node("world/Earth")
while save_game.get_position() < save_game.get_length():
var json_string = save_game.get_line()
# Creates the helper class to interact with JSON
var json = JSON.new()
# Check if there is any error while parsing the JSON string, skip in case of failure
var parse_result = json.parse(json_string)
if not parse_result == OK:
print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
continue
# Get the data from the JSON object
var node_data = json.get_data()
# Firstly, we need to create the object and add it to the tree and set its position.
#var new_object = load(node_data["filename"]).instantiate()
var new_object
match node_data["node"]:
"tile":
new_object = preload("res://scenes/models/tile.tscn").instantiate()
get_tree().root.get_node("world/Earth").add_child(new_object)
earth.add_child(new_object)
new_object.position = Vector3(node_data["pos_x"], node_data["pos_y"], node_data["pos_z"])
new_object.add_to_group("Persistent")
# Now we set the remaining variables.
for i in node_data.keys():
if i == "node" or "pos" in i:
continue
new_object.set(i, node_data[i])
new_object.update_tile()
#await get_tree().create_timer(1).timeout
#get_tree().root.get_node("world/Earth").call("mark_free_tiles")
# s
await get_tree().physics_frame
earth.mark_empty_tiles()