Esempio n. 1
0
 private static bool TryGetSavedBinaryValue <T>(IHasModSettings mod, IModSetting <T> setting, out T value) where T : IEquatable <T>
 {
     if (deserializedBinary.TryGetValue(mod.FactorioVersion, out var settings))
     {
         return(settings.TryGetValue(setting, out value));
     }
     else
     {
         value = default(T);
         return(false);
     }
 }
Esempio n. 2
0
        public void AddSetting(IModSetting setting)
        {
            var template = setting.CreateValueTemplate();

            switch (setting.LoadTime)
            {
            case LoadTime.Startup:
                StartupTemplates[setting.Name] = template;
                break;

            case LoadTime.RuntimeGlobal:
                RuntimeGlobalTemplates[setting.Name] = template;
                break;

            case LoadTime.RuntimeUser:
                RuntimeUserTemplates[setting.Name] = template;
                break;
            }
        }
Esempio n. 3
0
        public void AddSetting <T>(IModSetting <T> setting) where T : IEquatable <T>
        {
            var template = new ModSettingValueTemplate(setting.Value);

            switch (setting.LoadTime)
            {
            case LoadTime.Startup:
                StartupTemplates[setting.Name] = template;
                break;

            case LoadTime.RuntimeGlobal:
                RuntimeGlobalTemplates[setting.Name] = template;
                break;

            case LoadTime.RuntimeUser:
                RuntimeUserTemplates[setting.Name] = template;
                break;
            }
        }
Esempio n. 4
0
        public static bool TryGetSavedValue <T>(IHasModSettings mod, IModSetting <T> setting, out T value) where T : IEquatable <T>
        {
            if (mod.UseBinaryFileOverride && TryGetSavedBinaryValue(mod, setting, out value))
            {
                return(true);
            }

            bool result = modSettings.TryGetValue(mod.UniqueID, out var settings);

            if (result)
            {
                return(settings.TryGetValue(setting, out value));
            }
            else
            {
                value = default(T);
                return(false);
            }
        }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        if (Active)
        {
            switch (Mode)
            {
            case GravityMode.Global:
                Physics.gravity = GravityVector;     // set the global gravity to our gravity
                break;

            case GravityMode.Relative:
                Physics.gravity = Quaternion.Euler(ServiceProvider.Instance.PlayerAircraft.MainCockpitRotation) * GravityVector;     // set the global gravity to our gravity, relative to the main cockpit
                break;
            }
        }
        else if (LastActive)
        {   // make sure gravity is normal when this mod is disabled
            Physics.gravity = new Vector3(0.0f, -9.81f, 0.0f);
        }
        LastActive = Active;
        if (!ModSettingsHandler.ModSettingsReady)
        {   // if the mod settings aren't ready to generate settings, wait
            return;
        }
        if (SettingsPage == null || SettingsPage.Equals(null))
        {                                                                                                                                            // if we have no settings page
            SettingsPage       = ModSettingsHandler.AddSettingsPage("AdjustableGravity", "Adjustable Gravity", "Setting for the global gravity");    // generate page
            ActiveSetting      = ModSettingsHandler.AddSettingToPage(SettingsPage, "Active", "Mod Active", ModSettingTypes.Toggle, true.ToString()); // and settings
            GravitySetting     = ModSettingsHandler.AddSettingToPage(SettingsPage, "Gravity", "Gravity", ModSettingTypes.Vector3, new Vector3(0.0f, -9.81f, 0.0f).ToStringCompact());
            GravityModeSetting = ModSettingsHandler.AddSettingToPage(SettingsPage, "GravityMode", "Gravity Mode", ModSettingTypes.Dropdown, "0", GravityMode.Global.ToString(), GravityMode.Relative.ToString());
            SettingsPage.LoadSettings();                                                  // load saved settings (if they've been saved before, otherwise defaults)
            bool.TryParse(ActiveSetting.Value, out Active);                               // parse active
            ModSettingConverter.Vector3TryParse(GravitySetting.Value, ref GravityVector); // parse the GravitySetting out to our GravityVector
            int GMode = 0;
            int.TryParse(GravityModeSetting.Value, out GMode);
            Mode = (GravityMode)GMode;
        }
    }
Esempio n. 6
0
        public bool TryGetValue <T>(IModSetting <T> setting, out T value) where T : IEquatable <T>
        {
            Dictionary <string, ModSettingValueTemplate> dict;

            switch (setting.LoadTime)
            {
            case LoadTime.Startup:
                dict = StartupTemplates;
                break;

            case LoadTime.RuntimeGlobal:
                dict = RuntimeGlobalTemplates;
                break;

            case LoadTime.RuntimeUser:
                dict = RuntimeUserTemplates;
                break;

            default:
                value = default(T);
                return(false);
            }

            bool hasValue = dict.TryGetValue(setting.Name, out var template);

            if (hasValue && (template != null))
            {
                value = template.GetValue <T>();
                return(true);
            }
            else
            {
                value = default(T);
                return(false);
            }
        }
