Skip to content

Commit

Permalink
Add set_unique_id to card JSON files
Browse files Browse the repository at this point in the history
  • Loading branch information
luceleaftea committed Jan 26, 2023
1 parent fdb1acc commit be5971a
Show file tree
Hide file tree
Showing 30 changed files with 9,091 additions and 33 deletions.
12 changes: 11 additions & 1 deletion helper-scripts/generate-json/generate_json_file/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ def generate_json_file():

card_array = []


setJsonPath = Path(__file__).parent / "../../../json/english/set.json"

csvPath = Path(__file__).parent / "../../../csvs/english/card.csv"
jsonPath = Path(__file__).parent / "../../../json/english/card.json"

with csvPath.open(newline='') as csvfile:
with (
csvPath.open(newline='') as csvfile,
setJsonPath.open(newline='') as set_json_file,
):
reader = csv.reader(csvfile, delimiter='\t', quotechar='"')
next(reader)

set_array = json.load(set_json_file)
set_unique_id_cache = {}

for row in reader:
card_object = {}

Expand Down Expand Up @@ -244,6 +253,7 @@ def generate_json_file():
unique_id = valid_unique_ids[0]['unique_id'] if len(valid_unique_ids) > 0 else None

card_variation['unique_id'] = unique_id
card_variation['set_unique_id'] = helper_functions.get_set_unique_id(set_id, "english", set_array, set_unique_id_cache)
card_variation['id'] = card_id_from_variation
card_variation['set_id'] = set_id
card_variation['edition'] = set_edition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def generate_json_file(language):
card_variation = json.loads(json.dumps(card_object))

card_variation['variation_unique_id'] = printing['unique_id']
card_variation['set_unique_id'] = printing['set_unique_id']
card_variation['id'] = printing['id']
card_variation['set_id'] = printing['set_id']
card_variation['edition'] = printing['edition']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def generate_json_file(language):
language_card_json_path = Path(__file__).parent / f"../../../json/{language}/card.json"
language_ability_json_path = Path(__file__).parent / f"../../../json/{language}/ability.json"
language_keyword_json_path = Path(__file__).parent / f"../../../json/{language}/keyword.json"
language_set_json_path = Path(__file__).parent / f"../../../json/{language}/set.json"
language_type_json_path = Path(__file__).parent / f"../../../json/{language}/type.json"

with (
Expand All @@ -33,6 +34,7 @@ def generate_json_file(language):
english_type_json_path.open(newline='') as english_type_json_file,
language_ability_json_path.open(newline='') as language_ability_json_file,
language_keyword_json_path.open(newline='') as language_keyword_json_file,
language_set_json_path.open(newline='') as language_set_json_file,
language_type_json_path.open(newline='') as language_type_json_file
):
english_card_array = json.load(english_card_json_file)
Expand All @@ -41,8 +43,11 @@ def generate_json_file(language):
english_type_array = json.load(english_type_json_file)
language_ability_array = json.load(language_ability_json_file)
language_keyword_array = json.load(language_keyword_json_file)
language_set_array = json.load(language_set_json_file)
language_type_array = json.load(language_type_json_file)

set_unique_id_cache = {}

reader = csv.reader(csv_file, delimiter='\t', quotechar='"')
next(reader)

Expand Down Expand Up @@ -224,6 +229,7 @@ def generate_json_file(language):
unique_id = valid_unique_ids[0]['unique_id'] if len(valid_unique_ids) > 0 else None

card_variation['unique_id'] = unique_id
card_variation['set_unique_id'] = helper_functions.get_set_unique_id(set_id, language, language_set_array, set_unique_id_cache)
card_variation['id'] = card_id_from_variation
card_variation['set_id'] = set_id
card_variation['edition'] = set_edition
Expand Down
13 changes: 13 additions & 0 deletions helper-scripts/generate-json/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ def get_hero_gender_identity(hero):
print(f"ERROR: The hero {hero}'s gender could not be found, please make sure they're in the get_hero_gender_identity function (Yes I know this sounds weird, it's used for language translations that are affected by gender)")
exit()

def get_set_unique_id(set_id, language, language_set_array, set_unique_id_cache):
if set_id in set_unique_id_cache:
return set_unique_id_cache[set_id]

for set in language_set_array:
if set['id'] == set_id:
unique_id = set['unique_id']
set_unique_id_cache[set_id] = unique_id
return unique_id

print(f"Could not find the set with id {set_id} in the {language} set.json")
exit()

def treat_blank_string_as_boolean(field, default_value=True):
if field.strip() == '':
return default_value
Expand Down
3 changes: 2 additions & 1 deletion helper-scripts/generate-json/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
# English JSON files #
generate_json_file.ability.generate_json_file("english")
generate_json_file.artist.generate_json_file("english")
generate_json_file.set.generate_json_file("english")

generate_json_file.card.generate_json_file()
generate_json_file.card_flattened.generate_json_file("english")
generate_json_file.edition.generate_json_file()
generate_json_file.foiling.generate_json_file()
generate_json_file.icon.generate_json_file()
generate_json_file.keyword.generate_json_file("english")
generate_json_file.rarity.generate_json_file()
generate_json_file.set.generate_json_file("english")
generate_json_file.type.generate_json_file("english")

# Non-English JSON files #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def create_table(cur):
CREATE TABLE card_printings (
unique_id VARCHAR(21) NOT NULL,
card_unique_id VARCHAR(21) NOT NULL,
set_unique_id VARCHAR(21) NOT NULL,
card_id VARCHAR(15) NOT NULL COLLATE numeric,
set_id VARCHAR(15) NOT NULL COLLATE numeric,
edition VARCHAR(15) NOT NULL,
Expand Down
9 changes: 9 additions & 0 deletions json-schema/card-flattened-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@
"description": "Represents when the card is set to be unsuspended in Commoner. Contains a displayable text describing when it will be unsuspended if it is currently suspended (will not be present otherwise).",
"type": ["string"]
},
"variation_unique_id": {
"description": "A UUID representing the printing within this data set.",
"type": "string"
},
"set_unique_id": {
"description": "A UUID representing the set the printing belongs to within this data set.",
"type": "string"
},
"id": {
"description": "The ID of the card printing.",
"type": "string"
Expand Down Expand Up @@ -263,6 +271,7 @@
"cc_suspended",
"commoner_suspended",
"variation_unique_id",
"set_unique_id",
"id",
"set_id",
"edition",
Expand Down
5 changes: 5 additions & 0 deletions json-schema/card-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@
"description": "A UUID representing the printing within this data set.",
"type": "string"
},
"set_unique_id": {
"description": "A UUID representing the set the printing belongs to within this data set.",
"type": "string"
},
"id": {
"description": "The ID of the card printing.",
"type": "string"
Expand Down Expand Up @@ -246,6 +250,7 @@
},
"required": [
"unique_id",
"set_unique_id",
"id",
"set_id",
"edition",
Expand Down
Loading

0 comments on commit be5971a

Please sign in to comment.