Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wenv command #151

Merged
merged 4 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions addons/yat/docs/BUILTIN_COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
1 change: 1 addition & 0 deletions addons/yat/src/YAT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
68 changes: 68 additions & 0 deletions addons/yat/src/commands/builtin/Wenv.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}