Initial commit.

This commit is contained in:
Robert MacGregor 2012-07-27 17:22:05 -04:00
commit 9a05e8d86c
652 changed files with 154587 additions and 0 deletions

View file

@ -0,0 +1,207 @@
// -----------------------------------------------------
// Block Processing
// -----------------------------------------------------
function getBlockCount(%file,%blockName) //Searches a data file for all occurances of 'blockName'
{
if (!IsFile(%file))
return false;
%blockSearch = strLwr("[" @ %blockName @ "]");
%fileP = new FileObject();
%fileP.openForRead(%file);
%count = 0;
while (!%fileP.isEOF())
{
%line = %fileP.readLine();
%lineTest = strLwr(%line);
%Search = strStr(%lineTest,%blockSearch);
if (%search != -1)
%count++;
}
%fileP.detach();
return %count;
}
function getBlockData(%file,%blockName,%num,%data) //Gets values out of a block. Note that 1 is the first block in a file for %num
{
if (!IsFile(%file))
return false;
%blockCount = getBlockCount(%file,%blockName);
if (!%blockCount || %num > %blockCount) //None of 'typeName' exist here
return -1;
%blockSearch = strLwr("[" @ %blockName @ "]");
%fileP = new FileObject();
%fileP.openForRead(%file);
%count = 0;
%lineCount = 0;
while (!%fileP.isEOF())
{
%line = %fileP.readLine();
%lineCount++;
if (getSubStr(stripSpaces(%line),0,1) !$= ";") //If the beginning of the line is "commented", skip it.
{
%lineTest = strLwr(%line);
%Search = strStr(%lineTest,%blockSearch);
if (%Search != -1 && %Count != %num)
%count++;
else if (%count == %num) //We found it, stop incrementing the count and find our data.
{
%Search = strStr(strLwr(%line),strLwr(%data));
%lineTest = strLwr(strReplace(%line," ","")); //See if we exited our block
if (GetSubStr(%lineTest, 0, 1) $= "[") //The beginning of a new block
return -1;
if (%search != -1) //We found it,
{
%fileP.detach();
//Since our line might have some sort of commenting after it, we better return to just the "end" symbol..
%semiS =strStr(%line, ";");
if (%semiS == -1)
return -1;
%line = getSubStr(%line, 0, %semiS);
//Now find where "equals" is..
%equalS = strStr(%line, "=");
if (%equalS == -1)
return -1;
%line = getSubStr(%line, %equalS+1, strLen(%line));
//Is our data in single quotations? If so, convert it to a tagged string.
if (strStr(%line,"\x27") != -1) //It is.
%line = addTaggedString(stripChars(%line,"\x27"));
//Now return our string without quotations.
%line = stripChars(stripTrailingSpaces(strReplace(%line,%data,"")),"\x22");
return getSubStr(%line,1,strLen(%line));
}
}
}
}
%fileP.detach();
return false;
}
//function getBlockLength(%file,%blockName,%num) Won't work until I figure out a way to signal the end of a block without adding any extra characters,
//{
//if (!IsFile(%file))
//return "Not existant.";
//%blockSearch = "[" @ %blockName @ "]";
//%blockSearch = strLwr(%blockSearch); //Convert to lowerCase
//new FileObject(GetBlockCount);
//GetBlockCount.openForRead(%file);
//%count = 0;
//%len = 0;
// while (!GetBlockCount.isEOF())
// {
// %line = GetBlockCount.readLine();
// %lineTest = strLwr(%line);
// %Search = strStr(%lineTest,%blockSearch);
//if (%search != -1)
// %count++;
// else if (%search != -1 && %count == %num) //We found our wanted block, count it.
//{
// if (strStr(%lineTest,%blockSearch) == -1)
// %len++;
// else
// break;
// }
//}
//GetBlockCount.detach();
//return %len;
//}
// -----------------------------------------------------
// Array Processing
// -----------------------------------------------------
function getArrayCount(%file,%array)
{
if (!IsFile(%file))
return false;
%arraySearch = strLwr("\x22" @ %array @ "\x22");
%fileP = new FileObject();
%fileP.openForRead(%file);
%count = 0;
while (!%fileP.isEOF())
{
%line = %fileP.readLine();
%lineTest = strLwr(%line);
%Search = strStr(%lineTest,%typeSearch);
if (%search != -1)
%count++;
}
%fileP.detach();
return %count;
}
function getArrayData(%file,%arrayName,%num)
{
if (!IsFile(%file))
return false;
%arrayCount = getArrayCount(%file,%arrayName);
if (!%arrayCount)
return false;
%arraySearch = strLwr("\x22" @ %arrayName @ "\x22");
%fileP = new FileObject();
%fileP.openForRead(%file);
%lineCount = 0;
while (!%fileP.isEOF())
{
%line = stripSpaces(%fileP.readline());
%lineCount++;
if (getSubStr(%line,0,1) !$= ";") //Is this line a comment?
{
%search = strStr(strLwr(%line),%arraySearch);
if (%search !$= -1) //Found it.
break; //Break the loop, we know the array exists
if (%fileP.IsEOF() && %search == -1) //Didn't find it, return the error.
return false;
}
}
//Check where the array actually starts..
%line = %fileP.readLine();
if (%line $= "{") //Data starts on next line..
{
%line = %fileP.readLine(); //Drop it down one
for (%i = 0; %i < %num; %i++) //Keep going untill we hit the wanted data
{
%line = %fileP.readLine();
}
}
else //The line we just grabbed is part of the data
{
if (%num == 0) //The wanted data was on line zero..
return %line;
for (%i = 0; %i < %num; %i++) //Keep going untill we hit the wanted data
{
%line = %fileP.readLine();
}
}
%fileP.detach();
return %line;
}

