Created
September 20, 2023 16:39
Cassette Beasts Battle Move Tag Extractor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# battle_move_to_csv.py | |
# Reads all battle moves from a decompiled Cassette Beasts project, | |
# producing a csv file containing each move's name, type, and tags (separated by space). | |
# Run in data/battle_moves, no arguments. | |
import glob, os, re | |
content = "battle_move,type,tags\n" | |
regex_tags = """tags = \[ ([\w",\- ]+) \]""" | |
regex_type1 = """elemental_types = \[ ExtResource\( (\d+) \) \]""" | |
regex_type2 = """\[ext_resource path=\"res:\/\/data\/elemental_types\/([\w]+)\.tres\" type=\"Resource\" id={res_id}\]""" | |
for monsterpath in glob.glob('*.tres'): # process | |
monsterfile = open(monsterpath, 'r') | |
monster = monsterfile.read() | |
# Name | |
monstername = os.path.basename(monsterpath)[:-5] | |
content = content + monstername + "," | |
# Type | |
monstertype = "typeless" | |
match_type1 = re.search(regex_type1, monster) | |
if match_type1: | |
match_type2 = re.search(regex_type2.format(res_id=match_type1.group(1)), monster) | |
if match_type2: | |
monstertype = match_type2.group(1) | |
content = content + monstertype + "," | |
# Tags | |
monstertags = "" | |
match_tags = re.search(regex_tags, monster) | |
if match_tags: | |
monstertags = match_tags.group(1).replace("\"", "").replace(",", "") | |
content = content + monstertags + "\n" | |
monsterfile.close() | |
bulk = open('battle_move_tags.csv', 'w+') | |
bulk.write(content) | |
bulk.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment