aboutsummaryrefslogtreecommitdiff
path: root/go/client/main.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-01-20 12:00:32 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2023-01-26 22:17:17 +0100
commit5c8dd17404820e631fa3d5a82a67f07d067695bd (patch)
tree5ce54fc2a15fd005b55f92e3dbee600a5c6237fa /go/client/main.go
parenta72f4331a052c3e01ee27fc2cb96c9c12fed1651 (diff)
downloadmuhqs-game-5c8dd17404820e631fa3d5a82a67f07d067695bd.tar.gz
muhqs-game-5c8dd17404820e631fa3d5a82a67f07d067695bd.zip
intermediate commit
* Add static analysis and improve Makefile * Implement hints from static code analysis
Diffstat (limited to 'go/client/main.go')
-rw-r--r--go/client/main.go39
1 files changed, 14 insertions, 25 deletions
diff --git a/go/client/main.go b/go/client/main.go
index 13a07d0b..c8f2e46d 100644
--- a/go/client/main.go
+++ b/go/client/main.go
@@ -64,10 +64,6 @@ func (h *hoverDetector) reset() {
}
}
-func (h *hoverDetector) hovering() bool {
- return h.ticks >= HOVER_THRESHOLD
-}
-
func (h *hoverDetector) startedHovering() bool {
return h.ticks == HOVER_THRESHOLD
}
@@ -192,18 +188,16 @@ func (g *Game) Update() error {
log.Printf("Active object is of type %T\n", g.selectedObject)
- switch obj.(type) {
+ switch obj := obj.(type) {
case ui.Button:
- button := obj.(ui.Button)
- button.Click(x, y)
+ obj.Click(x, y)
case *game.Tile:
- tile := obj.(*game.Tile)
+ tile := obj
if g.selectedObject != nil {
- switch g.selectedObject.(type) {
+ switch obj := g.selectedObject.(type) {
case *game.MoveActionPrototype:
- proto := g.selectedObject.(*game.MoveActionPrototype)
- action := proto.Specialize(tile)
+ action := obj.Specialize(tile)
g.selectedObject = nil
g.declareAction(action)
g.mapView.HighlightTile(tile)
@@ -213,7 +207,7 @@ func (g *Game) Update() error {
}
case game.Permanent:
- perm := obj.(game.Permanent)
+ perm := obj
if g.selectedObject == nil {
actions := perm.GetAvailActionPrototypes()
if len(actions) > 0 {
@@ -225,10 +219,9 @@ func (g *Game) Update() error {
g.addWidget(ui.NewActionChoice(500, 200, actions, onClick))
}
} else {
- switch g.selectedObject.(type) {
+ switch obj := g.selectedObject.(type) {
case *game.AttackActionPrototype:
- proto := g.selectedObject.(*game.AttackActionPrototype)
- action := proto.Specialize(perm)
+ action := obj.Specialize(perm)
g.selectedObject = nil
g.declareAction(action)
g.mapView.HighlightPermanent(perm)
@@ -239,24 +232,20 @@ func (g *Game) Update() error {
log.Fatalf("Object of type %T not handled", obj)
}
- switch g.selectedObject.(type) {
+ switch obj := g.selectedObject.(type) {
case *game.MoveActionPrototype:
- proto := g.selectedObject.(*game.MoveActionPrototype)
- g.mapView.HighlightTiles(proto.Unit.MoveRangeTiles(g.gameState.Map))
+ g.mapView.HighlightTiles(obj.Unit.MoveRangeTiles(g.gameState.Map))
case *game.AttackActionPrototype:
- proto := g.selectedObject.(*game.AttackActionPrototype)
- perms := proto.Unit.AttackablePermanents(g.gameState.Map)
+ perms := obj.Unit.AttackablePermanents(g.gameState.Map)
g.mapView.HighlightPermanents(perms)
}
} else if g.hoverDetector.startedHovering() && g.selectedObject == nil && obj != nil {
var hoverHint *ui.TextBox
- switch obj.(type) {
+ switch obj := obj.(type) {
case *game.Unit:
- u := obj.(*game.Unit)
- hoverHint = ui.NewUnitInfo(x+ui.TILE_WIDTH, y, u)
+ hoverHint = ui.NewUnitInfo(x+ui.TILE_WIDTH, y, obj)
case game.Permanent:
- p := obj.(game.Permanent)
- hoverHint = ui.NewPermInfo(x+ui.TILE_WIDTH, y, p)
+ hoverHint = ui.NewPermInfo(x+ui.TILE_WIDTH, y, obj)
}
if hoverHint != nil {