-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIncludesUpdater.pb
113 lines (95 loc) · 3.17 KB
/
IncludesUpdater.pb
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Enumeration
#TYPE_EVENTS
#TYPE_FUNCTIONS
#TYPE_PLAYERCOMMANDS
EndEnumeration
Global serverBasePath$ = GetPathPart(ProgramFilename()) + "..\"
Global NewList Events.s()
Global NewList Includes.s()
Global NewList PlayerCommands.s()
Procedure addIncludes(type)
Select type
Case #TYPE_EVENTS
directoryName$ = "events"
Case #TYPE_FUNCTIONS
directoryName$ = "functions"
Case #TYPE_PLAYERCOMMANDS
directoryName$ = "commands"
EndSelect
dir = ExamineDirectory(#PB_Any, serverBasePath$ + "scripts\" + directoryName$, "*.nut")
If IsDirectory(dir)
While NextDirectoryEntry(dir)
name$ = DirectoryEntryName(dir)
If DirectoryEntryType(dir) = #PB_DirectoryEntry_File
name$ = Left(name$, Len(name$) - 4)
Select type
Case #TYPE_EVENTS
AddElement(Includes())
Includes() = directoryName$ + "/" + name$
AddElement(Events())
Events() = name$
Case #TYPE_FUNCTIONS
AddElement(Includes())
Includes() = directoryName$ + "/" + name$
Case #TYPE_PLAYERCOMMANDS
AddElement(PlayerCommands())
PlayerCommands() = name$
EndSelect
EndIf
Wend
FinishDirectory(dir)
EndIf
EndProcedure
Procedure writeFileHeader(file)
WriteStringN(file, "// Do not edit this file!")
WriteStringN(file, "// Run " + GetFilePart(ProgramFilename()) + " from tools directory to update.")
WriteStringN(file, "")
EndProcedure
addIncludes(#TYPE_PLAYERCOMMANDS)
file = CreateFile(#PB_Any, serverBasePath$ + "scripts\events\playerCommand.nut")
If IsFile(file)
writeFileHeader(file)
WriteStringN(file, "function onPlayerCommand(playerId, command)")
WriteStringN(file, "{")
WriteStringN(file, Chr(9) + "switch (command.slice(1))")
WriteStringN(file, Chr(9) + "{")
ForEach PlayerCommands()
If PlayerCommands() <> "default"
WriteStringN(file, Chr(9) + Chr(9) + "case " + Chr(34) + PlayerCommands() + Chr(34)+ ":")
WriteStringN(file, Chr(9) + Chr(9) + Chr(9) + "dofile(" + Chr(34) + "scripts/commands/" + PlayerCommands() + ".nut" + Chr(34) + ");")
WriteStringN(file, Chr(9) + Chr(9) + Chr(9) + "break;")
EndIf
Next
WriteStringN(file, Chr(9) + Chr(9) + "default:")
WriteStringN(file, Chr(9) + Chr(9) + Chr(9) + "dofile(" + Chr(34) + "scripts/commands/default.nut" + Chr(34) + ");")
WriteStringN(file, Chr(9) + Chr(9) + Chr(9) + "return false;")
WriteStringN(file, Chr(9) + "}")
WriteStringN(file, Chr(9) + "return true;")
WriteStringN(file, "}")
CloseFile(file)
EndIf
addIncludes(#TYPE_EVENTS)
addIncludes(#TYPE_FUNCTIONS)
file = CreateFile(#PB_Any, serverBasePath$ + "scripts\includes.nut")
If IsFile(file)
writeFileHeader(file)
WriteStringN(file, "// Includes")
ForEach Includes()
WriteStringN(file, "dofile(" + Chr(34) + "scripts/" + Includes() + ".nut" + Chr(34) + ");")
Next
WriteStringN(file, "")
WriteStringN(file, "// Events")
ForEach Events()
WriteStringN(file, "addEvent(" + Chr(34) + Events() + Chr(34) + ", " + "on" + UCase(Mid(Events(), 1, 1)) + Mid(Events(), 2) + ");")
Next
CloseFile(file)
EndIf
; IDE Options = PureBasic 5.11 (Windows - x86)
; CursorPosition = 68
; FirstLine = 48
; Folding = -
; EnableXP
; Executable = IncludesUpdater.exe
; EnableCompileCount = 14
; EnableBuildCount = 13
; EnableExeConstant