Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mogproject.mogami.core.io.html

import com.mogproject.mogami.core.game.Game.{CommentType, HistoryHash}
import com.mogproject.mogami.core.move._
import com.mogproject.mogami.core.state.State.{BoardType, HandType}
import com.mogproject.mogami.core.state.{State, StateCache}
Expand All @@ -16,6 +17,8 @@ trait HtmlBranchWriter {

def history: Vector[StateHash]

def historyHash: Vector[HistoryHash]

def finalAction: Option[SpecialMove]

private[this] def moveToString(move: Move, isJapanese: Boolean): String =
Expand All @@ -37,13 +40,13 @@ trait HtmlBranchWriter {
case _ => ""
}

def toHtmlString(isJapanese: Boolean = true, comments: Map[StateHash, String])(implicit stateCache: StateCache): String = {
val stateHistory = history.map(stateCache.get)
def toHtmlString(isJapanese: Boolean = true, comments: CommentType)(implicit stateCache: StateCache): String = {
val stateHistory = history.map(stateCache.get).zip(historyHash)
val states = stateHistory.zip(None +: moves.map(Some.apply)).zipWithIndex.map {
case ((Some(st), Some(m)), i) => st.toHtmlString(s"#${offset + i}: ${moveToString(m, isJapanese)}", Some(m.to), comments.get(st.hash))
case ((Some(st), None), _) => st.toHtmlString(s"Start", None, comments.get(st.hash))
case (((Some(st), hh), Some(m)), i) => st.toHtmlString(s"#${offset + i}: ${moveToString(m, isJapanese)}", Some(m.to), comments.get(hh))
case (((Some(st), hh), None), _) => st.toHtmlString(s"Start", None, comments.get(hh))
case _ => ""
}
(states :+ finalActionToHtml(stateHistory.last, isJapanese)).mkString("\n")
(states :+ finalActionToHtml(stateHistory.last._1, isJapanese)).mkString("\n")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class HtmlBranchWriterSpec extends FlatSpec with MustMatchers with GeneratorDriv

"HtmlBranchWriter#toHtmlString" must "make html with comments" in {
StateCache.withCache { implicit cache =>
Branch(State.HIRATE).toHtmlString(isJapanese = true, Map(State.HIRATE.hash -> "<comment&123>")) mustBe
val br = Branch(State.HIRATE)
br.toHtmlString(isJapanese = true, Map(br.historyHash.head -> "<comment&123>")) mustBe
"<div class=\"shogi-state\"><div class=\"shogi-header\">Start</div><div class=\"shogi-body\"><table><tbody><tr><td><div class=\"shogi-hand\">☖</div>" +
"<table class=\"shogi-board\"><tbody><tr><td class=\"sb-f\">9</td><td class=\"sb-f\">8</td><td class=\"sb-f\">7</td>" +
"<td class=\"sb-f\">6</td><td class=\"sb-f\">5</td><td class=\"sb-f\">4</td><td class=\"sb-f\">3</td><td class=\"sb-f\">2</td>" +
Expand Down