OSDN Git Service

ff5433a35f07bd9ceaf344204706d0d6bc3d7f58
[mikutoga/TogaGem.git] / src / main / java / jp / sfjp / mikutoga / pmd / parser / PmdParserExt2.java
1 /*
2  * pmd parser extensin 2
3  *
4  * License : The MIT License
5  * Copyright(c) 2010 MikuToga Partners
6  */
7
8 package jp.sfjp.mikutoga.pmd.parser;
9
10 import java.io.IOException;
11 import java.io.InputStream;
12 import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
13 import jp.sfjp.mikutoga.pmd.PmdLimits;
14
15 /**
16  * PMDモデルファイルのパーサ拡張その2。
17  * <p>※ 独自トゥーンテクスチャファイル名対応
18  */
19 public class PmdParserExt2 extends PmdParserExt1 {
20
21     private PmdToonHandler toonHandler = NullHandler.HANDLER;
22
23     /**
24      * コンストラクタ。
25      * @param source 入力ソース
26      */
27     public PmdParserExt2(InputStream source){
28         super(source);
29         return;
30     }
31
32     /**
33      * トゥーンテクスチャファイルハンドラを登録する。
34      * @param handler ハンドラ
35      */
36     public void setToonHandler(PmdToonHandler handler){
37         if(handler == null){
38             this.toonHandler = NullHandler.HANDLER;
39         }else{
40             this.toonHandler = handler;
41         }
42         return;
43     }
44
45     /**
46      * {@inheritDoc}
47      * @throws IOException {@inheritDoc}
48      * @throws MmdFormatException {@inheritDoc}
49      */
50     @Override
51     protected void parseBody()
52             throws IOException, MmdFormatException{
53         super.parseBody();
54
55         if(hasMore()){
56             parseToonName();
57         }
58
59         return;
60     }
61
62     /**
63      * 独自トゥーンテクスチャファイル名のパースと通知。
64      * @throws IOException IOエラー
65      * @throws MmdFormatException フォーマットエラー
66      */
67     private void parseToonName() throws IOException, MmdFormatException{
68         this.toonHandler.loopStart(PmdToonHandler.TOON_LIST,
69                                    PmdLimits.TOON_FIXEDNUM );
70
71         for(int ct = 0; ct < PmdLimits.TOON_FIXEDNUM; ct++){
72             String toonName =
73                     parsePmdText(PmdLimits.MAXBYTES_TOONFILENAME);
74             this.toonHandler.pmdToonFileInfo(toonName);
75
76             this.toonHandler.loopNext(PmdToonHandler.TOON_LIST);
77         }
78
79         this.toonHandler.loopEnd(PmdToonHandler.TOON_LIST);
80
81         return;
82     }
83
84 }