コード例 #1
0
        private void TryLoadingGMCM()
        {
            //See if we can find GMCM, quit if not.
            var api = Helper.ModRegistry.GetApi <GenericModConfigMenu.GenericModConfigMenuAPI>("spacechase0.GenericModConfigMenu");

            if (api == null)
            {
                Monitor.Log("Unable to load GMCM API.", LogLevel.Info);
                return;
            }

            WateringPattern dp = new WateringPattern(); //Just need this to refer to a thing

            string[] pattypes = dp.GetPatternTypes();

            api.RegisterModConfig(ModManifest, () => myConfig = new BasicSprinklerConfig(), () => Helper.WriteConfig(myConfig));

            //Pattern types
            api.RegisterChoiceOption(ModManifest, "Watering Pattern", "Which watering pattern to use. Set to 'custom' (it's in the dropdown, but might not be immediately visible) to set a custom area using the controls below. Otherwise they are ignored.", () => myConfig.patternType, (string val) => myConfig.patternType = val, pattypes);
            api.RegisterLabel(ModManifest, "Sum of custom values must not exceed 4.", "The improved basic sprinkler will have the same watering area as the default. Values entered here when custom pattern is selected will throw an error if they add up to more than 4. The game will then use the default pattern.");
            api.RegisterClampedOption(ModManifest, "Custom North Area", "How far north the sprinkler should water.", () => myConfig.northArea, (int val) => myConfig.northArea = val, 0, 4);
            api.RegisterClampedOption(ModManifest, "Custom South Area", "How far south the sprinkler should water.", () => myConfig.southArea, (int val) => myConfig.southArea = val, 0, 4);
            api.RegisterClampedOption(ModManifest, "Custom East Area", "How far east the sprinkler should water.", () => myConfig.eastArea, (int val) => myConfig.eastArea     = val, 0, 4);
            api.RegisterClampedOption(ModManifest, "Custom West Area", "How far west the sprinkler should water.", () => myConfig.westArea, (int val) => myConfig.westArea     = val, 0, 4);
        }
コード例 #2
0
        WateringPattern LoadPatternFromConfig(BasicSprinklerConfig config)
        {
            WateringPattern result;

            if (config == null)
            {
                Monitor.Log($"Tried to load nonexistent config...", LogLevel.Error);
                noProb = false;
                return(null);
            }

            string type = config.patternType;

            int[] dims = new int[4] {
                config.northArea, config.southArea, config.eastArea, config.westArea
            };
            result = new WateringPattern(type, dims);

            if (result.errorMsg != "")
            {
                Monitor.Log($"Error in current pattern: {result.errorMsg}", LogLevel.Warn);
                noProb = false;
            }

            return(result);
        }
コード例 #3
0
        void LoadConfigsFromFile(string fileName = "", WateringPattern toSet = null)
        {
            BasicSprinklerConfig tempConfig;
            string loadedName;

            //default config - what we're actually using.
            if (fileName == "")
            {
                Monitor.Log("Loading pattern from default config file.");
                myConfig = this.Helper.ReadConfig <BasicSprinklerConfig>();
            }
            //custom file
            else
            {
                Monitor.Log($"Loading pattern from config file: '{fileName}'");
                tempConfig = this.Helper.Data.ReadJsonFile <BasicSprinklerConfig>(fileName);
                loadedName = fileName;

                if (tempConfig != null && toSet != null)
                {
                    Monitor.Log("Configuration loaded correctly.");
                    toSet = LoadPatternFromConfig(tempConfig);

                    if (toSet == null)
                    {
                        Monitor.Log($"No pattern could be loaded from file: '{loadedName}'; may be saved & loaded later.");
                    }
                    else if (toSet.errorMsg != "")
                    {
                        Monitor.Log($"Error in setting pattern: {toSet.errorMsg}");
                    }
                    else
                    {
                        Monitor.Log($"Result = {toSet}");
                    }
                }
                else
                {
                    Monitor.Log($"Could not load from file '{loadedName}', did you pass a valid pattern to set?");
                }
            }
        }