Eliminating duplication of information in PlayerData
Attempting to eliminate race condition of u.CurCard
Change-Id: Icadd8fb9db6ab58496e6b98beaaaaceea96e0d1a
diff --git a/go/src/hearts/img/reposition/reposition.go b/go/src/hearts/img/reposition/reposition.go
index 9d894b1..3f2a477 100644
--- a/go/src/hearts/img/reposition/reposition.go
+++ b/go/src/hearts/img/reposition/reposition.go
@@ -228,6 +228,9 @@
// Animation for the 'play' action, when app is in the hand view
func AnimateHandCardPlay(ch chan bool, animCard *card.Card, u *uistate.UIState) {
+ for _, o := range u.Other {
+ BringNodeToFront(o.GetNode(), u)
+ }
imgs := []*staticimg.StaticImg{u.BackgroundImgs[0], u.DropTargets[0]}
for _, i := range imgs {
dims := i.GetDimensions()
@@ -254,7 +257,7 @@
dropTarget := u.DropTargets[(player-u.CurPlayerIndex+u.NumPlayers)%u.NumPlayers]
toPos := dropTarget.GetCurrent()
toDim := dropTarget.GetDimensions()
- texture.PopulateCardImage(c, u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(c, u)
switch player {
case (u.CurPlayerIndex + 1) % u.NumPlayers:
c.Move(coords.MakeVec(-toDim.X, 0), toDim, u.Eng)
@@ -341,13 +344,13 @@
func determineDestination(animCard *card.Card, dir direction.Direction, windowSize *coords.Vec) *coords.Vec {
switch dir {
case direction.Right:
- return coords.MakeVec(windowSize.X+2*animCard.GetDimensions().X, animCard.GetCurrent().Y)
+ return coords.MakeVec(animCard.GetCurrent().X+windowSize.X, animCard.GetCurrent().Y)
case direction.Left:
- return coords.MakeVec(0-2*animCard.GetDimensions().X, animCard.GetCurrent().Y)
+ return coords.MakeVec(animCard.GetCurrent().X-windowSize.X, animCard.GetCurrent().Y)
case direction.Across:
- return coords.MakeVec(animCard.GetCurrent().X, 0-2*animCard.GetDimensions().Y)
+ return coords.MakeVec(animCard.GetCurrent().X, animCard.GetCurrent().Y-windowSize.Y)
case direction.Down:
- return coords.MakeVec(animCard.GetCurrent().X, windowSize.Y+2*animCard.GetDimensions().Y)
+ return coords.MakeVec(animCard.GetCurrent().X, animCard.GetCurrent().Y+windowSize.Y)
// Should not occur
default:
return coords.MakeVec(-1, -1)
@@ -356,6 +359,9 @@
// Animation for when a trick is taken, when app is in the table view
func AnimateTableCardTakeTrick(cards []*card.Card, dir direction.Direction, quit chan bool, u *uistate.UIState) {
+ for _, c := range cards {
+ BringNodeToFront(c.GetNode(), u)
+ }
for i, animCard := range cards {
destination := determineDestination(animCard, dir, u.WindowSize)
if i < len(cards)-1 {
@@ -521,6 +527,11 @@
}
}
+func BringNodeToFront(n *sprite.Node, u *uistate.UIState) {
+ u.Scene.RemoveChild(n)
+ u.Scene.AppendChild(n)
+}
+
func SwitchOnChan(animChan, quitChan chan bool, f func(), u *uistate.UIState) {
select {
case <-quitChan:
diff --git a/go/src/hearts/img/texture/texture.go b/go/src/hearts/img/texture/texture.go
index 08c3fff..08e752b 100644
--- a/go/src/hearts/img/texture/texture.go
+++ b/go/src/hearts/img/texture/texture.go
@@ -24,7 +24,7 @@
)
// Given a card object, populates it with its image
-func PopulateCardImage(c *card.Card, texs map[string]sprite.SubTex, eng sprite.Engine, scene *sprite.Node) {
+func PopulateCardImage(c *card.Card, u *uistate.UIState) {
var texKey string
switch c.GetSuit() {
case card.Club:
@@ -49,11 +49,11 @@
texKey += strconv.Itoa(int(c.GetFace()))
}
texKey += ".png"
- n := MakeNode(eng, scene)
- eng.SetSubTex(n, texs[texKey])
+ n := MakeNode(u)
+ u.Eng.SetSubTex(n, u.Texs[texKey])
c.SetNode(n)
- c.SetImage(texs[texKey])
- c.SetBack(texs["BakuSquare.png"])
+ c.SetImage(u.Texs[texKey])
+ c.SetBack(u.Texs["BakuSquare.png"])
}
// Returns array of textures which make up a string
@@ -117,9 +117,9 @@
dims := subTexDims.DividedBy(scaler)
var textImg *staticimg.StaticImg
if len(altTexs) == 0 {
- textImg = MakeImgWithoutAlt(img, start, dims, u.Eng, u.Scene)
+ textImg = MakeImgWithoutAlt(img, start, dims, u)
} else {
- textImg = MakeImgWithAlt(img, altTexs[i], start, dims, displayColor, u.Eng, u.Scene)
+ textImg = MakeImgWithAlt(img, altTexs[i], start, dims, displayColor, u)
}
allImgs = append(allImgs, textImg)
start = coords.MakeVec(start.X+dims.X, start.Y)
@@ -156,9 +156,9 @@
end = coords.MakeVec(end.X-dims.X, end.Y)
var textImg *staticimg.StaticImg
if len(altTexs) == 0 {
- textImg = MakeImgWithoutAlt(img, end, dims, u.Eng, u.Scene)
+ textImg = MakeImgWithoutAlt(img, end, dims, u)
} else {
- textImg = MakeImgWithAlt(img, altTexs[i], end, dims, displayColor, u.Eng, u.Scene)
+ textImg = MakeImgWithAlt(img, altTexs[i], end, dims, displayColor, u)
}
allImgs = append(allImgs, textImg)
}
@@ -187,31 +187,24 @@
}
// Returns a new StaticImg instance with desired image and dimensions
-func MakeImgWithoutAlt(t sprite.SubTex,
- current, dim *coords.Vec,
- eng sprite.Engine,
- scene *sprite.Node) *staticimg.StaticImg {
- n := MakeNode(eng, scene)
- eng.SetSubTex(n, t)
+func MakeImgWithoutAlt(t sprite.SubTex, current, dim *coords.Vec, u *uistate.UIState) *staticimg.StaticImg {
+ n := MakeNode(u)
+ u.Eng.SetSubTex(n, t)
s := staticimg.MakeStaticImg()
s.SetNode(n)
s.SetImage(t)
s.SetInitial(current)
- s.Move(current, dim, eng)
+ s.Move(current, dim, u.Eng)
return s
}
// Returns a new StaticImg instance with desired image and dimensions
// Also includes an alternate image. If displayImage is true, image will be displayed. Else, alt will be displayed.
-func MakeImgWithAlt(t, alt sprite.SubTex,
- current, dim *coords.Vec,
- displayImage bool,
- eng sprite.Engine,
- scene *sprite.Node) *staticimg.StaticImg {
- s := MakeImgWithoutAlt(t, current, dim, eng, scene)
+func MakeImgWithAlt(t, alt sprite.SubTex, current, dim *coords.Vec, displayImage bool, u *uistate.UIState) *staticimg.StaticImg {
+ s := MakeImgWithoutAlt(t, current, dim, u)
s.SetAlt(alt)
if !displayImage {
- eng.SetSubTex(s.GetNode(), alt)
+ u.Eng.SetSubTex(s.GetNode(), alt)
s.SetDisplayingImage(false)
} else {
s.SetDisplayingImage(true)
@@ -318,9 +311,9 @@
// Returns a new sprite node
// NOTE: Currently, this is a public method, as it is useful in testing. Eventually it should be made private.
-func MakeNode(eng sprite.Engine, scene *sprite.Node) *sprite.Node {
+func MakeNode(u *uistate.UIState) *sprite.Node {
n := &sprite.Node{}
- eng.Register(n)
- scene.AppendChild(n)
+ u.Eng.Register(n)
+ u.Scene.AppendChild(n)
return n
}
diff --git a/go/src/hearts/img/uistate/uistate.go b/go/src/hearts/img/uistate/uistate.go
index 441b7b8..d9c405e 100644
--- a/go/src/hearts/img/uistate/uistate.go
+++ b/go/src/hearts/img/uistate/uistate.go
@@ -37,6 +37,12 @@
)
const (
+ Avatar string = "avatar"
+ Name string = "name"
+ Device string = "device"
+)
+
+const (
numPlayers int = 4
numSuits int = 4
cardSize float32 = 35
@@ -88,7 +94,7 @@
GameID int // used to differentiate between concurrent games
IsOwner bool // true if this player is the game creator
UserData map[int]map[string]interface{} // user data indexed by user ID
- PlayerData map[int]map[string]interface{} // user data indexed by player number
+ PlayerData map[int]int // key = player number, value = user id
AnimChans []chan bool // keeps track of all 'quit' channels in animations so their goroutines can be stopped
SGChan chan bool // pass in a bool to stop advertising the syncgroup
ScanChan chan bool // pass in a bool to stop scanning for syncgroups
@@ -119,9 +125,36 @@
Padding: float32(5),
CurView: None,
Done: false,
- Debug: false,
- UserData: make(map[int]map[string]interface{}, 0),
- PlayerData: make(map[int]map[string]interface{}, 0),
+ Debug: true,
+ UserData: make(map[int]map[string]interface{}),
+ PlayerData: make(map[int]int),
AnimChans: make([]chan bool, 0),
}
}
+
+func GetAvatar(playerNum int, u *UIState) sprite.SubTex {
+ blankTex := u.Texs["Heart.png"]
+ userID := u.PlayerData[playerNum]
+ if u.UserData[userID][Avatar] == nil {
+ return blankTex
+ }
+ return u.Texs[u.UserData[userID][Avatar].(string)]
+}
+
+func GetName(playerNum int, u *UIState) string {
+ emptyString := ""
+ userID := u.PlayerData[playerNum]
+ if u.UserData[userID][Name] == nil {
+ return emptyString
+ }
+ return u.UserData[userID][Name].(string)
+}
+
+func GetDevice(playerNum int, u *UIState) sprite.SubTex {
+ blankTex := u.Texs["laptop.png"]
+ userID := u.PlayerData[playerNum]
+ if u.UserData[userID][Device] == nil {
+ return blankTex
+ }
+ return u.Texs[u.UserData[userID][Device].(string)]
+}
diff --git a/go/src/hearts/img/view/view.go b/go/src/hearts/img/view/view.go
index 9718992..2242d1f 100644
--- a/go/src/hearts/img/view/view.go
+++ b/go/src/hearts/img/view/view.go
@@ -42,47 +42,43 @@
nilDim := coords.MakeVec(0, 0)
// player 0 seat
sitPos := coords.MakeVec((u.WindowSize.X-arrangeDim.X)/2, u.WindowSize.Y-arrangeDim.Y-2*u.Padding)
- if u.PlayerData[0] == nil {
- u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, arrangeDim, u.Eng, u.Scene))
+ if u.PlayerData[0] == 0 {
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, arrangeDim, u))
} else {
- u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, nilDim, u.Eng, u.Scene))
- avatarKey := u.PlayerData[0]["avatar"].(string)
- avatar := u.Texs[avatarKey]
- u.BackgroundImgs = append(u.BackgroundImgs, texture.MakeImgWithoutAlt(avatar, sitPos, arrangeDim, u.Eng, u.Scene))
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, nilDim, u))
+ avatar := uistate.GetAvatar(0, u)
+ u.BackgroundImgs = append(u.BackgroundImgs, texture.MakeImgWithoutAlt(avatar, sitPos, arrangeDim, u))
}
// player 1 seat
sitPos = coords.MakeVec((u.WindowSize.X-arrangeDim.X)/2-arrangeDim.X-2*u.Padding, u.WindowSize.Y-2*arrangeDim.Y-4*u.Padding)
- if u.PlayerData[1] == nil {
- u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, arrangeDim, u.Eng, u.Scene))
+ if u.PlayerData[1] == 0 {
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, arrangeDim, u))
} else {
- u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, nilDim, u.Eng, u.Scene))
- avatarKey := u.PlayerData[1]["avatar"].(string)
- avatar := u.Texs[avatarKey]
- u.BackgroundImgs = append(u.BackgroundImgs, texture.MakeImgWithoutAlt(avatar, sitPos, arrangeDim, u.Eng, u.Scene))
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, nilDim, u))
+ avatar := uistate.GetAvatar(0, u)
+ u.BackgroundImgs = append(u.BackgroundImgs, texture.MakeImgWithoutAlt(avatar, sitPos, arrangeDim, u))
}
// player 2 seat
- sitPos = coords.MakeVec((u.WindowSize.X-arrangeDim.X-2*u.Padding)/2, u.WindowSize.Y-3*arrangeDim.Y-6*u.Padding)
- if u.PlayerData[2] == nil {
- u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, arrangeDim, u.Eng, u.Scene))
+ sitPos = coords.MakeVec((u.WindowSize.X-arrangeDim.X)/2, u.WindowSize.Y-3*arrangeDim.Y-6*u.Padding)
+ if u.PlayerData[2] == 0 {
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, arrangeDim, u))
} else {
- u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, nilDim, u.Eng, u.Scene))
- avatarKey := u.PlayerData[2]["avatar"].(string)
- avatar := u.Texs[avatarKey]
- u.BackgroundImgs = append(u.BackgroundImgs, texture.MakeImgWithoutAlt(avatar, sitPos, arrangeDim, u.Eng, u.Scene))
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, nilDim, u))
+ avatar := uistate.GetAvatar(0, u)
+ u.BackgroundImgs = append(u.BackgroundImgs, texture.MakeImgWithoutAlt(avatar, sitPos, arrangeDim, u))
}
// player 3 seat
sitPos = coords.MakeVec((u.WindowSize.X-arrangeDim.X)/2+arrangeDim.X+2*u.Padding, u.WindowSize.Y-2*arrangeDim.Y-4*u.Padding)
- if u.PlayerData[3] == nil {
- u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, arrangeDim, u.Eng, u.Scene))
+ if u.PlayerData[3] == 0 {
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, arrangeDim, u))
} else {
- u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, nilDim, u.Eng, u.Scene))
- avatarKey := u.PlayerData[3]["avatar"].(string)
- avatar := u.Texs[avatarKey]
- u.BackgroundImgs = append(u.BackgroundImgs, texture.MakeImgWithoutAlt(avatar, sitPos, arrangeDim, u.Eng, u.Scene))
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(sitImg, sitPos, nilDim, u))
+ avatar := uistate.GetAvatar(0, u)
+ u.BackgroundImgs = append(u.BackgroundImgs, texture.MakeImgWithoutAlt(avatar, sitPos, arrangeDim, u))
}
// table
watchPos := coords.MakeVec((u.WindowSize.X-arrangeDim.X)/2, u.WindowSize.Y-2*arrangeDim.Y-4*u.Padding)
- u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(watchImg, watchPos, arrangeDim, u.Eng, u.Scene))
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(watchImg, watchPos, arrangeDim, u))
}
// Waiting view: Displays the word "Waiting". To be displayed when players are waiting for a new round to be dealt
@@ -109,14 +105,14 @@
newGameImg := u.Texs["NewGame.png"]
newGameDim := coords.MakeVec(2*u.CardDim.X, u.CardDim.Y)
newGamePos := coords.MakeVec((u.WindowSize.X-newGameDim.X)/2, u.TopPadding)
- u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(newGameImg, newGamePos, newGameDim, u.Eng, u.Scene))
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(newGameImg, newGamePos, newGameDim, u))
buttonNum := 1
go func() {
for u.CurView == uistate.Discovery {
sgSet := <-discChan
joinGameImg := u.Texs["JoinGame.png"]
joinGamePos := coords.MakeVec(newGamePos.X, newGamePos.Y+float32(buttonNum)*(newGameDim.Y+u.Padding))
- u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(joinGameImg, joinGamePos, newGameDim, u.Eng, u.Scene))
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(joinGameImg, joinGamePos, newGameDim, u))
u.Buttons[buttonNum].SetInfo(sgSet)
buttonNum++
}
@@ -144,11 +140,11 @@
}
dropTargetPos := coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u))
// card on top of first drop target
dropCard := u.CurTable.GetTrick()[0]
if dropCard != nil {
- texture.PopulateCardImage(dropCard, u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(dropCard, u)
dropCard.Move(dropTargetPos, dropTargetDimensions, u.Eng)
u.Cards = append(u.Cards, dropCard)
}
@@ -161,11 +157,11 @@
}
dropTargetPos = coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u))
// card on top of second drop target
dropCard = u.CurTable.GetTrick()[1]
if dropCard != nil {
- texture.PopulateCardImage(dropCard, u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(dropCard, u)
dropCard.Move(dropTargetPos, dropTargetDimensions, u.Eng)
u.Cards = append(u.Cards, dropCard)
}
@@ -178,11 +174,11 @@
}
dropTargetPos = coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u))
// card on top of third drop target
dropCard = u.CurTable.GetTrick()[2]
if dropCard != nil {
- texture.PopulateCardImage(dropCard, u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(dropCard, u)
dropCard.Move(dropTargetPos, dropTargetDimensions, u.Eng)
u.Cards = append(u.Cards, dropCard)
}
@@ -195,40 +191,41 @@
}
dropTargetPos = coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u))
// card on top of fourth drop target
dropCard = u.CurTable.GetTrick()[3]
if dropCard != nil {
- texture.PopulateCardImage(dropCard, u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(dropCard, u)
dropCard.Move(dropTargetPos, dropTargetDimensions, u.Eng)
u.Cards = append(u.Cards, dropCard)
}
// adding 4 player icons, text, and device icons
- playerIconImage := u.CurTable.GetPlayers()[0].GetIconImage()
+ playerIconImage := uistate.GetAvatar(0, u)
playerIconX := (u.WindowSize.X - u.PlayerIconDim.X) / 2
playerIconY := u.WindowSize.Y - u.TableCardDim.Y - u.BottomPadding - u.Padding - u.PlayerIconDim.Y
playerIconPos := coords.MakeVec(playerIconX, playerIconY)
if u.Debug {
u.Buttons = append(u.Buttons,
- texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u))
} else {
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u))
}
// player 0's name
center := coords.MakeVec(playerIconX+u.PlayerIconDim.X/2, playerIconY-30)
- textImgs := texture.MakeStringImgCenterAlign(u.CurTable.GetPlayers()[0].GetName(), "", "", true, center, scaler, maxWidth, u)
+ name := uistate.GetName(0, u)
+ textImgs := texture.MakeStringImgCenterAlign(name, "", "", true, center, scaler, maxWidth, u)
for _, img := range textImgs {
u.BackgroundImgs = append(u.BackgroundImgs, img)
}
// player 0's device icon
- deviceIconImage := u.CurTable.GetPlayers()[0].GetDeviceImage()
+ deviceIconImage := uistate.GetDevice(0, u)
deviceIconDim := u.PlayerIconDim.DividedBy(2)
deviceIconPos := coords.MakeVec(playerIconPos.X+u.PlayerIconDim.X, playerIconPos.Y)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u))
// player 1's icon
- playerIconImage = u.CurTable.GetPlayers()[1].GetIconImage()
+ playerIconImage = uistate.GetAvatar(1, u)
playerIconX = u.BottomPadding
playerIconY = (u.WindowSize.Y+2*u.BottomPadding+u.PlayerIconDim.Y-
(float32(len(u.CurTable.GetPlayers()[1].GetHand()))*
@@ -237,47 +234,49 @@
playerIconPos = coords.MakeVec(playerIconX, playerIconY)
if u.Debug {
u.Buttons = append(u.Buttons,
- texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u))
} else {
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u))
}
// player 1's name
start := coords.MakeVec(playerIconX, playerIconY-30)
- textImgs = texture.MakeStringImgLeftAlign(u.CurTable.GetPlayers()[1].GetName(), "", "", true, start, scaler, maxWidth, u)
+ name = uistate.GetName(1, u)
+ textImgs = texture.MakeStringImgLeftAlign(name, "", "", true, start, scaler, maxWidth, u)
for _, img := range textImgs {
u.BackgroundImgs = append(u.BackgroundImgs, img)
}
// player 1's device icon
- deviceIconImage = u.CurTable.GetPlayers()[1].GetDeviceImage()
+ deviceIconImage = uistate.GetDevice(1, u)
deviceIconPos = coords.MakeVec(playerIconPos.X+u.PlayerIconDim.X, playerIconPos.Y+u.PlayerIconDim.Y-deviceIconDim.Y)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u))
// player 2's icon
- playerIconImage = u.CurTable.GetPlayers()[2].GetIconImage()
+ playerIconImage = uistate.GetAvatar(2, u)
playerIconX = (u.WindowSize.X - u.PlayerIconDim.X) / 2
playerIconY = u.TopPadding + u.TableCardDim.Y + u.Padding
playerIconPos = coords.MakeVec(playerIconX, playerIconY)
if u.Debug {
u.Buttons = append(u.Buttons,
- texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u))
} else {
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u))
}
// player 2's name
center = coords.MakeVec(playerIconX+u.PlayerIconDim.X/2, playerIconY+u.PlayerIconDim.Y+5)
- textImgs = texture.MakeStringImgCenterAlign(u.CurTable.GetPlayers()[2].GetName(), "", "", true, center, scaler, maxWidth, u)
+ name = uistate.GetName(2, u)
+ textImgs = texture.MakeStringImgCenterAlign(name, "", "", true, center, scaler, maxWidth, u)
for _, img := range textImgs {
u.BackgroundImgs = append(u.BackgroundImgs, img)
}
// player 2's device icon
- deviceIconImage = u.CurTable.GetPlayers()[2].GetDeviceImage()
+ deviceIconImage = uistate.GetDevice(2, u)
deviceIconPos = coords.MakeVec(playerIconPos.X+u.PlayerIconDim.X, playerIconPos.Y+u.PlayerIconDim.Y-deviceIconDim.Y)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u))
// player 3's icon
- playerIconImage = u.CurTable.GetPlayers()[3].GetIconImage()
+ playerIconImage = uistate.GetAvatar(3, u)
playerIconX = u.WindowSize.X - u.BottomPadding - u.PlayerIconDim.X
playerIconY = (u.WindowSize.Y+2*u.BottomPadding+u.PlayerIconDim.Y-
(float32(len(u.CurTable.GetPlayers()[3].GetHand()))*
@@ -286,28 +285,29 @@
playerIconPos = coords.MakeVec(playerIconX, playerIconY)
if u.Debug {
u.Buttons = append(u.Buttons,
- texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u))
} else {
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u))
}
// player 3's name
end := coords.MakeVec(playerIconX+u.PlayerIconDim.X, playerIconY-30)
- textImgs = texture.MakeStringImgRightAlign(u.CurTable.GetPlayers()[3].GetName(), "", "", true, end, scaler, maxWidth, u)
+ name = uistate.GetName(3, u)
+ textImgs = texture.MakeStringImgRightAlign(name, "", "", true, end, scaler, maxWidth, u)
for _, img := range textImgs {
u.BackgroundImgs = append(u.BackgroundImgs, img)
}
// player 3's device icon
- deviceIconImage = u.CurTable.GetPlayers()[3].GetDeviceImage()
+ deviceIconImage = uistate.GetDevice(3, u)
deviceIconPos = coords.MakeVec(playerIconPos.X-deviceIconDim.X, playerIconPos.Y+u.PlayerIconDim.Y-deviceIconDim.Y)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u))
//adding cards
for _, p := range u.CurTable.GetPlayers() {
// cards in hand
hand := p.GetHand()
for i, c := range hand {
- texture.PopulateCardImage(c, u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(c, u)
cardIndex := coords.MakeVec(float32(len(hand)), float32(i))
reposition.SetCardPositionTable(c, p.GetPlayerIndex(), cardIndex, u)
u.Eng.SetSubTex(c.GetNode(), c.GetBack())
@@ -329,7 +329,7 @@
initial := reposition.CardPositionTable(passer, cardIndexVec, u)
c.SetInitial(initial)
if !p.GetDoneTaking() {
- texture.PopulateCardImage(c, u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(c, u)
c.SetBackDisplay(u.Eng)
pos := reposition.DetermineTablePassPosition(c, i, p.GetPlayerIndex(), u)
c.Move(pos, u.TableCardDim, u.Eng)
@@ -463,15 +463,15 @@
}
dropTargetPos := coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u))
// first player icon
- playerIconImage := u.CurTable.GetPlayers()[u.CurPlayerIndex].GetIconImage()
+ playerIconImage := uistate.GetAvatar(u.CurPlayerIndex, u)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(playerIconImage, dropTargetPos.Plus(2), playerIconDimensions, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, dropTargetPos.Plus(2), playerIconDimensions, u))
// card on top of first drop target
dropCard := u.CurTable.GetTrick()[u.CurPlayerIndex]
if dropCard != nil {
- texture.PopulateCardImage(dropCard, u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(dropCard, u)
dropCard.Move(dropTargetPos, dropTargetDimensions, u.Eng)
u.TableCards = append(u.TableCards, dropCard)
}
@@ -483,15 +483,15 @@
dropTargetX = splitWindowSize.X/2 - 3*u.CardDim.X/2 - u.Padding
dropTargetPos = coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u))
// second player icon
- playerIconImage = u.CurTable.GetPlayers()[(u.CurPlayerIndex+1)%len(u.CurTable.GetPlayers())].GetIconImage()
+ playerIconImage = uistate.GetAvatar((u.CurPlayerIndex+1)%u.NumPlayers, u)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(playerIconImage, dropTargetPos.Plus(2), playerIconDimensions, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, dropTargetPos.Plus(2), playerIconDimensions, u))
// card on top of second drop target
dropCard = u.CurTable.GetTrick()[(u.CurPlayerIndex+1)%len(u.CurTable.GetPlayers())]
if dropCard != nil {
- texture.PopulateCardImage(dropCard, u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(dropCard, u)
dropCard.Move(dropTargetPos, dropTargetDimensions, u.Eng)
u.TableCards = append(u.TableCards, dropCard)
}
@@ -503,15 +503,15 @@
}
dropTargetPos = coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u))
// third player icon
- playerIconImage = u.CurTable.GetPlayers()[(u.CurPlayerIndex+2)%len(u.CurTable.GetPlayers())].GetIconImage()
+ playerIconImage = uistate.GetAvatar((u.CurPlayerIndex+2)%u.NumPlayers, u)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(playerIconImage, dropTargetPos.Plus(2), playerIconDimensions, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, dropTargetPos.Plus(2), playerIconDimensions, u))
// card on top of third drop target
dropCard = u.CurTable.GetTrick()[(u.CurPlayerIndex+2)%len(u.CurTable.GetPlayers())]
if dropCard != nil {
- texture.PopulateCardImage(dropCard, u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(dropCard, u)
dropCard.Move(dropTargetPos, dropTargetDimensions, u.Eng)
u.TableCards = append(u.TableCards, dropCard)
}
@@ -523,15 +523,15 @@
dropTargetX = splitWindowSize.X/2 + u.CardDim.X/2 + u.Padding
dropTargetPos = coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u))
// fourth player icon
- playerIconImage = u.CurTable.GetPlayers()[(u.CurPlayerIndex+3)%len(u.CurTable.GetPlayers())].GetIconImage()
+ playerIconImage = uistate.GetAvatar((u.CurPlayerIndex+3)%u.NumPlayers, u)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(playerIconImage, dropTargetPos.Plus(2), playerIconDimensions, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, dropTargetPos.Plus(2), playerIconDimensions, u))
// card on top of fourth drop target
dropCard = u.CurTable.GetTrick()[(u.CurPlayerIndex+3)%len(u.CurTable.GetPlayers())]
if dropCard != nil {
- texture.PopulateCardImage(dropCard, u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(dropCard, u)
dropCard.Move(dropTargetPos, dropTargetDimensions, u.Eng)
u.TableCards = append(u.TableCards, dropCard)
}
@@ -546,7 +546,7 @@
} else if playerTurnNum == u.CurPlayerIndex {
turnText = "Your turn"
} else {
- name := u.CurTable.GetPlayers()[playerTurnNum].GetName()
+ name := uistate.GetName(playerTurnNum, u)
turnText = name + "'s turn"
}
return turnText
@@ -558,7 +558,7 @@
headerPos := coords.MakeVec(0, -10)
headerDimensions := coords.MakeVec(u.WindowSize.X, u.TopPadding+float32(20))
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(headerImage, headerPos, headerDimensions, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(headerImage, headerPos, headerDimensions, u))
}
func addPlayHeader(message string, beforeSplitAnimation bool, u *uistate.UIState) {
@@ -575,13 +575,13 @@
headerPos = coords.MakeVec(0, topOfHand-headerDimensions.Y-u.Padding)
}
u.Other = append(u.Other,
- texture.MakeImgWithoutAlt(headerImage, headerPos, headerDimensions, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(headerImage, headerPos, headerDimensions, u))
// adding pull tab
pullTabImage := u.Texs["HorizontalPullTab.png"]
pullTabDim := u.CardDim.DividedBy(2)
pullTabPos := headerPos.PlusVec(headerDimensions).MinusVec(pullTabDim).Minus(u.Padding)
u.Buttons = append(u.Buttons,
- texture.MakeImgWithoutAlt(pullTabImage, pullTabPos, pullTabDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(pullTabImage, pullTabPos, pullTabDim, u))
// adding text
color := "DBlue"
scaler := float32(4)
@@ -598,12 +598,12 @@
blueRectDim := coords.MakeVec(u.WindowSize.X-4*u.BottomPadding, topOfHand+u.CardDim.Y)
blueRectPos := coords.MakeVec(2*u.BottomPadding, -blueRectDim.Y)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(blueRectImg, blueRectPos, blueRectDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(blueRectImg, blueRectPos, blueRectDim, u))
// adding drop target
dropTargetImg := u.Texs["trickDrop.png"]
dropTargetPos := coords.MakeVec(u.WindowSize.X/2-u.CardDim.X/2, -u.CardDim.Y-3*u.Padding)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithoutAlt(dropTargetImg, dropTargetPos, u.CardDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(dropTargetImg, dropTargetPos, u.CardDim, u))
}
func addGrayPassBar(u *uistate.UIState) {
@@ -613,7 +613,7 @@
grayBarDim := u.WindowSize.Minus(4 * u.BottomPadding)
grayBarPos := coords.MakeVec(2*u.BottomPadding, 40-grayBarDim.Y+u.TopPadding)
u.Other = append(u.Other,
- texture.MakeImgWithAlt(grayBarImg, blueBarImg, grayBarPos, grayBarDim, true, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(grayBarImg, blueBarImg, grayBarPos, grayBarDim, true, u))
// adding name
var receivingPlayer int
switch u.CurTable.GetDir() {
@@ -624,12 +624,12 @@
case direction.Across:
receivingPlayer = (u.CurPlayerIndex + 2) % u.NumPlayers
}
- name := u.CurTable.GetPlayers()[receivingPlayer].GetName()
+ name := uistate.GetName(receivingPlayer, u)
color := "Gray"
altColor := "LBlue"
center := coords.MakeVec(u.WindowSize.X/2, u.TopPadding+5)
scaler := float32(3)
- maxWidth := u.WindowSize.X
+ maxWidth := grayBarDim.X
nameImgs := texture.MakeStringImgCenterAlign(name, color, altColor, true, center, scaler, maxWidth, u)
u.Other = append(u.Other, nameImgs...)
}
@@ -650,7 +650,7 @@
grayBarDim := coords.MakeVec(u.WindowSize.X-4*u.BottomPadding, grayBarHeight)
grayBarPos := coords.MakeVec(2*u.BottomPadding, -u.WindowSize.Y-20)
u.Other = append(u.Other,
- texture.MakeImgWithAlt(grayBarImg, grayBarAlt, grayBarPos, grayBarDim, display, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(grayBarImg, grayBarAlt, grayBarPos, grayBarDim, display, u))
// adding name
var passingPlayer int
switch u.CurTable.GetDir() {
@@ -661,13 +661,13 @@
case direction.Across:
passingPlayer = (u.CurPlayerIndex + 2) % u.NumPlayers
}
- name := u.CurTable.GetPlayers()[passingPlayer].GetName()
+ name := uistate.GetName(passingPlayer, u)
color := "Gray"
nameAltColor := "LBlue"
awaitingAltColor := "None"
center := coords.MakeVec(u.WindowSize.X/2, 20-u.WindowSize.Y)
scaler := float32(3)
- maxWidth := u.WindowSize.X
+ maxWidth := grayBarDim.X
u.Other = append(u.Other,
texture.MakeStringImgCenterAlign(name, color, nameAltColor, display, center, scaler, maxWidth, u)...)
center = coords.MakeVec(center.X, center.Y+30)
@@ -693,7 +693,7 @@
reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
// invisible drop target holding card
var emptyTex sprite.SubTex
- d := texture.MakeImgWithoutAlt(emptyTex, cardPos, u.CardDim, u.Eng, u.Scene)
+ d := texture.MakeImgWithoutAlt(emptyTex, cardPos, u.CardDim, u)
d.SetCardHere(c)
u.DropTargets = append(u.DropTargets, d)
}
@@ -707,14 +707,14 @@
passBannerPos := coords.MakeVec(6*u.BottomPadding, topOfHand-(2*u.Padding))
passBannerDim := coords.MakeVec(u.WindowSize.X-8*u.BottomPadding, u.CardDim.Y+2*u.Padding)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(passBannerImage, passBannerPos, passBannerDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(passBannerImage, passBannerPos, passBannerDim, u))
// adding undisplayed pull tab
pullTabSpotImage := u.Texs["Rectangle-LBlue.png"]
pullTabImage := u.Texs["VerticalPullTab.png"]
pullTabSpotPos := coords.MakeVec(2*u.BottomPadding, passBannerPos.Y)
pullTabSpotDim := coords.MakeVec(4*u.BottomPadding, u.CardDim.Y+2*u.Padding)
u.Buttons = append(u.Buttons,
- texture.MakeImgWithAlt(pullTabImage, pullTabSpotImage, pullTabSpotPos, pullTabSpotDim, false, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(pullTabImage, pullTabSpotImage, pullTabSpotPos, pullTabSpotDim, false, u))
// adding text
textLeft := coords.MakeVec(pullTabSpotPos.X+pullTabSpotDim.X/2, passBannerPos.Y-20)
scaler := float32(5)
@@ -730,7 +730,7 @@
dropTargetX := dropTargetXStart + float32(i)*(u.Padding+u.CardDim.X)
dropTargetPos := coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, u.CardDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, u.CardDim, u))
}
}
@@ -765,7 +765,7 @@
suitBannerY := u.WindowSize.Y - float32(i+1)*(u.CardDim.Y+u.Padding) - (2 * u.Padding / 5) - u.BottomPadding
suitBannerPos := coords.MakeVec(suitBannerX, suitBannerY)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(suitBannerImage, suitBannerPos, suitBannerDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(suitBannerImage, suitBannerPos, suitBannerDim, u))
}
// adding suit image to any empty suit in hand
for i, c := range suitCounts {
@@ -788,30 +788,30 @@
suitIconPos := coords.MakeVec(suitIconX, suitIconY)
suitIconDim := u.CardDim.Times(2).DividedBy(3)
u.EmptySuitImgs = append(u.EmptySuitImgs,
- texture.MakeImgWithAlt(suitIconImage, suitIconAlt, suitIconPos, suitIconDim, display, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(suitIconImage, suitIconAlt, suitIconPos, suitIconDim, display, u))
}
// adding clubs
for i := 0; i < clubCount; i++ {
numInSuit := i
- texture.PopulateCardImage(u.Cards[i], u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(u.Cards[i], u)
reposition.SetCardPositionHand(u.Cards[i], numInSuit, suitCounts, u)
}
// adding diamonds
for i := clubCount; i < clubCount+diamondCount; i++ {
numInSuit := i - clubCount
- texture.PopulateCardImage(u.Cards[i], u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(u.Cards[i], u)
reposition.SetCardPositionHand(u.Cards[i], numInSuit, suitCounts, u)
}
// adding spades
for i := clubCount + diamondCount; i < clubCount+diamondCount+spadeCount; i++ {
numInSuit := i - clubCount - diamondCount
- texture.PopulateCardImage(u.Cards[i], u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(u.Cards[i], u)
reposition.SetCardPositionHand(u.Cards[i], numInSuit, suitCounts, u)
}
// adding hearts
for i := clubCount + diamondCount + spadeCount; i < clubCount+diamondCount+spadeCount+heartCount; i++ {
numInSuit := i - clubCount - diamondCount - spadeCount
- texture.PopulateCardImage(u.Cards[i], u.Texs, u.Eng, u.Scene)
+ texture.PopulateCardImage(u.Cards[i], u)
reposition.SetCardPositionHand(u.Cards[i], numInSuit, suitCounts, u)
}
}
@@ -852,15 +852,15 @@
dividerDim := coords.MakeVec(u.WindowSize.X, u.Padding/2)
dividerPos := coords.MakeVec(0, top+(float32(i)+.5)*rowHeight)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(dividerImage, dividerPos, dividerDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(dividerImage, dividerPos, dividerDim, u))
// player icon
- playerIconImage := p.GetIconImage()
+ playerIconImage := uistate.GetAvatar(i, u)
playerIconDim := coords.MakeVec(rowHeight/2, rowHeight/2)
playerIconPos := coords.MakeVec(u.WindowSize.X/4-playerIconDim.X/2, top+(float32(i)+.5)*rowHeight+rowHeight/7)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, playerIconDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, playerIconDim, u))
// player name
- name := p.GetName()
+ name := uistate.GetName(i, u)
nameCenter := coords.MakeVec(playerIconPos.X+playerIconDim.X/2, playerIconPos.Y+playerIconDim.Y)
u.BackgroundImgs = append(u.BackgroundImgs,
texture.MakeStringImgCenterAlign(name, "", "", true, nameCenter, scaler, maxWidth, u)...)
@@ -890,7 +890,7 @@
dividerDim := coords.MakeVec(u.WindowSize.X, u.Padding/2)
dividerPos := coords.MakeVec(0, top+(float32(len(u.CurTable.GetPlayers()))+.5)*rowHeight)
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeImgWithoutAlt(dividerImage, dividerPos, dividerDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(dividerImage, dividerPos, dividerDim, u))
}
func addScoreButton(gameOver bool, u *uistate.UIState) {
@@ -903,7 +903,7 @@
buttonDim := coords.MakeVec(2*u.CardDim.X, 3*u.CardDim.Y/4)
buttonPos := coords.MakeVec((u.WindowSize.X-buttonDim.X)/2, u.WindowSize.Y-buttonDim.Y-u.BottomPadding)
u.Buttons = append(u.Buttons,
- texture.MakeImgWithoutAlt(buttonImg, buttonPos, buttonDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(buttonImg, buttonPos, buttonDim, u))
}
func resetImgs(u *uistate.UIState) {
@@ -938,11 +938,11 @@
debugTableImage := u.Texs["BakuSquare.png"]
debugTablePos := u.WindowSize.MinusVec(buttonDim)
u.Buttons = append(u.Buttons,
- texture.MakeImgWithoutAlt(debugTableImage, debugTablePos, buttonDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(debugTableImage, debugTablePos, buttonDim, u))
debugPassImage := u.Texs["Clubs-2.png"]
debugPassPos := coords.MakeVec(u.WindowSize.X-2*buttonDim.X, u.WindowSize.Y-buttonDim.Y)
u.Buttons = append(u.Buttons,
- texture.MakeImgWithoutAlt(debugPassImage, debugPassPos, buttonDim, u.Eng, u.Scene))
+ texture.MakeImgWithoutAlt(debugPassImage, debugPassPos, buttonDim, u))
}
// Helper function that returns the largest int in a non-negative int array (not index of largest int)
diff --git a/go/src/hearts/logic/player/player.go b/go/src/hearts/logic/player/player.go
index ce96d41..086d46c 100644
--- a/go/src/hearts/logic/player/player.go
+++ b/go/src/hearts/logic/player/player.go
@@ -7,40 +7,33 @@
package player
import (
- "golang.org/x/mobile/exp/sprite"
"hearts/logic/card"
)
// Returns a player instance with playerIndex equal to index
-func NewPlayer(index int, name string, iconTex, deviceTex sprite.SubTex) *Player {
+func NewPlayer(index int) *Player {
return &Player{
- hand: nil,
- tricks: make([]*card.Card, 0),
- score: 0,
- playerIndex: index,
- playerName: name,
- playerIconImage: iconTex,
- playerDeviceImage: deviceTex,
- donePassing: false,
- doneTaking: false,
- doneScoring: false,
+ hand: nil,
+ tricks: make([]*card.Card, 0),
+ score: 0,
+ playerIndex: index,
+ donePassing: false,
+ doneTaking: false,
+ doneScoring: false,
}
}
type Player struct {
- hand []*card.Card
- passedFrom []*card.Card
- passedTo []*card.Card
- tricks []*card.Card
- score int
- playerIndex int
- playerName string
- playerIconImage sprite.SubTex
- playerDeviceImage sprite.SubTex
- donePassing bool
- doneTaking bool
- donePlaying bool
- doneScoring bool
+ hand []*card.Card
+ passedFrom []*card.Card
+ passedTo []*card.Card
+ tricks []*card.Card
+ score int
+ playerIndex int
+ donePassing bool
+ doneTaking bool
+ donePlaying bool
+ doneScoring bool
}
// Returns the hand of p
@@ -68,18 +61,6 @@
return p.playerIndex
}
-func (p *Player) GetName() string {
- return p.playerName
-}
-
-func (p *Player) GetIconImage() sprite.SubTex {
- return p.playerIconImage
-}
-
-func (p *Player) GetDeviceImage() sprite.SubTex {
- return p.playerDeviceImage
-}
-
// Returns true if p has finished the pass phase of the current round
func (p *Player) GetDonePassing() bool {
return p.donePassing
@@ -119,18 +100,6 @@
p.hand = cards
}
-func (p *Player) SetName(name string) {
- p.playerName = name
-}
-
-func (p *Player) SetIconImage(image sprite.SubTex) {
- p.playerIconImage = image
-}
-
-func (p *Player) SetDeviceImage(image sprite.SubTex) {
- p.playerDeviceImage = image
-}
-
// Sets passedTo of p to cards
func (p *Player) SetPassedTo(cards []*card.Card) {
p.passedTo = cards
diff --git a/go/src/hearts/logic/table/table.go b/go/src/hearts/logic/table/table.go
index 74ed5ba..0df0732 100644
--- a/go/src/hearts/logic/table/table.go
+++ b/go/src/hearts/logic/table/table.go
@@ -18,11 +18,8 @@
// Returns a table instance with player set length numPlayers
func InitializeGame(numPlayers int, texs map[string]sprite.SubTex) *Table {
players := make([]*player.Player, 0)
- names := []string{"YoungSeok", "Dan", "Emily", "Ross"}
- iconImages := []sprite.SubTex{texs["player0.jpeg"], texs["player1.jpeg"], texs["player2.jpeg"], texs["player3.jpeg"]}
- deviceImages := []sprite.SubTex{texs["laptopIcon.png"], texs["watchIcon.png"], texs["tabletIcon.png"], texs["phoneIcon.png"]}
for i := 0; i < numPlayers; i++ {
- players = append(players, player.NewPlayer(i, names[i], iconImages[i], deviceImages[i]))
+ players = append(players, player.NewPlayer(i))
}
t := makeTable(players)
t.GenerateClassicCards()
diff --git a/go/src/hearts/syncbase/util/util.go b/go/src/hearts/syncbase/util/util.go
index cb293cd..a24b8c8 100644
--- a/go/src/hearts/syncbase/util/util.go
+++ b/go/src/hearts/syncbase/util/util.go
@@ -10,10 +10,10 @@
// switch back to my mountpoint with the following code:
MountPoint = "users/emshack@google.com"
//MountPoint = "/192.168.86.254:8101"
- UserID = 123
+ UserID = 1223
UserColor = 16777215
- UserAvatar = "Club.png"
- UserName = "Croupier Go Player (the blue)"
+ UserAvatar = "player1.jpeg"
+ UserName = "EmilyS"
SBName = "syncbase"
AppName = "app"
DbName = "db"
diff --git a/go/src/hearts/syncbase/watch/watch.go b/go/src/hearts/syncbase/watch/watch.go
index f749591..2452590 100644
--- a/go/src/hearts/syncbase/watch/watch.go
+++ b/go/src/hearts/syncbase/watch/watch.go
@@ -99,14 +99,14 @@
func onPlayers(key, value string, u *uistate.UIState) {
userID, _ := strconv.Atoi(strings.Split(key, "/")[2])
playerNum, _ := strconv.Atoi(value)
- u.PlayerData[playerNum] = u.UserData[userID]
- user := u.UserData[userID]
- if user != nil {
- img := u.Texs[user["avatar"].(string)]
- name := user["name"].(string)
- u.CurTable.GetPlayers()[playerNum].SetIconImage(img)
- u.CurTable.GetPlayers()[playerNum].SetName(name)
- }
+ u.PlayerData[playerNum] = userID
+ // user := u.UserData[userID]
+ // if user != nil {
+ // img := u.Texs[user["avatar"].(string)]
+ // name := user["name"].(string)
+ // u.CurTable.GetPlayers()[playerNum].SetIconImage(img)
+ // u.CurTable.GetPlayers()[playerNum].SetName(name)
+ // }
if u.CurView == uistate.Arrange {
view.LoadArrangeView(u)
}
@@ -260,7 +260,7 @@
view.LoadScoreView(roundScores, winners, u)
} else if trickOver {
if u.CurPlayerIndex != recipient {
- message := u.CurTable.GetPlayers()[recipient].GetName() + "'s trick"
+ message := uistate.GetName(recipient, u) + "'s trick"
view.ChangePlayMessage(message, u)
<-time.After(1 * time.Second)
view.LoadPlayView(u)
diff --git a/go/src/hearts/touchhandler/touchhandler.go b/go/src/hearts/touchhandler/touchhandler.go
index 69c104a..d7e545a 100644
--- a/go/src/hearts/touchhandler/touchhandler.go
+++ b/go/src/hearts/touchhandler/touchhandler.go
@@ -61,7 +61,7 @@
}
case touch.TypeEnd:
if u.CurCard != nil {
- endClickTake(t, u)
+ endClickTake(t, u.CurCard, u)
u.CurCard = nil
}
}
@@ -75,7 +75,7 @@
}
case touch.TypeEnd:
if u.CurCard != nil {
- endClickPlay(t, u)
+ endClickPlay(t, u.CurCard, u)
}
}
case uistate.Split:
@@ -88,7 +88,7 @@
}
case touch.TypeEnd:
if u.CurCard != nil {
- endClickSplit(t, u)
+ endClickSplit(t, u.CurCard, u)
u.CurCard = nil
}
}
@@ -140,16 +140,16 @@
func beginClickArrange(t touch.Event, u *uistate.UIState) {
buttonList := findClickedButton(t, u)
- if len(buttonList) > 0 && u.PlayerData[u.CurPlayerIndex] == nil {
+ if len(buttonList) > 0 {
for i, b := range u.Buttons {
if buttonList[0] == b {
u.CurPlayerIndex = i
}
}
- if u.CurPlayerIndex < 4 {
+ if u.CurPlayerIndex >= 0 && u.CurPlayerIndex < u.NumPlayers {
gamelog.LogReady(u)
- gamelog.LogPlayerNum(u)
}
+ gamelog.LogPlayerNum(u)
view.LoadWaitingView(u)
}
}
@@ -163,6 +163,9 @@
func beginClickPass(t touch.Event, u *uistate.UIState) {
u.CurCard = findClickedCard(t, u)
+ if u.CurCard != nil {
+ reposition.BringNodeToFront(u.CurCard.GetNode(), u)
+ }
buttonList := findClickedButton(t, u)
if len(buttonList) > 0 {
if u.Debug {
@@ -175,6 +178,11 @@
img.SetDisplayingImage(false)
}
blueBanner := u.Other[0]
+ reposition.BringNodeToFront(u.BackgroundImgs[1].GetNode(), u)
+ reposition.BringNodeToFront(pullTab.GetNode(), u)
+ for _, d := range u.DropTargets {
+ reposition.BringNodeToFront(d.GetCardHere().GetNode(), u)
+ }
if blueBanner.GetNode().Arranger == nil {
finalX := blueBanner.GetInitial().X
finalY := pullTab.GetInitial().Y + pullTab.GetDimensions().Y - blueBanner.GetDimensions().Y
@@ -196,6 +204,11 @@
img.SetDisplayingImage(false)
}
blueBanner := u.Other[0]
+ reposition.BringNodeToFront(u.BackgroundImgs[1].GetNode(), u)
+ reposition.BringNodeToFront(pullTab.GetNode(), u)
+ for _, d := range u.DropTargets {
+ reposition.BringNodeToFront(d.GetCardHere().GetNode(), u)
+ }
if blueBanner.GetNode().Arranger == nil {
finalX := blueBanner.GetInitial().X
finalY := pullTab.GetInitial().Y + pullTab.GetDimensions().Y - blueBanner.GetDimensions().Y
@@ -208,9 +221,7 @@
}
func moveClickPass(t touch.Event, u *uistate.UIState) {
- if u.CurCard != nil {
- reposition.DragCard(t, u)
- } else if u.CurImg != nil {
+ if u.CurImg != nil {
imgs := make([]*staticimg.StaticImg, 0)
cards := make([]*card.Card, 0)
pullTab := u.Buttons[0]
@@ -227,6 +238,8 @@
text.SetDisplayingImage(false)
}
reposition.DragImgs(t, cards, imgs, u)
+ } else if u.CurCard != nil {
+ reposition.DragCard(t, u)
}
}
@@ -277,6 +290,7 @@
func beginClickTake(t touch.Event, u *uistate.UIState) {
u.CurCard = findClickedCard(t, u)
if u.CurCard != nil {
+ reposition.BringNodeToFront(u.CurCard.GetNode(), u)
u.CurCard.GetNode().Arranger = nil
}
buttonList := findClickedButton(t, u)
@@ -295,12 +309,12 @@
reposition.DragCard(t, u)
}
-func endClickTake(t touch.Event, u *uistate.UIState) {
+func endClickTake(t touch.Event, c *card.Card, u *uistate.UIState) {
// check to see if card was removed from a drop target
- removeCardFromTarget(u.CurCard, u)
+ removeCardFromTarget(c, u)
// add card back to hand
- reposition.ResetCardPosition(u.CurCard, u.Eng)
- reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
+ reposition.ResetCardPosition(c, u.Eng)
+ reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
doneTaking := true
for _, d := range u.DropTargets {
if d.GetCardHere() != nil {
@@ -327,11 +341,13 @@
func beginClickPlay(t touch.Event, u *uistate.UIState) {
u.CurCard = findClickedCard(t, u)
+ if u.CurCard != nil {
+ reposition.BringNodeToFront(u.CurCard.GetNode(), u)
+ }
buttonList := findClickedButton(t, u)
if len(buttonList) > 0 {
if u.Debug {
if u.Buttons[0] == buttonList[0] {
- u.CurImg = u.Buttons[0]
view.LoadSplitView(false, u)
} else if u.Buttons[1] == buttonList[0] {
view.LoadTableView(u)
@@ -339,7 +355,6 @@
view.LoadPassOrTakeOrPlay(u)
}
} else {
- u.CurImg = u.Buttons[0]
view.LoadSplitView(false, u)
}
}
@@ -349,15 +364,15 @@
reposition.DragCard(t, u)
}
-func endClickPlay(t touch.Event, u *uistate.UIState) {
- if dropCardOnTarget(u.CurCard, t, u) {
+func endClickPlay(t touch.Event, c *card.Card, u *uistate.UIState) {
+ if dropCardOnTarget(c, t, u) {
ch := make(chan bool)
if err := playCard(ch, u.CurPlayerIndex, u); err != "" {
view.ChangePlayMessage(err, u)
- removeCardFromTarget(u.CurCard, u)
+ removeCardFromTarget(c, u)
// add card back to hand
- reposition.ResetCardPosition(u.CurCard, u.Eng)
- reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
+ reposition.ResetCardPosition(c, u.Eng)
+ reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
}
quit := make(chan bool)
u.AnimChans = append(u.AnimChans, quit)
@@ -367,15 +382,18 @@
}()
} else {
// check to see if card was removed from a drop target
- removeCardFromTarget(u.CurCard, u)
+ removeCardFromTarget(c, u)
// add card back to hand
- reposition.ResetCardPosition(u.CurCard, u.Eng)
- reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
+ reposition.ResetCardPosition(c, u.Eng)
+ reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
}
}
func beginClickSplit(t touch.Event, u *uistate.UIState) {
u.CurCard = findClickedCard(t, u)
+ if u.CurCard != nil {
+ reposition.BringNodeToFront(u.CurCard.GetNode(), u)
+ }
buttonList := findClickedButton(t, u)
if len(buttonList) > 0 {
if u.Debug {
@@ -410,24 +428,24 @@
reposition.DragCard(t, u)
}
-func endClickSplit(t touch.Event, u *uistate.UIState) {
- if dropCardHere(u.CurCard, u.DropTargets[0], t, u) {
+func endClickSplit(t touch.Event, c *card.Card, u *uistate.UIState) {
+ if dropCardHere(c, u.DropTargets[0], t, u) {
ch := make(chan bool)
if err := playCard(ch, u.CurPlayerIndex, u); err != "" {
view.ChangePlayMessage(err, u)
- removeCardFromTarget(u.CurCard, u)
+ removeCardFromTarget(c, u)
// add card back to hand
- reposition.ResetCardPosition(u.CurCard, u.Eng)
- reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
+ reposition.ResetCardPosition(c, u.Eng)
+ reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
} else {
- reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
+ reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
}
} else {
// check to see if card was removed from a drop target
- removeCardFromTarget(u.CurCard, u)
+ removeCardFromTarget(c, u)
// add card back to hand
- reposition.ResetCardPosition(u.CurCard, u.Eng)
- reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
+ reposition.ResetCardPosition(c, u.Eng)
+ reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
}
}