View file

@ -0,0 +1,66 @@
// -----------------------------------------------------
// Basic file functions
// -----------------------------------------------------
function getFileBuffer(%file)
{
if (!IsFile(%file))
return "Not existant.";
new FileObject(FileBuffer);
FileBuffer.openForRead(%file);
while (!FileBuffer.isEOF())
{
%buffer = FileBuffer.readLine() @ "\n";
}
FileBuffer.detach();
return %buffer; //Long string. >.>
}
function getLine(%file, %line)
{
if (!IsFile(%file))
return "Not existant.";
new FileObject(FileLine);
FileLine.openForRead(%file);
for (%i = 0; %i < %line; %i++)
{
%line = FileLine.readLine();
}
FileLine.detach();
return %line;
}
function getLine(%file, %line)
{
if (!IsFile(%file))
return "Not existant.";
new FileObject(FileLine);
FileLine.openForRead(%file);
for (%i = 0; %i < %line; %i++)
{
%line = FileLine.readLine();
}
FileLine.detach();
return %line;
}
// -----------------------------------------------------
// Bound Functions
// -----------------------------------------------------
function fileObject::Detach(%this) //Detaches fileObject from file & deletes
{
%this.close();
%this.delete();
return %this;
}

View file

@ -0,0 +1,9 @@
//------------------------------------------------------------------------------
// Shared Functions for T2Bol
//==============================================================================
exec("scripts/modScripts/shared/stringProcessing.cs");
exec("scripts/modScripts/shared/fileProcessing.cs");
exec("scripts/modScripts/shared/numericProcessing.cs");
exec("scripts/modScripts/shared/basicDataStorage.cs");

View file

@ -0,0 +1,14 @@
// -----------------------------------------------------
// Number Processing
// -----------------------------------------------------
function decimalToPercent(%decimal) //Doesn't work very nicely at the time.. probably won't be used after a bit
{
return %decimal * 100;
}
function isDecimal(%num)
{
return strStr(%num,".");
}

View file

@ -0,0 +1,175 @@
//------------------------------------------------------------------------------
function textToHash(%text)
{
new fileObject(TextToHash);
TextToHash.openForWrite("Hash.txt");
TextToHash.writeLine(%text);
TextToHash.detach();
%hash = getFileCRC("Hash.txt");
deleteFile("Hash.txt");
return %hash;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function strReverse(%string)
{
%len = StrLen(%string);
%rstring = "";
for (%i = 0; %i < %len; %i++)
{
%rstring = getSubStr(%string,%i,1) @ %rstring;
}
return %rstring;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function subStrInsert(%string,%insert,%slot)
{
%seg = getSubStr(%string,0,%slot);
%seg = %seg @ %insert;
%string = %seg @ getSubStr(%string,%slot,strLen(%string));
return %string;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function subStrRemove(%string,%slot)//Minimum: 1
{
%half2 = getSubStr(%string,%slot,strLen(%string));
%half1 = getSubStr(%string,0,%slot-1);
return %half1 @ %half2;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function strMove(%string,%factor)
{
%len = GetWordCount(%string);
for (%i = 0; %i < %len; %i++)
{
%sub = getWord(%string,%i);
%move = subStrInsert(%move,%sub,%i);
}
return %move;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function subStrMove(%string,%factor)
{
%len = strLen(%string);
for (%i = 0; %i < %len; %i++)
{
%sub = getSubStr(%string,%i,1);
%move = subStrInsert(%move,%sub,%factor);
}
return %move;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function subStrScramble(%string)
{
%len = strLen(%string);
for (%i = 0; %i < %len; %i++)
{
%sub = getSubStr(%string,%i,1);
%scramble = subStrInsert(%scramble,%sub,getRandom(0,%len));
}
return %scramble;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function strSplit(%string)
{
%count = strLen(%string);
%div = %count / 2;
return getSubStr(%string,0,%div) @ " | " @ getSubStr(%string,%div,%count);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function stripSpaces(%string)
{
return strReplace(%string," ","");
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function stripNonNumericCharacters(%string)
{
%string = strLwr(%string);
return stripChars(%string,"abcdefghijklmnopqrstuvwxyz`~!@#$%^&*()-_=+\|}]{[/?.>,<;:");
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function getSubStrOccurance(%string,%search)
{
%len = strLen(%string);
%srLen = strLen(%search);
%count = 0;
for (%i = 0; %i < %len; %i++)
{
%strSearch = strStr(%string,%search);
if (%strSearch != -1) //It exists somewhere in the string
{
%count++;
%string = getSubStr(%string,%strSearch+%srLen,%len);
}
else
return %count;
}
return %count;
}
function getSubStrPos(%string,%str,%num)
{
%len = strLen(%string);
%subC = 0;
for (%i = 0; %i < %len; %i++)
{
%sub = getSubStr(%string,%i,1);
if (%sub $= %str)
{
%subC++;
if (%subC == %num)
break;
}
}
return %i;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function getFileNameFromString(%string)
{
return getSubStr(%string,getSubStrPos(%string,"/",getSubStrOccurance(%string, "/"))+1,strLen(%string));
}
//------------------------------------------------------------------------------