42 lines
910 B
GDScript3
42 lines
910 B
GDScript3
|
extends Node2D
|
||
|
|
||
|
@export var chapter := 2
|
||
|
@export var section := 1
|
||
|
|
||
|
@onready var ground = %Ground
|
||
|
|
||
|
var scenes_dir = "res://scene/ground/scene/"
|
||
|
|
||
|
var ground_dict = {}
|
||
|
|
||
|
|
||
|
func _ready() -> void:
|
||
|
_read_grounds()
|
||
|
|
||
|
|
||
|
func _read_grounds():
|
||
|
var dir = DirAccess.open(scenes_dir)
|
||
|
for c_dir in dir.get_directories():
|
||
|
var c = int(c_dir.substr(1))
|
||
|
var c_path = scenes_dir + c_dir + "/"
|
||
|
for s_file in DirAccess.open(c_path).get_files():
|
||
|
if s_file.ends_with(".tscn"):
|
||
|
var s = int(s_file.substr(1, 2))
|
||
|
var s_path = c_path + s_file
|
||
|
ground_dict[str(c + s)] = s_path
|
||
|
|
||
|
|
||
|
func play_footstep_sound() -> void:
|
||
|
ground.play_footstep_sound()
|
||
|
|
||
|
|
||
|
func transition_to_scene(c: int, s: int, portal: String) -> void:
|
||
|
var scene_path = ground_dict[str(c + s)]
|
||
|
if scene_path:
|
||
|
ground.scene_config = load(scene_path)
|
||
|
ground.reload()
|
||
|
chapter = c
|
||
|
section = s
|
||
|
else:
|
||
|
print("Scene not found: " + str(c) + "-" + str(s))
|