store

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MapImages = map[int]image.Image{}

	MapImageKeyFmt = "m-%d"
)

Functions

This section is empty.

Types

type Line added in v1.0.3

type Line struct {
	Towers map[string]*Tower
	Units  map[string]*Unit

	Graph *graph.Graph

	// UpdatedAt is the last time
	// something was updated on this Line.
	// Towers added, Units added or
	// when the Units position was updated
	// the last time.
	// Used for the SyncState to know how much
	// time has passed since the last update
	// and move the Units accordingly
	// (60 moves per second pass)
	UpdatedAt time.Time
}

type Lines added in v1.0.3

type Lines struct {
	*flux.ReduceStore
	// contains filtered or unexported fields
}

func NewLines added in v1.0.3

func NewLines(d *flux.Dispatcher, s *Store) *Lines

func (*Lines) FindByID added in v1.0.3

func (ls *Lines) FindByID(id int) *Line

func (*Lines) List added in v1.0.3

func (ls *Lines) List() []*Line

func (*Lines) Reduce added in v1.0.3

func (ls *Lines) Reduce(state, a interface{}) interface{}

type LinesState added in v1.0.3

type LinesState struct {
	Lines map[int]*Line
}

type Map

type Map struct {
	*flux.ReduceStore
	// contains filtered or unexported fields
}

Map is a struct that holds all the information of the current map

func NewMap

func NewMap(d *flux.Dispatcher, s *Store) *Map

NewMap initializes the map

func (*Map) GetHomeCoordinates

func (m *Map) GetHomeCoordinates(lid int) (int, int)

func (*Map) GetImageKey added in v1.0.3

func (m *Map) GetImageKey() string

GetY returns the max Y value of the map

func (*Map) GetNextLineID

func (m *Map) GetNextLineID(clid int) int

GetNextLineID based on the map and max number of players it returns the next one and when it reaches the end then starts again

func (*Map) GetX

func (m *Map) GetX() int

GetX returns the max X value of the map

func (*Map) GetY

func (m *Map) GetY() int

GetY returns the max Y value of the map

func (*Map) Reduce

func (m *Map) Reduce(state, a interface{}) interface{}

type MapState

type MapState struct {
	Players int
	Image   image.Image
}

type Player

type Player struct {
	ID      string
	Name    string
	Lives   int
	LineID  int
	Income  int
	Gold    int
	Current bool
	Winner  bool
}

func (Player) CanPlaceTower

func (p Player) CanPlaceTower(tt string) bool

func (Player) CanSummonUnit

func (p Player) CanSummonUnit(ut string) bool

type Players

type Players struct {
	*flux.ReduceStore
	// contains filtered or unexported fields
}

func NewPlayers

func NewPlayers(d *flux.Dispatcher, s *Store) *Players

func (*Players) FindByID

func (ps *Players) FindByID(id string) Player

func (*Players) FindByLineID

func (ps *Players) FindByLineID(lid int) Player

func (*Players) FindCurrent

func (ps *Players) FindCurrent() Player

func (*Players) List

func (ps *Players) List() []*Player

GetPlayers returns the players list and it's meant for reading only purposes

func (*Players) Reduce

func (ps *Players) Reduce(state, a interface{}) interface{}

type PlayersState

type PlayersState struct {
	Players map[string]*Player

	// IncomeTimer is the internal counter that goes from 15 to 0
	IncomeTimer int
}

type Store

type Store struct {
	Players *Players
	Lines   *Lines
	Map     *Map
	// contains filtered or unexported fields
}

func NewStore

func NewStore(d *flux.Dispatcher, l *slog.Logger) *Store

func (*Store) Dispatch

func (s *Store) Dispatch(a *action.Action)

type Tower

type Tower struct {
	utils.Object

	ID string

	Type     string
	LineID   int
	PlayerID string
}

func (*Tower) FacetKey added in v1.0.3

func (t *Tower) FacetKey() string

type Unit

type Unit struct {
	utils.MovingObject

	ID string

	Type          string
	PlayerID      string
	PlayerLineID  int
	CurrentLineID int

	Health float64

	Path     []graph.Step
	HashPath string

	// CreatedAt has the time of creation so
	// on the next SyncState will be moved just
	// the diff amount and then it'll be set to 'nil'
	// so we know it's on sync
	CreatedAt time.Time
}

func (*Unit) FacesetKey added in v1.0.3

func (u *Unit) FacesetKey() string

func (*Unit) SpriteKey added in v1.0.3

func (u *Unit) SpriteKey() string

Jump to

Keyboard shortcuts

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