2023-06-07 23:01:06 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
"reflect"
|
2023-06-13 14:10:59 -06:00
|
|
|
"fmt"
|
2023-06-16 01:46:15 -06:00
|
|
|
"errors"
|
|
|
|
"time"
|
2023-06-07 23:01:06 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func GQLVexTypes() map[reflect.Type]*graphql.Object {
|
|
|
|
types := map[reflect.Type]*graphql.Object{}
|
|
|
|
types[reflect.TypeOf((*Match)(nil))] = GQLVexTypeMatch()
|
|
|
|
|
|
|
|
return types
|
|
|
|
}
|
|
|
|
|
2023-06-13 14:10:59 -06:00
|
|
|
func GQLVexMutations() map[string]*graphql.Field {
|
|
|
|
mutations := map[string]*graphql.Field{}
|
2023-06-16 01:46:15 -06:00
|
|
|
mutations["setMatchState"] = GQLVexMutationSetMatchState()
|
2023-06-13 14:10:59 -06:00
|
|
|
return mutations
|
|
|
|
}
|
|
|
|
|
|
|
|
func GQLVexQueries() map[string]*graphql.Field {
|
|
|
|
queries := map[string]*graphql.Field{}
|
|
|
|
queries["Arenas"] = GQLVexQueryArenas()
|
|
|
|
return queries
|
|
|
|
}
|
|
|
|
|
|
|
|
func FindResources(event Event, resource_type reflect.Type) []Resource {
|
|
|
|
resources := event.RequiredResources()
|
2023-06-13 14:23:33 -06:00
|
|
|
found := []Resource{}
|
|
|
|
for _, resource := range(resources) {
|
|
|
|
if reflect.TypeOf(resource) == resource_type {
|
|
|
|
found = append(found, resource)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-13 14:10:59 -06:00
|
|
|
for _, child := range(event.Children()) {
|
2023-06-13 14:23:33 -06:00
|
|
|
found = append(found, FindResources(child, resource_type)...)
|
2023-06-13 14:10:59 -06:00
|
|
|
}
|
|
|
|
|
2023-06-13 14:23:33 -06:00
|
|
|
m := map[string]Resource{}
|
|
|
|
for _, resource := range(found) {
|
|
|
|
m[resource.ID()] = resource
|
|
|
|
}
|
|
|
|
ret := []Resource{}
|
|
|
|
for _, resource := range(m) {
|
|
|
|
ret = append(ret, resource)
|
|
|
|
}
|
|
|
|
return ret
|
2023-06-13 14:10:59 -06:00
|
|
|
}
|
|
|
|
|
2023-06-16 01:46:15 -06:00
|
|
|
var gql_vex_mutation_set_match_state *graphql.Field= nil
|
|
|
|
func GQLVexMutationSetMatchState() *graphql.Field {
|
|
|
|
if gql_vex_mutation_set_match_state == nil {
|
|
|
|
gql_vex_mutation_set_match_state = &graphql.Field{
|
|
|
|
Type: GQLTypeSignal(),
|
|
|
|
Args: graphql.FieldConfigArgument{
|
|
|
|
"id": &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
"state": &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
"time": &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.DateTime,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
server, ok := p.Context.Value("gql_server").(*GQLServer)
|
|
|
|
if ok == false {
|
|
|
|
return nil, fmt.Errorf("Failed to cast context gql_server to GQLServer: %+v", p.Context.Value("gql_server"))
|
|
|
|
}
|
|
|
|
|
|
|
|
id, ok := p.Args["id"].(string)
|
|
|
|
if ok == false {
|
|
|
|
return nil, errors.New("Failed to cast arg id to string")
|
|
|
|
}
|
|
|
|
|
|
|
|
state, ok := p.Args["state"].(string)
|
|
|
|
if ok == false {
|
|
|
|
return nil, errors.New("Failed to cast arg state to string")
|
|
|
|
}
|
|
|
|
|
|
|
|
start, ok := p.Args["time"].(time.Time)
|
|
|
|
if ok == false {
|
|
|
|
start = time.Now()
|
|
|
|
}
|
|
|
|
|
|
|
|
signal := NewSignal(server, state)
|
|
|
|
signal.description = id
|
|
|
|
signal.time = start
|
|
|
|
|
|
|
|
owner := server.Owner()
|
|
|
|
if owner == nil {
|
|
|
|
return nil, errors.New("Cannot send update without owner")
|
|
|
|
}
|
|
|
|
|
|
|
|
root_event, ok := owner.(Event)
|
|
|
|
if ok == false {
|
|
|
|
return nil, errors.New("Cannot send update to Event unless owned by an Event")
|
|
|
|
}
|
|
|
|
|
|
|
|
node := FindChild(root_event, id)
|
|
|
|
if node == nil {
|
|
|
|
return nil, errors.New("Failed to find id in event tree from server")
|
|
|
|
}
|
|
|
|
|
|
|
|
SendUpdate(node, signal)
|
|
|
|
|
|
|
|
return signal, nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return gql_vex_mutation_set_match_state
|
|
|
|
}
|
|
|
|
|
2023-06-13 14:10:59 -06:00
|
|
|
var gql_vex_query_arenas *graphql.Field = nil
|
|
|
|
func GQLVexQueryArenas() *graphql.Field {
|
|
|
|
if gql_vex_query_arenas == nil {
|
|
|
|
gql_vex_query_arenas = &graphql.Field{
|
|
|
|
Type: GQLVexListArena(),
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
server, ok := p.Context.Value("gql_server").(*GQLServer)
|
|
|
|
if ok == false {
|
|
|
|
panic("Failed to get/cast gql_server from context")
|
|
|
|
}
|
|
|
|
|
|
|
|
owner, is_event := server.Owner().(Event)
|
|
|
|
if is_event == false {
|
|
|
|
return nil, fmt.Errorf("Can't enumerate arenas when server is attached to resource")
|
|
|
|
}
|
2023-06-13 14:23:33 -06:00
|
|
|
return FindResources(owner, reflect.TypeOf((*VirtualArena)(nil))), nil
|
2023-06-13 14:10:59 -06:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return gql_vex_query_arenas
|
|
|
|
}
|
|
|
|
|
|
|
|
var gql_vex_list_arena * graphql.List = nil
|
|
|
|
func GQLVexListArena() * graphql.List {
|
|
|
|
if gql_vex_list_arena == nil {
|
|
|
|
gql_vex_list_arena = graphql.NewList(GQLVexTypeArena())
|
|
|
|
}
|
|
|
|
return gql_vex_list_arena
|
|
|
|
}
|
|
|
|
|
2023-06-08 00:19:55 -06:00
|
|
|
var gql_vex_list_team * graphql.List = nil
|
|
|
|
func GQLVexListTeam() * graphql.List {
|
|
|
|
if gql_vex_list_team == nil {
|
|
|
|
gql_vex_list_team = graphql.NewList(GQLVexTypeTeam())
|
|
|
|
}
|
|
|
|
return gql_vex_list_team
|
|
|
|
}
|
|
|
|
|
|
|
|
var gql_vex_list_alliance * graphql.List = nil
|
|
|
|
func GQLVexListAlliance() * graphql.List {
|
|
|
|
if gql_vex_list_alliance == nil {
|
|
|
|
gql_vex_list_alliance = graphql.NewList(GQLVexTypeAlliance())
|
|
|
|
}
|
|
|
|
return gql_vex_list_alliance
|
|
|
|
}
|
|
|
|
|
|
|
|
func GQLVexMatchAlliances(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return GQLEventFn(p, func(event Event, p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return event.(*Match).alliances, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-06-08 00:36:16 -06:00
|
|
|
func GQLVexMatchArena(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return GQLEventFn(p, func(event Event, p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return event.(*Match).arena, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-06-08 16:48:28 -06:00
|
|
|
func GQLVexMatchControl(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return GQLEventFn(p, func(event Event, p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return event.(*Match).control, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func GQLVexMatchState(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return GQLEventFn(p, func(event Event, p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return event.(*Match).state, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-06-08 00:36:16 -06:00
|
|
|
func GQLVexAllianceTeams(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return GQLResourceFn(p, func(resource Resource, p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return resource.(*Alliance).teams, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var gql_vex_type_arena * graphql.Object = nil
|
|
|
|
func GQLVexTypeArena() * graphql.Object {
|
|
|
|
if gql_vex_type_arena == nil {
|
|
|
|
gql_vex_type_arena = graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: "Arena",
|
|
|
|
Interfaces: []*graphql.Interface{
|
2023-06-13 15:29:23 -06:00
|
|
|
GQLInterfaceNode(),
|
2023-06-08 00:36:16 -06:00
|
|
|
GQLInterfaceResource(),
|
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
|
|
|
_, ok := p.Value.(Arena)
|
|
|
|
return ok
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_vex_type_arena.AddFieldConfig("ID", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLResourceID,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_vex_type_arena.AddFieldConfig("Name", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLResourceName,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_vex_type_arena.AddFieldConfig("Description", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLResourceDescription,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_vex_type_arena.AddFieldConfig("Parents", &graphql.Field{
|
|
|
|
Type: GQLListResource(),
|
|
|
|
Resolve: GQLResourceParents,
|
|
|
|
})
|
2023-06-13 15:29:23 -06:00
|
|
|
|
|
|
|
gql_vex_type_arena.AddFieldConfig("Owner", &graphql.Field{
|
|
|
|
Type: GQLInterfaceNode(),
|
|
|
|
Resolve: GQLResourceOwner,
|
|
|
|
})
|
2023-06-08 00:36:16 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return gql_vex_type_arena
|
|
|
|
}
|
|
|
|
|
2023-06-07 23:01:06 -06:00
|
|
|
var gql_vex_type_match * graphql.Object = nil
|
|
|
|
func GQLVexTypeMatch() * graphql.Object {
|
|
|
|
if gql_vex_type_match == nil {
|
|
|
|
gql_vex_type_match = graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: "Match",
|
|
|
|
Interfaces: []*graphql.Interface{
|
2023-06-13 15:29:23 -06:00
|
|
|
GQLInterfaceNode(),
|
2023-06-07 23:01:06 -06:00
|
|
|
GQLInterfaceEvent(),
|
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
|
|
|
_, ok := p.Value.(*Match)
|
|
|
|
return ok
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_vex_type_match.AddFieldConfig("ID", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLEventID,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_vex_type_match.AddFieldConfig("Name", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLEventName,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_vex_type_match.AddFieldConfig("Description", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLEventDescription,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_vex_type_match.AddFieldConfig("Children", &graphql.Field{
|
|
|
|
Type: GQLListEvent(),
|
|
|
|
Resolve: GQLEventChildren,
|
|
|
|
})
|
2023-06-08 00:19:55 -06:00
|
|
|
|
|
|
|
gql_vex_type_match.AddFieldConfig("Alliances", &graphql.Field{
|
|
|
|
Type: GQLVexListAlliance(),
|
|
|
|
Resolve: GQLVexMatchAlliances,
|
|
|
|
})
|
2023-06-08 00:36:16 -06:00
|
|
|
|
|
|
|
gql_vex_type_match.AddFieldConfig("Arena", &graphql.Field{
|
2023-06-08 16:48:28 -06:00
|
|
|
Type: graphql.String,
|
2023-06-08 00:36:16 -06:00
|
|
|
Resolve: GQLVexMatchArena,
|
|
|
|
})
|
2023-06-08 16:48:28 -06:00
|
|
|
|
|
|
|
gql_vex_type_match.AddFieldConfig("Control", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLVexMatchControl,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_vex_type_match.AddFieldConfig("State", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLVexMatchState,
|
|
|
|
})
|
2023-06-07 23:01:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return gql_vex_type_match
|
|
|
|
}
|
2023-06-08 00:19:55 -06:00
|
|
|
|
|
|
|
var gql_vex_type_alliance * graphql.Object = nil
|
|
|
|
func GQLVexTypeAlliance() * graphql.Object {
|
|
|
|
if gql_vex_type_alliance == nil {
|
|
|
|
gql_vex_type_alliance = graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: "Alliance",
|
|
|
|
Interfaces: []*graphql.Interface{
|
2023-06-13 15:29:23 -06:00
|
|
|
GQLInterfaceNode(),
|
2023-06-08 00:19:55 -06:00
|
|
|
GQLInterfaceResource(),
|
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
|
|
|
_, ok := p.Value.(*Alliance)
|
|
|
|
return ok
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
2023-06-08 00:36:16 -06:00
|
|
|
gql_vex_type_alliance.AddFieldConfig("ID", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLResourceID,
|
|
|
|
})
|
2023-06-08 00:19:55 -06:00
|
|
|
|
2023-06-08 00:36:16 -06:00
|
|
|
gql_vex_type_alliance.AddFieldConfig("Name", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLResourceName,
|
|
|
|
})
|
2023-06-08 00:19:55 -06:00
|
|
|
|
2023-06-08 00:36:16 -06:00
|
|
|
gql_vex_type_alliance.AddFieldConfig("Description", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLResourceDescription,
|
|
|
|
})
|
2023-06-08 00:19:55 -06:00
|
|
|
|
2023-06-08 00:36:16 -06:00
|
|
|
gql_vex_type_alliance.AddFieldConfig("Parents", &graphql.Field{
|
|
|
|
Type: GQLListResource(),
|
|
|
|
Resolve: GQLResourceParents,
|
|
|
|
})
|
|
|
|
|
2023-06-13 15:29:23 -06:00
|
|
|
gql_vex_type_alliance.AddFieldConfig("Owner", &graphql.Field{
|
|
|
|
Type: GQLInterfaceNode(),
|
|
|
|
Resolve: GQLResourceOwner,
|
|
|
|
})
|
|
|
|
|
2023-06-08 00:36:16 -06:00
|
|
|
gql_vex_type_alliance.AddFieldConfig("Teams", &graphql.Field{
|
|
|
|
Type: GQLVexListTeam(),
|
|
|
|
Resolve: GQLVexAllianceTeams,
|
|
|
|
})
|
|
|
|
}
|
2023-06-08 00:19:55 -06:00
|
|
|
|
|
|
|
return gql_vex_type_alliance
|
|
|
|
}
|
|
|
|
|
|
|
|
var gql_vex_type_team * graphql.Object = nil
|
|
|
|
func GQLVexTypeTeam() * graphql.Object {
|
|
|
|
if gql_vex_type_team == nil {
|
|
|
|
gql_vex_type_team = graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: "Team",
|
|
|
|
Interfaces: []*graphql.Interface{
|
2023-06-13 15:29:23 -06:00
|
|
|
GQLInterfaceNode(),
|
2023-06-08 00:19:55 -06:00
|
|
|
GQLInterfaceResource(),
|
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
|
|
|
_, ok := p.Value.(*Team)
|
|
|
|
return ok
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
gql_vex_type_team.AddFieldConfig("ID", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLResourceID,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_vex_type_team.AddFieldConfig("Name", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLResourceName,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_vex_type_team.AddFieldConfig("Description", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLResourceDescription,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_vex_type_team.AddFieldConfig("Parents", &graphql.Field{
|
|
|
|
Type: GQLListResource(),
|
|
|
|
Resolve: GQLResourceParents,
|
|
|
|
})
|
|
|
|
|
2023-06-13 15:29:23 -06:00
|
|
|
gql_vex_type_team.AddFieldConfig("Owner", &graphql.Field{
|
|
|
|
Type: GQLInterfaceNode(),
|
|
|
|
Resolve: GQLResourceOwner,
|
|
|
|
})
|
|
|
|
|
2023-06-08 00:19:55 -06:00
|
|
|
return gql_vex_type_team
|
|
|
|
}
|