Skip to content

Commit

Permalink
#10 - refactor open and close logic into public functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nickavv committed Nov 5, 2020
1 parent e285c23 commit 392c152
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
19 changes: 19 additions & 0 deletions rt-shell/objects/obj_shell/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ if (instance_number(obj_shell) > 1) {
instance_destroy();
}

/// @function open
/// Opens the shell
function open() {
isOpen = true;
keyboard_string = "";
if (!is_undefined(openFunction)) {
openFunction();
}
}

/// @function close
/// Closes the shell
function close() {
isOpen = false;
if (!is_undefined(closeFunction)) {
closeFunction();
}
}

// Create a list of shell functions in the global namespace to
// filter for autocompletion
autocompleteFunctions = [];
Expand Down
11 changes: 2 additions & 9 deletions rt-shell/objects/obj_shell/Step_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@ if (!surface_exists(shellSurface)) {

if (!isOpen) {
if (self.keyComboPressed()) {
isOpen = true;
keyboard_string = "";
if (!is_undefined(openFunction)) {
openFunction();
}
self.open();
}
} else {
var prevConsoleString = consoleString;

if (keyboard_check_pressed(vk_escape)) {
isOpen = false;
if (!is_undefined(closeFunction)) {
closeFunction();
}
self.close()
} else if (self.keyboardCheckDelay(vk_backspace)) {
consoleString = string_delete(consoleString, cursorPos - 1, 1);
cursorPos = max(1, cursorPos - 1);
Expand Down
8 changes: 7 additions & 1 deletion rt-shell/scripts/scr_shell_scripts/scr_shell_scripts.gml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ function sh_help() {
"set_shell_width <width>\n" +
" sets the shell's width in pixels\n" +
"set_shell_height <height>\n" +
" sets the shell's height in pixels"
" sets the shell's height in pixels\n" +
"close\n" +
" closes the shell"
)
}

Expand Down Expand Up @@ -91,6 +93,10 @@ function sh_say_greeting(args) {
return "Hello " + whomToGreet + "!";
}

function sh_close() {
obj_shell.close();
}

function sh_theme_rtshell_dark() {
obj_shell.consoleAlpha = 0.9;
obj_shell.consoleColor = c_black;
Expand Down

0 comments on commit 392c152

Please sign in to comment.