Skip to content

Commit

Permalink
Merge pull request #151 from MASSHUU12/wenv-command
Browse files Browse the repository at this point in the history
Wenv command
  • Loading branch information
MASSHUU12 authored Jan 12, 2024
2 parents d7b051d + b2bcd07 commit 94ee210
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
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;
}
}
}

0 comments on commit 94ee210

Please sign in to comment.