Skip to content

Commit

Permalink
Stable 0.3.00.02
Browse files Browse the repository at this point in the history
  • Loading branch information
Reycko committed Mar 8, 2024
1 parent 7514f18 commit bbbabfe
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 30 deletions.
1 change: 1 addition & 0 deletions Console.resource_order
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{"name":"Timelines","order":8,"path":"folders/Timelines.yy",},
],
"ResourceOrderSettings": [
{"name":"obj_gmlive","order":4,"path":"objects/obj_gmlive/obj_gmlive.yy",},
{"name":"GMLive_node","order":2,"path":"scripts/GMLive_node/GMLive_node.yy",},
{"name":"GMLiveAPI_js","order":4,"path":"scripts/GMLiveAPI_js/GMLiveAPI_js.yy",},
{"name":"GMLive_notOnce","order":1,"path":"scripts/GMLive_notOnce/GMLive_notOnce.yy",},
Expand Down
6 changes: 6 additions & 0 deletions Console.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 29 additions & 16 deletions objects/obj_gmconsole/Alarm_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,36 @@ function(_args, _arg_count)
return game_get_speed(_type);
});

if (instance_exists(obj_gmlive) && live_enabled) // Requires YellowAfterlife's GMLive
{
con_add_command(new ConCommandMeta
(
"eval",
"Run a string live using GMLive.",
[
new ConCommandArg("code", "string", "The code to execute."),
],
["execute", "run"],
),
function(_args, _arg_count)

con_add_command(new ConCommandMeta
(
"eval",
"Run GML through the console, requires GMLive by YellowAfterlife.",
[
new ConCommandArg("code", "string", "The code to execute.", false, [], true),
],
["execute", "run"],
true,
),
function(_args, _arg_count)
{
if (_arg_count < 1) { con_log(con.enums.logtype.err, "Missing argument 1"); return "%h"; }
if (asset_get_index("obj_gmlive") == -1) { return "Missing GMLive"; }
if (is_undefined(live_enabled)) { return "Missing GMLive"; }
try
{
var _exec = [];
array_copy(_exec, 0, _args, 1, array_length(_args) - 1); // Use array copy to prevent working on the real _args + shift by 1
live_execute_string(string_join_ext(" ", _exec));
return live_result;
}
catch (_e)
{
if (_arg_count < 1) { return "%h"; }
live_execute_string(_args[1]);
});
}
var _missing_gmlive = (string_starts_with(string_lower(_e.message), "variable <unknown_object>.live_execute_string") && string_ends_with(string_lower(_e.message), "not set before reading it."));
if (_missing_gmlive) { con_log(con.enums.logtype.err, "Missing GMLive"); return; }
con_log(con.enums.logtype.err, _e.message);
}
});

