Exemple #1
0
 public static void FreeAllIDs()
 {
     foreach (var v in Registries)
     {
         v.UnRegisterAll(SRMod.GetCurrentMod());
     }
 }
Exemple #2
0
        public static Identifiable.Id CreateIdentifiableId(object value, string name, bool shouldCategorize = true)
        {
            if (SRModLoader.CurrentLoadingStep > SRModLoader.LoadingStep.PRELOAD)
            {
                throw new Exception("Can't register identifiables outside of the PreLoad step");
            }
            var id = (Identifiable.Id)value;

            if (moddedIdentifiables.ContainsKey(id))
            {
                throw new Exception(
                          $"Identifiable {value} is already registered to {moddedIdentifiables[id].ModInfo.Id}");
            }
            var sr = SRMod.GetCurrentMod();

            if (sr != null)
            {
                moddedIdentifiables[id] = sr;
            }
            EnumPatcher.AddEnumValue(typeof(Identifiable.Id), id, name);

            if (shouldCategorize)
            {
                CategorizeId(id);
            }
            return(id);
        }
        /// <summary>
        /// Register all <see cref="PlayerAction"/>'s in a Type
        /// </summary>
        /// <param name="type">Type holding the <see cref="PlayerAction"/>'s</param>
        public static void RegisterActions(Type type)
        {
            var mod = SRMod.GetCurrentMod();

            foreach (var field in type.GetFields().Where(x => x.IsStatic && typeof(PlayerAction).IsAssignableFrom(x.FieldType)))
            {
                PlayerActionCreateDelegate del = (set) =>
                {
                    var action = new PlayerAction(field.Name, set);
                    RegisterAction(action, mod);
                    field.SetValue(null, action);
                };

                switch (SRModLoader.CurrentLoadingStep)
                {
                case SRModLoader.LoadingStep.PRELOAD:
                    precreators.Add(del);
                    break;

                default:
                    del(SRInput.Actions);
                    break;
                }
            }
        }
Exemple #4
0
 public static void RegisterBasicTarget(Identifiable.Id id)
 {
     customBasicTarget.Add(id, SRMod.GetCurrentMod());
     foreach (var v in GetMetadatas())
     {
         v.targets = v.targets.AddToArray(new DroneMetadata.Program.Target.Basic(id));
     }
 }
Exemple #5
0
        /// <summary>
        /// Register a secret style in a <see cref="SlimeDefinition"/>
        /// </summary>
        /// <param name="definition">Slime definition to register the secret style for</param>
        /// <param name="exoticAppearance">Secret style to register</param>
        public static void RegisterSecretStyle(SlimeDefinition definition, SlimeAppearance exoticAppearance)
        {
            SecretStyle ss  = new SecretStyle(definition, exoticAppearance);
            SRMod       mod = SRMod.GetCurrentMod();

            if (secretStyles.ContainsKey(ss))
            {
                throw new Exception($"{definition.IdentifiableId} already has a secret style registered by {secretStyles[ss].ModInfo.Id}");
            }
            secretStyles[ss] = mod;
        }
Exemple #6
0
        /// <summary>
        /// Registers a new command into the console
        /// </summary>
        /// <param name="cmd">Command to register</param>
        /// <returns>True if registered succesfully, false otherwise</returns>
        public static bool RegisterCommand(ConsoleCommand cmd)
        {
            if (commands.ContainsKey(cmd.ID.ToLowerInvariant()))
            {
                LogWarning($"Trying to register command with id '<color=white>{cmd.ID.ToLowerInvariant()}</color>' but the ID is already registered!");
                return(false);
            }

            cmd.belongingMod = SRMod.GetCurrentMod();
            commands.Add(cmd.ID.ToLowerInvariant(), cmd);
            ConsoleWindow.cmdsText += $"{(ConsoleWindow.cmdsText.Equals(string.Empty) ? "" : "\n")}<color=#77DDFF>{ColorUsage(cmd.Usage)}</color> - {cmd.Description}";
            return(true);
        }
Exemple #7
0
        public T RegisterValue(T id)
        {
            if (ContainsKey(id))
            {
                throw new Exception(
                          $"{id} is already registered to {this[id].ModInfo.Id}");
            }
            var sr = SRMod.GetCurrentMod();

            if (sr != null)
            {
                this[id] = sr;
            }
            return(id);
        }
