Exemple #1
0
 public void TryTransferMod(IModObject mod)
 {
     AddMod(mod, otherList);
     RemoveMod(mod, this);
     RefreshDisplay();
     otherList.RefreshDisplay();
 }
Exemple #2
0
 private void RemoveMod(IModObject mod, ModScrollList modList)
 {
     for (int i = modList.modList.Count - 1; i >= 0; i--)
     {
         if (modList.modList[i] == mod)
         {
             modList.modList.RemoveAt(i);
         }
     }
 }
Exemple #3
0
 public bool TryLoadMod(IModObject toAdd)
 {
     if (_loadedMods.Add(toAdd))
     {
         toAdd.IsLoaded = true;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #4
0
 public bool TryDisableMod(IModObject toDisable)
 {
     if (_activeMods.Remove(toDisable))
     {
         toDisable.IsActivated = false;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #5
0
 public bool TryUnloadMod(IModObject toRemove)
 {
     if (_loadedMods.Remove(toRemove))
     {
         toRemove.IsLoaded = false;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #6
0
 public bool TryEnableMod(IModObject toActivate)
 {
     if (_loadedMods.Contains(toActivate) &&
         CheckAllModsActive(toActivate.Dependencies) &&
         !CheckSomeModsActive(toActivate.Incompatibles))
     {
         toActivate.IsActivated = true;
         _activeMods.Add(toActivate);
         return(true);
     }
     else
     {
         return(false);
     }
 }
        private void LoadObjects(IContentPack contentPack, IContentSource contentSource, ICoreTranslationHelper translationHelper, IEnumerable <ContentPackDataInfo> sources)
        {
            var objects = (from source in sources
                           from entry in source.Content.Objects
                           select new { Source = source, Name = entry.Key, Data = entry.Value }).ToArray();

            // Create exceptions for conflicting item names
            Exception[] exceptions = (from itemGroup in this.GetDuplicateGroups(objects, item => item.Name)
                                      select new Exception($"Object '{itemGroup.Key}' is being registered by multiple content files: {string.Join(", ", itemGroup.Select(item => $"'{item.Source.FullPath}'"))}")).ToArray();

            // Throw the exceptions
            if (exceptions.Any())
            {
                if (exceptions.Length > 1)
                {
                    throw new AggregateException(exceptions);
                }

                throw exceptions.First();
            }

            // Create each object
            foreach (var obj in objects)
            {
                ItemKey key = new ItemKey(contentPack.Manifest, obj.Name);

                // Create the sprite for the object
                ISprite sprite = this.CreateSprite(contentSource, obj.Source, obj.Name, obj.Data);
                if (obj.Data.Tint != Color.White)
                {
                    sprite = new TintedSprite(sprite, obj.Data.Tint);
                }

                // Create the object's manager
                Category   category = new Category(obj.Data.CategoryNumber, obj.Data.CategoryName);
                IModObject manager  = obj.Data.Buffs.HasValue.Match <bool, IModObject>()
                                      .When(true, () => new ModFood(translationHelper, sprite, key.LocalKey, obj.Data.Cost, obj.Data.Edibility, category, false, obj.Data.Buffs.Value))
                                      .When(false, () => new ModObject(translationHelper, sprite, key.LocalKey, obj.Data.Cost, category, obj.Data.Edibility))
                                      .ElseThrow();

                // Register the object
                this._api.Items.CommonRegistry.Objects.Register(key, manager);
                this._api.Owner.Monitor.Log($" - {key} registered (object)", LogLevel.Trace);
            }
        }
Exemple #8
0
 public void Setup(IModObject currentMod, ModScrollList currentScrollList)
 {
     item = currentMod;
     item.ModLoad();
     title.text       = item.Name;
     description.text = $"{item.Author}";
     version.text     = $"Version: {item.Version.ToString()}";
     icon.sprite      = item.Icon;
     scrollList       = currentScrollList;
     if (scrollList.isActiveList)
     {
         button.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = "-";
     }
     else
     {
         button.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = "+";
     }
 }
Exemple #9
0
        public void AssignID(IModObject mo, ICollection <string> used)
        {
            if (mo.ModID != null)
            {
                return;
            }
            lock (locker)
            {
                var fullname = mo.GetType().Name + " " + mo.Name;
                if (mo.Name != null && !used.Contains(fullname))
                {
                    mo.ModID = fullname;
                    used.Add(mo.ModID);
                }
                else
                {
                    // tack a number on
                    int    lastnum;
                    string name;
                    if (mo.Name == null)
                    {
                        name = "Generic " + mo.GetType().Name;
                    }
                    else
                    {
                        name = mo.GetType().Name + " " + mo.Name;
                    }
                    var lastword = name.LastWord();
                    if (int.TryParse(lastword, out lastnum))
                    {
                        // has a number, count from that number
                    }
                    else
                    {
                        lastnum = -1;                         // no number, start from 1
                    }
                    for (var num = lastnum + 1; num <= int.MaxValue; num++)
                    {
                        string exceptnum;
                        if (lastnum < 0 && num == 0)
                        {
                            exceptnum = name;
                            num       = 1;
                        }
                        else if (lastnum < 0)
                        {
                            exceptnum = name;
                        }
                        else
                        {
                            exceptnum = name.Substring(0, name.Length - lastword.Length - 1);
                        }
                        var withnextnum = exceptnum + " " + num;
                        if (!used.Contains(withnextnum))
                        {
                            mo.ModID = withnextnum;
                            used.Add(withnextnum);
                            break;
                        }
                        if (num == int.MaxValue)
                        {
                            throw new Exception("Can't assign mod ID to " + name + "; there's a gazillion other mod objects with that name.");
                        }
                    }
                }

                if (mo.ModID == null)
                {
                    throw new Exception("Failed to assign mod ID to {0}: {1}".F(mo.GetType(), mo));
                }

                objects[mo.ModID] = mo;
            }
        }
Exemple #10
0
 private void AddMod(IModObject mod, ModScrollList modList)
 {
     modList.modList.Add(mod);
 }