gamemanager

package
v0.0.0-...-85dc63b Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRoomNotFound occurs when the room doesn't exist in the given story.
	ErrRoomNotFound = errors.New("room not found")
	// ErrExitNotFound occurs when the exit doesn't exit in the given room.
	ErrExitNotFound = errors.New("exit not found")
)
View Source
var ErrInvalidSerializationFormat = errors.New("invalid serialization format")

ErrInvalidSerializationFormat occurs when engine config specifies a unsupported format.

View Source
var ErrInvalidStoryDirectory = errors.New("story directory does not exist")

ErrInvalidStoryDirectory occurs when the config specifies a nonexistent story directory.

View Source
var File_gamemanager_statetoken_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type EngineConfig

type EngineConfig struct {
	RenderDescriptions bool
	StateTokenFormat   SerializationFormat
}

EngineConfig contains settings information for driving the engine.

func NewEngineConfig

func NewEngineConfig(renderDesc bool, tokenFormat string) (EngineConfig, error)

NewEngineConfig news up an EngineConfig based on passed in values.

type Exit

type Exit struct {
	Description    string `yaml:"exit_description" json:"exit_description"`
	Destination    string `yaml:"destination_id" json:"destination_id" binding:"uuid"`
	SetCondition   string `yaml:"set_condition,omitempty" json:"set_condition"`
	IfCondition    string `yaml:"if_condition,omitempty" json:"if_condition"`
	NotCondition   string `yaml:"not_condition,omitempty" json:"not_condition"`
	UnsetCondition string `yaml:"unset_condition,omitempty" json:"unset_condition"`
}

Exit describes actions applied to GameState as part of leaving a Room.

type GameManager

type GameManager struct {
	Book         StoryBook
	EngineConfig EngineConfig
}

GameManager contains configuration info about stories and managed GameState objects.

func NewGameManager

func NewGameManager(book StoryBook, config EngineConfig) (*GameManager, error)

NewGameManager creates a new GameManager, using Stories in the Config.

func (*GameManager) ConstructSpeculativeStates

func (gm *GameManager) ConstructSpeculativeStates(gameState GameState, currentRoom Room) ([]SpeculativeState, error)

ConstructSpeculativeStates makes a SpeculativeState from the active GameState and actions available in currentRoom.

func (*GameManager) ConstructStartingState

func (gm *GameManager) ConstructStartingState(story StoryMetadata) (SpeculativeState, error)

ConstructStartingState generates a starting stateToken for each loaded story.

func (*GameManager) DeserializeState

func (gm *GameManager) DeserializeState(stateToken string) (GameState, error)

DeserializeState converts a stateToken into a GameState.

func (*GameManager) GetRoomByID

func (gm *GameManager) GetRoomByID(storyID string, roomID string) (Room, error)

GetRoomByID finds Room information based on room and story IDs.

func (*GameManager) GetStories

func (gm *GameManager) GetStories() []StoryMetadata

GetStories lists all StoryMetadata for stories tracked by GameManager.

func (*GameManager) SerializeState

func (gm *GameManager) SerializeState(gameState GameState) (string, error)

SerializeState generates a stateToken based on the given GameState.

func (*GameManager) StartGame

func (gm *GameManager) StartGame(storyID string) (GameState, error)

StartGame creates a new GameState representing the start of a given storyID.

type GameState

type GameState struct {
	StoryID     string   `json:"si"`
	CurrentRoom string   `json:"cr"`
	Conditions  []string `json:"cn"`
}

GameState contains state information about an active game in progress.

func (GameState) ConditionMet

func (gs GameState) ConditionMet(cond string) bool

ConditionMet checks to see if a condition has been met.

func (*GameState) MeetCondition

func (gs *GameState) MeetCondition(cond string)

MeetCondition adds a condtition to the list of met conditions if not already met.

func (*GameState) RemoveCondition

func (gs *GameState) RemoveCondition(cond string)

RemoveCondition removes a condtition from the list of met conditions if it exists.

func (GameState) UseExit

func (gs GameState) UseExit(exit Exit) GameState

UseExit applies an exit's consequences to the GameState to produce a new GameState.

type Room

type Room struct {
	ID          string `yaml:"room_id" json:"room_id" binding:"uuid"`
	Name        string `yaml:"room_name" json:"room_name"`
	Description string `yaml:"room_description,omitempty" json:"room_description"`
	Exits       []Exit `yaml:"exits,omitempty" json:"exits"`
}

Room contains information about a room and its Exits.

type SerializationFormat

type SerializationFormat int

SerializationFormat determines which format StateTokens are serialized as.

const (
	// JSON describes the json serilization format.
	JSON SerializationFormat = iota + 1
	// Protobuf describes the protobuf serilization format.
	Protobuf
)

func GetSerDeFormat

func GetSerDeFormat(format string) SerializationFormat

GetSerDeFormat translates format type strings to SerializationFormat.

type SpeculativeState

type SpeculativeState struct {
	Description string
	StateToken  string
}

SpeculativeState is used to provide "what if" GameStates for next available actions.

type StateToken

type StateToken struct {
	StoryID     string   `protobuf:"bytes,1,opt,name=StoryID,json=sid,proto3" json:"StoryID,omitempty"`
	CurrentRoom string   `protobuf:"bytes,2,opt,name=CurrentRoom,json=cr,proto3" json:"CurrentRoom,omitempty"`
	Conditions  []string `protobuf:"bytes,3,rep,name=Conditions,json=cn,proto3" json:"Conditions,omitempty"`
	// contains filtered or unexported fields
}

func (*StateToken) Descriptor deprecated

func (*StateToken) Descriptor() ([]byte, []int)

Deprecated: Use StateToken.ProtoReflect.Descriptor instead.

func (*StateToken) GetConditions

func (x *StateToken) GetConditions() []string

func (*StateToken) GetCurrentRoom

func (x *StateToken) GetCurrentRoom() string

func (*StateToken) GetStoryID

func (x *StateToken) GetStoryID() string

func (*StateToken) ProtoMessage

func (*StateToken) ProtoMessage()

func (*StateToken) ProtoReflect

func (x *StateToken) ProtoReflect() protoreflect.Message

func (*StateToken) Reset

func (x *StateToken) Reset()

func (*StateToken) String

func (x *StateToken) String() string

type Story

type Story struct {
	Metadata StoryMetadata `yaml:"metadata" json:"metadata"`
	Rooms    []Room        `yaml:"rooms" json:"rooms"`
}

Story contains all information about a loaded story.

type StoryBook

type StoryBook struct {
	Stories map[string]Story `yaml:"stories" json:"stories"`
}

StoryBook contains information on all of the stories loaded from disk.

func NewStoryBook

func NewStoryBook(root string) (StoryBook, error)

NewStoryBook makes a new Config object and loads in all of the stories from the given path.

type StoryMetadata

type StoryMetadata struct {
	ID              string   `yaml:"id"`
	Name            string   `yaml:"name"`
	Description     string   `yaml:"description"`
	ContentWarnings []string `yaml:"cw"`
	StartingScene   string   `yaml:"starting_scene"`
	Author          string   `yaml:"author"`
}

StoryMetadata contains story metadata - authorship information, etc.

Jump to

Keyboard shortcuts

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