OSDN Git Service

本番スキーマ移行
[mikutoga/Vmd2XML.git] / src / main / java / jp / sfjp / mikutoga / vmd / model / VmdMotion.java
1 /*
2  * motion & stage act
3  *
4  * License : The MIT License
5  * Copyright(c) 2011 MikuToga Partners
6  */
7
8 package jp.sfjp.mikutoga.vmd.model;
9
10 import java.text.MessageFormat;
11 import java.util.Collections;
12 import java.util.LinkedHashMap;
13 import java.util.LinkedList;
14 import java.util.List;
15 import java.util.Map;
16 import jp.sfjp.mikutoga.vmd.FrameNumbered;
17 import jp.sfjp.mikutoga.vmd.VmdUniq;
18
19 /**
20  * モーション及び演出情報。
21  */
22 public class VmdMotion {
23
24     private static final String MSG_TXT =
25           "model name : {0}\n"
26         + "bone#{1} morph#{2} camera#{3} luminous#{4} shadow#{5} flag#{6}";
27
28
29     private String modelName = VmdUniq.MODELNAME_STAGEACT;
30
31     private final Map<String, List<BoneMotion>>  bonePartMap;
32     private final Map<String, List<MorphMotion>> morphPartMap;
33
34     private final List<CameraMotion>    cameraMotionList;
35     private final List<LuminousMotion>  luminousMotionList;
36     private final List<ShadowMotion>    shadowMotionList;
37     private final List<NumberedVmdFlag> flagList;
38
39
40     /**
41      * コンストラクタ。
42      */
43     public VmdMotion(){
44         super();
45
46         this.bonePartMap  = new LinkedHashMap<String, List<BoneMotion>>();
47         this.morphPartMap = new LinkedHashMap<String, List<MorphMotion>>();
48
49         this.cameraMotionList   = new LinkedList<CameraMotion>();
50         this.luminousMotionList = new LinkedList<LuminousMotion>();
51         this.shadowMotionList   = new LinkedList<ShadowMotion>();
52         this.flagList           = new LinkedList<NumberedVmdFlag>();
53
54         return;
55     }
56
57
58     /**
59      * モデル名を返す。
60      * @return モデル名
61      */
62     public String getModelName(){
63         return this.modelName;
64     }
65
66     /**
67      * モデル名を設定する。
68      * <p>このモーションがモデルモーションかステージ演出情報かは、
69      * このモデル名で判別される。
70      * @param modelName モデル名
71      * @throws NullPointerException 引数がnull
72      * @see jp.sfjp.mikutoga.vmd.VmdUniq#MODELNAME_STAGEACT
73      */
74     public void setModelName(String modelName) throws NullPointerException{
75         if(modelName == null) throw new NullPointerException();
76         this.modelName = modelName;
77         return;
78     }
79
80     /**
81      * モデルモーションか否か判別する。
82      * <p>判別は特殊なモデル名を持つか否かで決定される。
83      * @return モデルモーションならtrue
84      * @see jp.sfjp.mikutoga.vmd.VmdUniq#MODELNAME_STAGEACT
85      */
86     public boolean isModelMotion(){
87         if(VmdUniq.isStageActName(this.modelName)){
88             return false;
89         }
90
91         return true;
92     }
93
94     /**
95      * フラグモーションが存在するか否か判定する。
96      * <p>フラグモーションは、
97      * MMD Ver7.40以降のVMDフォーマットでなければ記録できない。
98      * @return 存在するならtrue
99      */
100     public boolean hasFlagMotion(){
101         if(this.flagList.isEmpty()) return false;
102         return true;
103     }
104
105     /**
106      * 順序保証されたボーンモーションマップを返す。
107      * @return ボーンモーションマップ
108      * @see java.util.LinkedHashMap
109      */
110     public Map<String, List<BoneMotion>> getBonePartMap(){
111         return this.bonePartMap;
112     }
113
114     /**
115      * 順序保証されたモーフモーションマップを返す。
116      * @return モーフモーションマップ
117      * @see java.util.LinkedHashMap
118      */
119     public Map<String, List<MorphMotion>> getMorphPartMap(){
120         return this.morphPartMap;
121     }
122
123     /**
124      * カメラモーションのリストを返す。
125      * @return カメラモーションのリスト
126      */
127     public List<CameraMotion> getCameraMotionList(){
128         return this.cameraMotionList;
129     }
130
131     /**
132      * 照明モーションのリストを返す。
133      * @return 照明モーションのリスト
134      */
135     public List<LuminousMotion> getLuminousMotionList(){
136         return this.luminousMotionList;
137     }
138
139     /**
140      * シャドウモーションのリストを返す。
141      * @return シャドウモーションのリスト
142      */
143     public List<ShadowMotion> getShadowMotionList(){
144         return this.shadowMotionList;
145     }
146
147     /**
148      * 各種フレーム番号付きフラグのリストを返す。
149      * @return フレーム番号付きフラグのリスト
150      */
151     public List<NumberedVmdFlag> getNumberedFlagList(){
152         return this.flagList;
153     }
154
155     /**
156      * ボーンモーションを追加する。
157      * 追加順は保持される。
158      * @param motion ボーンモーション
159      * @see java.util.LinkedHashMap
160      */
161     public void addBoneMotion(BoneMotion motion){
162         String name = motion.getBoneName();
163
164         List<BoneMotion> list = this.bonePartMap.get(name);
165         if(list == null){
166             list = new LinkedList<BoneMotion>();
167             this.bonePartMap.put(name, list);
168         }
169
170         list.add(motion);
171
172         return;
173     }
174
175     /**
176      * モーフモーションを追加する。
177      * 追加順は保持される。
178      * @param motion モーフモーション
179      * @see java.util.LinkedHashMap
180      */
181     public void addMorphMotion(MorphMotion motion){
182         String name = motion.getMorphName();
183
184         List<MorphMotion> list = this.morphPartMap.get(name);
185         if(list == null){
186             list = new LinkedList<MorphMotion>();
187             this.morphPartMap.put(name, list);
188         }
189
190         list.add(motion);
191
192         return;
193     }
194
195     /**
196      * 各データをフレーム番号順に昇順ソートする。
197      */
198     public void frameSort(){
199         for(List<BoneMotion> list : this.bonePartMap.values()){
200             Collections.sort(list, FrameNumbered.COMPARATOR);
201         }
202
203         for(List<MorphMotion> list : this.morphPartMap.values()){
204             Collections.sort(list, FrameNumbered.COMPARATOR);
205         }
206
207         Collections.sort(this.cameraMotionList,   FrameNumbered.COMPARATOR);
208         Collections.sort(this.luminousMotionList, FrameNumbered.COMPARATOR);
209         Collections.sort(this.shadowMotionList,   FrameNumbered.COMPARATOR);
210         Collections.sort(this.flagList,           FrameNumbered.COMPARATOR);
211
212         return;
213     }
214
215     /**
216      * {@inheritDoc}
217      * @return {@inheritDoc}
218      */
219     @Override
220     public String toString(){
221         int boneNo = 0;
222         for(List<BoneMotion> motionList : this.bonePartMap.values()){
223             boneNo += motionList.size();
224         }
225
226         int morphNo = 0;
227         for(List<MorphMotion> motionList : this.morphPartMap.values()){
228             morphNo += motionList.size();
229         }
230
231         int cameraNo   = this.cameraMotionList  .size();
232         int luminousNo = this.luminousMotionList.size();
233         int shadowNo   = this.shadowMotionList  .size();
234         int flagNo     = this.flagList          .size();
235
236         String msg;
237         msg = MessageFormat.format(MSG_TXT,
238                 this.modelName,
239                 boneNo, morphNo, cameraNo, luminousNo, shadowNo, flagNo );
240
241         return msg;
242     }
243
244 }