Cocos Creator Image Location Resolution Algorithm
The parameters given in the Cocos Creator image location resolution algorithm and their descriptions are as follows:
Parameter | Description |
---|---|
url | The desired URL |
startDir | The starting search directory |
DEPTH | Search depth, fixed to 2 |
SEARCH_DIR_NAMES | Array of texture folder names, default is: textures , materials |
SEARCH_EXT_NAMES | Array of extensions to search for, fixed to .jpg , .jpeg , .png , .tga , .webp |
The Cocos Creator image location resolution algorithm is given by the following procedure:
If the file corresponding to
url
exists, returnurl
.Let
expectedExtName
be the extension ofurl
.let
expectedBaseName
be the extensionless filename ofurl
.Let
searchExtNames
be the array of[expectedExtName, ...SEARCH_EXT_NAMES]
after de-duplication.Let
currentDir
bestartDir
and loop forDEPTH
times:If
currentDir
is outside the project'sassets
directory, then exit the loop.If none of the subdirectories in the
currentDir
directory have names matchingSEARCH_DIR_NAMES
, then the next loop is executed.Make
dir
a subdirectory of thecurrentDir
directory with a name matchingSEARCH_DIR_NAMES
.Search
dir
for files with base names matchingexpectedBaseName
and extensions matchingsearchExtNames
, and if so, return their paths.Set
currentDir
to its parent directory.
Return search failure.