Hey, i was developing games for 4 years and after a lot of time i decided to make a universal module loader for any game i creating
This module loader has good configuration
Lets see what it can do:
Setting up and Configuration
Just run loader.setup() once and it will setup everything for future workflow
Configuration contains ServerDirectory, ClientDirectory, ServerConfigsDirectory, ClientConfigsDirectory, ServerIdentifier and ClientIdentifier values that can be found in Configuration inside of module loader
ServerDirectory and ClientDirectory (StringValues) is used to find base folders that contains subdirectories for modules
ServerDirectory must be in ServerStorage
ClientDirectory must be in ReplicatedStorage
ServerConfigsDirectory and ClientConfigsDirectory (StringValues) is used to find subdirectory for configurations
ServerConfigsDirectory must be in ServerDirectory
ClientConfigsDirectory must be in ClientDirectory
ServerIdentifier and ClientIdentifier (IntValues) is used to identify values that later you will use for loading modules
Default loading
loader.load(MODULE_PATH, MODULE_SIDE)
Instead of require() you just load module and you get required module from cache (if it already was loaded before) or loads it in cache and returns it
for example: loader.load("ModulesSubdirectory/ModuleName", 0) loads server module that can be found in ServerDirectory.ModulesSubdirectory.ModuleName
What is MODULE_PATH? Basically you can access any module by path that contains subdirectory and module name separated by /
What is MODULE_SIDE? Its a identifier for getting server or client module
Configuration Load
loader.load(CONFIG_NAME, CONFIG_SIDE)
You can load multiple modules at once and execute their .init() function while loading
for example: loader.loadConfiguration("ConfigName", 0) loads server configuration in ServerDirectory.ServerConfigsDirectory.ConfigName
Modules always execute in order and they must be one sided, if module has .init() function it executes too
Config looks like that:
return { modules = { "MyFolder/MyModule", "OtherFolder/OtherModule" } } Lazy Loading
loader.lazyLoad(MODULE_PATH, MODULE_SIDE)
Default load but actual module gets loaded only when module[key] was used
for example: loader.lazyLoad("ModulesSubdirectory/ModuleName", 0) works same as base loader.load() but module gonna get actually loaded only when you call module variable
Other utilities
loader.isLoaded(MODULE_PATH, MODULE_SIDE)- checks if module was loaded beforeloader.clearFromCache(MODULE_PATH, MODULE_SIDE)- removes module from cacheloader.getLoadedModules()- returns all loaded modules