Skip to content

Commit

Permalink
inputer/inputer: Removed it
Browse files Browse the repository at this point in the history
  • Loading branch information
xescugc committed Feb 4, 2024
1 parent 8650e5e commit 922de4a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 174 deletions.
15 changes: 5 additions & 10 deletions client/hud.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/xescugc/go-flux"
"github.com/xescugc/maze-wars/action"
"github.com/xescugc/maze-wars/inputer"
"github.com/xescugc/maze-wars/store"
"github.com/xescugc/maze-wars/tower"
"github.com/xescugc/maze-wars/unit"
Expand All @@ -31,8 +30,6 @@ type HUDStore struct {

ui *ebitenui.UI

input inputer.Inputer

statsListW *widget.List
incomeTextW *widget.Text
winLoseTextW *widget.Text
Expand Down Expand Up @@ -84,11 +81,9 @@ func init() {
}

// NewHUDStore creates a new HUDStore with the Dispatcher d and the Game g
func NewHUDStore(d *flux.Dispatcher, i inputer.Inputer, g *Game) (*HUDStore, error) {
func NewHUDStore(d *flux.Dispatcher, g *Game) (*HUDStore, error) {
hs := &HUDStore{
game: g,

input: i,
}
hs.ReduceStore = flux.NewReduceStore(d, hs.Reduce, HUDState{
ShowStats: true,
Expand All @@ -104,7 +99,7 @@ func (hs *HUDStore) Update() error {

cs := hs.game.Camera.GetState().(CameraState)
hst := hs.GetState().(HUDState)
x, y := hs.input.CursorPosition()
x, y := ebiten.CursorPosition()
cp := hs.game.Store.Players.FindCurrent()
tws := hs.game.Store.Towers.List()
// Only send a CursorMove when the curso has actually moved
Expand All @@ -117,7 +112,7 @@ func (hs *HUDStore) Update() error {
if cp.Lives == 0 || cp.Winner {
return nil
}
if hs.input.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
clickAbsolute := utils.Object{
X: float64(x) + cs.X,
Y: float64(y) + cs.Y,
Expand Down Expand Up @@ -192,12 +187,12 @@ func (hs *HUDStore) Update() error {
actionDispatcher.GoHome()
}
if hst.TowerOpenMenuID != "" {
if hs.input.IsKeyJustPressed(ebiten.KeyEscape) {
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
actionDispatcher.CloseTowerMenu()
}
}
if hst.SelectedTower != nil {
if hs.input.IsMouseButtonJustPressed(ebiten.MouseButtonRight) || hs.input.IsKeyJustPressed(ebiten.KeyEscape) {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) || inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
actionDispatcher.DeselectTower(hst.SelectedTower.Type)
} else {
var invalid bool
Expand Down
7 changes: 1 addition & 6 deletions client/lobby.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/xescugc/go-flux"
"github.com/xescugc/maze-wars/action"
"github.com/xescugc/maze-wars/inputer"
)

var (
Expand All @@ -22,8 +21,6 @@ type LobbyStore struct {

Store *Store

input inputer.Inputer

ui *ebitenui.UI
textPlayersW *widget.Text
}
Expand All @@ -32,11 +29,9 @@ type LobbyState struct {
TotalUsers int
}

func NewLobbyStore(d *flux.Dispatcher, i inputer.Inputer, s *Store) (*LobbyStore, error) {
func NewLobbyStore(d *flux.Dispatcher, s *Store) (*LobbyStore, error) {
ls := &LobbyStore{
Store: s,

input: i,
}
ls.ReduceStore = flux.NewReduceStore(d, ls.Reduce, LobbyState{})

Expand Down
7 changes: 1 addition & 6 deletions client/sign_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/hajimehoshi/ebiten/v2/colorm"
"github.com/xescugc/go-flux"
"github.com/xescugc/maze-wars/action"
"github.com/xescugc/maze-wars/inputer"
"github.com/xescugc/maze-wars/store"
)

Expand All @@ -27,8 +26,6 @@ type SignUpStore struct {

Camera *CameraStore

input inputer.Inputer

ui *ebitenui.UI
inputErrorW *widget.Text
}
Expand All @@ -37,11 +34,9 @@ type SignUpState struct {
Error string
}

func NewSignUpStore(d *flux.Dispatcher, i inputer.Inputer, s *store.Store) (*SignUpStore, error) {
func NewSignUpStore(d *flux.Dispatcher, s *store.Store) (*SignUpStore, error) {
su := &SignUpStore{
Store: s,

input: i,
}
su.ReduceStore = flux.NewReduceStore(d, su.Reduce, SignUpState{})

Expand Down
9 changes: 3 additions & 6 deletions client/wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/xescugc/go-flux"
"github.com/xescugc/maze-wars/client"
"github.com/xescugc/maze-wars/inputer"
"github.com/xescugc/maze-wars/store"
)

Expand Down Expand Up @@ -45,8 +44,6 @@ func NewClient() js.Func {
Store: s,
}

i := inputer.NewEbiten()

// TODO: Change this to pass the specific store needed instead of all the game object
cs := client.NewCameraStore(d, s, screenW, screenH)
g.Camera = cs
Expand All @@ -60,7 +57,7 @@ func NewClient() js.Func {
return fmt.Errorf("failed to initialize Towers: %w", err)
}

g.HUD, err = client.NewHUDStore(d, i, g)
g.HUD, err = client.NewHUDStore(d, g)
if err != nil {
return fmt.Errorf("failed to initialize HUDStore: %w", err)
}
Expand All @@ -70,12 +67,12 @@ func NewClient() js.Func {
us := client.NewUserStore(d)
cls := client.NewStore(s, us)

l, err := client.NewLobbyStore(d, i, cls)
l, err := client.NewLobbyStore(d, cls)
if err != nil {
return fmt.Errorf("failed to initialize LobbyStore: %w", err)
}

u, err := client.NewSignUpStore(d, i, s)
u, err := client.NewSignUpStore(d, s)
if err != nil {
return fmt.Errorf("failed to initial SignUpStore: %w", err)
}
Expand Down
9 changes: 3 additions & 6 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/spf13/cobra"
"github.com/xescugc/go-flux"
"github.com/xescugc/maze-wars/client"
"github.com/xescugc/maze-wars/inputer"
"github.com/xescugc/maze-wars/store"
)

Expand Down Expand Up @@ -38,8 +37,6 @@ var (
Store: s,
}

i := inputer.NewEbiten()

// TODO: Change this to pass the specific store needed instead of all the game object
cs := client.NewCameraStore(d, s, screenW, screenH)
g.Camera = cs
Expand All @@ -53,7 +50,7 @@ var (
return fmt.Errorf("failed to initialize Towers: %w", err)
}

g.HUD, err = client.NewHUDStore(d, i, g)
g.HUD, err = client.NewHUDStore(d, g)
if err != nil {
return fmt.Errorf("failed to initialize HUDStore: %w", err)
}
Expand All @@ -63,12 +60,12 @@ var (
us := client.NewUserStore(d)
cls := client.NewStore(s, us)

l, err := client.NewLobbyStore(d, i, cls)
l, err := client.NewLobbyStore(d, cls)
if err != nil {
return fmt.Errorf("failed to initialize LobbyStore: %w", err)
}

su, err := client.NewSignUpStore(d, i, s)
su, err := client.NewSignUpStore(d, s)
if err != nil {
return fmt.Errorf("failed to initial SignUpStore: %w", err)
}
Expand Down
32 changes: 0 additions & 32 deletions inputer/inputer.go

This file was deleted.

55 changes: 25 additions & 30 deletions integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import (
"time"

"github.com/golang/mock/gomock"
"github.com/hajimehoshi/ebiten/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/xescugc/go-flux"
"github.com/xescugc/maze-wars/client"
"github.com/xescugc/maze-wars/mock"
"github.com/xescugc/maze-wars/server"
"github.com/xescugc/maze-wars/store"
)
Expand Down Expand Up @@ -71,8 +68,6 @@ func TestRun(t *testing.T) {
Store: s,
}

i := mock.NewMockInputer(ctrl)

cs := client.NewCameraStore(cd, s, screenW, screenH)
g.Camera = cs
g.Units, err = client.NewUnits(g)
Expand All @@ -81,18 +76,18 @@ func TestRun(t *testing.T) {
g.Towers, err = client.NewTowers(g)
require.NoError(t, err)

g.HUD, err = client.NewHUDStore(cd, i, g)
g.HUD, err = client.NewHUDStore(cd, g)
require.NoError(t, err)

us := client.NewUserStore(cd)
cls := client.NewStore(s, us)

l, err := client.NewLobbyStore(cd, i, cls)
l, err := client.NewLobbyStore(cd, cls)
require.NoError(t, err)

wr := client.NewWaitingRoomStore(cd, cls)

su, err := client.NewSignUpStore(cd, i, s)
su, err := client.NewSignUpStore(cd, s)
require.NoError(t, err)

rs := client.NewRouterStore(cd, su, l, wr, g)
Expand All @@ -105,15 +100,15 @@ func TestRun(t *testing.T) {
// be able to change the content of the expectations.
// That's where this parameters help, they can change the content
// of the expectation and what they return
var (
x, y int
//var (
//x, y int

mouseButtonJustPressed ebiten.MouseButton
returnMouseButtonJustPressed bool
//mouseButtonJustPressed ebiten.MouseButton
//returnMouseButtonJustPressed bool

keyJustPressed ebiten.Key
returnKeyJustPressed bool
)
//keyJustPressed ebiten.Key
//returnKeyJustPressed bool
//)
//resetDefault := func() {
//x, y = 0, 0
//mouseButtonJustPressed = 0
Expand All @@ -122,21 +117,21 @@ func TestRun(t *testing.T) {
//keyJustPressed = 0
//returnKeyJustPressed = false
//}
i.EXPECT().CursorPosition().DoAndReturn(func() (int, int) {
return x, y
}).AnyTimes()
i.EXPECT().IsMouseButtonJustPressed(gomock.Any()).DoAndReturn(func(button ebiten.MouseButton) bool {
if returnMouseButtonJustPressed {
assert.Equal(t, mouseButtonJustPressed, button)
}
return returnMouseButtonJustPressed
}).AnyTimes()
i.EXPECT().IsKeyJustPressed(gomock.Any()).DoAndReturn(func(key ebiten.Key) bool {
if returnKeyJustPressed {
assert.Equal(t, keyJustPressed, key)
}
return returnKeyJustPressed
}).AnyTimes()
//i.EXPECT().CursorPosition().DoAndReturn(func() (int, int) {
//return x, y
//}).AnyTimes()
//i.EXPECT().IsMouseButtonJustPressed(gomock.Any()).DoAndReturn(func(button ebiten.MouseButton) bool {
//if returnMouseButtonJustPressed {
//assert.Equal(t, mouseButtonJustPressed, button)
//}
//return returnMouseButtonJustPressed
//}).AnyTimes()
//i.EXPECT().IsKeyJustPressed(gomock.Any()).DoAndReturn(func(key ebiten.Key) bool {
//if returnKeyJustPressed {
//assert.Equal(t, keyJustPressed, key)
//}
//return returnKeyJustPressed
//}).AnyTimes()

ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
Expand Down
Loading

0 comments on commit 922de4a

Please sign in to comment.