Update Server.pb, Object.pbi, kidney.ini, and 3 more files
This commit is contained in:
+49
-3
@@ -2,19 +2,65 @@
|
||||
;- Compiler Directives
|
||||
EnableExplicit
|
||||
|
||||
|
||||
XIncludeFile "../Commons/HashMap/HashMap.pbi"
|
||||
;XIncludeFile "../Commons/HashMap/HashMap.pbi"
|
||||
XIncludeFile "./test/Object.pbi"
|
||||
|
||||
|
||||
#DefsFolder = "C:\Users\Herwin\Desktop\Projects\Yass13"
|
||||
|
||||
|
||||
;- Tests
|
||||
|
||||
; Parses every definition file in the given folder, returns #False if any of them failed.
|
||||
Procedure.b Test_ParseDefsFolder(Folder.s)
|
||||
Protected Directory.i
|
||||
Protected FilePath.s
|
||||
Protected *Object.YassObject
|
||||
Protected Success.b = #True
|
||||
|
||||
Directory = ExamineDirectory(#PB_Any, Folder, "*.ini")
|
||||
If Not Directory
|
||||
PrintN("FAIL: Can't examine folder: " + Folder)
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
While NextDirectoryEntry(Directory)
|
||||
If DirectoryEntryType(Directory) <> #PB_DirectoryEntry_File
|
||||
Continue
|
||||
EndIf
|
||||
|
||||
FilePath = Folder + DirectoryEntryName(Directory)
|
||||
*Object = FromDefinitionFile(FilePath)
|
||||
|
||||
If *Object = #Null
|
||||
PrintN("FAIL: " + FilePath)
|
||||
Success = #False
|
||||
Else
|
||||
PrintN("OK: " + FilePath + " -> '" + *Object\Id + "' (" + *Object\Type + ")")
|
||||
FreeYassObject(*Object)
|
||||
EndIf
|
||||
Wend
|
||||
|
||||
FinishDirectory(Directory)
|
||||
ProcedureReturn Success
|
||||
EndProcedure
|
||||
|
||||
|
||||
;- Entry Point
|
||||
|
||||
If Not OpenConsole("YASS13")
|
||||
DebuggerError("Failed to open console !")
|
||||
End 1
|
||||
EndIf
|
||||
|
||||
Define TestsPassed.b = #True
|
||||
If Not Test_ParseDefsFolder(#DefsFolder + "\defs\items\") : TestsPassed = #False : EndIf
|
||||
If Not Test_ParseDefsFolder(#DefsFolder + "\defs\reagents\") : TestsPassed = #False : EndIf
|
||||
|
||||
|
||||
If Not TestsPassed
|
||||
DebuggerError("Definition parsing tests failed !")
|
||||
End 1
|
||||
EndIf
|
||||
|
||||
|
||||
Debug "Done :)"
|
||||
|
||||
@@ -1,9 +1,72 @@
|
||||
|
||||
|
||||
XIncludeFile "../../Commons/HashMap/HashMap.pbi"
|
||||
|
||||
Structure YassObject
|
||||
|
||||
id.s
|
||||
Id.s
|
||||
Type.s
|
||||
|
||||
EndStructure
|
||||
|
||||
Macro YassObjectPtr : i : EndMacro
|
||||
|
||||
; Returns the raw value with its surrounding double quotes removed.
|
||||
Procedure.s UnquoteValue(Value.s)
|
||||
ProcedureReturn Trim(Trim(Value), #DQUOTE$)
|
||||
EndProcedure
|
||||
|
||||
Procedure FreeYassObject(*Object.YassObject)
|
||||
FreeStructure(*Object)
|
||||
EndProcedure
|
||||
|
||||
; Returns a newly allocated YassObject, or #Null if the file can't be opened or lacks core values.
|
||||
; The caller owns the returned object and must free it with FreeYassObject().
|
||||
Procedure.YassObjectPtr FromDefinitionFile(DefFilePath.s)
|
||||
Protected *Object.YassObject
|
||||
|
||||
; 1. Load Ini
|
||||
If Not OpenPreferences(DefFilePath)
|
||||
Debug "Failed to open definition file: " + DefFilePath
|
||||
ProcedureReturn #Null
|
||||
EndIf
|
||||
|
||||
; 2. Read "Object" group
|
||||
If Not PreferenceGroup("Object")
|
||||
Debug "Missing [Object] group in: " + DefFilePath
|
||||
ClosePreferences()
|
||||
ProcedureReturn #Null
|
||||
EndIf
|
||||
|
||||
; 3. Read core values
|
||||
*Object = AllocateStructure(YassObject)
|
||||
*Object\Id = UnquoteValue(ReadPreferenceString("id", ""))
|
||||
*Object\Type = UnquoteValue(ReadPreferenceString("type", ""))
|
||||
|
||||
If *Object\Id = "" Or *Object\Type = ""
|
||||
Debug "Missing 'id' or 'type' in: " + DefFilePath
|
||||
FreeYassObject(*Object)
|
||||
ClosePreferences()
|
||||
ProcedureReturn #Null
|
||||
EndIf
|
||||
|
||||
; 4. For each other group, iterate
|
||||
ExaminePreferenceGroups()
|
||||
While NextPreferenceGroup()
|
||||
If PreferenceGroupName() = "Object"
|
||||
Continue
|
||||
EndIf
|
||||
|
||||
; 4.1 For each value, Debug it
|
||||
ExaminePreferenceKeys()
|
||||
While NextPreferenceKey()
|
||||
If Left(PreferenceKeyName(), 1) = "#"
|
||||
Continue
|
||||
EndIf
|
||||
Debug PreferenceKeyName() + " = " + UnquoteValue(PreferenceKeyValue())
|
||||
Wend
|
||||
Wend
|
||||
|
||||
ClosePreferences()
|
||||
ProcedureReturn *Object
|
||||
EndProcedure
|
||||
|
||||
Reference in New Issue
Block a user