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;
}