///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // D E R E L I C T // /// // (c) 2003..2025 using Godot; using Godot.Sharp.Extras; using System; [GlobalClass] public partial class DirSpawner : MultiplayerSpawner { [Export( PropertyHint.Dir )] public string Directory; // Called when the node enters the scene tree for the first time. public override void _Ready() { base._Ready(); this.OnReady(); log.info( $"{log.loc().Log}: Searching for spawns in {Directory}" ); AddSpawnables( Directory ); /* var dir = gd.DirAccess.Open( Directory); if( dir == null ) { log.error( $"{log.loc().Log}: Unable to open directory: {Directory}" ); return; } dir.ListDirBegin(); while (true) { var fileName = dir.GetNext(); if (fileName == String.Empty) break; if (dir.CurrentIsDir()) continue; var path = System.IO.Path.Combine(Directory, fileName); log.info( $"{log.loc().Log}: Spawning scene from file: {path}" ); AddSpawnableScene( path ); /* var scene = ResourceLoader.Load( path ); if ( scene == null ) { GD.PrintErr( $"DirSpawner: Unable to load scene: {path}" ); continue; } var instance = scene.Instantiate(); if ( instance == null ) { GD.PrintErr( $"DirSpawner: Unable to instantiate scene: {path}" ); continue; } AddChild( instance ); * / } dir.ListDirEnd(); */ } public void AddSpawnables( string dir ) { var files = DirAccess.GetFilesAt( dir ); foreach( var file in files ) { var path = System.IO.Path.Combine( dir, file ); log.info( $"{log.loc().Log}: Add scene: {path}" ); AddSpawnableScene( path ); } var directories = DirAccess.GetDirectoriesAt( dir ); foreach( var subdir in directories ) { var path = System.IO.Path.Combine( dir, subdir ); AddSpawnables( path ); } } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process( double delta ) { } }