Skip to content

Added CF_Trace, CF_Log, CF_Date, CF_Localiser #74

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

Merged
merged 20 commits into from
Dec 6, 2021
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
225 changes: 225 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,225 @@
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[out] firstOccurrence The index of the first character
*
* @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 firstOccurrence )
{
int count = 0;
firstOccurrence = -1;

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

if (count == 1 && firstOccurrence == -1)
{
firstOccurrence = 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.PadStringFront(4, "0"));
* >> '0055'
* @endcode
*/
string PadStringFront(int length, CF_String padChar)
{
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.PadStringBack(4, "0"));
* >> '5500'
* @endcode
*/
string PadStringBack(int length, CF_String padChar)
{
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 index at which to start changing the string
* @param padChar The string the content will be replaced with
*
* @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;
if (middle >= end)
{
return a + b;
}

string c = value.Substring(middle, end - middle);
return a + b + c;
}

/**
* @brief Replaces the string of length at the index with the splice. New string does not have to match the length.
*
* @param start The index at which to start changing the string
* @param length The length of characters to be removed
* @param padChar The string the content will be replaced with
*
* @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;
if (middle >= end)
{
return a + b;
}

string c = value.Substring(middle, end - middle);
return a + b + c;
}

/**
* @brief Checks to see if the two string matches
*
* @param a The first string to be checked
* @param b The second string to be checked
*
* @code
* CF_String a = "How are you?";
* CF_String b = "how are you?";
*
* Print(CF_String.Equals(a, b));
* >> false
*
* b = "How are you?";
* Print(CF_String.Equals(a, b));
* >> true
* @endcode
*/
static bool Equals(string a, string b)
{
return a == b;
}


/**
* @brief Checks to see if the two string matches, ignoring their case
*
* @param a The first string to be checked
* @param b The second string to be checked
*
* @code
* CF_String a = "How are you?";
* CF_String b = "how are you?";
*
* Print(CF_String.EqualsIgnoreCase(a, b));
* >> true
*
* b = "How are you?";
* Print(CF_String.EqualsIgnoreCase(a, b));
* >> true
* @endcode
*/
static bool EqualsIgnoreCase(string a, string b)
{
a.ToLower();
b.ToLower();

return a == b;
}
};
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,
};
Loading