engine

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: EUPL-1.2 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendText

func AppendText(message string, chatlog io.Writer)

func BindRooms

func BindRooms(room *Room, exit Exit, otherRooms ...*Room)

func BindRoomsBidirectional

func BindRoomsBidirectional(room *Room, exit Exit, otherRooms ...*Room)

func ErrorBox

func ErrorBox(message string, app *tview.Application, back tview.Primitive)

func FetchPlugin

func FetchPlugin[T Plugin](engine *Akevitt) (*T, error)

func FetchPluginUnsafe

func FetchPluginUnsafe[T Plugin](engine *Akevitt) T

func FilterByType

func FilterByType[T any, TCollection any](collection []TCollection) []T

func Find

func Find[T comparable](collection []T, value T) bool

func FindByKey

func FindByKey[TCollection, T comparable](collection []TCollection, selector func(key TCollection) T, value T) *TCollection

func FindNeighboringRoomByName

func FindNeighboringRoomByName(currentRoom *Room, name string) (*Room, *Exit, error)

func GetMapKeys

func GetMapKeys[TKey comparable, TMap map[TKey]TValues, TValues any](m TMap) (keys []TKey)

func GetMapValues

func GetMapValues[TKey comparable, TMap map[TKey]TResult, TResult any](m TMap) (values []TResult)

func GetScriptName

func GetScriptName(command string) string

func LogError

func LogError(message string)

func LogInfo

func LogInfo(message string)

func LogWarn

func LogWarn(message string)

func LookupOfType

func LookupOfType[T Object](room *Room) []T

func MapSlice

func MapSlice[T any, TResult any](l []T, callback func(v T) TResult) []TResult

func NewEngine

func NewEngine() *akevittBuilder

func NewSessionScreen

func NewSessionScreen(s ssh.Session) (tcell.Screen, error)

func PurgeDeadSessions

func PurgeDeadSessions(engine *Akevitt, callback ...DeadSessionFunc)

func RemoveItem

func RemoveItem[T comparable](l []T, item T) []T

func RemoveItemByIndex

func RemoveItemByIndex[T any](l []T, i int) []T

func SplitCommand

func SplitCommand(command string) []string

Types

type Account

type Account struct {
	ObjectImpl
	Username       string
	Password       string
	PersistentData map[string]any
}

Account is a basic structure for storing credential information.

func (*Account) GetName

func (account *Account) GetName() string

func (*Account) Save

func (account *Account) Save(engine *Akevitt) error

type ActiveSession

type ActiveSession struct {
	Account     *Account
	Application *tview.Application
	Data        map[string]any
	RoomID      string
}

func (*ActiveSession) Send

func (session *ActiveSession) Send(message string)

func (*ActiveSession) SendLines

func (session *ActiveSession) SendLines(lines ...string)

func (*ActiveSession) Sendf

func (session *ActiveSession) Sendf(format string, args ...any)

type Akevitt

type Akevitt struct {
	// contains filtered or unexported fields
}

func (*Akevitt) AddCommand

func (engine *Akevitt) AddCommand(command string, function CommandFunc)

func (*Akevitt) AddInit

func (engine *Akevitt) AddInit(fn func(*Akevitt, *ActiveSession))

func (*Akevitt) AddItem

func (engine *Akevitt) AddItem(item *Item)

func (*Akevitt) AddNPC

func (engine *Akevitt) AddNPC(npc *NPC)

func (*Akevitt) AddRoom

func (engine *Akevitt) AddRoom(room *Room) error

func (*Akevitt) AddSessionDead

func (engine *Akevitt) AddSessionDead(fn DeadSessionFunc)

func (*Akevitt) ExecuteCommand

func (engine *Akevitt) ExecuteCommand(command string, session *ActiveSession) error

func (*Akevitt) ExecuteLuaCommand

func (engine *Akevitt) ExecuteLuaCommand(command string, session *ActiveSession) error

func (*Akevitt) GetCommands

func (engine *Akevitt) GetCommands() []string

func (*Akevitt) GetItemByGUID

func (engine *Akevitt) GetItemByGUID(guid string) *Item

func (*Akevitt) GetLuaVM

func (engine *Akevitt) GetLuaVM() *LuaVM

func (*Akevitt) GetNPCByGUID

func (engine *Akevitt) GetNPCByGUID(guid string) *NPC

func (*Akevitt) GetNPCByName

func (engine *Akevitt) GetNPCByName(name string) *NPC

func (*Akevitt) GetOnDeadSession

func (engine *Akevitt) GetOnDeadSession() []DeadSessionFunc

func (*Akevitt) GetRoom

