update paths
This commit is contained in:
parent
e6661a26f4
commit
a73928bbd1
119
client/main.go
119
client/main.go
@ -12,6 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"git.saintnet.tech/tomecraft/tome_lib"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
@ -24,65 +25,65 @@ var matchID uuid.UUID
|
|||||||
func receiveHandler(connection *websocket.Conn, output chan string) {
|
func receiveHandler(connection *websocket.Conn, output chan string) {
|
||||||
defer close(done)
|
defer close(done)
|
||||||
for {
|
for {
|
||||||
var resp coordinator.SessionCommandResult
|
var resp tome_lib.SessionCommandResult
|
||||||
err := connection.ReadJSON(&resp)
|
err := connection.ReadJSON(&resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error in receive:", err)
|
log.Println("Error in receive:", err)
|
||||||
}
|
}
|
||||||
switch resp.Result {
|
switch resp.Result {
|
||||||
case coordinator.SessionRespJoined1:
|
case tome_lib.SessionRespJoined1:
|
||||||
pid = game.SentinalID
|
pid = tome_lib.SentinalID
|
||||||
output <- "joined as sentinal"
|
output <- "joined as sentinal"
|
||||||
case coordinator.SessionRespJoined2:
|
case tome_lib.SessionRespJoined2:
|
||||||
pid = game.ScourgeID
|
pid = tome_lib.ScourgeID
|
||||||
output <- "joined as scourge"
|
output <- "joined as scourge"
|
||||||
case coordinator.SessionRespFound:
|
case tome_lib.SessionRespFound:
|
||||||
matchID = resp.MatchID
|
matchID = resp.MatchID
|
||||||
output <- "game found"
|
output <- "tome_lib found"
|
||||||
case coordinator.SessionRespJoinError:
|
case tome_lib.SessionRespJoinError:
|
||||||
output <- "error joining game"
|
output <- "error joining tome_lib"
|
||||||
case coordinator.SessionRespPlayed:
|
case tome_lib.SessionRespPlayed:
|
||||||
if resp.GameResult != nil {
|
if resp.GameResult != nil {
|
||||||
output <- "played succesfully"
|
output <- "played succesfully"
|
||||||
switch resp.GameResult.ResultType {
|
switch resp.GameResult.ResultType {
|
||||||
case game.ActCmd:
|
case tome_lib.ActCmd:
|
||||||
output <- resp.GameResult.ActionResult.String()
|
output <- resp.GameResult.ActionResult.String()
|
||||||
case game.StateCmd:
|
case tome_lib.StateCmd:
|
||||||
output <- resp.GameResult.StateResult.String()
|
output <- resp.GameResult.StateResult.String()
|
||||||
case game.DebugCmd:
|
case tome_lib.DebugCmd:
|
||||||
output <- resp.GameResult.DebugResult.String()
|
output <- "debug response" //resp.GameResult.DebugResult
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
output <- "error playing"
|
output <- "error playing"
|
||||||
}
|
}
|
||||||
case coordinator.SessionRespLeft:
|
case tome_lib.SessionRespLeft:
|
||||||
output <- "game left"
|
output <- "tome_lib left"
|
||||||
break
|
break
|
||||||
case coordinator.SessionRespBroadcastSenTurn:
|
case tome_lib.SessionRespBroadcastSenTurn:
|
||||||
output <- "Sentinal may take their turn"
|
output <- "Sentinal may take their turn"
|
||||||
case coordinator.SessionRespBroadcastScoTrun:
|
case tome_lib.SessionRespBroadcastScoTrun:
|
||||||
output <- "Scourge may take their turn"
|
output <- "Scourge may take their turn"
|
||||||
case coordinator.SessionRespBroadcastSenWin:
|
case tome_lib.SessionRespBroadcastSenWin:
|
||||||
output <- "Sentinal wins!"
|
output <- "Sentinal wins!"
|
||||||
case coordinator.SessionRespBroadcastScoWin:
|
case tome_lib.SessionRespBroadcastScoWin:
|
||||||
output <- "Scourge wins!"
|
output <- "Scourge wins!"
|
||||||
case coordinator.SessionRespBroadcastUpdate:
|
case tome_lib.SessionRespBroadcastUpdate:
|
||||||
//we don't handle updates
|
//we don't handle updates
|
||||||
case coordinator.SessionRespBroadcastScoJoin:
|
case tome_lib.SessionRespBroadcastScoJoin:
|
||||||
output <- "Scourge has joined the game"
|
output <- "Scourge has joined the tome_lib"
|
||||||
case coordinator.SessionRespBroadcastSenJoin:
|
case tome_lib.SessionRespBroadcastSenJoin:
|
||||||
output <- "Sentinal has joined the game"
|
output <- "Sentinal has joined the tome_lib"
|
||||||
case coordinator.SessionRespBroadcastScoLeft:
|
case tome_lib.SessionRespBroadcastScoLeft:
|
||||||
output <- "Scourge has left the game"
|
output <- "Scourge has left the tome_lib"
|
||||||
case coordinator.SessionRespBroadcastSenLeft:
|
case tome_lib.SessionRespBroadcastSenLeft:
|
||||||
output <- "Sentinal has left the game"
|
output <- "Sentinal has left the tome_lib"
|
||||||
case coordinator.SessionRespBroadcastSenReady:
|
case tome_lib.SessionRespBroadcastSenReady:
|
||||||
output <- "Sentinal is ready"
|
output <- "Sentinal is ready"
|
||||||
case coordinator.SessionRespBroadcastScoReady:
|
case tome_lib.SessionRespBroadcastScoReady:
|
||||||
output <- "scourge is ready"
|
output <- "scourge is ready"
|
||||||
case coordinator.SessionRespBroadcastNone:
|
case tome_lib.SessionRespBroadcastNone:
|
||||||
|
|
||||||
case coordinator.SessionRespError:
|
case tome_lib.SessionRespError:
|
||||||
output <- "generic error"
|
output <- "generic error"
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -94,7 +95,7 @@ func receiveHandler(connection *websocket.Conn, output chan string) {
|
|||||||
func main() {
|
func main() {
|
||||||
done = make(chan interface{}) // Channel to indicate that the receiverHandler is done
|
done = make(chan interface{}) // Channel to indicate that the receiverHandler is done
|
||||||
interrupt = make(chan os.Signal) // Channel to listen for interrupt signal to terminate gracefully
|
interrupt = make(chan os.Signal) // Channel to listen for interrupt signal to terminate gracefully
|
||||||
cmd := make(chan coordinator.SessionCommand)
|
cmd := make(chan tome_lib.SessionCommand)
|
||||||
output := make(chan string)
|
output := make(chan string)
|
||||||
|
|
||||||
signal.Notify(interrupt, os.Interrupt) // Notify the interrupt channel for SIGINT
|
signal.Notify(interrupt, os.Interrupt) // Notify the interrupt channel for SIGINT
|
||||||
@ -117,7 +118,7 @@ func main() {
|
|||||||
// Our main loop for the client
|
// Our main loop for the client
|
||||||
// We send our relevant packets here
|
// We send our relevant packets here
|
||||||
for {
|
for {
|
||||||
var c coordinator.SessionCommand
|
var c tome_lib.SessionCommand
|
||||||
var o string
|
var o string
|
||||||
select {
|
select {
|
||||||
case c = <-cmd:
|
case c = <-cmd:
|
||||||
@ -126,7 +127,7 @@ func main() {
|
|||||||
log.Println("Error during writing to websocket:", err)
|
log.Println("Error during writing to websocket:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if c.Command == coordinator.SessionCmdLeave {
|
if c.Command == tome_lib.SessionCmdLeave {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case o = <-output:
|
case o = <-output:
|
||||||
@ -136,9 +137,9 @@ func main() {
|
|||||||
log.Println("Received SIGINT interrupt signal. Closing all pending connections")
|
log.Println("Received SIGINT interrupt signal. Closing all pending connections")
|
||||||
|
|
||||||
// Close our websocket connection
|
// Close our websocket connection
|
||||||
err := conn.WriteJSON(coordinator.SessionCommand{
|
err := conn.WriteJSON(tome_lib.SessionCommand{
|
||||||
ID: id,
|
ID: id,
|
||||||
Command: coordinator.SessionCmdLeave,
|
Command: tome_lib.SessionCmdLeave,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error during closing websocket:", err)
|
log.Println("Error during closing websocket:", err)
|
||||||
@ -154,10 +155,10 @@ func main() {
|
|||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if matchID != uuid.Nil {
|
if matchID != uuid.Nil {
|
||||||
err := conn.WriteJSON(coordinator.SessionCommand{
|
err := conn.WriteJSON(tome_lib.SessionCommand{
|
||||||
ID: id,
|
ID: id,
|
||||||
MatchID: matchID,
|
MatchID: matchID,
|
||||||
Command: coordinator.SessionCmdPoll,
|
Command: tome_lib.SessionCmdPoll,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error writing to websocket:", err)
|
log.Println("Error writing to websocket:", err)
|
||||||
@ -168,7 +169,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCommand(uid uuid.UUID, resp chan coordinator.SessionCommand) {
|
func GetCommand(uid uuid.UUID, resp chan tome_lib.SessionCommand) {
|
||||||
for {
|
for {
|
||||||
var cmd string
|
var cmd string
|
||||||
var t int
|
var t int
|
||||||
@ -188,48 +189,48 @@ func GetCommand(uid uuid.UUID, resp chan coordinator.SessionCommand) {
|
|||||||
switch t {
|
switch t {
|
||||||
case 0:
|
case 0:
|
||||||
//session
|
//session
|
||||||
switch coordinator.SessionCmd(cmd) {
|
switch tome_lib.SessionCmd(cmd) {
|
||||||
case coordinator.SessionCmdQuery:
|
case tome_lib.SessionCmdQuery:
|
||||||
resp <- coordinator.SessionCommand{
|
resp <- tome_lib.SessionCommand{
|
||||||
ID: uid,
|
ID: uid,
|
||||||
Command: coordinator.SessionCmdQuery,
|
Command: tome_lib.SessionCmdQuery,
|
||||||
}
|
}
|
||||||
case coordinator.SessionCmdJoin:
|
case tome_lib.SessionCmdJoin:
|
||||||
resp <- coordinator.SessionCommand{
|
resp <- tome_lib.SessionCommand{
|
||||||
ID: uid,
|
ID: uid,
|
||||||
MatchID: matchID,
|
MatchID: matchID,
|
||||||
Command: coordinator.SessionCmdJoin,
|
Command: tome_lib.SessionCmdJoin,
|
||||||
}
|
}
|
||||||
case coordinator.SessionCmdLeave:
|
case tome_lib.SessionCmdLeave:
|
||||||
resp <- coordinator.SessionCommand{
|
resp <- tome_lib.SessionCommand{
|
||||||
ID: uid,
|
ID: uid,
|
||||||
MatchID: matchID,
|
MatchID: matchID,
|
||||||
Command: coordinator.SessionCmdLeave,
|
Command: tome_lib.SessionCmdLeave,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
//state
|
//state
|
||||||
resp <- coordinator.SessionCommand{
|
resp <- tome_lib.SessionCommand{
|
||||||
ID: uid,
|
ID: uid,
|
||||||
MatchID: matchID,
|
MatchID: matchID,
|
||||||
Command: coordinator.SessionCmdPlay,
|
Command: tome_lib.SessionCmdPlay,
|
||||||
GameCommand: &game.Command{
|
GameCommand: &tome_lib.Command{
|
||||||
PlayerID: pid,
|
PlayerID: pid,
|
||||||
Type: game.StateCmd,
|
Type: tome_lib.StateCmd,
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
//action
|
//action
|
||||||
resp <- coordinator.SessionCommand{
|
resp <- tome_lib.SessionCommand{
|
||||||
ID: uid,
|
ID: uid,
|
||||||
MatchID: matchID,
|
MatchID: matchID,
|
||||||
Command: coordinator.SessionCmdPlay,
|
Command: tome_lib.SessionCmdPlay,
|
||||||
GameCommand: &game.Command{
|
GameCommand: &tome_lib.Command{
|
||||||
PlayerID: pid,
|
PlayerID: pid,
|
||||||
Type: game.ActCmd,
|
Type: tome_lib.ActCmd,
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"git.saintnet.tech/stryan/snengame/internal/coordinator"
|
"git.saintnet.tech/tomecraft/tome_lib"
|
||||||
"git.saintnet.tech/stryan/snengame/internal/game"
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
@ -24,65 +23,65 @@ var matchID uuid.UUID
|
|||||||
func receiveHandler(connection *websocket.Conn, container *UIContainer) {
|
func receiveHandler(connection *websocket.Conn, container *UIContainer) {
|
||||||
defer close(done)
|
defer close(done)
|
||||||
for {
|
for {
|
||||||
var resp coordinator.SessionCommandResult
|
var resp tome_lib.SessionCommandResult
|
||||||
err := connection.ReadJSON(&resp)
|
err := connection.ReadJSON(&resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error in receive:", err)
|
log.Println("Error in receive:", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
switch resp.Result {
|
switch resp.Result {
|
||||||
case coordinator.SessionRespJoined1:
|
case tome_lib.SessionRespJoined1:
|
||||||
pid = game.SentinalID
|
pid = tome_lib.SentinalID
|
||||||
container.Output <- "joined as sentinal"
|
container.Output <- "joined as sentinal"
|
||||||
case coordinator.SessionRespJoined2:
|
case tome_lib.SessionRespJoined2:
|
||||||
pid = game.ScourgeID
|
pid = tome_lib.ScourgeID
|
||||||
container.Output <- "joined as scourge"
|
container.Output <- "joined as scourge"
|
||||||
case coordinator.SessionRespFound:
|
case tome_lib.SessionRespFound:
|
||||||
matchID = resp.MatchID
|
matchID = resp.MatchID
|
||||||
container.Output <- "game found"
|
container.Output <- "tome_lib found"
|
||||||
case coordinator.SessionRespPlayed:
|
case tome_lib.SessionRespPlayed:
|
||||||
if resp.GameResult != nil {
|
if resp.GameResult != nil {
|
||||||
switch resp.GameResult.ResultType {
|
switch resp.GameResult.ResultType {
|
||||||
case game.ActCmd:
|
case tome_lib.ActCmd:
|
||||||
container.Output <- resp.GameResult.ActionResult.String()
|
container.Output <- resp.GameResult.ActionResult.String()
|
||||||
case game.StateCmd:
|
case tome_lib.StateCmd:
|
||||||
container.State = resp.GameResult.StateResult
|
container.State = resp.GameResult.StateResult
|
||||||
container.Updated <- true
|
container.Updated <- true
|
||||||
case game.DebugCmd:
|
case tome_lib.DebugCmd:
|
||||||
container.Output <- resp.GameResult.DebugResult.String()
|
container.Output <- "debug response"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
container.Output <- "error playing"
|
container.Output <- "error playing"
|
||||||
}
|
}
|
||||||
case coordinator.SessionRespLeft:
|
case tome_lib.SessionRespLeft:
|
||||||
container.Output <- "game left"
|
container.Output <- "tome_lib left"
|
||||||
matchID = uuid.Nil
|
matchID = uuid.Nil
|
||||||
return
|
return
|
||||||
case coordinator.SessionRespBroadcastSenTurn:
|
case tome_lib.SessionRespBroadcastSenTurn:
|
||||||
container.Output <- "Sentinal may take their turn"
|
container.Output <- "Sentinal may take their turn"
|
||||||
case coordinator.SessionRespBroadcastScoTrun:
|
case tome_lib.SessionRespBroadcastScoTrun:
|
||||||
container.Output <- "Scourge may take their turn"
|
container.Output <- "Scourge may take their turn"
|
||||||
case coordinator.SessionRespBroadcastSenWin:
|
case tome_lib.SessionRespBroadcastSenWin:
|
||||||
container.Output <- "Sentinal wins!"
|
container.Output <- "Sentinal wins!"
|
||||||
case coordinator.SessionRespBroadcastScoWin:
|
case tome_lib.SessionRespBroadcastScoWin:
|
||||||
container.Output <- "Scourge wins!"
|
container.Output <- "Scourge wins!"
|
||||||
case coordinator.SessionRespBroadcastUpdate:
|
case tome_lib.SessionRespBroadcastUpdate:
|
||||||
container.GetUpdate <- true
|
container.GetUpdate <- true
|
||||||
case coordinator.SessionRespBroadcastScoJoin:
|
case tome_lib.SessionRespBroadcastScoJoin:
|
||||||
container.Output <- "Scourge has joined the game"
|
container.Output <- "Scourge has joined the tome_lib"
|
||||||
case coordinator.SessionRespBroadcastSenJoin:
|
case tome_lib.SessionRespBroadcastSenJoin:
|
||||||
container.Output <- "Sentinal has joined the game"
|
container.Output <- "Sentinal has joined the tome_lib"
|
||||||
case coordinator.SessionRespBroadcastScoLeft:
|
case tome_lib.SessionRespBroadcastScoLeft:
|
||||||
container.Output <- "Scourge has left the game"
|
container.Output <- "Scourge has left the tome_lib"
|
||||||
case coordinator.SessionRespBroadcastSenLeft:
|
case tome_lib.SessionRespBroadcastSenLeft:
|
||||||
container.Output <- "Sentinal has left the game"
|
container.Output <- "Sentinal has left the tome_lib"
|
||||||
case coordinator.SessionRespBroadcastSenReady:
|
case tome_lib.SessionRespBroadcastSenReady:
|
||||||
container.Output <- "Sentinal is ready"
|
container.Output <- "Sentinal is ready"
|
||||||
case coordinator.SessionRespBroadcastScoReady:
|
case tome_lib.SessionRespBroadcastScoReady:
|
||||||
container.Output <- "scourge is ready"
|
container.Output <- "scourge is ready"
|
||||||
case coordinator.SessionRespBroadcastNone:
|
case tome_lib.SessionRespBroadcastNone:
|
||||||
|
|
||||||
case coordinator.SessionRespError:
|
case tome_lib.SessionRespError:
|
||||||
container.Output <- "generic error"
|
container.Output <- "generic error"
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -94,7 +93,7 @@ func receiveHandler(connection *websocket.Conn, container *UIContainer) {
|
|||||||
func backend(container *UIContainer) {
|
func backend(container *UIContainer) {
|
||||||
done = make(chan interface{}) // Channel to indicate that the receiverHandler is done
|
done = make(chan interface{}) // Channel to indicate that the receiverHandler is done
|
||||||
interrupt = make(chan os.Signal) // Channel to listen for interrupt signal to terminate gracefully
|
interrupt = make(chan os.Signal) // Channel to listen for interrupt signal to terminate gracefully
|
||||||
cmd := make(chan coordinator.SessionCommand)
|
cmd := make(chan tome_lib.SessionCommand)
|
||||||
|
|
||||||
signal.Notify(interrupt, os.Interrupt) // Notify the interrupt channel for SIGINT
|
signal.Notify(interrupt, os.Interrupt) // Notify the interrupt channel for SIGINT
|
||||||
hostname := flag.String("host", "localhost", "server hostname to connect to")
|
hostname := flag.String("host", "localhost", "server hostname to connect to")
|
||||||
@ -116,7 +115,7 @@ func backend(container *UIContainer) {
|
|||||||
// Our main loop for the client
|
// Our main loop for the client
|
||||||
// We send our relevant packets here
|
// We send our relevant packets here
|
||||||
for {
|
for {
|
||||||
var c coordinator.SessionCommand
|
var c tome_lib.SessionCommand
|
||||||
select {
|
select {
|
||||||
case c = <-cmd:
|
case c = <-cmd:
|
||||||
err := conn.WriteJSON(c)
|
err := conn.WriteJSON(c)
|
||||||
@ -124,18 +123,18 @@ func backend(container *UIContainer) {
|
|||||||
log.Println("Error during writing to websocket:", err)
|
log.Println("Error during writing to websocket:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if c.Command == coordinator.SessionCmdLeave {
|
if c.Command == tome_lib.SessionCmdLeave {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case <-container.GetUpdate:
|
case <-container.GetUpdate:
|
||||||
if container.State != nil {
|
if container.State != nil {
|
||||||
err = conn.WriteJSON(&coordinator.SessionCommand{
|
err = conn.WriteJSON(&tome_lib.SessionCommand{
|
||||||
ID: id,
|
ID: id,
|
||||||
MatchID: matchID,
|
MatchID: matchID,
|
||||||
Command: coordinator.SessionCmdPlay,
|
Command: tome_lib.SessionCmdPlay,
|
||||||
GameCommand: &game.Command{
|
GameCommand: &tome_lib.Command{
|
||||||
PlayerID: pid,
|
PlayerID: pid,
|
||||||
Type: game.StateCmd,
|
Type: tome_lib.StateCmd,
|
||||||
Cmd: "g",
|
Cmd: "g",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -151,9 +150,9 @@ func backend(container *UIContainer) {
|
|||||||
log.Println("Received SIGINT interrupt signal. Closing all pending connections")
|
log.Println("Received SIGINT interrupt signal. Closing all pending connections")
|
||||||
|
|
||||||
// Close our websocket connection
|
// Close our websocket connection
|
||||||
err := conn.WriteJSON(coordinator.SessionCommand{
|
err := conn.WriteJSON(tome_lib.SessionCommand{
|
||||||
ID: id,
|
ID: id,
|
||||||
Command: coordinator.SessionCmdLeave,
|
Command: tome_lib.SessionCmdLeave,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error during closing websocket:", err)
|
log.Println("Error during closing websocket:", err)
|
||||||
@ -173,10 +172,10 @@ func backend(container *UIContainer) {
|
|||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
if matchID != uuid.Nil {
|
if matchID != uuid.Nil {
|
||||||
err := conn.WriteJSON(coordinator.SessionCommand{
|
err := conn.WriteJSON(tome_lib.SessionCommand{
|
||||||
ID: id,
|
ID: id,
|
||||||
MatchID: matchID,
|
MatchID: matchID,
|
||||||
Command: coordinator.SessionCmdPoll,
|
Command: tome_lib.SessionCmdPoll,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error writing to websocket:", err)
|
log.Println("Error writing to websocket:", err)
|
||||||
@ -188,7 +187,7 @@ func backend(container *UIContainer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCommand(uid uuid.UUID, resp chan coordinator.SessionCommand, container *UIContainer) {
|
func GetCommand(uid uuid.UUID, resp chan tome_lib.SessionCommand, container *UIContainer) {
|
||||||
for {
|
for {
|
||||||
var cmd string
|
var cmd string
|
||||||
var t int
|
var t int
|
||||||
@ -204,48 +203,48 @@ func GetCommand(uid uuid.UUID, resp chan coordinator.SessionCommand, container *
|
|||||||
switch t {
|
switch t {
|
||||||
case 0:
|
case 0:
|
||||||
//session
|
//session
|
||||||
switch coordinator.SessionCmd(cmd) {
|
switch tome_lib.SessionCmd(cmd) {
|
||||||
case coordinator.SessionCmdQuery:
|
case tome_lib.SessionCmdQuery:
|
||||||
resp <- coordinator.SessionCommand{
|
resp <- tome_lib.SessionCommand{
|
||||||
ID: uid,
|
ID: uid,
|
||||||
Command: coordinator.SessionCmdQuery,
|
Command: tome_lib.SessionCmdQuery,
|
||||||
}
|
}
|
||||||
case coordinator.SessionCmdJoin:
|
case tome_lib.SessionCmdJoin:
|
||||||
resp <- coordinator.SessionCommand{
|
resp <- tome_lib.SessionCommand{
|
||||||
ID: uid,
|
ID: uid,
|
||||||
MatchID: matchID,
|
MatchID: matchID,
|
||||||
Command: coordinator.SessionCmdJoin,
|
Command: tome_lib.SessionCmdJoin,
|
||||||
}
|
}
|
||||||
case coordinator.SessionCmdLeave:
|
case tome_lib.SessionCmdLeave:
|
||||||
resp <- coordinator.SessionCommand{
|
resp <- tome_lib.SessionCommand{
|
||||||
ID: uid,
|
ID: uid,
|
||||||
MatchID: matchID,
|
MatchID: matchID,
|
||||||
Command: coordinator.SessionCmdLeave,
|
Command: tome_lib.SessionCmdLeave,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
//state
|
//state
|
||||||
resp <- coordinator.SessionCommand{
|
resp <- tome_lib.SessionCommand{
|
||||||
ID: uid,
|
ID: uid,
|
||||||
MatchID: matchID,
|
MatchID: matchID,
|
||||||
Command: coordinator.SessionCmdPlay,
|
Command: tome_lib.SessionCmdPlay,
|
||||||
GameCommand: &game.Command{
|
GameCommand: &tome_lib.Command{
|
||||||
PlayerID: pid,
|
PlayerID: pid,
|
||||||
Type: game.StateCmd,
|
Type: tome_lib.StateCmd,
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
//action
|
//action
|
||||||
resp <- coordinator.SessionCommand{
|
resp <- tome_lib.SessionCommand{
|
||||||
ID: uid,
|
ID: uid,
|
||||||
MatchID: matchID,
|
MatchID: matchID,
|
||||||
Command: coordinator.SessionCmdPlay,
|
Command: tome_lib.SessionCmdPlay,
|
||||||
GameCommand: &game.Command{
|
GameCommand: &tome_lib.Command{
|
||||||
PlayerID: pid,
|
PlayerID: pid,
|
||||||
Type: game.ActCmd,
|
Type: tome_lib.ActCmd,
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"code.rocketnine.space/tslocum/cview"
|
"code.rocketnine.space/tslocum/cview"
|
||||||
"git.saintnet.tech/stryan/snengame/internal/game"
|
"git.saintnet.tech/tomecraft/tome_lib"
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UIContainer struct {
|
type UIContainer struct {
|
||||||
State *game.GameView
|
State *tome_lib.GameView
|
||||||
Updated chan bool
|
Updated chan bool
|
||||||
Output chan string
|
Output chan string
|
||||||
Input chan string
|
Input chan string
|
||||||
@ -60,9 +60,9 @@ func main() {
|
|||||||
var pv string
|
var pv string
|
||||||
if container.State != nil && container.State.Player != nil {
|
if container.State != nil && container.State.Player != nil {
|
||||||
ct := "Noone"
|
ct := "Noone"
|
||||||
if container.State.CurrentTurn == game.SentinalID {
|
if container.State.CurrentTurn == tome_lib.SentinalID {
|
||||||
ct = "Sentinal"
|
ct = "Sentinal"
|
||||||
} else if container.State.CurrentTurn == game.ScourgeID {
|
} else if container.State.CurrentTurn == tome_lib.ScourgeID {
|
||||||
ct = "Scourge"
|
ct = "Scourge"
|
||||||
}
|
}
|
||||||
pv = fmt.Sprintf("Your Life: %v\nEnemy Life: %v\nEnemy Hand size: %v\nEnemy Deck Size: %v\n\nCT:%v CD: %v, HD %v, Status: %v\n", container.State.Player.Life, container.State.EnemyLife, container.State.EnemyHandSize, container.State.EnemyDeckSize, ct, container.State.CanDraw, container.State.HasDrawn, container.State.Status)
|
pv = fmt.Sprintf("Your Life: %v\nEnemy Life: %v\nEnemy Hand size: %v\nEnemy Deck Size: %v\n\nCT:%v CD: %v, HD %v, Status: %v\n", container.State.Player.Life, container.State.EnemyLife, container.State.EnemyHandSize, container.State.EnemyDeckSize, ct, container.State.CanDraw, container.State.HasDrawn, container.State.Status)
|
||||||
|
8
go.mod
8
go.mod
@ -1,3 +1,11 @@
|
|||||||
module git.saintnet.tech/tome_client
|
module git.saintnet.tech/tome_client
|
||||||
|
|
||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
|
require (
|
||||||
|
code.rocketnine.space/tslocum/cview v1.5.7 // indirect
|
||||||
|
git.saintnet.tech/tomecraft/tome_lib v0.1.0 // indirect
|
||||||
|
github.com/gdamore/tcell/v2 v2.4.1-0.20210828201608-73703f7ed490 // indirect
|
||||||
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
github.com/gorilla/websocket v1.4.2 // indirect
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user