Organize the project a little bit better

This commit is contained in:
Dendy 2024-02-16 13:48:18 +01:00
parent a811fb5d21
commit 93eb660028
7 changed files with 98 additions and 53 deletions

View File

@ -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
View File

@ -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()

33
run.sh Executable file
View File

@ -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

11
src/main.py Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env python3
import orig
def main():
orig.write_translated()
if __name__ == "__main__":
main()

44
src/orig.py Executable file
View File

@ -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()

View File

@ -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
@ -27,7 +28,7 @@ def get_functions_from_file(filepath: str):
if len(char) != 1: if len(char) != 1:
break break
#print(currentWord) # print(currentWord)
if char in " \n\t\r": if char in " \n\t\r":
currentWord = "" currentWord = ""
@ -40,7 +41,7 @@ def get_functions_from_file(filepath: str):
# Skip comments # Skip comments
if insideComment: if insideComment:
if char == "\n": if char == "\n":
#print("Skipped comment....") # print("Skipped comment....")
insideComment = False insideComment = False
continue continue
@ -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,11 +84,12 @@ 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(
os.path.join(scripts_path,"onik_000.txt") os.path.join(scripts_path, "onik_000.txt")
) )
structure = [] structure = []
@ -114,14 +115,11 @@ def main():
and "\\n" in token[2] and "\\n" in token[2]
): ):
count = token[2].count("\\n") count = token[2].count("\\n")
#structure.append(["LineBreak", count]) # structure.append(["LineBreak", count])
#for coso in structure: # for coso in structure:
# if coso[0] == "OutputLine": # if coso[0] == "OutputLine":
# print(coso[1], end="") # print(coso[1], end="")
# 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()