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