* Copyright(c) 2011 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.vmd.model;
+package jp.sfjp.mikutoga.vmd.model;
+import java.text.MessageFormat;
import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
-import jp.sourceforge.mikutoga.vmd.FrameNumbered;
-import jp.sourceforge.mikutoga.vmd.VmdConst;
+import java.util.Map;
+import jp.sfjp.mikutoga.vmd.FrameNumbered;
+import jp.sfjp.mikutoga.vmd.VmdUniq;
/**
* モーション及び演出情報。
*/
public class VmdMotion {
- private String modelName = VmdConst.MODELNAME_STAGEACT;
+ private static final String MSG_TXT =
+ "model name : {0}\n"
+ + "bone#{1} morph#{2} camera#{3} luminous#{4} shadow#{5}";
- private final NamedListMap<BoneMotion> bonePartMap;
- private final NamedListMap<MorphMotion> morphPartMap;
+
+ private String modelName = VmdUniq.MODELNAME_STAGEACT;
+
+ private final Map<String, List<BoneMotion>> bonePartMap;
+ private final Map<String, List<MorphMotion>> morphPartMap;
private final List<CameraMotion> cameraMotionList;
private final List<LuminousMotion> luminousMotionList;
public VmdMotion(){
super();
- this.bonePartMap = new NamedListMap<BoneMotion>();
- this.morphPartMap = new NamedListMap<MorphMotion>();
+ this.bonePartMap = new LinkedHashMap<String, List<BoneMotion>>();
+ this.morphPartMap = new LinkedHashMap<String, List<MorphMotion>>();
this.cameraMotionList = new LinkedList<CameraMotion>();
this.luminousMotionList = new LinkedList<LuminousMotion>();
* このモデル名で判別される。
* @param modelName モデル名
* @throws NullPointerException 引数がnull
+ * @see jp.sfjp.mikutoga.vmd.VmdUniq#MODELNAME_STAGEACT
*/
public void setModelName(String modelName) throws NullPointerException{
if(modelName == null) throw new NullPointerException();
* モデルモーションか否か判別する。
* <p>判別は特殊なモデル名を持つか否かで決定される。
* @return モデルモーションならtrue
+ * @see jp.sfjp.mikutoga.vmd.VmdUniq#MODELNAME_STAGEACT
*/
public boolean isModelMotion(){
- if(VmdConst.isStageActName(this.modelName)){
+ if(VmdUniq.isStageActName(this.modelName)){
return false;
}
}
/**
- * 名前付きボーンモーションマップを返す。
- * @return 名前付きボーンモーションマップ
+ * 順序保証されたボーンモーションマップを返す。
+ * @return ボーンモーションマップ
+ * @see java.util.LinkedHashMap
*/
- public NamedListMap<BoneMotion> getBonePartMap(){
+ public Map<String, List<BoneMotion>> getBonePartMap(){
return this.bonePartMap;
}
/**
- * 名前付きモーフモーションマップを返す。
- * @return 名前付きモーフモーションマップ
+ * 順序保証されたモーフモーションマップを返す。
+ * @return モーフモーションマップ
+ * @see java.util.LinkedHashMap
*/
- public NamedListMap<MorphMotion> getMorphPartMap(){
+ public Map<String, List<MorphMotion>> getMorphPartMap(){
return this.morphPartMap;
}
/**
* ボーンモーションを追加する。
+ * 追加順は保持される。
* @param motion ボーンモーション
+ * @see java.util.LinkedHashMap
*/
public void addBoneMotion(BoneMotion motion){
String name = motion.getBoneName();
- this.bonePartMap.addNamedElement(name, motion);
+
+ List<BoneMotion> list = this.bonePartMap.get(name);
+ if(list == null){
+ list = new LinkedList<BoneMotion>();
+ this.bonePartMap.put(name, list);
+ }
+
+ list.add(motion);
+
return;
}
/**
* モーフモーションを追加する。
+ * 追加順は保持される。
* @param motion モーフモーション
+ * @see java.util.LinkedHashMap
*/
public void addMorphMotion(MorphMotion motion){
String name = motion.getMorphName();
- this.morphPartMap.addNamedElement(name, motion);
+
+ List<MorphMotion> list = this.morphPartMap.get(name);
+ if(list == null){
+ list = new LinkedList<MorphMotion>();
+ this.morphPartMap.put(name, list);
+ }
+
+ list.add(motion);
+
return;
}
* 各データをフレーム番号順に昇順ソートする。
*/
public void frameSort(){
- for(String name : this.bonePartMap.getNames()){
- List<BoneMotion> motionList =
- this.bonePartMap.getNamedList(name);
- Collections.sort(motionList, FrameNumbered.COMPARATOR);
+ for(List<BoneMotion> list : this.bonePartMap.values()){
+ Collections.sort(list, FrameNumbered.COMPARATOR);
}
- for(String name : this.morphPartMap.getNames()){
- List<MorphMotion> motionList =
- this.morphPartMap.getNamedList(name);
- Collections.sort(motionList, FrameNumbered.COMPARATOR);
+ for(List<MorphMotion> list : this.morphPartMap.values()){
+ Collections.sort(list, FrameNumbered.COMPARATOR);
}
Collections.sort(this.cameraMotionList, FrameNumbered.COMPARATOR);
*/
@Override
public String toString(){
- String dash = "---";
-
- StringBuilder result = new StringBuilder();
-
- result.append("model name : ").append(this.modelName).append('\n');
-
- for(String boneName : this.bonePartMap.getNames()){
- List<BoneMotion> motionList =
- this.bonePartMap.getNamedList(boneName);
- for(BoneMotion motion : motionList){
- result.append(dash).append('\n');
- result.append(motion.toString()).append('\n');
- }
+ int boneNo = 0;
+ for(List<BoneMotion> motionList : this.bonePartMap.values()){
+ boneNo += motionList.size();
}
- for(String morphName : this.morphPartMap.getNames()){
- if(VmdConst.isBaseMorphName(morphName)) continue;
- List<MorphMotion> motionList =
- this.morphPartMap.getNamedList(morphName);
- for(MorphMotion morph : motionList){
- result.append(morph.toString()).append('\n');
- }
+ int morphNo = 0;
+ for(List<MorphMotion> motionList : this.morphPartMap.values()){
+ morphNo += motionList.size();
}
- for(CameraMotion camera : this.cameraMotionList){
- result.append(dash).append('\n');
- result.append(camera.toString()).append('\n');
- }
-
- for(LuminousMotion luminous : this.luminousMotionList){
- result.append(luminous.toString()).append('\n');
- }
+ int cameraNo = this.cameraMotionList .size();
+ int luminousNo = this.luminousMotionList.size();
+ int shadowNo = this.shadowMotionList .size();
- for(ShadowMotion shadow : this.shadowMotionList){
- result.append(shadow.toString()).append('\n');
- }
+ String msg;
+ msg = MessageFormat.format(MSG_TXT,
+ this.modelName,
+ boneNo, morphNo, cameraNo, luminousNo, shadowNo );
- return result.toString();
+ return msg;
}
}