aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-08-19 15:32:17 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:57:40 +0200
commitedf89db6fc28931ca59f6c9acfd0a561d68145c7 (patch)
treefe2961223279d16f5d9952f2e9d4aa6d1a5fcf66
parent97a80cc2cf2a5b5a8334fc42f65863651516d4cf (diff)
downloadmuhqs-game-edf89db6fc28931ca59f6c9acfd0a561d68145c7.tar.gz
muhqs-game-edf89db6fc28931ca59f6c9acfd0a561d68145c7.zip
add discard2 icon and button to trigger the free action
-rw-r--r--assets/icons/discard2.pngbin0 -> 1137 bytes
-rw-r--r--assets/icons/discard2.xcfbin0 -> 6122 bytes
-rw-r--r--go/Makefile36
-rw-r--r--go/assets/.gitignore1
-rw-r--r--go/assets/icons.go25
-rw-r--r--go/client/game.go18
-rw-r--r--go/ui/button.go15
7 files changed, 85 insertions, 10 deletions
diff --git a/assets/icons/discard2.png b/assets/icons/discard2.png
new file mode 100644
index 00000000..81cf6730
--- /dev/null
+++ b/assets/icons/discard2.png
Binary files differ
diff --git a/assets/icons/discard2.xcf b/assets/icons/discard2.xcf
new file mode 100644
index 00000000..6e0bc683
--- /dev/null
+++ b/assets/icons/discard2.xcf
Binary files differ
diff --git a/go/Makefile b/go/Makefile
index ced2e223..879cb8c0 100644
--- a/go/Makefile
+++ b/go/Makefile
@@ -1,7 +1,16 @@
-PACKAGES := activities assets client dummy-ui game log server
+# The full path to the Makefile
+MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
+# The path to the directory of the Makefile
+MAKEFILE_DIR := $(realpath $(dir $(MAKEFILE_PATH)))
+
+ASSETSROOT = $(MAKEFILE_DIR)/../assets/
+ASSETS = $(wildcard $(ASSETSROOT)/icons/*)
+ASSETSTOCOPY = $(addprefix assets/,$(ASSETS:$(ASSETSROOT)/%=copy/%))
SHELL := bash
+PACKAGES := activities assets client dummy-ui game log server
+
APPS := server client dummy-ui
OBJS := $(foreach app,$(APPS),$(app)/$(app))
WASM := client/client.wasm webtools/webtools.wasm dummy-ui/dummy-ui.wasm
@@ -21,21 +30,28 @@ client: client/client
server: server/server
dummy-ui: dummy-ui/dummy-ui
-$(OBJS):
- @echo Building $(@F)
- @pushd $(@D) >/dev/null && go build $(GO_BUILDTAGS) && popd >/dev/null
+VERBOSE ?= @
+
+assets/copy/%: $(ASSETSROOT)/%
+ $(VERBOSE)echo Copying asset $(@F)
+ $(VERBOSE)if test \( ! \( -d $(@D) \) \); then mkdir -p $(@D);fi
+ $(VERBOSE)cp $< $@
+
+$(OBJS): $(ASSETSTOCOPY)
+ $(VERBOSE)echo Building $(@F)
+ $(VERBOSE)pushd $(@D) >/dev/null && go build $(GO_BUILDTAGS) && popd >/dev/null
-$(WASM):
- @echo Building $(@F) ...
- @pushd $(@D) >/dev/null && env GOOS=js GOARCH=wasm go build $(GO_BUILDTAGS) -o $(@F) && popd >/dev/null
+$(WASM): $(ASSETSTOCOPY)
+ $(VERBOSE)echo Building $(@F) ...
+ $(VERBOSE)pushd $(@D) >/dev/null && env GOOS=js GOARCH=wasm go build $(GO_BUILDTAGS) -o $(@F) && popd >/dev/null
fmt:
- @set -e; for package in $(PACKAGES) webtools; do \
+ $(VERBOSE)set -e; for package in $(PACKAGES) webtools; do \
pushd $$package >/dev/null && $(GOFMT); popd >/dev/null; \
done
test:
- @STATUS=0; \
+ $(VERBOSE)STATUS=0; \
for package in $(PACKAGES); do \
if pushd "$$package" >/dev/null; then \
go test; \
@@ -47,7 +63,7 @@ test:
exit "$$STATUS"
check:
- @STATUS=0; \
+ $(VERBOSE)STATUS=0; \
for package in $(PACKAGES); do \
if pushd "$$package" >/dev/null; then \
golangci-lint run; \
diff --git a/go/assets/.gitignore b/go/assets/.gitignore
new file mode 100644
index 00000000..f312659d
--- /dev/null
+++ b/go/assets/.gitignore
@@ -0,0 +1 @@
+copy/ \ No newline at end of file
diff --git a/go/assets/icons.go b/go/assets/icons.go
new file mode 100644
index 00000000..6e461045
--- /dev/null
+++ b/go/assets/icons.go
@@ -0,0 +1,25 @@
+package assets
+
+import (
+ "bytes"
+ "embed"
+ "image"
+ _ "image/png"
+ "log"
+)
+
+//go:embed copy/icons/*
+var icons embed.FS
+
+// GetIcon returns a usable [image.Image] for an embeded icon by its name.
+func GetIcon(name string) image.Image {
+ iconData, err := icons.ReadFile("copy/icons/" + name)
+ if err != nil {
+ log.Panic(err)
+ }
+ icon, _, err := image.Decode(bytes.NewReader(iconData))
+ if err != nil {
+ log.Panic(err)
+ }
+ return icon
+}
diff --git a/go/client/game.go b/go/client/game.go
index d726e760..caf73933 100644
--- a/go/client/game.go
+++ b/go/client/game.go
@@ -45,6 +45,7 @@ type Game struct {
selectedObject any
handLayer *ui.HandView
+ discardBtn *ui.ImageButton
stateBar *ui.StateBar
mapView *ui.MapView
choice ui.Widget
@@ -170,6 +171,17 @@ func (g *Game) initPlayerUi(player *game.Player) *Game {
true)
g.AddWidget(g.handLayer)
+ discardImg := ebiten.NewImageFromImage(assets.GetIcon("discard2.png"))
+ g.discardBtn = ui.NewImageButton(
+ g.handLayer.X+2,
+ g.handLayer.Y+g.handLayer.Height-discardImg.Bounds().Dy()-2,
+ discardImg,
+ func(*ui.ImageButton) {
+ g.addCancelablePrompt(game.NewFreeDiscardAction(player), "select two hand cards")
+ },
+ )
+ g.AddWidget(g.discardBtn)
+
g.stateBar = ui.NewStateBar(0,
g.Height-DEFAULT_BUTTON_HEIGHT,
STATE_BAR_WIDTH,
@@ -471,6 +483,12 @@ func (g *Game) updateButtons() {
g.hide(g.passButton)
}
+ if g.activePlayer().Hand.Size() < 2 {
+ g.hide(g.discardBtn)
+ } else {
+ g.show(g.discardBtn)
+ }
+
passButtonLabel := "pass"
if g.prompt != nil {
targets := g.prompt.Action().Targets()
diff --git a/go/ui/button.go b/go/ui/button.go
index 9afa8c05..6e8fd8b7 100644
--- a/go/ui/button.go
+++ b/go/ui/button.go
@@ -83,3 +83,18 @@ func (b *SimpleButton) UpdateLabel(label string) {
b.ForceRedraw()
}
}
+
+type ImageButton struct {
+ WidgetBase
+ img *ebiten.Image
+}
+
+func NewImageButton(x, y int, img *ebiten.Image, onClick func(b *ImageButton)) *ImageButton {
+ bounds := img.Bounds()
+ sb := &ImageButton{NewWidgetBase(x, y, bounds.Dx(), bounds.Dy()), img}
+ sb.EventHandlersMap["click"] = func(int, int) { onClick(sb) }
+ sb.renderImpl = func() *ebiten.Image {
+ return sb.img
+ }
+ return sb
+}