diff --git a/CHANGELOG.md b/CHANGELOG.md index 60cbd348..3373de08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file. - Overloads for StartsWith & EndsWith methods accepting string. - SearchNode method for World helper. - Cn command now can search node tree for a node using '?'/'??' prefix. +- Wenv command. ### Changed diff --git a/addons/yat/docs/BUILTIN_COMMANDS.md b/addons/yat/docs/BUILTIN_COMMANDS.md index 232befe1..4cc28855 100644 --- a/addons/yat/docs/BUILTIN_COMMANDS.md +++ b/addons/yat/docs/BUILTIN_COMMANDS.md @@ -31,3 +31,4 @@ | cn | N/A | Changes the selected node to the specified node path. | | stats | st | Manages the game monitor. | | cs | N/A | Changes the scene. | +| wenv | N/A | Manages the world environment. | diff --git a/addons/yat/src/YAT.cs b/addons/yat/src/YAT.cs index 796594f5..a8d0f18f 100644 --- a/addons/yat/src/YAT.cs +++ b/addons/yat/src/YAT.cs @@ -71,6 +71,7 @@ public override void _Ready() AddCommand(new List()); AddCommand(new View()); AddCommand(new Ping()); + AddCommand(new Wenv()); AddCommand(new Pause()); AddCommand(new Watch()); AddCommand(new Stats()); diff --git a/addons/yat/src/commands/builtin/Wenv.cs b/addons/yat/src/commands/builtin/Wenv.cs new file mode 100644 index 00000000..8b0d7d91 --- /dev/null +++ b/addons/yat/src/commands/builtin/Wenv.cs @@ -0,0 +1,68 @@ +using Godot; +using YAT.Attributes; +using YAT.Enums; +using YAT.Interfaces; +using static YAT.Scenes.BaseTerminal.BaseTerminal; + +namespace YAT.Commands +{ + [Command("wenv", "Manages the world environment.", "[b]Usage[/b]: wenv [i]action[/i]")] + [Argument("action", "[remove, restore]", "Removes or restores the world environment.")] + public sealed class Wenv : ICommand + { + private Environment _world3DEnvironment; + private YAT _yat; + + public CommandResult Execute(CommandArguments args) + { + var action = (string)args.ConvertedArgs["action"]; + _yat = args.Yat; + + if (action == "remove") RemoveEnvironment(); + else RestoreEnvironment(); + + return CommandResult.Success; + } + + private void RestoreEnvironment() + { + var world3D = _yat.GetTree().Root.World3D; + + if (world3D is null) + { + _yat.Terminal.Print("No world to restore environment to.", PrintType.Error); + return; + } + + if (_world3DEnvironment is null) + { + _yat.Terminal.Print("No environment to restore.", PrintType.Error); + return; + } + + world3D.Environment = _world3DEnvironment; + _world3DEnvironment = null; + } + + private void RemoveEnvironment() + { + var world3D = _yat.GetTree().Root.World3D; + var env = world3D?.Environment; + + if (world3D is null) + { + _yat.Terminal.Print("No world to remove environment from.", PrintType.Error); + return; + } + + if (env is null) + { + _yat.Terminal.Print("No environment to remove.", PrintType.Error); + return; + } + + _world3DEnvironment = env; + world3D.Environment = null; + } + } +}