OSDN Git Service

MMD Ver7.40 対応 新スキーマ開発開始
[mikutoga/Vmd2XML.git] / src / main / java / jp / sfjp / mikutoga / vmd / model / binio / BoolLoader.java
1 /*
2  * boolean information builder
3  *
4  * License : The MIT License
5  * Copyright(c) 2013 MikuToga Partners
6  */
7
8 package jp.sfjp.mikutoga.vmd.model.binio;
9
10 import java.util.List;
11 import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
12 import jp.sfjp.mikutoga.bin.parser.ParseStage;
13 import jp.sfjp.mikutoga.vmd.model.IkSwitch;
14 import jp.sfjp.mikutoga.vmd.model.NumberedVmdFlag;
15 import jp.sfjp.mikutoga.vmd.model.VmdMotion;
16 import jp.sfjp.mikutoga.vmd.parser.VmdBoolHandler;
17
18 /**
19  * フラグ情報のビルダ。
20  * <p>MikuMikuDance Ver7.40以降でサポート
21  */
22 public class BoolLoader implements VmdBoolHandler{
23
24     private final List<NumberedVmdFlag> flagList;
25
26     private NumberedVmdFlag currentFlag;
27     private IkSwitch currentSwitch;
28
29     /**
30      * コンストラクタ。
31      * @param vmdMotion モーションデータの格納先。
32      */
33     BoolLoader(VmdMotion vmdMotion){
34         super();
35         this.flagList = vmdMotion.getNumberedFlagList();
36         return;
37     }
38
39
40     /**
41      * {@inheritDoc}
42      * @param stage {@inheritDoc}
43      * @param loops {@inheritDoc}
44      * @throws MmdFormatException {@inheritDoc}
45      */
46     @Override
47     public void loopStart(ParseStage stage, int loops)
48             throws MmdFormatException{
49         if(stage == VmdBoolHandler.MODELSIGHT_LIST){
50             this.currentFlag = new NumberedVmdFlag();
51         }else if(stage == VmdBoolHandler.IKSW_LIST){
52             this.currentSwitch = new IkSwitch();
53         }
54
55         return;
56     }
57
58     /**
59      * {@inheritDoc}
60      * @param stage {@inheritDoc}
61      * @throws MmdFormatException {@inheritDoc}
62      */
63     @Override
64     public void loopNext(ParseStage stage)
65             throws MmdFormatException{
66         if(stage == VmdBoolHandler.MODELSIGHT_LIST){
67             this.flagList.add(this.currentFlag);
68             this.currentFlag = new NumberedVmdFlag();
69         }else if(stage == VmdBoolHandler.IKSW_LIST){
70             List<IkSwitch> swList = this.currentFlag.getIkSwitchList();
71             swList.add(this.currentSwitch);
72             this.currentSwitch = new IkSwitch();
73         }
74
75         return;
76     }
77
78     /**
79      * {@inheritDoc}
80      * @param stage {@inheritDoc}
81      * @throws MmdFormatException {@inheritDoc}
82      */
83     @Override
84     public void loopEnd(ParseStage stage)
85             throws MmdFormatException{
86         if(stage == VmdBoolHandler.MODELSIGHT_LIST){
87             this.currentFlag = null;
88         }else if(stage == VmdBoolHandler.IKSW_LIST){
89             this.currentSwitch = null;
90         }
91
92         return;
93     }
94
95     /**
96      * {@inheritDoc}
97      * @param show {@inheritDoc}
98      * @param keyFrameNo {@inheritDoc}
99      * @throws MmdFormatException {@inheritDoc}
100      */
101     @Override
102     public void vmdModelSight(boolean show, int keyFrameNo)
103             throws MmdFormatException {
104         this.currentFlag.setModelShown(show);
105         this.currentFlag.setFrameNumber(keyFrameNo);
106         return;
107     }
108
109     /**
110      * {@inheritDoc}
111      * @param boneName {@inheritDoc}
112      * @param validIk {@inheritDoc}
113      * @param keyFrameNo {@inheritDoc}
114      * @throws MmdFormatException {@inheritDoc}
115      */
116     @Override
117     public void vmdIkSwitch(String boneName,
118                               boolean validIk,
119                               int keyFrameNo )
120             throws MmdFormatException {
121         this.currentSwitch.setBoneName(boneName);
122         this.currentSwitch.setValid(validIk);
123         return;
124     }
125
126 }