Skip to content

Commit

Permalink
Adds SnitchLogGetString()
Browse files Browse the repository at this point in the history
  • Loading branch information
JujuAdams committed May 2, 2023
1 parent 7c4ce57 commit 3715d2f
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Snitch.yyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"resourceVersion": "1.6",
"name": "Snitch",
"resources": [
{"id":{"name":"__SnitchShowDebugMessage","path":"scripts/__SnitchShowDebugMessage/__SnitchShowDebugMessage.yy",},"order":15,},
{"id":{"name":"SnitchServiceSet","path":"scripts/SnitchServiceSet/SnitchServiceSet.yy",},"order":6,},
{"id":{"name":"SnitchLogSet","path":"scripts/SnitchLogSet/SnitchLogSet.yy",},"order":0,},
{"id":{"name":"SnitchSoftError","path":"scripts/SnitchSoftError/SnitchSoftError.yy",},"order":2,},
{"id":{"name":"__SnitchInitialize","path":"scripts/__SnitchInitialize/__SnitchInitialize.yy",},"order":0,},
{"id":{"name":"SnitchLogGetString","path":"scripts/SnitchLogGetString/SnitchLogGetString.yy",},"order":4,},
{"id":{"name":"SnitchNetworkSet","path":"scripts/SnitchNetworkSet/SnitchNetworkSet.yy",},"order":2,},
{"id":{"name":"oInvalidObject","path":"objects/oInvalidObject/oInvalidObject.yy",},"order":2,},
{"id":{"name":"SnitchSendStringToNetwork","path":"scripts/SnitchSendStringToNetwork/SnitchSendStringToNetwork.yy",},"order":3,},
Expand Down
2 changes: 1 addition & 1 deletion scripts/Snitch/Snitch.gml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Snitch()
++_i;
}

show_debug_message(_string);
__SnitchShowDebugMessage(_string);
SnitchSendStringToLogFile(_string);
SnitchSendStringToNetwork(_string); //TODO - Format this string for consumption (LogCat?)
}
24 changes: 24 additions & 0 deletions scripts/SnitchLogGetString/SnitchLogGetString.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// @param index

function SnitchLogGetString(_index)
{
static _logArray = __SnitchState().__logArray;

if (_index == all)
{
var _string = "";

var _i = 0;
repeat(SNITCH_IN_GAME_LOG_SIZE)
{
_string += _logArray[_i] + "\n";
++_i;
}

_string = string_delete(_string, string_length(_string), 1);

return _string;
}

return ((_index < 0) || (_index >= SNITCH_IN_GAME_LOG_SIZE))? "" : _logArray[_index];
}
11 changes: 11 additions & 0 deletions scripts/SnitchLogGetString/SnitchLogGetString.yy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"resourceType": "GMScript",
"resourceVersion": "1.0",
"name": "SnitchLogGetString",
"isDnD": false,
"isCompatibility": false,
"parent": {
"name": "Advanced",
"path": "folders/Snitch/Advanced.yy",
},
}
2 changes: 1 addition & 1 deletion scripts/__SnitchClassError/__SnitchClassError.gml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function __SnitchClassError() constructor
var _string = "[" + (__fatal? "fatal" : "error") + " " + __uuid + "] " + __message;
if (is_array(__rawCallstackArray)) _string += " " + string(__GuaranteeSimpleCallstack());

show_debug_message(_string);
__SnitchShowDebugMessage(_string);
SnitchSendStringToLogFile(_string);
SnitchSendStringToNetwork(_string);
}
Expand Down
4 changes: 4 additions & 0 deletions scripts/__SnitchConfigLog/__SnitchConfigLog.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//How many strings to store in the in-game copy of the log
//You can fetch strings using SnitchLogGetString()
#macro SNITCH_IN_GAME_LOG_SIZE 20

//Controls whether logging to file should be allowed at all
#macro SNITCH_LOG_PERMITTED true

Expand Down
1 change: 1 addition & 0 deletions scripts/__SnitchInitialize/__SnitchInitialize.gml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function __SnitchInitialize()
__CrashCapture = __RunningFromIDE? SNITCH_CRASH_CAPTURE_FROM_IDE : SNITCH_CRASH_CAPTURE_COMPILED;

//Log files
__logArray = array_create(SNITCH_IN_GAME_LOG_SIZE, "");
__WroteLogFileHeader = false;
__ZerothLogFile = string_replace(SNITCH_LOG_FILENAME, "#", "0");
__LogFileBuffer = buffer_create(SNITCH_LOG_BUFFER_START_SIZE, buffer_grow, 1);
Expand Down
11 changes: 11 additions & 0 deletions scripts/__SnitchShowDebugMessage/__SnitchShowDebugMessage.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// @param string

function __SnitchShowDebugMessage(_string)
{
static _logArray = __SnitchState().__logArray;

array_insert(_logArray, 0, _string);
array_delete(_logArray, SNITCH_IN_GAME_LOG_SIZE-1, 1);

show_debug_message(_string);
}
11 changes: 11 additions & 0 deletions scripts/__SnitchShowDebugMessage/__SnitchShowDebugMessage.yy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"resourceType": "GMScript",
"resourceVersion": "1.0",
"name": "__SnitchShowDebugMessage",
"isDnD": false,
"isCompatibility": false,
"parent": {
"name": "THE SNITCH SEES ALL",
"path": "folders/Snitch/(System)/THE SNITCH SEES ALL.yy",
},
}
2 changes: 1 addition & 1 deletion scripts/__SnitchTrace/__SnitchTrace.gml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ function __SnitchTrace()

SnitchSendStringToLogFile(_string);
SnitchSendStringToNetwork(_string);
show_debug_message(_string);
__SnitchShowDebugMessage(_string);
}

0 comments on commit 3715d2f

Please sign in to comment.