Exemple #8
0
        /// <summary>
        /// Register a slime definition in the <see cref="SlimeDefinitions"/> database
        /// </summary>
        /// <param name="definition">Slime definition to register</param>
        public static void RegisterSlimeDefinition(SlimeDefinition definition, bool refreshEatMaps = true)
        {
            slimeDefinitions[definition] = SRMod.GetCurrentMod();
            SlimeDefinitions definitions;

            switch (SRModLoader.CurrentLoadingStep)
            {
            case SRModLoader.LoadingStep.PRELOAD:
                definitions = UnityEngine.Object.FindObjectOfType <GameContext>().SlimeDefinitions;
                break;

            default:
                definitions = GameContext.Instance.SlimeDefinitions;
                break;
            }
            if (definition.IsLargo && definition.BaseSlimes != null && definition.BaseSlimes.Length == 2 && definition.BaseSlimes[0].Diet.ProducePlorts() && definition.BaseSlimes[1].Diet.ProducePlorts())
            {
                SlimeDefinitions.PlortPair pair = new SlimeDefinitions.PlortPair(definition.BaseSlimes[0].Diet.Produces[0], definition.BaseSlimes[1].Diet.Produces[0]);
                definitions.largoDefinitionByBasePlorts = definitions.largoDefinitionByBasePlorts.Where(x => !x.Key.Equals(pair)).ToDictionary(x => x.Key, y => y.Value);
                definitions.largoDefinitionByBasePlorts.Add(pair, definition);
            }
            if (definition.IsLargo && definition.BaseSlimes != null && definition.BaseSlimes.Length == 2)
            {
                SlimeDefinitions.SlimeDefinitionPair pair = new SlimeDefinitions.SlimeDefinitionPair(definition.BaseSlimes[0], definition.BaseSlimes[1]);
                definitions.largoDefinitionByBaseDefinitions = definitions.largoDefinitionByBaseDefinitions.Where(x => !x.Key.Equals(pair)).ToDictionary(x => x.Key, y => y.Value);
                definitions.largoDefinitionByBaseDefinitions.Add(pair, definition);
            }
            definitions.slimeDefinitionsByIdentifiable.Add(definition.IdentifiableId, definition);
            definitions.Slimes = definitions.Slimes.Where(x => x.IdentifiableId != definition.IdentifiableId).ToArray();
            definitions.Slimes = definitions.Slimes.AddToArray(definition);
            if (refreshEatMaps)
            {
                definition.Diet.RefreshEatMap(definitions, definition);
                if (definition.BaseSlimes != null)
                {
                    foreach (SlimeDefinition child in definition.BaseSlimes)
                    {
                        child.Diet.RefreshEatMap(definitions, child);
                    }
                }
            }
        }
        /// <summary>
        /// Register a slime definition in the <see cref="SlimeDefinitions"/> database
        /// </summary>
        /// <param name="definition">Slime definition to register</param>
        public static void RegisterSlimeDefinition(SlimeDefinition definition)
        {
            slimeDefinitions[definition] = SRMod.GetCurrentMod();
            SlimeDefinitions definitions;

            switch (SRModLoader.CurrentLoadingStep)
            {
            case SRModLoader.LoadingStep.PRELOAD:
                definitions = UnityEngine.Object.FindObjectOfType <GameContext>().SlimeDefinitions;
                break;

            default:
                definitions = GameContext.Instance.SlimeDefinitions;
                break;
            }
            definitions.largoDefinitionByBasePlorts.Clear();
            definitions.largoDefinitionByBaseDefinitions.Clear();
            definitions.slimeDefinitionsByIdentifiable.Clear();
            definitions.Slimes = definitions.Slimes.Where(x => x.IdentifiableId != definition.IdentifiableId).ToArray();
            definitions.Slimes = definitions.Slimes.AddToArray(definition);
            definitions.OnEnable();
        }
        public static PlayerState.Upgrade CreatePersonalUpgrade(object value, string name)
        {
            if (SRModLoader.CurrentLoadingStep > SRModLoader.LoadingStep.PRELOAD)
            {
                throw new Exception("Can't register gadgets outside of the PreLoad step");
            }
            var id = (PlayerState.Upgrade)value;

            if (moddedUpgrades.ContainsKey(id))
            {
                throw new Exception(
                          $"Upgrade {value} is already registered to {moddedUpgrades[id].ModInfo.Id}");
            }
            var sr = SRMod.GetCurrentMod();

            if (sr != null)
            {
                moddedUpgrades[id] = sr;
            }
            EnumPatcher.AddEnumValue(typeof(PlayerState.Upgrade), id, name);
            return(id);
        }
Exemple #11
0
 public static void RegisterOfferID(string id)
 {
     customOfferIDs.Add(id, SRMod.GetCurrentMod());
 }
Exemple #12
0
 public static void RegisterWorldDataLoadDelegate(WorldDataLoadDelegate del)
 {
     GetSaveInfo(SRMod.GetCurrentMod()).OnDataLoad += del;
 }
Exemple #13
0
 public static string ClaimID(string prefix, string id)
 {
     return(ClaimID(prefix, SRMod.GetCurrentMod(), id));
 }
Exemple #14
0
 public static void RegisterRancher(string id)
 {
     customRanchers.Add(id, SRMod.GetCurrentMod());
 }
Exemple #15
0
 public static void FreeID(string prefix, string id)
 {
     GetRegistry(prefix).UnRegisterID(id, SRMod.GetCurrentMod());
 }
Exemple #16
0
 public static CompoundDataPiece GetWorldSaveData()
 {
     return(worldSaveData.Get(SRMod.GetCurrentMod()));
 }
Exemple #17
0
        internal static CompoundDataPiece GetDataForCurrentMod(CompoundDataPiece piece)
        {
            var strin = SRMod.GetCurrentMod().ModInfo.Id;

            return(ExtendedDataUtils.GetPieceForMod(strin, piece));
        }
Exemple #18
0
 public static void FreeAllIDs(string prefix)
 {
     GetRegistry(prefix).UnRegisterAll(SRMod.GetCurrentMod());
 }
Exemple #19
0
 internal static ModSaveInfo GetSaveInfo()
 {
     return(GetSaveInfo(SRMod.GetCurrentMod()));
 }
Exemple #20
0
 /// <summary>
 /// Add a plaintext translation for a localization key
 /// </summary>
 /// <param name="bundlename">Key bundle the localization key is located in</param>
 /// <param name="key">The localization key</param>
 /// <param name="value">The plain text translation</param>
 public static void AddTranslationKey(string bundlename, string key, string value) => AddTranslationKey(bundlename, key, value, SRMod.GetCurrentMod());
Exemple #21
0
 public static void RegisterPediaTab(PediaTab tab)
 {
     customTabs.Add(tab, SRMod.GetCurrentMod());
 }