OSDN Git Service

parse onStage tag.
authorOlyutorskii <olyutorskii@users.osdn.me>
Sun, 15 Mar 2020 13:30:03 +0000 (22:30 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Sun, 15 Mar 2020 13:30:03 +0000 (22:30 +0900)
src/main/java/jp/sfjp/jindolf/data/SysEvent.java
src/main/java/jp/sfjp/jindolf/data/Talk.java
src/main/java/jp/sfjp/jindolf/data/html/PeriodHandler.java
src/main/java/jp/sfjp/jindolf/data/xml/VillageHandler.java
src/main/java/jp/sfjp/jindolf/summary/GameSummary.java

index d9f44a6..615bcd9 100644 (file)
@@ -33,6 +33,9 @@ public class SysEvent implements Topic{
     private final List<Integer>  integerList = new LinkedList<>();
     private final List<CharSequence>  charseqList =
             new LinkedList<>();
+    /** for playerList and onStage. */
+    private final List<Player> playerList = new LinkedList<>();
+
 
     /**
      * コンストラクタ。
@@ -139,6 +142,16 @@ public class SysEvent implements Topic{
     }
 
     /**
+     * Playerリストを返す。
+     * @return Playerリスト
+     */
+    public List<Player> getPlayerList(){
+        List<Player> result =
+                Collections.unmodifiableList(this.playerList);
+        return result;
+    }
+
+    /**
      * Avatar一覧を追加する。
      * @param list Avatar一覧
      */
@@ -175,6 +188,16 @@ public class SysEvent implements Topic{
     }
 
     /**
+     * Player一覧を追加する。
+     *
+     * @param list Player一覧
+     */
+    public void addPlayerList(List<Player> list){
+        this.playerList.addAll(list);
+        return;
+    }
+
+    /**
      * システムイベントを解析し、処刑されたAvatarを返す。
      * G国運用中の時点で、処刑者が出るのはCOUNTINGとEXECUTIONのみ。
      * @return 処刑されたAvatar。いなければnull
index 8725ef2..0d97f2b 100644 (file)
@@ -34,12 +34,12 @@ public class Talk implements Topic{
     private final Period homePeriod;
     private final TalkType talkType;
     private final Avatar avatar;
-    private final int talkNo;
     private final String messageID;
     private final int hour;
     private final int minute;
-    private final CharSequence dialog;
     private final int charNum;
+    private int talkNo;
+    private CharSequence dialog;
     private int count = -1;
 
 
@@ -200,6 +200,18 @@ public class Talk implements Topic{
     }
 
     /**
+     * 公開発言番号を設定する。
+     *
+     * <p>0以下の値は公開発言番号を持たないと判断される。
+     *
+     * @param talkNo 公開発言番号
+     */
+    public void setTalkNo(int talkNo){
+        this.talkNo = talkNo;
+        return;
+    }
+
+    /**
      * 公開発言番号の有無を返す。
      *
      * @return 公開発言番号が割り当てられているならtrueを返す。
@@ -257,6 +269,16 @@ public class Talk implements Topic{
     }
 
     /**
+     * 会話データを設定する。
+     *
+     * @param seq 会話データ
+     */
+    public void setDialog(CharSequence seq){
+        this.dialog = seq;
+        return;
+    }
+
+    /**
      * 発言種別ごとの発言回数を設定する。
      *
      * <p>システム生成の襲撃予告では負の値を入れれば良い。
index 3022eb4..3049ba1 100644 (file)
@@ -19,6 +19,7 @@ import jp.osdn.jindolf.parser.SeqRange;
 import jp.osdn.jindolf.parser.content.DecodedContent;
 import jp.sfjp.jindolf.data.Avatar;
 import jp.sfjp.jindolf.data.Period;
+import jp.sfjp.jindolf.data.Player;
 import jp.sfjp.jindolf.data.SysEvent;
 import jp.sfjp.jindolf.data.Talk;
 import jp.sfjp.jindolf.data.Topic;
@@ -76,6 +77,7 @@ class PeriodHandler extends HtmlAdapter {
     private final List<Integer> integerList = new LinkedList<>();
     private final List<CharSequence>  charseqList =
         new LinkedList<>();
+    private final List<Player> playerList = new LinkedList<>();
 
 
     /**
@@ -158,6 +160,7 @@ class PeriodHandler extends HtmlAdapter {
         this.roleList.clear();
         this.integerList.clear();
         this.charseqList.clear();
+        this.playerList.clear();
         return;
     }
 
@@ -536,8 +539,10 @@ class PeriodHandler extends HtmlAdapter {
                                 SeqRange avatarRange)
             throws HtmlParseException{
         Avatar newAvatar = toAvatar(content, avatarRange);
-        this.integerList.add(entryNo);
-        this.avatarList.add(newAvatar);
+        Player player = new Player();
+        player.setAvatar(newAvatar);
+        player.setEntryNo(entryNo);
+        this.playerList.add(player);
         return;
     }
 
@@ -888,6 +893,7 @@ class PeriodHandler extends HtmlAdapter {
         event.addRoleList(this.roleList);
         event.addIntegerList(this.integerList);
         event.addCharSequenceList(this.charseqList);
+        event.addPlayerList(this.playerList);
 
         this.period.addTopic(event);
 
index 5ad78fb..b4eb25f 100644 (file)
@@ -7,6 +7,7 @@
 
 package jp.sfjp.jindolf.data.xml;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import jp.osdn.jindolf.parser.content.DecodedContent;
@@ -14,6 +15,7 @@ import jp.sfjp.jindolf.data.Avatar;
 import jp.sfjp.jindolf.data.CoreData;
 import jp.sfjp.jindolf.data.Land;
 import jp.sfjp.jindolf.data.Period;
+import jp.sfjp.jindolf.data.Player;
 import jp.sfjp.jindolf.data.SysEvent;
 import jp.sfjp.jindolf.data.Talk;
 import jp.sfjp.jindolf.data.Topic;
@@ -45,14 +47,10 @@ public class VillageHandler implements ContentHandler{
     private Village village;
     private Period period;
 
-    private Avatar talkAvatar;
+    private Talk talk;
     private int talkNo;
 
-    private TalkType talkType;
-    private String messageId;
-    private String talkTime;
-
-    private SysEventType sysEventType;
+    private SysEvent sysEvent;
 
     private boolean inLine;
     private final StringBuilder content = new StringBuilder(250);
@@ -215,8 +213,6 @@ public class VillageHandler implements ContentHandler{
         this.nsPfx = null;
         this.land = null;
         this.period = null;
-        this.messageId = null;
-        this.talkTime = null;
         return;
     }
 
@@ -297,11 +293,20 @@ public class VillageHandler implements ContentHandler{
         String xname    = attrValue(atts, "xname");
         String time     = attrValue(atts, "time");
 
-        this.talkAvatar = this.idAvatarMap.get(avatarId);
-        this.talkType = decodeTalkType(type);
-        this.messageId = xname;
+        TalkType talkType = decodeTalkType(type);
+        Avatar talkAvatar = this.idAvatarMap.get(avatarId);
+        int hour   = decodeHour  (time);
+        int minute = decodeMinute(time);
+
+        this.talk = new Talk(
+                this.period,
+                talkType, talkAvatar,
+                0, xname,
+                hour, minute,
+                ""
+        );
+
         this.content.setLength(0);
-        this.talkTime = time;
 
         return;
     }
@@ -311,30 +316,17 @@ public class VillageHandler implements ContentHandler{
      */
     private void endTalk(){
         int no = 0;
-        if(this.talkType == TalkType.PUBLIC){
+        if(this.talk.getTalkType() == TalkType.PUBLIC){
             no = ++this.talkNo;
         }
 
-        int hour   = decodeHour  (this.talkTime);
-        int minute = decodeMinute(this.talkTime);
-
         String dialog = this.content.toString();
+        this.content.setLength(0);
 
-        Talk talk = new Talk(
-                this.period,
-                this.talkType, this.talkAvatar,
-                no, this.messageId,
-                hour, minute,
-                dialog
-        );
-
-        this.period.addTopic(talk);
+        this.talk.setTalkNo(no);
+        this.talk.setDialog(dialog);
 
-        this.talkType = null;
-        this.talkAvatar = null;
-        this.messageId = null;
-        this.content.setLength(0);
-        this.talkTime = null;
+        this.period.addTopic(this.talk);
 
         return;
     }
@@ -365,21 +357,28 @@ public class VillageHandler implements ContentHandler{
      *
      * @param type SysEvent種別
      */
-    private void startSysEvent(SysEventType type, Attributes atts){
-        this.sysEventType = type;
+    private void startSysEvent(ElemTag tag, Attributes atts){
+        this.sysEvent = new SysEvent();
 
-        if(this.sysEventType == SysEventType.ASSAULT){
-            String byWhom = attrValue(atts, "byWhom");
-            String xname  = attrValue(atts, "xname");
-            String time   = attrValue(atts, "time");
+        SysEventType type = tag.getSystemEventType();
+        EventFamily eventFamily = type.getEventFamily();
+        this.sysEvent.setSysEventType(type);
+        this.sysEvent.setEventFamily(eventFamily);
 
-            this.talkAvatar = this.idAvatarMap.get(byWhom);
-            this.talkType = TalkType.WOLFONLY;
-            this.messageId = xname;
-            this.talkTime = time;
+        if(this.sysEvent.getSysEventType() == SysEventType.ASSAULT){
+            startAssault(atts);
+        }else{
+            switch(tag){
+                case ONSTAGE:
+                    startOnStage(atts);
+                    break;
+                default:
+                    break;
+            }
         }
 
         this.content.setLength(0);
+
         return;
     }
 
@@ -388,57 +387,81 @@ public class VillageHandler implements ContentHandler{
      *
      * @return パースしたSysEvent。
      */
-    private SysEvent endSysEvent(){
-        SysEvent ev = null;
+    private void endSysEvent(){
         Topic topic;
-        if(this.sysEventType == SysEventType.ASSAULT){
-            int hour   = decodeHour  (this.talkTime);
-            int minute = decodeMinute(this.talkTime);
-
-            String dialog = this.content.toString();
-
-            Talk talk = new Talk(
-                    this.period,
-                    this.talkType, this.talkAvatar,
-                    0, this.messageId,
-                    hour, minute,
-                    dialog );
-            topic = talk;
-            this.talkType = null;
-            this.talkAvatar = null;
-            this.talkTime = null;
-            this.messageId = null;
+        if(this.sysEvent.getSysEventType() == SysEventType.ASSAULT){
+            endAssault();
+            topic = this.talk;
         }else{
-            ev = buildSysEvent();
-            topic = ev;
+            DecodedContent decoded = new DecodedContent(this.content);
+            this.sysEvent.setContent(decoded);
+            topic = this.sysEvent;
         }
 
         this.period.addTopic(topic);
 
         this.content.setLength(0);
-        this.sysEventType = null;
 
-        return ev;
+        return;
     }
 
     /**
-     * SystemEvent 生成共通処理
+     * assault要素開始の受信
      *
-     * <p>イベントファミリ、イベントタイプ、会話テキストが設定される。
+     * @param atts 属性
+     */
+    private void startAssault(Attributes atts){
+        String byWhom = attrValue(atts, "byWhom");
+        String xname  = attrValue(atts, "xname");
+        String time   = attrValue(atts, "time");
+
+        Avatar talkAvatar = this.idAvatarMap.get(byWhom);
+
+        int hour   = decodeHour  (time);
+        int minute = decodeMinute(time);
+
+        this.talk = new Talk(
+                this.period,
+                TalkType.WOLFONLY, talkAvatar,
+                0, xname,
+                hour, minute,
+                ""
+        );
+
+        return;
+    }
+
+    /**
+     * assault要素終了の受信。
+     */
+    private void endAssault(){
+        String dialog = this.content.toString();
+        this.content.setLength(0);
+
+        this.talk.setDialog(dialog);
+
+        return;
+    }
+
+    /**
+     * onStage要素開始の受信。
      *
-     * @return SystemEvent
+     * @param atts 属性
      */
-    private SysEvent buildSysEvent(){
-        SysEvent ev = new SysEvent();
+    private void startOnStage(Attributes atts){
+        String entryNo  = attrValue(atts, "entryNo");
+        String avatarId = attrValue(atts, "avatarId");
 
-        EventFamily eventFamily = this.sysEventType.getEventFamily();
-        ev.setSysEventType(this.sysEventType);
-        ev.setEventFamily(eventFamily);
+        Avatar avatar = this.idAvatarMap.get(avatarId);
+        int entry = Integer.parseInt(entryNo);
 
-        DecodedContent dc = new DecodedContent(this.content);
-        ev.setContent(dc);
+        Player player = new Player();
+        player.setAvatar(avatar);
+        player.setEntryNo(entry);
 
-        return ev;
+        this.sysEvent.addPlayerList(Collections.singletonList(player));
+
+        return;
     }
 
     /**
@@ -521,7 +544,7 @@ public class VillageHandler implements ContentHandler{
         if(tag == null) return;
 
         if(tag.isSysEventTag()){
-            startSysEvent(tag.getSystemEventType(), atts);
+            startSysEvent(tag, atts);
             return;
         }
 
index 1d66056..f22f697 100644 (file)
@@ -211,11 +211,10 @@ public class GameSummary{
 
         eventList = this.eventMap.get(SysEventType.ONSTAGE);
         for(SysEvent event : eventList){
-            avatarList  = event.getAvatarList();
-            integerList = event.getIntegerList();
-            Avatar onstageAvatar = avatarList.get(0);
+            Player player = event.getPlayerList().get(0);
+            Avatar onstageAvatar = player.getAvatar();
             Player onstagePlayer = registPlayer(onstageAvatar);
-            onstagePlayer.setEntryNo(integerList.get(0));
+            onstagePlayer.setEntryNo(player.getEntryNo());
         }
 
         eventList = this.eventMap.get(SysEventType.PLAYERLIST);