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) {
return GQLResourceFn(p, func(resource Resource, p graphql.ResolveParams) (interface{}, error) {
return resource.(*Alliance).teams, nil
@ -331,6 +343,16 @@ func GQLVexTypeMatch() * graphql.Object {
Type: graphql.String,
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

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

@ -148,6 +148,7 @@ type Match struct {
state string
control string
control_start time.Time
control_duration int
alliances []*Alliance
}
@ -165,6 +166,7 @@ func NewMatch(alliance0 * Alliance, alliance1 * Alliance, arena Arena) * Match {
state: "init",
control: "init",
control_start: time.UnixMilli(0),
control_duration: 0,
arena: arena,
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())
match.control = "none"
match.state = "scheduled"
match.control_start = time.Now()
return "wait", nil
}