From 5c8dd17404820e631fa3d5a82a67f07d067695bd Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 20 Jan 2023 12:00:32 +0100 Subject: intermediate commit * Add static analysis and improve Makefile * Implement hints from static code analysis --- go/client/main.go | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'go/client/main.go') 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 { -- cgit v1.2.3