game_sync/gamesrv/slotspkg/slots/machine/machine.go

64 lines
1.6 KiB
Go

package machine
import (
"mongo.games.com/game/gamesrv/base"
"mongo.games.com/game/gamesrv/slotspkg/internal/generic/errors"
"mongo.games.com/game/gamesrv/slotspkg/internal/generic/key"
"mongo.games.com/game/gamesrv/slotspkg/internal/module/player"
"mongo.games.com/game/gamesrv/slotspkg/internal/module/shell"
"mongo.games.com/game/gamesrv/slotspkg/slots/entity"
"mongo.games.com/game/gamesrv/slotspkg/slots/intf"
)
// Machine is wrapper for entity
type Machine struct {
*entity.Entity
}
// NewMachine creates a new machine with Spinner interface
func NewMachine(s *base.SlotsSession, theme string, shell *shell.Shell, isFree bool) intf.Spinner {
p := player.Get(s)
if theme == "" {
panic(errors.LeakTheme.ErrorWith(p.UID.Get()))
}
m := &Machine{}
m.Entity = entity.NewEntity(s, theme, m, shell, isFree)
m.Init()
oldMachineInter := m.Session.Value(key.SessionMachine)
if oldMachineInter != nil {
oldMachine := oldMachineInter.(*Machine)
m.Data = oldMachine.Data
}
m.Session.Set(key.SessionMachine, m)
return m
}
// Node gets specific node
func (m *Machine) Node(nodeID int64) intf.Node {
return asNodeIntf(m, m.GetNode(nodeID))
}
// Cursor gets cursor node
func (m *Machine) Cursor() intf.Node {
return asNodeIntf(m, m.CursorNode())
}
// Root gets root node
func (m *Machine) Root() intf.Node {
return asNodeIntf(m, m.RootNode())
}
// Root gets root node
func (m *Machine) Next() intf.Node {
return asNodeIntf(m, m.NextNode())
}
// GetParentNode gets cursor node
func (m *Machine) Parent() intf.Node {
return asNodeIntf(m, m.ParentNode())
}
func (m *Machine) Ancestor() intf.Node {
return asNodeIntf(m, m.AncestorNode())
}