2 * model exporter for pmd-file(Ext1)
4 * License : The MIT License
5 * Copyright(c) 2010 MikuToga Partners
8 package jp.sourceforge.mikutoga.pmd.model.binio;
10 import jp.sourceforge.mikutoga.pmd.IllegalPmdDataException;
11 import java.io.IOException;
12 import java.io.OutputStream;
13 import java.util.List;
15 import jp.sourceforge.mikutoga.binio.IllegalTextExportException;
16 import jp.sourceforge.mikutoga.pmd.MorphType;
17 import jp.sourceforge.mikutoga.pmd.model.BoneGroup;
18 import jp.sourceforge.mikutoga.pmd.model.BoneInfo;
19 import jp.sourceforge.mikutoga.pmd.model.MorphPart;
20 import jp.sourceforge.mikutoga.pmd.model.PmdModel;
21 import jp.sourceforge.mikutoga.pmd.parser.PmdLimits;
24 * PMDファイルのエクスポーター(拡張1:英名対応)。
26 * 任意のトゥーンファイル名対応以降のPMDファイルフォーマットを
27 * 使いたくない場合はこのエクスポーターを用いて出力せよ。
29 public class PmdExporterExt1 extends PmdExporterBase{
33 * @param stream 出力ストリーム
34 * @throws NullPointerException 引数がnull
36 public PmdExporterExt1(OutputStream stream)
37 throws NullPointerException{
44 * @param model {@inheritDoc}
45 * @throws IOException {@inheritDoc}
46 * @throws IllegalPmdDataException {@inheritDoc}
49 public void dumpPmdModel(PmdModel model)
50 throws IOException, IllegalPmdDataException{
51 super.dumpPmdModel(model);
53 dumpGlobalInfo(model);
61 * @throws IOException 出力エラー
62 * @throws IllegalPmdTextException 文字列が長すぎる。
64 private void dumpGlobalInfo(PmdModel model)
65 throws IOException, IllegalPmdDataException{
66 boolean hasGlobal = model.hasGlobalText();
68 if(hasGlobal) globalFlag = 0x01;
69 else globalFlag = 0x00;
74 dumpBasicGlobal(model);
75 dumpBoneGlobal(model);
76 dumpMorphGlobal(model);
77 dumpBoneGroupGlobal(model);
78 }catch(IllegalTextExportException e){
79 throw new IllegalPmdDataException(e);
91 * @throws IOException 出力エラー
92 * @throws IllegalPmdTextException 文字列が長すぎる。
94 private void dumpBasicGlobal(PmdModel model)
95 throws IOException, IllegalTextExportException{
96 String modelName = model.getModelName().getGlobalText();
97 if(modelName == null) modelName = "";
98 dumpText(modelName, PmdLimits.MAXBYTES_MODELNAME);
100 String description = model.getDescription().getGlobalText();
101 if(description == null) description = "";
102 dumpText(description, PmdLimits.MAXBYTES_MODELDESC);
109 * @param model モデルデータ
110 * @throws IOException 出力エラー
111 * @throws IllegalPmdTextException 文字列が長すぎる。
113 private void dumpBoneGlobal(PmdModel model)
114 throws IOException, IllegalTextExportException{
115 for(BoneInfo bone : model.getBoneList()){
116 String boneName = bone.getBoneName().getGlobalText();
117 if(boneName == null) boneName = "";
118 dumpText(boneName, PmdLimits.MAXBYTES_BONENAME);
126 * @param model モデルデータ
127 * @throws IOException 出力エラー
128 * @throws IllegalPmdTextException 文字列が長すぎる。
130 private void dumpMorphGlobal(PmdModel model)
131 throws IOException, IllegalTextExportException{
132 Map<MorphType, List<MorphPart>> morphMap = model.getMorphMap();
134 for(MorphType type : MorphType.values()){
135 if(type.isBase()) continue;
136 List<MorphPart> partList = morphMap.get(type);
137 if(partList == null) continue;
138 for(MorphPart part : partList){
139 String morphName = part.getMorphName().getGlobalText();
140 if(morphName == null) morphName = "";
141 dumpText(morphName, PmdLimits.MAXBYTES_MORPHNAME);
150 * @param model モデルデータ
151 * @throws IOException 出力エラー
152 * @throws IllegalPmdTextException 文字列が長すぎる
154 private void dumpBoneGroupGlobal(PmdModel model)
155 throws IOException, IllegalTextExportException{
156 for(BoneGroup group : model.getBoneGroupList()){
157 if(group.isDefaultBoneGroup()) continue;
158 String groupName = group.getGroupName().getGlobalText();
159 if(groupName == null) groupName = "";
160 dumpText(groupName, PmdLimits.MAXBYTES_BONEGROUPNAME);