Dear God why did I ever use Tribal IDE!

Fixed tabbing and made the code cleaner and not so hard to read.
This commit is contained in:
Robert MacGregor 2012-07-28 10:56:45 -04:00
parent 9a05e8d86c
commit c4114d5c6d
15 changed files with 766 additions and 809 deletions

View file

@ -3,91 +3,90 @@
// -----------------------------------------------------
function getBlockCount(%file,%blockName) //Searches a data file for all occurances of 'blockName'
{
if (!IsFile(%file))
return false;
if (!IsFile(%file))
return false;
%blockSearch = strLwr("[" @ %blockName @ "]");
%blockSearch = strLwr("[" @ %blockName @ "]");
%fileP = new FileObject();
%fileP.openForRead(%file);
%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;
%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;
if (!IsFile(%file))
return false;
%blockCount = getBlockCount(%file,%blockName);
%blockCount = getBlockCount(%file,%blockName);
if (!%blockCount || %num > %blockCount) //None of 'typeName' exist here
return -1;
if (!%blockCount || %num > %blockCount) //None of 'typeName' exist here
return -1;
%blockSearch = strLwr("[" @ %blockName @ "]");
%blockSearch = strLwr("[" @ %blockName @ "]");
%fileP = new FileObject();
%fileP.openForRead(%file);
%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);
%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));
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;
%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();
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;
//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,
@ -127,81 +126,76 @@ return false;
// -----------------------------------------------------
function getArrayCount(%file,%array)
{
if (!IsFile(%file))
return false;
if (!IsFile(%file))
return false;
%arraySearch = strLwr("\x22" @ %array @ "\x22");
%arraySearch = strLwr("\x22" @ %array @ "\x22");
%fileP = new FileObject();
%fileP.openForRead(%file);
%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;
%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;
if (!IsFile(%file))
return false;
%arrayCount = getArrayCount(%file,%arrayName);
%arrayCount = getArrayCount(%file,%arrayName);
if (!%arrayCount)
return false;
if (!%arrayCount)
return false;
%arraySearch = strLwr("\x22" @ %arrayName @ "\x22");
%arraySearch = strLwr("\x22" @ %arrayName @ "\x22");
%fileP = new FileObject();
%fileP.openForRead(%file);
%fileP = new FileObject();
%fileP.openForRead(%file);
%lineCount = 0;
while (!%fileP.isEOF())
{
%line = stripSpaces(%fileP.readline());
%lineCount++;
%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 (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;
}
}
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();
}
//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;
}
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

@ -1,54 +1,48 @@
// -----------------------------------------------------
// fileProcessing.cs
// Basic file functions
// Copyright (c) 2012 The DarkDragonDX
// -----------------------------------------------------
function getFileBuffer(%file)
{
if (!IsFile(%file))
return "Not existant.";
if (!IsFile(%file))
return "Not existant.";
new FileObject(FileBuffer);
FileBuffer.openForRead(%file);
new FileObject(FileBuffer);
FileBuffer.openForRead(%file);
while (!FileBuffer.isEOF())
{
%buffer = FileBuffer.readLine() @ "\n";
}
FileBuffer.detach();
return %buffer; //Long string. >.>
while (!FileBuffer.isEOF())
%buffer = FileBuffer.readLine() @ "\n";
FileBuffer.detach();
return %buffer; //Long string. >.>
}
function getLine(%file, %line)
{
if (!IsFile(%file))
return "Not existant.";
if (!IsFile(%file))
return "Not existant.";
new FileObject(FileLine);
FileLine.openForRead(%file);
new FileObject(FileLine);
FileLine.openForRead(%file);
for (%i = 0; %i < %line; %i++)
{
%line = FileLine.readLine();
}
FileLine.detach();
return %line;
for (%i = 0; %i < %line; %i++)
%line = FileLine.readLine();
FileLine.detach();
return %line;
}
function getLine(%file, %line)
{
if (!IsFile(%file))
return "Not existant.";
if (!IsFile(%file))
return "Not existant.";
new FileObject(FileLine);
FileLine.openForRead(%file);
new FileObject(FileLine);
FileLine.openForRead(%file);
for (%i = 0; %i < %line; %i++)
{
%line = FileLine.readLine();
}
FileLine.detach();
return %line;
for (%i = 0; %i < %line; %i++)
%line = FileLine.readLine();
FileLine.detach();
return %line;
}
// -----------------------------------------------------
@ -56,9 +50,9 @@ return %line;
// -----------------------------------------------------
function fileObject::Detach(%this) //Detaches fileObject from file & deletes
{
%this.close();
%this.delete();
return %this;
%this.close();
%this.delete();
return %this;
}

View file

@ -1,9 +1,10 @@
//------------------------------------------------------------------------------
// initialise.cs
// Shared Functions for T2Bol
// Copyright (c) 2012 The DarkDragonDX
//==============================================================================
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

