|
1 | 1 | # NINJA GAIDEN SIGMA 2 TMC Importer by Nozomi Miyamori is under the public domain
|
2 | 2 | # and also marked with CC0 1.0. This file is a part of NINJA GAIDEN SIGMA 2 TMC Importer.
|
3 | 3 |
|
4 |
| -from .tmc11 import ImportTMC11 |
| 4 | +from .importer import import_ngs2_tmc |
| 5 | + |
| 6 | +from . import tcmlib |
| 7 | + |
5 | 8 | import bpy
|
6 | 9 |
|
| 10 | +from bpy_extras.io_utils import ImportHelper |
| 11 | +from bpy.props import StringProperty |
| 12 | +from bpy.types import Operator |
| 13 | + |
| 14 | +import os |
| 15 | +import mmap |
| 16 | + |
| 17 | +def import_tmc_wrapper(context, tmc_path, tmcl_path): |
| 18 | + tmc_m, tmcl_m = mmap_open(tmc_path), mmap_open(tmcl_path) |
| 19 | + with tmc_m, tmcl_m: |
| 20 | + with tcmlib.ngs2.TMCParser(tmc_m, tmcl_m) as tmc: |
| 21 | + import_ngs2_tmc(context, tmc) |
| 22 | + |
| 23 | +class SelectTMCLImportTMC(Operator, ImportHelper): |
| 24 | + bl_idname = 'ninja_gaiden_tmc.select_tmcl_import_tmc' |
| 25 | + bl_label = 'Select TMCL' |
| 26 | + bl_options = {'REGISTER', 'UNDO'} |
| 27 | + |
| 28 | + filter_glob: StringProperty( |
| 29 | + default="*.tmcl;*.dat", |
| 30 | + options={'SKIP_SAVE', 'HIDDEN'}, |
| 31 | + ) |
| 32 | + |
| 33 | + tmc_path: StringProperty() |
| 34 | + |
| 35 | + def execute(self, context): |
| 36 | + if not self.tmc_path: |
| 37 | + return {'CANCELLED'} |
| 38 | + |
| 39 | + try: |
| 40 | + import_tmc_wrapper(context, self.tmc_path, self.filepath) |
| 41 | + except tcmlib.ParserError as e: |
| 42 | + self.report({'ERROR'}, "Failed to parse TMC: {e}") |
| 43 | + return {'CANCELLED'} |
| 44 | + return {'FINISHED'} |
| 45 | + |
| 46 | +class ImportTMCEntry(Operator, ImportHelper): |
| 47 | + '''Load a TMC file (NGS2)''' |
| 48 | + bl_idname = 'ninja_gaiden_tmc.import_tmc_entry' |
| 49 | + bl_label = 'Select TMC' |
| 50 | + |
| 51 | + filter_glob: StringProperty( |
| 52 | + default="*.tmc;*.dat", |
| 53 | + options={'SKIP_SAVE', 'HIDDEN'}, |
| 54 | + ) |
| 55 | + |
| 56 | + def execute(self, context): |
| 57 | + return bpy.ops.ninja_gaiden_tmc.select_tmcl_import_tmc('INVOKE_DEFAULT', tmc_path=self.filepath) |
| 58 | + |
| 59 | +def mmap_open(path): |
| 60 | + with open(path, 'rb') as f: |
| 61 | + return mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) |
| 62 | + |
7 | 63 | def menu_func_import(self, context):
|
8 |
| - self.layout.operator(ImportTMC11.bl_idname, text="Ninja Gaiden Sigam 2 TMC (.tmc/.tmcl)") |
| 64 | + self.layout.operator(ImportTMCEntry.bl_idname, text="Ninja Gaiden Sigam 2 TMC (.tmc/.tmcl)") |
9 | 65 |
|
10 | 66 | def register():
|
11 |
| - bpy.utils.register_class(ImportTMC11) |
| 67 | + bpy.utils.register_class(SelectTMCLImportTMC) |
| 68 | + bpy.utils.register_class(ImportTMCEntry) |
12 | 69 | bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
|
13 | 70 |
|
14 | 71 | def unregister():
|
15 |
| - bpy.utils.unregister_class(ImportTMC11) |
| 72 | + bpy.utils.unregister_class(SelectTMCLImportTMC) |
| 73 | + bpy.utils.unregister_class(ImportTMCEntry) |
16 | 74 | bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
|
17 | 75 |
|
18 | 76 | if __name__ == "__main__":
|
|
0 commit comments