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

Added CF_Trace, CF_Log, CF_Date, CF_Localiser #74

Merged
merged 20 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 15 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
165 changes: 165 additions & 0 deletions JM/CF/Scripts/1_Core/CommunityFramework/CF_String.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
typedef string CF_String;
class CF_String : string
{

/**
* @brief Returns the number of times the specified character exists in the string
*
* @param char The character that will be matched
*
* @code
* CF_String str = "Hello, World!";
* int count = str.CountCharacter("l");
* Print(count);
* >> '3'
* @endcode
*/
int CountCharacter(CF_String char)
{
int count = 0;
int length = value.Length();
for (int index = 0; index < length; index++)
{
count += value.Substring(index, 1) == char;
}
return count;
}

/**
* @brief Returns the number of times the specified character exists in the string
*
* @param char The character that will be matched
* @param firstIndex The index of the first character
Jacob-Mango marked this conversation as resolved.
Show resolved Hide resolved
*
* @code
* CF_String str = "Hello, World!";
* int index;
* int count = str.CountCharacter("l", index);
* Print(count);
* Print(index);
* >> '3'
* >> '2'
* @endcode
*/
int CountCharacter(CF_String char, out int firstIndex)
{
int count = 0;
firstIndex = -1;

int length = value.Length();
for (int index = 0; index < length; index++)
{
count += value.Substring(index, 1) == char;

if (count == 1 && firstIndex == -1)
{
firstIndex = index;
}
}

return count;
}

/**
* @brief Fills the string with the specified character at the start so the string matches the length.
* Does nothing if string is equal to or exceeds the specifiying length.
*
* @param length The total string length
* @param padChar The character that will be padded
*
* @code
* CF_String str = "55";
* Print(str.PadStringEnd(4, "0"));
Jacob-Mango marked this conversation as resolved.
Show resolved Hide resolved
* >> '0055'
* @endcode
*/
string PadString(int length, CF_String padChar)
Jacob-Mango marked this conversation as resolved.
Show resolved Hide resolved
{
string newString = value;
length = newString.Length() - length;

if (length > 0)
{
for (int index = 0; index < length; index++)
{
newString = padChar + newString;
}
}

return newString;
}

/**
* @brief Fills the string with the specified character at the end so the string matches the length.
* Does nothing if string is equal to or exceeds the specifiying length.
*
* @param length The total string length
* @param padChar The character that will be padded
*
* @code
* CF_String str = "55";
* Print(str.PadStringEnd(4, "0"));
* >> '5500'
* @endcode
*/
string PadStringEnd(int length, CF_String padChar)
Jacob-Mango marked this conversation as resolved.
Show resolved Hide resolved
{
string newString = value;
length = newString.Length() - length;

if (length > 0)
{
for (int index = 0; index < length; index++)
{
newString += padChar;
}
}

return newString;
}

/**
* @brief Replaces the string of length at the index with the splice.
*
* @param start The first character to be removed
Jacob-Mango marked this conversation as resolved.
Show resolved Hide resolved
* @param padChar The string that will replace those characters
Jacob-Mango marked this conversation as resolved.
Show resolved Hide resolved
*
* @code
* CF_String str = "How is you?";
* Print(str.SpliceString(4, "be"));
* >> 'How be you?'
* @endcode
*/
string SpliceString(int start, CF_String splice)
{
int middle = start + splice.Length();
int end = value.Length();
string a = value.Substring(0, start);
string b = splice;
string c = value.Substring(middle, end - middle);
return a + b + c;
}
Jacob-Mango marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Replaces the string of length at the index with the splice. New string does not have to match the length.
*
* @param start The first character to be removed
* @param length The length of characters to be removed
* @param padChar The string that will replace those characters
*
* @code
* CF_String str = "How are you?";
* Print(str.SpliceString(4, 3, "is"));
* >> 'How is you?'
* @endcode
*/
string SpliceString(int start, int length, CF_String splice)
{
int middle = start + length;
int end = value.Length();
string a = value.Substring(0, start);
string b = splice;
string c = value.Substring(middle, end - middle);
return a + b + c;
}
Jacob-Mango marked this conversation as resolved.
Show resolved Hide resolved
};
69 changes: 69 additions & 0 deletions JM/CF/Scripts/1_Core/CommunityFramework/Logging/CF_Log.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class CF_Log
{
static int Level = CF_LogLevel.ERROR;

static bool IsLogging(CF_LogLevel level)
{
return level >= Level;
}

/**
* @brief Logs that contain the most detailed messages. These messages should never be enabled in a production environment.
*/
static void Trace(string message, string param1 = "", string param2 = "", string param3 = "", string param4 = "", string param5 = "", string param6 = "", string param7 = "", string param8 = "", string param9 = "")
{
if (Level > CF_LogLevel.TRACE) return;

PrintFormat("[TRACE] %1", string.Format(message, param1, param2, param3, param4, param5, param6, param7, param8, param9));
}

/**
* @brief Logs that should primarily contain information useful for debugging.
*/
static void Debug(string message, string param1 = "", string param2 = "", string param3 = "", string param4 = "", string param5 = "", string param6 = "", string param7 = "", string param8 = "", string param9 = "")
{
if (Level > CF_LogLevel.DEBUG) return;

PrintFormat("[DEBUG] %1", string.Format(message, param1, param2, param3, param4, param5, param6, param7, param8, param9));
}

/**
* @brief Logs that output information that may be relevant to the user.
*/
static void Info(string message, string param1 = "", string param2 = "", string param3 = "", string param4 = "", string param5 = "", string param6 = "", string param7 = "", string param8 = "", string param9 = "")
{
if (Level > CF_LogLevel.INFO) return;

PrintFormat("[INFO] %1", string.Format(message, param1, param2, param3, param4, param5, param6, param7, param8, param9));
}

/**
* @brief Logs that highlight an abnormal action, but does cause the user to notice anything different.
*/
static void Warn(string message, string param1 = "", string param2 = "", string param3 = "", string param4 = "", string param5 = "", string param6 = "", string param7 = "", string param8 = "", string param9 = "")
{
if (Level > CF_LogLevel.WARNING) return;

PrintFormat("[WARNING] %1", string.Format(message, param1, param2, param3, param4, param5, param6, param7, param8, param9));
}

/**
* @brief Logs that highlight when the current flow of execution is stopped due to a failure. This should indicate if the current activity has a failure and will not result in the game shutting down.
*/
static void Error(string message, string param1 = "", string param2 = "", string param3 = "", string param4 = "", string param5 = "", string param6 = "", string param7 = "", string param8 = "", string param9 = "")
{
if (Level > CF_LogLevel.ERROR) return;

PrintFormat("[ERROR] %1", string.Format(message, param1, param2, param3, param4, param5, param6, param7, param8, param9));
}

/**
* @brief Logs that describe an unrecoverable event and will most likely lead to the shutdown of the game.
*/
static void Critical(string message, string param1 = "", string param2 = "", string param3 = "", string param4 = "", string param5 = "", string param6 = "", string param7 = "", string param8 = "", string param9 = "")
{
if (Level > CF_LogLevel.CRITICAL) return;

PrintFormat("[CRITICAL] %1", string.Format(message, param1, param2, param3, param4, param5, param6, param7, param8, param9));
}
};
10 changes: 10 additions & 0 deletions JM/CF/Scripts/1_Core/CommunityFramework/Logging/CF_LogLevel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
enum CF_LogLevel
{
TRACE = 0,
DEBUG,
INFO,
WARNING,
ERROR,
CRITICAL,
NONE,
};
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static void CF_DumpWidgets( Widget root, int tabs = 0 )
static void Assert_Log( string str )
{
Print( "==============================================WARNING=======================================================" );
string time = JMDate.Now( false ).ToString( "YYYY-MM-DD hh:mm:ss" );
string time = CF_Date.Now( false ).Format( CF_Date.DATETIME );
Print( "[WARNING " + time + "] " + str );
Print( "Do you see this message? Unless the time is within a second of the crash than this was not the cause." );

Expand Down
Loading