1
+ Import " Utility.bmx "
2
+
1
3
'//// SETTINGS MANAGER //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
4
3
- Global g_DefaultInputZoom:Int = 4
4
- Global g_DefaultOutputZoom:Int = 1
5
- Global g_DefaultFrameCount:Int = 7
6
5
Global g_DefaultBackgroundRed:Int = 50
7
6
Global g_DefaultBackgroundGreen:Int = 170
8
7
Global g_DefaultBackgroundBlue:Int = 255
8
+ Global g_DefaultInputZoom:Int = 4
9
+ Global g_DefaultOutputZoom:Int = 1
10
+ Global g_DefaultFrameCount:Int = 7
11
+ Global g_DefaultSaveAsFrames:Int = False
12
+ Global g_DefaultSaveAsIndexed:Int = False
9
13
Global g_DefaultIndexedFileType:String = " png"
10
14
11
15
Type SettingsManager
16
+
17
+ '////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18
+
19
+ Method New ()
20
+ ReadSettingsFile()
21
+ EndMethod
22
+
23
+ '////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24
+
25
+ Method ReadSettingsFile ()
26
+ Local inputStream:TStream = ReadStream(" BenderUserSettings.ini" )
27
+ If Not inputStream Then
28
+ 'Notify("No settings file found, using default settings!")
29
+ Return
30
+ EndIf
31
+
32
+ While Not inputStream.Eof()
33
+ Local line:String = ReadLine(inputStream)
34
+
35
+ 'Skip whitespace and comment lines
36
+ If line.Length = 0 Or line.Find(" //" ) = 0 Then
37
+ Continue
38
+ EndIf
39
+
40
+ Local propAndValue:String [] = line.Split(" =" )
41
+ propAndValue[ 0 ] = propAndValue[ 0 ] .Trim()
42
+ propAndValue[ 1 ] = propAndValue[ 1 ] .Trim()
43
+
44
+ Select propAndValue[ 0 ]
45
+ Case " BackgroundRed"
46
+ g_DefaultBackgroundRed = Utility.Clamp(propAndValue[ 1 ] .ToInt(), 0 , 255 )
47
+ Case " BackgroundGreen"
48
+ g_DefaultBackgroundGreen = Utility.Clamp(propAndValue[ 1 ] .ToInt(), 0 , 255 )
49
+ Case " BackgroundBlue"
50
+ g_DefaultBackgroundBlue = Utility.Clamp(propAndValue[ 1 ] .ToInt(), 0 , 255 )
51
+ Case " InputZoom"
52
+ g_DefaultInputZoom = Utility.Clamp(propAndValue[ 1 ] .ToInt(), 1 , DesktopWidth() - 260 )
53
+ Case " OutputZoom"
54
+ g_DefaultOutputZoom = Utility.Clamp(propAndValue[ 1 ] .ToInt(), 1 , 5 )
55
+ Case " FrameCount"
56
+ g_DefaultFrameCount = Utility.Clamp(propAndValue[ 1 ] .ToInt(), 1 , 20 )
57
+ Case " SaveAsFrames"
58
+ g_DefaultSaveAsFrames = Utility.Clamp(propAndValue[ 1 ] .ToInt(), False , True )
59
+ Case " SaveAsIndexed"
60
+ g_DefaultSaveAsIndexed = Utility.Clamp(propAndValue[ 1 ] .ToInt(), False , True )
61
+ Case " IndexedFileType"
62
+ propAndValue[ 1 ] = propAndValue[ 1 ] .ToLower()
63
+ If propAndValue[ 1 ] = " png" Or propAndValue[ 1 ] = " bmp" Then
64
+ g_DefaultIndexedFileType = propAndValue[ 1 ]
65
+ Else
66
+ Notify(" Invalid indexed file type set from settings, defaulting to PNG!" )
67
+ EndIf
68
+ EndSelect
69
+ EndWhile
70
+
71
+ CloseStream(inputStream)
72
+ EndMethod
73
+
74
+ '////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75
+
76
+ Method WriteSettingsFile (propertyValues:String [] )
77
+ Local outputString:TStringBuilder = New TStringBuilder (" // User Settings~n~n " )
78
+
79
+ outputString.Append(" BackgroundRed = " + propertyValues[ 0 ] + " ~n " )
80
+ outputString.Append(" BackgroundGreen = " + propertyValues[ 1 ] + " ~n " )
81
+ outputString.Append(" BackgroundBlue = " + propertyValues[ 2 ] + " ~n " )
82
+ outputString.Append(" InputZoom = " + propertyValues[ 3 ] + " ~n " )
83
+ outputString.Append(" OutputZoom = " + propertyValues[ 4 ] + " ~n " )
84
+ outputString.Append(" FrameCount = " + propertyValues[ 5 ] + " ~n " )
85
+ outputString.Append(" SaveAsFrames = " + propertyValues[ 6 ] + " ~n " )
86
+ outputString.Append(" SaveAsIndexed = " + propertyValues[ 7 ] + " ~n " )
87
+ outputString.Append(" IndexedFileType = " + propertyValues[ 8 ] .ToLower())
88
+
89
+ Local saveResult:Int = SaveText(outputString.ToString(), " BenderUserSettings.ini" )
90
+ If saveResult Then
91
+ Notify(" Settings file saved successfully!" )
92
+ Else
93
+ Notify(" Failed to save settings file!" , True )
94
+ EndIf
95
+ EndMethod
12
96
EndType
0 commit comments