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

Restore yat enable functionality #208

Merged
merged 3 commits into from
Feb 13, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
- GetRangeFromHint method to Scene class.
- PreferencesManager hold all the preferences & is a child of YAT.
- Preferences command.
- Documentation file: YAT_ENABLE.md.

### Changed

Expand All @@ -29,6 +30,7 @@ All notable changes to this project will be documented in this file.
- YAT.md
- Input.md
- BaseTerminal.md
- Restored YatEnable functionality.

### Fixed

Expand Down
9 changes: 0 additions & 9 deletions addons/yat/docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ You can find all the used actions below.
- yat_example_player_move_forward: `W`
- yat_example_player_move_backward: `S`

## Options

### YAT Enable File

You can make YAT accessible only when a specific file (default .yatenable)
is present in either the `user://` or `res://` directory (default user://).

This makes it easy to restrict terminal access to players without removing the extension.

## Script Templates

YAT includes script templates that can be used as a base for creating new classes. They are available from Godot in the `Create Script` window.
Expand Down
14 changes: 14 additions & 0 deletions addons/yat/docs/YAT_ENABLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div align="center">
<h3>YatEnable</h1>
<p>Here you can find information on the YatEnable functionality that allows you to restrict access to the terminal.</p>
</div>

### YatEnable

Yat allows you to restrict access to the terminal via the `YatEnable` file located in the `user://` or `res://` directories.

The file name as well as the target directory can be customized.

If the file is present, Yat is available, otherwise running the terminal is not possible.

Checking for the presence of the file is only done during Ready.
11 changes: 4 additions & 7 deletions addons/yat/src/YAT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,19 @@ public partial class YAT : Node
public BaseTerminal CurrentTerminal { get; set; }

public RegisteredCommands Commands { get; private set; }
public PreferencesManager PreferencesManager { get; private set; }
public TerminalManager TerminalManager { get; private set; }
public PreferencesManager PreferencesManager { get; private set; }

public override void _Ready()
{

Windows = GetNode<Node>("./Windows");
Commands = GetNode<RegisteredCommands>("./RegisteredCommands");
PreferencesManager = GetNode<PreferencesManager>("%PreferencesManager");

TerminalManager = GetNode<TerminalManager>("./TerminalManager");
TerminalManager.GameTerminal.Ready += () =>
{
TerminalManager.GameTerminal.TerminalSwitcher.TerminalSwitcherInitialized += () =>
{
CurrentTerminal = TerminalManager.GameTerminal.TerminalSwitcher.CurrentTerminal;
// CallDeferred(nameof(CheckYatEnableSettings));

};
TerminalManager.GameTerminal.TerminalSwitcher.CurrentTerminalChanged +=
(BaseTerminal terminal) =>
{
Expand All @@ -44,6 +39,8 @@ public override void _Ready()
};

Keybindings.LoadDefaultActions();

CheckYatEnableSettings();
}

private void CheckYatEnableSettings()
Expand Down
7 changes: 1 addition & 6 deletions addons/yat/src/scenes/game_terminal/GameTerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public override void _Ready()
base._Ready();

_yat = GetNode<YAT>("/root/YAT");
_yat.YatReady += () =>
{
CloseRequested += _yat.TerminalManager.CloseTerminal;
};
_yat.PreferencesManager.PreferencesUpdated += UpdateOptions;

TerminalSwitcher = GetNode<TerminalSwitcher>("%TerminalSwitcher");
Expand All @@ -30,6 +26,7 @@ public override void _Ready()
CurrentTerminal.PositionResetRequested += ResetPosition;
CurrentTerminal.SizeResetRequested += () => Size = InitialSize;

CloseRequested += _yat.TerminalManager.CloseTerminal;
ContextMenu.AddSubmenuItem("QuickCommands", "QuickCommandsContext");

MoveToCenter();
Expand All @@ -38,9 +35,7 @@ public override void _Ready()
public override void _Input(InputEvent @event)
{
if (@event.IsActionPressed(Keybindings.TerminalToggle))
{
CallDeferred("emit_signal", SignalName.CloseRequested);
}
}

private void UpdateOptions(YatPreferences prefs)
Expand Down