forked from IAmMoltony/ds-craft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcraftingls.py
60 lines (46 loc) · 1.77 KB
/
craftingls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# craftingls.py
# A handy script to list all crafting recipes
import os
from dataclasses import dataclass
@dataclass
class CraftingRecipe:
recipe_file: str
identifier: int # because 'id' is already taken
count: int
output: str
texid: int
def __repr__(self) -> str:
return f"file: {self.recipe_file}, ID: {self.identifier}, count: {self.count}, outputs: {self.output}"
files = os.listdir('nitrofs/crafting')
def get_recipes() -> dict[int, CraftingRecipe]:
recipes: dict[int, CraftingRecipe] = {}
for file in files:
fn = f'nitrofs/crafting/{file}' # get full file name
fsplit = file.split('.')
curr_id = -1
with open(fn, 'r') as f:
data = f.read()
for line in data.split('\n'): # go line by line
# we dont need the recipe part
if line.startswith('RECIPE'):
break
lsplit = line.split(' ') # split by space
if lsplit[0] == 'id':
curr_id = int(lsplit[1])
recipes[curr_id] = CraftingRecipe(
file, curr_id, 0, '', 0)
elif lsplit[0] == 'count':
count = int(lsplit[1])
recipes[curr_id].count = count
elif lsplit[0] == 'output':
recipes[curr_id].output = lsplit[1]
elif lsplit[0] == 'texid':
recipes[curr_id].texid = int(lsplit[1])
if curr_id == -1:
raise Exception(f"Recipe file {file} does not have an ID field")
recipes_sorted = dict(sorted(recipes.items()))
return recipes_sorted
if __name__ == "__main__":
recipes = get_recipes()
for k, v in recipes.items():
print(f"{k}. {repr(v)}")