Skip to content

Commit

Permalink
DataChecker.py checks for structures placement and displays amount of…
Browse files Browse the repository at this point in the history
… possible errors found.
  • Loading branch information
ThomasQTruong committed Oct 25, 2023
1 parent 8f84b38 commit e6159f3
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions DataChecker.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
import os, json
"""DataChecker.py
def main():
# Directory to read data files from.
DATA_DIR = "./CobblemonData/"
Used to check possible errors in data files.
"""

# Gets and sorts directory.
sortedDirectory = sorted(os.listdir(DATA_DIR))
import os
import sys
import json


# Directory to read data files from.
DATA_DIR = "./CobblemonData/"

# All of the possible conditions in pData["spawns"]["conditions"]
possible_conditions = ["dimensions", "biomes", "moonPhase", "canSeeSky", "minX", "minY", "minZ", "maxX",
"maxY", "maxZ", "minLight", "maxLight", "timeRange", "isRaining", "isThundering",
"minWidth", "maxWidth", "minHeight", "maxHeight", "neededNearbyBlocks",
"neededBaseBlocks", "minDepth", "maxDepth", "fluidIsSource", "fluidBlock"]

# For every fileName in directory.
for fileName in sortedDirectory:
pFile = open(DATA_DIR + fileName, "r")
def main():
error_count = 0

# Gets and sorts directory.
sorted_directory = sorted(os.listdir(DATA_DIR))

# All of the possible conditions in p_data["spawns"]["conditions"]
possible_conditions = ["dimensions", "biomes", "structures", "moonPhase",
"canSeeSky", "minX", "minY", "minZ", "maxX", "maxY",
"maxZ", "minLight", "maxLight", "timeRange",
"isRaining", "isThundering", "minWidth", "maxWidth",
"minHeight", "maxHeight", "neededNearbyBlocks",
"neededBaseBlocks", "minDepth", "maxDepth",
"fluidIsSource", "fluidBlock"]

# For every file_name in directory.
for file_name in sorted_directory:
p_file = open(DATA_DIR + file_name, mode = "r", encoding = "utf-8")
# Obtain json data.
pData = json.load(pFile)
p_data = json.load(p_file)

# For every condition in possible_conditions.
for condition in possible_conditions:
# If condition is outside of pData["spawns"]["conditions"].
if (condition in pData["spawns"][0]):
# If condition is outside of p_data["spawns"]["conditions"].
if condition in p_data["spawns"][0]:
# Print error with file name and condition.
print(f"ERROR: {fileName}: {condition} outside of condition.")
print(f"ERROR: {file_name}: {condition} outside of condition.")
error_count += 1

# Close file.
pFile.close()
exit()
p_file.close()

print(f"Finished with {error_count} possible errors.")
sys.exit()


if __name__ == "__main__":
Expand Down

0 comments on commit e6159f3

Please sign in to comment.