diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-30 20:25:15 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-07-30 20:28:56 +0200 |
| commit | 5a4a5159b3dcc1caa01e81222f3f1beefcfb4b02 (patch) | |
| tree | 643fa1cdddca1f03d5e76719a2afb607009d91c1 | |
| parent | f64e8747e287e949ce7cbbb42303ad1cdfabec89 (diff) | |
| download | muhqs-game-5a4a5159b3dcc1caa01e81222f3f1beefcfb4b02.tar.gz muhqs-game-5a4a5159b3dcc1caa01e81222f3f1beefcfb4b02.zip | |
use any instead of interface{}
| -rw-r--r-- | go/client/game.go | 10 | ||||
| -rw-r--r-- | go/game/action.go | 10 | ||||
| -rw-r--r-- | go/game/card.go | 2 | ||||
| -rw-r--r-- | go/game/cardParsing.go | 8 | ||||
| -rw-r--r-- | go/game/costs.go | 2 | ||||
| -rw-r--r-- | go/game/targets.go | 46 | ||||
| -rw-r--r-- | go/game/trigger.go | 20 | ||||
| -rw-r--r-- | go/ui/cardGrid.go | 2 | ||||
| -rw-r--r-- | go/ui/cardView.go | 2 | ||||
| -rw-r--r-- | go/ui/choice.go | 4 | ||||
| -rw-r--r-- | go/ui/collection.go | 2 | ||||
| -rw-r--r-- | go/ui/hand.go | 2 | ||||
| -rw-r--r-- | go/ui/mapView.go | 2 | ||||
| -rw-r--r-- | go/ui/prompt.go | 4 | ||||
| -rw-r--r-- | go/ui/stateBar.go | 2 | ||||
| -rw-r--r-- | go/ui/textBox.go | 2 | ||||
| -rw-r--r-- | go/ui/widget.go | 4 | ||||
| -rw-r--r-- | go/webtools/main.go | 2 |
18 files changed, 63 insertions, 63 deletions
diff --git a/go/client/game.go b/go/client/game.go index fdb72683..13209695 100644 --- a/go/client/game.go +++ b/go/client/game.go @@ -37,7 +37,7 @@ type Game struct { keyBindings keyBindings - selectedObject interface{} + selectedObject any handLayer *ui.HandView stateBar *ui.StateBar @@ -377,7 +377,7 @@ func (g *Game) addTriggers(actions []*game.TriggeredAction) { g.triggers = actions } -func (g *Game) addHighlight(obj interface{}, color color.Color) { +func (g *Game) addHighlight(obj any, color color.Color) { switch obj := obj.(type) { case ui.HandCard: g.handLayer.AddHighlightCard(obj.C, color) @@ -392,7 +392,7 @@ func (g *Game) addHighlight(obj interface{}, color color.Color) { } } -func (g *Game) addHighlights(objs []interface{}, color color.Color) { +func (g *Game) addHighlights(objs []any, color color.Color) { for _, obj := range objs { g.addHighlight(obj, color) } @@ -538,7 +538,7 @@ func (g *Game) handlePlayerNotifications() { } } -func (g *Game) findObjectAt(x, y int) interface{} { +func (g *Game) findObjectAt(x, y int) any { // Iterate the widget in reverse order to ensure that objects are found // in the newer widget possibly drawn over older ones widgets := g.Widgets() @@ -565,7 +565,7 @@ func (g *Game) progressPlayAction(a *game.PlayAction) { } } -func (g *Game) handleSelection(obj interface{}, x, y int) { +func (g *Game) handleSelection(obj any, x, y int) { if obj == nil { log.Printf("No object found at cursor position (%d, %d)\n", x, y) return diff --git a/go/game/action.go b/go/game/action.go index 913e1574..cfb9809f 100644 --- a/go/game/action.go +++ b/go/game/action.go @@ -49,7 +49,7 @@ type Action interface { type PassPriority struct{ player *Player } -func (a *PassPriority) Source() interface{} { return a.player } +func (a *PassPriority) Source() any { return a.player } func (a *PassPriority) Controller() *Player { return a.player } func (a *PassPriority) Speed() ActionSpeed { return fast } func (a *PassPriority) GameState() *LocalState { return a.player.gameState } @@ -67,7 +67,7 @@ type TargetSelection struct { targets *Targets } -func (sel *TargetSelection) Source() interface{} { return sel.player } +func (sel *TargetSelection) Source() any { return sel.player } func (sel *TargetSelection) Controller() *Player { return sel.player } func (sel *TargetSelection) Speed() ActionSpeed { return fast } func (sel *TargetSelection) GameState() *LocalState { return sel.player.gameState } @@ -96,7 +96,7 @@ type DraftPick struct { pack PileOfCards } -func (pick *DraftPick) Source() interface{} { return pick.player } +func (pick *DraftPick) Source() any { return pick.player } func (pick *DraftPick) Controller() *Player { return pick.player } func (pick *DraftPick) Speed() ActionSpeed { return fast } func (pick *DraftPick) GameState() *LocalState { return pick.player.gameState } @@ -189,7 +189,7 @@ type DeclareTriggeredActionsAction struct { actions []*TriggeredAction } -func (sel *DeclareTriggeredActionsAction) Source() interface{} { return nil } +func (sel *DeclareTriggeredActionsAction) Source() any { return nil } func (sel *DeclareTriggeredActionsAction) Controller() *Player { return nil } func (sel *DeclareTriggeredActionsAction) Speed() ActionSpeed { return fast } func (sel *DeclareTriggeredActionsAction) GameState() *LocalState { return nil } @@ -270,7 +270,7 @@ func NewPlayActionCostFunc(player *Player, cost int, card *Card) ActionCostFunc } } -func NewPlayAction(p *Player, c *Card, args ...interface{}) *PlayAction { +func NewPlayAction(p *Player, c *Card, args ...any) *PlayAction { a := &PlayAction{ ActionBase{ source: p, diff --git a/go/game/card.go b/go/game/card.go index 5ecce64c..72b32335 100644 --- a/go/game/card.go +++ b/go/game/card.go @@ -171,7 +171,7 @@ type Card struct { Type CardType BuyCosts *ResourceCosts PlayCosts *ResourceCosts - Values map[string]interface{} + Values map[string]any Impl cardImplementation } diff --git a/go/game/cardParsing.go b/go/game/cardParsing.go index 5ccf181a..3b1e7cdb 100644 --- a/go/game/cardParsing.go +++ b/go/game/cardParsing.go @@ -160,10 +160,10 @@ func (impl *dynamicCardImplementation) parseFullAction(fullAction string) { } } -func parseUnitConstrain(constrain string) func(ctx interface{}, u *Unit) bool { +func parseUnitConstrain(constrain string) func(ctx any, u *Unit) bool { enemy := strings.Contains(constrain, "enemy") if enemy { - return func(ctx interface{}, e *Unit) bool { + return func(ctx any, e *Unit) bool { p := ctx.(*Player) return p.IsEnemy(e.Controller()) } @@ -174,7 +174,7 @@ func parseUnitConstrain(constrain string) func(ctx interface{}, u *Unit) bool { return nil } -func parseLocation(location string) func(interface{}, *LocalState) []*Tile { +func parseLocation(location string) func(any, *LocalState) []*Tile { r := -1 var what string if strings.Contains(location, "on") { @@ -209,7 +209,7 @@ func parseLocation(location string) func(interface{}, *LocalState) []*Tile { if strings.Contains(what, "unit") { constrainFunc := parseUnitConstrain(what) if constrainFunc != nil { - return func(ctx interface{}, s *LocalState) []*Tile { + return func(ctx any, s *LocalState) []*Tile { origins := s.Map().FilterTiles(func(t *Tile) bool { if t.Permanent != nil && t.Permanent.Card().Type == CardTypes.Unit && diff --git a/go/game/costs.go b/go/game/costs.go index da8993db..bb6562ea 100644 --- a/go/game/costs.go +++ b/go/game/costs.go @@ -51,7 +51,7 @@ func (c *ResourceCosts) Costs(s *LocalState, choosenVariadicCosts ...int) int { return costs } -func ParseCardResourceCosts(_costs interface{}, effects []string) *ResourceCosts { +func ParseCardResourceCosts(_costs any, effects []string) *ResourceCosts { switch c := _costs.(type) { case int: return &ResourceCosts{fixed: c} diff --git a/go/game/targets.go b/go/game/targets.go index 3eccfe76..742d5c7f 100644 --- a/go/game/targets.go +++ b/go/game/targets.go @@ -12,7 +12,7 @@ import ( ) type ( - TargetConstraintFunc func(interface{}) error + TargetConstraintFunc func(any) error TargetDesc struct { target, req string @@ -27,7 +27,7 @@ type ( desc string requirement TargetRequirement constraint TargetConstraintFunc - sel []interface{} + sel []any } Targets struct { @@ -70,7 +70,7 @@ func (t *Targets) String() string { return s[:len(s)-1] + "]" } -func newTargetWithSel(s *LocalState, desc TargetDesc, action Action, sel []interface{}) *Target { +func newTargetWithSel(s *LocalState, desc TargetDesc, action Action, sel []any) *Target { t := &Target{ s: s, desc: desc.target, @@ -83,13 +83,13 @@ func newTargetWithSel(s *LocalState, desc TargetDesc, action Action, sel []inter } func newTarget(s *LocalState, desc TargetDesc, action Action) *Target { - return newTargetWithSel(s, desc, action, []interface{}{}) + return newTargetWithSel(s, desc, action, []any{}) } func newUnitAiTarget(s *LocalState, desc TargetDesc, ai *UnitAI) *Target { // Dummy action allowing the parsing code to determine the controller of the AI dummyAction := NewPassPriority(ai.u.controller) - return newTargetWithSel(s, desc, dummyAction, []interface{}{}) + return newTargetWithSel(s, desc, dummyAction, []any{}) } func newConstraintTarget(s *LocalState, desc TargetDesc, constraint TargetConstraintFunc, action Action, @@ -144,7 +144,7 @@ func newArtifactMoveTargets(s *LocalState, a *ArtifactMoveAction) *Targets { constraints = []TargetConstraintFunc{tileTargetConstraint} constraints = append(constraints, availableTileConstraint(a, a.Artifact.Card())) - constraints = append(constraints, func(t interface{}) error { + constraints = append(constraints, func(t any) error { c := rangeTargetConstraint(moveTarget.sel[0], 1) return c(t) }) @@ -207,11 +207,11 @@ func (t *Target) HasSelection() bool { return len(t.sel) > 0 } func (t *Target) AllowSelection() bool { return (t.requirement.max == -1 || len(t.sel) < t.requirement.max) && len(t.Options()) > 0 } -func (t *Target) ClearSelection() { t.sel = []interface{}{} } -func (t *Target) NoSelection() bool { return len(t.sel) == 0 } -func (t *Target) Selection() []interface{} { return t.sel } +func (t *Target) ClearSelection() { t.sel = []any{} } +func (t *Target) NoSelection() bool { return len(t.sel) == 0 } +func (t *Target) Selection() []any { return t.sel } -func (t *Target) Options() (options []interface{}) { +func (t *Target) Options() (options []any) { candidates := t.candidates() for _, candidate := range candidates { @@ -328,7 +328,7 @@ func (targets *Targets) AllowSelection() bool { } func conjunction(constraints ...TargetConstraintFunc) TargetConstraintFunc { - return func(t interface{}) error { + return func(t any) error { for _, constraint := range constraints { if err := constraint(t); err != nil { return err @@ -340,7 +340,7 @@ func conjunction(constraints ...TargetConstraintFunc) TargetConstraintFunc { } func disjunction(constraints ...TargetConstraintFunc) TargetConstraintFunc { - return func(t interface{}) error { + return func(t any) error { var err error for _, constraint := range constraints { if err = constraint(t); err == nil { @@ -353,7 +353,7 @@ func disjunction(constraints ...TargetConstraintFunc) TargetConstraintFunc { } func noPreviousSelectionConstraint(targets *Targets, idx int) TargetConstraintFunc { - return func(t interface{}) error { + return func(t any) error { for i := 0; i < idx && i < targets.idx; i++ { target := targets.ts[i] if slices.Contains(target.sel, t) { @@ -410,7 +410,7 @@ func enemyPermanentTargetConstraint(action Action) TargetConstraintFunc { log.Panicf("Unhandled source type %T in enemyPermanentTargetConstraint", source) } - return func(t interface{}) (err error) { + return func(t any) (err error) { p, _ := t.(Permanent) if !p.Controller().IsEnemy(sourceController) { err = fmt.Errorf("Controller %v of target %v is not an enemy of %v", @@ -468,7 +468,7 @@ func attackableTargetConstraint(action Action) TargetConstraintFunc { } } -func posFromTileOrPermanent(tileOrPermanent interface{}) Position { +func posFromTileOrPermanent(tileOrPermanent any) Position { switch obj := tileOrPermanent.(type) { case *Tile: return obj.Position @@ -480,10 +480,10 @@ func posFromTileOrPermanent(tileOrPermanent interface{}) Position { } } -func rangeTargetConstraint(source interface{}, r int) TargetConstraintFunc { +func rangeTargetConstraint(source any, r int) TargetConstraintFunc { sourcePos := posFromTileOrPermanent(source) - return func(t interface{}) (err error) { + return func(t any) (err error) { targetPos := posFromTileOrPermanent(t) if !IsPositionInRange(sourcePos, targetPos, r) { err = fmt.Errorf("Position %v of target %v not in range %d of source's position %v", @@ -494,7 +494,7 @@ func rangeTargetConstraint(source interface{}, r int) TargetConstraintFunc { } func typeTargetConstraint[T any](typeDesc string) TargetConstraintFunc { - return func(t interface{}) (err error) { + return func(t any) (err error) { _, ok := t.(T) if !ok { err = fmt.Errorf("unexpected target type %T not %s", t, typeDesc) @@ -504,7 +504,7 @@ func typeTargetConstraint[T any](typeDesc string) TargetConstraintFunc { } func cardTypeTargetConstraint(f func(CardType) bool) TargetConstraintFunc { - return func(t interface{}) (err error) { + return func(t any) (err error) { p, ok := t.(Permanent) if !ok { err = fmt.Errorf("unexpected target type %T not Permanent", t) @@ -580,7 +580,7 @@ func parseArtifactTargetConstraint(constraint string, s *LocalState, action Acti return constraints } -func _relaxedTileTarget(t interface{}) *Tile { +func _relaxedTileTarget(t any) *Tile { switch t := t.(type) { case *Tile: return t @@ -593,7 +593,7 @@ func _relaxedTileTarget(t interface{}) *Tile { return nil } -func relaxedTileTarget(action Action, t interface{}) *Tile { +func relaxedTileTarget(action Action, t any) *Tile { switch action.(type) { // Some actions allow to also move to Tile occupied by a crewable permanent case *MoveAction: @@ -806,7 +806,7 @@ func parseCardTargetConstraint(desc string, s *LocalState, action Action) []Targ } } - constraints = append(constraints, func(t interface{}) (err error) { + constraints = append(constraints, func(t any) (err error) { c := t.(*Card) for _, poc := range pocs { if poc.Contains(c) { @@ -820,7 +820,7 @@ func parseCardTargetConstraint(desc string, s *LocalState, action Action) []Targ return constraints } -func (t *Target) candidates() []interface{} { +func (t *Target) candidates() []any { c := []any{} if strings.Contains(t.desc, "unit") || strings.Contains(t.desc, "artifact") || diff --git a/go/game/trigger.go b/go/game/trigger.go index b8eb28c0..34caf9b1 100644 --- a/go/game/trigger.go +++ b/go/game/trigger.go @@ -56,8 +56,8 @@ func (e eventType) String() string { type Event struct { eventType eventType - sources []interface{} - affected []interface{} + sources []any + affected []any } func (e Event) String() string { @@ -72,31 +72,31 @@ func newEotEvent() Event { return Event{eventType: eot} } -func newTargetEvent(source interface{}, targets *Targets) Event { - affected := make([]interface{}, 0, len(targets.ts)) +func newTargetEvent(source any, targets *Targets) Event { + affected := make([]any, 0, len(targets.ts)) for _, t := range targets.ts { affected = append(affected, t.sel...) } - return Event{eventType: target, sources: []interface{}{source}, affected: affected} + return Event{eventType: target, sources: []any{source}, affected: affected} } type Trigger interface { - Source() interface{} + Source() any String() string Card() *Card trigger(*LocalState, Event) ([]*TriggeredAction, bool) } type triggerBase struct { - source interface{} + source any condition func(*LocalState, Event) (bool, bool) resolveFunc ActionResolveFunc costFunc ActionCostFunc desc string } -func (t *triggerBase) Source() interface{} { return t.source } -func (t *triggerBase) String() string { return t.desc } +func (t *triggerBase) Source() any { return t.source } +func (t *triggerBase) String() string { return t.desc } func (t *triggerBase) Card() *Card { switch t := t.source.(type) { case *Card: @@ -122,7 +122,7 @@ func newTargetedTrigger(p Permanent, singleshot bool, resolveFunc ActionResolveF t := triggerBase{source: p, resolveFunc: resolveFunc, desc: desc} t.condition = func(_ *LocalState, event Event) (bool, bool) { c := event.eventType == EventTypes.Target && - slices.Contains(event.affected, p.(interface{})) + slices.Contains(event.affected, p.(any)) remove := singleshot && c return c, remove } diff --git a/go/ui/cardGrid.go b/go/ui/cardGrid.go index e3866369..355965a1 100644 --- a/go/ui/cardGrid.go +++ b/go/ui/cardGrid.go @@ -125,7 +125,7 @@ func (w *CardGrid) render() *ebiten.Image { return img } -func (w *CardGrid) FindObjectAt(_x, _y int) interface{} { +func (w *CardGrid) FindObjectAt(_x, _y int) any { if !w.Contains(_x, _y) || w.grid == nil { return nil } diff --git a/go/ui/cardView.go b/go/ui/cardView.go index 960f9230..0dff9481 100644 --- a/go/ui/cardView.go +++ b/go/ui/cardView.go @@ -91,7 +91,7 @@ func (cv *ToggleCardView) Contains(x, y int) bool { return cv.cv.Contains(x, y) || cv.tgglBtn.Contains(x, y) } -func (cv *ToggleCardView) FindObjectAt(x, y int) interface{} { +func (cv *ToggleCardView) FindObjectAt(x, y int) any { return cv.cv.FindObjectAt(x, y) } diff --git a/go/ui/choice.go b/go/ui/choice.go index 7c32b2bc..1c1c72b6 100644 --- a/go/ui/choice.go +++ b/go/ui/choice.go @@ -10,11 +10,11 @@ import ( type Choice struct { TextBox - choices []interface{} + choices []any onClick func(*Choice, int, int) } -func NewChoice(x, y int, choices []interface{}, onClick func(*Choice, int, int)) *Choice { +func NewChoice(x, y int, choices []any, onClick func(*Choice, int, int)) *Choice { c := &Choice{ TextBox: *(NewAutoTextBox(x, y, "")), choices: choices, diff --git a/go/ui/collection.go b/go/ui/collection.go index ece205a0..78944814 100644 --- a/go/ui/collection.go +++ b/go/ui/collection.go @@ -114,7 +114,7 @@ func (c *Collection) FindWidgetAt(x, y int) Widget { return nil } -func (c *Collection) FindObjectAt(x, y int) interface{} { +func (c *Collection) FindObjectAt(x, y int) any { // Iterate the widget in reverse order to ensure that upper widgets are // considered first diff --git a/go/ui/hand.go b/go/ui/hand.go index 7c8feab8..46dd34c6 100644 --- a/go/ui/hand.go +++ b/go/ui/hand.go @@ -24,7 +24,7 @@ func NewHandView(x, y, width, height int, h *game.Hand, bottomAligned bool) *Han return hv } -func (hv *HandView) FindObjectAt(x, y int) interface{} { +func (hv *HandView) FindObjectAt(x, y int) any { if obj := hv.CardGrid.FindObjectAt(x, y); obj != nil { return HandCard{obj.(*game.Card)} } diff --git a/go/ui/mapView.go b/go/ui/mapView.go index f716278c..d73f3573 100644 --- a/go/ui/mapView.go +++ b/go/ui/mapView.go @@ -386,7 +386,7 @@ func isSymbolTransparentAt(p game.Permanent, relativeX, relativeY int) bool { return alpha == 0 } -func (vw *MapView) FindObjectAt(screenX, screenY int) interface{} { +func (vw *MapView) FindObjectAt(screenX, screenY int) any { scaled_tile_wdth := int(float64(TILE_WIDTH) * vw.scale) scaled_tile_hght := int(float64(TILE_HEIGHT) * vw.scale) x := screenX / scaled_tile_wdth diff --git a/go/ui/prompt.go b/go/ui/prompt.go index a289ae13..5448dfde 100644 --- a/go/ui/prompt.go +++ b/go/ui/prompt.go @@ -40,7 +40,7 @@ func NewCancelablePrompt(y, width int, action game.Action, promptText string) *P func (p *Prompt) Cancelable() bool { return p.cancelable } func (p *Prompt) Action() game.Action { return p.action } -func (p *Prompt) Add(obj interface{}) error { +func (p *Prompt) Add(obj any) error { if handCard, ok := obj.(HandCard); ok { obj = handCard.C } @@ -66,7 +66,7 @@ func (p *Prompt) Contains(x, y int) bool { return x >= 0 && y >= 0 && x <= p.width && y >= p.y && y <= p.y+PROMPT_HEIGHT } -func (p *Prompt) FindObjectAt(screenX, screenY int) interface{} { return nil } +func (p *Prompt) FindObjectAt(screenX, screenY int) any { return nil } func (*Prompt) Render(Widget) *ebiten.Image { return nil } func (p *Prompt) setTextBgAlpha(alpha uint8) { diff --git a/go/ui/stateBar.go b/go/ui/stateBar.go index 65187e30..a5189a84 100644 --- a/go/ui/stateBar.go +++ b/go/ui/stateBar.go @@ -46,7 +46,7 @@ func (sb *StateBar) Draw(screen *ebiten.Image) { sb.phaseView.Draw(screen) } -func (sb *StateBar) FindObjectAt(x, y int) interface{} { return nil } +func (sb *StateBar) FindObjectAt(x, y int) any { return nil } func (sb *StateBar) ForceRedraw() { if sb.resourceView != nil { diff --git a/go/ui/textBox.go b/go/ui/textBox.go index c93e14e2..7a3772f0 100644 --- a/go/ui/textBox.go +++ b/go/ui/textBox.go @@ -179,7 +179,7 @@ func (w *PocList) setText() { w.Y = w.bottomY - int(height) - w.YMargin } -func (w *PocList) FindObjectAt(_x, _y int) interface{} { +func (w *PocList) FindObjectAt(_x, _y int) any { if !w.Contains(_x, _y) { return nil } diff --git a/go/ui/widget.go b/go/ui/widget.go index da12929d..4082c828 100644 --- a/go/ui/widget.go +++ b/go/ui/widget.go @@ -6,7 +6,7 @@ import ( type Widget interface { Draw(*ebiten.Image) - FindObjectAt(int, int) interface{} + FindObjectAt(int, int) any Contains(int, int) bool Layout() (int, int) @@ -57,7 +57,7 @@ func (w *WidgetBase) Contains(x, y int) bool { return x >= 0 && y >= 0 && x >= w.X && x <= w.X+w.Width && y >= w.Y && y <= w.Y+w.Height } -func (w *WidgetBase) FindObjectAt(int, int) interface{} { +func (w *WidgetBase) FindObjectAt(int, int) any { return nil } diff --git a/go/webtools/main.go b/go/webtools/main.go index c468f4dd..68095801 100644 --- a/go/webtools/main.go +++ b/go/webtools/main.go @@ -28,7 +28,7 @@ func jSRandomTileFromMap() js.Func { if err != nil { return err.Error() } - return map[string]interface{}{"y": position.Y + 1, "x": position.X + 1} + return map[string]any{"y": position.Y + 1, "x": position.X + 1} }) return jsonFunc } |
