Skip to content

Commit

Permalink
display hero cost
Browse files Browse the repository at this point in the history
  • Loading branch information
haaase committed Oct 29, 2023
1 parent c0115e7 commit ad1518e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/main/scala/uicomponents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import rescala.default._
import miniscribe.data.{Force, Warband}
import scalatags.JsDom._
import scalatags.JsDom.all._
import miniscribe.data.given

trait UIComponent:
def render: HtmlTag
Expand All @@ -19,10 +20,11 @@ object UIComponent:
// things that change the UI state
val toggled: Signal[Map[ID, Boolean]] =
Events.foldAll(Map.WithDefault(Map.empty[ID, Boolean], _ => false)) { acc =>
// everything that can toggle a menu
Seq(
// toggle button presses
// button presses
toggleMenuEvt act2 (id => acc.updated(id, !acc(id))),
// force removals
// removal of a force collapses the associated menu
armyEvents.deleteForce act2 (forceName => acc.updated(forceName, false))
)
}
Expand Down Expand Up @@ -81,6 +83,6 @@ case class WarbandComponent(
warband: Warband
) extends UIComponent:
def render: HtmlTag = div(
h3(warband.hero.flatMap(_.model.map(_.name))),
h3(warband.hero.flatMap(h => h.model.map(m => s"${m.name} (${h.cost})"))),
warband.troops.map(_.name)
)
2 changes: 1 addition & 1 deletion src/main/scala/view.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class toggleMenu(label: String, content: Signal[TypedTag[Element]]):
val toggle: Evt[String] = Evt()
println(s"menu $label created")
private val visible: Signal[Boolean] =
this.toggle.fold(true)((vis, _) => !vis)
this.toggle.fold(false)((vis, _) => !vis)
private val toggleButton =
Events.fromCallback[UIEvent](cb =>
Signal.dynamic {
Expand Down

0 comments on commit ad1518e

Please sign in to comment.