This AI is still in early stages of development.
Tricks for including files
- Aubergine
Including a file if some other file not loaded
You can use this trick to create mods for your mods. A basic approach can be done using just the include() function and nothing else...
if (include("path/to/mymod.custom.js") === false) { // not found include("path/to/mymod.default.js"); // load default settings }
But, assuming you're starting to use dependencies, you might want a more robust approach...
include("path/to/util.js"); Check.paths = ["path/to/"]; // enable autoloading if (!Check.has("mymod.custom.js")) { Check.load("mymod.default.js"); }
The obvious problem here is that you might have dependencies that rely on "mymod.default.js", but if "mymod.custom.js" gets loaded instead those dependencies will break.
The solution to this is to provide a fake file in both "mymod.default.js" and "mymod.extend.js" and then use that for dependency checks:
// The normal provide() lets you check later which file was loaded... Check.provide(self); // The fake provide() lets you check that any settings were loaded... Check.provide({ file: "settings.loaded", ver : self.ver });
If you're particularly paranoid about having both file somehow get loaded, you can make sure "settings.loaded" isn't loaded during dependency checks at the top of those files...
var dependencies = { "Util.js": Check.ANY_VERSION, "settings.loaded": Check.NOT_LOADED } // will throw error if "settings.loaded" already loaded... Check.required(dependencies, self);
Dependency Checking
Topics:
- Tricks for including files — Some tricks with the include() function...
- Dependency Descriptor Object — Define one or more dependencies for your script...
- Check() — Perform a soft-check to see if a dependency is available...
- Check.basePath — The base path to the folder that contains the APIs folder...
- Check.paths[] — Define one or more folder paths to enable autoloading...
- Check.doWhen() — Perform a task when dependencies become available.
- Check.has() — Check if a dependency is available, try and load it if not, return availability state...
- Check.LAZY_LOAD — Disable autoloading during a dependency check...
- Check.required() — Thrown a descriptive error if dependency check fails...
- Check.NOT_LOADED — Indicates a script is not yet loaded, or must not be loaded, depending on the Check function being used...
- Check.ANY_VERSION — Skip version checking for a dependency check...
- Check.provide() — Indicate a file is now available.
- Check.versionOf() — Check the version of a dependency.
- Self Descriptor Object — Define the filename and version of your script...