-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gamesettings.CB
91 lines (81 loc) · 2.57 KB
/
Gamesettings.CB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/////Funktiot settingsien lukuun by Latexi95
Type MAIN_Settings
Field key$
Field value$
EndType
Function MAIN_ParseSettings(filePath$)
MAIN_ClearSettings()
file = OpenToRead(filePath$)
If file = 0 Then Return False
lineNum = 1
While Not EOF(file)
l$ = ReadLine(file)
notComment$ = Trim(GetWord(l$,1,"#"))
If notComment <> "" Then
If CountWords(notComment$,"=") < 2 Then
MakeError "Syntax error in file "+filePath$+" at line "+lineNum
EndIf
If CountWords(notComment$,"=") = 2 Then
newSetting.MAIN_Settings = New(MAIN_Settings)
newSetting\key$ = Lower(Trim(GetWord(notComment$,1,"=")))
newSetting\value$ = Trim(GetWord(notComment$,2,"="))
Else
place = InStr(notComment$,"=")
newSetting.MAIN_Settings = New(MAIN_Settings)
newSetting\key$ = Lower(Trim(Left(notComment$,place-1)))
newSetting\value$ = Trim(Mid(notComment,place+1))
EndIf
EndIf
lineNum + 1
Wend
CloseFile file
EndFunction
Function MAIN_SaveSettings(filePath$)
f = OpenToWrite(filePath$)
For setting.MAIN_Settings = Each MAIN_Settings
WriteLine f,setting\key$ + " = " + setting\value
Next setting
CloseFile f
EndFunction
Function MAIN_DeleteSetting(key$)
key$ = Lower(key$)
For setting.MAIN_Settings = Each MAIN_Settings
If setting\key$ = key Then
Delete setting
Return True
EndIf
Next setting
Return False
EndFunction
Function MAIN_GetSetting(key$)
key$ = Lower(key$)
For setting.MAIN_Settings = Each MAIN_Settings
If setting\key$ = key Then Return setting\value$
Next setting
Return ""
EndFunction
Function MAIN_HasSetting(key$)
key$ = Lower(key$)
For setting.MAIN_Settings = Each MAIN_Settings
If setting\key$ = key Then Return True
Next setting
Return False
EndFunction
Function MAIN_SetSetting(key$,value$)
key$ = Lower(key$)
For setting.MAIN_Settings = Each MAIN_Settings
If setting\key$ = key Then
setting\value = value
Return True
EndIf
Next setting
newSetting.MAIN_Settings = New(MAIN_Settings)
newSetting\key = key
newSetting\value = value
Return False
EndFunction
Function MAIN_ClearSettings()
For setting.MAIN_Settings = Each MAIN_Settings
Delete setting
Next setting
EndFunction