User Tools

Site Tools


api:umfconfig:parser_umfconfigfloat

Description:
Default float parser.

Added In: v0.45

Function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
public class UMFConfigFloat : UMFConfigParser<float>
{
    public float DefaultValue;
    public float MinValue;
    public float MaxValue;
    public int Decimals;
    public float VanillaValue;
    public bool RequiresRestart;
    public float[] AllowedValues;
 
    public UMFConfigFloat(float defaultValue = default(float), float minValue = default(float), float maxValue = default(float), int decimals = 1, float vanillaValue = default(float), bool requiresRestart = false, params float[] allowedValues)
    {
        DefaultValue = defaultValue;
        MinValue = Math.Min(minValue, maxValue);
        MaxValue = Math.Max(minValue, maxValue);
        Decimals = decimals;
        VanillaValue = vanillaValue;
        RequiresRestart = requiresRestart;
        AllowedValues = allowedValues;
    }
 
    public override float Parse(string value)
    {
        if (!float.TryParse(value, out float result)) result = DefaultValue;
        return result;
    }
 
    public override string ToString()
    {
        return DefaultValue.ToString();
    }
 
    public override string Default()
    {
        return DefaultValue.ToString();
    }
 
    public override string Range()
    {
        return (MaxValue != default(float) ? MinValue.ToString() + "," + MaxValue.ToString() + "," + Decimals.ToString() : null);
    }
 
    public override string Vanilla()
    {
        return (VanillaValue != default(float) ? VanillaValue.ToString() : null);
    }
 
    public override string Allowed()
    {
        return (AllowedValues.Length > 0 ? string.Join(",", AllowedValues.Select(x => x.ToString()).ToArray()) : null);
    }
 
    public override string Restart()
    {
        return RequiresRestart.ToString();
    }
}



Usage

1
//Coming soon



Examples

1
//Coming soon


This topic does not exist yet

You've followed a link to a topic that doesn't exist yet. If permissions allow, you may create it by clicking on Create this page.

api/umfconfig/parser_umfconfigfloat.txt · Last modified: 2019/06/29 23:37 by umfdev