forked from ONI-Wiki-zh/BotNotIncluded
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_codex.py
46 lines (33 loc) · 1.28 KB
/
get_codex.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
import utils
import pathlib
import yaml
import re
import os.path as path
DIR_CODEX = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\OxygenNotIncluded\\OxygenNotIncluded_Data" \
"\\StreamingAssets\\codex"
def default_ctor(loader, tag_suffix, node):
if isinstance(node, yaml.MappingNode):
return {"tag": tag_suffix, "nodes": loader.construct_mapping(node)}
if isinstance(node, yaml.SequenceNode):
return {"tag": tag_suffix, "nodes": loader.construct_sequence(node)}
return {"tag": tag_suffix, "nodes": loader.construct_scalar(node)}
yaml.add_multi_constructor('', default_ctor)
def getDataInDir(root: pathlib.Path):
out = {"dirs": [], "files": []}
for sub in root.iterdir():
if sub.is_dir():
out["dirs"].append(
{"name": sub.name, "content": getDataInDir(sub)})
if sub.is_file():
with open(sub, "r") as f:
out["files"].append({
"name": sub.name,
"content": yaml.unsafe_load(re.sub(r"\s+\n", "\n", f.read()))
})
return out
def getCodexData():
return getDataInDir(pathlib.Path(DIR_CODEX))
def main():
utils.save_lua(path.join(utils.DIR_OUT, "codex"), getCodexData())
if __name__ == '__main__':
main()