Esempio n. 7
0
            private bool TryConvert(Dictionary <string, DynValue> dict, IHasModSettings owner, out IModSetting result)
            {
                result = null;

                if (!dict.TryGetValue("type", out var typeDyn))
                {
                    return(false);
                }
                if ((typeDyn.Type != DataType.String) || !settingTypeMapping.TryGetValue(typeDyn.String, out var type))
                {
                    return(false);
                }

                if (!dict.TryGetValue("name", out var nameDyn))
                {
                    return(false);
                }
                if (nameDyn.Type != DataType.String)
                {
                    return(false);
                }
                string name = nameDyn.String;

                if (!dict.TryGetValue("setting_type", out var loadTimeDyn))
                {
                    return(false);
                }
                if ((loadTimeDyn.Type != DataType.String) || !loadTimeMapping.TryGetValue(loadTimeDyn.String, out var loadTime))
                {
                    return(false);
                }

                string ordering = string.Empty;

                if (dict.TryGetValue("order", out var orderingDyn) && (orderingDyn.Type == DataType.String))
                {
                    ordering = orderingDyn.String;
                }

                bool hasDefaultValue = dict.TryGetValue("default_value", out var defaultValueDyn);

                bool isList = dict.TryGetValue("allowed_values", out var allowedValuesDyn);

                if (isList && (allowedValuesDyn.Type != DataType.Table))
                {
                    return(false);
                }

                if (isList)
                {
                    var allowedValuesListDyn = allowedValuesDyn.Table.Values;

                    switch (type)
                    {
                    case SettingType.Boolean:
                        return(false);

                    case SettingType.Integer:
                        if (hasDefaultValue && (defaultValueDyn.Type != DataType.Number))
                        {
                            return(false);
                        }
                        if (!TryConvertNumberTable(allowedValuesListDyn, out var allowedIntValues))
                        {
                            return(false);
                        }
                        result = new IntegerListModSetting(owner, name, loadTime, ordering, hasDefaultValue ? (long)defaultValueDyn.Number : 0, allowedIntValues.Select(value => (long)value));
                        break;

                    case SettingType.FloatingPoint:
                        if (hasDefaultValue && (defaultValueDyn.Type != DataType.Number))
                        {
                            return(false);
                        }
                        if (!TryConvertNumberTable(allowedValuesListDyn, out var allowedFloatValues))
                        {
                            return(false);
                        }
                        result = new FloatingPointListModSetting(owner, name, loadTime, ordering, hasDefaultValue ? (decimal)defaultValueDyn.Number : 0, allowedFloatValues);
                        break;

                    case SettingType.String:
                        if (hasDefaultValue && (defaultValueDyn.Type != DataType.String))
                        {
                            return(false);
                        }
                        if (!TryConvertStringTable(allowedValuesListDyn, out var allowedStringValues))
                        {
                            return(false);
                        }
                        result = new StringListModSetting(owner, name, loadTime, ordering, hasDefaultValue ? defaultValueDyn.String : string.Empty, allowedStringValues);
                        break;
                    }
                }
                else
                {
                    bool hasMinValue = dict.TryGetValue("minimum_value", out var minValueDyn);
                    if (hasMinValue && (minValueDyn.Type != DataType.Number))
                    {
                        return(false);
                    }

                    bool hasMaxValue = dict.TryGetValue("maximum_value", out var maxValueDyn);
                    if (hasMaxValue && (maxValueDyn.Type != DataType.Number))
                    {
                        return(false);
                    }

                    switch (type)
                    {
                    case SettingType.Boolean:
                        if (hasDefaultValue && (defaultValueDyn.Type != DataType.Boolean))
                        {
                            return(false);
                        }
                        result = new BooleanModSetting(owner, name, loadTime, ordering, hasDefaultValue ? defaultValueDyn.Boolean : false);
                        break;

                    case SettingType.Integer:
                        if (hasDefaultValue && (defaultValueDyn.Type != DataType.Number))
                        {
                            return(false);
                        }
                        result = new IntegerModSetting(owner, name, loadTime, ordering, hasDefaultValue ? (long)defaultValueDyn.Number : 0, hasMinValue ? (long)minValueDyn.Number : long.MinValue, hasMaxValue ? (long)maxValueDyn.Number : long.MaxValue);
                        break;

                    case SettingType.FloatingPoint:
                        if (hasDefaultValue && (defaultValueDyn.Type != DataType.Number))
                        {
                            return(false);
                        }
                        result = new FloatingPointModSetting(owner, name, loadTime, ordering, hasDefaultValue ? (decimal)defaultValueDyn.Number : 0, hasMinValue ? (decimal)minValueDyn.Number : decimal.MinValue, hasMaxValue ? (decimal)maxValueDyn.Number : decimal.MaxValue);
                        break;

                    case SettingType.String:
                        if (hasDefaultValue && (defaultValueDyn.Type != DataType.String))
                        {
                            return(false);
                        }
                        bool allowEmptyValue = false;
                        if (dict.TryGetValue("allow_blank", out var allowEmptyValueDyn) && (allowEmptyValueDyn.Type == DataType.Boolean))
                        {
                            allowEmptyValue = allowEmptyValueDyn.Boolean;
                        }
                        result = new StringModSetting(owner, name, loadTime, ordering, hasDefaultValue ? defaultValueDyn.String : string.Empty, allowEmptyValue);
                        break;
                    }
                }

                return(true);
            }
Esempio n. 8
0
 public void RemoveModSetting(IModSetting setting) => this.modSettings.Remove(setting);
Esempio n. 9
0
 public void AddModSetting(IModSetting setting) => this.modSettings.Add(setting);
Esempio n. 10
0
 public ResourcePackGenerator(ITextureProviderSystemAndUser textureProvider, IModSetting setting)
 {
     this.textureProvider = textureProvider;
     this.setting         = setting;
 }