The base class used to define a mod. Every mod must have exactly one type that inherits from ModDef.
Inheritance: HookContainer
Beispiel #1
0
        public T ByObjRef(ObjectRef or, ModDef requesting)
        {
            var req = requesting ?? or.requesting;

            if (String.IsNullOrEmpty(or.ModName) && req != null && GetModDefs(req).ContainsKey(or.Name))
            {
                return(GetModDefs(req)[or.Name]);
            }

            if (or.Mod == PrismApi.VanillaInfo)
            {
                if (!VanillaDefsByName.ContainsKey(or.Name))
                {
                    throw new InvalidOperationException("Vanilla " + objName + " definition '" + or.Name + "' is not found.");
                }

                return(VanillaDefsByName[or.Name]);
            }

            if (!ModData.ModsFromInternalName.ContainsKey(or.ModName))
            {
                throw new InvalidOperationException(objName + " definition '" + or.Name + "' in mod '" + or.ModName + "' could not be returned because the mod is not loaded.");
            }
            if (!ModData.ModsFromInternalName[or.ModName].ItemDefs.ContainsKey(or.Name))
            {
                throw new InvalidOperationException(objName + " definition '" + or.Name + "' in mod '" + or.ModName + "' could not be resolved because the " + objName + " is not loaded.");
            }

            return(GetModDefs(ModData.ModsFromInternalName[or.ModName])[or.Name]);
        }
Beispiel #2
0
        public T ByObjRef(ObjectRef or, ModDef requesting)
        {
            var req = requesting ?? or.requesting;
            T   ret;

            if (String.IsNullOrEmpty(or.ModName) && req != null && GetModDefs(req).TryGetValue(or.Name, out ret))
            {
                return(ret);
            }

            if (or.Mod == PrismApi.VanillaInfo)
            {
                if (VanillaDefsByName.TryGetValue(or.Name, out ret))
                {
                    return(ret);
                }

                throw new InvalidOperationException("Vanilla " + objName + " definition '" + or.Name + "' is not found.");
            }

            ModDef md;

            if (!ModData.ModsFromInternalName.TryGetValue(or.ModName, out md))
            {
                throw new InvalidOperationException(objName + " definition '" + or.Name + "' in mod '" + or.ModName + "' could not be returned because the mod is not loaded.");
            }

            if (GetModDefs(md).TryGetValue(or.Name, out ret))
            {
                return(ret);
            }

            throw new InvalidOperationException(objName + " definition '" + or.Name + "' in mod '" + or.ModName + "' could not be resolved because the " + objName + " is not loaded.");
        }
Beispiel #3
0
 internal static IEnumerable<RecipeDef> SetRecipeModDefs(ModDef mod, IEnumerable<RecipeDef> defs)
 {
     return defs.Select(d =>
     {
         d.Mod = mod.Info;
         return d;
     });
 }
Beispiel #4
0
        public ObjectRef(string name, string modName = null)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            this.name    = name;
            this.modName = modName ?? String.Empty;

            requesting = ModData.ModFromAssembly(Assembly.GetCallingAssembly());
        }
Beispiel #5
0
 public ObjectRef(string name, ModInfo mod)
     : this(name, mod.InternalName)
 {
     requesting = null;
 }
Beispiel #6
0
 public override void OnAllModsLoaded()
 {
     Mod = this;
 }