Documentation ¶
Overview ¶
Program written by Ivan Korchmit (c) 2023 Licensed under European Union Public Licence 1.2. For more information, view LICENCE or README
Index ¶
- func AppendText(message string, chatlog *logview.LogView)
- func BindRooms(emptyExit Exit, room *Room, otherRooms ...*Room)
- func CreateObject[T GameObject](engine *Akevitt, session *ActiveSession, object T, params interface{}) (T, error)
- func ErrorBox(message string, app *tview.Application, back tview.Primitive)
- func FilterByType[T any, TCollection any](collection []TCollection) []T
- func Find[T comparable](collection []T, value T) bool
- func FindByKey[TCollection, T comparable](collection []TCollection, selector func(key TCollection) T, value T) *TCollection
- func FindNeighboringRoomByName(currentRoom *Room, name string) (*Room, *Exit, error)
- func FindObject[T GameObject](engine *Akevitt, session *ActiveSession, key uint64) (T, error)
- func LogError(message string)
- func LogInfo(message string)
- func LogWarn(message string)
- func LoginScreen(engine *Akevitt, session *ActiveSession, nextScreen UIFunc) tview.Primitive
- func LookupOfType[T GameObject](room Room) []T
- func MapSlice[T any, TResult any](l []T, callback func(v T) TResult) []TResult
- func NewEngine() *akevittBuilder
- func OocCmd(engine *Akevitt, session *ActiveSession, command string) error
- func RegistrationScreen(engine *Akevitt, session *ActiveSession, nextScreen UIFunc) tview.Primitive
- func RemoveItem[T comparable](l []T, item T) []T
- func RemoveItemByIndex[T any](l []T, i int) []T
- func SaveObject[T Object](engine *Akevitt, obj T, category string, key uint64) error
- type Account
- type ActiveSession
- type Akevitt
- func (engine *Akevitt) Dialogue(dialogue *Dialogue, session *ActiveSession) error
- func (engine *Akevitt) ExecuteCommand(command string, session *ActiveSession) error
- func (engine *Akevitt) GenerateKey(gameobject GameObject) (uint64, error)
- func (engine *Akevitt) GetCommands() []string
- func (engine *Akevitt) GetRoom(key uint64) (*Room, error)
- func (engine *Akevitt) GetSpawnRoom() *Room
- func (engine *Akevitt) GlobalLookup(room *Room, name string) []GameObject
- func (engine *Akevitt) Login(username, password string, session *ActiveSession) error
- func (engine *Akevitt) Message(channel, message, username string, session *ActiveSession) error
- func (engine *Akevitt) Register(username, password, repeatPassword string, session *ActiveSession) error
- func (engine *Akevitt) Run() error
- func (engine *Akevitt) SaveGameObject(gameObject GameObject, key uint64, account *Account) error
- func (engine *Akevitt) SaveObject(gameObject GameObject, key uint64) error
- func (engine *Akevitt) SubscribeToHeartBeat(interval int, fn func() error) error
- type CommandFunc
- type DeadSessionFunc
- type Dialogue
- func (dial *Dialogue) AddOption(title string, content tview.Primitive) *Dialogue
- func (dial *Dialogue) End() *Dialogue
- func (dial *Dialogue) GetContents() tview.Primitive
- func (dial *Dialogue) GetOptions() []*Dialogue
- func (dial *Dialogue) GetTitle() string
- func (dial *Dialogue) Proceed(index int, session *ActiveSession, engine *Akevitt) error
- func (dial *Dialogue) SetContent(content tview.Primitive) *Dialogue
- type DialogueFunc
- type Exit
- type GameObject
- type MessageFunc
- type Object
- type Room
- type Sessions
- type UIFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendText ¶ added in v0.3.3
func CreateObject ¶
func CreateObject[T GameObject](engine *Akevitt, session *ActiveSession, object T, params interface{}) (T, error)
func ErrorBox ¶ added in v0.3.3
func ErrorBox(message string, app *tview.Application, back tview.Primitive)
func FilterByType ¶
func FindByKey ¶ added in v0.3.3
func FindByKey[TCollection, T comparable](collection []TCollection, selector func(key TCollection) T, value T) *TCollection
func FindNeighboringRoomByName ¶ added in v0.3.3
func FindObject ¶
func FindObject[T GameObject](engine *Akevitt, session *ActiveSession, key uint64) (T, error)
Finds game object associated with an account in database.
func LoginScreen ¶ added in v0.3.3
func LoginScreen(engine *Akevitt, session *ActiveSession, nextScreen UIFunc) tview.Primitive
func LookupOfType ¶
func LookupOfType[T GameObject](room Room) []T
func OocCmd ¶ added in v0.3.3
func OocCmd(engine *Akevitt, session *ActiveSession, command string) error
Out-of-character chat command
func RegistrationScreen ¶ added in v0.3.3
func RegistrationScreen(engine *Akevitt, session *ActiveSession, nextScreen UIFunc) tview.Primitive
func RemoveItem ¶
func RemoveItem[T comparable](l []T, item T) []T
Removes item from collection and returns it.
func RemoveItemByIndex ¶ added in v0.3.3
Types ¶
type Account ¶
Basic structure for storing credential information. After registering an account, the password is hashed in a proper way To create one you would need to invoke `engine.Register(username, password, session)`
type ActiveSession ¶
type ActiveSession struct { Account *Account Application *tview.Application Data map[string]any }
type Akevitt ¶
type Akevitt struct {
// contains filtered or unexported fields
}
The engine instance which can be passed as an argument and provide some useful methods like Login, Register, Message, Dialogue, etc. Methods with name starting like Use should be called in a main function during the initialisation step. To actually run the engine, you must call Run function and pass the engine instance Example: fmt.Fatal(akevitt.Run[*MySessionStruct](engine))
func (*Akevitt) Dialogue ¶
func (engine *Akevitt) Dialogue(dialogue *Dialogue, session *ActiveSession) error
Invokes dialogue event. Make sure you have installed the hook during initalisation.
func (*Akevitt) ExecuteCommand ¶
func (engine *Akevitt) ExecuteCommand(command string, session *ActiveSession) error
Execute the command specified in a `command`. The command can be registered using the useRegisterCommand method. Returns an error if the given command not found or the result of associated function returns an error.
func (*Akevitt) GenerateKey ¶
func (engine *Akevitt) GenerateKey(gameobject GameObject) (uint64, error)
Auto-increment uint64 key by object's name.
func (*Akevitt) GetCommands ¶
Gets currently registered commands. This is useful if your game implements auto-completion.
func (*Akevitt) GetRoom ¶
Obtains currently loaded rooms by key. It will return an error if room not found.
func (*Akevitt) GetSpawnRoom ¶
Get sspawn room if specified. Useful for setting character's initial room during its creation.
func (*Akevitt) GlobalLookup ¶ added in v0.3.0
func (engine *Akevitt) GlobalLookup(room *Room, name string) []GameObject
func (*Akevitt) Login ¶
func (engine *Akevitt) Login(username, password string, session *ActiveSession) error
Login call to the database. Note: returns an error if the session is already active.
func (*Akevitt) Message ¶
func (engine *Akevitt) Message(channel, message, username string, session *ActiveSession) error
Send the message to other current sessions
func (*Akevitt) Register ¶
func (engine *Akevitt) Register(username, password, repeatPassword string, session *ActiveSession) error
Create an account Returns an error if account with the same username already exists
func (*Akevitt) Run ¶ added in v0.3.3
Run the given instance of engine. You should pass your own implementation of ActiveSession, so it can be controlled of how your game would behave
func (*Akevitt) SaveGameObject ¶
func (engine *Akevitt) SaveGameObject(gameObject GameObject, key uint64, account *Account) error
Saves game object in a database associated with an account.
func (*Akevitt) SaveObject ¶
func (engine *Akevitt) SaveObject(gameObject GameObject, key uint64) error
Saves object into a database.
type CommandFunc ¶
type CommandFunc = func(engine *Akevitt, session *ActiveSession, arguments string) error
type DeadSessionFunc ¶
type DeadSessionFunc = func(deadSession *ActiveSession, liveSessions []*ActiveSession, engine *Akevitt)
type Dialogue ¶
type Dialogue struct {
// contains filtered or unexported fields
}
Dialogue struct for creating dialogue-like events. The content is actually a UI element, so you implement merchants, dialogues, etc. You must call NewDialogue to get started.
func (*Dialogue) GetContents ¶
Gets the UI of dialogue
func (*Dialogue) GetOptions ¶
Gets an array of options
type DialogueFunc ¶
type DialogueFunc = func(engine *Akevitt, session *ActiveSession, dialogue *Dialogue) error
type Exit ¶
func IsRoomReachable ¶
func IsRoomReachable[T Room](engine *Akevitt, session *ActiveSession, name string, currentRoomKey uint64) (*Exit, error)
Checks if current room specified reachable to another room.
type GameObject ¶
type GameObject interface { Object GetName() string Create(engine *Akevitt, session *ActiveSession, params interface{}) error // Create an object wuth specified parameters. }
Base of the gameobjects that can be involved in gameplay.
type MessageFunc ¶
type MessageFunc = func(engine *Akevitt, session *ActiveSession, channel, message, username string) error
type Room ¶
type Room struct { Name string Exits []*Exit Objects []GameObject OnPreEnter func(*ActiveSession) error }
type Sessions ¶
type Sessions = map[ssh.Session]*ActiveSession