X-Git-Url: http://git.osdn.net/view?p=jindolf%2FJindolf.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fjp%2Fsfjp%2Fjindolf%2Fdata%2Fhtml%2FVillageInfoHandler.java;fp=src%2Fmain%2Fjava%2Fjp%2Fsfjp%2Fjindolf%2Fdata%2Fhtml%2FVillageInfoHandler.java;h=984b5c3b608f6014d437d6ca88b24aaacd5cc0a2;hp=0000000000000000000000000000000000000000;hb=cde32116e69984f1c22380b8ecae9a4d28479adb;hpb=d12d773cc29e5ca5efbb5ad879e9e5b373e4c67d diff --git a/src/main/java/jp/sfjp/jindolf/data/html/VillageInfoHandler.java b/src/main/java/jp/sfjp/jindolf/data/html/VillageInfoHandler.java new file mode 100644 index 0000000..984b5c3 --- /dev/null +++ b/src/main/java/jp/sfjp/jindolf/data/html/VillageInfoHandler.java @@ -0,0 +1,290 @@ +/* + * village info handler + * + * License : The MIT License + * Copyright(c) 2020 olyutorskii + */ + +package jp.sfjp.jindolf.data.html; + +import java.util.logging.Logger; +import jp.osdn.jindolf.parser.HtmlAdapter; +import jp.osdn.jindolf.parser.HtmlParseException; +import jp.osdn.jindolf.parser.PageType; +import jp.osdn.jindolf.parser.SeqRange; +import jp.osdn.jindolf.parser.content.DecodedContent; +import jp.sfjp.jindolf.data.Land; +import jp.sfjp.jindolf.data.Period; +import jp.sfjp.jindolf.data.Village; +import jp.sourceforge.jindolf.corelib.LandDef; +import jp.sourceforge.jindolf.corelib.LandState; +import jp.sourceforge.jindolf.corelib.PeriodType; +import jp.sourceforge.jindolf.corelib.VillageState; + + +/** + * åæã®HTMLããã¼ã¹ããææ å ±ãæ¥ç¨ã®éç¥ãåãåãããã®ãã³ãã©ã + * + *
ãã¼ã¹çµäºæã«ã¯ã + * ãããããæå®ããVillageã¤ã³ã¹ã¿ã³ã¹ã« + * æ´æ°æå»ãªã©ã®ææ å ±ãé©åã«æ´æ°ãããã + * + *
æ¥ç¨ã¯ç©ºPeriodã®ãªã¹ãã«åæ ããããåPeriodã®ãã¼ãã¯ã¾ã è¡ãããªãã + * + *
â»äººç¼BBS:Gå½ã«ãããG2087æã®ã¨ããã¼ã°ãçµäºãã段éã§ã + * 人ç¼BBSã¯éå»ãã°ã®æä¾ããè¡ã£ã¦ããªãã + * ã ããã®ã¯ã©ã¹ã«ã¯é²è¡ä¸ã®æããã¼ã¹ããããã®åé·ãªå¦çãè¥å¹²æ®ã£ã¦ããã + */ +class VillageInfoHandler extends HtmlAdapter { + + private static final Logger LOGGER = Logger.getAnonymousLogger(); + + + private Village village = null; + + private boolean hasPrologue; + private boolean hasProgress; + private boolean hasEpilogue; + + private boolean hasDone; + private int maxProgress; + + + /** + * ã³ã³ã¹ãã©ã¯ã¿ã + */ + VillageInfoHandler(){ + super(); + return; + } + + + /** + * æ´æ°å¯¾è±¡ã®æã¤ã³ã¹ã¿ã³ã¹ãè¨å®ããã + * + * @param village æã¤ã³ã¹ã¿ã³ã¹ + */ + void setVillage(Village village){ + this.village = village; + reset(); + return; + } + + /** + * å種é²è¡ã³ã³ããã¹ãã®ãªã»ãããè¡ãã + */ + void reset() { + this.hasPrologue = false; + this.hasProgress = false; + this.hasEpilogue = false; + this.hasDone = false; + this.maxProgress = 0; + return; + } + + /** + * ãã¼ã¹çµæããæã®ç¶æ ãç®åºããã + * + * @return æã®ç¶æ + */ + private VillageState getVillageState() { + VillageState result = VillageState.UNKNOWN; + + if(this.hasDone){ + result = VillageState.GAMEOVER; + }else if(this.hasEpilogue){ + result = VillageState.EPILOGUE; + }else if(this.hasProgress){ + result = VillageState.PROGRESS; + }else if(this.hasPrologue){ + result = VillageState.PROLOGUE; + } + + return result; + } + + /** + * {@inheritDoc} + * + * @param content {@inheritDoc} + * @throws HtmlParseException {@inheritDoc} + */ + @Override + public void startParse(DecodedContent content) + throws HtmlParseException { + reset(); + return; + } + + /** + * {@inheritDoc} + * + *
HTMLèªåå¤å®ã®çµæãæã®æ¥ç¨ãã¼ã¸ã§ãªããã°ä¾å¤ãæãã + * ãã¼ã¹ãä¸æ¢ããã + * + * @param type {@inheritDoc} + * @throws HtmlParseException {@inheritDoc} æå³ããªããã¼ã¸ãæ¥ãã + */ + @Override + public void pageType(PageType type) throws HtmlParseException { + if(type != PageType.PERIOD_PAGE){ + throw new HtmlParseException("æ¥ãã¼ã¸ãå¿ è¦ã§ãã"); + } + return; + } + + /** + * {@inheritDoc} + * + *
æ´æ°æå»ã®éç¥ãåãåãã + * æ´æ°æå»ã¯Villageã¤ã³ã¹ã¿ã³ã¹ã¸åæ ãããã + * + * @param month {@inheritDoc} + * @param day {@inheritDoc} + * @param hour {@inheritDoc} + * @param minute {@inheritDoc} + * @throws HtmlParseException {@inheritDoc} + */ + @Override + public void commitTime(int month, int day, int hour, int minute) + throws HtmlParseException { + this.village.setLimit(month, day, hour, minute); + return; + } + + /** + * {@inheritDoc} + * + *
æ¥ç¨ãã¼ã¸ããåPeriod(æ¥)ã¸ã®ãªã³ã¯HTMLåºç¾ã®éç¥ãåãåãã + * Villageã¤ã³ã¹ã¿ã³ã¹ã®é²è¡ç¶æ³ã¸åæ ãããã + * + * @param content {@inheritDoc} + * @param anchorRange {@inheritDoc} + * @param periodType {@inheritDoc} + * @param day {@inheritDoc} + * @throws HtmlParseException {@inheritDoc} + */ + @Override + public void periodLink(DecodedContent content, + SeqRange anchorRange, + PeriodType periodType, + int day) + throws HtmlParseException { + if(periodType == null){ + this.hasDone = true; + return; + } + + switch(periodType){ + case PROLOGUE: + this.hasPrologue = true; + break; + case PROGRESS: + this.hasProgress = true; + this.maxProgress = day; + break; + case EPILOGUE: + this.hasEpilogue = true; + break; + default: + assert false; + break; + } + + return; + } + + /** + * {@inheritDoc} + * + *
ãã¼ã¹çµäºæã®å¦çãè¡ãã + * + *
æã¨ãã¦ã®ä½è£ã«çç¾ãæ¤åºãããã¨ã + * ä¾å¤ãæããã¼ã¹ãä¸æããã + * + *
æã®é²è¡ã«å¾ã空Periodã®ãªã¹ããçæããã + * + * @throws HtmlParseException {@inheritDoc} + */ + @Override + public void endParse() throws HtmlParseException { + VillageState villageState = getVillageState(); + if(villageState == VillageState.UNKNOWN){ + this.village.setState(villageState); + LOGGER.warning("æã®ç¶æ³ãèªã¿åãã¾ãã"); + return; + } + + Land land = this.village.getParentLand(); + LandDef landDef = land.getLandDef(); + LandState landState = landDef.getLandState(); + + if(landState != LandState.ACTIVE){ + villageState = VillageState.GAMEOVER; + } + this.village.setState(villageState); + + modifyPeriodList(); + + return; + } + + /** + * æ½åºããPeriodå¥ãªã³ã¯æ å ±ã«ä¼´ã空Periodãªã¹ããæºåããã + * + *
ã¾ã Periodãã¼ã¿ã®ãã¼ãã¯è¡ãããªãã + * + *
ã²ã¼ã é²è¡ä¸ã®æã§æ´æ°æå»ãã¾ããã§æ´æ°ãè¡ãããå ´åã + * æ¢åã®Periodãªã¹ãã伸張ããå ´åãããã + */ + private void modifyPeriodList() { + Period lastPeriod = null; + if(this.hasPrologue){ + Period prologue = this.village.getPrologue(); + if(prologue == null){ + lastPeriod = + new Period(this.village, + PeriodType.PROLOGUE, + 0 ); + this.village.setPeriod(0, lastPeriod); + }else{ + lastPeriod = prologue; + } + } + + if(this.hasProgress){ + for(int day = 1; day <= this.maxProgress; day++){ + Period progress = this.village.getProgress(day); + if(progress == null){ + lastPeriod = + new Period(this.village, + PeriodType.PROGRESS, + day ); + this.village.setPeriod(day, lastPeriod); + }else{ + lastPeriod = progress; + } + } + } + + if(this.hasEpilogue){ + Period epilogue = this.village.getEpilogue(); + if(epilogue == null){ + int epilogueDay = this.maxProgress + 1; + lastPeriod = + new Period(this.village, + PeriodType.EPILOGUE, + epilogueDay ); + this.village.setPeriod(epilogueDay, lastPeriod); + } else { + lastPeriod = epilogue; + } + } + + assert this.village.getPeriodSize() > 0; + assert lastPeriod != null; + + return; + } + +}