Buttons to control game state

graph-rework
noah metz 2023-06-16 18:50:19 -06:00
parent d5c1340555
commit 8e0bb14f40
3 changed files with 43 additions and 19 deletions

@ -225,6 +225,18 @@ func GQLVexMatchState(p graphql.ResolveParams) (interface{}, error) {
}) })
} }
func GQLVexMatchStateStart(p graphql.ResolveParams) (interface{}, error) {
return GQLEventFn(p, func(event Event, p graphql.ResolveParams) (interface{}, error) {
return event.(*Match).control_start, nil
})
}
func GQLVexMatchStateDuration(p graphql.ResolveParams) (interface{}, error) {
return GQLEventFn(p, func(event Event, p graphql.ResolveParams) (interface{}, error) {
return event.(*Match).control_duration, nil
})
}
func GQLVexAllianceTeams(p graphql.ResolveParams) (interface{}, error) { func GQLVexAllianceTeams(p graphql.ResolveParams) (interface{}, error) {
return GQLResourceFn(p, func(resource Resource, p graphql.ResolveParams) (interface{}, error) { return GQLResourceFn(p, func(resource Resource, p graphql.ResolveParams) (interface{}, error) {
return resource.(*Alliance).teams, nil return resource.(*Alliance).teams, nil
@ -331,6 +343,16 @@ func GQLVexTypeMatch() * graphql.Object {
Type: graphql.String, Type: graphql.String,
Resolve: GQLVexMatchState, Resolve: GQLVexMatchState,
}) })
gql_vex_type_match.AddFieldConfig("StateStart", &graphql.Field{
Type: graphql.DateTime,
Resolve: GQLVexMatchStateStart,
})
gql_vex_type_match.AddFieldConfig("StateDuration", &graphql.Field{
Type: graphql.Int,
Resolve: GQLVexMatchStateDuration,
})
} }
return gql_vex_type_match return gql_vex_type_match

@ -11,31 +11,38 @@ const client = createClient({
keepAlive: 10_000, keepAlive: 10_000,
}); });
var game_id = "5746b429-de0b-409b-b10f-e64bd2faa02c" var game_id = null
var arena_id = null
console.log("STARTING_CLIENT") console.log("STARTING_CLIENT")
client.subscribe({
query: "query { Arenas { Name ID Owner { Name, ID } }}"
},
{
next: (data) => {
let obj = JSON.parse(data.data)
arena_id = obj.Arenas[0].ID
game_id = obj.Arenas[0].Owner.ID
client.subscribe({ client.subscribe({
query: "query { Arenas { Name Owner { ... on Match { Name, ID } } } }" query: "subscription($arena_id:String) { Arena(arena_id:$arena_id) { Owner { Name ... on Match { State Control StateStart StateDuration } } }}",
variables: {
arena_id: arena_id
},
}, },
{ {
next: (data) => { next: (data) => {
console.log("ARENA_SUB")
console.log(data) console.log(data)
}, },
error: (err) => { error: (err) => {
console.log("ARENA_SUB")
console.log(err) console.log(err)
}, },
complete: () => { complete: () => {
}, },
}); });
client.subscribe({
query: "subscription { Updates { String } }"
},
{
next: (data) => {
console.log(data)
}, },
error: (err) => { error: (err) => {
console.log(err) console.log(err)
@ -45,27 +52,19 @@ client.subscribe({
}); });
client.subscribe({ client.subscribe({
query: "subscription($arena_id:String) { Arena(arena_id:$arena_id) { Owner { Name }} }", query: "subscription { Updates { String } }"
variables: {
arena_id: "bcd6c679-964f-4c4a-96e1-58e39032ded8"
},
}, },
{ {
next: (data) => { next: (data) => {
console.log("ARENA_SUB")
console.log(data) console.log(data)
}, },
error: (err) => { error: (err) => {
console.log("ARENA_SUB")
console.log(err) console.log(err)
}, },
complete: () => { complete: () => {
}, },
}); });
async function match_state(match_id, state) { async function match_state(match_id, state) {
let url = "http://localhost:8080/gql" let url = "http://localhost:8080/gql"
let data = { let data = {

@ -148,6 +148,7 @@ type Match struct {
state string state string
control string control string
control_start time.Time control_start time.Time
control_duration int
alliances []*Alliance alliances []*Alliance
} }
@ -165,6 +166,7 @@ func NewMatch(alliance0 * Alliance, alliance1 * Alliance, arena Arena) * Match {
state: "init", state: "init",
control: "init", control: "init",
control_start: time.UnixMilli(0), control_start: time.UnixMilli(0),
control_duration: 0,
arena: arena, arena: arena,
alliances: []*Alliance{alliance0, alliance1}, alliances: []*Alliance{alliance0, alliance1},
} }
@ -176,6 +178,7 @@ func NewMatch(alliance0 * Alliance, alliance1 * Alliance, arena Arena) * Match {
log.Logf("vex", "STARTING_MATCH %s", match.Name()) log.Logf("vex", "STARTING_MATCH %s", match.Name())
match.control = "none" match.control = "none"
match.state = "scheduled" match.state = "scheduled"
match.control_start = time.Now()
return "wait", nil return "wait", nil
} }