Organize the project a little bit better
This commit is contained in:
parent
a811fb5d21
commit
93eb660028
|
@ -1 +1,2 @@
|
||||||
scripts_path = "/path/ho/higurashi/sdk/Scripts/"
|
scripts_path = "/path/to/higurashi/sdk/Scripts/"
|
||||||
|
original_path = "/path/to/onscripter_file.txt"
|
||||||
|
|
42
orig.py
42
orig.py
|
@ -1,42 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import config
|
|
||||||
import parser
|
|
||||||
from unidecode import unidecode
|
|
||||||
|
|
||||||
#with open('enctest.txt', 'w', encoding='shift_jisx0213') as fileout:
|
|
||||||
|
|
||||||
japanese_ranges = [
|
|
||||||
(0x4E00, 0x9FFF), # Kanji
|
|
||||||
(0x3040, 0x309F), # Hiragana
|
|
||||||
(0x30A0, 0x30FF), # Katakana
|
|
||||||
(0xFF00, 0xFFEF), # Full-width Roman characters and symbols
|
|
||||||
(0x3000, 0x303F), # CJK symbols and punctuation (including 「」)
|
|
||||||
]
|
|
||||||
|
|
||||||
translation = parser.main()
|
|
||||||
outfile = open('out.txt', 'w', encoding='shift_jisx0213')
|
|
||||||
|
|
||||||
with open(config.get('original_path'), 'r', encoding='shift_jisx0213') as file:
|
|
||||||
for line in file:
|
|
||||||
found = False
|
|
||||||
for start, end in japanese_ranges:
|
|
||||||
if start <= ord(line[0]) <= end:
|
|
||||||
found = True
|
|
||||||
|
|
||||||
if found and len(translation) > 0:
|
|
||||||
#outfile.write(unidecode(translation.pop(0)[1]).replace("\\","¥"))
|
|
||||||
amount = line.count("@") + line.count("¥")
|
|
||||||
|
|
||||||
outfile.write('`')
|
|
||||||
|
|
||||||
for _ in range(amount):
|
|
||||||
outfile.write(unidecode(translation.pop(0)[1]).replace("\\","¥"))
|
|
||||||
|
|
||||||
if amount > 0:
|
|
||||||
outfile.write('\n')
|
|
||||||
else:
|
|
||||||
outfile.write(line)
|
|
||||||
|
|
||||||
|
|
||||||
outfile.close()
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# --- Check if venv exists, create if not ---
|
||||||
|
|
||||||
|
[ ! -d "./venv/" ] && {
|
||||||
|
echo -n " - venv not detected, creating... "
|
||||||
|
/usr/bin/env python3 -m venv venv || {
|
||||||
|
echo "Failed to initialize virtual environment. Quitting."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "OK"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
pycmd='./venv/bin/python3'
|
||||||
|
|
||||||
|
# --- Make sure the current requirements are met ---
|
||||||
|
|
||||||
|
$pycmd -c "import pkg_resources; pkg_resources.require(open('requirements.txt',mode='r'))" &>/dev/null || {
|
||||||
|
echo " - Requirements not installed, installing..."
|
||||||
|
|
||||||
|
$pycmd -m pip install -r 'requirements.txt' || {
|
||||||
|
echo "Errored out while trying to install requirements. Check logs above."
|
||||||
|
}
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# --- Run the code ---
|
||||||
|
|
||||||
|
$pycmd src/main.py
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import orig
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
orig.write_translated()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -0,0 +1,44 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import config
|
||||||
|
import parser
|
||||||
|
from unidecode import unidecode
|
||||||
|
|
||||||
|
# with open('enctest.txt', 'w', encoding='shift_jisx0213') as fileout:
|
||||||
|
|
||||||
|
japanese_ranges = [
|
||||||
|
(0x4E00, 0x9FFF), # Kanji
|
||||||
|
(0x3040, 0x309F), # Hiragana
|
||||||
|
(0x30A0, 0x30FF), # Katakana
|
||||||
|
(0xFF00, 0xFFEF), # Full-width Roman characters and symbols
|
||||||
|
(0x3000, 0x303F), # CJK symbols and punctuation (including 「」)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def write_translated():
|
||||||
|
translation = parser.parse_to_tokens()
|
||||||
|
outfile = open('out.txt', 'w', encoding='shift_jisx0213')
|
||||||
|
|
||||||
|
with open(config.get('original_path'), 'r', encoding='shift_jisx0213') as file:
|
||||||
|
for line in file:
|
||||||
|
found = False
|
||||||
|
for start, end in japanese_ranges:
|
||||||
|
if start <= ord(line[0]) <= end:
|
||||||
|
found = True
|
||||||
|
|
||||||
|
if found and len(translation) > 0:
|
||||||
|
# outfile.write(unidecode(translation.pop(0)[1]).replace("\\","¥"))
|
||||||
|
amount = line.count("@") + line.count("¥")
|
||||||
|
|
||||||
|
outfile.write('`')
|
||||||
|
|
||||||
|
for _ in range(amount):
|
||||||
|
outfile.write(
|
||||||
|
unidecode(translation.pop(0)[1]).replace("\\", "¥"))
|
||||||
|
|
||||||
|
if amount > 0:
|
||||||
|
outfile.write('\n')
|
||||||
|
else:
|
||||||
|
outfile.write(line)
|
||||||
|
|
||||||
|
outfile.close()
|
|
@ -3,6 +3,7 @@
|
||||||
import os
|
import os
|
||||||
import config
|
import config
|
||||||
|
|
||||||
|
|
||||||
def get_functions_from_file(filepath: str):
|
def get_functions_from_file(filepath: str):
|
||||||
"""
|
"""
|
||||||
Gets the function calls from a file and returns
|
Gets the function calls from a file and returns
|
||||||
|
@ -71,7 +72,6 @@ def get_functions_from_file(filepath: str):
|
||||||
currentToken.append(currentTokenParameter[:-1].strip())
|
currentToken.append(currentTokenParameter[:-1].strip())
|
||||||
currentTokenParameter = ""
|
currentTokenParameter = ""
|
||||||
|
|
||||||
|
|
||||||
if insideToken and char == ")":
|
if insideToken and char == ")":
|
||||||
insideToken = False
|
insideToken = False
|
||||||
|
|
||||||
|
@ -84,7 +84,8 @@ def get_functions_from_file(filepath: str):
|
||||||
|
|
||||||
return tokens
|
return tokens
|
||||||
|
|
||||||
def main():
|
|
||||||
|
def parse_to_tokens():
|
||||||
scripts_path = config.get("scripts_path")
|
scripts_path = config.get("scripts_path")
|
||||||
|
|
||||||
tokens = get_functions_from_file(
|
tokens = get_functions_from_file(
|
||||||
|
@ -122,6 +123,3 @@ def main():
|
||||||
# elif coso[0] == "LineBreak":
|
# elif coso[0] == "LineBreak":
|
||||||
# print(":".join(["br"] * coso[1]))
|
# print(":".join(["br"] * coso[1]))
|
||||||
return structure
|
return structure
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
Loading…
Reference in New Issue