src to pkg, impl lobby.Closed

This commit is contained in:
Bel LaPointe
2025-02-12 16:48:58 -07:00
parent 1f6b79aa3b
commit e35ddef4b7
18 changed files with 117 additions and 21 deletions

View 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)
}