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
urlexists, returnurl.Let
expectedExtNamebe the extension ofurl.let
expectedBaseNamebe the extensionless filename ofurl.Let
searchExtNamesbe the array of[expectedExtName, ...SEARCH_EXT_NAMES]after de-duplication.Let
currentDirbestartDirand loop forDEPTHtimes:If
currentDiris outside the project'sassetsdirectory, then exit the loop.If none of the subdirectories in the
currentDirdirectory have names matchingSEARCH_DIR_NAMES, then the next loop is executed.Make
dira subdirectory of thecurrentDirdirectory with a name matchingSEARCH_DIR_NAMES.Search
dirfor files with base names matchingexpectedBaseNameand extensions matchingsearchExtNames, and if so, return their paths.Set
currentDirto its parent directory.
Return search failure.