storage

package
v0.0.0-...-7ca9688 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const GameEntity = "KaiserGame"

Variables

View Source
var (
	ErrNotFound             = errors.New("Not found")
	ErrNotUnique            = errors.New("ID is not unique")
	ErrPlayerPositionFilled = errors.New("Player position is already filled")
	ErrPlayerAlreadyAdded   = errors.New("Player is already added")
)
View Source
var (
	// ErrCacheMiss means the item was not found in the cache.
	ErrCacheMiss = errors.New("Not in cache")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get gets a value for a key. Returns ErrCacheMiss if not found.
	Get(ctx context.Context, key string) (string, error)
	// Set sets a value for a key. Use timeout=0 for "forever".
	// Of course, since this is a "cache", nothing is guaranted and the item may disappear at any time.
	Set(ctx context.Context, key, value string, timeout time.Duration) error
	// Clear clears the cache key.
	Clear(ctx context.Context, key string) error
}

Cache stores key/value pairs inexpensively.

func NewFakeCache

func NewFakeCache() Cache

NewFakeCache creates simple memory-backed cache.

func NewMemcacheCache

func NewMemcacheCache() Cache

NewMemcacheCache creates a cache backed by appengine.memcache.

type Game

type Game struct {
	Key       *datastore.Key
	PlayerIDs []string // Organizing player is 0-index; clockwise afterwards (e.g., 0 and 2 are partners).
	Created   time.Time
	Updated   time.Time
	Complete  bool

	Score string `datastore:",noindex"` // The running tally of the game.

	CurrentDealerPos int    `datastore:",noindex"` // The position of the current dealer.
	CurrentBidding   string `datastore:",noindex"` // The bids for the current hand; 0-index is the player clockwise from the CurrentDealerPos (one higher, wrapping at 4).
	CurrentHands     string `datastore:",noindex"` // Cards held by each player, parallel with the PlayerIDs above.
	CurrentTrick     string `datastore:",noindex"` // Cards played for current trick; 0-index is the lead player (i.e., the order the cards were played).
	LastTrick        string `datastore:",noindex"` // Cards played for the previous trick.
	CurrentTally     string `datastore:",noindex"` // The running tally for the current hand.

	PassedCards string `datastore:",noindex"` // Cards passed for the current trick.

	Rules Rules
}

func (*Game) Load

func (x *Game) Load(ps []datastore.Property) error

func (*Game) LoadKey

func (x *Game) LoadKey(k *datastore.Key) error

func (*Game) Save

func (x *Game) Save() ([]datastore.Property, error)

type GameStore

type GameStore interface {
	Create(ctx context.Context, id, organizingPlayerID string, rules Rules) (*Game, error)
	Get(ctx context.Context, id string) (*Game, error)
	Set(ctx context.Context, id string, g *Game) error
	AddPlayer(ctx context.Context, id, playerID string, pos int) (*Game, error)
	GetCurrentGames(ctx context.Context, playerID string, count int) ([]*Game, error)
}

func NewDatastoreGameStore

func NewDatastoreGameStore() GameStore

func NewFakeGameStore

func NewFakeGameStore(games map[string]*Game) GameStore

NewFakeGameStore creates an in-memory game store, accepting an initial map of id->*Game.

type Player

type Player struct {
	Name string `datastore:",noindex"`
}

type PlayerStore

type PlayerStore interface {
	Create(ctx context.Context, id, name string) (*Player, error)
	Get(ctx context.Context, id string) (*Player, error)
	GetMulti(ctx context.Context, ids []string) ([]*Player, error)
	Set(ctx context.Context, id string, p *Player) error
}

func NewDatastorePlayerStore

func NewDatastorePlayerStore() PlayerStore

func NewFakePlayerStore

func NewFakePlayerStore(ids ...string) PlayerStore

NewFakePlayerStore creates an in-memory player store.

type Rules

type Rules struct {
	PassCard bool `datastore:",noindex"` // Players pass one card before bidding.
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL