DB.gd 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. extends Object
  2. class_name DB
  3. static var MapsDB : Dictionary = {}
  4. static var MusicsDB : Dictionary = {}
  5. static var EthnicitiesDB : Dictionary = {}
  6. static var EntitiesDB : Dictionary = {}
  7. static var EmotesDB : Dictionary = {}
  8. static var ItemsDB : Dictionary = {}
  9. static var SkillsDB : Dictionary = {}
  10. static var hashDB : Dictionary = {}
  11. const UnknownHash : int = -1
  12. #
  13. static func ParseMapsDB():
  14. var result = FileSystem.LoadDB("maps.json")
  15. if not result.is_empty():
  16. for key in result:
  17. var map : MapData = MapData.new()
  18. map._name = key
  19. map._path = result[key].Path
  20. MapsDB[key] = map
  21. static func ParseMusicsDB():
  22. var result = FileSystem.LoadDB("musics.json")
  23. if not result.is_empty():
  24. for key in result:
  25. var music : MusicData = MusicData.new()
  26. music._name = key
  27. music._path = result[key].Path
  28. MusicsDB[key] = music
  29. static func ParseEthnicitiesDB():
  30. var result = FileSystem.LoadDB("ethnicities.json")
  31. if not result.is_empty():
  32. for key in result:
  33. var ethnicity : TraitData = TraitData.new()
  34. ethnicity._name = key
  35. ethnicity._path.append(result[key].Male)
  36. ethnicity._path.append(result[key].Female)
  37. ethnicity._path.append(result[key].Nonbinary)
  38. EthnicitiesDB[key] = ethnicity
  39. static func ParseEntitiesDB():
  40. var result = FileSystem.LoadDB("entities.json")
  41. if not result.is_empty():
  42. for key in result:
  43. EntitiesDB[key] = EntityData.Create(key, result[key])
  44. static func ParseEmotesDB():
  45. var result = FileSystem.LoadDB("emotes.json")
  46. if not result.is_empty():
  47. for key in result:
  48. var cell : BaseCell = FileSystem.LoadCell(Path.EmotePst + result[key].Path + Path.RscExt)
  49. cell.id = SetCellHash(cell.name)
  50. assert(EmotesDB.has(cell.id) == false, "Duplicated cell in EmotesDB")
  51. EmotesDB[cell.id] = cell
  52. static func ParseItemsDB():
  53. var result = FileSystem.LoadDB("items.json")
  54. if not result.is_empty():
  55. for key in result:
  56. var cell : BaseCell = FileSystem.LoadCell(Path.ItemPst + result[key].Path + Path.RscExt)
  57. cell.id = SetCellHash(cell.name)
  58. assert(ItemsDB.has(cell.id) == false, "Duplicated cell in ItemsDB")
  59. ItemsDB[cell.id] = cell
  60. static func ParseSkillsDB():
  61. var result = FileSystem.LoadDB("skills.json")
  62. if not result.is_empty():
  63. for key in result:
  64. var cell : BaseCell = FileSystem.LoadCell(Path.SkillPst + result[key].Path + Path.RscExt)
  65. cell.id = SetCellHash(cell.name)
  66. assert(SkillsDB.has(cell.id) == false, "Duplicated cell in SkillsDB")
  67. SkillsDB[cell.id] = cell
  68. #
  69. static func GetMapPath(mapName : String) -> String:
  70. var path : String = ""
  71. var mapInfo = null
  72. if MapsDB.has(mapName):
  73. mapInfo = MapsDB[mapName]
  74. assert(mapInfo != null, "Could not find the map " + mapName + " within the db")
  75. if mapInfo:
  76. path = mapInfo._path
  77. return path
  78. #
  79. static func HasCellHash(cellname : StringName) -> bool:
  80. return hashDB.has(cellname)
  81. static func SetCellHash(cellname : StringName) -> int:
  82. var cellHash : int = UnknownHash
  83. var hasHash : bool = HasCellHash(cellname)
  84. assert(not hasHash, "Cell hash %d already exists for %s" % [cellHash, cellname])
  85. if not hasHash:
  86. cellHash = cellname.hash()
  87. hashDB[cellname] = cellHash
  88. return cellHash
  89. static func GetCellHash(cellname : StringName) -> int:
  90. var hasHash : bool = HasCellHash(cellname)
  91. assert(hasHash, "Cell hash already exists for " + cellname)
  92. return hashDB[cellname] if hasHash else UnknownHash
  93. #
  94. static func GetItem(cellHash : int) -> BaseCell:
  95. assert(cellHash in ItemsDB, "Could not find the identifier %s in ItemsDB" % [cellHash])
  96. return ItemsDB[cellHash] if cellHash in ItemsDB else null
  97. static func GetEmote(cellHash : int) -> BaseCell:
  98. assert(cellHash in EmotesDB, "Could not find the identifier %s in EmotesDB" % [cellHash])
  99. return EmotesDB[cellHash] if cellHash in EmotesDB else null
  100. static func GetSkill(cellHash : int) -> SkillCell:
  101. assert(cellHash in SkillsDB, "Could not find the identifier %s in SkillsDB" % [cellHash])
  102. return SkillsDB[cellHash] if cellHash in SkillsDB else null
  103. #
  104. static func Init():
  105. ParseMapsDB()
  106. ParseMusicsDB()
  107. ParseEthnicitiesDB()
  108. ParseEmotesDB()
  109. ParseItemsDB()
  110. ParseSkillsDB()
  111. ParseEntitiesDB()