Skip to content

Commit 7a7cd4f

Browse files
committed
Updated sublime script
- Refactored to dict and json from strings
1 parent e58add3 commit 7a7cd4f

File tree

5 files changed

+11849
-11844
lines changed

5 files changed

+11849
-11844
lines changed

.vscodeignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
defs.txt
55
node_modules
66
tf2-snippets.sublime-completions
7-
README.md
7+
todo.md

convert-to-sublime.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
#!/usr/bin/env python3
22

3-
import json, re
3+
from json import load, dump
44

5-
original = open("squirrel.json", "r")
6-
unparsed = original.read()
7-
original.close()
5+
def main():
6+
try:
7+
with open("squirrel.json", "r", encoding="utf-8") as vsc_file:
8+
vsc_data = load(vsc_file)
9+
except IOError:
10+
print("Unable to local \".json\" file")
11+
quit()
812

9-
unparsed = re.sub("\n\t///// BEGIN TF2 VScript Snippets /////", "", unparsed)
10-
unparsed = re.sub("\n\t///// END TF2 VScript Snippets /////", "", unparsed)
13+
snippets = []
1114

12-
parsed = json.loads(unparsed)
15+
for annotation in vsc_data:
16+
snippet = {
17+
"trigger": vsc_data[annotation]["prefix"],
18+
"annotation": annotation,
19+
"contents": vsc_data[annotation]["body"][0],
20+
"kind": "keyword",
21+
"details": vsc_data[annotation]["description"]
22+
}
23+
snippets.append(snippet)
24+
25+
snippets_registry = {
26+
"scope": "source.nut",
27+
"completions": snippets
28+
}
1329

14-
i = 1
15-
print("{\n\t\"scope\": \"source.nut\",\n\t\"completions\": [")
16-
for annotation in parsed:
17-
trigger = parsed[annotation]["prefix"]
18-
contents = parsed[annotation]["body"][0]
19-
details = parsed[annotation]["description"]
20-
details = re.sub("\"", "\\\"", details)
21-
print("\t\t{")
22-
print(f"\t\t\t\"trigger\": \"{trigger}\",\n\t\t\t\"annotation\": \"{annotation}\",\n\t\t\t\"contents\": \"{contents}\",\n\t\t\t\"kind\": \"keyword\",\n\t\t\t\"details\": \"{details}\"")
23-
print("\t\t}", end="")
24-
if (i < len(parsed)):
25-
print(",")
26-
i += 1
27-
print("\n\t]\n}", end="")
30+
with open("tf2-snippets.sublime-completions", "w", encoding="utf-8") as sublime_json:
31+
dump(snippets_registry, sublime_json, indent=2)
32+
33+
if __name__ == "__main__":
34+
main()

gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def main():
1414
sorted_keys = sorted(list(functions.keys()))# Good for comparing diffs
1515
function_registry = generate_snippet_format(sorted_keys, functions)
1616

17-
with open("squirrel.json", "w") as json_test:
17+
with open("squirrel.json", "w", encoding="utf-8") as json_test:
1818
dump(function_registry, json_test, indent=2)
1919

2020
def parse_defs(defs_data: str) -> dict:

squirrel.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
///// BEGIN TF2 VScript Snippets /////
32
"AGGRESSIVE": {
43
"prefix": "AGGRESSIVE",
54
"body": [
@@ -11816,5 +11815,4 @@
1181611815
],
1181711816
"description": ""
1181811817
}
11819-
///// END TF2 VScript Snippets /////
1182011818
}

0 commit comments

Comments
 (0)