コード例 #1
0
#!/bin/python

import os, sys
from ast import literal_eval
sys.path.append(os.path.join(os.path.dirname(__file__), 'common'))
from common import utils, tilesets

output_file = sys.argv[1]
input_file = sys.argv[2]
version_suffix = sys.argv[3]

prefix = "." + os.path.splitext(os.path.basename(input_file))[0]

char_table = utils.reverse_dict(
    utils.merge_dicts([
        tilesets.get_tileset("MainSpecial"),
        tilesets.get_tileset("MainDialog"),
        tilesets.get_tileset("dakuten", override_offset=0x0)
    ]))

try:
    with open(input_file, 'r', encoding="utf-8") as i, open(output_file,
                                                            'w') as o:
        term, prefixlen = literal_eval(i.readline().strip())
        ptrs = []

        version_check = "[{}]".format(version_suffix)
        for n, line in enumerate(i):
            if not line.startswith("[") or line.startswith(version_check):
                line = line.replace(
                    version_check,
                    "")  # Not the best way to do it, but it's good enough
コード例 #2
0
ファイル: dialog2bin.py プロジェクト: lukesheep/medarot3
import csv
import re
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), 'common'))
from common import utils, tilesets

output_file = sys.argv[1]
input_file = sys.argv[2]
column_name = sys.argv[3]
version_suffix = sys.argv[4]

base_name = os.path.splitext(os.path.basename(input_file))[0]
char_table = utils.reverse_dict(
    utils.merge_dicts([
        tilesets.get_tileset("MainDialog1", override_offset=0x0),
        tilesets.get_tileset("MainDialog2", override_offset=0x80),
        tilesets.get_tileset("Special", override_offset=0xE0)
    ]))
kanji = utils.reverse_dict(tilesets.get_tileset("Kanji", override_offset=0x0))
assert ((set(kanji.keys()) - set(char_table.keys())) == set(kanji.keys()))
ptr_names = utils.read_table(os.path.join(os.path.dirname(__file__), 'res',
                                          'ptrs.tbl'),
                             keystring=True)

with open(input_file, 'r', encoding='utf-8-sig') as fp:
    reader = csv.reader(fp, delimiter=',', quotechar='"')
    header = next(reader, None)
    idx_index = header.index("Index[#version]")
    idx_pointer = header.index("Pointer[#version|]")
    idx_text = header.index(column_name)