@ -1,14 +0,0 @@
// -----------------------------------------------------
// 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

@ -1,13 +1,19 @@
//------------------------------------------------------------------------------
// stringProcessing.cs
// String functions
// Copyright (c) 2012 The DarkDragonDX
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function textToHash(%text)
{
new fileObject(TextToHash);
TextToHash.openForWrite("Hash.txt");
TextToHash.writeLine(%text);
TextToHash.detach();
%hash = getFileCRC("Hash.txt");
deleteFile("Hash.txt");
return %hash;
new fileObject(TextToHash);
TextToHash.openForWrite("Hash.txt");
TextToHash.writeLine(%text);
TextToHash.detach();
%hash = getFileCRC("Hash.txt");
deleteFile("Hash.txt");
return %hash;
}
//------------------------------------------------------------------------------
@ -15,14 +21,11 @@ return %hash;
//------------------------------------------------------------------------------
function strReverse(%string)
{
%len = StrLen(%string);
%rstring = "";
for (%i = 0; %i < %len; %i++)
{
%rstring = getSubStr(%string,%i,1) @ %rstring;
}
return %rstring;
%len = StrLen(%string);
%rstring = "";
for (%i = 0; %i < %len; %i++)
%rstring = getSubStr(%string,%i,1) @ %rstring;
return %rstring;
}
//------------------------------------------------------------------------------
@ -30,11 +33,10 @@ return %rstring;
//------------------------------------------------------------------------------
function subStrInsert(%string,%insert,%slot)
{
%seg = getSubStr(%string,0,%slot);
%seg = %seg @ %insert;
%string = %seg @ getSubStr(%string,%slot,strLen(%string));
return %string;
%seg = getSubStr(%string,0,%slot);
%seg = %seg @ %insert;
%string = %seg @ getSubStr(%string,%slot,strLen(%string));
return %string;
}
//------------------------------------------------------------------------------
@ -42,9 +44,9 @@ return %string;
//------------------------------------------------------------------------------
function subStrRemove(%string,%slot)//Minimum: 1
{
%half2 = getSubStr(%string,%slot,strLen(%string));
%half1 = getSubStr(%string,0,%slot-1);
return %half1 @ %half2;
%half2 = getSubStr(%string,%slot,strLen(%string));
%half1 = getSubStr(%string,0,%slot-1);
return %half1 @ %half2;
}
//------------------------------------------------------------------------------
@ -52,15 +54,13 @@ 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;
%len = GetWordCount(%string);
for (%i = 0; %i < %len; %i++)
{
%sub = getWord(%string,%i);
%move = subStrInsert(%move,%sub,%i);
}
return %move;
}
//------------------------------------------------------------------------------
@ -68,15 +68,13 @@ 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;
%len = strLen(%string);
for (%i = 0; %i < %len; %i++)
{
%sub = getSubStr(%string,%i,1);
%move = subStrInsert(%move,%sub,%factor);
}
return %move;
}
//------------------------------------------------------------------------------
@ -84,25 +82,22 @@ 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;
%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);
%count = strLen(%string);
%div = %count / 2;
return getSubStr(%string,0,%div) @ " | " @ getSubStr(%string,%div,%count);
}
//------------------------------------------------------------------------------
@ -110,7 +105,7 @@ return getSubStr(%string,0,%div) @ " | " @ getSubStr(%string,%div,%count);
//------------------------------------------------------------------------------
function stripSpaces(%string)
{
return strReplace(%string," ","");
return strReplace(%string," ","");
}
//------------------------------------------------------------------------------
@ -118,8 +113,8 @@ return strReplace(%string," ","");
//------------------------------------------------------------------------------
function stripNonNumericCharacters(%string)
{
%string = strLwr(%string);
return stripChars(%string,"abcdefghijklmnopqrstuvwxyz`~!@#$%^&*()-_=+\|}]{[/?.>,<;:");
%string = strLwr(%string);
return stripChars(%string,"abcdefghijklmnopqrstuvwxyz`~!@#$%^&*()-_=+\|}]{[/?.>,<;:");
}
//------------------------------------------------------------------------------
@ -127,41 +122,39 @@ 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;
%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);
%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;
if (%sub $= %str)
{
%subC++;
if (%subC == %num)
break;
}
}
return %i;
}
//------------------------------------------------------------------------------
@ -169,7 +162,7 @@ return %i;
//------------------------------------------------------------------------------
function getFileNameFromString(%string)
{
return getSubStr(%string,getSubStrPos(%string,"/",getSubStrOccurance(%string, "/"))+1,strLen(%string));
return getSubStr(%string,getSubStrPos(%string,"/",getSubStrOccurance(%string, "/"))+1,strLen(%string));
}
//------------------------------------------------------------------------------