con_add_command(new ConCommandMeta
(
Expand Down
39 changes: 27 additions & 12 deletions objects/obj_gmconsole/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ con = {}; // This is our console's struct!
#region Others (pre-enum)
global.__con = id;
con.open = false;
con.version = "0.3.00.01";
con.version = "0.3.00.02";
con.latest_version = "";
con.github = {
link: "https://github.com/Reycko/GMConsole",
branch: (string_ends_with(con.version, "-dev") ? "master" : "stable"),
branch: (con_is_stable(con.version) ? "stable" : "master"),
}
con.github.get_req = { // Defining it right after defining con.github is important to avoid a crash w `link`
link: $"https://raw.github.com/Reycko/GMConsole/{con.github.branch}/ver.txt",
Expand All @@ -51,6 +51,9 @@ con.game_guisize = [display_get_gui_width(), display_get_gui_height()];
con.guisize = [1280, 720];
con.deactivation = []; // this is used for opening and closing console
con.screenshot = -1;
con.easteregg = {
konami: 0,
}
#endregion
#region Console UI customization
con.ui = {
Expand Down Expand Up @@ -149,6 +152,11 @@ con.strings = {
got: "got",
extra_argument: "Extra argument",
},

con_convert_value: {
couldnt_convert: "Couldn't convert type",
to: "to",
},
},
outdated: {
unknown: "Unknown",
Expand Down Expand Up @@ -256,22 +264,24 @@ function ConCommandArg(_arg, _type, _description, _optional = false, _values = [
arg = _arg;
var _newtype = _type;
if (_newtype == "real") { _newtype = "number"; } // Prevent typoing number as real
if (!array_contains(["string", "number", "int64", "struct", "any"], typeof(_newtype))) { con_log(con.enums.logtype.warn, $"A command tried to use invalid type {_type}, so it was changed to `any`."); _newtype = "any"; }
if (!array_contains(["string", "all", "number", "int64", "struct", "any"], _newtype)) { con_log(con.enums.logtype.warn, $"A command tried to use invalid type {_type}, so it was changed to `any`."); _newtype = "any"; }
type = _newtype;
description = _description;
optional = _optional;
values = _values;
}
/// @param {String} _name Command name.
/// @param {String} _description Command description.
/// @param {Array<Struct.ConCommandArg>} _arguments Arguments for the command.
/// @param {Array<String>} _aliases Command aliases.
function ConCommandMeta(_name, _description, _arguments = [], _aliases = []) constructor
/// @param {String} _name Command name.
/// @param {String} _description Command description.
/// @param {Array<Struct.ConCommandArg>} _arguments Arguments for the command.
/// @param {Array<String>} _aliases Command aliases.
/// @param {Bool} _allow_extra_args If true, will allow extra arguments.
function ConCommandMeta(_name, _description, _arguments = [], _aliases = [], _allow_extra_args = false) constructor
{
name = string_replace_all(_name, " ", "_");
description = _description;
arguments = _arguments;
aliases = _aliases;
allow_extra_args = _allow_extra_args;
}
#endregion
#region Command-related functions
Expand Down Expand Up @@ -317,8 +327,8 @@ function con_enum_get_name(_enum, _val)
return _inv_struct[$ _val];
}
#endregion
/// @param {Array<String>} _args Contains arguments, make them strings, they will be converted.
/// @returns {Any} Success => Command's return; Fail => undefined
/// @param {Array<String>} _args Contains arguments, make them strings, they will be converted.
/// @returns {Any} Success => Command's return; Fail => undefined
function con_call_command(_args = [])
{
try
Expand All @@ -329,6 +339,7 @@ function con_call_command(_args = [])
var _cmdargs = [];
array_copy(_cmdargs, 0, _args, 0, array_length(_args));
_cmdargs[0] = con_translate_alias(_cmdargs[0]);
if (!struct_exists(con.commands.funcs, _cmdargs[0])) { con_log(con.enums.logtype.err, $"{con.strings.cmdbar.couldnt_exec} {con.strings.cmdbar.invalid} {con.strings.cmdbar.invalid_help}"); return undefined; }
try // Silently fail if extra args are provided
{
for (var i = 1; i < array_length(_cmdargs); i++)
Expand Down Expand Up @@ -364,6 +375,7 @@ function con_convert_value(_val, _to)
switch (_to)
{
case "string": return string(_val);
case "string_all": return string(_val);
case "number": return real(string_to_number(_val));
case "int64": return int64(_val);
case "struct": return json_parse(_val);
Expand All @@ -374,7 +386,7 @@ function con_convert_value(_val, _to)
return undefined;*/
catch (_e)
{
con_log(con.enums.logtype.debug, $"con_convert_value(): Unable to convert {typeof(_val)} to `{_to}`.");
con_log(con.enums.logtype.debug, $"con_convert_value(): {con.strings.commands.con_convert_value.couldnt_convert} {typeof(_val)} {con.strings.commands.con_convert_value.to} `{_to}`.");
return undefined;
}
}
Expand Down Expand Up @@ -404,7 +416,8 @@ function con_get_arg(_args, _index)
// TODO: Implement this in a way that `args` directly gives these! (Step code?)
// TODO: Convert all the text here to con.strings
var _meta = con.commands.metas[$ _args[0]];
if (_index >= array_length(_meta.arguments) + 1) { con_log(con.enums.logtype.warn, $"{con.strings.commands.con_get_arg.extra_argument} {_index}"); return undefined; } // Extra args
if (_index >= array_length(_meta.arguments) + 1 && !_meta.allow_extra_args) { con_log(con.enums.logtype.warn, $"{con.strings.commands.con_get_arg.extra_argument} {_index}"); return undefined; } // Extra args
else if (_index >= array_length(_meta.arguments) + 1 && _meta.allow_extra_args) { return _args[_index]; }
var _arg_meta = _meta.arguments[_index - 1];

if (_index == 0) { return _arg_meta.name; }
Expand Down Expand Up @@ -475,6 +488,8 @@ function string_to_number(_str)
var _negative = string_char_at(_str, 1) == "-";
return _negative ? -real(string_digits(_str)) : real(string_digits(_str)); //TODO: Make this use math instead of an ternary (optimization)
}

// con_is_stable() in gmconsole_init for it to be initialized before obj_gmconsole
#endregion
#endregion

Expand Down
2 changes: 1 addition & 1 deletion objects/obj_gmconsole/Destroy_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

con_close();
global.__con = undefined;
show_debug_message("Console is deleted");
show_debug_message("Console is deleted");
46 changes: 46 additions & 0 deletions objects/obj_gmconsole/Step_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,50 @@ if (con.open)
}
// Feather disable once GM2016
_cmdargs = undefined;

if (keyboard_check_pressed(vk_anykey)) // Konami code easter egg (not so secret now that you're seeing it, is it?)
{
var _check = vk_nokey;
switch (con.easteregg.konami)
{
case 0:
case 1:
_check = vk_up;
break;
case 2:
case 3:
_check = vk_down;
break;
case 4: // Left (Right)
case 6: // Left (Right) 2
_check = vk_left;
break;
case 5: // (Left) Right
case 7: // (Left) Right 2
_check = vk_right;
break;
case 8:
_check = ord("B");
break;
case 9:
_check = ord("A");
break;
default:
con.easteregg.konami = 0; // Reset
break;
}

if (keyboard_check_pressed(_check))
{
con.easteregg.konami++;
} else
{
con.easteregg.konami = 0;
}

if (con.easteregg.konami == 10)
{
instance_destroy(self); // Sorry anyone that expected something cool
}
}
}
9 changes: 9 additions & 0 deletions scripts/gmconsole_init/gmconsole_init.gml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ function compile_type_tostring(in)
}
return _compile_type;
}

/// @param {String} _cver
/// @returns {Bool}
function con_is_stable(_cver)
{
if (string_ends_with(con.version, "-dev")) { return false; }
for (var i = 0; i < 10; i++) { if (string_ends_with(con.version, $"-rc{i}")) { return false; } }
return true;
}
2 changes: 1 addition & 1 deletion ver.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.00.01
0.3.00.02

0 comments on commit bbbabfe

Please sign in to comment.