src to pkg, impl lobby.Closed
This commit is contained in:
49
pkg/state/priceiswrong/internal/event.go
Normal file
49
pkg/state/priceiswrong/internal/event.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package priceiswrong
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitea/price-is-wrong/pkg/lib/event"
|
||||
)
|
||||
|
||||
type Event interface{}
|
||||
|
||||
type Players struct {
|
||||
IDs []int
|
||||
}
|
||||
|
||||
type Host struct {
|
||||
ID int
|
||||
}
|
||||
|
||||
type Score struct {
|
||||
ID int
|
||||
Score int
|
||||
}
|
||||
|
||||
type Item struct {
|
||||
ImageURL string
|
||||
Title string
|
||||
Description string
|
||||
Value string
|
||||
}
|
||||
|
||||
type Guess struct {
|
||||
ID int
|
||||
Guess string
|
||||
}
|
||||
|
||||
func ParseEvent(b []byte) (Event, error) {
|
||||
typesToPointers := map[string]any{
|
||||
"*priceiswrong.Players": &Players{},
|
||||
"*priceiswrong.Host": &Host{},
|
||||
"*priceiswrong.Score": &Score{},
|
||||
"*priceiswrong.Item": &Item{},
|
||||
"*priceiswrong.Guess": &Guess{},
|
||||
}
|
||||
t, err := event.Parse(b, typesToPointers)
|
||||
return typesToPointers[t], err
|
||||
}
|
||||
|
||||
func MarshalEvent(e Event) ([]byte, error) {
|
||||
return event.Serialize(fmt.Sprintf("%T", e), e)
|
||||
}
|
||||
Reference in New Issue
Block a user