Class Loader
- Namespace
- PolyMod
- Assembly
- PolyMod.dll
The methods that register mods, sort them, load their files and apply their GLD data.
public static class Loader
- Inheritance
-
Loader
- Inherited Members
Methods
AddPatchDataType(string, Type)
Adds a type mapping for a GLD data category. PolyMod.Loader.CreateMappings(Newtonsoft.Json.Linq.JObject) makes EnumCache mappings for new entries of this category.
If PolyMod.Loader.typeMappings already contains the category name, the method does nothing.
public static void AddPatchDataType(string typeId, Type type)
Parameters
typeIdstringThe name of the data category in the GLD, for example
unitData.typeTypeThe C# enum type of the data category.
AddPatchDataType(string, Type, bool)
Adds a type mapping for a GLD data category. If PolyMod.Loader.typeMappings already contains the category name, the method does nothing.
public static void AddPatchDataType(string typeId, Type type, bool shouldCreateCache)
Parameters
typeIdstringThe name of the data category in the GLD, for example
unitData.typeTypeThe C# type of the data category.
shouldCreateCacheboolIf true, PolyMod.Loader.CreateMappings(Newtonsoft.Json.Linq.JObject) makes
EnumCachemappings for new entries of the category. If false, it only calls the type handlers.
AddTypeHandler(Type, Action<JObject, bool>)
Adds a type handler for a C# type to PolyMod.Loader.typeHandlers. A type mapping for the type must exist in PolyMod.Loader.typeMappings. If no type mapping exists, the method writes a warning to the log and does not add the handler.
public static void AddTypeHandler(Type type, Action<JObject, bool> handler)
Parameters
typeTypeThe C# type of the data category.
handlerAction<JObject, bool>The handler to add. It gets the JSON object of a GLD entry and a flag. The flag is true when PolyMod.Loader.CreateMappings(Newtonsoft.Json.Linq.JObject) just made a new
EnumCachemapping for the entry.
LoadAssemblyFile(Mod, File)
Loads a .dll file of a mod as an assembly and starts its code.
public static void LoadAssemblyFile(Mod mod, Mod.File file)
Parameters
Remarks
If the assembly has a subclass of PolyScriptBase, the method makes an instance of the first one.
It calls Initialize and then Load on that instance, and does nothing more.
If the assembly has no such subclass, the method calls each static Load(ManualLogSource) method and each static Load() method in the assembly.
If a static Load method or the constructor of the subclass throws an exception, the method writes an error to the log.
It also sets the status of the mod to Error.
The method catches only exceptions of the type TargetInvocationException.
For this reason, it does not catch an exception from Initialize or from Load on a PolyScriptBase instance.
LoadAssetBundle(Mod, File)
Loads a .bundle file of a mod as an asset bundle and adds it to PolyMod.Registry.assetBundles.
The key is the file name without the extension.
public static void LoadAssetBundle(Mod mod, Mod.File file)
Parameters
modModThe mod that contains the file. The method does not use this parameter.
fileMod.FileThe asset bundle file to load.
LoadGameLogicDataPatch(Mod, JObject, JObject)
Merges a GLD patch of a mod into the GLD.
The method uses Merge(JObject, JObject), which changes gld in place.
If an error occurs, the method writes the error to the log and sets the status of the mod to Error.
public static void LoadGameLogicDataPatch(Mod mod, JObject gld, JObject patch)
Parameters
modModThe mod that contains the patch.
gldJObjectThe GLD as a JSON object. The method changes this object.
patchJObjectThe patch to merge.
LoadImprovementPrefabFile(Mod, File)
Loads an improvement prefab file of a mod and adds its improvement prefab info to Prefabs.improvementInfos.
If the file contains JSON null, the method does nothing.
If an error occurs, the method writes the error to the log.
public static void LoadImprovementPrefabFile(Mod mod, Mod.File file)
Parameters
LoadLanguageFile(Mod, File, string)
Loads a language file of a mod and adds it to Loc.languagesToAdd.
public static void LoadLanguageFile(Mod mod, Mod.File file, string languageName)
Parameters
modModThe mod that contains the file.
fileMod.FileThe language file to load.
languageNamestringThe language code from the file name. It is the text after
language_, or an empty string forlanguage.json.
Remarks
The file is a JSON object that maps term names to texts. If an error occurs, the method writes the error to the log. An error occurs, for example, when a different file already added the same language code.
LoadLocalizationFile(Mod, File)
Loads a localization file of a mod and adds its terms to the game localization.
public static void LoadLocalizationFile(Mod mod, Mod.File file)
Parameters
Remarks
The file is a JSON object. Each key is a term name, and each value is an object that maps language names to texts.
The method gives the data to Loc.BuildAndLoadLocalization.
If an error occurs, the method writes the error to the log.
LoadPrefabsFile(Mod, File)
Loads a prefabs file of a mod.
The method adds its unit, improvement and resource prefab infos to the lists in Prefabs.
If the file contains JSON null, the method does nothing.
If an error occurs, the method writes the error to the log.
public static void LoadPrefabsFile(Mod mod, Mod.File file)
Parameters
LoadResourcePrefabFile(Mod, File)
Loads a resource prefab file of a mod and adds its resource prefab info to Prefabs.resourceInfos.
If the file contains JSON null, the method does nothing.
If an error occurs, the method writes the error to the log.
public static void LoadResourcePrefabFile(Mod mod, Mod.File file)
Parameters
LoadSpriteInfoFile(Mod, File)
Loads a sprite info file of a mod and adds its sprite infos to PolyMod.Registry.spriteInfos.
public static Dictionary<string, Visual.SpriteInfo>? LoadSpriteInfoFile(Mod mod, Mod.File file)
Parameters
Returns
- Dictionary<string, Visual.SpriteInfo>
The sprite infos from the file, keyed by the sprite name as the file gives it, or null if an error occurs.
Remarks
The method changes each sprite name and each sprite origin name to lowercase. A sprite info replaces an existing sprite info with the same name. If an error occurs, the method writes the error to the log.
LoadTextureFile(Mod, File)
Loads a PNG file of a mod as a texture and adds it to PolyMod.Registry.textures.
The key is the lowercase file name without the extension.
The method does not make a sprite. Visual.CreateSprites makes the sprites later.
public static void LoadTextureFile(Mod mod, Mod.File file)
Parameters
modModThe mod that contains the file. The method does not use this parameter.
fileMod.FileThe PNG file to load.
LoadUnitPrefabFile(Mod, File)
Loads a unit prefab file of a mod and adds its unit prefab info to Prefabs.unitInfos.
If the file contains JSON null, the method does nothing.
If an error occurs, the method writes the error to the log.
public static void LoadUnitPrefabFile(Mod mod, Mod.File file)