1
- # NINJA GAIDEN SIGMA 2 TMC Importer by Nozomi Miyamori is under the public domain
1
+ # NINJA GAIDEN Model 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 .importer import import_ngs2_tmc
5
-
6
4
from . import tcmlib
5
+ from .ngs1 .importer import import_tmc as ngs1_import_tmc
6
+ from .ngs2 .importer import import_tmc as ngs2_import_tmc
7
7
8
8
import bpy
9
9
14
14
import os
15
15
import mmap
16
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 )
17
+ class NGS1SelectG1TGImportTMC (Operator , ImportHelper ):
18
+ bl_idname = 'ninja_gaiden_tmc.ngs1_select_g1tg_import_tmc'
19
+ bl_label = 'Select TMCL2 or G1TG'
20
+ bl_options = {'REGISTER' , 'UNDO' }
21
+
22
+ filter_glob : StringProperty (
23
+ default = "*.g1t;*.gt1;*.g1tg;*.tmcl2;*.dat" ,
24
+ options = {'SKIP_SAVE' , 'HIDDEN' },
25
+ )
26
+ directory : StringProperty (subtype = 'DIR_PATH' )
22
27
23
- class SelectTMCLImportTMC (Operator , ImportHelper ):
24
- bl_idname = 'ninja_gaiden_tmc.select_tmcl_import_tmc'
28
+ tmc_path : StringProperty (
29
+ subtype = 'FILE_PATH' ,
30
+ default = '' ,
31
+ options = {'SKIP_SAVE' , 'HIDDEN' }
32
+ )
33
+
34
+ tmcl_path : StringProperty (
35
+ subtype = 'FILE_PATH' ,
36
+ default = '' ,
37
+ options = {'SKIP_SAVE' , 'HIDDEN' }
38
+ )
39
+
40
+ def execute (self , context ):
41
+ if not self .tmc_path or not self .tmcl_path :
42
+ return {'CANCELLED' }
43
+
44
+ try :
45
+ with (mmap_open (self .tmc_path ) as tmc , mmap_open (self .tmcl_path ) as tmcl ,
46
+ mmap_open (self .filepath ) as g1tg , tcmlib .ngs1 .TMCParser (tmc , tmcl ) as tmc ):
47
+ ngs1_import_tmc (context , tmc , g1tg )
48
+ except tcmlib .ParserError as e :
49
+ self .report ({'ERROR' }, f"Failed to parse TMC: { e } " )
50
+ return {'CANCELLED' }
51
+ return {'FINISHED' }
52
+
53
+ class NGS1SelectTMCL (Operator , ImportHelper ):
54
+ bl_idname = 'ninja_gaiden_tmc.ngs1_select_tmcl'
55
+ bl_label = 'Select TMCL'
56
+
57
+ filter_glob : StringProperty (
58
+ default = "*.tmcl;*.dat" ,
59
+ options = {'SKIP_SAVE' , 'HIDDEN' },
60
+ )
61
+ directory : StringProperty (subtype = 'DIR_PATH' )
62
+
63
+ tmc_path : StringProperty (
64
+ subtype = 'FILE_PATH' ,
65
+ default = '' ,
66
+ options = {'SKIP_SAVE' , 'HIDDEN' }
67
+ )
68
+
69
+ def execute (self , context ):
70
+ return bpy .ops .ninja_gaiden_tmc .ngs1_select_g1tg_import_tmc ('INVOKE_DEFAULT' , tmc_path = self .tmc_path , tmcl_path = self .filepath , directory = self .directory )
71
+
72
+ class NGS2SelectTMCLImportTMC (Operator , ImportHelper ):
73
+ bl_idname = 'ninja_gaiden_tmc.ngs2_select_tmcl_import_tmc'
25
74
bl_label = 'Select TMCL'
26
75
bl_options = {'REGISTER' , 'UNDO' }
27
76
@@ -42,14 +91,15 @@ def execute(self, context):
42
91
return {'CANCELLED' }
43
92
44
93
try :
45
- import_tmc_wrapper (context , self .tmc_path , self .filepath )
94
+ with mmap_open (self .tmc_path ) as tmc , mmap_open (self .filepath ) as tmcl , tcmlib .ngs2 .TMCParser (tmc , tmcl ) as tmc :
95
+ ngs2_import_tmc (context , tmc )
46
96
except tcmlib .ParserError as e :
47
- self .report ({'ERROR' }, "Failed to parse TMC: {e}" )
97
+ self .report ({'ERROR' }, f "Failed to parse TMC: { e } " )
48
98
return {'CANCELLED' }
49
99
return {'FINISHED' }
50
100
51
101
class ImportTMCEntry (Operator , ImportHelper ):
52
- '''Load a TMC file (NGS2) '''
102
+ '''Load a TMC file'''
53
103
bl_idname = 'ninja_gaiden_tmc.import_tmc_entry'
54
104
bl_label = 'Select TMC'
55
105
old_dir = ''
@@ -58,6 +108,7 @@ class ImportTMCEntry(Operator, ImportHelper):
58
108
default = "*.tmc;*.dat" ,
59
109
options = {'SKIP_SAVE' , 'HIDDEN' },
60
110
)
111
+ filename : StringProperty ()
61
112
directory : StringProperty (subtype = 'DIR_PATH' )
62
113
63
114
def invoke (self , context , event ):
@@ -66,22 +117,35 @@ def invoke(self, context, event):
66
117
67
118
def execute (self , context ):
68
119
ImportTMCEntry .old_dir = self .directory
69
- return bpy .ops .ninja_gaiden_tmc .select_tmcl_import_tmc ('INVOKE_DEFAULT' , tmc_path = self .filepath , directory = self .directory )
120
+ try :
121
+ with mmap_open (self .filepath ) as tmc , tcmlib .ContainerParser (b'TMC' , tmc ) as tmc :
122
+ min_v = tmc ._minor_ver
123
+ except tcmlib .ParserError as e :
124
+ self .report ({'ERROR' }, f"{ self .filename } is not TMC" )
125
+ return {'CANCELLED' }
126
+ if min_v == 0 :
127
+ return bpy .ops .ninja_gaiden_tmc .ngs1_select_tmcl ('INVOKE_DEFAULT' , tmc_path = self .filepath , directory = self .directory )
128
+ else :
129
+ return bpy .ops .ninja_gaiden_tmc .ngs2_select_tmcl_import_tmc ('INVOKE_DEFAULT' , tmc_path = self .filepath , directory = self .directory )
70
130
71
131
def mmap_open (path ):
72
132
with open (path , 'rb' ) as f :
73
133
return mmap .mmap (f .fileno (), 0 , access = mmap .ACCESS_READ )
74
134
75
135
def menu_func_import (self , context ):
76
- self .layout .operator (ImportTMCEntry .bl_idname , text = "Ninja Gaiden Sigam 2 TMC (.tmc/.tmcl )" )
136
+ self .layout .operator (ImportTMCEntry .bl_idname , text = "Ninja Gaiden Master Collection TMC (.tmc)" )
77
137
78
138
def register ():
79
- bpy .utils .register_class (SelectTMCLImportTMC )
139
+ bpy .utils .register_class (NGS1SelectG1TGImportTMC )
140
+ bpy .utils .register_class (NGS1SelectTMCL )
141
+ bpy .utils .register_class (NGS2SelectTMCLImportTMC )
80
142
bpy .utils .register_class (ImportTMCEntry )
81
143
bpy .types .TOPBAR_MT_file_import .append (menu_func_import )
82
144
83
145
def unregister ():
84
- bpy .utils .unregister_class (SelectTMCLImportTMC )
146
+ bpy .utils .unregister_class (NGS1SelectG1TGImportTMC )
147
+ bpy .utils .unregister_class (NGS1SelectTMCL )
148
+ bpy .utils .unregister_class (NGS2SelectTMCLImportTMC )
85
149
bpy .utils .unregister_class (ImportTMCEntry )
86
150
bpy .types .TOPBAR_MT_file_import .remove (menu_func_import )
87
151
0 commit comments