func (engine *Akevitt) GetRoom(key uint64) (*Room, error)

func (*Akevitt) GetRoomByGUID

func (engine *Akevitt) GetRoomByGUID(guid string) *Room

func (*Akevitt) GetRoomByName

func (engine *Akevitt) GetRoomByName(name string) *Room

func (*Akevitt) GetSessions

func (engine *Akevitt) GetSessions() Sessions

func (*Akevitt) GetSpawnRoom

func (engine *Akevitt) GetSpawnRoom() *Room

func (*Akevitt) GlobalLookup

func (engine *Akevitt) GlobalLookup(room *Room, name string) []Object

func (*Akevitt) LoadLuaScript

func (engine *Akevitt) LoadLuaScript(path string) error

func (*Akevitt) LoadLuaScriptsDir

func (engine *Akevitt) LoadLuaScriptsDir(dir string) error

func (*Akevitt) ReloadLua

func (engine *Akevitt) ReloadLua() error

func (*Akevitt) Run

func (engine *Akevitt) Run() error

func (*Akevitt) SaveObject

func (engine *Akevitt) SaveObject(object Object) error

type CommandFunc

type CommandFunc = func(engine *Akevitt, session *ActiveSession, arguments string) error

type DatabasePlugin

type DatabasePlugin[T Object] interface {
	Plugin

	Save(T) error
	LoadAll() ([]T, error)
}

type DeadSessionFunc

type DeadSessionFunc = func(deadSession *ActiveSession, liveSessions []*ActiveSession, engine *Akevitt)

type Exit

type Exit struct {
	Room       *Room
	Name       string
	OnPreEnter func(*Akevitt, *ActiveSession) error
}

func IsRoomReachable

func IsRoomReachable[T Room](engine *Akevitt, session *ActiveSession, name string, currentRoomKey uint64) (*Exit, error)

type Item

type Item struct {
	ObjectImpl
	Properties map[string]any
}

func NewItem

func NewItem(name string) *Item

type LuaVM

type LuaVM struct {
	L *lua.LState
	// contains filtered or unexported fields
}

func NewLuaVM

func NewLuaVM() *LuaVM

func (*LuaVM) CallCommand

func (vm *LuaVM) CallCommand(command string, session *ActiveSession) error

func (*LuaVM) Close

func (vm *LuaVM) Close()

func (*LuaVM) GetScript

func (vm *LuaVM) GetScript(name string) (*lua.LFunction, bool)

func (*LuaVM) LoadScript

func (vm *LuaVM) LoadScript(path string) error

func (*LuaVM) LoadScriptsDir

func (vm *LuaVM) LoadScriptsDir(dir string) error

func (*LuaVM) Reload

func (vm *LuaVM) Reload() error

func (*LuaVM) SetEngine

func (vm *LuaVM) SetEngine(engine *Akevitt)

func (*LuaVM) SetScriptsPath

func (vm *LuaVM) SetScriptsPath(path string)

type NPC

type NPC struct {
	ObjectImpl
	RoomID     string
	Dialogue   string
	OnInteract func(*Akevitt, *ActiveSession) error
}

func NewNPC

func NewNPC(name string) *NPC

type Object

type Object interface {
	GetName() string
	GetGUID() string
}

type ObjectImpl

type ObjectImpl struct {
	Name        string
	Description string
	GUID        string
}

func (*ObjectImpl) GetGUID

func (o *ObjectImpl) GetGUID() string

func (*ObjectImpl) GetName

func (o *ObjectImpl) GetName() string

type Pair

type Pair[TFirst any, TSecond any] struct {
	L TFirst
	R TSecond
}

type Plugin

type Plugin interface {
	Build(*Akevitt) error
}

type Room

type Room struct {
	ObjectImpl
	Exits      []*Exit
	Objects    []Object
	OnPreEnter func(*Akevitt, *ActiveSession, *Exit) error
	// contains filtered or unexported fields
}

func NewRoom

func NewRoom(name string) *Room

func (*Room) AddObject

func (room *Room) AddObject(obj Object)

func (*Room) Enter

func (room *Room) Enter(engine *Akevitt, session *ActiveSession, targetExit *Exit) error

func (*Room) GetKey

func (room *Room) GetKey() uint64

func (*Room) GetObjects

func (room *Room) GetObjects() []Object

func (*Room) RemoveObject

func (room *Room) RemoveObject(obj Object)

type Sessions

type Sessions = map[ssh.Session]*ActiveSession

type UIFunc

type UIFunc = func(engine *Akevitt, session *ActiveSession) tview.Primitive

Jump to

Keyboard shortcuts

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