style: format python script
This commit is contained in:
+16
-10
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
TARGET_FILE = os.path.join(os.path.dirname(__file__), "..", "default", "inc_sentences.glsl")
|
TARGET_FILE = os.path.join(
|
||||||
|
os.path.dirname(__file__), "..", "default", "inc_sentences.glsl"
|
||||||
|
)
|
||||||
|
|
||||||
SENTENCES = [
|
SENTENCES = [
|
||||||
"forge",
|
"forge",
|
||||||
@@ -24,34 +26,38 @@ SENTENCES = [
|
|||||||
"Art as code",
|
"Art as code",
|
||||||
]
|
]
|
||||||
|
|
||||||
MAPPING = {
|
MAPPING = {"π": "0xE3"}
|
||||||
"π": "0xE3"
|
|
||||||
}
|
|
||||||
|
|
||||||
def code(char: str) -> str:
|
def code(char: str) -> str:
|
||||||
if char in MAPPING:
|
if char in MAPPING:
|
||||||
return MAPPING[char]
|
return MAPPING[char]
|
||||||
return "0x" + f"{ord(char):02x}".upper()
|
return "0x" + f"{ord(char):02x}".upper()
|
||||||
|
|
||||||
|
|
||||||
def convert(txt: str) -> str:
|
def convert(txt: str) -> str:
|
||||||
out = []
|
out = []
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
out += [code(txt[i]) if i < len(txt) else "0x00"]
|
out += [code(txt[i]) if i < len(txt) else "0x00"]
|
||||||
return f"{{{', '.join(out)}}}"
|
return f"{{{', '.join(out)}}}"
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
with open(TARGET_FILE, mode = 'w') as file:
|
with open(TARGET_FILE, mode="w") as file:
|
||||||
file.write(f"#ifndef INC_SENTENCES\n")
|
file.write("#ifndef INC_SENTENCES\n")
|
||||||
file.write(f"#define INC_SENTENCES\n\n")
|
file.write("#define INC_SENTENCES\n\n")
|
||||||
file.write(f"#define SENTENCE_COUNT {len(SENTENCES)}\n\n")
|
file.write(f"#define SENTENCE_COUNT {len(SENTENCES)}\n\n")
|
||||||
file.write("const int sentences[SENTENCE_COUNT][20] = {\n")
|
file.write("const int sentences[SENTENCE_COUNT][20] = {\n")
|
||||||
for sentence in SENTENCES:
|
for sentence in SENTENCES:
|
||||||
file.write(" " + convert(sentence) + "," + "\n")
|
file.write(" " + convert(sentence) + "," + "\n")
|
||||||
file.write("};\n\n")
|
file.write("};\n\n")
|
||||||
file.write("const int lengths[SENTENCE_COUNT] = {\n")
|
file.write("const int lengths[SENTENCE_COUNT] = {\n")
|
||||||
file.write(" " + ", ".join(str(len(sentence)) for sentence in SENTENCES) + "\n")
|
file.write(
|
||||||
|
" " + ", ".join(str(len(sentence)) for sentence in SENTENCES) + "\n"
|
||||||
|
)
|
||||||
file.write("};\n")
|
file.write("};\n")
|
||||||
file.write("#endif")
|
file.write("#endif")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user