Merged logic between main- and sub- script import.

This commit is contained in:
arookas 2015-12-10 17:51:21 -05:00
parent 85d85695e2
commit 0c973514d9

View file

@ -20,6 +20,7 @@ namespace arookas
List<sunScriptFile> imports = new List<sunScriptFile>(10); List<sunScriptFile> imports = new List<sunScriptFile>(10);
Stack<sunScriptFile> current = new Stack<sunScriptFile>(5); Stack<sunScriptFile> current = new Stack<sunScriptFile>(5);
string rootDirectory, currentDirectory; string rootDirectory, currentDirectory;
string CurrentDirectory { get { return current.Count > 0 ? Path.GetDirectoryName(current.Peek().Name) : currentDirectory; } }
public sunDefaultImportResolver() public sunDefaultImportResolver()
{ {
@ -43,12 +44,10 @@ namespace arookas
} }
} }
else else
{
if (current.Count > 0)
{ {
// check if the file exists relative to the current one; // check if the file exists relative to the current one;
// if it's not there, check the root directory // if it's not there, check the root directory
fullPath = Path.Combine(Path.GetDirectoryName(current.Peek().Name), name); fullPath = Path.Combine(CurrentDirectory, name);
if (!File.Exists(fullPath)) if (!File.Exists(fullPath))
{ {
fullPath = Path.Combine(rootDirectory, name); fullPath = Path.Combine(rootDirectory, name);
@ -58,16 +57,6 @@ namespace arookas
} }
} }
} }
else
{
// if this is the main script file (i.e. current stack is empty), just use the current directory
fullPath = Path.Combine(currentDirectory, name);
if (!File.Exists(fullPath))
{
return sunImportResult.Missing;
}
}
}
// make sure the file has not been imported yet // make sure the file has not been imported yet
if (imports.Any(i => i.Name == fullPath)) if (imports.Any(i => i.Name == fullPath))
{ {